Пример #1
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());
  }
Пример #2
0
  private ProcessDefinition deployAndEnableProcessWithReceivedTask(
      final String processName,
      final String receiveTaskName,
      final String userTaskName,
      final String actorName,
      final User user,
      final String messageName,
      final List<BEntry<Expression, Expression>> correlations,
      final Map<String, String> processData,
      final List<Operation> operations)
      throws BonitaException {
    final ProcessDefinitionBuilder processBuilder = new ProcessDefinitionBuilder();
    processBuilder.createNewInstance(processName, "1.0");
    addProcessData(processData, processBuilder);
    processBuilder.addStartEvent("startEvent");
    final ReceiveTaskDefinitionBuilder receiveTaskBuilder =
        processBuilder.addReceiveTask(receiveTaskName, messageName);
    if (correlations != null) {
      for (final Entry<Expression, Expression> entry : correlations) {
        receiveTaskBuilder.addCorrelation(entry.getKey(), entry.getValue());
      }
    }
    if (operations != null) {
      for (final Operation operation : operations) {
        receiveTaskBuilder.addMessageOperation(operation);
      }
    }

    processBuilder.addActor(actorName);
    processBuilder.addUserTask(userTaskName, actorName);
    processBuilder.addEndEvent("endEvent");
    processBuilder.addTransition("startEvent", receiveTaskName);
    processBuilder.addTransition(receiveTaskName, userTaskName);
    processBuilder.addTransition(userTaskName, "endEvent");
    final DesignProcessDefinition designProcessDefinition = processBuilder.done();

    final BusinessArchiveBuilder archiveBuilder = new BusinessArchiveBuilder();
    archiveBuilder.createNewBusinessArchive().setProcessDefinition(designProcessDefinition);
    final BusinessArchive receiveMessaceArchive = archiveBuilder.done();
    final ProcessDefinition receiveMessageProcess = deployProcess(receiveMessaceArchive);

    final List<ActorInstance> actors =
        getProcessAPI().getActors(receiveMessageProcess.getId(), 0, 1, ActorCriterion.NAME_ASC);
    getProcessAPI().addUserToActor(actors.get(0).getId(), user.getId());

    getProcessAPI().enableProcess(receiveMessageProcess.getId());

    final ProcessDeploymentInfo processDeploymentInfo =
        getProcessAPI().getProcessDeploymentInfo(receiveMessageProcess.getId());
    assertEquals(ActivationState.ENABLED, processDeploymentInfo.getActivationState());

    return receiveMessageProcess;
  }
Пример #3
0
  protected void addProcessImage(
      final BusinessArchiveBuilder builder, final AbstractProcess process) throws CoreException {
    if (PlatformUI.isWorkbenchRunning()) {
      final String processName = process.getName() + "_" + process.getVersion();
      final String path = processName + ".png"; // $NON-NLS-1$

      try {
        Diagram diagram = ModelHelper.getDiagramFor(ModelHelper.getMainProcess(process));
        if (diagram == null) {
          return; // DON'T ADD IMAGE, DON'T THROW EXCEPTION FOR TESTS PURPUSES
        }
        final ResourceSet resourceSet = new ResourceSetImpl();
        final TransactionalEditingDomain editingDomain =
            CustomDiagramEditingDomainFactory.getInstance().createEditingDomain(resourceSet);
        final Resource resource = resourceSet.createResource(diagram.eResource().getURI());
        try {
          resource.load(resourceSet.getLoadOptions());
        } catch (final IOException e1) {
          BonitaStudioLog.error(e1);
        }
        diagram = (Diagram) resource.getEObject(diagram.eResource().getURIFragment(diagram));
        final CopyToImageUtilEx copyToImageUtil = new CopyToImageUtilEx();
        byte[] imageBytes = null;
        try {
          imageBytes =
              copyToImageUtil.copyToImageByteArray(
                  diagram,
                  process,
                  ImageFileFormat.PNG,
                  Repository.NULL_PROGRESS_MONITOR,
                  new PreferencesHint("exportToImage"),
                  true);
        } catch (final Exception e) {
          BonitaStudioLog.error(e);
          return;
        } finally {
          editingDomain.dispose();
        }
        if (imageBytes != null) {
          try {
            builder.addExternalResource(new BarResource(path, imageBytes));
          } catch (final Exception e) {
            BonitaStudioLog.log("Process image file generation has failed"); // $NON-NLS-1$
          }
        }
      } catch (final Exception e) {
        BonitaStudioLog.error(e);
      }
    }
  }
Пример #4
0
  public BusinessArchive createBusinessArchive(
      final AbstractProcess process,
      final Configuration configuration,
      final Set<EObject> excludedObject,
      final boolean addProcessImage)
      throws Exception {

    checkArgument(configuration != null);
    BonitaStudioLog.info(
        "Building bar for process " + process.getName() + " (" + process.getVersion() + " )...",
        EnginePlugin.PLUGIN_ID);
    final DesignProcessDefinitionBuilder procBuilder = getProcessDefinitionBuilder();
    procBuilder.seteObjectNotExported(excludedObject);
    final DesignProcessDefinition def = procBuilder.createDefinition(process);

    if (def == null) {
      throw new Exception(Messages.cantDeployEmptyPool);
    }

    final BusinessArchiveBuilder builder = new BusinessArchiveBuilder().createNewBusinessArchive();
    builder.setProcessDefinition(def);

    builder.setParameters(getParameterMapFromConfiguration(configuration));
    final byte[] content = new ActorMappingExporter().toByteArray(configuration);
    if (content != null) {
      builder.setActorMapping(content);
    }

    for (final BARResourcesProvider resourceProvider : getBARResourcesProvider()) {
      resourceProvider.addResourcesForConfiguration(
          builder, process, configuration, excludedObject);
    }

    // Add forms resources
    final BARResourcesProvider provider = getBARApplicationResourcesProvider();
    if (provider != null) {
      provider.addResourcesForConfiguration(builder, process, configuration, excludedObject);
    }

    if (!(process instanceof SubProcessEvent)) {
      if (addProcessImage) {
        Display.getDefault()
            .syncExec(
                new Runnable() {

                  @Override
                  public void run() {
                    try {
                      addProcessImage(builder, process);
                    } catch (final CoreException e) {
                      BonitaStudioLog.error(e);
                    }
                  }
                });
      }
    }

    final BusinessArchive archive = builder.done();
    BonitaStudioLog.info(
        "Build complete for process " + process.getName() + " (" + process.getVersion() + " ).",
        EnginePlugin.PLUGIN_ID);
    return archive;
  }