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