Coverage Report - org.kuali.rice.edl.impl.components.NetworkIdWorkflowEDLConfigComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
NetworkIdWorkflowEDLConfigComponent
0%
0/22
0%
0/16
4
 
 1  
 /**
 2  
  * Copyright 2005-2011 The Kuali Foundation
 3  
  *
 4  
  * Licensed under the Educational Community License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  * http://www.opensource.org/licenses/ecl2.php
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  */
 16  
 package org.kuali.rice.edl.impl.components;
 17  
 
 18  
 import org.kuali.rice.edl.impl.EDLXmlUtils;
 19  
 import org.kuali.rice.edl.impl.RequestParser;
 20  
 import org.kuali.rice.kim.api.identity.principal.Principal;
 21  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 22  
 import org.w3c.dom.Element;
 23  
 import org.w3c.dom.NodeList;
 24  
 
 25  
 
 26  
 /**
 27  
  * Matches network ID param to UserService to validate network Id.  Returns error message if networkId does NOT match.
 28  
  * 
 29  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 30  
  */
 31  0
 public class NetworkIdWorkflowEDLConfigComponent extends SimpleWorkflowEDLConfigComponent {
 32  
         
 33  0
         private boolean required = false;
 34  
         
 35  
         @Override
 36  
         public Element getReplacementConfigElement(Element element) {
 37  0
                 Element replacementEl = (Element)element.cloneNode(true);
 38  0
                 Element type = (Element)((NodeList)replacementEl.getElementsByTagName(EDLXmlUtils.TYPE_E)).item(0);
 39  0
                 type.setTextContent("text");
 40  
                 
 41  
                 //find the validation element if required is true set a boolean and determin if blanks
 42  
                 //are allowed based on that
 43  0
                 Element validation = (Element)((NodeList)replacementEl.getElementsByTagName(EDLXmlUtils.VALIDATION_E)).item(0);
 44  0
                 if (validation != null && validation.getAttribute("required").equals("true")) {
 45  0
                         required = true;
 46  
                 }
 47  0
                 return replacementEl;
 48  
         }
 49  
         
 50  
         @Override
 51  
         public String getErrorMessage(Element originalConfigElement, RequestParser requestParser, MatchingParam param) {
 52  0
         if (!getEdlContext().getUserAction().isValidatableAction()) {
 53  0
             return null;
 54  0
         } else if (param.getParamValue().length() == 0 && required == true) {
 55  
                         //empty and required so send error
 56  0
                         return ("Network ID is a required field");
 57  0
                 } else if (param.getParamValue().length() == 0 && required == false) { 
 58  
                         //empty but not required then just return 
 59  0
                         return null;                        
 60  
                 } else {
 61  
                         //not blank validate as normal whether required or not
 62  0
                         Principal principal = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(param.getParamValue());
 63  0
                         if (principal == null) {
 64  0
                                 return ("The value " + param.getParamValue() + " is an invalid principal name");
 65  
                         }
 66  
                 }
 67  0
                 return null;
 68  
         }
 69  
 
 70  
         public boolean isRequired() {
 71  0
                 return required;
 72  
         }
 73  
 
 74  
         public void setRequired(boolean required) {
 75  0
                 this.required = required;
 76  0
         }
 77  
 
 78  
 }