1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.impl.peopleflow;
17
18 import org.apache.commons.collections.CollectionUtils;
19 import org.apache.commons.lang.StringUtils;
20 import org.kuali.rice.core.api.util.RiceKeyConstants;
21 import org.kuali.rice.kew.impl.KewImplConstants;
22 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
23 import org.kuali.rice.krad.rules.MaintenanceDocumentRuleBase;
24 import org.kuali.rice.krad.service.BusinessObjectService;
25 import org.kuali.rice.krad.service.KRADServiceLocator;
26 import org.kuali.rice.krad.util.GlobalVariables;
27
28 import java.util.Collection;
29 import java.util.HashMap;
30 import java.util.Map;
31
32 public class PeopleFlowBusRule extends MaintenanceDocumentRuleBase {
33 private BusinessObjectService businessObjectService;
34
35 @Override
36 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
37 boolean result = super.processCustomSaveDocumentBusinessRules(document);
38 PeopleFlowBo peopleFlowDoc = (PeopleFlowBo)document.getNewMaintainableObject().getDataObject();
39 if (StringUtils.isBlank(peopleFlowDoc.getId())) {
40 result &= checkIfDuplicatePeopleFlow(peopleFlowDoc);
41 }
42 return result;
43 }
44
45 protected boolean checkIfDuplicatePeopleFlow(PeopleFlowBo peopleFlowBo){
46 boolean rulePassed = true;
47 if (!(StringUtils.isBlank(peopleFlowBo.getName()) ||
48 StringUtils.isBlank(peopleFlowBo.getNamespaceCode()))) {
49 Map<String,String> criteria = new HashMap<String,String>();
50 criteria.put(KewImplConstants.PropertyConstants.NAMESPACE_CODE, peopleFlowBo.getNamespaceCode());
51 criteria.put(KewImplConstants.PropertyConstants.NAME, peopleFlowBo.getName());
52 Collection<PeopleFlowBo> peopleFlows = getBusinessObjectService().findMatching(PeopleFlowBo.class,criteria);
53 if (CollectionUtils.isEmpty(peopleFlows)) {
54 rulePassed = true;
55 } else {
56 GlobalVariables.getMessageMap().putError("document.peopleFlow.duplicate",
57 RiceKeyConstants.PEOPLEFLOW_DUPLICATE, peopleFlowBo.getName().toString(), peopleFlowBo.getNamespaceCode().toString());
58 rulePassed = false;
59 }
60 }
61 return rulePassed;
62 }
63
64 public BusinessObjectService getBusinessObjectService() {
65 if(businessObjectService == null){
66 businessObjectService = KRADServiceLocator.getBusinessObjectService();
67 }
68 return businessObjectService;
69 }
70
71 public void setBusinessObjectService(BusinessObjectService businessObjectService) {
72 this.businessObjectService = businessObjectService;
73 }
74 }