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.gl.util;
017:
018: import java.util.HashSet;
019: import java.util.Iterator;
020: import java.util.Set;
021:
022: import org.apache.commons.lang.StringUtils;
023: import org.kuali.module.gl.bo.CollectorDetail;
024: import org.kuali.module.gl.bo.OriginEntryFull;
025: import org.kuali.module.gl.bo.Transaction;
026:
027: /**
028: * This class represents document group-related data
029: */
030: public class DocumentGroupData {
031: protected String documentNumber;
032: protected String financialDocumentTypeCode;
033: protected String financialSystemOriginationCode;
034:
035: public DocumentGroupData(Transaction entry) {
036: documentNumber = entry.getDocumentNumber();
037: financialDocumentTypeCode = entry
038: .getFinancialDocumentTypeCode();
039: financialSystemOriginationCode = entry
040: .getFinancialSystemOriginationCode();
041: }
042:
043: public DocumentGroupData(String documentNumber,
044: String financialDocumentTypeCode,
045: String financialSystemOriginationCode) {
046: this .documentNumber = documentNumber;
047: this .financialDocumentTypeCode = financialDocumentTypeCode;
048: this .financialSystemOriginationCode = financialSystemOriginationCode;
049: }
050:
051: /**
052: * Returns true if DocumentGroupData objects have the same document number, document type code, and financial system origination code
053: *
054: * @see java.lang.Object#equals(java.lang.Object)
055: */
056: @Override
057: public boolean equals(Object obj) {
058: if (obj == null || !(obj instanceof DocumentGroupData)) {
059: return false;
060: }
061: DocumentGroupData o2 = (DocumentGroupData) obj;
062: return StringUtils.equals(documentNumber, o2.documentNumber)
063: && StringUtils.equals(financialDocumentTypeCode,
064: o2.financialDocumentTypeCode)
065: && StringUtils.equals(financialSystemOriginationCode,
066: o2.financialSystemOriginationCode);
067: }
068:
069: /**
070: * Returns true if this document group data object's and the transaction have the same document number, document type code, and origination code match the passed
071: *
072: * @param transaction transaction to compare
073: * @return true if this document group data object's and the transaction have the same document number, document type code, and origination code match the passed
074: */
075: public boolean matchesTransaction(Transaction transaction) {
076: return StringUtils.equals(documentNumber, transaction
077: .getDocumentNumber())
078: && StringUtils.equals(financialDocumentTypeCode,
079: transaction.getFinancialDocumentTypeCode())
080: && StringUtils
081: .equals(
082: financialSystemOriginationCode,
083: transaction
084: .getFinancialSystemOriginationCode());
085: }
086:
087: public boolean matchesCollectorDetail(CollectorDetail detail) {
088: return StringUtils.equals(documentNumber, detail
089: .getDocumentNumber())
090: && StringUtils.equals(financialDocumentTypeCode, detail
091: .getFinancialDocumentTypeCode())
092: && StringUtils.equals(financialSystemOriginationCode,
093: detail.getFinancialSystemOriginationCode());
094: }
095:
096: /**
097: *
098: * @see java.lang.Object#hashCode()
099: */
100: @Override
101: public int hashCode() {
102: // hash based on the doc #, because it's likely to have the most variation within an origin entry doc
103: if (documentNumber == null) {
104: return "".hashCode();
105: }
106: return documentNumber.hashCode();
107: }
108:
109: /**
110: * This returns an origin entry with document number, document type code, origination code set from this DocumentGroupData's document number, document type code, and origination code
111: *
112: * @return populated origin entry
113: */
114: public OriginEntryFull populateDocumentGroupDataFieldsInOriginEntry() {
115: OriginEntryFull entry = new OriginEntryFull();
116: entry.setDocumentNumber(documentNumber);
117: entry.setFinancialDocumentTypeCode(financialDocumentTypeCode);
118: entry
119: .setFinancialSystemOriginationCode(financialSystemOriginationCode);
120: return entry;
121: }
122:
123: /**
124: * Gets the documentNumber attribute.
125: *
126: * @return Returns the documentNumber.
127: */
128: public String getDocumentNumber() {
129: return documentNumber;
130: }
131:
132: /**
133: * Sets the documentNumber attribute value.
134: *
135: * @param documentNumber The documentNumber to set.
136: */
137: public void setDocumentNumber(String documentNumber) {
138: this .documentNumber = documentNumber;
139: }
140:
141: /**
142: * Gets the financialDocumentTypeCode attribute.
143: *
144: * @return Returns the financialDocumentTypeCode.
145: */
146: public String getFinancialDocumentTypeCode() {
147: return financialDocumentTypeCode;
148: }
149:
150: /**
151: * Sets the financialDocumentTypeCode attribute value.
152: *
153: * @param financialDocumentTypeCode The financialDocumentTypeCode to set.
154: */
155: public void setFinancialDocumentTypeCode(
156: String financialDocumentTypeCode) {
157: this .financialDocumentTypeCode = financialDocumentTypeCode;
158: }
159:
160: /**
161: * Gets the financialSystemOriginationCode attribute.
162: *
163: * @return Returns the financialSystemOriginationCode.
164: */
165: public String getFinancialSystemOriginationCode() {
166: return financialSystemOriginationCode;
167: }
168:
169: /**
170: * Sets the financialSystemOriginationCode attribute value.
171: *
172: * @param financialSystemOriginationCode The financialSystemOriginationCode to set.
173: */
174: public void setFinancialSystemOriginationCode(
175: String financialSystemOriginationCode) {
176: this .financialSystemOriginationCode = financialSystemOriginationCode;
177: }
178:
179: /**
180: * Given an iterator of {@link Transaction} objects, return a set of all the document groups (doc #, doc type, origination code)
181: * for these transactions
182: *
183: * @param transactions iterator of transactions
184: * @return Set of all of the document groups for this these trasnactions
185: */
186: public static <E extends Transaction> Set<DocumentGroupData> getDocumentGroupDatasForTransactions(
187: Iterator<E> transactions) {
188: Set<DocumentGroupData> documentGroupDatas = new HashSet<DocumentGroupData>();
189: while (transactions.hasNext()) {
190: Transaction transaction = transactions.next();
191: documentGroupDatas.add(new DocumentGroupData(transaction));
192: }
193: return documentGroupDatas;
194: }
195: }
|