Coverage Report - org.kuali.rice.kew.edl.components.NetworkIdWorkflowEDLConfigComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
NetworkIdWorkflowEDLConfigComponent
0%
0/20
0%
0/14
3.5
 
 1  
 /*
 2  
  * Copyright 2005-2007 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.kew.edl.components;
 18  
 
 19  
 import org.kuali.rice.kew.edl.EDLXmlUtils;
 20  
 import org.kuali.rice.kew.edl.RequestParser;
 21  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 22  
 import org.kuali.rice.kim.bo.entity.KimPrincipal;
 23  
 import org.kuali.rice.kew.user.AuthenticationUserId;
 24  
 import org.kuali.rice.kim.bo.entity.KimPrincipal;
 25  
 import org.kuali.rice.kim.service.KIMServiceLocator;
 26  
 import org.w3c.dom.Element;
 27  
 import org.w3c.dom.NodeList;
 28  
 
 29  
 
 30  
 /**
 31  
  * Matches network ID param to UserService to validate network Id.  Returns error message if networkId does NOT match.
 32  
  * 
 33  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 34  
  */
 35  0
 public class NetworkIdWorkflowEDLConfigComponent extends SimpleWorkflowEDLConfigComponent {
 36  
         
 37  0
         private boolean required = false;
 38  
         
 39  
         @Override
 40  
         public Element getReplacementConfigElement(Element element) {
 41  0
                 Element replacementEl = (Element)element.cloneNode(true);
 42  0
                 Element type = (Element)((NodeList)replacementEl.getElementsByTagName(EDLXmlUtils.TYPE_E)).item(0);
 43  0
                 type.setTextContent("text");
 44  
                 
 45  
                 //find the validation element if required is true set a boolean and determin if blanks
 46  
                 //are allowed based on that
 47  0
                 Element validation = (Element)((NodeList)replacementEl.getElementsByTagName(EDLXmlUtils.VALIDATION_E)).item(0);
 48  0
                 if (validation != null && validation.getAttribute("required").equals("true")) {
 49  0
                         required = true;
 50  
                 }
 51  0
                 return replacementEl;
 52  
         }
 53  
         
 54  
         @Override
 55  
         public String getErrorMessage(Element originalConfigElement, RequestParser requestParser, MatchingParam param) {
 56  
                 
 57  0
                 if (param.getParamValue().length() == 0 && required == true) {
 58  
                         //empty and required so send error
 59  0
                         return ("Network ID is a required field");
 60  0
                 } else if (param.getParamValue().length() == 0 && required == false) { 
 61  
                         //empty but not required then just return 
 62  0
                         return null;                        
 63  
                 } else {
 64  
                         //not blank validate as normal whether required or not
 65  0
                         KimPrincipal principal = KIMServiceLocator.getIdentityManagementService().getPrincipalByPrincipalName(param.getParamValue());
 66  0
                         if (principal == null) {
 67  0
                                 return ("The value " + param.getParamValue() + " is an invalid principal name");
 68  
                         }
 69  
                 }
 70  0
                 return null;
 71  
         }
 72  
 
 73  
         public boolean isRequired() {
 74  0
                 return required;
 75  
         }
 76  
 
 77  
         public void setRequired(boolean required) {
 78  0
                 this.required = required;
 79  0
         }
 80  
 
 81  
 }