Coverage Report - org.kuali.rice.ken.kew.ChannelReviewerRoleAttribute
 
Classes in this File Line Coverage Branch Coverage Complexity
ChannelReviewerRoleAttribute
0%
0/48
0%
0/10
2.167
 
 1  
 /*
 2  
  * Copyright 2007 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.ken.kew;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Collections;
 20  
 import java.util.List;
 21  
 import java.util.Map;
 22  
 
 23  
 import javax.xml.xpath.XPathExpressionException;
 24  
 
 25  
 import org.apache.log4j.Logger;
 26  
 import org.kuali.rice.kew.api.WorkflowRuntimeException;
 27  
 import org.kuali.rice.kew.engine.RouteContext;
 28  
 import org.kuali.rice.kew.identity.Id;
 29  
 import org.kuali.rice.kew.routeheader.DocumentContent;
 30  
 import org.kuali.rice.kew.rule.GenericRoleAttribute;
 31  
 import org.kuali.rice.kew.rule.QualifiedRoleName;
 32  
 import org.kuali.rice.kew.rule.Role;
 33  
 import org.kuali.rice.kew.rule.RuleExtension;
 34  
 import org.kuali.rice.kew.identity.PrincipalName;
 35  
 import org.kuali.rice.kew.workgroup.GroupNameId;
 36  
 
 37  
 
 38  
 /**
 39  
  * KEW RoleAttribute implementation that is responsible for encapsulating a list
 40  
  * of users and groups which are reviewers for a Notification Channel.
 41  
  * This implementation relies on the default XML form implemented by GenericRoleAttribute
 42  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 43  
  */
 44  
 public class ChannelReviewerRoleAttribute extends GenericRoleAttribute {
 45  0
     private static final Logger LOG = Logger.getLogger(ChannelReviewerRoleAttribute.class);
 46  
     private static final List<Role> SUPPORTED_ROLES;
 47  
     
 48  
     static {
 49  0
         Role reviewerRole = new Role(ChannelReviewerRoleAttribute.class, "reviewers", "Reviewers");
 50  0
         List<Role> tmp = new ArrayList<Role>(1);
 51  0
         tmp.add(reviewerRole);
 52  0
         SUPPORTED_ROLES = Collections.unmodifiableList(tmp);
 53  0
     }
 54  
 
 55  
     /**
 56  
      * Constructs a ChannelReviewerRoleAttribute.java.
 57  
      */
 58  
     public ChannelReviewerRoleAttribute() {
 59  0
         super("channelReviewers");
 60  0
         LOG.info("CHANNEL REVIEWER ROLE ATTRIBUTE CONSTRUCTOR");
 61  0
     }
 62  
 
 63  
     /**
 64  
      * @see org.kuali.rice.kew.rule.GenericRoleAttribute#isMatch(org.kuali.rice.kew.routeheader.DocumentContent, java.util.List)
 65  
      */
 66  
     @Override
 67  
     public boolean isMatch(DocumentContent docContent, List<RuleExtension> ruleExtensions) {
 68  0
         LOG.info("CHANNEL REVIEWER ROLE ATTRIBUTE IS MATCH");
 69  0
         return super.isMatch(docContent, ruleExtensions);
 70  
     }
 71  
 
 72  
     /**
 73  
      * @see org.kuali.rice.kew.rule.GenericWorkflowAttribute#getProperties()
 74  
      */
 75  
     @Override
 76  
     public Map<String, String> getProperties() {
 77  0
         LOG.info("CHANNEL REVIEWER ROLE ATTRIBUTE GETPROPERTIES");
 78  
         // intentionally unimplemented...not intending on using this attribute client-side
 79  0
         return null;
 80  
     }
 81  
 
 82  
     /**
 83  
      * @see org.kuali.rice.kew.rule.RoleAttribute#getRoleNames()
 84  
      */
 85  
     public List<Role> getRoleNames() {
 86  0
         LOG.info("CHANNEL REVIEWER ROLE ATTRIBUTE CALLED ROLENAMES");
 87  0
         return SUPPORTED_ROLES;
 88  
     }
 89  
     
 90  
     /**
 91  
      * @see org.kuali.rice.kew.rule.GenericRoleAttribute#getQualifiedRoleNames(java.lang.String, org.kuali.rice.kew.routeheader.DocumentContent)
 92  
      */
 93  
     @Override
 94  
     public List<String> getQualifiedRoleNames(String roleName, DocumentContent documentContent) {
 95  0
         List<String> qrn = new ArrayList<String>(1);
 96  0
         qrn.add(roleName);
 97  0
         return qrn;
 98  
     }
 99  
 
 100  
     /**
 101  
      * This looks at the reviewers list passed through from KEN and then resolves the individuals that need to actually approve 
 102  
      * the message.
 103  
      * @see org.kuali.rice.kew.rule.GenericRoleAttribute#resolveRecipients(org.kuali.rice.kew.engine.RouteContext, org.kuali.rice.kew.rule.QualifiedRoleName)
 104  
      */
 105  
     @Override
 106  
     protected List<Id> resolveRecipients(RouteContext routeContext, QualifiedRoleName qualifiedRoleName) {
 107  0
         LOG.info("CHANNEL REVIEWER ROLE ATTRIBUTE CALLED");
 108  0
         List<Id> ids = new ArrayList<Id>();
 109  
 
 110  0
         LOG.info("DOC CONTENT:" + routeContext.getDocumentContent().getDocContent());
 111  0
         LOG.info("ATTR CONTENT:" + routeContext.getDocumentContent().getAttributeContent());
 112  0
         DocumentContent dc = routeContext.getDocumentContent();
 113  
         List<Map<String, String>> attrs;
 114  
         try {
 115  0
             attrs = content.parseContent(dc.getAttributeContent());
 116  0
         } catch (XPathExpressionException xpee) {
 117  0
             throw new WorkflowRuntimeException("Error parsing ChannelReviewer role attribute content", xpee);
 118  0
         }
 119  
         
 120  0
         if (attrs.size() > 0) {
 121  0
             Map<String, String> values = attrs.get(0);
 122  0
             if (values != null) {
 123  
                 // iterate through all "fields" and accumulate a list of users and groups
 124  0
                 for (Map.Entry<String, String> entry: values.entrySet()) {
 125  0
                     String name = entry.getKey();
 126  0
                     String value = entry.getValue();
 127  0
                     LOG.info("Entry: " + name + "=" + value);
 128  
                     Id id;
 129  0
                     if (name.startsWith("user")) {
 130  0
                         LOG.info("Adding user: " + value);
 131  0
                         id = new PrincipalName(value);
 132  0
                         ids.add(id);
 133  0
                     } else if (name.startsWith("group")) {
 134  0
                         LOG.info("Adding group: " + value);
 135  0
                         id = new GroupNameId(value);
 136  0
                         ids.add(id);
 137  
                     } else {
 138  0
                         LOG.error("Invalid attribute value: " + name + "=" + value);
 139  
                     }
 140  0
                 }
 141  
             }
 142  0
         } else {
 143  0
             LOG.debug("No attribute content found for ChannelReviewerRoleAttribute");
 144  
         }
 145  
         
 146  0
         LOG.info("Returning ids: " + ids.size());
 147  0
         return ids;
 148  
     }
 149  
 }