Search in sources :

Example 1 with ProcessDefinition

use of org.activiti.api.process.model.ProcessDefinition in project Activiti by Activiti.

the class APIProcessDefinitionConverterTest method should_convertFromProcessDefinition_when_allFieldsAreSet.

@Test
public void should_convertFromProcessDefinition_when_allFieldsAreSet() {
    ProcessDefinition convertedProcessDefinition = processDefinitionConverter.from(processDefinitionBuilderBuilder().withId("anId").withKey("processKey").withName("Process Name").withDescription("process description").withVersion(3).withAppVersion(1).build());
    assertThat(convertedProcessDefinition).isNotNull().extracting(ProcessDefinition::getId, ProcessDefinition::getKey, ProcessDefinition::getName, ProcessDefinition::getDescription, ProcessDefinition::getVersion, ProcessDefinition::getAppVersion, ProcessDefinition::getFormKey).containsExactly("anId", "processKey", "Process Name", "process description", 3, "1", "AFormKey");
}
Also used : ProcessDefinition(org.activiti.api.process.model.ProcessDefinition) Test(org.junit.jupiter.api.Test)

Example 2 with ProcessDefinition

use of org.activiti.api.process.model.ProcessDefinition in project Activiti by Activiti.

the class ProcessAdminRuntimeImpl method start.

@Override
public ProcessInstance start(StartProcessPayload startProcessPayload) {
    ProcessDefinition processDefinition = null;
    if (startProcessPayload.getProcessDefinitionId() != null) {
        processDefinition = processDefinition(startProcessPayload.getProcessDefinitionId());
    }
    if (processDefinition == null && startProcessPayload.getProcessDefinitionKey() != null) {
        processDefinition = processDefinition(startProcessPayload.getProcessDefinitionKey());
    }
    if (processDefinition == null) {
        throw new IllegalStateException("At least Process Definition Id or Key needs to be provided to start a process");
    }
    processVariablesValidator.checkStartProcessPayloadVariables(startProcessPayload, processDefinition.getId());
    return processInstanceConverter.from(runtimeService.createProcessInstanceBuilder().processDefinitionId(processDefinition.getId()).processDefinitionKey(processDefinition.getKey()).businessKey(startProcessPayload.getBusinessKey()).variables(startProcessPayload.getVariables()).name(startProcessPayload.getName()).start());
}
Also used : ProcessDefinition(org.activiti.api.process.model.ProcessDefinition)

Example 3 with ProcessDefinition

use of org.activiti.api.process.model.ProcessDefinition in project Activiti by Activiti.

the class ProcessRuntimeImpl method processDefinitions.

@Override
public Page<ProcessDefinition> processDefinitions(Pageable pageable, GetProcessDefinitionsPayload getProcessDefinitionsPayload) {
    if (getProcessDefinitionsPayload == null) {
        throw new IllegalStateException("payload cannot be null");
    }
    GetProcessDefinitionsPayload securityKeysInPayload = securityPoliciesManager.restrictProcessDefQuery(SecurityPolicyAccess.READ);
    // else ignore and use the user provided ones.
    if (!securityKeysInPayload.getProcessDefinitionKeys().isEmpty()) {
        getProcessDefinitionsPayload.setProcessDefinitionKeys(securityKeysInPayload.getProcessDefinitionKeys());
    }
    ProcessDefinitionQuery processDefinitionQuery = repositoryService.createProcessDefinitionQuery();
    if (getProcessDefinitionsPayload.hasDefinitionKeys()) {
        processDefinitionQuery.processDefinitionKeys(getProcessDefinitionsPayload.getProcessDefinitionKeys());
    }
    List<org.activiti.engine.repository.ProcessDefinition> currentVersionDefinitions = filterCurrentVersionDefinitions(processDefinitionQuery.list());
    return new PageImpl<>(processDefinitionConverter.from(currentVersionDefinitions), Math.toIntExact(processDefinitionQuery.count()));
}
Also used : PageImpl(org.activiti.runtime.api.query.impl.PageImpl) ProcessDefinitionQuery(org.activiti.engine.repository.ProcessDefinitionQuery) ProcessDefinition(org.activiti.api.process.model.ProcessDefinition) GetProcessDefinitionsPayload(org.activiti.api.process.model.payloads.GetProcessDefinitionsPayload)

Example 4 with ProcessDefinition

use of org.activiti.api.process.model.ProcessDefinition in project Activiti by Activiti.

the class ProcessRuntimeImpl method createProcessInstanceBuilder.

