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.fp.document.validation.impl;
017
018 import org.kuali.kfs.fp.businessobject.CapitalAssetInformation;
019 import org.kuali.kfs.fp.document.CapitalAssetEditable;
020 import org.kuali.kfs.integration.cab.CapitalAssetBuilderModuleService;
021 import org.kuali.kfs.sys.KFSPropertyConstants;
022 import org.kuali.kfs.sys.context.SpringContext;
023 import org.kuali.kfs.sys.document.AccountingDocument;
024 import org.kuali.kfs.sys.document.validation.GenericValidation;
025 import org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent;
026 import org.kuali.rice.kns.util.GlobalVariables;
027 import org.kuali.rice.kns.util.MessageMap;
028 import org.kuali.rice.kns.util.ObjectUtils;
029
030 /**
031 * validate the capital asset information associated with the accounting document for validation
032 */
033 public class CapitalAssetInformationValidation extends GenericValidation {
034 private static org.apache.log4j.Logger LOG = org.apache.log4j.Logger.getLogger(CapitalAssetInformationValidation.class);
035
036 private CapitalAssetBuilderModuleService capitalAssetBuilderModuleService = SpringContext.getBean(CapitalAssetBuilderModuleService.class);
037 private AccountingDocument accountingDocumentForValidation;
038
039 /**
040 * @see org.kuali.kfs.sys.document.validation.Validation#validate(org.kuali.kfs.sys.document.validation.event.AttributedDocumentEvent)
041 */
042 public boolean validate(AttributedDocumentEvent event) {
043 return this.hasValidCapitalAssetInformation(accountingDocumentForValidation);
044 }
045
046 // determine whehter the given document has valid capital asset information if any
047 protected boolean hasValidCapitalAssetInformation(AccountingDocument accountingDocument) {
048 LOG.debug("hasValidCapitalAssetInformation(Document) - start");
049
050 if (accountingDocument instanceof CapitalAssetEditable == false) {
051 return true;
052 }
053
054 CapitalAssetEditable capitalAssetEditable = (CapitalAssetEditable) accountingDocument;
055 CapitalAssetInformation capitalAssetInformation = capitalAssetEditable.getCapitalAssetInformation();
056
057 if (ObjectUtils.isNotNull(capitalAssetInformation)) {
058 MessageMap errors = GlobalVariables.getMessageMap();
059 errors.addToErrorPath(KFSPropertyConstants.DOCUMENT);
060 errors.addToErrorPath(KFSPropertyConstants.CAPITAL_ASSET_INFORMATION);
061
062 boolean isValid = capitalAssetBuilderModuleService.validateFinancialProcessingData(accountingDocument, capitalAssetInformation);
063
064 errors.removeFromErrorPath(KFSPropertyConstants.CAPITAL_ASSET_INFORMATION);
065 errors.removeFromErrorPath(KFSPropertyConstants.DOCUMENT);
066 return isValid;
067 }
068
069 return true;
070 }
071
072 /**
073 * Sets the accountingDocumentForValidation attribute value.
074 *
075 * @param accountingDocumentForValidation The accountingDocumentForValidation to set.
076 */
077 public void setAccountingDocumentForValidation(AccountingDocument accountingDocumentForValidation) {
078 this.accountingDocumentForValidation = accountingDocumentForValidation;
079 }
080
081 }