View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.coa.businessobject;
20  
21  import java.lang.reflect.InvocationTargetException;
22  import java.util.LinkedHashMap;
23  import java.util.SortedSet;
24  import java.util.TreeSet;
25  
26  import org.apache.commons.beanutils.PropertyUtils;
27  import org.apache.commons.lang.StringUtils;
28  import org.kuali.kfs.coa.service.ObjectCodeService;
29  import org.kuali.kfs.sys.KFSConstants;
30  import org.kuali.kfs.sys.KFSPropertyConstants;
31  import org.kuali.kfs.sys.context.SpringContext;
32  import org.kuali.rice.krad.bo.GlobalBusinessObjectDetailBase;
33  
34  /**
35   * This is a representation of an Organization Reversion Detail, made specifically for Global Organization Reversions. However, as
36   * OrganizationReversionDetail lists Organization as a primary key and Global Organization Reversions deal with several
37   * Organizations, that class could not be re-used for Globals.
38   */
39  public class OrganizationReversionGlobalDetail extends GlobalBusinessObjectDetailBase {
40      protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OrganizationReversionGlobalDetail.class);
41  
42      private String documentNumber;
43      private String organizationReversionCategoryCode;
44      private String organizationReversionObjectCode;
45      private String organizationReversionCode;
46  
47      private OrganizationReversionCategory organizationReversionCategory;
48      private OrganizationReversionGlobal parentGlobalOrganizationReversion;
49      private ObjectCode organizationReversionObject;
50  
51      /**
52       * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper()
53       */
54      
55      protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
56          LinkedHashMap stringMapper = new LinkedHashMap();
57          stringMapper.put(KFSPropertyConstants.DOCUMENT_NUMBER, this.documentNumber);
58          stringMapper.put("OrganizationReversionCategoryCode", this.organizationReversionCategoryCode);
59          return stringMapper;
60      }
61  
62      /**
63       * Constructs an OrganizationReversionGlobalDocumentDetail.
64       */
65      public OrganizationReversionGlobalDetail() {
66      }
67  
68      /**
69       * Gets the documentNumber attribute.
70       * 
71       * @return Returns the documentNumber.
72       */
73      public String getDocumentNumber() {
74          return documentNumber;
75      }
76  
77      /**
78       * Sets the documentNumber attribute value.
79       * 
80       * @param documentNumber The documentNumber to set.
81       */
82      public void setDocumentNumber(String documentNumber) {
83          this.documentNumber = documentNumber;
84      }
85  
86      /**
87       * Gets the organizationReversionCode attribute.
88       * 
89       * @return Returns the organizationReversionCode.
90       */
91      public String getOrganizationReversionCode() {
92          return organizationReversionCode;
93      }
94  
95      /**
96       * Sets the organizationReversionCode attribute value.
97       * 
98       * @param organizationReversionCode The organizationReversionCode to set.
99       */
100     public void setOrganizationReversionCode(String organizationReversionCode) {
101         this.organizationReversionCode = organizationReversionCode;
102     }
103 
104     /**
105      * Gets the organizationReversionCategory attribute.
106      * 
107      * @return Returns the organizationReversionCategory.
108      */
109     public OrganizationReversionCategory getOrganizationReversionCategory() {
110         return organizationReversionCategory;
111     }
112 
113     /**
114      * Sets the organizationReversionCategory attribute value.
115      * 
116      * @param organizationReversionCategory The organizationReversionCategory to set.
117      */
118     public void setOrganizationReversionCategory(OrganizationReversionCategory organizationReversionCategory) {
119         this.organizationReversionCategory = organizationReversionCategory;
120     }
121 
122     /**
123      * Gets the organizationReversionCategoryCode attribute.
124      * 
125      * @return Returns the organizationReversionCategoryCode.
126      */
127     public String getOrganizationReversionCategoryCode() {
128         return organizationReversionCategoryCode;
129     }
130 
131     /**
132      * Sets the organizationReversionCategoryCode attribute value.
133      * 
134      * @param organizationReversionCategoryCode The organizationReversionCategoryCode to set.
135      */
136     public void setOrganizationReversionCategoryCode(String organizationReversionCategoryCode) {
137         this.organizationReversionCategoryCode = organizationReversionCategoryCode;
138     }
139 
140     /**
141      * Gets the organizationReversionObjectCode attribute.
142      * 
143      * @return Returns the organizationReversionObjectCode.
144      */
145     public String getOrganizationReversionObjectCode() {
146         return organizationReversionObjectCode;
147     }
148 
149     /**
150      * Sets the organizationReversionObjectCode attribute value.
151      * 
152      * @param organizationReversionObjectCode The organizationReversionObjectCode to set.
153      */
154     public void setOrganizationReversionObjectCode(String organizationReversionObjectCode) {
155         this.organizationReversionObjectCode = organizationReversionObjectCode;
156     }
157 
158     /**
159      * Gets the parentGlobalOrganizationReversion attribute. This field does not persist, and is populated by
160      * OrganzationReversionChangeMaintainable.
161      * 
162      * @return Returns the parentGlobalOrganizationReversion.
163      */
164     public OrganizationReversionGlobal getParentGlobalOrganizationReversion() {
165         return parentGlobalOrganizationReversion;
166     }
167 
168     /**
169      * Sets the parentGlobalOrganizationReversion attribute value. This field does not persist, and is populated by
170      * OrganizationReversionGlobalMaintainableImpl.
171      * 
172      * @param parentGlobalOrganizationReversion The parentGlobalOrganizationReversion to set.
173      */
174     public void setParentGlobalOrganizationReversion(OrganizationReversionGlobal parentGlobalOrganizationReversion) {
175         this.parentGlobalOrganizationReversion = parentGlobalOrganizationReversion;
176     }
177 
178     /**
179      * Gets the organizationReversionObject attribute. 
180      * @return Returns the organizationReversionObject.
181      */
182     public ObjectCode getOrganizationReversionObject() {
183         return organizationReversionObject;
184     }
185 
186     /**
187      * Sets the organizationReversionObject attribute value.
188      * @param organizationReversionObject The organizationReversionObject to set.
189      */
190     public void setOrganizationReversionObject(ObjectCode organizationReversionObject) {
191         this.organizationReversionObject = organizationReversionObject;
192     }
193 
194     /**
195      * This utility method converts the name of a property into a string suitable for being part of a locking representation.
196      * 
197      * @param keyName the name of the property to convert to a locking representation
198      * @return a part of a locking representation
199      */
200     private String convertKeyToLockingRepresentation(String keyName) {
201         StringBuffer sb = new StringBuffer();
202         sb.append(keyName);
203         sb.append(KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
204         String keyValue = "";
205         try {
206             Object keyValueObj = PropertyUtils.getProperty(this, keyName);
207             if (keyValueObj != null) {
208                 keyValue = keyValueObj.toString();
209             }
210         }
211         catch (IllegalAccessException iae) {
212             LOG.info("Illegal access exception while attempting to read property " + keyName, iae);
213         }
214         catch (InvocationTargetException ite) {
215             LOG.info("Illegal Target Exception while attempting to read property " + keyName, ite);
216         }
217         catch (NoSuchMethodException nsme) {
218             LOG.info("There is no such method to read property " + keyName + " in this class.", nsme);
219         }
220         finally {
221             sb.append(keyValue);
222         }
223         sb.append(KFSConstants.Maintenance.AFTER_VALUE_DELIM);
224         return sb.toString();
225     }
226 
227     /**
228      * This returns a string of object code names associated with the object code in this org rev change detail.
229      * 
230      * @return String of distinct object code names
231      */
232     public String getObjectCodeNames() {
233         String objectCodeNames = "";
234         if (!StringUtils.isBlank(this.getOrganizationReversionObjectCode())) {
235             if (this.getParentGlobalOrganizationReversion().getUniversityFiscalYear() != null && this.getParentGlobalOrganizationReversion().getOrganizationReversionGlobalOrganizations() != null && this.getParentGlobalOrganizationReversion().getOrganizationReversionGlobalOrganizations().size() > 0) {
236                 // find distinct chart of account codes
237                 SortedSet<String> chartCodes = new TreeSet<String>();
238                 for (OrganizationReversionGlobalOrganization org : this.getParentGlobalOrganizationReversion().getOrganizationReversionGlobalOrganizations()) {
239                     chartCodes.add(org.getChartOfAccountsCode());
240                 }
241                 String[] chartCodesArray = new String[chartCodes.size()];
242                 int i = 0;
243                 for (String chartCode : chartCodes) {
244                     chartCodesArray[i] = chartCode;
245                     i++;
246                 }
247                 objectCodeNames = (String) SpringContext.getBean(ObjectCodeService.class).getObjectCodeNamesByCharts(this.getParentGlobalOrganizationReversion().getUniversityFiscalYear(), chartCodesArray, this.getOrganizationReversionObjectCode());
248             }
249         }
250         return objectCodeNames;
251     }
252 }