示例#1
0
  @Test
  public void deletingProcessDeletesActorMappings() throws Exception {
    final TenantServiceAccessor tenantAccessor = getTenantAccessor();
    final UserTransactionService transactionService = tenantAccessor.getUserTransactionService();
    final String userTaskName = "actNaturally";
    final ProcessDefinition definition =
        deployAndEnableProcessWithOneHumanTask(
            "deletingProcessDeletesActorMappings", "CandidateForOscarReward", userTaskName);

    final ProcessInstance processInstanceId = getProcessAPI().startProcess(definition.getId());
    waitForUserTask(processInstanceId, userTaskName);

    disableAndDeleteProcess(definition);

    setSessionInfo(getSession()); // the session was cleaned by api call. This must be improved
    final List<SActorMember> actorMembers =
        transactionService.executeInTransaction(
            new Callable<List<SActorMember>>() {

              @Override
              public List<SActorMember> call() throws Exception {
                return getTenantAccessor()
                    .getActorMappingService()
                    .getActorMembersOfUser(john.getId(), 0, 1);
              }
            });

    // Check there is no actor left:
    assertEquals(0, actorMembers.size());
  }
示例#2
0
  @Test
  public void checkMoreThan20DependenciesAreDeletedWhenProcessIsDeleted() throws Exception {
    final TenantServiceAccessor tenantAccessor = getTenantAccessor();
    final DependencyService dependencyService = tenantAccessor.getDependencyService();
    final UserTransactionService transactionService = tenantAccessor.getUserTransactionService();
    final ProcessDefinitionBuilder processDef =
        new ProcessDefinitionBuilder().createNewInstance("processToTestTransitions", "1.0");
    processDef.addStartEvent("start").addUserTask("step1", ACTOR_NAME).addEndEvent("end");
    processDef.addTransition("start", "step1").addTransition("step1", "end");
    processDef.addActor(ACTOR_NAME);
    final BusinessArchiveBuilder businessArchiveBuilder =
        new BusinessArchiveBuilder()
            .createNewBusinessArchive()
            .setProcessDefinition(processDef.done());
    for (int i = 0; i < 25; i++) {
      final byte[] content =
          new byte[] {
            1,
            2,
            3,
            4,
            5,
            6,
            7,
            (byte) (i >>> 24),
            (byte) (i >> 16 & 0xff),
            (byte) (i >> 8 & 0xff),
            (byte) (i & 0xff)
          };
      businessArchiveBuilder.addClasspathResource(new BarResource("myDep" + i, content));
    }
    final ProcessDefinition definition =
        deployAndEnableProcessWithActor(businessArchiveBuilder.done(), ACTOR_NAME, john);
    final ProcessInstance processInstance = getProcessAPI().startProcess(definition.getId());
    final Long step1Id = waitForUserTask(processInstance, "step1");
    setSessionInfo(getSession()); // the session was cleaned by api call. This must be improved
    List<Long> dependencyIds =
        transactionService.executeInTransaction(
            new GetDependenciesIds(getSession(), definition.getId(), dependencyService, 0, 100));
    assertEquals(25, dependencyIds.size());
    final SDependency dependency =
        transactionService.executeInTransaction(
            new GetSDependency(dependencyIds.get(0), dependencyService));
    assertNotNull(dependency);

    assignAndExecuteStep(step1Id, john.getId());
    waitForProcessToFinish(processInstance);
    disableAndDeleteProcess(definition);
    setSessionInfo(getSession()); // the session was cleaned by api call. This must be improved
    dependencyIds =
        transactionService.executeInTransaction(
            new GetDependenciesIds(getSession(), definition.getId(), dependencyService, 0, 100));
    assertEquals(0, dependencyIds.size());
  }
 @Before
 public void before() {
   lockProcessInstanceWork = new LockProcessInstanceWork(wrappedWork, processInstanceId);
   when(wrappedWork.getTenantId()).thenReturn(TENANT_ID);
   tenantAccessor = mock(TenantServiceAccessor.class);
   lockService = mock(LockService.class);
   workService = mock(WorkService.class);
   when(tenantAccessor.getLockService()).thenReturn(lockService);
   when(tenantAccessor.getWorkService()).thenReturn(workService);
   when(tenantAccessor.getTechnicalLoggerService()).thenReturn(mock(TechnicalLoggerService.class));
 }
  @Override
  public Serializable execute(
      final Map<String, Serializable> parameters, final TenantServiceAccessor serviceAccessor)
      throws SCommandParameterizationException, SCommandExecutionException {

    final String queryName = getStringMandadoryParameter(parameters, QUERY_NAME);
    @SuppressWarnings("unchecked")
    final Map<String, Serializable> queryParameters =
        (Map<String, Serializable>) parameters.get(QUERY_PARAMETERS);
    final String entityClassName = getStringMandadoryParameter(parameters, ENTITY_CLASS_NAME);
    final Integer startIndex = getIntegerMandadoryParameter(parameters, START_INDEX);
    final Integer maxResults = getIntegerMandadoryParameter(parameters, MAX_RESULTS);
    String businessDataURIPattern =
        getStringMandadoryParameter(parameters, BusinessDataCommandField.BUSINESS_DATA_URI_PATTERN);
    try {
      return serviceAccessor
          .getBusinessDataService()
          .getJsonQueryEntities(
              entityClassName,
              queryName,
              queryParameters,
              startIndex,
              maxResults,
              businessDataURIPattern);
    } catch (SBusinessDataRepositoryException e) {
      throw new SCommandExecutionException(e);
    }
  }
