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.KRADServiceLocatorWeb;
25 import org.kuali.rice.krad.util.GlobalVariables;
26
27 import java.util.Collection;
28 import java.util.HashMap;
29 import java.util.Map;
30
31 public class PeopleFlowBusRule extends MaintenanceDocumentRuleBase {
32
33 @Override
34 protected boolean processCustomSaveDocumentBusinessRules(MaintenanceDocument document) {
35 boolean result = super.processCustomSaveDocumentBusinessRules(document);
36 PeopleFlowBo peopleFlowDoc = (PeopleFlowBo)document.getNewMaintainableObject().getDataObject();
37 if (StringUtils.isBlank(peopleFlowDoc.getId())) {
38 result &= checkIfDuplicatePeopleFlow(peopleFlowDoc);
39 }
40 return result;
41 }
42
43 protected boolean checkIfDuplicatePeopleFlow(PeopleFlowBo peopleFlowBo){
44 boolean rulePassed = true;
45 if (!(StringUtils.isBlank(peopleFlowBo.getName()) ||
46 StringUtils.isBlank(peopleFlowBo.getNamespaceCode()))) {
47 Map<String,String> criteria = new HashMap<String,String>();
48 criteria.put(KewImplConstants.PropertyConstants.NAMESPACE_CODE, peopleFlowBo.getNamespaceCode());
49 criteria.put(KewImplConstants.PropertyConstants.NAME, peopleFlowBo.getName());
50 Collection<PeopleFlowBo> peopleFlows = KRADServiceLocatorWeb.getLegacyDataAdapter().findMatching(PeopleFlowBo.class, criteria);
51 if (CollectionUtils.isEmpty(peopleFlows)) {
52 rulePassed = true;
53 } else {
54 GlobalVariables.getMessageMap().putError("document.peopleFlow.duplicate",
55 RiceKeyConstants.PEOPLEFLOW_DUPLICATE, peopleFlowBo.getName().toString(), peopleFlowBo.getNamespaceCode().toString());
56 rulePassed = false;
57 }
58 }
59 return rulePassed;
60 }
61 }