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