示例#5
0
  @Test
  public void checkPendingMappingAreDeleted() throws Exception {
    final TenantServiceAccessor tenantAccessor = getTenantAccessor();
    final ActivityInstanceService activityInstanceService =
        tenantAccessor.getActivityInstanceService();
    final UserTransactionService transactionService = tenantAccessor.getUserTransactionService();
    final ProcessDefinitionBuilder processDef =
        new ProcessDefinitionBuilder().createNewInstance("processToTestComment", "1.0");
    processDef.addShortTextData(
        "kikoo", new ExpressionBuilder().createConstantStringExpression("lol"));
    processDef.addStartEvent("start");
    processDef
        .addUserTask("step1", ACTOR_NAME)
        .addShortTextData("kikoo2", new ExpressionBuilder().createConstantStringExpression("lol"));
    processDef.addUserTask("step2", ACTOR_NAME);
    processDef.addEndEvent("end");
    processDef.addTransition("start", "step1");
    processDef.addTransition("step1", "step2");
    processDef.addTransition("step2", "end");
    processDef.addActor(ACTOR_NAME);
    final ProcessDefinition definition =
        deployAndEnableProcessWithActor(processDef.done(), ACTOR_NAME, john);
    final ProcessInstance processInstance = getProcessAPI().startProcess(definition.getId());
    final Long step1Id = waitForUserTask(processInstance, "step1");
    setSessionInfo(getSession()); // the session was cleaned by api call. This must be improved
    final Callable<List<SPendingActivityMapping>> getPendingMappings =
        new Callable<List<SPendingActivityMapping>>() {

          @Override
          public List<SPendingActivityMapping> call() throws Exception {
            final QueryOptions queryOptions =
                new QueryOptions(0, 100, SPendingActivityMapping.class, "id", OrderByType.ASC);
            return activityInstanceService.getPendingMappings(step1Id, queryOptions);
          }
        };
    List<SPendingActivityMapping> mappings =
        transactionService.executeInTransaction(getPendingMappings);
    assertEquals(1, mappings.size());
    assignAndExecuteStep(step1Id, john.getId());
    waitForUserTask(processInstance, "step2");
    setSessionInfo(getSession()); // the session was cleaned by api call. This must be improved
    mappings = transactionService.executeInTransaction(getPendingMappings);
    assertEquals(0, mappings.size());
    disableAndDeleteProcess(definition);
  }
 @Override
 public void execute() throws SBonitaException {
   // set tenant classloader
   final int maxResults = 100;
   final DependencyService dependencyService = tenantServiceAccessor.getDependencyService();
   dependencyService.refreshClassLoader(ScopeType.TENANT, tenantId);
   final ProcessDefinitionService processDefinitionService =
       tenantServiceAccessor.getProcessDefinitionService();
   List<Long> processDefinitionIds;
   int j = 0;
   do {
     processDefinitionIds = processDefinitionService.getProcessDefinitionIds(j, maxResults);
     j += maxResults;
     for (final Long id : processDefinitionIds) {
       dependencyService.refreshClassLoader(ScopeType.PROCESS, id);
     }
   } while (processDefinitionIds.size() == maxResults);
 }
示例#7
0
  @Override
  public void work(final Map<String, Object> context) throws Exception {
    final TenantServiceAccessor tenantAccessor = getTenantAccessor(context);
    final UserTransactionService userTransactionService =
        tenantAccessor.getUserTransactionService();

    final Callable<Void> runWork =
        new Callable<Void>() {

          @Override
          public Void call() throws Exception {
            getWrappedWork().work(context);
            return null;
          }
        };
    // Call the method work() wrapped in a transaction.
    userTransactionService.executeInTransaction(runWork);
  }
