@Override
  public List<String> getNextTransitionNames(
      long companyId, long userId, long workflowTaskInstanceId) throws WorkflowException {

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

      if (kaleoTaskInstanceToken.isCompleted()) {
        return Collections.emptyList();
      }

      KaleoTask kaleoTask = kaleoTaskInstanceToken.getKaleoTask();
      KaleoNode kaleoNode = kaleoTask.getKaleoNode();

      List<KaleoTransition> kaleoTransitions = kaleoNode.getKaleoTransitions();

      List<String> transitionNames = new ArrayList<>(kaleoTransitions.size());

      for (KaleoTransition kaleoTransition : kaleoTransitions) {
        transitionNames.add(kaleoTransition.getName());
      }

      return transitionNames;
    } catch (Exception e) {
      throw new WorkflowException(e);
    }
  }
  public KaleoTaskInstanceToken completeKaleoTaskInstanceToken(
      long kaleoTaskInstanceTokenId, ServiceContext serviceContext)
      throws PortalException, SystemException {

    // Kaleo task instance token

    KaleoTaskInstanceToken kaleoTaskInstanceToken =
        kaleoTaskInstanceTokenPersistence.findByPrimaryKey(kaleoTaskInstanceTokenId);

    kaleoTaskInstanceToken.setCompletionUserId(serviceContext.getUserId());
    kaleoTaskInstanceToken.setCompleted(true);
    kaleoTaskInstanceToken.setCompletionDate(new Date());

    kaleoTaskInstanceTokenPersistence.update(kaleoTaskInstanceToken, false);

    // Kaleo task assignment instance

    kaleoTaskAssignmentInstanceLocalService.completeKaleoTaskInstanceToken(
        kaleoTaskInstanceTokenId, serviceContext);

    // Kaleo timers

    kaleoTimerInstanceTokenLocalService.completeKaleoTimerInstanceTokens(
        kaleoTaskInstanceToken.getKaleoInstanceTokenId(), serviceContext);

    return kaleoTaskInstanceToken;
  }
  @Test
  public void testFetchByPrimaryKeyExisting() throws Exception {
    KaleoTaskInstanceToken newKaleoTaskInstanceToken = addKaleoTaskInstanceToken();

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

    Assert.assertEquals(existingKaleoTaskInstanceToken, newKaleoTaskInstanceToken);
  }
  @Test
  public void testCreate() throws Exception {
    long pk = RandomTestUtil.nextLong();

    KaleoTaskInstanceToken kaleoTaskInstanceToken = _persistence.create(pk);

    Assert.assertNotNull(kaleoTaskInstanceToken);

    Assert.assertEquals(kaleoTaskInstanceToken.getPrimaryKey(), pk);
  }
  @Test
  public void testRemove() throws Exception {
    KaleoTaskInstanceToken newKaleoTaskInstanceToken = addKaleoTaskInstanceToken();

    _persistence.remove(newKaleoTaskInstanceToken);

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

    Assert.assertNull(existingKaleoTaskInstanceToken);
  }
