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.kim.api.identity.principal.Principal;
21 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
22 import org.w3c.dom.Element;
23 import org.w3c.dom.NodeList;
24
25
26
27
28
29
30
31 public class NetworkIdWorkflowEDLConfigComponent extends SimpleWorkflowEDLConfigComponent {
32
33 private boolean required = false;
34
35 @Override
36 public Element getReplacementConfigElement(Element element) {
37 Element replacementEl = (Element)element.cloneNode(true);
38 Element type = (Element)((NodeList)replacementEl.getElementsByTagName(EDLXmlUtils.TYPE_E)).item(0);
39 type.setTextContent("text");
40
41
42
43 Element validation = (Element)((NodeList)replacementEl.getElementsByTagName(EDLXmlUtils.VALIDATION_E)).item(0);
44 if (validation != null && validation.getAttribute("required").equals("true")) {
45 required = true;
46 }
47 return replacementEl;
48 }
49
50 @Override
51 public String getErrorMessage(Element originalConfigElement, RequestParser requestParser, MatchingParam param) {
52 if (!getEdlContext().getUserAction().isValidatableAction()) {
53 return null;
54 } else if (param.getParamValue().length() == 0 && required == true) {
55
56 return ("Network ID is a required field");
57 } else if (param.getParamValue().length() == 0 && required == false) {
58
59 return null;
60 } else {
61
62 Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(param.getParamValue());
63 if (principal == null) {
64 return ("The value " + param.getParamValue() + " is an invalid principal name");
65 }
66 }
67 return null;
68 }
69
70 public boolean isRequired() {
71 return required;
72 }
73
74 public void setRequired(boolean required) {
75 this.required = required;
76 }
77
78 }