1   
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  package org.kuali.ole.coa.document.validation.impl;
17  
18  import java.util.Map;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.ole.coa.businessobject.ObjectCode;
22  import org.kuali.ole.coa.businessobject.ObjectLevel;
23  import org.kuali.ole.coa.service.ChartService;
24  import org.kuali.ole.coa.service.ObjectLevelService;
25  import org.kuali.ole.sys.OLEConstants;
26  import org.kuali.ole.sys.OLEKeyConstants;
27  import org.kuali.ole.sys.context.SpringContext;
28  import org.kuali.rice.core.api.config.property.ConfigurationService;
29  import org.kuali.rice.kns.document.MaintenanceDocument;
30  import org.kuali.rice.kns.rules.PromptBeforeValidationBase;
31  import org.kuali.rice.krad.document.Document;
32  
33  
34  
35  
36  
37  public class ObjectCodePreRules extends PromptBeforeValidationBase {
38      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(ObjectCodePreRules.class);
39  
40      protected static ChartService chartService;
41      protected static ObjectLevelService objectLevelService;
42      protected Map reportsTo;
43  
44      
45  
46  
47  
48  
49      public ObjectCodePreRules() {
50          if (objectLevelService == null) {
51              objectLevelService = SpringContext.getBean(ObjectLevelService.class);
52              chartService = SpringContext.getBean(ChartService.class);
53          }
54  
55          reportsTo = chartService.getReportsToHierarchy();
56      }
57  
58      
59  
60  
61  
62  
63  
64  
65  
66      @Override
67      public boolean doPrompts(Document document) {
68          MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document;
69  
70          LOG.debug("doRules");
71  
72          if (LOG.isDebugEnabled()) {
73              LOG.debug("new maintainable is: " + maintenanceDocument.getNewMaintainableObject().getClass());
74          }
75          ObjectCode newObjectCode = (ObjectCode) maintenanceDocument.getNewMaintainableObject().getBusinessObject();
76  
77          String chart = newObjectCode.getChartOfAccountsCode();
78          String reportsToChart = (String) reportsTo.get(chart);
79          if (LOG.isDebugEnabled()) {
80              LOG.debug("Chart: " + chart);
81              LOG.debug("reportsTo: " + reportsToChart);
82              LOG.debug("User supplied reportsToChart: " + newObjectCode.getReportsToChartOfAccountsCode());
83          }
84  
85          
86          newObjectCode.setReportsToChartOfAccountsCode(reportsToChart);
87  
88          
89          ObjectLevel financialObjectLevel = objectLevelService.getByPrimaryId(chart, newObjectCode.getFinancialObjectLevelCode());
90          if (!(financialObjectLevel == null)) {
91              if (!financialObjectLevel.isActive()) {
92                  String objectLevelChartOfAccountCode = financialObjectLevel.getChartOfAccountsCode();
93                  String objectLevelFinancialObjectLevelCode = financialObjectLevel.getFinancialObjectLevelCode();
94                  String objectLevelFinancialObjectLevelName = financialObjectLevel.getFinancialObjectLevelName();
95                  String questionText = SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(OLEKeyConstants.ObjectCode.QUESTION_INACTIVE_OBJECT_LEVEL_CONFIRMATION);
96                  questionText = StringUtils.replace(questionText, "{0}", objectLevelChartOfAccountCode);
97                  questionText = StringUtils.replace(questionText, "{1}", objectLevelFinancialObjectLevelCode);
98                  questionText = StringUtils.replace(questionText, "{2}", objectLevelFinancialObjectLevelName);
99                  boolean useInactiveObjectLevel = super.askOrAnalyzeYesNoQuestion(OLEConstants.ObjectCodeConstants.INACTIVE_OBJECT_LEVEL_QUESTION_ID, questionText);
100                 if (!useInactiveObjectLevel) {
101                     event.setActionForwardName(OLEConstants.MAPPING_BASIC);
102                     return false;
103                 }
104             }
105         }
106 
107         return true;
108 
109     }
110 }