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.purap.document.validation.impl;
017
018 import org.apache.commons.lang.StringUtils;
019 import org.kuali.kfs.module.purap.PurapKeyConstants;
020 import org.kuali.kfs.module.purap.businessobject.NegativePaymentRequestApprovalLimit;
021 import org.kuali.kfs.sys.KFSPropertyConstants;
022 import org.kuali.rice.kns.document.MaintenanceDocument;
023 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
024 import org.kuali.rice.kns.util.GlobalVariables;
025
026 /**
027 * Business rules for the NegativePaymentRequestApprovalLimit maintenance document
028 */
029 public class NegativePaymentRequestApprovalLimitRule extends MaintenanceDocumentRuleBase {
030
031 /**
032 * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomApproveDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
033 */
034 @Override
035 protected boolean processCustomApproveDocumentBusinessRules(MaintenanceDocument document) {
036 boolean result = super.processCustomApproveDocumentBusinessRules(document);
037 final NegativePaymentRequestApprovalLimit limit = (NegativePaymentRequestApprovalLimit)getNewBo();
038 result &= checkExclusiveOrganizationCodeAndAccountNumber(limit);
039 return result;
040 }
041
042 /**
043 * @see org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.rice.kns.document.MaintenanceDocument)
044 */
045 @Override
046 protected boolean processCustomRouteDocumentBusinessRules(MaintenanceDocument document) {
047 boolean result = super.processCustomRouteDocumentBusinessRules(document);
048 final NegativePaymentRequestApprovalLimit limit = (NegativePaymentRequestApprovalLimit)getNewBo();
049 result &= checkExclusiveOrganizationCodeAndAccountNumber(limit);
050 return result;
051 }
052
053 /**
054 * Checks that organization code and account number aren't both specified on a new NegativePaymentRequestApprovalLimit
055 * @param limit the NegativePaymentRequestApprovalLimit to check
056 * @return true if the rule passed, false otherwise (with error message added)
057 */
058 protected boolean checkExclusiveOrganizationCodeAndAccountNumber(NegativePaymentRequestApprovalLimit limit) {
059 if (!StringUtils.isBlank(limit.getOrganizationCode()) && !StringUtils.isBlank(limit.getAccountNumber())) {
060 putFieldError(KFSPropertyConstants.ORGANIZATION_CODE, PurapKeyConstants.ERROR_NEGATIVE_PAYMENT_REQUEST_APPROVAL_LIMIT_ORG_AND_ACCOUNT_EXCLUSIVE, new String[] {});
061 putFieldError(KFSPropertyConstants.ACCOUNT_NUMBER, PurapKeyConstants.ERROR_NEGATIVE_PAYMENT_REQUEST_APPROVAL_LIMIT_ORG_AND_ACCOUNT_EXCLUSIVE, new String[] {});
062 return false;
063 }
064 return true;
065 }
066
067 }