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