001: /*
002: * Copyright 2006-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:
017: package org.kuali.module.gl.bo;
018:
019: import java.util.ArrayList;
020: import java.util.Collections;
021: import java.util.Iterator;
022: import java.util.LinkedHashMap;
023: import java.util.List;
024:
025: import org.kuali.core.bo.PersistableBusinessObjectBase;
026: import org.kuali.kfs.KFSPropertyConstants;
027:
028: /**
029: * This class represents a GLCP correction change group
030: */
031: public class CorrectionChangeGroup extends
032: PersistableBusinessObjectBase implements Comparable {
033: private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger
034: .getLogger(CorrectionChangeGroup.class);
035:
036: private String documentNumber;
037: private Integer correctionChangeGroupLineNumber;
038: private Integer correctionCriteriaNextLineNumber;
039: private Integer correctionChangeNextLineNumber;
040: private List<CorrectionCriteria> correctionCriteria;
041: private List<CorrectionChange> correctionChange;
042:
043: public CorrectionChangeGroup(String documentNumber,
044: Integer correctionChangeGroupLineNumber) {
045: setCorrectionChangeGroupLineNumber(correctionChangeGroupLineNumber);
046:
047: correctionCriteria = new ArrayList();
048: correctionChange = new ArrayList();
049: correctionCriteriaNextLineNumber = new Integer(0);
050: correctionChangeNextLineNumber = new Integer(0);
051:
052: setDocumentNumber(documentNumber);
053: }
054:
055: public CorrectionChangeGroup() {
056: super ();
057: correctionCriteria = new ArrayList();
058: correctionChange = new ArrayList();
059: correctionCriteriaNextLineNumber = new Integer(0);
060: correctionChangeNextLineNumber = new Integer(0);
061: }
062:
063: /**
064: * Add correction change to this correction change group
065: *
066: * @param cc correction change to add
067: */
068: public void addCorrectionChange(CorrectionChange cc) {
069: LOG.debug("addCorrectionChange() started");
070:
071: cc.setDocumentNumber(documentNumber);
072: cc
073: .setCorrectionChangeGroupLineNumber(correctionChangeGroupLineNumber);
074: cc
075: .setCorrectionChangeLineNumber(correctionChangeNextLineNumber++);
076: correctionChange.add(cc);
077: }
078:
079: /**
080: * Add correction criteria to this correction change group
081: *
082: * @param cc correction criteria to add to this correction change group
083: */
084: public void addCorrectionCriteria(CorrectionCriteria cc) {
085: cc.setDocumentNumber(documentNumber);
086: cc
087: .setCorrectionChangeGroupLineNumber(correctionChangeGroupLineNumber);
088: cc
089: .setCorrectionCriteriaLineNumber(correctionCriteriaNextLineNumber++);
090: correctionCriteria.add(cc);
091: }
092:
093: /**
094: * Remove correction change item
095: *
096: * @param changeNumber correction change line number used to determine which correction change item to remove
097: */
098: public void removeCorrectionChangeItem(int changeNumber) {
099: for (Iterator iter = correctionChange.iterator(); iter
100: .hasNext();) {
101: CorrectionChange element = (CorrectionChange) iter.next();
102: if (changeNumber == element.getCorrectionChangeLineNumber()
103: .intValue()) {
104: iter.remove();
105: }
106: }
107: }
108:
109: /**
110: * Remove correction criteria item
111: *
112: * @param criteriaNumber correction criteria line number used to determine which correction change to remove
113: */
114: public void removeCorrectionCriteriaItem(int criteriaNumber) {
115: for (Iterator iter = correctionCriteria.iterator(); iter
116: .hasNext();) {
117: CorrectionCriteria element = (CorrectionCriteria) iter
118: .next();
119: if (criteriaNumber == element
120: .getCorrectionCriteriaLineNumber().intValue()) {
121: iter.remove();
122: }
123: }
124: }
125:
126: /**
127: * Get correction change item
128: *
129: * @param changeNumber correction change line number of object to return
130: * @return CorrectionChange correction change object with specified line number to return
131: */
132: public CorrectionChange getCorrectionChangeItem(int changeNumber) {
133: for (Iterator iter = correctionChange.iterator(); iter
134: .hasNext();) {
135: CorrectionChange element = (CorrectionChange) iter.next();
136: if (changeNumber == element.getCorrectionChangeLineNumber()
137: .intValue()) {
138: return element;
139: }
140: }
141:
142: CorrectionChange cc = new CorrectionChange(getDocumentNumber(),
143: correctionChangeGroupLineNumber, changeNumber);
144: correctionChange.add(cc);
145:
146: return cc;
147: }
148:
149: /**
150: * Get correction criteria item
151: *
152: * @param criteriaNumber correction change line number of object to return
153: * @return CorrectionChange correction change object with specified line number to return
154: */
155: public CorrectionCriteria getCorrectionCriteriaItem(
156: int criteriaNumber) {
157: for (Iterator iter = correctionCriteria.iterator(); iter
158: .hasNext();) {
159: CorrectionCriteria element = (CorrectionCriteria) iter
160: .next();
161: if (criteriaNumber == element
162: .getCorrectionCriteriaLineNumber().intValue()) {
163: return element;
164: }
165: }
166:
167: CorrectionCriteria cc = new CorrectionCriteria(
168: getDocumentNumber(), correctionChangeGroupLineNumber,
169: criteriaNumber);
170: correctionCriteria.add(cc);
171: return cc;
172: }
173:
174: public String getDocumentNumber() {
175: return documentNumber;
176: }
177:
178: /**
179: * Set document number for this correction change group. This also sets the document number for this correction change group's
180: * correction criteria and correction change
181: *
182: * @param documentNumber new document number
183: */
184: public void setDocumentNumber(String documentNumber) {
185: this .documentNumber = documentNumber;
186:
187: for (Iterator iter = correctionCriteria.iterator(); iter
188: .hasNext();) {
189: CorrectionCriteria element = (CorrectionCriteria) iter
190: .next();
191: element.setDocumentNumber(documentNumber);
192: }
193: for (Iterator iter = correctionChange.iterator(); iter
194: .hasNext();) {
195: CorrectionChange element = (CorrectionChange) iter.next();
196: element.setDocumentNumber(documentNumber);
197: }
198: }
199:
200: public Integer getCorrectionChangeGroupLineNumber() {
201: return correctionChangeGroupLineNumber;
202: }
203:
204: public void setCorrectionChangeGroupLineNumber(
205: Integer correctionChangeGroupLineNumber) {
206: this .correctionChangeGroupLineNumber = correctionChangeGroupLineNumber;
207: }
208:
209: public Integer getCorrectionCriteriaNextLineNumber() {
210: return correctionCriteriaNextLineNumber;
211: }
212:
213: public void setCorrectionCriteriaNextLineNumber(
214: Integer correctionCriteriaNextLineNumber) {
215: this .correctionCriteriaNextLineNumber = correctionCriteriaNextLineNumber;
216: }
217:
218: public Integer getCorrectionChangeNextLineNumber() {
219: return correctionChangeNextLineNumber;
220: }
221:
222: public void setCorrectionChangeNextLineNumber(
223: Integer correctionChangeNextLineNumber) {
224: this .correctionChangeNextLineNumber = correctionChangeNextLineNumber;
225: }
226:
227: public List<CorrectionCriteria> getCorrectionCriteria() {
228: Collections.sort(correctionCriteria);
229: return correctionCriteria;
230: }
231:
232: public void setCorrectionCriteria(
233: List<CorrectionCriteria> correctionCriteria) {
234: this .correctionCriteria = correctionCriteria;
235: }
236:
237: public List<CorrectionChange> getCorrectionChange() {
238: Collections.sort(correctionChange);
239: return correctionChange;
240: }
241:
242: public void setCorrectionChange(
243: List<CorrectionChange> correctionChange) {
244: this .correctionChange = correctionChange;
245: }
246:
247: /**
248: * Compares this correction change group to another correction change group object by comparing document number and correction group line number
249: *
250: * @see java.lang.Comparable#compareTo(java.lang.Object)
251: */
252: public int compareTo(Object o) {
253: CorrectionChangeGroup other = (CorrectionChangeGroup) o;
254:
255: String this FdocNbr = documentNumber == null ? ""
256: : documentNumber;
257: String thatFdocNbr = other.documentNumber == null ? ""
258: : other.documentNumber;
259:
260: int c = this FdocNbr.compareTo(thatFdocNbr);
261: if (c == 0) {
262: Integer this Nbr = correctionChangeGroupLineNumber == null ? 0
263: : correctionChangeGroupLineNumber;
264: Integer thatNbr = other.correctionChangeGroupLineNumber == null ? 0
265: : other.correctionChangeGroupLineNumber;
266: return this Nbr.compareTo(thatNbr);
267: } else {
268: return c;
269: }
270: }
271:
272: /**
273: * @see org.kuali.core.bo.BusinessObjectBase#toStringMapper()
274: */
275: protected LinkedHashMap toStringMapper() {
276: LinkedHashMap m = new LinkedHashMap();
277: m
278: .put(KFSPropertyConstants.DOCUMENT_NUMBER,
279: this .documentNumber);
280: if (this .correctionChangeGroupLineNumber != null) {
281: m.put("correctionChangeGroupLineNumber",
282: this.correctionChangeGroupLineNumber.toString());
283: }
284: return m;
285: }
286: }
|