001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.edl.components;
018:
019: import org.w3c.dom.Element;
020: import org.w3c.dom.NodeList;
021:
022: import edu.iu.uis.eden.KEWServiceLocator;
023: import edu.iu.uis.eden.edl.EDLXmlUtils;
024: import edu.iu.uis.eden.edl.RequestParser;
025: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
026: import edu.iu.uis.eden.user.EmplId;
027:
028: /**
029: * Matches university ID param to UserService to validate universityId. Returns error message if
030: * universityId does NOT match.
031: *
032: * @author jitrue
033: */
034: public class UniversityIdWorkflowEDLConfigComponent extends
035: SimpleWorkflowEDLConfigComponent {
036:
037: private boolean required;
038:
039: @Override
040: public Element getReplacementConfigElement(Element element) {
041: Element replacementEl = (Element) element.cloneNode(true);
042: Element type = (Element) ((NodeList) replacementEl
043: .getElementsByTagName(EDLXmlUtils.TYPE_E)).item(0);
044: type.setTextContent("text");
045:
046: //find the validation element if required is true set a boolean and determin if blanks
047: //are allowed based on that
048: Element validation = (Element) ((NodeList) replacementEl
049: .getElementsByTagName(EDLXmlUtils.VALIDATION_E))
050: .item(0);
051: if (validation != null
052: && validation.getAttribute("required").equals("true")) {
053: required = true;
054: }
055: return replacementEl;
056: }
057:
058: @Override
059: public String getErrorMessage(Element originalConfigElement,
060: RequestParser requestParser, MatchingParam param) {
061:
062: /*
063: * <documentContent>
064: * <applicationContent>
065: * <data edlName="Test2">
066: * <version current="true" date="Thu Sep 14 14:44:43 EDT 2006" version="0">
067: * <field name="networkId">
068: * <value>jitrue</value>
069: * </field>
070: * <field name="universityId">
071: * <value>0000394389</value>
072: * </field>
073: * </version>
074: * </data>
075: * </applicationContent>
076: * </documentContent>
077: */
078:
079: if (param.getParamValue().length() == 0 && required == true) {
080: //empty and required so send error
081: return ("University ID is a required field");
082: } else if (param.getParamValue().length() == 0
083: && required == false) {
084: //empty but not required then just return
085: return null;
086: } else {
087: //not blank validate as normal whether required or not
088: try {
089: KEWServiceLocator.getUserService().getWorkflowUser(
090: new EmplId(param.getParamValue()));
091: } catch (EdenUserNotFoundException e) {
092: return ("The value " + param.getParamValue() + " is an invalid University ID");
093: }
094: }
095: return null;
096: }
097:
098: public boolean isRequired() {
099: return required;
100: }
101:
102: public void setRequired(boolean required) {
103: this.required = required;
104: }
105:
106: }
|