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.pdp.document;
017    
018    import java.security.GeneralSecurityException;
019    import java.sql.Date;
020    import java.util.ArrayList;
021    import java.util.List;
022    import java.util.Map;
023    
024    import org.apache.commons.lang.StringUtils;
025    import org.kuali.kfs.coa.businessobject.AccountDelegate;
026    import org.kuali.kfs.coa.businessobject.AccountDelegateGlobal;
027    import org.kuali.kfs.coa.identity.OrgReviewRole;
028    import org.kuali.kfs.coa.identity.OrgReviewRoleLookupableHelperServiceImpl;
029    import org.kuali.kfs.coa.service.AccountDelegateService;
030    import org.kuali.kfs.coa.service.OrganizationReversionService;
031    import org.kuali.kfs.pdp.PdpPropertyConstants;
032    import org.kuali.kfs.pdp.businessobject.CustomerProfile;
033    import org.kuali.kfs.sys.KFSConstants;
034    import org.kuali.kfs.sys.context.SpringContext;
035    import org.kuali.kfs.sys.document.FinancialSystemMaintainable;
036    import org.kuali.rice.core.service.EncryptionService;
037    import org.kuali.rice.kim.service.RoleManagementService;
038    import org.kuali.rice.kns.bo.DocumentHeader;
039    import org.kuali.rice.kns.document.MaintenanceDocument;
040    import org.kuali.rice.kns.document.MaintenanceLock;
041    import org.kuali.rice.kns.maintenance.Maintainable;
042    import org.kuali.rice.kns.service.BusinessObjectAuthorizationService;
043    import org.kuali.rice.kns.service.DataDictionaryService;
044    import org.kuali.rice.kns.service.DateTimeService;
045    import org.kuali.rice.kns.service.KNSServiceLocator;
046    import org.kuali.rice.kns.util.ObjectUtils;
047    import org.kuali.rice.kns.web.ui.Field;
048    import org.kuali.rice.kns.web.ui.Row;
049    import org.kuali.rice.kns.web.ui.Section;
050    
051    /**
052     * This class is a special implementation of Maintainable specifically for Account Delegates. It was created to correctly update the
053     * default Start Date on edits and copies, ala JIRA #KULRNE-62.
054     */
055    public class CustomerProfileMaintenanceDocumentMaintainableImpl extends FinancialSystemMaintainable {
056        private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CustomerProfileMaintenanceDocumentMaintainableImpl.class);
057    
058        /**
059         * This method will reset AccountDelegate's Start Date to the current timestamp on edits and copies
060         * 
061         * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#processAfterRetrieve()
062         */
063        @Override
064        public void processAfterCopy( MaintenanceDocument document, Map<String,String[]> parameters ) {
065            
066            super.processAfterCopy( document, parameters );
067            CustomerProfile customerProfile = (CustomerProfile) document.getNewMaintainableObject().getBusinessObject();
068            customerProfile.setChartCode(null);
069            customerProfile.setUnitCode(null); 
070            customerProfile.setSubUnitCode(null);
071        }
072        
073        
074        public List getSections(MaintenanceDocument document, Maintainable oldMaintainable) {
075            List<Section> sections = super.getSections(document, oldMaintainable);
076            //If oldMaintainable is null, it means we are trying to get sections for the old part
077            //If oldMaintainable is not null, it means we are trying to get sections for the new part
078            //Refer to KualiMaintenanceForm lines 288-294
079            CustomerProfile customerProfile = (CustomerProfile) document.getNewMaintainableObject().getBusinessObject();
080            if(oldMaintainable==null) return sections;
081            if (shouldReviewTypesFieldBeReadOnly(document) == false) return sections;
082    
083            for (Section section : sections) {
084                for (Row row : section.getRows()) {
085                    for (Field field : row.getFields()) {
086                        if (PdpPropertyConstants.CustomerProfile.CUSTOMER_PROFILE_CHART_CODE.equals(field.getPropertyName())) {
087                            field.setReadOnly(true);
088                         }
089                        if (PdpPropertyConstants.CustomerProfile.CUSTOMER_PROFILE_UNIT_CODE.equals(field.getPropertyName())) {
090                             field.setReadOnly(true);
091                        }
092                        if (PdpPropertyConstants.CustomerProfile.CUSTOMER_PROFILE_SUB_UNIT_CODE.equals(field.getPropertyName())) {
093                            field.setReadOnly(true);
094                        }
095                    }
096                }
097            }
098            return sections;
099        }
100    
101    
102        protected boolean shouldReviewTypesFieldBeReadOnly(MaintenanceDocument document){
103            CustomerProfile  customerProfile = (CustomerProfile)document.getNewMaintainableObject().getBusinessObject();
104            if(StringUtils.isEmpty(customerProfile.getChartCode())) return false;
105            if(StringUtils.isEmpty(customerProfile.getSubUnitCode())) return false;
106            if(StringUtils.isEmpty(customerProfile.getUnitCode())) return false;
107            return true;
108        }
109    
110    
111      
112    }