Beispiel #1
0
  public WorkflowTaskAdapter(
      KaleoTaskInstanceToken kaleoTaskInstanceToken, Map<String, Serializable> workflowContext)
      throws PortalException, SystemException {

    setCreateDate(kaleoTaskInstanceToken.getCreateDate());
    setCompletionDate(kaleoTaskInstanceToken.getCompletionDate());
    setDescription(kaleoTaskInstanceToken.getKaleoTask().getDescription());
    setDueDate(kaleoTaskInstanceToken.getDueDate());
    setName(kaleoTaskInstanceToken.getKaleoTask().getName());

    if (workflowContext != null) {
      setOptionalAttributes(workflowContext);
    } else {
      setOptionalAttributes(
          WorkflowContextUtil.convert(kaleoTaskInstanceToken.getWorkflowContext()));
    }

    KaleoInstanceToken kaleoInstanceToken = kaleoTaskInstanceToken.getKaleoInstanceToken();
    KaleoInstance kaleoInstance = kaleoInstanceToken.getKaleoInstance();

    setWorkflowDefinitionId(kaleoInstance.getKaleoDefinitionId());
    setWorkflowDefinitionName(kaleoInstance.getKaleoDefinitionName());
    setWorkflowDefinitionVersion(kaleoInstance.getKaleoDefinitionVersion());
    setWorkflowInstanceId(kaleoInstance.getKaleoInstanceId());

    List<WorkflowTaskAssignee> workflowTaskAssignees =
        KaleoTaskAssignmentInstanceUtil.getWorkflowTaskAssignees(kaleoTaskInstanceToken);

    setWorkflowTaskAssignees(workflowTaskAssignees);

    setWorkflowTaskId(kaleoTaskInstanceToken.getKaleoTaskInstanceTokenId());
  }
  protected List<WorkflowTask> toWorkflowTasks(List<KaleoTaskInstanceToken> kaleoTaskInstanceTokens)
      throws PortalException {

    List<WorkflowTask> workflowTasks = new ArrayList<>(kaleoTaskInstanceTokens.size());

    for (KaleoTaskInstanceToken kaleoTaskInstanceToken : kaleoTaskInstanceTokens) {

      workflowTasks.add(
          WorkflowModelUtil.toWorkflowTask(
              kaleoTaskInstanceToken,
              WorkflowContextUtil.convert(kaleoTaskInstanceToken.getWorkflowContext())));
    }

    return workflowTasks;
  }
  @Override
  public WorkflowTask getWorkflowTask(long companyId, long workflowTaskInstanceId)
      throws WorkflowException {

    try {
      KaleoTaskInstanceToken kaleoTaskInstanceToken =
          KaleoTaskInstanceTokenLocalServiceUtil.getKaleoTaskInstanceToken(workflowTaskInstanceId);

      return WorkflowModelUtil.toWorkflowTask(
          kaleoTaskInstanceToken,
          WorkflowContextUtil.convert(kaleoTaskInstanceToken.getWorkflowContext()));
    } catch (Exception e) {
      throw new WorkflowException(e);
    }
  }
  protected List<KaleoTaskAssignment> getCalculatedKaleoTaskAssignments(
      KaleoTaskInstanceToken kaleoTaskInstanceToken) throws PortalException {

    List<KaleoTaskAssignment> calculatedKaleoTaskAssignments = new ArrayList<>();

    KaleoInstanceToken kaleoInstanceToken = kaleoTaskInstanceToken.getKaleoInstanceToken();

    Map<String, Serializable> workflowContext =
        WorkflowContextUtil.convert(kaleoTaskInstanceToken.getWorkflowContext());

    ServiceContext workflowContextServiceContext =
        (ServiceContext) workflowContext.get(WorkflowConstants.CONTEXT_SERVICE_CONTEXT);

    ExecutionContext executionContext =
        new ExecutionContext(kaleoInstanceToken, workflowContext, workflowContextServiceContext);

    List<KaleoTaskAssignment> configuredKaleoTaskAssignments =
        KaleoTaskAssignmentLocalServiceUtil.getKaleoTaskAssignments(
            kaleoTaskInstanceToken.getKaleoTaskId());

    for (KaleoTaskAssignment configuredKaleoTaskAssignment : configuredKaleoTaskAssignments) {

      String[] assigneeScriptRequiredContexts =
          StringUtil.split(configuredKaleoTaskAssignment.getAssigneeScriptRequiredContexts());

      ClassLoader[] classLoaders = ClassLoaderUtil.getClassLoaders(assigneeScriptRequiredContexts);

      Collection<KaleoTaskAssignment> kaleoTaskAssignments =
          _taskAssignmentSelector.calculateTaskAssignments(
              configuredKaleoTaskAssignment, executionContext, classLoaders);

      calculatedKaleoTaskAssignments.addAll(kaleoTaskAssignments);
    }

    return calculatedKaleoTaskAssignments;
  }
  @Test
  public void testUpdateExisting() throws Exception {
    long pk = RandomTestUtil.nextLong();

    KaleoTaskInstanceToken newKaleoTaskInstanceToken = _persistence.create(pk);

    newKaleoTaskInstanceToken.setGroupId(RandomTestUtil.nextLong());

    newKaleoTaskInstanceToken.setCompanyId(RandomTestUtil.nextLong());

    newKaleoTaskInstanceToken.setUserId(RandomTestUtil.nextLong());

    newKaleoTaskInstanceToken.setUserName(RandomTestUtil.randomString());

    newKaleoTaskInstanceToken.setCreateDate(RandomTestUtil.nextDate());

    newKaleoTaskInstanceToken.setModifiedDate(RandomTestUtil.nextDate());

    newKaleoTaskInstanceToken.setKaleoDefinitionId(RandomTestUtil.nextLong());

    newKaleoTaskInstanceToken.setKaleoInstanceId(RandomTestUtil.nextLong());

    newKaleoTaskInstanceToken.setKaleoInstanceTokenId(RandomTestUtil.nextLong());

    newKaleoTaskInstanceToken.setKaleoTaskId(RandomTestUtil.nextLong());

    newKaleoTaskInstanceToken.setKaleoTaskName(RandomTestUtil.randomString());

    newKaleoTaskInstanceToken.setClassName(RandomTestUtil.randomString());

    newKaleoTaskInstanceToken.setClassPK(RandomTestUtil.nextLong());

    newKaleoTaskInstanceToken.setCompletionUserId(RandomTestUtil.nextLong());

    newKaleoTaskInstanceToken.setCompleted(RandomTestUtil.randomBoolean());

    newKaleoTaskInstanceToken.setCompletionDate(RandomTestUtil.nextDate());

    newKaleoTaskInstanceToken.setDueDate(RandomTestUtil.nextDate());

    newKaleoTaskInstanceToken.setWorkflowContext(RandomTestUtil.randomString());

    _kaleoTaskInstanceTokens.add(_persistence.update(newKaleoTaskInstanceToken));

    KaleoTaskInstanceToken existingKaleoTaskInstanceToken =
        _persistence.findByPrimaryKey(newKaleoTaskInstanceToken.getPrimaryKey());

    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getKaleoTaskInstanceTokenId(),
        newKaleoTaskInstanceToken.getKaleoTaskInstanceTokenId());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getGroupId(), newKaleoTaskInstanceToken.getGroupId());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getCompanyId(), newKaleoTaskInstanceToken.getCompanyId());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getUserId(), newKaleoTaskInstanceToken.getUserId());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getUserName(), newKaleoTaskInstanceToken.getUserName());
    Assert.assertEquals(
        Time.getShortTimestamp(existingKaleoTaskInstanceToken.getCreateDate()),
        Time.getShortTimestamp(newKaleoTaskInstanceToken.getCreateDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingKaleoTaskInstanceToken.getModifiedDate()),
        Time.getShortTimestamp(newKaleoTaskInstanceToken.getModifiedDate()));
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getKaleoDefinitionId(),
        newKaleoTaskInstanceToken.getKaleoDefinitionId());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getKaleoInstanceId(),
        newKaleoTaskInstanceToken.getKaleoInstanceId());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getKaleoInstanceTokenId(),
        newKaleoTaskInstanceToken.getKaleoInstanceTokenId());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getKaleoTaskId(),
        newKaleoTaskInstanceToken.getKaleoTaskId());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getKaleoTaskName(),
        newKaleoTaskInstanceToken.getKaleoTaskName());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getClassName(), newKaleoTaskInstanceToken.getClassName());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getClassPK(), newKaleoTaskInstanceToken.getClassPK());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getCompletionUserId(),
        newKaleoTaskInstanceToken.getCompletionUserId());
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getCompleted(), newKaleoTaskInstanceToken.getCompleted());
    Assert.assertEquals(
        Time.getShortTimestamp(existingKaleoTaskInstanceToken.getCompletionDate()),
        Time.getShortTimestamp(newKaleoTaskInstanceToken.getCompletionDate()));
    Assert.assertEquals(
        Time.getShortTimestamp(existingKaleoTaskInstanceToken.getDueDate()),
        Time.getShortTimestamp(newKaleoTaskInstanceToken.getDueDate()));
    Assert.assertEquals(
        existingKaleoTaskInstanceToken.getWorkflowContext(),
        newKaleoTaskInstanceToken.getWorkflowContext());
  }