protected void deleteInstance(ActionRequest actionRequest) throws Exception {

    ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);

    long workflowInstanceId = ParamUtil.getLong(actionRequest, "workflowInstanceId");

    WorkflowInstance workflowInstance =
        WorkflowInstanceManagerUtil.getWorkflowInstance(
            themeDisplay.getCompanyId(), workflowInstanceId);

    Map<String, Serializable> workflowContext = workflowInstance.getWorkflowContext();

    long companyId = GetterUtil.getLong(workflowContext.get(WorkflowConstants.CONTEXT_COMPANY_ID));
    long groupId = GetterUtil.getLong(workflowContext.get(WorkflowConstants.CONTEXT_GROUP_ID));
    String className =
        GetterUtil.getString(workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_NAME));
    long classPK =
        GetterUtil.getLong(workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK));

    WorkflowHandler workflowHandler = WorkflowHandlerRegistryUtil.getWorkflowHandler(className);

    workflowHandler.updateStatus(WorkflowConstants.STATUS_DRAFT, workflowContext);

    WorkflowInstanceLinkLocalServiceUtil.deleteWorkflowInstanceLink(
        companyId, groupId, className, classPK);
  }
  @Override
  public void startWorkflowInstance(
      long companyId,
      long groupId,
      long userId,
      String className,
      long classPK,
      Map<String, Serializable> workflowContext)
      throws PortalException {

    if (!WorkflowThreadLocal.isEnabled()) {
      return;
    }

    if (userId == 0) {
      userId = userLocalService.getDefaultUserId(companyId);
    }

    WorkflowHandler<?> workflowHandler = WorkflowHandlerRegistryUtil.getWorkflowHandler(className);

    WorkflowDefinitionLink workflowDefinitionLink =
        workflowHandler.getWorkflowDefinitionLink(companyId, groupId, classPK);

    String workflowDefinitionName = workflowDefinitionLink.getWorkflowDefinitionName();
    int workflowDefinitionVersion = workflowDefinitionLink.getWorkflowDefinitionVersion();

    if (workflowContext != null) {
      workflowContext = new HashMap<>(workflowContext);
    } else {
      workflowContext = new HashMap<>();
    }

    workflowContext.put(WorkflowConstants.CONTEXT_COMPANY_ID, String.valueOf(companyId));
    workflowContext.put(WorkflowConstants.CONTEXT_GROUP_ID, String.valueOf(groupId));
    workflowContext.put(WorkflowConstants.CONTEXT_ENTRY_CLASS_NAME, className);
    workflowContext.put(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK, String.valueOf(classPK));
    workflowContext.put(
        WorkflowConstants.CONTEXT_ENTRY_TYPE, workflowHandler.getType(LocaleUtil.getDefault()));

    WorkflowInstance workflowInstance =
        WorkflowInstanceManagerUtil.startWorkflowInstance(
            companyId,
            groupId,
            userId,
            workflowDefinitionName,
            workflowDefinitionVersion,
            null,
            workflowContext);

    addWorkflowInstanceLink(
        userId, companyId, groupId, className, classPK, workflowInstance.getWorkflowInstanceId());
  }
  @Override
  protected String getLink(
      UserNotificationEvent userNotificationEvent, ServiceContext serviceContext) throws Exception {

    JSONObject jsonObject = JSONFactoryUtil.createJSONObject(userNotificationEvent.getPayload());

    String entryClassName = jsonObject.getString("entryClassName");

    WorkflowHandler<?> workflowHandler =
        WorkflowHandlerRegistryUtil.getWorkflowHandler(entryClassName);

    if (workflowHandler == null) {
      return null;
    }

    long workflowTaskId = jsonObject.getLong("workflowTaskId");

    return workflowHandler.getURLEditWorkflowTask(workflowTaskId, serviceContext);
  }