1 package org.kuali.ole.select.controller;
2
3 import org.kuali.ole.DataCarrierService;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.select.bo.OleLicenseRequestBo;
6 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
7 import org.kuali.rice.kew.actionitem.ActionItem;
8 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
9 import org.kuali.rice.kew.actionrequest.service.ActionRequestService;
10 import org.kuali.rice.kew.api.document.DocumentStatus;
11 import org.kuali.rice.kew.service.KEWServiceLocator;
12 import org.kuali.rice.kim.api.identity.Person;
13 import org.kuali.rice.krad.document.Document;
14 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
15 import org.kuali.rice.krad.maintenance.MaintenanceDocumentAuthorizerBase;
16
17 import java.util.List;
18
19
20
21
22 public class LicenseMaintenanceDocumentAuthorizerBase extends MaintenanceDocumentAuthorizerBase {
23 public DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
24
25
26
27
28
29
30
31
32 @Override
33 public boolean canEdit(Document document, Person user) {
34 boolean canEdit = super.canEdit(document, user);
35 String statusCode = document.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
36 MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document;
37 OleLicenseRequestBo oleLicenseRequestBo = (OleLicenseRequestBo) maintenanceDocument.getNewMaintainableObject().getDataObject();
38 if (!canEdit) {
39 canEdit &= oleLicenseRequestBo.getAssignee() != null &&
40 !(statusCode.equalsIgnoreCase(DocumentStatus.INITIATED.getCode()) || statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())) ?
41 oleLicenseRequestBo.getAssignee().equalsIgnoreCase(user.getPrincipalId()) : true;
42 String canEditStr = null;
43 String routeHeaderId = document.getDocumentHeader().getDocumentNumber();
44 if (statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())) {
45 ActionRequestService actionReqSrv = KEWServiceLocator.getActionRequestService();
46 List<ActionRequestValue> actionReqValues = actionReqSrv.findAllPendingRequests(routeHeaderId);
47 for (ActionRequestValue actionRequest : actionReqValues) {
48 List<ActionItem> actionItems = actionRequest.getActionItems();
49 canEditStr = actionItems != null && actionItems.size() > 0 ? actionItems.get(0).getPrincipalId() : null;
50 }
51 return (oleLicenseRequestBo.getAssignee() != null && oleLicenseRequestBo.getAssignee().equalsIgnoreCase(user.getPrincipalId())) ||
52 (canEditStr != null && canEditStr.equalsIgnoreCase(user.getPrincipalId()));
53 }
54 }
55 return canEdit;
56 }
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 public boolean canRoute(Document document, Person user) {
78 boolean canRoute = super.canRoute(document, user);
79 String statusCode = document.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
80 MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document;
81 OleLicenseRequestBo oleLicenseRequestBo = (OleLicenseRequestBo) maintenanceDocument.getNewMaintainableObject().getDataObject();
82 String canRouteStr = null;
83 String routeHeaderId = document.getDocumentHeader().getDocumentNumber();
84 if (statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())) {
85 ActionRequestService actionReqSrv = KEWServiceLocator.getActionRequestService();
86 List<ActionRequestValue> actionReqValues = actionReqSrv.findAllPendingRequests(routeHeaderId);
87 for (ActionRequestValue actionRequest : actionReqValues) {
88 List<ActionItem> actionItems = actionRequest.getActionItems();
89 canRouteStr = actionItems != null && actionItems.size() > 0 ? actionItems.get(0).getPrincipalId() : null;
90 }
91 return (oleLicenseRequestBo.getAssignee() != null && oleLicenseRequestBo.getAssignee().equalsIgnoreCase(user.getPrincipalId())) ||
92 (canRouteStr != null && canRouteStr.equalsIgnoreCase(user.getPrincipalId()));
93 }
94 return canRoute;
95 }
96 }