View Javadoc

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.coa.document;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.kuali.ole.coa.businessobject.OrganizationReversionCategory;
22  import org.kuali.ole.coa.service.OrganizationReversionDetailTrickleDownInactivationService;
23  import org.kuali.ole.sys.context.SpringContext;
24  import org.kuali.ole.sys.document.FinancialSystemMaintainable;
25  import org.kuali.rice.krad.service.BusinessObjectService;
26  import org.kuali.rice.krad.util.KRADConstants;
27  import org.kuali.rice.krad.util.ObjectUtils;
28  
29  /**
30   * A Maintainable for the Organization Reversion Category maintenance document
31   */
32  public class OrganizationReversionCategoryMaintainableImpl extends FinancialSystemMaintainable {
33  
34      /**
35       * Determines if this maint doc is inactivating an organization reversion category
36       * @return true if the document is inactivating an active organization reversioncategory, false otherwise
37       */
38      protected boolean isInactivatingOrganizationReversionCategory() {
39          // the account has to be closed on the new side when editing in order for it to be possible that we are closing the account
40          if (KRADConstants.MAINTENANCE_EDIT_ACTION.equals(getMaintenanceAction()) && !((OrganizationReversionCategory) getBusinessObject()).isActive()) {
41              OrganizationReversionCategory existingOrganizationReversionCategoryFromDB = retrieveExistingOrganizationReversionCategory();
42              if (ObjectUtils.isNotNull(existingOrganizationReversionCategoryFromDB)) {
43                  // now see if the original account was not closed, in which case, we are closing the account
44                  if (existingOrganizationReversionCategoryFromDB.isActive()) {
45                      return true;
46                  }
47              }
48          }
49          return false;
50      }
51      
52      /**
53       * Determines if this maint doc is activating an organization reversion category
54       * @return true if the document is activating an inactive organization reversion category, false otherwise
55       */
56      protected boolean isActivatingOrganizationReversionCategory() {
57          // the account has to be closed on the new side when editing in order for it to be possible that we are closing the account
58          if (KRADConstants.MAINTENANCE_EDIT_ACTION.equals(getMaintenanceAction()) && ((OrganizationReversionCategory) getBusinessObject()).isActive()) {
59              OrganizationReversionCategory existingOrganizationReversionCategoryFromDB = retrieveExistingOrganizationReversionCategory();
60              if (ObjectUtils.isNotNull(existingOrganizationReversionCategoryFromDB)) {
61                  // now see if the original account was not closed, in which case, we are closing the account
62                  if (!existingOrganizationReversionCategoryFromDB.isActive()) {
63                      return true;
64                  }
65              }
66          }
67          return false;
68      }
69      
70      /**
71       * Grabs the old version of this org reversion category from the database
72       * @return the old version of this organization reversion category
73       */
74      protected OrganizationReversionCategory retrieveExistingOrganizationReversionCategory() {
75          final OrganizationReversionCategory orgRevCategory = (OrganizationReversionCategory)getBusinessObject();
76          Map<String, Object> pkMap = new HashMap<String, Object>();
77          pkMap.put("organizationReversionCategoryCode", ((OrganizationReversionCategory)getBusinessObject()).getOrganizationReversionCategoryCode());
78          final OrganizationReversionCategory oldOrgRevCategory = (OrganizationReversionCategory)SpringContext.getBean(BusinessObjectService.class).findByPrimaryKey(OrganizationReversionCategory.class, pkMap);
79          return oldOrgRevCategory;
80      }
81  
82      /**
83       * Overridden to trickle down inactivation or activation to details
84       * @see org.kuali.rice.kns.maintenance.KualiMaintainableImpl#saveBusinessObject()
85       */
86      @Override
87      public void saveBusinessObject() {
88          final boolean isActivatingOrgReversionCategory = isActivatingOrganizationReversionCategory();
89          final boolean isInactivatingOrgReversionCategory = isInactivatingOrganizationReversionCategory();
90          
91          super.saveBusinessObject();
92          
93          if (isActivatingOrgReversionCategory) {
94              SpringContext.getBean(OrganizationReversionDetailTrickleDownInactivationService.class).trickleDownActiveOrganizationReversionDetails((OrganizationReversionCategory)getBusinessObject(), getDocumentNumber());
95          } else if (isInactivatingOrgReversionCategory) {
96              SpringContext.getBean(OrganizationReversionDetailTrickleDownInactivationService.class).trickleDownInactiveOrganizationReversionDetails((OrganizationReversionCategory)getBusinessObject(), getDocumentNumber());
97          }
98      }
99  
100 }