1 /*
2 * Copyright 2009 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.businessobject;
17
18 import java.util.Comparator;
19
20 import org.apache.commons.lang.StringUtils;
21 import org.kuali.ole.sys.OLEPropertyConstants;
22
23 /**
24 * Holds summary data for the ledger summary report
25 */
26 public class LedgerSummaryDetailLine extends LedgerBalanceTypeSummaryTotalLine {
27 private String financialSystemOriginationCode;
28 private Integer universityFiscalYear;
29 private String universityAccountPeriodCode;
30
31 /**
32 * Constructs a LedgerSummaryDetailLine
33 *
34 * @param balanceTypeCode
35 * @param financialSystemOriginationCode
36 * @param universityFiscalYear
37 * @param universityAccountPeriodCode
38 */
39 public LedgerSummaryDetailLine(String balanceTypeCode, String financialSystemOriginationCode, Integer universityFiscalYear, String universityAccountPeriodCode) {
40 super(balanceTypeCode);
41 this.financialSystemOriginationCode = financialSystemOriginationCode;
42 this.universityFiscalYear = universityFiscalYear;
43 this.universityAccountPeriodCode = universityAccountPeriodCode;
44 }
45
46 /**
47 * Gets the financialSystemOriginationCode attribute.
48 *
49 * @return Returns the financialSystemOriginationCode.
50 */
51 public String getFinancialSystemOriginationCode() {
52 return financialSystemOriginationCode;
53 }
54
55 /**
56 * Gets the universityFiscalYear attribute.
57 *
58 * @return Returns the universityFiscalYear.
59 */
60 public Integer getUniversityFiscalYear() {
61 return universityFiscalYear;
62 }
63
64 /**
65 * Gets the universityAccountPeriodCode attribute.
66 *
67 * @return Returns the universityAccountPeriodCode.
68 */
69 public String getUniversityAccountPeriodCode() {
70 return universityAccountPeriodCode;
71 }
72
73 /**
74 * @return gets a "key" for this summary line - just a convenient key for Maps which might hold these
75 */
76 public String getKey() {
77 return LedgerSummaryDetailLine.makeKey(this.getFinancialBalanceTypeCode(), this.getFinancialSystemOriginationCode(), this.getUniversityFiscalYear(), this.getUniversityAccountPeriodCode());
78 }
79
80 /**
81 * Generates a Map key in a consistent format with the rest of the uses of this class for a given OriginEntryInformation
82 *
83 * @param entry the entry to build a key for
84 * @return the "key" for a summary line which would include totals from entries like the given origin entry
85 */
86 public static String getKeyString(OriginEntryInformation entry) {
87 return LedgerSummaryDetailLine.makeKey(entry.getFinancialBalanceTypeCode(), entry.getFinancialSystemOriginationCode(), entry.getUniversityFiscalYear(), entry.getUniversityFiscalPeriodCode());
88 }
89
90 /**
91 * Given the various values, puts together a convenient Map key
92 *
93 * @param balanceTypeCode a balance type code
94 * @param financialSystemOriginationCode an origination code
95 * @param universityFiscalYear a fiscal year, smothered in mustard
96 * @param universityAccountingPeriodCode an accounting period code
97 * @return all of them magically put together, to form a Map key. Like Voltron, but more financially oriented
98 */
99 private static String makeKey(String balanceTypeCode, String financialSystemOriginationCode, Integer universityFiscalYear, String universityAccountingPeriodCode) {
100 return StringUtils.join(new String[] { balanceTypeCode, financialSystemOriginationCode, universityFiscalYear == null ? "" : universityFiscalYear.toString(), universityAccountingPeriodCode }, ':');
101 }
102
103 /**
104 * @return a standard comparator for comparing NightlyOutPendingEntryLedgerSummaryDetailLine objects
105 */
106 public static Comparator<LedgerSummaryDetailLine> getStandardComparator() {
107 return new Comparator<LedgerSummaryDetailLine>() {
108
109 /**
110 * Compares two NightlyOutPendingEntryLedgerSummaryDetailLine objects
111 *
112 * @param detail1 the first NightlyOutPendingEntryLedgerSummaryDetailLine object
113 * @param detail2 the second NightlyOutPendingEntryLedgerSummaryDetailLine other
114 * @return the standard 0 for equals, greater than 0 for greater than, less than 0 for less than
115 */
116 public int compare(LedgerSummaryDetailLine detail1, LedgerSummaryDetailLine detail2) {
117 int comp = 0;
118 comp = nullSafeCompare(detail1.getFinancialBalanceTypeCode(), detail2.getFinancialBalanceTypeCode());
119
120 if (comp == 0) {
121 comp = nullSafeCompare(detail1.getFinancialSystemOriginationCode(), detail2.getFinancialSystemOriginationCode());
122 }
123
124 if (comp == 0) {
125 comp = nullSafeCompare(detail1.getUniversityFiscalYear(), detail2.getUniversityFiscalYear());
126 }
127
128 if (comp == 0) {
129 comp = nullSafeCompare(detail1.getUniversityAccountPeriodCode(), detail2.getUniversityAccountPeriodCode());
130 }
131
132 return comp;
133 }
134
135 /**
136 * Checks for nulls in the two comparables before calling the compare. If one is null and not the other, the null is
137 * considered less. If both are null they are considered equal.
138 *
139 * @param o1 object to compare
140 * @param o2 object to compare o1 to
141 * @return -1 for less, 0 for equal, 1 for greater
142 */
143 protected int nullSafeCompare(Comparable o1, Comparable o2) {
144 if (o1 == null && o2 != null) {
145 return -1;
146 }
147
148 if (o1 != null && o2 == null) {
149 return 1;
150 }
151
152 if (o1 == null && o2 == null) {
153 return 0;
154 }
155
156 return o1.compareTo(o2);
157 }
158 };
159 }
160
161 public static String[] keyFields = new String[] { OLEPropertyConstants.FINANCIAL_BALANCE_TYPE_CODE, OLEPropertyConstants.FINANCIAL_SYSTEM_ORIGINATION_CODE, OLEPropertyConstants.UNIVERSITY_FISCAL_YEAR, "universityAccountPeriodCode" };
162
163 }