001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.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/ecl2.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.kfs.coa.service.impl;
017
018 import java.util.ArrayList;
019 import java.util.Collection;
020 import java.util.Iterator;
021 import java.util.Map;
022
023 import org.kuali.rice.kns.bo.BusinessObject;
024 import org.kuali.rice.kns.bo.Inactivateable;
025 import org.kuali.rice.kns.datadictionary.InactivationBlockingMetadata;
026 import org.kuali.rice.kns.service.impl.InactivationBlockingDetectionServiceImpl;
027
028 /**
029 * This class is used when the offset definition represents the object that is blocking other records from being inactivated.
030 *
031 * Normally, only active BO's with the proper primary key values are allowed to inactivate other business objects. However,
032 * OffsetDefinitions do not have an active indicator. An offset definition that references another BO is allowed to block the inactivation
033 * of that BO, without regard to active status, because the OD bo does not have an active status on it.
034 */
035 public class OffsetDefinitionInactivationBlockingDetectionServiceImpl extends InactivationBlockingDetectionServiceImpl {
036 protected static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(OffsetDefinitionInactivationBlockingDetectionServiceImpl.class);
037 /**
038 * Overriding to let blocking records through
039 * @see org.kuali.rice.kns.service.impl.InactivationBlockingDetectionServiceImpl#listAllBlockerRecords(org.kuali.rice.kns.bo.BusinessObject, org.kuali.rice.kns.datadictionary.InactivationBlockingMetadata)
040 */
041 public Collection<BusinessObject> listAllBlockerRecords(BusinessObject blockedBo, InactivationBlockingMetadata inactivationBlockingMetadata) {
042 Collection<BusinessObject> blockingRecords = new ArrayList<BusinessObject>();
043
044 Map<String, String> queryMap = buildInactivationBlockerQueryMap(blockedBo, inactivationBlockingMetadata);
045 if (LOG.isDebugEnabled()) {
046 LOG.debug("Checking for blocker records for object: " + blockedBo);
047 LOG.debug(" With Metadata: " + inactivationBlockingMetadata);
048 LOG.debug(" Resulting Query Map: " + queryMap);
049 }
050
051 if (queryMap != null) {
052 Collection<? extends BusinessObject> potentialBlockingRecords = businessObjectService.findMatching(
053 inactivationBlockingMetadata.getBlockingReferenceBusinessObjectClass(), queryMap);
054 for (Iterator<? extends BusinessObject> iterator = potentialBlockingRecords.iterator(); iterator.hasNext();) {
055 Inactivateable businessObject = (Inactivateable) iterator.next();
056 blockingRecords.add((BusinessObject) businessObject);
057 }
058 }
059
060 return blockingRecords;
061 }
062
063 /**
064 * Overriding to say that any record of the same PK is blocking..
065 * @see org.kuali.rice.kns.service.impl.InactivationBlockingDetectionServiceImpl#hasABlockingRecord(org.kuali.rice.kns.bo.BusinessObject, org.kuali.rice.kns.datadictionary.InactivationBlockingMetadata)
066 */
067 public boolean hasABlockingRecord(BusinessObject blockedBo, InactivationBlockingMetadata inactivationBlockingMetadata) {
068 boolean hasBlockingRecord = false;
069
070 Map<String, String> queryMap = buildInactivationBlockerQueryMap(blockedBo, inactivationBlockingMetadata);
071 if (queryMap != null) {
072 Collection<? extends BusinessObject> potentialBlockingRecords = businessObjectService.findMatching(
073 inactivationBlockingMetadata.getBlockingReferenceBusinessObjectClass(), queryMap);
074 return !potentialBlockingRecords.isEmpty();
075 }
076
077 // if queryMap were null, means that we couldn't perform a query, and hence, need to return false
078 return hasBlockingRecord;
079 }
080 }