View Javadoc
1   /*
2    * Copyright 2008 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.service.impl;
17  
18  import java.util.HashMap;
19  import java.util.Map;
20  
21  import org.kuali.ole.coa.businessobject.Account;
22  import org.kuali.ole.coa.businessobject.ObjectCode;
23  import org.kuali.ole.coa.businessobject.SubAccount;
24  import org.kuali.ole.coa.businessobject.SubObjectCode;
25  import org.kuali.ole.sys.OLEConstants;
26  import org.kuali.ole.sys.OLEPropertyConstants;
27  import org.kuali.rice.krad.bo.BusinessObject;
28  import org.kuali.rice.krad.datadictionary.InactivationBlockingMetadata;
29  import org.kuali.rice.krad.service.PersistenceService;
30  import org.kuali.rice.krad.service.impl.InactivationBlockingDetectionServiceImpl;
31  
32  public class IndirectCostRecoveryRateDetailInactivationBlockingDetectionServiceImpl extends InactivationBlockingDetectionServiceImpl {
33      protected PersistenceService persistenceService;
34      
35      @Override
36      protected Map<String, String> buildInactivationBlockerQueryMap(BusinessObject blockedBo, InactivationBlockingMetadata inactivationBlockingMetadata) {
37          Class<? extends BusinessObject> boClass = blockedBo.getClass();
38          if (!(Account.class.isAssignableFrom(boClass) || SubAccount.class.isAssignableFrom(boClass) || ObjectCode.class.isAssignableFrom(boClass) || SubObjectCode.class.isAssignableFrom(boClass))) {
39              throw new IllegalArgumentException("BO must be either an Account, SubAccount, ObjectCode, or SubObjectCode (was: " + boClass + ")");
40          }
41          
42          // this code assumes that the PK field names in the BO are identical to the field names in the ICR Rate Detail BO
43          Map<String, Object> fieldValues = persistenceService.getPrimaryKeyFieldValues(blockedBo);
44          if (Account.class.isAssignableFrom(boClass)) {
45              fieldValues.put(OLEPropertyConstants.ACCOUNT_ACTIVE_INDICATOR, OLEConstants.ParameterValues.NO);
46          }
47          else {
48              fieldValues.put(OLEPropertyConstants.ACTIVE, OLEConstants.ParameterValues.YES);
49          }
50          return convertFieldValuesToStrings(fieldValues);
51      }
52      
53      /**
54       * Converts the map of PKs - which is a Map of <String, Object> to a Map of <String, String> by turning any objects inside into Strings...
55       * @param fieldValues field values to convert
56       * @return the Map of fieldValues converted to a Map of <String, String>
57       */
58      protected Map<String, String> convertFieldValuesToStrings(Map<String, Object> fieldValues) {
59          Map<String, String> newFieldValues = new HashMap<String, String>();
60          for (String key : fieldValues.keySet()) {
61              final Object value = fieldValues.get(key);
62              if (value != null) {
63                  newFieldValues.put(key, value.toString());
64              }
65          }
66          return newFieldValues;
67      }
68  
69      public void setPersistenceService(PersistenceService persistenceService) {
70          this.persistenceService = persistenceService;
71      }
72  }