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.service.impl;
17  
18  import java.util.ArrayList;
19  import java.util.Collection;
20  import java.util.Iterator;
21  import java.util.Map;
22  
23  import org.kuali.rice.core.api.mo.common.active.MutableInactivatable;
24  import org.kuali.rice.krad.bo.BusinessObject;
25  import org.kuali.rice.krad.datadictionary.InactivationBlockingMetadata;
26  import org.kuali.rice.krad.service.impl.InactivationBlockingDetectionServiceImpl;
27  
28  /**
29   * This class is used when the offset definition represents the object that is blocking other records from being inactivated.
30   * 
31   * Normally, only active BO's with the proper primary key values are allowed to inactivate other business objects.  However, 
32   * OffsetDefinitions do not have an active indicator.  An offset definition that references another BO is allowed to block the inactivation
33   * of that BO, without regard to active status, because the OD bo does not have an active status on it.
34   */
35  public class OffsetDefinitionInactivationBlockingDetectionServiceImpl extends InactivationBlockingDetectionServiceImpl {
36      protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OffsetDefinitionInactivationBlockingDetectionServiceImpl.class);
37      /**
38       * Overriding to let blocking records through
39       * @see org.kuali.rice.krad.service.impl.InactivationBlockingDetectionServiceImpl#listAllBlockerRecords(org.kuali.rice.krad.bo.BusinessObject, org.kuali.rice.krad.datadictionary.InactivationBlockingMetadata)
40       */
41      public Collection<BusinessObject> listAllBlockerRecords(BusinessObject blockedBo, InactivationBlockingMetadata inactivationBlockingMetadata) {
42          Collection<BusinessObject> blockingRecords = new ArrayList<BusinessObject>();
43  
44          Map<String, String> queryMap = buildInactivationBlockerQueryMap(blockedBo, inactivationBlockingMetadata);
45          if (LOG.isDebugEnabled()) {
46              LOG.debug("Checking for blocker records for object: " + blockedBo);
47              LOG.debug("    With Metadata: " + inactivationBlockingMetadata);
48              LOG.debug("    Resulting Query Map: " + queryMap);
49          }
50  
51          if (queryMap != null) {
52              Collection<? extends BusinessObject> potentialBlockingRecords = businessObjectService.findMatching(
53                      inactivationBlockingMetadata.getBlockingReferenceBusinessObjectClass(), queryMap);
54              for (Iterator<? extends BusinessObject> iterator = potentialBlockingRecords.iterator(); iterator.hasNext();) {
55                  MutableInactivatable businessObject = (MutableInactivatable) iterator.next();
56                  blockingRecords.add((BusinessObject) businessObject);
57              }
58          }
59  
60          return blockingRecords;
61      }
62      
63      /**
64       * Overriding to say that any record of the same PK is blocking..
65       * @see org.kuali.rice.krad.service.impl.InactivationBlockingDetectionServiceImpl#hasABlockingRecord(org.kuali.rice.krad.bo.BusinessObject, org.kuali.rice.krad.datadictionary.InactivationBlockingMetadata)
66       */
67      public boolean hasABlockingRecord(BusinessObject blockedBo, InactivationBlockingMetadata inactivationBlockingMetadata) {
68          boolean hasBlockingRecord = false;
69  
70          Map<String, String> queryMap = buildInactivationBlockerQueryMap(blockedBo, inactivationBlockingMetadata);
71          if (queryMap != null) {
72              Collection<? extends BusinessObject> potentialBlockingRecords = businessObjectService.findMatching(
73                      inactivationBlockingMetadata.getBlockingReferenceBusinessObjectClass(), queryMap);
74              return !potentialBlockingRecords.isEmpty();
75          }
76  
77          // if queryMap were null, means that we couldn't perform a query, and hence, need to return false
78          return hasBlockingRecord;
79      }
80  }