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