001/** 002 * Copyright 2005-2016 The Kuali Foundation 003 * 004 * Licensed under the Educational Community License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.opensource.org/licenses/ecl2.php 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.kuali.rice.kew.api.action; 017 018import java.io.Serializable; 019import java.util.ArrayList; 020import java.util.Collection; 021import java.util.Collections; 022import java.util.List; 023import javax.xml.bind.annotation.XmlAccessType; 024import javax.xml.bind.annotation.XmlAccessorType; 025import javax.xml.bind.annotation.XmlAnyElement; 026import javax.xml.bind.annotation.XmlElement; 027import javax.xml.bind.annotation.XmlElementWrapper; 028import javax.xml.bind.annotation.XmlRootElement; 029import javax.xml.bind.annotation.XmlType; 030 031import org.kuali.rice.core.api.CoreConstants; 032import org.kuali.rice.core.api.mo.AbstractDataTransferObject; 033import org.kuali.rice.core.api.mo.ModelBuilder; 034import org.w3c.dom.Element; 035 036@XmlRootElement(name = RoutingReportCriteria.Constants.ROOT_ELEMENT_NAME) 037@XmlAccessorType(XmlAccessType.NONE) 038@XmlType(name = RoutingReportCriteria.Constants.TYPE_NAME, propOrder = { 039 RoutingReportCriteria.Elements.DOCUMENT_ID, 040 RoutingReportCriteria.Elements.TARGET_NODE_NAME, 041 RoutingReportCriteria.Elements.TARGET_PRINCIPAL_IDS, 042 RoutingReportCriteria.Elements.ROUTING_PRINCIPAL_ID, 043 RoutingReportCriteria.Elements.DOCUMENT_TYPE_NAME, 044 RoutingReportCriteria.Elements.XML_CONTENT, 045 RoutingReportCriteria.Elements.RULE_TEMPLATE_NAMES, 046 RoutingReportCriteria.Elements.NODE_NAMES, 047 RoutingReportCriteria.Elements.ACTIONS_TO_TAKE, 048 RoutingReportCriteria.Elements.ACTIVATE_REQUESTS, 049 RoutingReportCriteria.Elements.FLATTEN_NODES, 050 CoreConstants.CommonElements.FUTURE_ELEMENTS}) 051public final class RoutingReportCriteria extends AbstractDataTransferObject implements RoutingReportCriteriaContract { 052 053 @XmlElement(name = Elements.DOCUMENT_ID, required = false) 054 private final String documentId; 055 056 @XmlElement(name = Elements.TARGET_NODE_NAME, required = false) 057 private final String targetNodeName; 058 059 @XmlElementWrapper(name = Elements.TARGET_PRINCIPAL_IDS, required = false) 060 @XmlElement(name = Elements.TARGET_PRINCIPAL_ID, required = false) 061 private final List<String> targetPrincipalIds; 062 063 @XmlElement(name = Elements.ROUTING_PRINCIPAL_ID, required = false) 064 private final String routingPrincipalId; 065 066 @XmlElement(name = Elements.DOCUMENT_TYPE_NAME, required = false) 067 private final String documentTypeName; 068 069 @XmlElement(name = Elements.XML_CONTENT, required = false) 070 private final String xmlContent; 071 072 @XmlElementWrapper(name = Elements.RULE_TEMPLATE_NAMES, required = false) 073 @XmlElement(name = Elements.RULE_TEMPLATE_NAME, required = false) 074 private final List<String> ruleTemplateNames; 075 076 @XmlElementWrapper(name = Elements.NODE_NAMES, required = false) 077 @XmlElement(name = Elements.NODE_NAME, required = false) 078 private final List<String> nodeNames; 079 080 @XmlElementWrapper(name = Elements.ACTIONS_TO_TAKE, required = false) 081 @XmlElement(name = Elements.ACTION_TO_TAKE, required = false) 082 private final List<RoutingReportActionToTake> actionsToTake; 083 084 @XmlElement(name = Elements.ACTIVATE_REQUESTS, required = false) 085 private final boolean activateRequests; 086 087 @XmlElement(name = Elements.FLATTEN_NODES, required = false) 088 private final boolean flattenNodes; 089 090 @SuppressWarnings("unused") 091 @XmlAnyElement 092 private final Collection<Element> _futureElements = null; 093 094 /** 095 * Private constructor used only by JAXB. 096 */ 097 private RoutingReportCriteria() { 098 this.documentId = null; 099 this.targetNodeName = null; 100 this.targetPrincipalIds = null; 101 this.routingPrincipalId = null; 102 this.documentTypeName = null; 103 this.xmlContent = null; 104 this.ruleTemplateNames = null; 105 this.nodeNames = null; 106 this.actionsToTake = null; 107 this.flattenNodes = false; 108 this.activateRequests = false; 109 } 110 111 private RoutingReportCriteria(Builder builder) { 112 this.documentId = builder.getDocumentId(); 113 this.targetNodeName = builder.getTargetNodeName(); 114 this.targetPrincipalIds = builder.getTargetPrincipalIds(); 115 this.routingPrincipalId = builder.getRoutingPrincipalId(); 116 this.documentTypeName = builder.getDocumentTypeName(); 117 this.xmlContent = builder.getXmlContent(); 118 this.ruleTemplateNames = builder.getRuleTemplateNames(); 119 this.nodeNames = builder.getNodeNames(); 120 if (builder.getActionsToTake() != null) { 121 List<RoutingReportActionToTake> actions = new ArrayList<RoutingReportActionToTake>(); 122 for (RoutingReportActionToTake.Builder actionBuilder : builder.getActionsToTake()) { 123 actions.add(actionBuilder.build()); 124 } 125 this.actionsToTake = actions; 126 } else { 127 this.actionsToTake = Collections.emptyList(); 128 } 129 this.flattenNodes = builder.isFlattenNodes(); 130 this.activateRequests = builder.isActivateRequests(); 131 } 132 133 @Override 134 public String getDocumentId() { 135 return this.documentId; 136 } 137 138 @Override 139 public String getTargetNodeName() { 140 return this.targetNodeName; 141 } 142 143 @Override 144 public List<String> getTargetPrincipalIds() { 145 return this.targetPrincipalIds; 146 } 147 148 @Override 149 public String getRoutingPrincipalId() { 150 return this.routingPrincipalId; 151 } 152 153 @Override 154 public String getDocumentTypeName() { 155 return this.documentTypeName; 156 } 157 158 @Override 159 public String getXmlContent() { 160 return this.xmlContent; 161 } 162 163 @Override 164 public List<String> getRuleTemplateNames() { 165 return this.ruleTemplateNames; 166 } 167 168 @Override 169 public List<String> getNodeNames() { 170 return this.nodeNames; 171 } 172 173 @Override 174 public List<RoutingReportActionToTake> getActionsToTake() { 175 return this.actionsToTake; 176 } 177 178 @Override 179 public boolean isActivateRequests() { 180 return this.activateRequests; 181 } 182 183 @Override 184 public boolean isFlattenNodes() { 185 return this.flattenNodes; 186 } 187 188 /** 189 * A builder which can be used to construct {@link RoutingReportCriteria} instances. Enforces the constraints of 190 * the {@link RoutingReportCriteriaContract}. 191 */ 192 public final static class Builder implements Serializable, ModelBuilder, RoutingReportCriteriaContract { 193 194 private String documentId; 195 private String targetNodeName; 196 private List<String> targetPrincipalIds; 197 private String routingPrincipalId; 198 private String documentTypeName; 199 private String xmlContent; 200 private List<String> ruleTemplateNames; 201 private List<String> nodeNames; 202 private List<RoutingReportActionToTake.Builder> actionsToTake; 203 private boolean activateRequests; 204 private boolean flattenNodes; 205 206 private Builder(String documentId, String targetNodeName) { 207 this.setDocumentId(documentId); 208 this.setTargetNodeName(targetNodeName); 209 } 210 211 private Builder(String documentTypeName) { 212 this.setDocumentTypeName(documentTypeName); 213 } 214 215 public static Builder createByDocumentTypeName(String documentTypeName) { 216 return new Builder(documentTypeName); 217 } 218 219 public static Builder createByDocumentId(String documentId) { 220 return new Builder(documentId, null); 221 } 222 223 public static Builder createByDocumentIdAndTargetNodeName(String documentId, String targetNodeName) { 224 return new Builder(documentId, targetNodeName); 225 } 226 227 public static Builder create(RoutingReportCriteriaContract contract) { 228 if (contract == null) { 229 throw new IllegalArgumentException("contract was null"); 230 } 231 Builder builder = 232 createByDocumentIdAndTargetNodeName(contract.getDocumentId(), contract.getTargetNodeName()); 233 builder.setDocumentId(contract.getDocumentId()); 234 builder.setTargetNodeName(contract.getTargetNodeName()); 235 builder.setTargetPrincipalIds(contract.getTargetPrincipalIds()); 236 builder.setRoutingPrincipalId(contract.getRoutingPrincipalId()); 237 builder.setDocumentTypeName(contract.getDocumentTypeName()); 238 builder.setXmlContent(contract.getXmlContent()); 239 builder.setRuleTemplateNames(contract.getRuleTemplateNames()); 240 builder.setNodeNames(contract.getNodeNames()); 241 if (contract.getActionsToTake() != null) { 242 List<RoutingReportActionToTake.Builder> actionsToTake = new ArrayList<RoutingReportActionToTake.Builder>(); 243 for (RoutingReportActionToTakeContract action : contract.getActionsToTake()) { 244 actionsToTake.add(RoutingReportActionToTake.Builder.create(action)); 245 } 246 builder.setActionsToTake(actionsToTake); 247 } 248 builder.setActivateRequests(contract.isActivateRequests()); 249 builder.setFlattenNodes(contract.isFlattenNodes()); 250 251 return builder; 252 } 253 254 public RoutingReportCriteria build() { 255 return new RoutingReportCriteria(this); 256 } 257 258 @Override 259 public String getDocumentId() { 260 return this.documentId; 261 } 262 263 @Override 264 public String getTargetNodeName() { 265 return this.targetNodeName; 266 } 267 268 @Override 269 public List<String> getTargetPrincipalIds() { 270 return this.targetPrincipalIds; 271 } 272 273 @Override 274 public String getRoutingPrincipalId() { 275 return this.routingPrincipalId; 276 } 277 278 @Override 279 public String getDocumentTypeName() { 280 return this.documentTypeName; 281 } 282 283 @Override 284 public String getXmlContent() { 285 return this.xmlContent; 286 } 287 288 @Override 289 public List<String> getRuleTemplateNames() { 290 return this.ruleTemplateNames; 291 } 292 293 @Override 294 public List<String> getNodeNames() { 295 return this.nodeNames; 296 } 297 298 @Override 299 public List<RoutingReportActionToTake.Builder> getActionsToTake() { 300 return this.actionsToTake; 301 } 302 303 @Override 304 public boolean isActivateRequests() { 305 return this.activateRequests; 306 } 307 308 @Override 309 public boolean isFlattenNodes() { 310 return this.flattenNodes; 311 } 312 313 public void setDocumentId(String documentId) { 314 // TODO add validation of input value if required and throw IllegalArgumentException if needed 315 this.documentId = documentId; 316 } 317 318 public void setTargetNodeName(String targetNodeName) { 319 // TODO add validation of input value if required and throw IllegalArgumentException if needed 320 this.targetNodeName = targetNodeName; 321 } 322 323 public void setTargetPrincipalIds(List<String> targetPrincipalIds) { 324 // TODO add validation of input value if required and throw IllegalArgumentException if needed 325 this.targetPrincipalIds = Collections.unmodifiableList(targetPrincipalIds); 326 } 327 328 public void setRoutingPrincipalId(String routingPrincipalId) { 329 // TODO add validation of input value if required and throw IllegalArgumentException if needed 330 this.routingPrincipalId = routingPrincipalId; 331 } 332 333 public void setDocumentTypeName(String documentTypeName) { 334 // TODO add validation of input value if required and throw IllegalArgumentException if needed 335 this.documentTypeName = documentTypeName; 336 } 337 338 public void setXmlContent(String xmlContent) { 339 // TODO add validation of input value if required and throw IllegalArgumentException if needed 340 this.xmlContent = xmlContent; 341 } 342 343 public void setRuleTemplateNames(List<String> ruleTemplateNames) { 344 // TODO add validation of input value if required and throw IllegalArgumentException if needed 345 this.ruleTemplateNames = Collections.unmodifiableList(ruleTemplateNames); 346 } 347 348 public void setNodeNames(List<String> nodeNames) { 349 // TODO add validation of input value if required and throw IllegalArgumentException if needed 350 this.nodeNames = Collections.unmodifiableList(nodeNames); 351 } 352 353 public void setActionsToTake(List<RoutingReportActionToTake.Builder> actionsToTake) { 354 // TODO add validation of input value if required and throw IllegalArgumentException if needed 355 this.actionsToTake = Collections.unmodifiableList(actionsToTake); 356 } 357 358 public void setActivateRequests(boolean activateRequests) { 359 // TODO add validation of input value if required and throw IllegalArgumentException if needed 360 this.activateRequests = activateRequests; 361 } 362 363 public void setFlattenNodes(boolean flattenNodes) { 364 // TODO add validation of input value if required and throw IllegalArgumentException if needed 365 this.flattenNodes = flattenNodes; 366 } 367 } 368 369 /** 370 * Defines some internal constants used on this class. 371 */ 372 static class Constants { 373 374 final static String ROOT_ELEMENT_NAME = "routingReportCriteria"; 375 final static String TYPE_NAME = "RoutingReportCriteriaType"; 376 } 377 378 /** 379 * A private class which exposes constants which define the XML element names to use when this object is marshalled 380 * to XML. 381 */ 382 static class Elements { 383 384 final static String DOCUMENT_ID = "documentId"; 385 final static String TARGET_NODE_NAME = "targetNodeName"; 386 final static String TARGET_PRINCIPAL_IDS = "targetPrincipalIds"; 387 final static String TARGET_PRINCIPAL_ID = "targetPrincipalId"; 388 final static String ROUTING_PRINCIPAL_ID = "routingPrincipalId"; 389 final static String DOCUMENT_TYPE_NAME = "documentTypeName"; 390 final static String XML_CONTENT = "xmlContent"; 391 final static String RULE_TEMPLATE_NAMES = "ruleTemplateNames"; 392 final static String RULE_TEMPLATE_NAME = "ruleTemplateName"; 393 final static String NODE_NAMES = "nodeNames"; 394 final static String NODE_NAME = "nodeName"; 395 final static String ACTIONS_TO_TAKE = "actionsToTake"; 396 final static String ACTION_TO_TAKE = "actionToTake"; 397 final static String ACTIVATE_REQUESTS = "activateRequests"; 398 final static String FLATTEN_NODES = "flattenNodes"; 399 } 400}