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 OleStewardship oleStewardship = (OleStewardship) document.getNewMaintainableObject().getBusinessObject();
33
34 isValid &= validateStewardShipTypeName(oleStewardship);
35 return isValid;
36
37 }
38
39
40
41
42
43
44 private boolean validateStewardShipTypeName(OleStewardship oleStewardship) {
45
46 if (oleStewardship.getStewardshipTypeName() != null) {
47
48 Map<String, String> criteria = new HashMap<String, String>();
49
50 criteria.put(OLEKeyConstants.STWRDSHIP_TYPE_NAME, oleStewardship.getStewardshipTypeName());
51
52
53 List<OleStewardship> oleStewardshipInDatabase = (List<OleStewardship>) getBoService().findMatching(OleStewardship.class, criteria);
54
55 if ((oleStewardshipInDatabase.size() > 0)) {
56 for(OleStewardship oleStewardshipObj:oleStewardshipInDatabase){
57 String stewardShipTypeName=oleStewardshipObj.getStewardshipTypeName();
58 if(null==oleStewardship.getStewardshipTypeName()|| oleStewardship.getStewardshipTypeName().equalsIgnoreCase(stewardShipTypeName)) {
59 putFieldError(OLEKeyConstants.STWRDSHIP_TYPE_NAME, OLEKeyConstants.ERROR_DUP_FOUND_STWRD_TYP_NAME);
60 return false;
61 }
62 }
63 }
64 }
65
66 return true;
67 }
68
69 }