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