示例#8
0
  @Test
  public void checkDependenciesAreDeletedWhenProcessIsDeleted() throws Exception {
    final TenantServiceAccessor tenantAccessor = getTenantAccessor();
    final DependencyService dependencyService = tenantAccessor.getDependencyService();
    final UserTransactionService transactionService = tenantAccessor.getUserTransactionService();
    final ProcessDefinitionBuilder processDef =
        new ProcessDefinitionBuilder().createNewInstance("processToTestTransitions", "1.0");
    processDef.addStartEvent("start");
    processDef.addUserTask("step1", ACTOR_NAME);
    processDef.addEndEvent("end");
    processDef.addTransition("start", "step1");
    processDef.addTransition("step1", "end");
    processDef.addActor(ACTOR_NAME);
    final byte[] content = new byte[] {1, 2, 3, 4, 5, 6, 7};
    final BusinessArchive businessArchive =
        new BusinessArchiveBuilder()
            .createNewBusinessArchive()
            .setProcessDefinition(processDef.done())
            .addClasspathResource(new BarResource("myDep", content))
            .done();
    final ProcessDefinition definition =
        deployAndEnableProcessWithActor(businessArchive, ACTOR_NAME, john);
    final ProcessInstance processInstance = getProcessAPI().startProcess(definition.getId());
    final Long step1Id = waitForUserTask(processInstance, "step1");
    List<Long> dependencyIds =
        transactionService.executeInTransaction(
            new GetDependenciesIds(getSession(), definition.getId(), dependencyService, 0, 100));
    assertEquals(1, dependencyIds.size());
    final SDependency dependency =
        transactionService.executeInTransaction(
            new GetSDependency(dependencyIds.get(0), dependencyService));
    assertTrue(dependency.getName().endsWith("myDep"));
    assertTrue(Arrays.equals(content, dependency.getValue()));

    assignAndExecuteStep(step1Id, john);
    waitForProcessToFinish(processInstance);
    disableAndDeleteProcess(definition);

    dependencyIds =
        transactionService.executeInTransaction(
            new GetDependenciesIds(getSession(), definition.getId(), dependencyService, 0, 100));
    assertEquals(0, dependencyIds.size());
  }
示例#9
0
  @Test
  public void checkProcessCommentAreArchived() throws Exception {
    final TenantServiceAccessor tenantAccessor = getTenantAccessor();
    final SCommentService commentService = tenantAccessor.getCommentService();
    final UserTransactionService transactionService = tenantAccessor.getUserTransactionService();
    final ProcessDefinitionBuilder processDef =
        new ProcessDefinitionBuilder().createNewInstance("processToTestComment", "1.0");
    processDef.addStartEvent("start");
    processDef.addUserTask("step1", ACTOR_NAME);
    processDef.addEndEvent("end");
    processDef.addTransition("start", "step1");
    processDef.addTransition("step1", "end");
    processDef.addActor(ACTOR_NAME);
    final ProcessDefinition definition =
        deployAndEnableProcessWithActor(processDef.done(), ACTOR_NAME, john);
    setSessionInfo(getSession()); // the session was cleaned by api call. This must be improved
    final Callable<Long> getNumberOfComments =
        new Callable<Long>() {

          @Override
          public Long call() throws Exception {
            return commentService.getNumberOfComments(QueryOptions.countQueryOptions());
          }
        };
    final Callable<Long> getNumberOfArchivedComments =
        new Callable<Long>() {

          @Override
          public Long call() throws Exception {
            return commentService.getNumberOfArchivedComments(QueryOptions.countQueryOptions());
          }
        };
    assertEquals(0, (long) transactionService.executeInTransaction(getNumberOfComments));
    final long numberOfInitialArchivedComments =
        transactionService.executeInTransaction(getNumberOfArchivedComments);
    final ProcessInstance processInstance = getProcessAPI().startProcess(definition.getId());
    final Long step1Id = waitForUserTask(processInstance, "step1");
    getProcessAPI().addProcessComment(processInstance.getId(), "kikoo lol");
    setSessionInfo(getSession()); // the session was cleaned by api call. This must be improved
    assertEquals(1, (long) transactionService.executeInTransaction(getNumberOfComments));
    assertEquals(
        numberOfInitialArchivedComments,
        (long) transactionService.executeInTransaction(getNumberOfArchivedComments));
    assignAndExecuteStep(step1Id, john);

    setSessionInfo(getSession()); // the session was cleaned by api call. This must be improved
    assertEquals(
        2,
        (long)
            transactionService.executeInTransaction(getNumberOfComments)); // claim add a comment...
    assertEquals(
        numberOfInitialArchivedComments,
        (long) transactionService.executeInTransaction(getNumberOfArchivedComments));
    waitForProcessToFinish(processInstance);

    setSessionInfo(getSession()); // the session was cleaned by api call. This must be improved
    assertEquals(0, (long) transactionService.executeInTransaction(getNumberOfComments));
    assertEquals(
        numberOfInitialArchivedComments + 2,
        (long) transactionService.executeInTransaction(getNumberOfArchivedComments));
    disableAndDeleteProcess(definition);
  }