View Javadoc
1   /*
2    * Copyright 2005 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.fp.document;
17  
18  import static org.kuali.ole.sys.OLEConstants.FROM;
19  import static org.kuali.ole.sys.OLEConstants.TO;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.ole.fp.businessobject.GECSourceAccountingLine;
23  import org.kuali.ole.fp.businessobject.GECTargetAccountingLine;
24  import org.kuali.ole.integration.cam.CapitalAssetManagementModuleService;
25  import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntry;
26  import org.kuali.ole.sys.businessobject.GeneralLedgerPendingEntrySourceDetail;
27  import org.kuali.ole.sys.context.SpringContext;
28  import org.kuali.ole.sys.document.AmountTotaling;
29  import org.kuali.ole.sys.document.Correctable;
30  import org.kuali.ole.sys.document.validation.impl.AccountingDocumentRuleBaseConstants.GENERAL_LEDGER_PENDING_ENTRY_CODE;
31  import org.kuali.rice.kew.framework.postprocessor.DocumentRouteStatusChange;
32  import org.kuali.rice.kns.service.DataDictionaryService;
33  import org.kuali.rice.krad.document.Copyable;
34  import org.kuali.rice.krad.rules.rule.event.KualiDocumentEvent;
35  import org.kuali.rice.krad.rules.rule.event.SaveDocumentEvent;
36  
37  
38  /**
39   * This is the business object that represents the GeneralErrorCorrectionDocument in Kuali. This is a transactional document that
40   * will eventually post transactions to the G/L. It integrates with workflow and also contains two groupings of accounting lines:
41   * from and to. From lines are the source lines, to lines are the target lines.
42   */
43  public class GeneralErrorCorrectionDocument extends CapitalAccountingLinesDocumentBase implements Copyable, Correctable, AmountTotaling, CapitalAssetEditable {
44      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(GeneralErrorCorrectionDocument.class);
45  
46      protected transient CapitalAssetManagementModuleService capitalAssetManagementModuleService;
47  
48      /**
49       * Initializes the array lists and some basic info.
50       */
51      public GeneralErrorCorrectionDocument() {
52          super();
53      }
54  
55      /**
56       * Overrides the base implementation to return "From".
57       * 
58       * @see org.kuali.ole.sys.document.AccountingDocument#getSourceAccountingLinesSectionTitle()
59       */
60      @Override
61      public String getSourceAccountingLinesSectionTitle() {
62          return FROM;
63      }
64  
65      /**
66       * Overrides the base implementation to return "To".
67       * 
68       * @see org.kuali.ole.sys.document.AccountingDocument#getTargetAccountingLinesSectionTitle()
69       */
70      @Override
71      public String getTargetAccountingLinesSectionTitle() {
72          return TO;
73      }
74  
75      /**
76       * @see org.kuali.ole.sys.document.AccountingDocumentBase#getSourceAccountingLineClass()
77       */
78      @Override
79      public Class getSourceAccountingLineClass() {
80          return GECSourceAccountingLine.class;
81      }
82  
83      /**
84       * @see org.kuali.ole.sys.document.AccountingDocumentBase#getTargetAccountingLineClass()
85       */
86      @Override
87      public Class getTargetAccountingLineClass() {
88          return GECTargetAccountingLine.class;
89      }
90  
91      /**
92       * Customizes a GLPE by setting financial document number, financial system origination code and document type code to null
93       * 
94       * @param transactionalDocument submitted accounting document
95       * @param accountingLine accounting line in document
96       * @param explicitEntry general ledger pending entry
97       * @see FinancialDocumentRuleBase#customizeExplicitGeneralLedgerPendingEntry(FinancialDocument, AccountingLine,
98       *      GeneralLedgerPendingEntry)
99       */
100     @Override
101     public void customizeExplicitGeneralLedgerPendingEntry(GeneralLedgerPendingEntrySourceDetail postable, GeneralLedgerPendingEntry explicitEntry) {
102         explicitEntry.setTransactionLedgerEntryDescription(buildTransactionLedgerEntryDescriptionUsingRefOriginAndRefDocNumber(postable));
103 
104         // Clearing fields that are already handled by the parent algorithm - we don't actually want
105         // these to copy over from the accounting lines b/c they don't belong in the GLPEs
106         // if the aren't nulled, then GECs fail to post
107         explicitEntry.setReferenceFinancialDocumentNumber(null);
108         explicitEntry.setReferenceFinancialSystemOriginationCode(null);
109         explicitEntry.setReferenceFinancialDocumentTypeCode(null);
110     }
111 
112     /**
113      * Builds an appropriately formatted string to be used for the <code>transactionLedgerEntryDescription</code>. It is built
114      * using information from the <code>{@link AccountingLine}</code>. Format is "01-12345: blah blah blah".
115      * 
116      * @param line accounting line
117      * @param transactionalDocument submitted accounting document
118      * @return String formatted string to be used for transaction ledger entry description
119      */
120     protected String buildTransactionLedgerEntryDescriptionUsingRefOriginAndRefDocNumber(GeneralLedgerPendingEntrySourceDetail line) {
121         String description = "";
122         description = line.getReferenceOriginCode() + "-" + line.getReferenceNumber();
123 
124         if (StringUtils.isNotBlank(line.getFinancialDocumentLineDescription())) {
125             description += ": " + line.getFinancialDocumentLineDescription();
126         }
127         else {
128             description += ": " + getDocumentHeader().getDocumentDescription();
129         }
130 
131         if (description.length() > GENERAL_LEDGER_PENDING_ENTRY_CODE.GLPE_DESCRIPTION_MAX_LENGTH) {
132             description = description.substring(0, GENERAL_LEDGER_PENDING_ENTRY_CODE.GLPE_DESCRIPTION_MAX_LENGTH - 3) + "...";
133         }
134 
135         return description;
136     }
137 
138     /**
139      * @see org.kuali.ole.sys.document.GeneralLedgerPostingDocumentBase#doRouteStatusChange()
140      */
141     @Override
142     public void doRouteStatusChange(DocumentRouteStatusChange statusChangeEvent) {
143         super.doRouteStatusChange(statusChangeEvent);
144         this.getCapitalAssetManagementModuleService().deleteDocumentAssetLocks(this);
145     }
146 
147 
148     /**
149      * @see org.kuali.rice.krad.document.DocumentBase#postProcessSave(org.kuali.rice.krad.rule.event.KualiDocumentEvent)
150      */
151     @Override
152     public void postProcessSave(KualiDocumentEvent event) {
153         super.postProcessSave(event);
154         if (!(event instanceof SaveDocumentEvent)) { // don't lock until they route
155             String documentTypeName = SpringContext.getBean(DataDictionaryService.class).getDocumentTypeNameByClass(this.getClass());
156             this.getCapitalAssetManagementModuleService().generateCapitalAssetLock(this, documentTypeName);
157         }
158     }
159 
160     /**
161      * @return CapitalAssetManagementModuleService
162      */
163     public CapitalAssetManagementModuleService getCapitalAssetManagementModuleService() {
164         if (capitalAssetManagementModuleService == null) {
165             capitalAssetManagementModuleService = SpringContext.getBean(CapitalAssetManagementModuleService.class);
166         }
167         return capitalAssetManagementModuleService;
168     }
169 }