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          canEdit &=oleLicenseRequestBo.getAssignee()!=null &&
36                       !(statusCode.equalsIgnoreCase(DocumentStatus.INITIATED.getCode())||statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode()))?
37                         oleLicenseRequestBo.getAssignee().equalsIgnoreCase(user.getPrincipalId()):true;
38         String canEditStr = null;
39         String routeHeaderId = document.getDocumentHeader().getDocumentNumber();
40          if(statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())){
41              ActionRequestService actionReqSrv = KEWServiceLocator.getActionRequestService();
42              List<ActionRequestValue> actionReqValues = actionReqSrv.findAllPendingRequests(routeHeaderId);
43              for(ActionRequestValue actionRequest:actionReqValues){
44                  List<ActionItem> actionItems = actionRequest.getActionItems();
45                  canEditStr = actionItems!=null && actionItems.size()>0? actionItems.get(0).getPrincipalId():null;
46              }
47              return  (oleLicenseRequestBo.getAssignee()!=null && oleLicenseRequestBo.getAssignee().equalsIgnoreCase(user.getPrincipalId())) ||
48                      (canEditStr!=null && canEditStr.equalsIgnoreCase(user.getPrincipalId()));
49          }
50          return canEdit;
51      }
52      public boolean canSave(Document document, Person user) {
53          boolean canSave = super.canSave(document,user);
54          String statusCode = document.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
55          MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document;
56          OleLicenseRequestBo oleLicenseRequestBo = (OleLicenseRequestBo)maintenanceDocument.getNewMaintainableObject().getDataObject();
57          String canSaveStr = null;
58          String routeHeaderId = document.getDocumentHeader().getDocumentNumber();
59          if(statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())){
60              ActionRequestService actionReqSrv = KEWServiceLocator.getActionRequestService();
61              List<ActionRequestValue> actionReqValues = actionReqSrv.findAllPendingRequests(routeHeaderId);
62              for(ActionRequestValue actionRequest:actionReqValues){
63                  List<ActionItem> actionItems = actionRequest.getActionItems();
64                  canSaveStr = actionItems!=null && actionItems.size()>0? actionItems.get(0).getPrincipalId():null;
65              }
66              return  (oleLicenseRequestBo.getAssignee()!=null && oleLicenseRequestBo.getAssignee().equalsIgnoreCase(user.getPrincipalId())) ||
67                      (canSaveStr!=null && canSaveStr.equalsIgnoreCase(user.getPrincipalId()));
68          }
69          return canSave;
70      }
71  
72      public boolean canRoute(Document document, Person user) {
73          boolean canRoute = super.canRoute(document, user);
74          String statusCode = document.getDocumentHeader().getWorkflowDocument().getStatus().getCode();
75          MaintenanceDocument maintenanceDocument = (MaintenanceDocument) document;
76          OleLicenseRequestBo oleLicenseRequestBo = (OleLicenseRequestBo)maintenanceDocument.getNewMaintainableObject().getDataObject();
77          String canRouteStr = null;
78          String routeHeaderId = document.getDocumentHeader().getDocumentNumber();
79          if(statusCode.equalsIgnoreCase(DocumentStatus.SAVED.getCode())){
80              ActionRequestService actionReqSrv = KEWServiceLocator.getActionRequestService();
81              List<ActionRequestValue> actionReqValues = actionReqSrv.findAllPendingRequests(routeHeaderId);
82              for(ActionRequestValue actionRequest:actionReqValues){
83                  List<ActionItem> actionItems = actionRequest.getActionItems();
84                  canRouteStr = actionItems!=null && actionItems.size()>0? actionItems.get(0).getPrincipalId():null;
85              }
86              return  (oleLicenseRequestBo.getAssignee()!=null && oleLicenseRequestBo.getAssignee().equalsIgnoreCase(user.getPrincipalId())) ||
87                      (canRouteStr!=null && canRouteStr.equalsIgnoreCase(user.getPrincipalId()));
88          }
89          return canRoute;
90      }
91  }