001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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.module.purap.rules;
017:
018: import java.util.HashMap;
019: import java.util.Map;
020:
021: import org.kuali.core.document.MaintenanceDocument;
022: import org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase;
023: import org.kuali.core.service.BusinessObjectService;
024: import org.kuali.module.purap.PurapKeyConstants;
025: import org.kuali.module.purap.bo.PurchaseOrderContractLanguage;
026:
027: /**
028: * Business rule(s) applicable to Purchase Order Contract Language maintenance document.
029: */
030: public class PurchaseOrderContractLanguageRule extends
031: MaintenanceDocumentRuleBase {
032:
033: private PurchaseOrderContractLanguage newContractLanguage;
034: private BusinessObjectService boService;
035:
036: /**
037: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#setupConvenienceObjects()
038: */
039: @Override
040: public void setupConvenienceObjects() {
041: // setup newDelegateChange convenience objects, make sure all possible sub-objects are populated
042: newContractLanguage = (PurchaseOrderContractLanguage) super
043: .getNewBo();
044: boService = (BusinessObjectService) super .getBoService();
045: super .setupConvenienceObjects();
046: }
047:
048: /**
049: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomApproveDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
050: */
051: protected boolean processCustomApproveDocumentBusinessRules(
052: MaintenanceDocument document) {
053: LOG.info("processCustomApproveDocumentBusinessRules called");
054: this .setupConvenienceObjects();
055: boolean success = this .checkForDuplicate();
056: return success
057: && super
058: .processCustomApproveDocumentBusinessRules(document);
059: }
060:
061: /**
062: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomRouteDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
063: */
064: protected boolean processCustomRouteDocumentBusinessRules(
065: MaintenanceDocument document) {
066: LOG.info("processCustomRouteDocumentBusinessRules called");
067: this .setupConvenienceObjects();
068: boolean success = this .checkForDuplicate();
069: return success
070: && super
071: .processCustomRouteDocumentBusinessRules(document);
072: }
073:
074: /**
075: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#processCustomSaveDocumentBusinessRules(org.kuali.core.document.MaintenanceDocument)
076: */
077: protected boolean processCustomSaveDocumentBusinessRules(
078: MaintenanceDocument document) {
079: LOG.info("processCustomSaveDocumentBusinessRules called");
080: this .setupConvenienceObjects();
081: boolean success = this .checkForDuplicate();
082: return success
083: && super
084: .processCustomSaveDocumentBusinessRules(document);
085: }
086:
087: /**
088: * Check to see if data duplicates existing data
089: *
090: * @return boolean indicating if validation succeeded
091: */
092: protected boolean checkForDuplicate() {
093: LOG.info("checkForDuplicate called");
094: boolean success = true;
095: Map fieldValues = new HashMap();
096: fieldValues.put("campusCode", newContractLanguage
097: .getCampusCode());
098: fieldValues.put("purchaseOrderContractLanguageDescription",
099: newContractLanguage
100: .getPurchaseOrderContractLanguageDescription());
101: fieldValues.put("contractLanguageCreateDate",
102: newContractLanguage.getContractLanguageCreateDate());
103: if (boService.countMatching(newContractLanguage.getClass(),
104: fieldValues) != 0) {
105: success &= false;
106: putGlobalError(PurapKeyConstants.PURAP_GENERAL_POTENTIAL_DUPLICATE);
107: }
108: return success;
109: }
110: }
|