View Javadoc
1   /*
2    * Copyright 2006 The Kuali Foundation
3    * 
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    * http://www.opensource.org/licenses/ecl2.php
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.ole.gl.report;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.kuali.ole.sys.OLEConstants;
22  
23  /**
24   * This class represents a summary amount used in reporst
25   */
26  public class Summary implements Comparable {
27      /**
28       * This number is used by TransactionReport when sorting the list of Summary objects passed to
29       * TransactionReport.generateReport(). Lowest number prints first.
30       */
31      public static final int TOTAL_RECORD_COUNT_SUMMARY_SORT_ORDER = 1;
32      public static final int SELECTED_RECORD_COUNT_SUMMARY_SORT_ORDER = 2;
33      public static final int SEQUENCE_RECORDS_WRITTEN_SUMMARY_SORT_ORDER = 3;
34      private int sortOrder;
35  
36      /**
37       * This is the description that prints for the summary line.
38       */
39      private String description;
40  
41      /**
42       * This is the count that displays. FIXME: Make this documentation a bit more clear.
43       */
44      private long count;
45  
46      /**
47       * 
48       */
49      public Summary() {
50          super();
51      }
52  
53      
54      /**
55       * Constructs a Summary.java.
56       * @param sortOrder
57       * @param description
58       * @param count
59       */
60      public Summary(int sortOrder, String description, long count) {
61          this.sortOrder = sortOrder;
62          this.description = description;
63          this.count = count;
64      }
65  
66      /**
67       * Constructs a Summary.java.
68       * @param sortOrder
69       * @param description
70       * @param count
71       */
72      public Summary(int sortOrder, String description, Integer count) {
73          this.sortOrder = sortOrder;
74          this.description = description;
75          if (count == null) {
76              this.count = 0;
77          }
78          else {
79              this.count = count.longValue();
80          }
81      }
82  
83      /**
84       * Compare this Summary object with another summary object
85       * 
86       * (non-Javadoc)
87       * 
88       * @see java.lang.Comparable#compareTo(java.lang.Object)
89       */
90      public int compareTo(Object arg0) {
91          if (arg0 instanceof Summary) {
92              Summary otherObject = (Summary) arg0;
93              Integer otherSort = new Integer(otherObject.getSortOrder());
94              Integer thisSort = new Integer(sortOrder);
95              return thisSort.compareTo(otherSort);
96          }
97          else {
98              return 0;
99          }
100     }
101 
102     /**
103      * Returns true if the description of this summary object and the passed in summary object are the same
104      * 
105      * @see java.lang.Object#equals(java.lang.Object)
106      */
107     @Override
108     public boolean equals(Object object) {
109         if (this == object)
110             return true;
111         if (!(object instanceof Summary))
112             return false;
113 
114         Summary that = (Summary) object;
115         return this.description.equals(that.getDescription());
116     }
117 
118     /**
119      * Build a report summary list for labor general ledger posting
120      * 
121      * @param destination description of summary displayed
122      * @param startingOrder order how information is displayed
123      * @return a list of summary objects
124      */
125     public static List<Summary> buildDefualtReportSummary(String destination, int startingOrder) {
126         List<Summary> reportSummary = new ArrayList<Summary>();
127         updateReportSummary(reportSummary, destination, OLEConstants.OperationType.INSERT, 0, startingOrder++);
128         updateReportSummary(reportSummary, destination, OLEConstants.OperationType.UPDATE, 0, startingOrder++);
129         updateReportSummary(reportSummary, destination, OLEConstants.OperationType.DELETE, 0, startingOrder++);
130         return reportSummary;
131     }
132 
133     /**
134      * Update the report summary with the given information
135      * 
136      * @param reportSummary list of summaries
137      * @param destinationName description of summary displayed
138      * @param operationType description of what action is related to the summary (i.e. insert, updated, deleted)
139      * @param count count of how many "objects" are affected
140      * @param order order how information is displayed
141      */
142     public static void updateReportSummary(List<Summary> reportSummary, String destinationName, String operationType, int count, int order) {
143         StringBuilder summaryDescription = buildSummaryDescription(destinationName, operationType);
144         updateReportSummary(reportSummary, summaryDescription.toString(), count, order);
145     }
146 
147     /**
148      * Update the report summary with the given information
149      * 
150      * @param reportSummary list of summaries
151      * @param summaryDescription description of summary displayed
152      * @param count count of how many "objects" are affected
153      * @param order order how information is displayed
154      */
155     public static void updateReportSummary(List<Summary> reportSummary, String summaryDescription, int count, int order) {
156         Summary inputSummary = new Summary(order, summaryDescription, count);
157 
158         int index = reportSummary.indexOf(inputSummary);
159         if (index >= 0) {
160             Summary summary = reportSummary.get(index);
161             summary.setCount(summary.getCount() + count);
162         }
163         else {
164             reportSummary.add(inputSummary);
165         }
166     }
167 
168     /**
169      * Build the description of summary with the given information
170      * 
171      * @param destinationName description of summary displayed
172      * @param operationType description of what action is related to the summary (i.e. insert, updated, deleted)
173      * @return
174      */
175     public static StringBuilder buildSummaryDescription(String destinationName, String operationType) {
176         StringBuilder summaryDescription = new StringBuilder();
177         summaryDescription.append("Number of ").append(destinationName).append(" records ").append(operationType).append(":");
178         return summaryDescription;
179     }
180 
181 
182     public long getCount() {
183         return count;
184     }
185 
186     public void setCount(long count) {
187         this.count = count;
188     }
189 
190     public String getDescription() {
191         return description;
192     }
193 
194     public void setDescription(String description) {
195         this.description = description;
196     }
197 
198     public int getSortOrder() {
199         return sortOrder;
200     }
201 
202     public void setSortOrder(int sortOrder) {
203         this.sortOrder = sortOrder;
204     }
205 }