private ProcessInstanceBuilder createProcessInstanceBuilder(StartProcessPayload startProcessPayload) {
    ProcessDefinition processDefinition = getProcessDefinitionAndCheckUserHasRights(startProcessPayload.getProcessDefinitionId(), startProcessPayload.getProcessDefinitionKey());
    processVariablesValidator.checkStartProcessPayloadVariables(startProcessPayload, processDefinition.getId());
    return runtimeService.createProcessInstanceBuilder().processDefinitionId(processDefinition.getId()).processDefinitionKey(processDefinition.getKey()).businessKey(startProcessPayload.getBusinessKey()).variables(startProcessPayload.getVariables()).name(startProcessPayload.getName());
}
Also used : ProcessDefinition(org.activiti.api.process.model.ProcessDefinition)

Example 5 with ProcessDefinition

use of org.activiti.api.process.model.ProcessDefinition in project Activiti by Activiti.

the class ProcessRuntimeIT method updateProcessInstanceAdmin.

@Test
public void updateProcessInstanceAdmin() {
    securityUtil.logInAs("admin");
    Page<ProcessDefinition> processDefinitionPage = processAdminRuntime.processDefinitions(Pageable.of(0, 50));
    assertThat(processDefinitionPage.getContent()).isNotNull();
    assertThat(processDefinitionPage.getContent()).extracting(ProcessDefinition::getKey).contains(CATEGORIZE_HUMAN_PROCESS);
    // start a process with a business key to check filters
    ProcessInstance categorizeProcess = processAdminRuntime.start(ProcessPayloadBuilder.start().withProcessDefinitionKey(CATEGORIZE_HUMAN_PROCESS).withVariable("expectedKey", true).withBusinessKey("my business key").withName("my process name").build());
    assertThat(categorizeProcess).isNotNull();
    assertThat(categorizeProcess.getStatus()).isEqualTo(ProcessInstance.ProcessInstanceStatus.RUNNING);
    assertThat(categorizeProcess.getName()).isEqualTo("my process name");
    // update a process
    Page<ProcessInstance> processInstancePage = processAdminRuntime.processInstances(PAGEABLE);
    ProcessInstance processInstance = processInstancePage.getContent().get(0);
    UpdateProcessPayload updateProcessPayload = ProcessPayloadBuilder.update().withProcessInstanceId(processInstance.getId()).withBusinessKey(processInstance.getBusinessKey() + " UPDATED").withName(processInstance.getName() + " UPDATED").build();
    ProcessInstance updatedProcessInstance = processAdminRuntime.update(updateProcessPayload);
    assertThat(updatedProcessInstance).isNotNull();
    processInstancePage = processAdminRuntime.processInstances(PAGEABLE);
    assertThat(processInstancePage).isNotNull();
    assertThat(processInstancePage.getContent()).hasSize(1);
    processInstance = processInstancePage.getContent().get(0);
    assertThat(processInstance.getName()).isEqualTo("my process name UPDATED");
    assertThat(processInstance.getBusinessKey()).isEqualTo("my business key UPDATED");
    // delete a process to avoid possible problems with other tests
    ProcessInstance deletedProcessInstance = processAdminRuntime.delete(ProcessPayloadBuilder.delete(categorizeProcess));
    assertThat(deletedProcessInstance).isNotNull();
    assertThat(deletedProcessInstance.getStatus()).isEqualTo(ProcessInstance.ProcessInstanceStatus.CANCELLED);
}
Also used : UpdateProcessPayload(org.activiti.api.process.model.payloads.UpdateProcessPayload) ProcessDefinition(org.activiti.api.process.model.ProcessDefinition) ProcessInstance(org.activiti.api.process.model.ProcessInstance) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

ProcessDefinition (org.activiti.api.process.model.ProcessDefinition)21 Test (org.junit.jupiter.api.Test)13 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)11 ProcessInstance (org.activiti.api.process.model.ProcessInstance)5 UpdateProcessPayload (org.activiti.api.process.model.payloads.UpdateProcessPayload)4 ProcessRuntimeConfiguration (org.activiti.api.process.runtime.conf.ProcessRuntimeConfiguration)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ProcessPayloadBuilder (org.activiti.api.process.model.builders.ProcessPayloadBuilder)3 SignalPayload (org.activiti.api.process.model.payloads.SignalPayload)3 ProcessRuntime (org.activiti.api.process.runtime.ProcessRuntime)3 Page (org.activiti.api.runtime.shared.query.Page)3 Pageable (org.activiti.api.runtime.shared.query.Pageable)3 RepositoryService (org.activiti.engine.RepositoryService)3 APIProcessDefinitionConverter (org.activiti.runtime.api.model.impl.APIProcessDefinitionConverter)3 SecurityUtil (org.activiti.spring.boot.security.util.SecurityUtil)3 ProcessCleanUpUtil (org.activiti.spring.boot.test.util.ProcessCleanUpUtil)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2