Coverage Report - org.kuali.rice.kew.engine.simulation.SimulationCriteria
 
Classes in this File Line Coverage Branch Coverage Complexity
SimulationCriteria
0%
0/79
0%
0/26
1.448
 
 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.kew.engine.simulation;
 17  
 
 18  
 import org.apache.commons.lang.StringUtils;
 19  
 import org.kuali.rice.core.api.exception.RiceRuntimeException;
 20  
 import org.kuali.rice.kew.actionrequest.KimPrincipalRecipient;
 21  
 import org.kuali.rice.kew.actionrequest.Recipient;
 22  
 import org.kuali.rice.kew.api.action.RoutingReportActionToTake;
 23  
 import org.kuali.rice.kew.api.action.RoutingReportCriteria;
 24  
 import org.kuali.rice.kew.service.KEWServiceLocator;
 25  
 import org.kuali.rice.kim.api.identity.Person;
 26  
 import org.kuali.rice.kim.api.identity.principal.Principal;
 27  
 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
 28  
 
 29  
 import java.util.ArrayList;
 30  
 import java.util.List;
 31  
 
 32  
 /**
 33  
  * Criteria which acts as input to the {@link SimulationEngine}.
 34  
  *
 35  
  * @author Kuali Rice Team (rice.collab@kuali.org)
 36  
  * @see SimulationEngine
 37  
  */
 38  
 public class SimulationCriteria {
 39  
 
 40  
     // fields related to document simulation
 41  
     private String documentId;
 42  
     private String destinationNodeName;
 43  0
     private List<Recipient> destinationRecipients = new ArrayList<Recipient>();
 44  
 
 45  
     // fields related to document type simulation
 46  
     private String documentTypeName;
 47  
     private String xmlContent;
 48  0
     private List<String> nodeNames = new ArrayList<String>();
 49  0
     private List<String> ruleTemplateNames = new ArrayList<String>();
 50  
 
 51  
     // fields related to both simulation types
 52  
     private Boolean activateRequests;
 53  
     private Person routingUser;
 54  0
     private List<SimulationActionToTake> actionsToTake = new ArrayList<SimulationActionToTake>();
 55  
     private boolean flattenNodes;
 56  
 
 57  0
     public SimulationCriteria() {
 58  0
         this.activateRequests = null;
 59  0
         this.flattenNodes = false;
 60  0
     }
 61  
 
 62  
     public static SimulationCriteria createSimulationCritUsingDocumentId(String documentId) {
 63  0
         return new SimulationCriteria(null, documentId);
 64  
     }
 65  
 
 66  
     public static SimulationCriteria createSimulationCritUsingDocTypeName(String documentTypeName) {
 67  0
         return new SimulationCriteria(documentTypeName, null);
 68  
     }
 69  
 
 70  0
     private SimulationCriteria(String documentTypeName, String documentId) {
 71  0
         if (StringUtils.isNotBlank(documentId)) {
 72  0
             this.documentId = documentId;
 73  0
         } else if (StringUtils.isNotBlank(documentTypeName)) {
 74  0
             this.documentTypeName = documentTypeName;
 75  
         }
 76  0
     }
 77  
 
 78  
     public Boolean isActivateRequests() {
 79  0
         return this.activateRequests;
 80  
     }
 81  
 
 82  
     public void setActivateRequests(Boolean activateRequests) {
 83  0
         this.activateRequests = activateRequests;
 84  0
     }
 85  
 
 86  
     public String getDocumentId() {
 87  0
         return documentId;
 88  
     }
 89  
 
 90  
     public void setDocumentId(String documentId) {
 91  0
         this.documentId = documentId;
 92  0
     }
 93  
 
 94  
     public String getDestinationNodeName() {
 95  0
         return destinationNodeName;
 96  
     }
 97  
 
 98  
     public void setDestinationNodeName(String destinationNodeName) {
 99  0
         this.destinationNodeName = destinationNodeName;
 100  0
     }
 101  
 
 102  
     public List<Recipient> getDestinationRecipients() {
 103  0
         return destinationRecipients;
 104  
     }
 105  
 
 106  
     public void setDestinationRecipients(List<Recipient> destinationRecipients) {
 107  0
         this.destinationRecipients = destinationRecipients;
 108  0
     }
 109  
 
 110  
     public String getDocumentTypeName() {
 111  0
         return documentTypeName;
 112  
     }
 113  
 
 114  
     public void setDocumentTypeName(String documentTypeName) {
 115  0
         this.documentTypeName = documentTypeName;
 116  0
     }
 117  
 
 118  
     public List<String> getRuleTemplateNames() {
 119  0
         return ruleTemplateNames;
 120  
     }
 121  
 
 122  
     public void setRuleTemplateNames(List<String> ruleTemplateNames) {
 123  0
         this.ruleTemplateNames = ruleTemplateNames;
 124  0
     }
 125  
 
 126  
     public String getXmlContent() {
 127  0
         return xmlContent;
 128  
     }
 129  
 
 130  
     public void setXmlContent(String xmlContent) {
 131  0
         this.xmlContent = xmlContent;
 132  0
     }
 133  
 
 134  
     public List<String> getNodeNames() {
 135  0
         return nodeNames;
 136  
     }
 137  
 
 138  
     public void setNodeNames(List<String> nodeNames) {
 139  0
         this.nodeNames = nodeNames;
 140  0
     }
 141  
 
 142  
     public boolean isDocumentSimulation() {
 143  0
         return documentId != null;
 144  
     }
 145  
 
 146  
     public boolean isDocumentTypeSimulation() {
 147  0
         return !org.apache.commons.lang.StringUtils.isEmpty(documentTypeName);
 148  
     }
 149  
 
 150  
     public List<SimulationActionToTake> getActionsToTake() {
 151  0
         return actionsToTake;
 152  
     }
 153  
 
 154  
     public void setActionsToTake(List<SimulationActionToTake> actionsToTake) {
 155  0
         this.actionsToTake = actionsToTake;
 156  0
     }
 157  
 
 158  
     public Person getRoutingUser() {
 159  0
         return routingUser;
 160  
     }
 161  
 
 162  
     public void setRoutingUser(Person routingUser) {
 163  0
         this.routingUser = routingUser;
 164  0
     }
 165  
 
 166  
     public boolean isFlattenNodes() {
 167  0
         return this.flattenNodes;
 168  
     }
 169  
 
 170  
     public void setFlattenNodes(boolean flattenNodes) {
 171  0
         this.flattenNodes = flattenNodes;
 172  0
     }
 173  
 
 174  
     public static SimulationCriteria from(RoutingReportCriteria criteriaVO) {
 175  0
         if (criteriaVO == null) {
 176  0
             return null;
 177  
         }
 178  0
         SimulationCriteria criteria = new SimulationCriteria();
 179  0
         criteria.setDestinationNodeName(criteriaVO.getTargetNodeName());
 180  0
         criteria.setDocumentId(criteriaVO.getDocumentId());
 181  0
         criteria.setDocumentTypeName(criteriaVO.getDocumentTypeName());
 182  0
         criteria.setXmlContent(criteriaVO.getXmlContent());
 183  0
         criteria.setActivateRequests(criteriaVO.isActivateRequests());
 184  0
         criteria.setFlattenNodes(criteriaVO.isFlattenNodes());
 185  0
         if (criteriaVO.getRoutingPrincipalId() != null) {
 186  0
             Principal kPrinc = KEWServiceLocator.getIdentityHelperService().
 187  
                     getPrincipal(criteriaVO.getRoutingPrincipalId());
 188  0
             Person user = KimApiServiceLocator.getPersonService().getPerson(kPrinc.getPrincipalId());
 189  0
             if (user == null) {
 190  0
                 throw new RiceRuntimeException(
 191  
                         "Could not locate user for the given id: " + criteriaVO.getRoutingPrincipalId());
 192  
             }
 193  0
             criteria.setRoutingUser(user);
 194  
         }
 195  0
         if (criteriaVO.getRuleTemplateNames() != null) {
 196  0
             criteria.setRuleTemplateNames(criteriaVO.getRuleTemplateNames());
 197  
         }
 198  0
         if (criteriaVO.getNodeNames() != null) {
 199  0
             criteria.setNodeNames(criteriaVO.getNodeNames());
 200  
         }
 201  0
         if (criteriaVO.getTargetPrincipalIds() != null) {
 202  0
             for (String targetPrincipalId : criteriaVO.getTargetPrincipalIds()) {
 203  0
                 Principal principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(targetPrincipalId);
 204  0
                 criteria.getDestinationRecipients().add(new KimPrincipalRecipient(principal));
 205  0
             }
 206  
         }
 207  
 
 208  0
         if (criteriaVO.getActionsToTake() != null) {
 209  0
             for (RoutingReportActionToTake actionToTake : criteriaVO.getActionsToTake()) {
 210  0
                 criteria.getActionsToTake().add(SimulationActionToTake.from(actionToTake));
 211  
             }
 212  
         }
 213  
 
 214  0
         return criteria;
 215  
     }
 216  
 }