01: /*
02: * Copyright 2007 The Kuali Foundation.
03: *
04: * Licensed under the Educational Community License, Version 1.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.opensource.org/licenses/ecl1.php
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.kuali.module.purap.rules;
17:
18: import java.util.HashMap;
19: import java.util.Map;
20:
21: import org.kuali.core.document.MaintenanceDocument;
22: import org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase;
23: import org.kuali.core.service.BusinessObjectService;
24: import org.kuali.module.purap.PurapKeyConstants;
25: import org.kuali.module.purap.bo.PurchaseOrderQuoteLanguage;
26:
27: /*
28: * THIS CODE IS NOT USED IN RELEASE 2 BUT THE CODE WAS LEFT IN TO
29: * FACILITATE TURNING IT BACK ON EARLY IN THE DEVELOPMENT CYCLE OF RELEASE 3.
30: */
31: public class PurchaseOrderQuoteLanguageRule extends
32: MaintenanceDocumentRuleBase {
33:
34: private PurchaseOrderQuoteLanguage newQuoteLanguage;
35: private BusinessObjectService boService;
36:
37: /**
38: * @see org.kuali.core.maintenance.rules.MaintenanceDocumentRuleBase#setupConvenienceObjects()
39: */
40: @Override
41: public void setupConvenienceObjects() {
42: // setup newDelegateChange convenience objects, make sure all possible sub-objects are populated
43: newQuoteLanguage = (PurchaseOrderQuoteLanguage) super
44: .getNewBo();
45: boService = (BusinessObjectService) super .getBoService();
46: super .setupConvenienceObjects();
47: }
48:
49: protected boolean processCustomApproveDocumentBusinessRules(
50: MaintenanceDocument document) {
51: LOG.info("processCustomApproveDocumentBusinessRules called");
52: this .setupConvenienceObjects();
53: boolean success = this .checkForDuplicate();
54: return success
55: && super
56: .processCustomApproveDocumentBusinessRules(document);
57: }
58:
59: protected boolean processCustomRouteDocumentBusinessRules(
60: MaintenanceDocument document) {
61: LOG.info("processCustomRouteDocumentBusinessRules called");
62: this .setupConvenienceObjects();
63: boolean success = this .checkForDuplicate();
64: return success
65: && super
66: .processCustomRouteDocumentBusinessRules(document);
67: }
68:
69: protected boolean processCustomSaveDocumentBusinessRules(
70: MaintenanceDocument document) {
71: LOG.info("processCustomSaveDocumentBusinessRules called");
72: this .setupConvenienceObjects();
73: boolean success = this .checkForDuplicate();
74: return success
75: && super
76: .processCustomSaveDocumentBusinessRules(document);
77: }
78:
79: protected boolean checkForDuplicate() {
80: LOG.info("checkForDuplicate called");
81: boolean success = true;
82: Map fieldValues = new HashMap();
83: fieldValues.put("purchaseOrderQuoteLanguageDescription",
84: newQuoteLanguage
85: .getPurchaseOrderQuoteLanguageDescription());
86: fieldValues.put("purchaseOrderQuoteLanguageCreateDate",
87: newQuoteLanguage
88: .getPurchaseOrderQuoteLanguageCreateDate());
89: if (boService.countMatching(newQuoteLanguage.getClass(),
90: fieldValues) != 0) {
91: success &= false;
92: putGlobalError(PurapKeyConstants.PURAP_GENERAL_POTENTIAL_DUPLICATE);
93: }
94: return success;
95: }
96: }
|