001 /* 002 * Copyright 2011 The Kuali Foundation. 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016 package org.kuali.kfs.module.bc.document.web.struts; 017 018 import java.util.Arrays; 019 import java.util.Collections; 020 import java.util.List; 021 022 import javax.servlet.http.HttpServletRequest; 023 024 import org.kuali.kfs.coa.service.OrganizationService; 025 import org.kuali.kfs.module.bc.BCConstants; 026 import org.kuali.kfs.module.bc.BCPropertyConstants; 027 import org.kuali.kfs.module.bc.businessobject.BudgetConstructionHeader; 028 import org.kuali.kfs.module.bc.document.service.BudgetConstructionProcessorService; 029 import org.kuali.kfs.module.bc.document.service.BudgetDocumentService; 030 import org.kuali.kfs.module.bc.document.service.SalarySettingService; 031 import org.kuali.kfs.sys.context.SpringContext; 032 import org.kuali.kfs.sys.identity.KfsKimAttributes; 033 import org.kuali.rice.kim.bo.types.dto.AttributeSet; 034 import org.kuali.rice.kim.service.IdentityManagementService; 035 import org.kuali.rice.kns.service.PersistenceService; 036 import org.kuali.rice.kns.util.GlobalVariables; 037 038 039 /** 040 * This class... 041 */ 042 public class BudgetConstructionSelectionForm extends BudgetExpansionForm { 043 private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(BudgetConstructionSelectionForm.class); 044 045 private BudgetConstructionHeader budgetConstructionHeader; 046 private boolean hideDetails = false; 047 private boolean accountReportsExist; 048 private boolean rootApprover; 049 private boolean sessionInProgressDetected = false; 050 051 public BudgetConstructionSelectionForm() { 052 super(); 053 setBudgetConstructionHeader(new BudgetConstructionHeader()); 054 } 055 056 /** 057 * @see org.kuali.rice.kns.web.struts.form.KualiForm#populate(javax.servlet.http.HttpServletRequest) 058 */ 059 @Override 060 public void populate(HttpServletRequest request) { 061 062 super.populate(request); 063 064 final List REFRESH_FIELDS = Collections.unmodifiableList(Arrays.asList(new String[] { "chartOfAccounts", "account", "subAccount", "budgetConstructionAccountReports" })); 065 SpringContext.getBean(PersistenceService.class).retrieveReferenceObjects(this.getBudgetConstructionHeader(), REFRESH_FIELDS); 066 067 } 068 069 /** 070 * Gets the budgetConstructionHeader attribute. 071 * 072 * @return Returns the budgetConstructionHeader. 073 */ 074 public BudgetConstructionHeader getBudgetConstructionHeader() { 075 return budgetConstructionHeader; 076 } 077 078 /** 079 * Sets the budgetConstructionHeader attribute value. 080 * 081 * @param budgetConstructionHeader The budgetConstructionHeader to set. 082 */ 083 public void setBudgetConstructionHeader(BudgetConstructionHeader budgetConstructionHeader) { 084 this.budgetConstructionHeader = budgetConstructionHeader; 085 } 086 087 /** 088 * Gets the hideDetails attribute. 089 * 090 * @return Returns the hideDetails. 091 */ 092 public boolean isHideDetails() { 093 return hideDetails; 094 } 095 096 /** 097 * Sets the hideDetails attribute value. 098 * 099 * @param hideDetails The hideDetails to set. 100 */ 101 public void setHideDetails(boolean hideDetails) { 102 this.hideDetails = hideDetails; 103 } 104 105 /** 106 * Gets the accountReportsExist attribute. 107 * 108 * @return Returns the accountReportsExist. 109 */ 110 public boolean isAccountReportsExist() { 111 accountReportsExist = false; 112 113 if (this.budgetConstructionHeader.getAccountNumber() != null && this.budgetConstructionHeader.getChartOfAccountsCode() != null) { 114 if (SpringContext.getBean(BudgetDocumentService.class).isAccountReportsExist(this.budgetConstructionHeader.getChartOfAccountsCode(), this.budgetConstructionHeader.getAccountNumber())){ 115 accountReportsExist = true; 116 } 117 } 118 return accountReportsExist; 119 } 120 121 /** 122 * Sets the accountReportsExist attribute value. 123 * 124 * @param accountReportsExist The accountReportsExist to set. 125 */ 126 public void setAccountReportsExist(boolean accountReportsExist) { 127 this.accountReportsExist = accountReportsExist; 128 } 129 130 /** 131 * Gets the salarySettingDisabled attribute. 132 * 133 * @return Returns the salarySettingDisabled. 134 */ 135 public boolean isSalarySettingDisabled() { 136 return SpringContext.getBean(SalarySettingService.class).isSalarySettingDisabled(); 137 } 138 139 /** 140 * Checks whether the user has permission to do payrate import/export 141 */ 142 public boolean getCanPerformPayrateImportExport() { 143 String[] rootOrg = SpringContext.getBean(OrganizationService.class).getRootOrganizationCode(); 144 AttributeSet qualification = new AttributeSet(); 145 qualification.put(BCPropertyConstants.ORGANIZATION_CHART_OF_ACCOUNTS_CODE, rootOrg[0]); 146 qualification.put(KfsKimAttributes.ORGANIZATION_CODE, rootOrg[1]); 147 148 return SpringContext.getBean(IdentityManagementService.class).isAuthorized(GlobalVariables.getUserSession().getPerson().getPrincipalId(), BCConstants.BUDGET_CONSTRUCTION_NAMESPACE, BCConstants.KimConstants.IMPORT_EXPORT_PAYRATE_PERMISSION_NAME, null, qualification); 149 } 150 151 /** 152 * Gets the sessionInProgressDetected attribute. 153 * @return Returns the sessionInProgressDetected. 154 */ 155 public boolean isSessionInProgressDetected() { 156 return sessionInProgressDetected; 157 } 158 159 /** 160 * Sets the sessionInProgressDetected attribute value. 161 * @param sessionInProgressDetected The sessionInProgressDetected to set. 162 */ 163 public void setSessionInProgressDetected(boolean sessionInProgressDetected) { 164 this.sessionInProgressDetected = sessionInProgressDetected; 165 } 166 167 } 168