1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
34
35
36
37
38 public class SimulationCriteria {
39
40
41 private String documentId;
42 private String destinationNodeName;
43 private List<Recipient> destinationRecipients = new ArrayList<Recipient>();
44
45
46 private String documentTypeName;
47 private String xmlContent;
48 private List<String> nodeNames = new ArrayList<String>();
49 private List<String> ruleTemplateNames = new ArrayList<String>();
50
51
52 private Boolean activateRequests;
53 private Person routingUser;
54 private List<SimulationActionToTake> actionsToTake = new ArrayList<SimulationActionToTake>();
55 private boolean flattenNodes;
56
57 public SimulationCriteria() {
58 this.activateRequests = null;
59 this.flattenNodes = false;
60 }
61
62 public static SimulationCriteria createSimulationCritUsingDocumentId(String documentId) {
63 return new SimulationCriteria(null, documentId);
64 }
65
66 public static SimulationCriteria createSimulationCritUsingDocTypeName(String documentTypeName) {
67 return new SimulationCriteria(documentTypeName, null);
68 }
69
70 private SimulationCriteria(String documentTypeName, String documentId) {
71 if (StringUtils.isNotBlank(documentId)) {
72 this.documentId = documentId;
73 } else if (StringUtils.isNotBlank(documentTypeName)) {
74 this.documentTypeName = documentTypeName;
75 }
76 }
77
78 public Boolean isActivateRequests() {
79 return this.activateRequests;
80 }
81
82 public void setActivateRequests(Boolean activateRequests) {
83 this.activateRequests = activateRequests;
84 }
85
86 public String getDocumentId() {
87 return documentId;
88 }
89
90 public void setDocumentId(String documentId) {
91 this.documentId = documentId;
92 }
93
94 public String getDestinationNodeName() {
95 return destinationNodeName;
96 }
97
98 public void setDestinationNodeName(String destinationNodeName) {
99 this.destinationNodeName = destinationNodeName;
100 }
101
102 public List<Recipient> getDestinationRecipients() {
103 return destinationRecipients;
104 }
105
106 public void setDestinationRecipients(List<Recipient> destinationRecipients) {
107 this.destinationRecipients = destinationRecipients;
108 }
109
110 public String getDocumentTypeName() {
111 return documentTypeName;
112 }
113
114 public void setDocumentTypeName(String documentTypeName) {
115 this.documentTypeName = documentTypeName;
116 }
117
118 public List<String> getRuleTemplateNames() {
119 return ruleTemplateNames;
120 }
121
122 public void setRuleTemplateNames(List<String> ruleTemplateNames) {
123 this.ruleTemplateNames = ruleTemplateNames;
124 }
125
126 public String getXmlContent() {
127 return xmlContent;
128 }
129
130 public void setXmlContent(String xmlContent) {
131 this.xmlContent = xmlContent;
132 }
133
134 public List<String> getNodeNames() {
135 return nodeNames;
136 }
137
138 public void setNodeNames(List<String> nodeNames) {
139 this.nodeNames = nodeNames;
140 }
141
142 public boolean isDocumentSimulation() {
143 return documentId != null;
144 }
145
146 public boolean isDocumentTypeSimulation() {
147 return !org.apache.commons.lang.StringUtils.isEmpty(documentTypeName);
148 }
149
150 public List<SimulationActionToTake> getActionsToTake() {
151 return actionsToTake;
152 }
153
154 public void setActionsToTake(List<SimulationActionToTake> actionsToTake) {
155 this.actionsToTake = actionsToTake;
156 }
157
158 public Person getRoutingUser() {
159 return routingUser;
160 }
161
162 public void setRoutingUser(Person routingUser) {
163 this.routingUser = routingUser;
164 }
165
166 public boolean isFlattenNodes() {
167 return this.flattenNodes;
168 }
169
170 public void setFlattenNodes(boolean flattenNodes) {
171 this.flattenNodes = flattenNodes;
172 }
173
174 public static SimulationCriteria from(RoutingReportCriteria criteriaVO) {
175 if (criteriaVO == null) {
176 return null;
177 }
178 SimulationCriteria criteria = new SimulationCriteria();
179 criteria.setDestinationNodeName(criteriaVO.getTargetNodeName());
180 criteria.setDocumentId(criteriaVO.getDocumentId());
181 criteria.setDocumentTypeName(criteriaVO.getDocumentTypeName());
182 criteria.setXmlContent(criteriaVO.getXmlContent());
183 criteria.setActivateRequests(criteriaVO.isActivateRequests());
184 criteria.setFlattenNodes(criteriaVO.isFlattenNodes());
185 if (criteriaVO.getRoutingPrincipalId() != null) {
186 Principal kPrinc = KEWServiceLocator.getIdentityHelperService().
187 getPrincipal(criteriaVO.getRoutingPrincipalId());
188 Person user = KimApiServiceLocator.getPersonService().getPerson(kPrinc.getPrincipalId());
189 if (user == null) {
190 throw new RiceRuntimeException(
191 "Could not locate user for the given id: " + criteriaVO.getRoutingPrincipalId());
192 }
193 criteria.setRoutingUser(user);
194 }
195 if (criteriaVO.getRuleTemplateNames() != null) {
196 criteria.setRuleTemplateNames(criteriaVO.getRuleTemplateNames());
197 }
198 if (criteriaVO.getNodeNames() != null) {
199 criteria.setNodeNames(criteriaVO.getNodeNames());
200 }
201 if (criteriaVO.getTargetPrincipalIds() != null) {
202 for (String targetPrincipalId : criteriaVO.getTargetPrincipalIds()) {
203 Principal principal = KEWServiceLocator.getIdentityHelperService().getPrincipal(targetPrincipalId);
204 criteria.getDestinationRecipients().add(new KimPrincipalRecipient(principal));
205 }
206 }
207
208 if (criteriaVO.getActionsToTake() != null) {
209 for (RoutingReportActionToTake actionToTake : criteriaVO.getActionsToTake()) {
210 criteria.getActionsToTake().add(SimulationActionToTake.from(actionToTake));
211 }
212 }
213
214 return criteria;
215 }
216 }