1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
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  
34  
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  
41  
42  
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  
56  
57  
58  
59  
60  
61  
62      @Override
63      public List getSections(MaintenanceDocument document, Maintainable oldMaintainable) {
64          List<Section> sections = super.getSections(document, oldMaintainable);
65          
66          
67          
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 
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 }