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.Collection;
019: import java.util.Collections;
020: import java.util.Comparator;
021: import java.util.List;
022: import java.util.Map;
023:
024: import org.kuali.core.bo.PersistableBusinessObject;
025: import org.kuali.core.maintenance.KualiMaintainableImpl;
026: import org.kuali.core.util.TypedArrayList;
027: import org.kuali.kfs.context.SpringContext;
028: import org.kuali.module.chart.bo.OrganizationReversion;
029: import org.kuali.module.chart.bo.OrganizationReversionCategory;
030: import org.kuali.module.chart.bo.OrganizationReversionDetail;
031: import org.kuali.module.chart.service.OrganizationReversionService;
032:
033: /**
034: * This class provides some specific functionality for the {@link OrganizationReversion} maintenance document inner class for doing
035: * comparisons on {@link OrganizationReversionCategory} populateBusinessObject setBusinessObject - pre-populate the static list of
036: * details with each category isRelationshipRefreshable - makes sure that {@code organizationReversionGlobalDetails} isn't wiped out
037: * accidentally
038: */
039: public class OrganizationReversionMaintainableImpl extends
040: KualiMaintainableImpl {
041:
042: /**
043: * This comparator is used internally for sorting the list of categories
044: */
045: private class categoryComparator implements
046: Comparator<OrganizationReversionDetail> {
047:
048: public int compare(OrganizationReversionDetail detail0,
049: OrganizationReversionDetail detail1) {
050:
051: OrganizationReversionCategory category0 = detail0
052: .getOrganizationReversionCategory();
053: OrganizationReversionCategory category1 = detail1
054: .getOrganizationReversionCategory();
055:
056: String code0 = category0
057: .getOrganizationReversionCategoryCode();
058: String code1 = category1
059: .getOrganizationReversionCategoryCode();
060:
061: return code0.compareTo(code1);
062: }
063:
064: }
065:
066: /**
067: * @see org.kuali.core.maintenance.KualiMaintainableImpl#populateBusinessObject(java.util.Map)
068: */
069: public Map populateBusinessObject(Map fieldValues) {
070: Map result = super .populateBusinessObject(fieldValues);
071: return result;
072: }
073:
074: /**
075: * pre-populate the static list of details with each category
076: *
077: * @see org.kuali.core.maintenance.KualiMaintainableImpl#setBusinessObject(org.kuali.core.bo.BusinessObject)
078: */
079: public void setBusinessObject(
080: PersistableBusinessObject businessObject) {
081:
082: OrganizationReversionService organizationReversionService = SpringContext
083: .getBean(OrganizationReversionService.class);
084: OrganizationReversion organizationReversion = (OrganizationReversion) businessObject;
085: List<OrganizationReversionDetail> details = organizationReversion
086: .getOrganizationReversionDetail();
087:
088: if (details == null) {
089: details = new TypedArrayList(
090: OrganizationReversionDetail.class);
091: organizationReversion
092: .setOrganizationReversionDetail(details);
093: }
094:
095: if (details.size() == 0) {
096:
097: Collection<OrganizationReversionCategory> categories = organizationReversionService
098: .getCategoryList();
099:
100: for (OrganizationReversionCategory category : categories) {
101: if (category
102: .isOrganizationReversionCategoryActiveIndicator()) {
103: OrganizationReversionDetail detail = new OrganizationReversionDetail();
104: detail
105: .setOrganizationReversionCategoryCode(category
106: .getOrganizationReversionCategoryCode());
107: detail.setOrganizationReversionCategory(category);
108: details.add(detail);
109: }
110: }
111:
112: Collections.sort(details, new categoryComparator());
113:
114: }
115:
116: super .setBusinessObject(businessObject);
117: }
118:
119: /**
120: * A method that prevents lookups from refreshing the Organization Reversion Detail list (because, if it is refreshed before a
121: * save...it ends up destroying the list).
122: *
123: * @see org.kuali.core.maintenance.KualiMaintainableImpl#isRelationshipRefreshable(java.lang.Class, java.lang.String)
124: */
125: @Override
126: protected boolean isRelationshipRefreshable(Class boClass,
127: String relationshipName) {
128: if (relationshipName.equals("organizationReversionDetail")) {
129: return false;
130: } else {
131: return super.isRelationshipRefreshable(boClass,
132: relationshipName);
133: }
134: }
135:
136: }
|