001: /*
002: * Copyright 2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.opensource.org/licenses/ecl1.php
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.kuali.module.chart.bo;
017:
018: import java.lang.reflect.InvocationTargetException;
019: import java.util.LinkedHashMap;
020: import java.util.SortedSet;
021: import java.util.TreeSet;
022:
023: import org.apache.commons.beanutils.PropertyUtils;
024: import org.apache.commons.lang.StringUtils;
025: import org.kuali.core.bo.GlobalBusinessObjectDetailBase;
026: import org.kuali.kfs.KFSConstants;
027: import org.kuali.kfs.KFSPropertyConstants;
028: import org.kuali.kfs.context.SpringContext;
029: import org.kuali.module.chart.service.ObjectCodeService;
030:
031: /**
032: * This is a representation of an Organization Reversion Detail, made specifically for Global Organization Reversions. However, as
033: * OrganizationReversionDetail lists Organization as a primary key and Global Organization Reversions deal with several
034: * Organizations, that class could not be re-used for Globals.
035: */
036: public class OrganizationReversionGlobalDetail extends
037: GlobalBusinessObjectDetailBase {
038: protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
039: .getLogger(OrganizationReversionGlobalDetail.class);
040:
041: private String documentNumber;
042: private String organizationReversionCategoryCode;
043: private String organizationReversionObjectCode;
044: private String organizationReversionCode;
045:
046: private OrganizationReversionCategory organizationReversionCategory;
047: private OrganizationReversionGlobal parentGlobalOrganizationReversion;
048:
049: /**
050: * @see org.kuali.core.bo.BusinessObjectBase#toStringMapper()
051: */
052: @Override
053: protected LinkedHashMap toStringMapper() {
054: LinkedHashMap stringMapper = new LinkedHashMap();
055: stringMapper.put(KFSPropertyConstants.DOCUMENT_NUMBER,
056: this .documentNumber);
057: stringMapper.put("OrganizationReversionCategoryCode",
058: this .organizationReversionCategoryCode);
059: return stringMapper;
060: }
061:
062: /**
063: * Constructs an OrganizationReversionGlobalDocumentDetail.
064: */
065: public OrganizationReversionGlobalDetail() {
066: }
067:
068: /**
069: * Gets the documentNumber attribute.
070: *
071: * @return Returns the documentNumber.
072: */
073: public String getDocumentNumber() {
074: return documentNumber;
075: }
076:
077: /**
078: * Sets the documentNumber attribute value.
079: *
080: * @param documentNumber The documentNumber to set.
081: */
082: public void setDocumentNumber(String documentNumber) {
083: this .documentNumber = documentNumber;
084: }
085:
086: /**
087: * Gets the organizationReversionCode attribute.
088: *
089: * @return Returns the organizationReversionCode.
090: */
091: public String getOrganizationReversionCode() {
092: return organizationReversionCode;
093: }
094:
095: /**
096: * Sets the organizationReversionCode attribute value.
097: *
098: * @param organizationReversionCode The organizationReversionCode to set.
099: */
100: public void setOrganizationReversionCode(
101: String organizationReversionCode) {
102: this .organizationReversionCode = organizationReversionCode;
103: }
104:
105: /**
106: * Gets the organizationReversionCategory attribute.
107: *
108: * @return Returns the organizationReversionCategory.
109: */
110: public OrganizationReversionCategory getOrganizationReversionCategory() {
111: return organizationReversionCategory;
112: }
113:
114: /**
115: * Sets the organizationReversionCategory attribute value.
116: *
117: * @param organizationReversionCategory The organizationReversionCategory to set.
118: */
119: public void setOrganizationReversionCategory(
120: OrganizationReversionCategory organizationReversionCategory) {
121: this .organizationReversionCategory = organizationReversionCategory;
122: }
123:
124: /**
125: * Gets the organizationReversionCategoryCode attribute.
126: *
127: * @return Returns the organizationReversionCategoryCode.
128: */
129: public String getOrganizationReversionCategoryCode() {
130: return organizationReversionCategoryCode;
131: }
132:
133: /**
134: * Sets the organizationReversionCategoryCode attribute value.
135: *
136: * @param organizationReversionCategoryCode The organizationReversionCategoryCode to set.
137: */
138: public void setOrganizationReversionCategoryCode(
139: String organizationReversionCategoryCode) {
140: this .organizationReversionCategoryCode = organizationReversionCategoryCode;
141: }
142:
143: /**
144: * Gets the organizationReversionObjectCode attribute.
145: *
146: * @return Returns the organizationReversionObjectCode.
147: */
148: public String getOrganizationReversionObjectCode() {
149: return organizationReversionObjectCode;
150: }
151:
152: /**
153: * Sets the organizationReversionObjectCode attribute value.
154: *
155: * @param organizationReversionObjectCode The organizationReversionObjectCode to set.
156: */
157: public void setOrganizationReversionObjectCode(
158: String organizationReversionObjectCode) {
159: this .organizationReversionObjectCode = organizationReversionObjectCode;
160: }
161:
162: /**
163: * Gets the parentGlobalOrganizationReversion attribute. This field does not persist, and is populated by
164: * OrganzationReversionChangeMaintainable.
165: *
166: * @return Returns the parentGlobalOrganizationReversion.
167: */
168: public OrganizationReversionGlobal getParentGlobalOrganizationReversion() {
169: return parentGlobalOrganizationReversion;
170: }
171:
172: /**
173: * Sets the parentGlobalOrganizationReversion attribute value. This field does not persist, and is populated by
174: * OrganizationReversionGlobalMaintainableImpl.
175: *
176: * @param parentGlobalOrganizationReversion The parentGlobalOrganizationReversion to set.
177: */
178: public void setParentGlobalOrganizationReversion(
179: OrganizationReversionGlobal parentGlobalOrganizationReversion) {
180: this .parentGlobalOrganizationReversion = parentGlobalOrganizationReversion;
181: }
182:
183: /**
184: * This utility method converts the name of a property into a string suitable for being part of a locking representation.
185: *
186: * @param keyName the name of the property to convert to a locking representation
187: * @return a part of a locking representation
188: */
189: private String convertKeyToLockingRepresentation(String keyName) {
190: StringBuffer sb = new StringBuffer();
191: sb.append(keyName);
192: sb.append(KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
193: String keyValue = "";
194: try {
195: Object keyValueObj = PropertyUtils.getProperty(this ,
196: keyName);
197: if (keyValueObj != null) {
198: keyValue = keyValueObj.toString();
199: }
200: } catch (IllegalAccessException iae) {
201: LOG.info(
202: "Illegal access exception while attempting to read property "
203: + keyName, iae);
204: } catch (InvocationTargetException ite) {
205: LOG.info(
206: "Illegal Target Exception while attempting to read property "
207: + keyName, ite);
208: } catch (NoSuchMethodException nsme) {
209: LOG.info("There is no such method to read property "
210: + keyName + " in this class.", nsme);
211: } finally {
212: sb.append(keyValue);
213: }
214: sb.append(KFSConstants.Maintenance.AFTER_VALUE_DELIM);
215: return sb.toString();
216: }
217:
218: /**
219: * This returns a string of object code names associated with the object code in this org rev change detail.
220: *
221: * @return String of distinct object code names
222: */
223: public String getObjectCodeNames() {
224: String objectCodeNames = "";
225: if (!StringUtils.isBlank(this
226: .getOrganizationReversionObjectCode())) {
227: if (this .getParentGlobalOrganizationReversion()
228: .getUniversityFiscalYear() != null
229: && this
230: .getParentGlobalOrganizationReversion()
231: .getOrganizationReversionGlobalOrganizations() != null
232: && this
233: .getParentGlobalOrganizationReversion()
234: .getOrganizationReversionGlobalOrganizations()
235: .size() > 0) {
236: // find distinct chart of account codes
237: SortedSet<String> chartCodes = new TreeSet<String>();
238: for (OrganizationReversionGlobalOrganization org : this
239: .getParentGlobalOrganizationReversion()
240: .getOrganizationReversionGlobalOrganizations()) {
241: chartCodes.add(org.getChartOfAccountsCode());
242: }
243: String[] chartCodesArray = new String[chartCodes.size()];
244: int i = 0;
245: for (String chartCode : chartCodes) {
246: chartCodesArray[i] = chartCode;
247: i++;
248: }
249: objectCodeNames = (String) SpringContext
250: .getBean(ObjectCodeService.class)
251: .getObjectCodeNamesByCharts(
252: this
253: .getParentGlobalOrganizationReversion()
254: .getUniversityFiscalYear(),
255: chartCodesArray,
256: this
257: .getOrganizationReversionObjectCode());
258: }
259: }
260: return objectCodeNames;
261: }
262: }
|