예제 #6
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());
  }
  @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<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;
  }
  @Test
  public void testFetchByPrimaryKeysWithOnePrimaryKey() throws Exception {
    KaleoTaskInstanceToken newKaleoTaskInstanceToken = addKaleoTaskInstanceToken();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newKaleoTaskInstanceToken.getPrimaryKey());

    Map<Serializable, KaleoTaskInstanceToken> kaleoTaskInstanceTokens =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, kaleoTaskInstanceTokens.size());
    Assert.assertEquals(
        newKaleoTaskInstanceToken,
        kaleoTaskInstanceTokens.get(newKaleoTaskInstanceToken.getPrimaryKey()));
  }
  @Test
  public void testResetOriginalValues() throws Exception {
    KaleoTaskInstanceToken newKaleoTaskInstanceToken = addKaleoTaskInstanceToken();

    _persistence.clearCache();

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

    Assert.assertEquals(
        Long.valueOf(existingKaleoTaskInstanceToken.getKaleoInstanceId()),
        ReflectionTestUtil.<Long>invoke(
            existingKaleoTaskInstanceToken, "getOriginalKaleoInstanceId", new Class<?>[0]));
    Assert.assertEquals(
        Long.valueOf(existingKaleoTaskInstanceToken.getKaleoTaskId()),
        ReflectionTestUtil.<Long>invoke(
            existingKaleoTaskInstanceToken, "getOriginalKaleoTaskId", new Class<?>[0]));
  }
  @Test
  public void testDynamicQueryByPrimaryKeyExisting() throws Exception {
    KaleoTaskInstanceToken newKaleoTaskInstanceToken = addKaleoTaskInstanceToken();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(KaleoTaskInstanceToken.class, _dynamicQueryClassLoader);

    dynamicQuery.add(
        RestrictionsFactoryUtil.eq(
            "kaleoTaskInstanceTokenId", newKaleoTaskInstanceToken.getKaleoTaskInstanceTokenId()));

    List<KaleoTaskInstanceToken> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    KaleoTaskInstanceToken existingKaleoTaskInstanceToken = result.get(0);

    Assert.assertEquals(existingKaleoTaskInstanceToken, newKaleoTaskInstanceToken);
  }
  @Test
  public void testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereSomePrimaryKeysExist()
      throws Exception {
    KaleoTaskInstanceToken newKaleoTaskInstanceToken = addKaleoTaskInstanceToken();

    long pk = RandomTestUtil.nextLong();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newKaleoTaskInstanceToken.getPrimaryKey());
    primaryKeys.add(pk);

    Map<Serializable, KaleoTaskInstanceToken> kaleoTaskInstanceTokens =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(1, kaleoTaskInstanceTokens.size());
    Assert.assertEquals(
        newKaleoTaskInstanceToken,
        kaleoTaskInstanceTokens.get(newKaleoTaskInstanceToken.getPrimaryKey()));
  }
  public KaleoTaskInstanceToken updateDueDate(
      long kaleoTaskInstanceTokenId, Date dueDate, ServiceContext serviceContext)
      throws PortalException, SystemException {

    KaleoTaskInstanceToken kaleoTaskInstance =
        kaleoTaskInstanceTokenPersistence.findByPrimaryKey(kaleoTaskInstanceTokenId);

    kaleoTaskInstance.setModifiedDate(new Date());

    if (dueDate != null) {
      Calendar cal = CalendarFactoryUtil.getCalendar(LocaleUtil.getDefault());

      cal.setTime(dueDate);

      kaleoTaskInstance.setDueDate(cal.getTime());
    }

    kaleoTaskInstanceTokenPersistence.update(kaleoTaskInstance, false);

    return kaleoTaskInstance;
  }
  public KaleoTaskInstanceToken assignKaleoTaskInstanceToken(
      long kaleoTaskInstanceTokenId,
      String assigneeClassName,
      long assigneeClassPK,
      Map<String, Serializable> workflowContext,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    KaleoTaskInstanceToken kaleoTaskInstanceToken =
        kaleoTaskInstanceTokenPersistence.findByPrimaryKey(kaleoTaskInstanceTokenId);

    kaleoTaskInstanceToken.setModifiedDate(new Date());
    kaleoTaskInstanceToken.setWorkflowContext(WorkflowContextUtil.convert(workflowContext));

    kaleoTaskInstanceTokenPersistence.update(kaleoTaskInstanceToken, false);

    kaleoTaskAssignmentInstanceLocalService.assignKaleoTaskAssignmentInstance(
        kaleoTaskInstanceToken, assigneeClassName,
        assigneeClassPK, serviceContext);

    return kaleoTaskInstanceToken;
  }
  @Test
  public void testDynamicQueryByProjectionExisting() throws Exception {
    KaleoTaskInstanceToken newKaleoTaskInstanceToken = addKaleoTaskInstanceToken();

    DynamicQuery dynamicQuery =
        DynamicQueryFactoryUtil.forClass(KaleoTaskInstanceToken.class, _dynamicQueryClassLoader);

    dynamicQuery.setProjection(ProjectionFactoryUtil.property("kaleoTaskInstanceTokenId"));

    Object newKaleoTaskInstanceTokenId = newKaleoTaskInstanceToken.getKaleoTaskInstanceTokenId();

    dynamicQuery.add(
        RestrictionsFactoryUtil.in(
            "kaleoTaskInstanceTokenId", new Object[] {newKaleoTaskInstanceTokenId}));

    List<Object> result = _persistence.findWithDynamicQuery(dynamicQuery);

    Assert.assertEquals(1, result.size());

    Object existingKaleoTaskInstanceTokenId = result.get(0);

    Assert.assertEquals(existingKaleoTaskInstanceTokenId, newKaleoTaskInstanceTokenId);
  }
  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 testFetchByPrimaryKeysWithMultiplePrimaryKeysWhereAllPrimaryKeysExist()
      throws Exception {
    KaleoTaskInstanceToken newKaleoTaskInstanceToken1 = addKaleoTaskInstanceToken();
    KaleoTaskInstanceToken newKaleoTaskInstanceToken2 = addKaleoTaskInstanceToken();

    Set<Serializable> primaryKeys = new HashSet<Serializable>();

    primaryKeys.add(newKaleoTaskInstanceToken1.getPrimaryKey());
    primaryKeys.add(newKaleoTaskInstanceToken2.getPrimaryKey());

    Map<Serializable, KaleoTaskInstanceToken> kaleoTaskInstanceTokens =
        _persistence.fetchByPrimaryKeys(primaryKeys);

    Assert.assertEquals(2, kaleoTaskInstanceTokens.size());
    Assert.assertEquals(
        newKaleoTaskInstanceToken1,
        kaleoTaskInstanceTokens.get(newKaleoTaskInstanceToken1.getPrimaryKey()));
    Assert.assertEquals(
        newKaleoTaskInstanceToken2,
        kaleoTaskInstanceTokens.get(newKaleoTaskInstanceToken2.getPrimaryKey()));
  }
  public KaleoTaskInstanceToken addKaleoTaskInstanceToken(
      long kaleoInstanceTokenId,
      long kaleoTaskId,
      String kaleoTaskName,
      Collection<KaleoTaskAssignment> kaleoTaskAssignments,
      Date dueDate,
      Map<String, Serializable> workflowContext,
      ServiceContext serviceContext)
      throws PortalException, SystemException {

    KaleoInstanceToken kaleoInstanceToken =
        kaleoInstanceTokenPersistence.findByPrimaryKey(kaleoInstanceTokenId);

    User user = userPersistence.findByPrimaryKey(serviceContext.getGuestOrUserId());
    Date now = new Date();

    long kaleoTaskInstanceTokenId = counterLocalService.increment();

    KaleoTaskInstanceToken kaleoTaskInstanceToken =
        kaleoTaskInstanceTokenPersistence.create(kaleoTaskInstanceTokenId);

    long groupId = StagingUtil.getLiveGroupId(serviceContext.getScopeGroupId());

    kaleoTaskInstanceToken.setGroupId(groupId);

    kaleoTaskInstanceToken.setCompanyId(user.getCompanyId());
    kaleoTaskInstanceToken.setUserId(user.getUserId());
    kaleoTaskInstanceToken.setUserName(user.getFullName());
    kaleoTaskInstanceToken.setCreateDate(now);
    kaleoTaskInstanceToken.setModifiedDate(now);
    kaleoTaskInstanceToken.setDueDate(dueDate);
    kaleoTaskInstanceToken.setKaleoDefinitionId(kaleoInstanceToken.getKaleoDefinitionId());
    kaleoTaskInstanceToken.setKaleoInstanceId(kaleoInstanceToken.getKaleoInstanceId());
    kaleoTaskInstanceToken.setKaleoInstanceTokenId(kaleoInstanceTokenId);

    kaleoTaskInstanceToken.setKaleoTaskId(kaleoTaskId);
    kaleoTaskInstanceToken.setKaleoTaskName(kaleoTaskName);

    if (workflowContext != null) {
      kaleoTaskInstanceToken.setClassName(
          (String) workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_NAME));

      if (workflowContext.containsKey(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK)) {

        kaleoTaskInstanceToken.setClassPK(
            GetterUtil.getLong(
                (String) workflowContext.get(WorkflowConstants.CONTEXT_ENTRY_CLASS_PK)));
      }
    }

    kaleoTaskInstanceToken.setCompleted(false);
    kaleoTaskInstanceToken.setWorkflowContext(WorkflowContextUtil.convert(workflowContext));

    kaleoTaskInstanceTokenPersistence.update(kaleoTaskInstanceToken, false);

    kaleoTaskAssignmentInstanceLocalService.addTaskAssignmentInstances(
        kaleoTaskInstanceToken, kaleoTaskAssignments, workflowContext, serviceContext);

    return kaleoTaskInstanceToken;
  }
  @Override
  public long[] getPooledActorsIds(long companyId, long workflowTaskInstanceId)
      throws WorkflowException {

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

      List<KaleoTaskAssignment> calculatedKaleoTaskAssignments =
          getCalculatedKaleoTaskAssignments(kaleoTaskInstanceToken);

      Map<String, Long> pooledActors = new TreeMap<>(new NaturalOrderStringComparator());

      for (KaleoTaskAssignment calculatedKaleoTaskAssignment : calculatedKaleoTaskAssignments) {

        String assigneeClassName = calculatedKaleoTaskAssignment.getAssigneeClassName();
        long assigneeClassPK = calculatedKaleoTaskAssignment.getAssigneeClassPK();

        if (assigneeClassName.equals(User.class.getName())) {
          User user = UserLocalServiceUtil.fetchUser(assigneeClassPK);

          if (user != null) {
            pooledActors.put(user.getFullName(), user.getUserId());
          }

          continue;
        }

        Role role =
            RoleLocalServiceUtil.getRole(calculatedKaleoTaskAssignment.getAssigneeClassPK());

        if ((role.getType() == RoleConstants.TYPE_SITE)
            || (role.getType() == RoleConstants.TYPE_ORGANIZATION)) {

          List<UserGroupRole> userGroupRoles =
              UserGroupRoleLocalServiceUtil.getUserGroupRolesByGroupAndRole(
                  kaleoTaskInstanceToken.getGroupId(), assigneeClassPK);

          for (UserGroupRole userGroupRole : userGroupRoles) {
            User user = userGroupRole.getUser();

            pooledActors.put(user.getFullName(), user.getUserId());
          }

          List<UserGroupGroupRole> userGroupGroupRoles =
              UserGroupGroupRoleLocalServiceUtil.getUserGroupGroupRolesByGroupAndRole(
                  kaleoTaskInstanceToken.getGroupId(), assigneeClassPK);

          for (UserGroupGroupRole userGroupGroupRole : userGroupGroupRoles) {

            List<User> userGroupUsers =
                UserLocalServiceUtil.getUserGroupUsers(userGroupGroupRole.getUserGroupId());

            for (User user : userGroupUsers) {
              pooledActors.put(user.getFullName(), user.getUserId());
            }
          }
        } else {
          List<User> inheritedRoleUsers =
              UserLocalServiceUtil.getInheritedRoleUsers(
                  assigneeClassPK, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);

          for (User user : inheritedRoleUsers) {
            pooledActors.put(user.getFullName(), user.getUserId());
          }
        }
      }

      return ArrayUtil.toLongArray(pooledActors.values());
    } catch (Exception e) {
      throw new WorkflowException(e);
    }
  }
  @Override
  public WorkflowTask completeWorkflowTask(
      long companyId,
      long userId,
      long workflowTaskInstanceId,
      String transitionName,
      String comment,
      Map<String, Serializable> workflowContext)
      throws WorkflowException {

    Lock lock = null;

    try {
      lock =
          LockManagerUtil.lock(
              userId,
              WorkflowTask.class.getName(),
              workflowTaskInstanceId,
              String.valueOf(userId),
              false,
              1000);
    } catch (PortalException pe) {
      if (pe instanceof DuplicateLockException) {
        throw new WorkflowException(
            "Workflow task " + workflowTaskInstanceId + " is locked by user " + userId, pe);
      }

      throw new WorkflowException("Unable to lock workflow task " + workflowTaskInstanceId, pe);
    }

    try {
      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setCompanyId(companyId);
      serviceContext.setUserId(userId);

      WorkflowTask workflowTask =
          _taskManager.completeWorkflowTask(
              workflowTaskInstanceId, transitionName, comment, workflowContext, serviceContext);

      KaleoTaskInstanceToken kaleoTaskInstanceToken =
          KaleoTaskInstanceTokenLocalServiceUtil.getKaleoTaskInstanceToken(
              workflowTask.getWorkflowTaskId());

      KaleoInstanceToken kaleoInstanceToken = kaleoTaskInstanceToken.getKaleoInstanceToken();

      if (workflowContext == null) {
        workflowContext =
            WorkflowContextUtil.convert(kaleoInstanceToken.getKaleoInstance().getWorkflowContext());
      }

      workflowContext.put(WorkflowConstants.CONTEXT_TASK_COMMENTS, comment);
      workflowContext.put(WorkflowConstants.CONTEXT_TRANSITION_NAME, transitionName);

      ExecutionContext executionContext =
          new ExecutionContext(
              kaleoInstanceToken, kaleoTaskInstanceToken, workflowContext, serviceContext);

      _kaleoSignaler.signalExit(transitionName, executionContext);

      return workflowTask;
    } catch (Exception e) {
      throw new WorkflowException("Unable to complete task", e);
    } finally {
      LockManagerUtil.unlock(lock.getClassName(), lock.getKey());
    }
  }
  @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());
  }
  protected KaleoTaskInstanceToken addKaleoTaskInstanceToken() throws Exception {
    long pk = RandomTestUtil.nextLong();

    KaleoTaskInstanceToken kaleoTaskInstanceToken = _persistence.create(pk);

    kaleoTaskInstanceToken.setGroupId(RandomTestUtil.nextLong());

    kaleoTaskInstanceToken.setCompanyId(RandomTestUtil.nextLong());

    kaleoTaskInstanceToken.setUserId(RandomTestUtil.nextLong());

    kaleoTaskInstanceToken.setUserName(RandomTestUtil.randomString());

    kaleoTaskInstanceToken.setCreateDate(RandomTestUtil.nextDate());

    kaleoTaskInstanceToken.setModifiedDate(RandomTestUtil.nextDate());

    kaleoTaskInstanceToken.setKaleoDefinitionId(RandomTestUtil.nextLong());

    kaleoTaskInstanceToken.setKaleoInstanceId(RandomTestUtil.nextLong());

    kaleoTaskInstanceToken.setKaleoInstanceTokenId(RandomTestUtil.nextLong());

    kaleoTaskInstanceToken.setKaleoTaskId(RandomTestUtil.nextLong());

    kaleoTaskInstanceToken.setKaleoTaskName(RandomTestUtil.randomString());

    kaleoTaskInstanceToken.setClassName(RandomTestUtil.randomString());

    kaleoTaskInstanceToken.setClassPK(RandomTestUtil.nextLong());

    kaleoTaskInstanceToken.setCompletionUserId(RandomTestUtil.nextLong());

    kaleoTaskInstanceToken.setCompleted(RandomTestUtil.randomBoolean());

    kaleoTaskInstanceToken.setCompletionDate(RandomTestUtil.nextDate());

    kaleoTaskInstanceToken.setDueDate(RandomTestUtil.nextDate());

    kaleoTaskInstanceToken.setWorkflowContext(RandomTestUtil.randomString());

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

    return kaleoTaskInstanceToken;
  }