Coverage Report - org.kuali.rice.edl.impl.components.WorkgroupWorkflowEDLConfigComponent
 
Classes in this File Line Coverage Branch Coverage Complexity
WorkgroupWorkflowEDLConfigComponent
0%
0/26
0%
0/16
3.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.kew.service.KEWServiceLocator;
 21  
 import org.kuali.rice.kew.util.Utilities;
 22  
 import org.kuali.rice.kew.workgroup.GroupId;
 23  
 import org.kuali.rice.kew.workgroup.GroupNameId;
 24  
 import org.kuali.rice.kim.api.group.Group;
 25  
 import org.w3c.dom.Element;
 26  
 import org.w3c.dom.NodeList;
 27  
 
 28  
 /**
 29  
  * Looks up workgroup param to validate workgroup exists and is active.  Returns error message if workgroup is does not exist or is not active.
 30  
  * 
 31  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 32  
  */
 33  0
 public class WorkgroupWorkflowEDLConfigComponent extends SimpleWorkflowEDLConfigComponent {
 34  
         
 35  0
         private boolean required = false;
 36  
         
 37  
         protected GroupId resolveId(String id) {
 38  0
                 String groupName = Utilities.parseGroupName(id);
 39  0
             String namespace = Utilities.parseGroupNamespaceCode(id);
 40  0
                 return new GroupNameId(namespace, groupName);
 41  
         }
 42  
         
 43  
         @Override
 44  
         public Element getReplacementConfigElement(Element element) {
 45  0
                 Element replacementEl = (Element)element.cloneNode(true);
 46  0
                 Element type = (Element)((NodeList)replacementEl.getElementsByTagName(EDLXmlUtils.TYPE_E)).item(0);
 47  0
                 type.setTextContent("text");
 48  
                 
 49  
                 //find the validation element if required is true set a boolean and determine if blanks
 50  
                 //are allowed based on that
 51  0
                 Element validation = (Element)((NodeList)replacementEl.getElementsByTagName(EDLXmlUtils.VALIDATION_E)).item(0);
 52  0
                 if (validation != null && validation.getAttribute("required").equals("true")) {
 53  0
                         required = true;
 54  
                 }
 55  0
                 return replacementEl;
 56  
         }
 57  
         
 58  
         @Override
 59  
         public String getErrorMessage(Element originalConfigElement, RequestParser requestParser, MatchingParam param) {
 60  
                 
 61  0
                 if (param.getParamValue().length() == 0 && required == true) {
 62  
                         //empty and required so send error
 63  0
                         return ("Workgroup is a required field");
 64  0
                 } else if (param.getParamValue().length() == 0 && required == false) { 
 65  
                         //empty but not required then just return 
 66  0
                         return null;
 67  
                 }
 68  0
                 String wrkgrpName = param.getParamValue();
 69  
                 // TODO add support for namespace here!
 70  0
                 Group group = KEWServiceLocator.getIdentityHelperService().getGroup(resolveId(wrkgrpName));
 71  0
                 if (group == null) {
 72  0
                     return ("Group " + wrkgrpName + " not found.");
 73  
                 }
 74  0
                 if (!group.isActive()) {
 75  0
                     return ("Group " + wrkgrpName + " is not an active group.");
 76  
                 }
 77  0
                 return null;
 78  
         }
 79  
         
 80  
         public boolean isRequired() {
 81  0
                 return required;
 82  
         }
 83  
 
 84  
         public void setRequired(boolean required) {
 85  0
                 this.required = required;
 86  0
         }
 87  
 
 88  
 }