1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
25
26 public class Summary implements Comparable {
27
28
29
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
38
39 private String description;
40
41
42
43
44 private long count;
45
46
47
48
49 public Summary() {
50 super();
51 }
52
53
54
55
56
57
58
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
68
69
70
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
85
86
87
88
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
104
105
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
120
121
122
123
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
135
136
137
138
139
140
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
149
150
151
152
153
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
170
171
172
173
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 }