001/*
002 * Copyright 2007 The Kuali Foundation
003 * 
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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 */
016package org.kuali.ole.coa.businessobject;
017
018import java.lang.reflect.InvocationTargetException;
019import java.util.LinkedHashMap;
020
021import org.apache.commons.beanutils.PropertyUtils;
022import org.kuali.ole.sys.OLEConstants;
023import org.kuali.ole.sys.OLEPropertyConstants;
024import org.kuali.rice.krad.bo.GlobalBusinessObjectDetailBase;
025
026/**
027 * An organization which is related to a Global Organization Reversion Detail.
028 */
029public class OrganizationReversionGlobalOrganization extends GlobalBusinessObjectDetailBase {
030    protected static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OrganizationReversionGlobalOrganization.class);
031    private String documentNumber;
032    private String chartOfAccountsCode;
033    private String organizationCode;
034
035    private Chart chartOfAccounts;
036    private Organization organization;
037
038    /**
039     * @see org.kuali.rice.krad.bo.BusinessObjectBase#toStringMapper()
040     */
041    
042    protected LinkedHashMap toStringMapper_RICE20_REFACTORME() {
043        LinkedHashMap stringMapper = new LinkedHashMap();
044        stringMapper.put(OLEPropertyConstants.DOCUMENT_NUMBER, this.documentNumber);
045        stringMapper.put(OLEPropertyConstants.CHART_OF_ACCOUNTS_CODE, this.chartOfAccountsCode);
046        stringMapper.put(OLEPropertyConstants.ORGANIZATION_CODE, this.organizationCode);
047        return stringMapper;
048    }
049
050    /**
051     * Constructs a OrganizationReversionGlobalOrganization
052     */
053    public OrganizationReversionGlobalOrganization() {
054        super();
055    }
056
057    /**
058     * Gets the documentNumber attribute.
059     * 
060     * @return Returns the documentNumber.
061     */
062    public String getDocumentNumber() {
063        return documentNumber;
064    }
065
066    /**
067     * Sets the documentNumber attribute value.
068     * 
069     * @param documentNumber The documentNumber to set.
070     */
071    public void setDocumentNumber(String documentNumber) {
072        this.documentNumber = documentNumber;
073    }
074
075    /**
076     * Gets the chartOfAccounts attribute.
077     * 
078     * @return Returns the chartOfAccounts.
079     */
080    public Chart getChartOfAccounts() {
081        return chartOfAccounts;
082    }
083
084    /**
085     * Sets the chartOfAccounts attribute value.
086     * 
087     * @param chartOfAccounts The chartOfAccounts to set.
088     * @deprecated
089     */
090    public void setChartOfAccounts(Chart chartOfAccounts) {
091        this.chartOfAccounts = chartOfAccounts;
092    }
093
094    /**
095     * Gets the chartOfAccountsCode attribute.
096     * 
097     * @return Returns the chartOfAccountsCode.
098     */
099    public String getChartOfAccountsCode() {
100        return chartOfAccountsCode;
101    }
102
103    /**
104     * Sets the chartOfAccountsCode attribute value.
105     * 
106     * @param chartOfAccountsCode The chartOfAccountsCode to set.
107     */
108    public void setChartOfAccountsCode(String chartOfAccountsCode) {
109        this.chartOfAccountsCode = chartOfAccountsCode;
110    }
111
112    /**
113     * Gets the organization attribute.
114     * 
115     * @return Returns the organization.
116     */
117    public Organization getOrganization() {
118        return organization;
119    }
120
121    /**
122     * Sets the organization attribute value.
123     * 
124     * @param organization The organization to set.
125     * @deprecated
126     */
127    public void setOrganization(Organization organization) {
128        this.organization = organization;
129    }
130
131    /**
132     * Gets the organizationCode attribute.
133     * 
134     * @return Returns the organizationCode.
135     */
136    public String getOrganizationCode() {
137        return organizationCode;
138    }
139
140    /**
141     * Sets the organizationCode attribute value.
142     * 
143     * @param organizationCode The organizationCode to set.
144     */
145    public void setOrganizationCode(String organizationCode) {
146        this.organizationCode = organizationCode;
147    }
148
149    /**
150     * This utility method converts the name of a property into a string suitable for being part of a locking representation.
151     * 
152     * @param keyName the name of the property to convert to a locking representation
153     * @return a part of a locking representation
154     */
155    private String convertKeyToLockingRepresentation(String keyName) {
156        StringBuffer sb = new StringBuffer();
157        sb.append(keyName);
158        sb.append(OLEConstants.Maintenance.AFTER_FIELDNAME_DELIM);
159        String keyValue = "";
160        try {
161            Object keyValueObj = PropertyUtils.getProperty(this, keyName);
162            if (keyValueObj != null) {
163                keyValue = keyValueObj.toString();
164            }
165        }
166        catch (IllegalAccessException iae) {
167            LOG.info("Illegal access exception while attempting to read property " + keyName, iae);
168        }
169        catch (InvocationTargetException ite) {
170            LOG.info("Illegal Target Exception while attempting to read property " + keyName, ite);
171        }
172        catch (NoSuchMethodException nsme) {
173            LOG.info("There is no such method to read property " + keyName + " in this class.", nsme);
174        }
175        finally {
176            sb.append(keyValue);
177        }
178        sb.append(OLEConstants.Maintenance.AFTER_VALUE_DELIM);
179        return sb.toString();
180    }
181
182    /**
183     * @see java.lang.Object#hashCode()
184     */
185    @Override
186    public int hashCode() {
187        final int PRIME = 31;
188        int result = 1;
189        result = PRIME * result + ((this.getChartOfAccountsCode() == null) ? 0 : this.getChartOfAccountsCode().hashCode());
190        result = PRIME * result + ((this.getDocumentNumber() == null) ? 0 : this.getDocumentNumber().hashCode());
191        result = PRIME * result + ((this.getOrganizationCode() == null) ? 0 : this.getOrganizationCode().hashCode());
192        return result;
193    }
194
195    /**
196     * @see java.lang.Object#equals(java.lang.Object)
197     */
198    @Override
199    public boolean equals(Object obj) {
200        if (this == obj)
201            return true;
202        if (obj == null)
203            return false;
204        if (getClass() != obj.getClass())
205            return false;
206        final OrganizationReversionGlobalOrganization other = (OrganizationReversionGlobalOrganization) obj;
207        if (this.getChartOfAccountsCode() == null) {
208            if (other.getChartOfAccountsCode() != null)
209                return false;
210        }
211        else if (!this.getChartOfAccountsCode().equals(other.getChartOfAccountsCode()))
212            return false;
213        if (this.getDocumentNumber() == null) {
214            if (other.getDocumentNumber() != null)
215                return false;
216        }
217        else if (!this.getDocumentNumber().equals(other.getDocumentNumber()))
218            return false;
219        if (this.getOrganizationCode() == null) {
220            if (other.getOrganizationCode() != null)
221                return false;
222        }
223        else if (!this.getOrganizationCode().equals(other.getOrganizationCode()))
224            return false;
225        return true;
226    }
227
228}