View Javadoc
1   /*
2    * Copyright 2007 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.pdp.document;
17  
18  import java.util.List;
19  import java.util.Map;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.ole.pdp.PdpPropertyConstants;
23  import org.kuali.ole.pdp.businessobject.CustomerProfile;
24  import org.kuali.ole.sys.document.FinancialSystemMaintainable;
25  import org.kuali.rice.kns.document.MaintenanceDocument;
26  import org.kuali.rice.kns.maintenance.Maintainable;
27  import org.kuali.rice.kns.web.ui.Field;
28  import org.kuali.rice.kns.web.ui.Row;
29  import org.kuali.rice.kns.web.ui.Section;
30  import org.kuali.rice.krad.util.ObjectUtils;
31  
32  /**
33   * This class is a special implementation of Maintainable specifically for Account Delegates. It was created to correctly update the
34   * default Start Date on edits and copies, ala JIRA #KULRNE-62.
35   */
36  public class CustomerProfileMaintenanceDocumentMaintainableImpl extends FinancialSystemMaintainable {
37      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CustomerProfileMaintenanceDocumentMaintainableImpl.class);
38  
39      /**
40       * This method will reset AccountDelegate's Start Date to the current timestamp on edits and copies
41       * 
42       * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#processAfterRetrieve()
43       */
44      @Override
45      public void processAfterCopy( MaintenanceDocument document, Map<String,String[]> parameters ) {
46          
47          super.processAfterCopy( document, parameters );
48          CustomerProfile customerProfile = (CustomerProfile) document.getNewMaintainableObject().getBusinessObject();
49          customerProfile.setChartCode(null);
50          customerProfile.setUnitCode(null); 
51          customerProfile.setSubUnitCode(null);
52      }
53      
54      /**
55       * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#refresh(java.lang.String, java.util.Map,
56       *      org.kuali.rice.kns.document.MaintenanceDocument)
57       * 
58       * KRAD Conversion: Performs customization of the sections making fields read only.
59       * 
60       * No use of data dictionary.
61       */
62      @Override
63      public List getSections(MaintenanceDocument document, Maintainable oldMaintainable) {
64          List<Section> sections = super.getSections(document, oldMaintainable);
65          //If oldMaintainable is null, it means we are trying to get sections for the old part
66          //If oldMaintainable is not null, it means we are trying to get sections for the new part
67          //Refer to KualiMaintenanceForm lines 288-294
68          CustomerProfile customerProfile = (CustomerProfile) document.getNewMaintainableObject().getBusinessObject();
69          if(oldMaintainable==null) {
70              return sections;
71          }
72          if (shouldReviewTypesFieldBeReadOnly(document) == false) {
73              return sections;
74          }
75  
76          for (Section section : sections) {
77              for (Row row : section.getRows()) {
78                  for (Field field : row.getFields()) {
79                      if (PdpPropertyConstants.CustomerProfile.CUSTOMER_PROFILE_CHART_CODE.equals(field.getPropertyName())) {
80                          field.setReadOnly(true);
81                       }
82                      if (PdpPropertyConstants.CustomerProfile.CUSTOMER_PROFILE_UNIT_CODE.equals(field.getPropertyName())) {
83                           field.setReadOnly(true);
84                      }
85                      if (PdpPropertyConstants.CustomerProfile.CUSTOMER_PROFILE_SUB_UNIT_CODE.equals(field.getPropertyName())) {
86                          field.setReadOnly(true);
87                      }
88                  }
89              }
90          }
91          return sections;
92      }
93  
94  
95      protected boolean shouldReviewTypesFieldBeReadOnly(MaintenanceDocument document){
96          CustomerProfile  customerProfile = (CustomerProfile)document.getNewMaintainableObject().getBusinessObject();
97          if(StringUtils.isEmpty(customerProfile.getChartCode())) {
98              return false;
99          }
100         if(StringUtils.isEmpty(customerProfile.getSubUnitCode())) {
101             return false;
102         }
103         if(StringUtils.isEmpty(customerProfile.getUnitCode())) {
104             return false;
105         }
106         return true;
107     }
108 
109     /**
110      * @see org.kuali.ole.sys.document.FinancialSystemMaintainable#processAfterPost(org.kuali.rice.kns.document.MaintenanceDocument, java.util.Map)
111      */
112     @Override
113     public void processAfterPost(MaintenanceDocument document, Map<String, String[]> parameters) {
114         CustomerProfile  customerProfile = (CustomerProfile)document.getNewMaintainableObject().getBusinessObject();
115 
116        if (ObjectUtils.isNull(customerProfile.getDefaultSubAccountNumber())) {
117         customerProfile.setDefaultSubAccountNumber(PdpPropertyConstants.CustomerProfile.CUSTOMER_DEFAULT_SUB_ACCOUNT_NUMBER);
118     }
119        if (ObjectUtils.isNull(customerProfile.getDefaultSubObjectCode())) {
120         customerProfile.setDefaultSubObjectCode(PdpPropertyConstants.CustomerProfile.CUSTOMER_DEFAULT_SUB_OBJECT_CODE);
121     }
122         super.processAfterPost(document, parameters);
123     }
124 }