001: /*
002: * Copyright 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.labor.bo;
017:
018: import java.util.HashSet;
019: import java.util.Set;
020:
021: import org.kuali.kfs.bo.AccountingLine;
022: import org.kuali.kfs.bo.AccountingLineOverride;
023: import org.kuali.kfs.bo.AccountingLineOverride.COMPONENT;
024:
025: /**
026: * Labor business object for Labor Accounting Line Override
027: */
028: public class LaborAccountingLineOverride {
029:
030: /**
031: * On the given AccountingLine, converts override input checkboxes from a Struts Form into a persistable override code.
032: *
033: * @param line
034: */
035: public static void populateFromInput(AccountingLine line) {
036: // todo: this logic won't work if a single account checkbox might also stands for NON_FRINGE_ACCOUNT_USED; needs thought
037:
038: Set<Integer> overrideInputComponents = new HashSet<Integer>();
039: if (line.getAccountExpiredOverride()) {
040: overrideInputComponents.add(COMPONENT.EXPIRED_ACCOUNT);
041: }
042: if (line.isObjectBudgetOverride()) {
043: overrideInputComponents.add(COMPONENT.NON_BUDGETED_OBJECT);
044: }
045: if (line.getNonFringeAccountOverride()) {
046: overrideInputComponents
047: .add(COMPONENT.NON_FRINGE_ACCOUNT_USED);
048: }
049:
050: Integer[] inputComponentArray = overrideInputComponents
051: .toArray(new Integer[overrideInputComponents.size()]);
052: line.setOverrideCode(AccountingLineOverride.valueOf(
053: inputComponentArray).getCode());
054: }
055:
056: /**
057: * Prepares the given AccountingLine in a Struts Action for display by a JSP. This means converting the override code to
058: * checkboxes for display and input, as well as analyzing the accounting line and determining which override checkboxes are
059: * needed.
060: *
061: * @param line
062: */
063: public static void processForOutput(AccountingLine line) {
064: AccountingLineOverride fromCurrentCode = AccountingLineOverride
065: .valueOf(line.getOverrideCode());
066: AccountingLineOverride needed = determineNeededOverrides(line);
067: line.setAccountExpiredOverride(fromCurrentCode
068: .hasComponent(COMPONENT.EXPIRED_ACCOUNT));
069: line.setAccountExpiredOverrideNeeded(needed
070: .hasComponent(COMPONENT.EXPIRED_ACCOUNT));
071: line.setObjectBudgetOverride(fromCurrentCode
072: .hasComponent(COMPONENT.NON_BUDGETED_OBJECT));
073: line.setObjectBudgetOverrideNeeded(needed
074: .hasComponent(COMPONENT.NON_BUDGETED_OBJECT));
075: line.setNonFringeAccountOverride(fromCurrentCode
076: .hasComponent(COMPONENT.NON_FRINGE_ACCOUNT_USED));
077: line.setNonFringeAccountOverrideNeeded(needed
078: .hasComponent(COMPONENT.NON_FRINGE_ACCOUNT_USED));
079: }
080:
081: /**
082: * Determines what overrides the given line needs.
083: *
084: * @param line
085: * @return what overrides the given line needs.
086: */
087: public static AccountingLineOverride determineNeededOverrides(
088: AccountingLine line) {
089: Set<Integer> neededOverrideComponents = new HashSet<Integer>();
090: if (AccountingLineOverride.needsExpiredAccountOverride(line
091: .getAccount())) {
092: neededOverrideComponents.add(COMPONENT.EXPIRED_ACCOUNT);
093: }
094: if (AccountingLineOverride.needsObjectBudgetOverride(line
095: .getAccount(), line.getObjectCode())) {
096: neededOverrideComponents.add(COMPONENT.NON_BUDGETED_OBJECT);
097: }
098: if (AccountingLineOverride.needsNonFringAccountOverride(line
099: .getAccount())) {
100: neededOverrideComponents
101: .add(COMPONENT.NON_FRINGE_ACCOUNT_USED);
102: }
103: Integer[] inputComponentArray = neededOverrideComponents
104: .toArray(new Integer[neededOverrideComponents.size()]);
105:
106: return AccountingLineOverride.valueOf(inputComponentArray);
107: }
108: }
|