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  
17  package org.kuali.ole.coa.businessobject;
18  
19  import java.util.ArrayList;
20  import java.util.Collection;
21  import java.util.HashMap;
22  import java.util.LinkedHashMap;
23  import java.util.List;
24  import java.util.Map;
25  
26  import org.kuali.ole.sys.OLEPropertyConstants;
27  import org.kuali.ole.sys.businessobject.SystemOptions;
28  import org.kuali.ole.sys.context.SpringContext;
29  import org.kuali.rice.core.api.mo.common.active.MutableInactivatable;
30  import org.kuali.rice.krad.bo.DocumentHeader;
31  import org.kuali.rice.krad.bo.GlobalBusinessObject;
32  import org.kuali.rice.krad.bo.GlobalBusinessObjectDetail;
33  import org.kuali.rice.krad.bo.PersistableBusinessObject;
34  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
35  import org.kuali.rice.krad.service.BusinessObjectService;
36  
37  /**
38   * 
39   */
40  public class SubObjectCodeGlobal extends PersistableBusinessObjectBase implements GlobalBusinessObject, MutableInactivatable {
41  
42      private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(SubObjectCodeGlobal.class);
43  
44      protected String documentNumber;
45      protected Integer universityFiscalYear;
46      protected String chartOfAccountsCode;
47      protected String financialSubObjectCode;
48      protected String financialSubObjectCodeName;
49      protected String financialSubObjectCodeShortName;
50      protected boolean active;
51  
52      protected DocumentHeader financialDocument;
53      protected SystemOptions universityFiscal;
54      protected Chart chartOfAccounts;
55  
56      protected List<SubObjectCodeGlobalDetail> subObjCdGlobalDetails;
57      protected List<AccountGlobalDetail> accountGlobalDetails;
58  
59      /**
60       * Default constructor.
61       */
62      public SubObjectCodeGlobal() {
63  
64  
65          subObjCdGlobalDetails = new ArrayList<SubObjectCodeGlobalDetail>();
66          accountGlobalDetails = new ArrayList<AccountGlobalDetail>();
67  
68      }
69  
70      /**
71       * Gets the documentNumber attribute.
72       * 
73       * @return Returns the documentNumber
74       */
75      public String getDocumentNumber() {
76          return documentNumber;
77      }
78  
79      /**
80       * Sets the documentNumber attribute.
81       * 
82       * @param documentNumber The documentNumber to set.
83       */
84      public void setDocumentNumber(String documentNumber) {
85          this.documentNumber = documentNumber;
86      }
87  
88  
89      /**
90       * Gets the universityFiscalYear attribute.
91       * 
92       * @return Returns the universityFiscalYear
93       */
94      public Integer getUniversityFiscalYear() {
95          return universityFiscalYear;
96      }
97  
98      /**
99       * Sets the universityFiscalYear attribute.
100      * 
101      * @param universityFiscalYear The universityFiscalYear to set.
102      */
103     public void setUniversityFiscalYear(Integer universityFiscalYear) {
104         this.universityFiscalYear = universityFiscalYear;
105     }
106 
107 
108     /**
109      * Gets the chartOfAccountsCode attribute.
110      * 
111      * @return Returns the chartOfAccountsCode
112      */
113     public String getChartOfAccountsCode() {
114         return chartOfAccountsCode;
115     }
116 
117     /**
118      * Sets the chartOfAccountsCode attribute.
119      * 
120      * @param chartOfAccountsCode The chartOfAccountsCode to set.
121      */
122     public void setChartOfAccountsCode(String chartOfAccountsCode) {
123         this.chartOfAccountsCode = chartOfAccountsCode;
124     }
125 
126 
127     /**
128      * Gets the financialSubObjectCode attribute.
129      * 
130      * @return Returns the financialSubObjectCode
131      */
132     public String getFinancialSubObjectCode() {
133         return financialSubObjectCode;
134     }
135 
136     /**
137      * Sets the financialSubObjectCode attribute.
138      * 
139      * @param financialSubObjectCode The financialSubObjectCode to set.
140      */
141     public void setFinancialSubObjectCode(String financialSubObjectCode) {
142         this.financialSubObjectCode = financialSubObjectCode;
143     }
144 
145 
146     /**
147      * Gets the financialSubObjectCodeName attribute.
148      * 
149      * @return Returns the financialSubObjectCodeName
150      */
151     public String getFinancialSubObjectCodeName() {
152         return financialSubObjectCodeName;
153     }
154 
155     /**
156      * Sets the financialSubObjectCodeName attribute.
157      * 
158      * @param financialSubObjectCodeName The financialSubObjectCodeName to set.
159      */
160     public void setFinancialSubObjectCodeName(String financialSubObjectCodeName) {
161         this.financialSubObjectCodeName = financialSubObjectCodeName;
162     }
163 
164 
165     /**
166      * Gets the financialSubObjectCodeShortName attribute.
167      * 
168      * @return Returns the financialSubObjectCodeShortName
169      */
170     public String getFinancialSubObjectCodeShortName() {
171         return financialSubObjectCodeShortName;
172     }
173 
174     /**
175      * Sets the financialSubObjectCodeShortName attribute.
176      * 
177      * @param financialSubObjectCodeShortName The financialSubObjectCodeShortName to set.
178      */
179     public void setFinancialSubObjectCodeShortName(String financialSubObjectCdshortNm) {
180         this.financialSubObjectCodeShortName = financialSubObjectCdshortNm;
181     }
182 
183 
184     /**
185      * Gets the active attribute.
186      * 
187      * @return Returns the active
188      */
189     public boolean isActive() {
190         return active;
191     }
192 
193 
194     /**
195      * Sets the active attribute.
196      * 
197      * @param active The active to set.
198      */
199     public void setActive(boolean active) {
200         this.active = active;
201     }
202 
203 
204     /**
205      * Gets the financialDocument attribute.
206      * 
207      * @return Returns the financialDocument
208      */
209     public DocumentHeader getFinancialDocument() {
210         return financialDocument;
211     }
212 
213     /**
214      * Sets the financialDocument attribute.
215      * 
216      * @param financialDocument The financialDocument to set.
217      * @deprecated
218      */
219     public void setFinancialDocument(DocumentHeader financialDocument) {
220         this.financialDocument = financialDocument;
221     }
222 
223     /**
224      * Gets the universityFiscal attribute.
225      * 
226      * @return Returns the universityFiscal
227      */
228     public SystemOptions getUniversityFiscal() {
229         return universityFiscal;
230     }
231 
232     /**
233      * Sets the universityFiscal attribute.
234      * 
235      * @param universityFiscal The universityFiscal to set.
236      * @deprecated
237      */
238     public void setUniversityFiscal(SystemOptions universityFiscal) {
239         this.universityFiscal = universityFiscal;
240     }
241 
242     /**
243      * Gets the chartOfAccounts attribute.
244      * 
245      * @return Returns the chartOfAccounts
246      */
247     public Chart getChartOfAccounts() {
248         return chartOfAccounts;
249     }
250 
251     /**
252      * Sets the chartOfAccounts attribute.
253      * 
254      * @param chartOfAccounts The chartOfAccounts to set.
255      * @deprecated
256      */
257     public void setChartOfAccounts(Chart chartOfAccounts) {
258         this.chartOfAccounts = chartOfAccounts;
259     }
260 
261     /**
262      * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper()
263      */
264     protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
265         LinkedHashMap m = new LinkedHashMap();
266         m.put(OLEPropertyConstants.DOCUMENT_NUMBER, this.documentNumber);
267         return m;
268     }
269 
270     public List<SubObjectCodeGlobalDetail> getSubObjCdGlobalDetails() {
271         return subObjCdGlobalDetails;
272     }
273 
274     public void setSubObjCdGlobalDetails(List<SubObjectCodeGlobalDetail> subObjCdGlobalDetails) {
275         this.subObjCdGlobalDetails = subObjCdGlobalDetails;
276     }
277 
278     public List<AccountGlobalDetail> getAccountGlobalDetails() {
279         return accountGlobalDetails;
280     }
281 
282     public void setAccountGlobalDetails(List<AccountGlobalDetail> accountGlobalDetails) {
283         this.accountGlobalDetails = accountGlobalDetails;
284     }
285 
286     /**
287      * @see org.kuali.rice.krad.document.GlobalBusinessObject#getGlobalChangesToDelete()
288      */
289     public List<PersistableBusinessObject> generateDeactivationsToPersist() {
290         return null;
291     }
292 
293     /**
294      * This returns a list of Sub Object Codes to Update and/or Add
295      * 
296      * @see org.kuali.rice.krad.document.GlobalBusinessObject#applyGlobalChanges()
297      */
298     public List<PersistableBusinessObject> generateGlobalChangesToPersist() {
299         LOG.debug("applyGlobalChanges");
300         List result = new ArrayList();
301 
302         // Iterate through Account/Object Code combinations; create new or update as necessary
303 
304         for (SubObjectCodeGlobalDetail subObjCdGlobalDetail : subObjCdGlobalDetails) {
305 
306             String financialObjectCode = subObjCdGlobalDetail.getFinancialObjectCode();
307 
308             if (financialObjectCode != null && financialObjectCode.length() > 0) {
309 
310                 for (AccountGlobalDetail accountGlobalDetail : accountGlobalDetails) {
311 
312                     Map pk = new HashMap();
313 
314                     String accountNumber = accountGlobalDetail.getAccountNumber();
315 
316                     if (accountNumber != null && accountNumber.length() > 0) {
317                         pk.put("UNIV_FISCAL_YR", this.universityFiscalYear);
318                         pk.put("FIN_COA_CD", this.chartOfAccountsCode);
319                         pk.put("ACCOUNT_NBR", accountNumber);
320                         pk.put("FIN_OBJECT_CD", financialObjectCode);
321                         pk.put("FIN_SUB_OBJ_CD", this.financialSubObjectCode);
322 
323                         SubObjectCode subObjCd = (SubObjectCode) SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(SubObjectCode.class, pk);
324                         if (subObjCd == null) {
325                             subObjCd = new SubObjectCode(this.universityFiscalYear, this.chartOfAccountsCode, accountNumber, financialObjectCode, this.financialSubObjectCode);
326                         }
327                         populate(subObjCd, accountGlobalDetail, subObjCdGlobalDetail);
328                         result.add(subObjCd);
329                     }
330                 }
331             }
332         }
333 
334         return result;
335     }
336 
337     public void populate(SubObjectCode old, AccountGlobalDetail accountGlobalDetail, SubObjectCodeGlobalDetail subObjCdGlobalDetail) {
338         old.setFinancialSubObjectCodeName(update(old.getFinancialSubObjectCodeName(), financialSubObjectCodeName));
339         old.setFinancialSubObjectCdshortNm(update(old.getFinancialSubObjectCdshortNm(), financialSubObjectCodeShortName));
340         old.setActive(update(old.isActive(), active));
341     }
342 
343 
344     /**
345      * This method returns newvalue iff it is not empty
346      * 
347      * @param oldValue
348      * @param newValue
349      * @return
350      */
351     protected String update(String oldValue, String newValue) {
352         if (newValue == null || newValue.length() == 0) {
353             return oldValue;
354         }
355         return newValue;
356     }
357 
358     protected boolean update(boolean oldValue, boolean newValue) {
359         return newValue;
360     }
361 
362 
363     public boolean isPersistable() {
364         return true;
365     }
366 
367     public List<? extends GlobalBusinessObjectDetail> getAllDetailObjects() {
368         ArrayList<GlobalBusinessObjectDetail> details = new ArrayList<GlobalBusinessObjectDetail>(accountGlobalDetails.size() + subObjCdGlobalDetails.size());
369         details.addAll(accountGlobalDetails);
370         details.addAll(subObjCdGlobalDetails);
371         return details;
372     }
373 
374     /**
375      * @see org.kuali.rice.krad.bo.PersistableBusinessObjectBase#buildListOfDeletionAwareLists()
376      */
377     @Override
378     public List buildListOfDeletionAwareLists() {
379         List<Collection<PersistableBusinessObject>> managedLists = super.buildListOfDeletionAwareLists();
380 
381         managedLists.add( new ArrayList<PersistableBusinessObject>( getAccountGlobalDetails() ) );
382         managedLists.add( new ArrayList<PersistableBusinessObject>( getSubObjCdGlobalDetails() ) );
383 
384         return managedLists;
385     }
386 }