001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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.kfs.module.ec.businessobject;
017
018 import java.util.Arrays;
019 import java.util.HashSet;
020 import java.util.List;
021 import java.util.Set;
022
023 import org.kuali.kfs.sys.KFSPropertyConstants;
024 import org.kuali.kfs.sys.businessobject.AccountingLineOverride;
025 import org.kuali.kfs.sys.businessobject.AccountingLineOverride.COMPONENT;
026
027 /**
028 * to handle Effort certification detail line override
029 */
030 public class EffortCertificationDetailLineOverride {
031
032 public static final List<String> REFRESH_FIELDS = Arrays.asList(new String[]{ KFSPropertyConstants.ACCOUNT});
033
034 /**
035 * convert override input checkboxes from a Struts Form into an override code.
036 *
037 * @param detailLine the given detail line
038 */
039 public static void populateFromInput(EffortCertificationDetail detailLine) {
040 Set<Integer> overrideInputComponents = new HashSet<Integer>();
041 if (detailLine.isAccountExpiredOverride()) {
042 overrideInputComponents.add(COMPONENT.EXPIRED_ACCOUNT);
043 }
044
045 Integer[] inputComponentArray = overrideInputComponents.toArray(new Integer[overrideInputComponents.size()]);
046 detailLine.setOverrideCode(AccountingLineOverride.valueOf(inputComponentArray).getCode());
047 }
048
049 /**
050 * prepare the given detail line in a Struts Action for display by a JSP. This means converting the override code to
051 * checkboxes for display and input, as well as analyzing the accounting line and determining which override checkboxes are
052 * needed.
053 *
054 * @param detailLine the given detail line
055 */
056 public static void processForOutput(EffortCertificationDetail detailLine) {
057 AccountingLineOverride fromCurrentCode = AccountingLineOverride.valueOf(detailLine.getOverrideCode());
058 AccountingLineOverride needed = determineNeededOverrides(detailLine);
059 detailLine.setAccountExpiredOverride(fromCurrentCode.hasComponent(COMPONENT.EXPIRED_ACCOUNT));
060 detailLine.setAccountExpiredOverrideNeeded(needed.hasComponent(COMPONENT.EXPIRED_ACCOUNT));
061 }
062
063 /**
064 * determine whether the given detail line has any attribute with override
065 *
066 * @param detailLine the given detail line
067 * @return what overrides the given line needs.
068 */
069 public static AccountingLineOverride determineNeededOverrides(EffortCertificationDetail detailLine) {
070 Set<Integer> neededOverrideComponents = new HashSet<Integer>();
071 if (AccountingLineOverride.needsExpiredAccountOverride(detailLine.getAccount())) {
072 neededOverrideComponents.add(COMPONENT.EXPIRED_ACCOUNT);
073 }
074
075 Integer[] inputComponentArray = neededOverrideComponents.toArray(new Integer[neededOverrideComponents.size()]);
076 return AccountingLineOverride.valueOf(inputComponentArray);
077 }
078 }