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