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