1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.ole.coa.document.validation.impl;
17
18 import java.util.HashMap;
19 import java.util.List;
20 import java.util.Map;
21
22 import org.kuali.ole.coa.businessobject.OleStewardship;
23 import org.kuali.ole.sys.OLEKeyConstants;
24 import org.kuali.rice.kns.document.MaintenanceDocument;
25 import org.kuali.rice.kns.maintenance.rules.MaintenanceDocumentRuleBase;
26
27 public class OleStewardShipRule extends MaintenanceDocumentRuleBase{
28
29 @Override
30 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
31 boolean isValid = true;
32 isValid &= validateStewardShipTypeName(document);
33 return isValid;
34
35 }
36
37
38
39
40
41
42 private boolean validateStewardShipTypeName(MaintenanceDocument document) {
43 OleStewardship oleStewardship = (OleStewardship) document.getNewMaintainableObject().getBusinessObject();
44 if (!document.isEdit() && oleStewardship.getStewardshipTypeName() != null) {
45 Map<String, String> criteria = new HashMap<String, String>();
46 criteria.put(OLEKeyConstants.STWRDSHIP_TYPE_NAME, oleStewardship.getStewardshipTypeName());
47 List<OleStewardship> oleStewardshipList = (List<OleStewardship>) getBoService().findMatching(OleStewardship.class, criteria);
48
49 if ((oleStewardshipList.size() > 0)) {
50 for(OleStewardship oleStewardshipObj:oleStewardshipList){
51 String stewardShipTypeName=oleStewardshipObj.getStewardshipTypeName();
52 if(null==oleStewardship.getStewardshipTypeName()|| oleStewardship.getStewardshipTypeName().equalsIgnoreCase(stewardShipTypeName)) {
53 putFieldError(OLEKeyConstants.STWRDSHIP_TYPE_NAME, OLEKeyConstants.ERROR_DUP_FOUND_STWRD_TYP_NAME);
54 return false;
55 }
56 }
57 }
58 }
59 return true;
60 }
61
62 }