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.AuthenticationUserId;
027:
028: /**
029: * Matches network ID param to UserService to validate network Id. Returns error message if networkId does NOT match.
030: *
031: * @author jitrue
032: */
033: public class NetworkIdWorkflowEDLConfigComponent extends
034: SimpleWorkflowEDLConfigComponent {
035:
036: private boolean required = false;
037:
038: @Override
039: public Element getReplacementConfigElement(Element element) {
040: Element replacementEl = (Element) element.cloneNode(true);
041: Element type = (Element) ((NodeList) replacementEl
042: .getElementsByTagName(EDLXmlUtils.TYPE_E)).item(0);
043: type.setTextContent("text");
044:
045: //find the validation element if required is true set a boolean and determin if blanks
046: //are allowed based on that
047: Element validation = (Element) ((NodeList) replacementEl
048: .getElementsByTagName(EDLXmlUtils.VALIDATION_E))
049: .item(0);
050: if (validation != null
051: && validation.getAttribute("required").equals("true")) {
052: required = true;
053: }
054: return replacementEl;
055: }
056:
057: @Override
058: public String getErrorMessage(Element originalConfigElement,
059: RequestParser requestParser, MatchingParam param) {
060:
061: /*
062: * <documentContent>
063: * <applicationContent>
064: * <data edlName="Test2">
065: * <version current="true" date="Thu Sep 14 14:44:43 EDT 2006" version="0">
066: * <field name="networkId">
067: * <value>jitrue</value>
068: * </field>
069: * <field name="universityId">
070: * <value>0000394389</value>
071: * </field>
072: * </version>
073: * </data>
074: * </applicationContent>
075: * </documentContent>
076: */
077:
078: if (param.getParamValue().length() == 0 && required == true) {
079: //empty and required so send error
080: return ("Network ID is a required field");
081: } else if (param.getParamValue().length() == 0
082: && required == false) {
083: //empty but not required then just return
084: return null;
085: } else {
086: //not blank validate as normal whether required or not
087: try {
088: KEWServiceLocator.getUserService()
089: .getWorkflowUser(
090: new AuthenticationUserId(param
091: .getParamValue()));
092: } catch (EdenUserNotFoundException e) {
093: return ("The value " + param.getParamValue() + " is an invalid Network ID");
094: }
095: }
096: return null;
097: }
098:
099: public boolean isRequired() {
100: return required;
101: }
102:
103: public void setRequired(boolean required) {
104: this.required = required;
105: }
106:
107: }
|