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: package org.kuali.module.gl.util;
017:
018: import java.util.ArrayList;
019: import java.util.List;
020:
021: import org.kuali.kfs.KFSConstants;
022:
023: /**
024: * This class represents a summary amount used in reporst
025: */
026: public class Summary implements Comparable {
027: /**
028: * This number is used by TransactionReport when sorting the list of Summary objects passed to
029: * TransactionReport.generateReport(). Lowest number prints first.
030: */
031: public static final int TOTAL_RECORD_COUNT_SUMMARY_SORT_ORDER = 1;
032: public static final int SELECTED_RECORD_COUNT_SUMMARY_SORT_ORDER = 2;
033: public static final int SEQUENCE_RECORDS_WRITTEN_SUMMARY_SORT_ORDER = 3;
034: private int sortOrder;
035:
036: /**
037: * This is the description that prints for the summary line.
038: */
039: private String description;
040:
041: /**
042: * This is the count that displays. FIXME: Make this documentation a bit more clear.
043: */
044: private long count;
045:
046: /**
047: *
048: */
049: public Summary() {
050: super ();
051: }
052:
053: /**
054: * Constructs a Summary.java.
055: * @param sortOrder
056: * @param description
057: * @param count
058: */
059: public Summary(int sortOrder, String description, long count) {
060: this .sortOrder = sortOrder;
061: this .description = description;
062: this .count = count;
063: }
064:
065: /**
066: * Constructs a Summary.java.
067: * @param sortOrder
068: * @param description
069: * @param count
070: */
071: public Summary(int sortOrder, String description, Integer count) {
072: this .sortOrder = sortOrder;
073: this .description = description;
074: if (count == null) {
075: this .count = 0;
076: } else {
077: this .count = count.longValue();
078: }
079: }
080:
081: /**
082: * Compare this Summary object with another summary object
083: *
084: * (non-Javadoc)
085: *
086: * @see java.lang.Comparable#compareTo(java.lang.Object)
087: */
088: public int compareTo(Object arg0) {
089: if (arg0 instanceof Summary) {
090: Summary otherObject = (Summary) arg0;
091: Integer otherSort = new Integer(otherObject.getSortOrder());
092: Integer this Sort = new Integer(sortOrder);
093: return this Sort.compareTo(otherSort);
094: } else {
095: return 0;
096: }
097: }
098:
099: /**
100: * Returns true if the description of this summary object and the passed in summary object are the same
101: *
102: * @see java.lang.Object#equals(java.lang.Object)
103: */
104: @Override
105: public boolean equals(Object object) {
106: if (this == object)
107: return true;
108: if (!(object instanceof Summary))
109: return false;
110:
111: Summary that = (Summary) object;
112: return this .description.equals(that.getDescription());
113: }
114:
115: /**
116: * Build a report summary list for labor general ledger posting
117: *
118: * @param destination description of summary displayed
119: * @param startingOrder order how information is displayed
120: * @return a list of summary objects
121: */
122: public static List<Summary> buildDefualtReportSummary(
123: String destination, int startingOrder) {
124: List<Summary> reportSummary = new ArrayList<Summary>();
125: updateReportSummary(reportSummary, destination,
126: KFSConstants.OperationType.INSERT, 0, startingOrder++);
127: updateReportSummary(reportSummary, destination,
128: KFSConstants.OperationType.UPDATE, 0, startingOrder++);
129: updateReportSummary(reportSummary, destination,
130: KFSConstants.OperationType.DELETE, 0, startingOrder++);
131: return reportSummary;
132: }
133:
134: /**
135: * Update the report summary with the given information
136: *
137: * @param reportSummary list of summaries
138: * @param destinationName description of summary displayed
139: * @param operationType description of what action is related to the summary (i.e. insert, updated, deleted)
140: * @param count count of how many "objects" are affected
141: * @param order order how information is displayed
142: */
143: public static void updateReportSummary(List<Summary> reportSummary,
144: String destinationName, String operationType, int count,
145: int order) {
146: StringBuilder summaryDescription = buildSummaryDescription(
147: destinationName, operationType);
148: updateReportSummary(reportSummary, summaryDescription
149: .toString(), count, order);
150: }
151:
152: /**
153: * Update the report summary with the given information
154: *
155: * @param reportSummary list of summaries
156: * @param summaryDescription description of summary displayed
157: * @param count count of how many "objects" are affected
158: * @param order order how information is displayed
159: */
160: public static void updateReportSummary(List<Summary> reportSummary,
161: String summaryDescription, int count, int order) {
162: Summary inputSummary = new Summary(order, summaryDescription,
163: count);
164:
165: int index = reportSummary.indexOf(inputSummary);
166: if (index >= 0) {
167: Summary summary = reportSummary.get(index);
168: summary.setCount(summary.getCount() + count);
169: } else {
170: reportSummary.add(inputSummary);
171: }
172: }
173:
174: /**
175: * Build the description of summary with the given information
176: *
177: * @param destinationName description of summary displayed
178: * @param operationType description of what action is related to the summary (i.e. insert, updated, deleted)
179: * @return
180: */
181: public static StringBuilder buildSummaryDescription(
182: String destinationName, String operationType) {
183: StringBuilder summaryDescription = new StringBuilder();
184: summaryDescription.append("Number of ").append(destinationName)
185: .append(" records ").append(operationType).append(":");
186: return summaryDescription;
187: }
188:
189: public long getCount() {
190: return count;
191: }
192:
193: public void setCount(long count) {
194: this .count = count;
195: }
196:
197: public String getDescription() {
198: return description;
199: }
200:
201: public void setDescription(String description) {
202: this .description = description;
203: }
204:
205: public int getSortOrder() {
206: return sortOrder;
207: }
208:
209: public void setSortOrder(int sortOrder) {
210: this.sortOrder = sortOrder;
211: }
212: }
|