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.module.cam.document.validation.impl;
017
018 import java.util.ArrayList;
019 import java.util.List;
020
021 import org.kuali.kfs.module.cam.CamsConstants;
022 import org.kuali.kfs.module.cam.businessobject.AssetPaymentAssetDetail;
023 import org.kuali.kfs.module.cam.document.AssetPaymentDocument;
024 import org.kuali.kfs.module.cam.service.AssetLockService;
025 import org.kuali.kfs.sys.document.validation.GenericValidation;
026 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
027
028 /**
029 * This class validates if asset is locked by other document, if so returns false
030 */
031 public class AssetPaymentLockValidation extends GenericValidation {
032
033 private AssetLockService assetLockService;
034
035 /**
036 * Validates asset to ensure it is not locked by any other document
037 *
038 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
039 */
040 public boolean validate(AttributedDocumentEvent event) {
041 AssetPaymentDocument assetPaymentDocument = (AssetPaymentDocument) event.getDocument();
042 List<Long> assetNumbers = new ArrayList<Long>();
043 for (AssetPaymentAssetDetail assetPaymentAssetDetail : assetPaymentDocument.getAssetPaymentAssetDetail()) {
044 if (assetPaymentAssetDetail.getCapitalAssetNumber() != null) {
045 assetNumbers.add(assetPaymentAssetDetail.getCapitalAssetNumber());
046 }
047 }
048 String documentTypeForLocking = CamsConstants.DocumentTypeName.ASSET_PAYMENT;
049 if (assetPaymentDocument.isCapitalAssetBuilderOriginIndicator()) {
050 documentTypeForLocking = CamsConstants.DocumentTypeName.ASSET_PAYMENT_FROM_CAB;
051 }
052
053 if (assetLockService.isAssetLocked(assetNumbers, documentTypeForLocking, assetPaymentDocument.getDocumentNumber())) {
054 return false;
055 }
056
057 return true;
058 }
059
060 public AssetLockService getAssetLockService() {
061 return assetLockService;
062 }
063
064 public void setAssetLockService(AssetLockService assetLockService) {
065 this.assetLockService = assetLockService;
066 }
067 }