1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
package org.kuali.rice.kew.rule.web; |
17 | |
|
18 | |
import org.apache.log4j.Logger; |
19 | |
import org.apache.struts.action.ActionForm; |
20 | |
import org.apache.struts.action.ActionForward; |
21 | |
import org.apache.struts.action.ActionMapping; |
22 | |
import org.apache.struts.action.ActionMessages; |
23 | |
import org.kuali.rice.core.api.config.property.ConfigContext; |
24 | |
import org.kuali.rice.core.api.criteria.Predicate; |
25 | |
import org.kuali.rice.core.api.criteria.QueryByCriteria; |
26 | |
import org.kuali.rice.kew.doctype.bo.DocumentType; |
27 | |
import org.kuali.rice.kew.doctype.service.DocumentTypeService; |
28 | |
import org.kuali.rice.kew.engine.node.BranchPrototype; |
29 | |
import org.kuali.rice.kew.engine.node.RouteNode; |
30 | |
import org.kuali.rice.kew.engine.node.RouteNodeConfigParam; |
31 | |
import org.kuali.rice.kew.rule.RuleBaseValues; |
32 | |
import org.kuali.rice.kew.rule.bo.RuleTemplateBo; |
33 | |
import org.kuali.rice.kew.rule.service.RuleServiceInternal; |
34 | |
import org.kuali.rice.kew.service.KEWServiceLocator; |
35 | |
import org.kuali.rice.kew.api.KewApiConstants; |
36 | |
import org.kuali.rice.kew.web.KewKualiAction; |
37 | |
import org.kuali.rice.kim.api.KimConstants; |
38 | |
import org.kuali.rice.kim.api.group.Group; |
39 | |
import org.kuali.rice.kim.api.permission.Permission; |
40 | |
import org.kuali.rice.kim.api.responsibility.Responsibility; |
41 | |
import org.kuali.rice.kim.api.services.KimApiServiceLocator; |
42 | |
import org.kuali.rice.kns.service.KNSServiceLocator; |
43 | |
import org.kuali.rice.kns.service.MaintenanceDocumentDictionaryService; |
44 | |
import org.kuali.rice.krad.service.DocumentHelperService; |
45 | |
import org.kuali.rice.krad.service.KRADServiceLocatorWeb; |
46 | |
import org.kuali.rice.krad.util.GlobalVariables; |
47 | |
import org.kuali.rice.krad.util.KRADConstants; |
48 | |
|
49 | |
import javax.servlet.http.HttpServletRequest; |
50 | |
import javax.servlet.http.HttpServletResponse; |
51 | |
import java.util.ArrayList; |
52 | |
import java.util.HashMap; |
53 | |
import java.util.Iterator; |
54 | |
import java.util.List; |
55 | |
import java.util.Map; |
56 | |
|
57 | |
import static org.kuali.rice.core.api.criteria.PredicateFactory.and; |
58 | |
import static org.kuali.rice.core.api.criteria.PredicateFactory.equal; |
59 | |
|
60 | |
|
61 | |
|
62 | |
|
63 | |
|
64 | |
|
65 | |
|
66 | 0 | public class RuleQuickLinksAction extends KewKualiAction { |
67 | |
|
68 | 0 | private static final Logger LOG = Logger.getLogger(RuleQuickLinksAction.class); |
69 | |
|
70 | |
private MaintenanceDocumentDictionaryService maintenanceDocumentDictionaryService; |
71 | |
private DocumentHelperService documentHelperService; |
72 | |
|
73 | |
public ActionForward start(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
74 | 0 | makeLookupPathParam(mapping, request); |
75 | 0 | establishRequiredState(request, form); |
76 | 0 | return mapping.findForward("basic"); |
77 | |
} |
78 | |
|
79 | |
@SuppressWarnings("unchecked") |
80 | |
public ActionMessages establishRequiredState(HttpServletRequest request, ActionForm form) throws Exception { |
81 | 0 | RuleQuickLinksForm qlForm = (RuleQuickLinksForm) form; |
82 | |
List<DocumentType> documentTypes; |
83 | 0 | if (qlForm.getRootDocTypeName() != null) { |
84 | 0 | documentTypes = new ArrayList<DocumentType>(); |
85 | 0 | DocumentType docType = getDocumentTypeService().findByName(qlForm.getRootDocTypeName()); |
86 | 0 | documentTypes.add(docType); |
87 | 0 | request.setAttribute("renderOpened", Boolean.TRUE); |
88 | 0 | } else { |
89 | 0 | documentTypes = getDocumentTypeService().findAllCurrentRootDocuments(); |
90 | |
} |
91 | 0 | qlForm.setDocumentTypeQuickLinksStructures(getDocumentTypeDataStructure(documentTypes)); |
92 | 0 | int shouldDisplayCount = 0; |
93 | 0 | for ( DocumentTypeQuickLinksStructure dt : qlForm.getDocumentTypeQuickLinksStructures() ) { |
94 | 0 | if ( dt.isShouldDisplay() ) { |
95 | 0 | shouldDisplayCount++; |
96 | |
} |
97 | |
} |
98 | 0 | if ( shouldDisplayCount == 1 ) { |
99 | 0 | request.setAttribute("renderOpened", Boolean.TRUE); |
100 | |
} |
101 | 0 | String documentTypeName = getMaintenanceDocumentDictionaryService().getDocumentTypeName(DocumentType.class); |
102 | |
try { |
103 | 0 | if ((documentTypeName != null) && getDocumentHelperService().getDocumentAuthorizer(documentTypeName).canInitiate(documentTypeName, GlobalVariables.getUserSession().getPerson())) { |
104 | 0 | qlForm.setCanInitiateDocumentTypeDocument( true ); |
105 | |
} |
106 | 0 | } catch (Exception ex) { |
107 | |
|
108 | 0 | LOG.error( "Unable to check initiation permission for "+ documentTypeName, ex ); |
109 | 0 | } |
110 | |
|
111 | 0 | return null; |
112 | |
} |
113 | |
|
114 | |
public ActionForward addDelegationRule(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { |
115 | 0 | ActionForward result = null; |
116 | |
|
117 | 0 | String ruleTemplateId = request.getParameter("delegationRuleBaseValues.ruleTemplate.ruleTemplateId"); |
118 | 0 | String docTypeName = request.getParameter("delegationRuleBaseValues.documentType.name"); |
119 | 0 | List rules = getRuleService().search(docTypeName, null, ruleTemplateId, "", null, null, Boolean.FALSE, Boolean.TRUE, new HashMap(), null); |
120 | |
|
121 | 0 | if (rules.size() == 1) { |
122 | 0 | RuleBaseValues rule = (RuleBaseValues)rules.get(0); |
123 | 0 | String url = ConfigContext.getCurrentContextConfig().getKEWBaseURL() + |
124 | |
"/DelegateRule.do?methodToCall=start" + |
125 | |
"&parentRuleId=" + rule.getId(); |
126 | 0 | result = new ActionForward(url, true); |
127 | 0 | } else { |
128 | 0 | makeLookupPathParam(mapping, request); |
129 | 0 | result = new ActionForward(ConfigContext.getCurrentContextConfig().getKRBaseURL() + |
130 | |
"/lookup.do?methodToCall=start&"+ stripMethodToCall(request.getQueryString()), true); |
131 | |
} |
132 | |
|
133 | 0 | return result; |
134 | |
} |
135 | |
|
136 | |
private List getDocumentTypeDataStructure(List rootDocuments) { |
137 | 0 | List documentTypeQuickLinksStructures = new ArrayList(); |
138 | 0 | for (Iterator iter = rootDocuments.iterator(); iter.hasNext();) { |
139 | 0 | DocumentTypeQuickLinksStructure quickLinkStruct =new DocumentTypeQuickLinksStructure((DocumentType) iter.next()); |
140 | 0 | if (! quickLinkStruct.getFlattenedNodes().isEmpty() || ! quickLinkStruct.getChildrenDocumentTypes().isEmpty()) { |
141 | 0 | documentTypeQuickLinksStructures.add(quickLinkStruct); |
142 | |
} |
143 | |
|
144 | 0 | } |
145 | |
|
146 | 0 | return documentTypeQuickLinksStructures; |
147 | |
} |
148 | |
|
149 | |
|
150 | |
|
151 | |
|
152 | |
|
153 | |
|
154 | |
|
155 | |
|
156 | 0 | public static class DocumentTypeQuickLinksStructure { |
157 | |
private DocumentType documentType; |
158 | 0 | private List<RouteNode> flattenedNodes = new ArrayList<RouteNode>(); |
159 | 0 | private List<DocumentTypeQuickLinksStructure> childrenDocumentTypes = new ArrayList<DocumentTypeQuickLinksStructure>(); |
160 | 0 | private List<Permission> permissions = null; |
161 | |
|
162 | 0 | private DocumentTypeQuickLinksStructure(DocumentType documentType) { |
163 | 0 | this.documentType = documentType; |
164 | 0 | if ( documentType != null ) { |
165 | 0 | List<RouteNode> tempFlattenedNodes = KEWServiceLocator.getRouteNodeService() |
166 | |
.getFlattenedNodes( documentType, true ); |
167 | 0 | for ( RouteNode routeNode : tempFlattenedNodes ) { |
168 | 0 | if ( routeNode.isFlexRM() || routeNode.isRoleNode() ) { |
169 | 0 | flattenedNodes.add( new RouteNodeForDisplay( routeNode ) ); |
170 | |
} |
171 | |
} |
172 | 0 | for ( Iterator<DocumentType> iter = documentType.getChildrenDocTypes().iterator(); iter.hasNext(); ) { |
173 | 0 | childrenDocumentTypes.add( new DocumentTypeQuickLinksStructure( iter.next() ) ); |
174 | |
} |
175 | |
} |
176 | 0 | } |
177 | |
|
178 | |
public List getChildrenDocumentTypes() { |
179 | 0 | return childrenDocumentTypes; |
180 | |
} |
181 | |
public void setChildrenDocumentTypes(List<DocumentTypeQuickLinksStructure> childrenDocumentTypes) { |
182 | 0 | this.childrenDocumentTypes = childrenDocumentTypes; |
183 | 0 | } |
184 | |
public DocumentType getDocumentType() { |
185 | 0 | return documentType; |
186 | |
} |
187 | |
public void setDocumentType(DocumentType documentType) { |
188 | 0 | this.documentType = documentType; |
189 | 0 | } |
190 | |
public List getFlattenedNodes() { |
191 | 0 | return flattenedNodes; |
192 | |
} |
193 | |
public void setFlattenedNodes(List<RouteNode> flattenedNodes) { |
194 | 0 | this.flattenedNodes = flattenedNodes; |
195 | 0 | } |
196 | |
public boolean isShouldDisplay() { |
197 | |
|
198 | |
|
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | 0 | return true; |
206 | |
} |
207 | |
|
208 | |
public List<Permission> getPermissions() { |
209 | 0 | if ( permissions == null ) { |
210 | 0 | Predicate p = and( |
211 | |
equal("attributeName", "documentTypeName"), |
212 | |
equal("active", "Y"), |
213 | |
equal("detailCriteria", |
214 | |
KimConstants.AttributeConstants.DOCUMENT_TYPE_NAME+"="+getDocumentType().getName())); |
215 | 0 | permissions = KimApiServiceLocator.getPermissionService().findPermissions( QueryByCriteria.Builder.fromPredicates(p)).getResults(); |
216 | |
|
217 | |
} |
218 | 0 | return permissions; |
219 | |
} |
220 | |
|
221 | |
public boolean isHasRelatedPermissions() { |
222 | 0 | return !getPermissions().isEmpty(); |
223 | |
} |
224 | |
|
225 | |
public int getRelatedPermissionCount() { |
226 | 0 | return getPermissions().size(); |
227 | |
} |
228 | |
} |
229 | |
|
230 | 0 | public static class RouteNodeForDisplay extends RouteNode { |
231 | |
private static final long serialVersionUID = 1L; |
232 | |
private RouteNode baseNode; |
233 | |
|
234 | 0 | public RouteNodeForDisplay( RouteNode baseNode ) { |
235 | 0 | this.baseNode = baseNode; |
236 | 0 | } |
237 | |
|
238 | |
public boolean equals(Object obj) { |
239 | 0 | return this.baseNode.equals(obj); |
240 | |
} |
241 | |
|
242 | |
public String getActivationType() { |
243 | 0 | return this.baseNode.getActivationType(); |
244 | |
} |
245 | |
|
246 | |
public BranchPrototype getBranch() { |
247 | 0 | return this.baseNode.getBranch(); |
248 | |
} |
249 | |
|
250 | |
public List<RouteNodeConfigParam> getConfigParams() { |
251 | 0 | return this.baseNode.getConfigParams(); |
252 | |
} |
253 | |
|
254 | |
public String getContentFragment() { |
255 | 0 | return this.baseNode.getContentFragment(); |
256 | |
} |
257 | |
|
258 | |
public DocumentType getDocumentType() { |
259 | 0 | return this.baseNode.getDocumentType(); |
260 | |
} |
261 | |
|
262 | |
public String getDocumentTypeId() { |
263 | 0 | return this.baseNode.getDocumentTypeId(); |
264 | |
} |
265 | |
public Group getExceptionWorkgroup() { |
266 | 0 | return this.baseNode.getExceptionWorkgroup(); |
267 | |
} |
268 | |
public String getExceptionWorkgroupId() { |
269 | 0 | return this.baseNode.getExceptionWorkgroupId(); |
270 | |
} |
271 | |
public String getExceptionWorkgroupName() { |
272 | 0 | return this.baseNode.getExceptionWorkgroupName(); |
273 | |
} |
274 | |
public Boolean getFinalApprovalInd() { |
275 | 0 | return this.baseNode.getFinalApprovalInd(); |
276 | |
} |
277 | |
public Integer getLockVerNbr() { |
278 | 0 | return this.baseNode.getLockVerNbr(); |
279 | |
} |
280 | |
public Boolean getMandatoryRouteInd() { |
281 | 0 | return this.baseNode.getMandatoryRouteInd(); |
282 | |
} |
283 | |
public List<RouteNode> getNextNodes() { |
284 | 0 | return this.baseNode.getNextNodes(); |
285 | |
} |
286 | |
public String getNodeType() { |
287 | 0 | return this.baseNode.getNodeType(); |
288 | |
} |
289 | |
public List<RouteNode> getPreviousNodes() { |
290 | 0 | return this.baseNode.getPreviousNodes(); |
291 | |
} |
292 | |
public String getRouteMethodCode() { |
293 | 0 | return this.baseNode.getRouteMethodCode(); |
294 | |
} |
295 | |
public String getRouteMethodName() { |
296 | 0 | return this.baseNode.getRouteMethodName(); |
297 | |
} |
298 | |
public String getRouteNodeId() { |
299 | 0 | return this.baseNode.getRouteNodeId(); |
300 | |
} |
301 | |
public String getRouteNodeName() { |
302 | 0 | return this.baseNode.getRouteNodeName(); |
303 | |
} |
304 | |
public RuleTemplateBo getRuleTemplate() { |
305 | 0 | return this.baseNode.getRuleTemplate(); |
306 | |
} |
307 | |
public int hashCode() { |
308 | 0 | return this.baseNode.hashCode(); |
309 | |
} |
310 | |
public boolean isExceptionGroupDefined() { |
311 | 0 | return this.baseNode.isExceptionGroupDefined(); |
312 | |
} |
313 | |
public boolean isFlexRM() { |
314 | 0 | return this.baseNode.isFlexRM(); |
315 | |
} |
316 | |
public boolean isRoleNode() { |
317 | 0 | return this.baseNode.isRoleNode(); |
318 | |
} |
319 | |
public String toString() { |
320 | 0 | return this.baseNode.toString(); |
321 | |
} |
322 | |
|
323 | 0 | private List<Responsibility> responsibilities = null; |
324 | |
|
325 | |
public List<Responsibility> getResponsibilities() { |
326 | 0 | if ( responsibilities == null ) { |
327 | 0 | QueryByCriteria.Builder builder = QueryByCriteria.Builder.create(); |
328 | 0 | Predicate p = and( |
329 | |
equal("template.namespaceCode", KRADConstants.KUALI_RICE_WORKFLOW_NAMESPACE), |
330 | |
equal("template.name", KewApiConstants.DEFAULT_RESPONSIBILITY_TEMPLATE_NAME), |
331 | |
equal("active", "Y"), |
332 | |
equal("attributes[documentTypeName]", getDocumentType().getName()), |
333 | |
equal("attributes[routeNodeName]", getRouteNodeName()) |
334 | |
); |
335 | 0 | builder.setPredicates(p); |
336 | 0 | responsibilities = KimApiServiceLocator.getResponsibilityService().findResponsibilities(builder.build()).getResults(); |
337 | |
} |
338 | 0 | return responsibilities; |
339 | |
} |
340 | |
|
341 | |
public int getResponsibilityCount() { |
342 | 0 | return getResponsibilities().size(); |
343 | |
} |
344 | |
|
345 | |
public boolean isHasResponsibility() { |
346 | 0 | return !getResponsibilities().isEmpty(); |
347 | |
} |
348 | |
} |
349 | |
|
350 | |
private void makeLookupPathParam(ActionMapping mapping, HttpServletRequest request) { |
351 | 0 | String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + mapping.getModuleConfig().getPrefix(); |
352 | 0 | request.setAttribute("basePath", basePath); |
353 | 0 | } |
354 | |
|
355 | |
private String stripMethodToCall(String queryString) { |
356 | 0 | return queryString.replaceAll("methodToCall=addDelegationRule&", ""); |
357 | |
} |
358 | |
|
359 | |
private DocumentTypeService getDocumentTypeService() { |
360 | 0 | return KEWServiceLocator.getDocumentTypeService(); |
361 | |
} |
362 | |
|
363 | |
private RuleServiceInternal getRuleService() { |
364 | 0 | return KEWServiceLocator.getRuleService(); |
365 | |
} |
366 | |
|
367 | |
public DocumentHelperService getDocumentHelperService() { |
368 | 0 | if(documentHelperService == null){ |
369 | 0 | documentHelperService = KRADServiceLocatorWeb.getDocumentHelperService(); |
370 | |
} |
371 | 0 | return documentHelperService; |
372 | |
} |
373 | |
|
374 | |
public MaintenanceDocumentDictionaryService getMaintenanceDocumentDictionaryService() { |
375 | 0 | if(maintenanceDocumentDictionaryService == null){ |
376 | 0 | maintenanceDocumentDictionaryService = KNSServiceLocator.getMaintenanceDocumentDictionaryService(); |
377 | |
} |
378 | 0 | return maintenanceDocumentDictionaryService; |
379 | |
} |
380 | |
|
381 | |
@Override |
382 | |
public ActionForward toggleTab(ActionMapping mapping, ActionForm form, |
383 | |
HttpServletRequest request, HttpServletResponse response) |
384 | |
throws Exception { |
385 | |
|
386 | 0 | establishRequiredState(request, form); |
387 | 0 | return super.toggleTab(mapping, form, request, response); |
388 | |
} |
389 | |
|
390 | |
} |