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.List;
019
020 import org.kuali.kfs.module.cam.CamsConstants;
021 import org.kuali.kfs.module.cam.CamsKeyConstants;
022 import org.kuali.kfs.module.cam.CamsPropertyConstants;
023 import org.kuali.kfs.module.cam.businessobject.AssetGlobal;
024 import org.kuali.kfs.module.cam.businessobject.AssetPaymentAssetDetail;
025 import org.kuali.kfs.module.cam.businessobject.AssetPaymentDetail;
026 import org.kuali.kfs.module.cam.document.AssetPaymentDocument;
027 import org.kuali.kfs.module.cam.document.service.AssetService;
028 import org.kuali.kfs.sys.businessobject.AccountingLine;
029 import org.kuali.kfs.sys.document.validation.GenericValidation;
030 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
031 import org.kuali.rice.kns.service.ParameterService;
032 import org.kuali.rice.kns.util.GlobalVariables;
033
034 /**
035 * This class validates object sub type code for the financial object for which payment is being made
036 */
037 public class AssetPaymentObjectCodeValidation extends GenericValidation {
038 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(AssetPaymentObjectCodeValidation.class);
039
040 private AssetService assetService;
041 private ParameterService parameterService;
042
043 private AccountingLine accountingLineForValidation;
044
045 /**
046 * Validate financial object sub type code validation, it should be of type capital asset.
047 *
048 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
049 */
050 public boolean validate(AttributedDocumentEvent event) {
051 // skip check if accounting line is from CAB
052 AssetPaymentDocument assetPaymentDocument = (AssetPaymentDocument) event.getDocument();
053 if (assetPaymentDocument.isCapitalAssetBuilderOriginIndicator()) {
054 return true;
055 }
056
057 AssetPaymentDetail assetPaymentDetail = (AssetPaymentDetail) getAccountingLineForValidation();
058 boolean result = true;
059
060 List<String> validSubtypeCodes = parameterService.getParameterValues(AssetGlobal.class, CamsConstants.Parameters.CAPITAL_OBJECT_SUB_TYPES);
061 String parameterDetail = "(module:"+parameterService.getNamespace(AssetGlobal.class)+"/component:"+parameterService.getDetailType(AssetGlobal.class)+")";
062
063 boolean capitalAssetFound = false;
064
065 List<AssetPaymentAssetDetail> assetPaymentAssetDetails = assetPaymentDocument.getAssetPaymentAssetDetail();
066 for(AssetPaymentAssetDetail assetPaymentAssetDetail:assetPaymentAssetDetails) {
067 if (assetService.isCapitalAsset(assetPaymentAssetDetail.getAsset())) {
068 if (!validSubtypeCodes.contains(assetPaymentDetail.getObjectCode().getFinancialObjectSubTypeCode())) {
069 GlobalVariables.getMessageMap().putError(CamsPropertyConstants.AssetPaymentDetail.FINANCIAL_OBJECT_CODE, CamsKeyConstants.Payment.ERROR_INVALID_OBJECT_SUBTYPE, new String[] { assetPaymentDetail.getFinancialObjectCode(), assetPaymentDetail.getObjectCode().getFinancialObjectSubTypeCode(), CamsConstants.Parameters.CAPITAL_OBJECT_SUB_TYPES +" "+parameterDetail,validSubtypeCodes.toString() });
070 result = false;
071 break;
072 }
073 }
074
075 }
076 return result;
077 }
078
079 public AccountingLine getAccountingLineForValidation() {
080 return accountingLineForValidation;
081 }
082
083 public void setAccountingLineForValidation(AccountingLine accountingLine) {
084 this.accountingLineForValidation = accountingLine;
085 }
086
087 public AssetService getAssetService() {
088 return assetService;
089 }
090
091 public void setAssetService(AssetService assetService) {
092 this.assetService = assetService;
093 }
094
095 public ParameterService getParameterService() {
096 return parameterService;
097 }
098
099 public void setParameterService(ParameterService parameterService) {
100 this.parameterService = parameterService;
101 }
102
103
104 }