Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
UniversityIdWorkflowEDLConfigComponent |
|
| 3.5;3.5 |
1 | /** | |
2 | * Copyright 2005-2011 The Kuali Foundation | |
3 | * | |
4 | * Licensed under the Educational Community License, Version 2.0 (the "License"); | |
5 | * you may not use this file except in compliance with the License. | |
6 | * You may obtain a copy of the License at | |
7 | * | |
8 | * http://www.opensource.org/licenses/ecl2.php | |
9 | * | |
10 | * Unless required by applicable law or agreed to in writing, software | |
11 | * distributed under the License is distributed on an "AS IS" BASIS, | |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
13 | * See the License for the specific language governing permissions and | |
14 | * limitations under the License. | |
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 | * Matches university ID param to UserService to validate universityId. Returns error message if | |
28 | * universityId does NOT match. | |
29 | * | |
30 | * @author Kuali Rice Team (rice.collab@kuali.org) | |
31 | */ | |
32 | 0 | public class UniversityIdWorkflowEDLConfigComponent extends SimpleWorkflowEDLConfigComponent { |
33 | ||
34 | private boolean required; | |
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 | //find the validation element if required is true set a boolean and determin if blanks | |
43 | //are allowed based on that | |
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 | /* | |
55 | * <documentContent> | |
56 | * <applicationContent> | |
57 | * <data edlName="Test2"> | |
58 | * <version current="true" date="Thu Sep 14 14:44:43 EDT 2006" version="0"> | |
59 | * <field name="networkId"> | |
60 | * <value>jitrue</value> | |
61 | * </field> | |
62 | * <field name="universityId"> | |
63 | * <value>0000394389</value> | |
64 | * </field> | |
65 | * </version> | |
66 | * </data> | |
67 | * </applicationContent> | |
68 | * </documentContent> | |
69 | */ | |
70 | ||
71 | 0 | if (param.getParamValue().length() == 0 && required == true) { |
72 | //empty and required so send error | |
73 | 0 | return ("University ID is a required field"); |
74 | 0 | } else if (param.getParamValue().length() == 0 && required == false) { |
75 | //empty but not required then just return | |
76 | 0 | return null; |
77 | } else { | |
78 | //not blank validate as normal whether required or not | |
79 | 0 | String employeeId = param.getParamValue(); |
80 | ||
81 | 0 | Principal principal = KimApiServiceLocator.getIdentityService().getPrincipal(employeeId); |
82 | 0 | if (principal == null) { |
83 | 0 | return ("The value " + employeeId + " is an invalid University ID"); |
84 | } | |
85 | ||
86 | ||
87 | } | |
88 | 0 | return null; |
89 | } | |
90 | ||
91 | public boolean isRequired() { | |
92 | 0 | return required; |
93 | } | |
94 | ||
95 | public void setRequired(boolean required) { | |
96 | 0 | this.required = required; |
97 | 0 | } |
98 | ||
99 | ||
100 | } | |
101 |