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.chart.maintenance;
017:
018: import java.util.ArrayList;
019: import java.util.List;
020: import java.util.Map;
021:
022: import org.kuali.core.document.MaintenanceDocument;
023: import org.kuali.core.document.MaintenanceLock;
024: import org.kuali.core.maintenance.KualiGlobalMaintainableImpl;
025: import org.kuali.kfs.KFSConstants;
026: import org.kuali.module.chart.bo.ObjectCode;
027: import org.kuali.module.chart.bo.ObjectCodeGlobal;
028: import org.kuali.module.chart.bo.ObjectCodeGlobalDetail;
029:
030: /**
031: * This class provides some specific functionality for the {@link ObjectCodeGlobal} maintenance document refresh - sets the current
032: * fiscal year from the {@link ObjectCodeGlobalDetail} prepareGlobalsForSave - sets the object code on each detail object in the
033: * collection generateMaintenanceLocks - generates the appropriate maintenance locks for the {@link ObjectCode}
034: */
035: public class ObjectCodeGlobalMaintainableImpl extends
036: KualiGlobalMaintainableImpl {
037: private static String CHANGE_DETAIL_COLLECTION = "objectCodeGlobalDetails";
038:
039: /**
040: * This method sets the current fiscal year from the {@link ObjectCodeGlobalDetail} on the {@link ObjectCodeGlobal}
041: *
042: * @see org.kuali.core.maintenance.KualiMaintainableImpl#refresh(java.lang.String, java.util.Map,
043: * org.kuali.core.document.MaintenanceDocument)
044: */
045: @Override
046: public void refresh(String refreshCaller, Map fieldValues,
047: MaintenanceDocument document) {
048: // if our detail objects have a null fiscal year we need to fill these in with the "addLine" fiscal year
049: // otherwise we leave it alone, these should only be null when coming back from a multiple value lookup
050: if (refreshCaller != null
051: && refreshCaller.equals(KFSConstants.MULTIPLE_VALUE)) {
052: ObjectCodeGlobal objectCodeGlobal = (ObjectCodeGlobal) document
053: .getDocumentBusinessObject();
054: ObjectCodeGlobalDetail addLineDetail = (ObjectCodeGlobalDetail) newCollectionLines
055: .get(CHANGE_DETAIL_COLLECTION);
056: int fiscalYear = addLineDetail.getUniversityFiscalYear();
057: for (ObjectCodeGlobalDetail detail : objectCodeGlobal
058: .getObjectCodeGlobalDetails()) {
059: if (detail.getUniversityFiscalYear() == null) {
060:
061: detail.setUniversityFiscalYear(fiscalYear);
062: }
063: }
064: }
065:
066: super .refresh(refreshCaller, fieldValues, document);
067: }
068:
069: //
070: // @Override
071: // protected List<String> getMultiValueIdentifierList(Collection maintCollection) {
072: // List<String> identifierList = new ArrayList<String>();
073: // for (ObjectCodeGlobalDetail bo : (Collection<ObjectCodeGlobalDetail>)maintCollection) {
074: // identifierList.add(bo.getChartOfAccountsCode());
075: // }
076: // return identifierList;
077: // }
078:
079: // @Override
080: // protected boolean hasBusinessObjectExistedInLookupResult(BusinessObject bo, List<String> existingIdentifierList) {
081: // // default implementation does nothing
082: // if (existingIdentifierList.contains(((ObjectCodeGlobalDetail)bo).getChartOfAccountsCode())) {
083: // return true;
084: // }
085: // else {
086: // return false;
087: // }
088: // }
089:
090: /**
091: * This method sets the object code on each detail object in the collection
092: */
093: @Override
094: protected void prepareGlobalsForSave() {
095: // copy the object code down from the header into the details
096: ObjectCodeGlobal objectCodeGlobal = (ObjectCodeGlobal) getBusinessObject();
097:
098: for (ObjectCodeGlobalDetail detail : objectCodeGlobal
099: .getObjectCodeGlobalDetails()) {
100: detail.setFinancialObjectCode(objectCodeGlobal
101: .getFinancialObjectCode());
102: }
103: super .prepareGlobalsForSave();
104: }
105:
106: /**
107: * This generates the appropriate maintenance locks for the {@link ObjectCode}
108: *
109: * @see org.kuali.core.maintenance.Maintainable#generateMaintenanceLocks()
110: */
111: @Override
112: public List<MaintenanceLock> generateMaintenanceLocks() {
113: ObjectCodeGlobal objectCodeGlobal = (ObjectCodeGlobal) getBusinessObject();
114: List<MaintenanceLock> maintenanceLocks = new ArrayList();
115:
116: for (ObjectCodeGlobalDetail detail : objectCodeGlobal
117: .getObjectCodeGlobalDetails()) {
118: MaintenanceLock maintenanceLock = new MaintenanceLock();
119: StringBuffer lockrep = new StringBuffer();
120:
121: lockrep.append(ObjectCode.class.getName()
122: + KFSConstants.Maintenance.AFTER_CLASS_DELIM);
123: lockrep.append("universityFiscalYear"
124: + KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
125: lockrep.append(detail.getUniversityFiscalYear()
126: + KFSConstants.Maintenance.AFTER_VALUE_DELIM);
127: lockrep.append("chartOfAccountsCode"
128: + KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
129: lockrep.append(detail.getChartOfAccountsCode()
130: + KFSConstants.Maintenance.AFTER_VALUE_DELIM);
131: lockrep.append("financialObjectCode"
132: + KFSConstants.Maintenance.AFTER_FIELDNAME_DELIM);
133: lockrep.append(detail.getFinancialObjectCode());
134:
135: maintenanceLock.setDocumentNumber(objectCodeGlobal
136: .getDocumentNumber());
137: maintenanceLock
138: .setLockingRepresentation(lockrep.toString());
139: maintenanceLocks.add(maintenanceLock);
140: }
141: return maintenanceLocks;
142: }
143: }
|