View Javadoc

1   package org.kuali.ole.license.controller;
2   
3   import org.kuali.ole.DataCarrierService;
4   import org.kuali.ole.OLEConstants;
5   import org.kuali.ole.license.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  import java.util.List;
17  
18  /**
19   * LicenseMaintenanceDocumentAuthorizerBase authorises permission for License Maintenance Document.
20   */
21  public class LicenseMaintenanceDocumentAuthorizerBase extends MaintenanceDocumentAuthorizerBase {
22      public DataCarrierService dataCarrierService = GlobalResourceLoader.getService(OLEConstants.DATA_CARRIER_SERVICE);
23      /**
24       *  Check user has credential to modify maintenanceDocument.
25       * @param document
26       * @param user
27       * @return boolean
28       */
29      @Override
30      public boolean canEdit(Document document, Person user) {
31          boolean canEdit =  super.canEdit(document,user);
32          String statusCode = document.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
33          MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document;
34          OleLicenseRequestBo oleLicenseRequestBo = (OleLicenseRequestBo)maintenanceDocument.getNewMaintainableObject().getDataObject();
35          if(!canEdit) {
36              canEdit &=oleLicenseRequestBo.getAssignee()!=null &&
37                      !(statusCode.equalsIgnoreCase(DocumentStatus.INITIATED.getCode())||statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode()))?
38                      oleLicenseRequestBo.getAssignee().equalsIgnoreCase(user.getPrincipalId()):true;
39              String canEditStr = null;
40              String routeHeaderId = document.getDocumentHeader().getDocumentNumber();
41              if(statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())){
42                  ActionRequestService actionReqSrv = KEWServiceLocator.getActionRequestService();
43                  List<ActionRequestValue> actionReqValues = actionReqSrv.findAllPendingRequests(routeHeaderId);
44                  for(ActionRequestValue actionRequest:actionReqValues){
45                      List<ActionItem> actionItems = actionRequest.getActionItems();
46                      canEditStr = actionItems!=null && actionItems.size()>0? actionItems.get(0).getPrincipalId():null;
47                  }
48                  return  (oleLicenseRequestBo.getAssignee()!=null && oleLicenseRequestBo.getAssignee().equalsIgnoreCase(user.getPrincipalId())) ||
49                          (canEditStr!=null && canEditStr.equalsIgnoreCase(user.getPrincipalId()));
50              }
51          }
52          return canEdit;
53      }
54      /*public boolean canSave(Document document, Person user) {
55          boolean canSave = super.canSave(document,user);
56          String statusCode = document.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
57          MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document;
58          OleLicenseRequestBo oleLicenseRequestBo = (OleLicenseRequestBo)maintenanceDocument.getNewMaintainableObject().getDataObject();
59          String canSaveStr = null;
60          String routeHeaderId = document.getDocumentHeader().getDocumentNumber();
61          if(statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())){
62              ActionRequestService actionReqSrv = KEWServiceLocator.getActionRequestService();
63              List<ActionRequestValue> actionReqValues = actionReqSrv.findAllPendingRequests(routeHeaderId);
64              for(ActionRequestValue actionRequest:actionReqValues){
65                  List<ActionItem> actionItems = actionRequest.getActionItems();
66                  canSaveStr = actionItems!=null && actionItems.size()>0? actionItems.get(0).getPrincipalId():null;
67              }
68              return  (oleLicenseRequestBo.getAssignee()!=null && oleLicenseRequestBo.getAssignee().equalsIgnoreCase(user.getPrincipalId())) ||
69                      (canSaveStr!=null && canSaveStr.equalsIgnoreCase(user.getPrincipalId()));
70          }
71          return canSave;
72      }*/
73      public boolean canRoute(Document document, Person user) {
74          boolean canRoute = super.canRoute(document, user);
75          String statusCode = document.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
76          MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document;
77          OleLicenseRequestBo oleLicenseRequestBo = (OleLicenseRequestBo)maintenanceDocument.getNewMaintainableObject().getDataObject();
78          String canRouteStr = null;
79          String routeHeaderId = document.getDocumentHeader().getDocumentNumber();
80          if(statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())){
81              ActionRequestService actionReqSrv = KEWServiceLocator.getActionRequestService();
82              List<ActionRequestValue> actionReqValues = actionReqSrv.findAllPendingRequests(routeHeaderId);
83              for(ActionRequestValue actionRequest:actionReqValues){
84                  List<ActionItem> actionItems = actionRequest.getActionItems();
85                  canRouteStr = actionItems!=null && actionItems.size()>0? actionItems.get(0).getPrincipalId():null;
86              }
87              return  (oleLicenseRequestBo.getAssignee()!=null && oleLicenseRequestBo.getAssignee().equalsIgnoreCase(user.getPrincipalId())) ||
88                      (canRouteStr!=null && canRouteStr.equalsIgnoreCase(user.getPrincipalId()));
89          }
90          return canRoute;
91      }
92  }