1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.edl.components;
18
19 import org.kuali.rice.kew.edl.EDLXmlUtils;
20 import org.kuali.rice.kew.edl.RequestParser;
21 import org.kuali.rice.kew.service.KEWServiceLocator;
22 import org.kuali.rice.kew.util.Utilities;
23 import org.kuali.rice.kew.workgroup.GroupId;
24 import org.kuali.rice.kew.workgroup.GroupNameId;
25 import org.kuali.rice.kim.bo.Group;
26 import org.w3c.dom.Element;
27 import org.w3c.dom.NodeList;
28
29
30
31
32
33
34 public class WorkgroupWorkflowEDLConfigComponent extends SimpleWorkflowEDLConfigComponent {
35
36 private boolean required = false;
37
38 protected GroupId resolveId(String id) {
39 String groupName = Utilities.parseGroupName(id);
40 String namespace = Utilities.parseGroupNamespaceCode(id);
41 return new GroupNameId(namespace, groupName);
42 }
43
44 @Override
45 public Element getReplacementConfigElement(Element element) {
46 Element replacementEl = (Element)element.cloneNode(true);
47 Element type = (Element)((NodeList)replacementEl.getElementsByTagName(EDLXmlUtils.TYPE_E)).item(0);
48 type.setTextContent("text");
49
50
51
52 Element validation = (Element)((NodeList)replacementEl.getElementsByTagName(EDLXmlUtils.VALIDATION_E)).item(0);
53 if (validation != null && validation.getAttribute("required").equals("true")) {
54 required = true;
55 }
56 return replacementEl;
57 }
58
59 @Override
60 public String getErrorMessage(Element originalConfigElement, RequestParser requestParser, MatchingParam param) {
61
62 if (param.getParamValue().length() == 0 && required == true) {
63
64 return ("Workgroup is a required field");
65 } else if (param.getParamValue().length() == 0 && required == false) {
66
67 return null;
68 }
69 String wrkgrpName = param.getParamValue();
70
71 Group group = KEWServiceLocator.getIdentityHelperService().getGroup(resolveId(wrkgrpName));
72 if (group == null) {
73 return ("Group " + wrkgrpName + " not found.");
74 }
75 if (!group.isActive()) {
76 return ("Group " + wrkgrpName + " is not an active group.");
77 }
78 return null;
79 }
80
81 public boolean isRequired() {
82 return required;
83 }
84
85 public void setRequired(boolean required) {
86 this.required = required;
87 }
88
89 }