org.flowable.engine.repository.ProcessDefinition Java Examples

The following examples show how to use org.flowable.engine.repository.ProcessDefinition. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ProcessInstanceSuspensionTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = "org/flowable/engine/test/api/runtime/ProcessInstanceSuspensionTest.testJobNotExecutedAfterProcessInstanceSuspend.bpmn20.xml")
public void testJobActivationAfterProcessInstanceSuspend() {

    Date now = new Date();
    processEngineConfiguration.getClock().setCurrentTime(now);

    // Suspending the process instance should also stop the execution of jobs for that process instance
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstance processInstance = runtimeService.startProcessInstanceById(processDefinition.getId());
    assertThat(managementService.createTimerJobQuery().count()).isEqualTo(1);
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    assertThat(managementService.createSuspendedJobQuery().count()).isEqualTo(1);

    Job job = managementService.createTimerJobQuery().executable().singleResult();
    assertThat(job).isNull();

    Job suspendedJob = managementService.createSuspendedJobQuery().singleResult();
    assertThat(suspendedJob).isNotNull();

    // Activation of the suspended job instance should throw exception because parent is suspended
    assertThatThrownBy(() -> managementService.moveSuspendedJobToExecutableJob(suspendedJob.getId()))
            .as("FlowableIllegalArgumentException expected. Cannot activate job with suspended parent")
            .isExactlyInstanceOf(FlowableIllegalArgumentException.class)
            .hasMessageContaining("Can not activate job " + suspendedJob.getId() + ". Parent is suspended.");
}
 
Example #2
Source File: BusinessProcess.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deprecated
public ProcessInstance startProcessByName(String string) {

    if (Context.getCommandContext() != null) {
        throw new FlowableCdiException("Cannot use startProcessByName in an active command.");
    }

    ProcessDefinition definition = processEngine.getRepositoryService().createProcessDefinitionQuery().processDefinitionName(string).singleResult();
    if (definition == null) {
        throw new FlowableObjectNotFoundException("No process definition found for name: " + string, ProcessDefinition.class);
    }
    ProcessInstance instance = processEngine.getRuntimeService().startProcessInstanceById(definition.getId(), getAndClearCachedVariables());
    if (!instance.isEnded()) {
        setExecution(instance);
    }
    return instance;
}
 
Example #3
Source File: ProcessDefinitionQueryTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void testProcessDefinitionProperties() {
    List<ProcessDefinition> processDefinitions = repositoryService
            .createProcessDefinitionQuery()
            .orderByProcessDefinitionName().asc()
            .orderByProcessDefinitionVersion().asc()
            .orderByProcessDefinitionCategory().asc()
            .list();

    ProcessDefinition processDefinition = processDefinitions.get(0);
    assertEquals("one", processDefinition.getKey());
    assertEquals("One", processDefinition.getName());
    assertTrue(processDefinition.getId().startsWith("one:1"));
    assertEquals("Examples", processDefinition.getCategory());

    processDefinition = processDefinitions.get(1);
    assertEquals("one", processDefinition.getKey());
    assertEquals("One", processDefinition.getName());
    assertTrue(processDefinition.getId().startsWith("one:2"));
    assertEquals("Examples", processDefinition.getCategory());

    processDefinition = processDefinitions.get(2);
    assertEquals("two", processDefinition.getKey());
    assertEquals("Two", processDefinition.getName());
    assertTrue(processDefinition.getId().startsWith("two:1"));
    assertEquals("Examples2", processDefinition.getCategory());
}
 
Example #4
Source File: GetStartFormCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public StartFormData execute(CommandContext commandContext) {
    ProcessDefinition processDefinition = CommandContextUtil.getProcessEngineConfiguration(commandContext).getDeploymentManager().findDeployedProcessDefinitionById(processDefinitionId);
    if (processDefinition == null) {
        throw new FlowableObjectNotFoundException("No process definition found for id '" + processDefinitionId + "'", ProcessDefinition.class);
    }

    if (Flowable5Util.isFlowable5ProcessDefinition(processDefinition, commandContext)) {
        return Flowable5Util.getFlowable5CompatibilityHandler().getStartFormData(processDefinitionId);
    }

    FormHandlerHelper formHandlerHelper = CommandContextUtil.getProcessEngineConfiguration(commandContext).getFormHandlerHelper();
    StartFormHandler startFormHandler = formHandlerHelper.getStartFormHandler(commandContext, processDefinition);
    if (startFormHandler == null) {
        throw new FlowableException("No startFormHandler defined in process '" + processDefinitionId + "'");
    }

    return startFormHandler.createStartFormData(processDefinition);
}
 
Example #5
Source File: AbstractDynamicStateManager.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected ProcessDefinition resolveProcessDefinition(String processDefinitionKey, Integer processDefinitionVersion, String tenantId, CommandContext commandContext) {
    ProcessDefinitionEntityManager processDefinitionEntityManager = CommandContextUtil.getProcessDefinitionEntityManager(commandContext);
    ProcessDefinition processDefinition;
    if (processDefinitionVersion != null) {
        processDefinition = processDefinitionEntityManager.findProcessDefinitionByKeyAndVersionAndTenantId(processDefinitionKey, processDefinitionVersion, tenantId);
    } else {
        if (tenantId == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(tenantId)) {
            processDefinition = processDefinitionEntityManager.findLatestProcessDefinitionByKey(processDefinitionKey);
        } else {
            processDefinition = processDefinitionEntityManager.findLatestProcessDefinitionByKeyAndTenantId(processDefinitionKey, tenantId);
        }
    }

    if (processDefinition == null) {
        DeploymentManager deploymentManager = CommandContextUtil.getProcessEngineConfiguration(commandContext).getDeploymentManager();
        if (tenantId == null || ProcessEngineConfiguration.NO_TENANT_ID.equals(tenantId)) {
            processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKey(processDefinitionKey);
        } else {
            processDefinition = deploymentManager.findDeployedLatestProcessDefinitionByKeyAndTenantId(processDefinitionKey, tenantId);
        }
    }
    return processDefinition;
}
 
Example #6
Source File: DeploymentEntityManagerImpl.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void restoreSignalStartEvent(ProcessDefinition previousProcessDefinition, BpmnModel bpmnModel, StartEvent startEvent, EventDefinition eventDefinition) {
    CommandContext commandContext = Context.getCommandContext();
    SignalEventDefinition signalEventDefinition = (SignalEventDefinition) eventDefinition;
    SignalEventSubscriptionEntity subscriptionEntity = CommandContextUtil.getEventSubscriptionService(commandContext).createSignalEventSubscription();

    String eventName = EventDefinitionExpressionUtil.determineSignalName(commandContext, signalEventDefinition, bpmnModel, null);
    subscriptionEntity.setEventName(eventName);
    subscriptionEntity.setActivityId(startEvent.getId());
    subscriptionEntity.setProcessDefinitionId(previousProcessDefinition.getId());
    if (previousProcessDefinition.getTenantId() != null) {
        subscriptionEntity.setTenantId(previousProcessDefinition.getTenantId());
    }

    CommandContextUtil.getEventSubscriptionService(commandContext).insertEventSubscription(subscriptionEntity);
    CountingEntityUtil.handleInsertEventSubscriptionEntityCount(subscriptionEntity);
}
 
Example #7
Source File: HistoricProcessInstanceQueryImpl.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void localize(HistoricProcessInstance processInstance, CommandContext commandContext) {
    processInstance.setLocalizedName(null);
    processInstance.setLocalizedDescription(null);

    if (locale != null && processInstance.getProcessDefinitionId() != null) {
        ProcessDefinition processDefinition = commandContext.getProcessEngineConfiguration().getDeploymentManager().findDeployedProcessDefinitionById(processInstance.getProcessDefinitionId());
        ObjectNode languageNode = Context.getLocalizationElementProperties(locale, processDefinition.getKey(),
                processInstance.getProcessDefinitionId(), withLocalizationFallback);

        if (languageNode != null) {
            JsonNode languageNameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME);
            if (languageNameNode != null && !languageNameNode.isNull()) {
                processInstance.setLocalizedName(languageNameNode.asText());
            }

            JsonNode languageDescriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION);
            if (languageDescriptionNode != null && !languageDescriptionNode.isNull()) {
                processInstance.setLocalizedDescription(languageDescriptionNode.asText());
            }
        }
    }
}
 
Example #8
Source File: StartProcessInstanceBeforeContext.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public StartProcessInstanceBeforeContext(String businessKey, String processInstanceName,
                String callbackId, String callbackType, String referenceId, String referenceType,
                Map<String, Object> variables, Map<String, Object> transientVariables, String tenantId, 
                String initiatorVariableName, String initialActivityId, FlowElement initialFlowElement, Process process,
                ProcessDefinition processDefinition, String overrideDefinitionTenantId, String predefinedProcessInstanceId) {
    
    super(businessKey, processInstanceName, variables, initialActivityId, initialFlowElement, process, processDefinition);
    
    this.callbackId = callbackId;
    this.callbackType = callbackType;
    this.referenceId = referenceId;
    this.referenceType = referenceType;
    this.transientVariables = transientVariables;
    this.tenantId = tenantId;
    this.initiatorVariableName = initiatorVariableName;
    this.overrideDefinitionTenantId = overrideDefinitionTenantId;
    this.predefinedProcessInstanceId = predefinedProcessInstanceId;
}
 
Example #9
Source File: ProcessDefinitionSuspensionTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/db/processOne.bpmn20.xml" })
public void testSuspendActivateProcessDefinitionByKey() {

    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertThat(processDefinition.isSuspended()).isFalse();

    // suspend
    repositoryService.suspendProcessDefinitionByKey(processDefinition.getKey());
    processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertThat(processDefinition.isSuspended()).isTrue();

    // activate
    repositoryService.activateProcessDefinitionByKey(processDefinition.getKey());
    processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    assertThat(processDefinition.isSuspended()).isFalse();
}
 
Example #10
Source File: ProcessInstanceSuspensionTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/api/runtime/oneTaskProcess.bpmn20.xml" })
public void testSuspendActivateProcessInstance() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    runtimeService.startProcessInstanceByKey(processDefinition.getKey());

    ProcessInstance processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertThat(processInstance.isSuspended()).isFalse();

    // suspend
    runtimeService.suspendProcessInstanceById(processInstance.getId());
    processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertThat(processInstance.isSuspended()).isTrue();

    // activate
    runtimeService.activateProcessInstanceById(processInstance.getId());
    processInstance = runtimeService.createProcessInstanceQuery().singleResult();
    assertThat(processInstance.isSuspended()).isFalse();
}
 
Example #11
Source File: DeploymentEntityManagerImpl.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void restoreMessageStartEvent(ProcessDefinition previousProcessDefinition, BpmnModel bpmnModel, StartEvent startEvent, EventDefinition eventDefinition) {
    MessageEventDefinition messageEventDefinition = (MessageEventDefinition) eventDefinition;
    if (bpmnModel.containsMessageId(messageEventDefinition.getMessageRef())) {
        Message message = bpmnModel.getMessage(messageEventDefinition.getMessageRef());
        messageEventDefinition.setMessageRef(message.getName());
    }

    CommandContext commandContext = Context.getCommandContext();
    MessageEventSubscriptionEntity newSubscription = CommandContextUtil.getEventSubscriptionService(commandContext).createMessageEventSubscription();
    String messageName = EventDefinitionExpressionUtil.determineMessageName(commandContext, messageEventDefinition, null);
    newSubscription.setEventName(messageName);
    newSubscription.setActivityId(startEvent.getId());
    newSubscription.setConfiguration(previousProcessDefinition.getId());
    newSubscription.setProcessDefinitionId(previousProcessDefinition.getId());

    if (previousProcessDefinition.getTenantId() != null) {
        newSubscription.setTenantId(previousProcessDefinition.getTenantId());
    }

    CommandContextUtil.getEventSubscriptionService().insertEventSubscription(newSubscription);
    CountingEntityUtil.handleInsertEventSubscriptionEntityCount(newSubscription);
}
 
Example #12
Source File: ProcessWithFormTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void completeTaskWithoutValidationOnModelLevel(RuntimeService runtimeService,
    TaskService taskService, RepositoryService repositoryService) {

    Deployment deployment = repositoryService.createDeployment().
        addString("oneTaskWithFormKeySideEffectProcess.bpmn20.xml",
            ONE_TASK_PROCESS.
                replace("START_EVENT_VALIDATION", "false").
                replace("USER_TASK_VALIDATION", "false")
        ).
        deploy();
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();
    ProcessInstance processInstance = runtimeService.startProcessInstanceWithForm(processDefinition.getId(),"__COMPLETE", Collections.emptyMap(),
        "oneTaskWithFormSideEffectProcess");
    assertThat(SideEffectExecutionListener.getSideEffect()).isEqualTo(1);
    SideEffectExecutionListener.reset();

    Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();

    FormRepositoryService formRepositoryService = FormEngines.getDefaultFormEngine().getFormRepositoryService();
    FormDefinition formDefinition = formRepositoryService.createFormDefinitionQuery().formDefinitionKey("form1").singleResult();

    taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), "__COMPLETE", Collections.singletonMap("initiator", "someInitiator"));

    assertThat(SideEffectExecutionListener.getSideEffect()).isEqualTo(1);
}
 
Example #13
Source File: ProcessDefinitionSuspensionTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment(resources = {
        "org/activiti/engine/test/db/processOne.bpmn20.xml",
        "org/activiti/engine/test/db/processTwo.bpmn20.xml"
})
public void testQueryForSuspendedDefinitions() {

    // default = all definitions
    List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery()
            .list();
    assertEquals(2, processDefinitionList.size());

    assertEquals(2, repositoryService.createProcessDefinitionQuery().active().count());

    ProcessDefinition processDefinition = processDefinitionList.get(0);
    repositoryService.suspendProcessDefinitionById(processDefinition.getId());

    assertEquals(2, repositoryService.createProcessDefinitionQuery().count());
    assertEquals(1, repositoryService.createProcessDefinitionQuery().suspended().count());
}
 
Example #14
Source File: FlowableBpmnProcessManager.java    From syncope with Apache License 2.0 6 votes vote down vote up
@Override
public void exportProcess(final String key, final BpmnProcessFormat format, final OutputStream os) {
    switch (format) {
        case JSON:
            exportProcessModel(key, os);
            break;

        case XML:
        default:
            ProcessDefinition procDef = FlowableRuntimeUtils.getLatestProcDefByKey(engine, key);
            if (procDef == null) {
                throw new NotFoundException("Process Definition " + key);
            }
            exportProcessResource(procDef.getDeploymentId(), procDef.getResourceName(), os);
    }
}
 
Example #15
Source File: ProcessDefinitionSuspensionTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Deployment
public void testJobIsExecutedOnProcessDefinitionSuspend() {

    Date now = new Date();
    processEngineConfiguration.getClock().setCurrentTime(now);

    // Suspending the process definition should not stop the execution of jobs
    // Added this test because in previous implementations, this was the case.
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    runtimeService.startProcessInstanceById(processDefinition.getId());
    repositoryService.suspendProcessDefinitionById(processDefinition.getId());
    assertEquals(1, managementService.createTimerJobQuery().count());

    // The jobs should simply be executed
    processEngineConfiguration.getClock().setCurrentTime(new Date(now.getTime() + (60 * 60 * 1000))); // Timer is set to fire on 5 minutes
    waitForJobExecutorToProcessAllJobs(2000L, 100L);
    assertEquals(0, managementService.createTimerJobQuery().count());
}
 
Example #16
Source File: SpringAutoDeployTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testAutoDeployWithInvalidResourcesWithDeploymentModeDefault() {
    Map<String, Object> properties = new HashMap<>();
    properties.put("deploymentMode", "default");
    properties.put("deploymentResources", DEFAULT_INVALID_DEPLOYMENT_RESOURCES);
    assertThatThrownBy(() -> createAppContext(properties))
            .hasCauseInstanceOf(XMLException.class);
    assertThat(repositoryService).isNull();

    // Some of the resources should have been deployed
    properties.put("deploymentResources", "classpath*:/notExisting*.bpmn20.xml");
    createAppContext(properties);
    assertThat(repositoryService.createProcessDefinitionQuery().list())
            .extracting(ProcessDefinition::getKey)
            .isEmpty();
    assertThat(repositoryService.createDeploymentQuery().count()).isZero();
}
 
Example #17
Source File: ProcessDefinitionPersistenceTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
public void testProcessDefinitionPersistence() {
    String deploymentId = repositoryService
            .createDeployment()
            .addClasspathResource("org/activiti/engine/test/db/processOne.bpmn20.xml")
            .addClasspathResource("org/activiti/engine/test/db/processTwo.bpmn20.xml")
            .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
            .deploy()
            .getId();

    List<ProcessDefinition> processDefinitions = repositoryService
            .createProcessDefinitionQuery()
            .list();

    assertEquals(2, processDefinitions.size());

    repositoryService.deleteDeployment(deploymentId);
}
 
Example #18
Source File: SetProcessDefinitionVersionCmd.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
protected void validateAndSwitchVersionOfExecution(CommandContext commandContext, ExecutionEntity execution, ProcessDefinition newProcessDefinition) {
    // check that the new process definition version contains the current activity
    org.flowable.bpmn.model.Process process = ProcessDefinitionUtil.getProcess(newProcessDefinition.getId());
    if (execution.getActivityId() != null && process.getFlowElement(execution.getActivityId(), true) == null) {
        throw new FlowableException("The new process definition " + "(key = '" + newProcessDefinition.getKey() + "') " + "does not contain the current activity " + "(id = '"
                + execution.getActivityId() + "') " + "of the process instance " + "(id = '" + processInstanceId + "').");
    }

    // switch the process instance to the new process definition version
    execution.setProcessDefinitionId(newProcessDefinition.getId());
    execution.setProcessDefinitionName(newProcessDefinition.getName());
    execution.setProcessDefinitionKey(newProcessDefinition.getKey());

    // and change possible existing tasks (as the process definition id is stored there too)
    List<TaskEntity> tasks = CommandContextUtil.getTaskService(commandContext).findTasksByExecutionId(execution.getId());
    Clock clock = commandContext.getCurrentEngineConfiguration().getClock();
    for (TaskEntity taskEntity : tasks) {
        taskEntity.setProcessDefinitionId(newProcessDefinition.getId());
        CommandContextUtil.getActivityInstanceEntityManager(commandContext).recordTaskInfoChange(taskEntity, clock.getCurrentTime());
    }
}
 
Example #19
Source File: ProcessEngineMvcEndpoint.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Look up the process definition by key. For example, this is <A href="http://localhost:8080/activiti/processes/fulfillmentProcess">process-diagram for</A> a process definition named
 * {@code fulfillmentProcess}.
 */
@GetMapping(value = "/processes/{processDefinitionKey:.*}", produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public ResponseEntity processDefinitionDiagram(@PathVariable String processDefinitionKey) {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
            .processDefinitionKey(processDefinitionKey)
            .latestVersion()
            .singleResult();
    if (processDefinition == null) {
        return ResponseEntity.status(HttpStatus.NOT_FOUND).body(null);
    }

    ProcessDiagramGenerator processDiagramGenerator = new DefaultProcessDiagramGenerator();
    BpmnModel bpmnModel = repositoryService.getBpmnModel(processDefinition.getId());

    if (bpmnModel.getLocationMap().size() == 0) {
        BpmnAutoLayout autoLayout = new BpmnAutoLayout(bpmnModel);
        autoLayout.execute();
    }

    InputStream is = processDiagramGenerator.generateJpgDiagram(bpmnModel);
    return ResponseEntity.ok(new InputStreamResource(is));
}
 
Example #20
Source File: ProcessDefinitionQueryByLatestTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueryByLatestAndVersion() throws Exception {
    // Deploy
    List<String> xmlFileNameList = Arrays.asList("version_testProcess1_one.bpmn20.xml",
            "version_testProcess1_two.bpmn20.xml", "version_testProcess2_one.bpmn20.xml");
    List<String> deploymentIdList = deploy(xmlFileNameList);

    // version
    ProcessDefinitionQuery nameQuery = repositoryService.createProcessDefinitionQuery().processDefinitionVersion(1).latestVersion();
    List<ProcessDefinition> processDefinitions = nameQuery.list();
    assertThat(processDefinitions)
            .extracting(ProcessDefinition::getKey)
            .containsExactly("testProcess2");

    // Undeploy
    unDeploy(deploymentIdList);
}
 
Example #21
Source File: ProcessDefinitionsTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeployIdenticalProcessDefinitions() {
    List<String> deploymentIds = new ArrayList<>();
    deploymentIds.add(deployProcessString(("<definitions " + NAMESPACE + " " + TARGET_NAMESPACE + ">" + "  <process id='IDR' name='Insurance Damage Report' />" + "</definitions>")));
    deploymentIds.add(deployProcessString(("<definitions " + NAMESPACE + " " + TARGET_NAMESPACE + ">" + "  <process id='IDR' name='Insurance Damage Report' />" + "</definitions>")));

    List<ProcessDefinition> processDefinitions = repositoryService.createProcessDefinitionQuery().orderByProcessDefinitionKey().asc().orderByProcessDefinitionVersion().desc().list();

    assertThat(processDefinitions).isNotNull();
    assertThat(processDefinitions)
            .extracting(ProcessDefinition::getKey, ProcessDefinition::getName, ProcessDefinition::getVersion)
            .containsExactly(
                    tuple("IDR", "Insurance Damage Report", 2),
                    tuple("IDR", "Insurance Damage Report", 1)
            );
    assertThat(processDefinitions.get(0).getId()).startsWith("IDR:2");
    assertThat(processDefinitions.get(1).getId()).startsWith("IDR:1");

    deleteDeployments(deploymentIds);
}
 
Example #22
Source File: MixedDeploymentTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/form/engine/test/deployment/oneTaskWithFormKeyProcess.bpmn20.xml",
        "org/flowable/form/engine/test/deployment/simple.form" })
public void deploySingleProcessAndForm() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery()
            .latestVersion()
            .processDefinitionKey("oneTaskWithFormProcess")
            .singleResult();

    assertThat(processDefinition).isNotNull();
    assertThat(processDefinition.getKey()).isEqualTo("oneTaskWithFormProcess");

    FormDefinition formDefinition = formRepositoryService.createFormDefinitionQuery()
            .latestVersion()
            .formDefinitionKey("form1")
            .singleResult();
    assertThat(formDefinition).isNotNull();
    assertThat(formDefinition.getKey()).isEqualTo("form1");

    List<FormDefinition> formDefinitionList = repositoryService.getFormDefinitionsForProcessDefinition(processDefinition.getId());
    assertThat(formDefinitionList)
            .extracting(FormDefinition::getKey)
            .containsExactly("form1");
}
 
Example #23
Source File: DefaultProcessDefinitionLocalizationManager.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
public void localize(ProcessDefinition processDefinition, String locale, boolean withLocalizationFallback) {
    ProcessDefinitionEntity processDefinitionEntity = (ProcessDefinitionEntity) processDefinition;
    processDefinitionEntity.setLocalizedName(null);
    processDefinitionEntity.setLocalizedDescription(null);

    if (locale != null) {
        ObjectNode languageNode = BpmnOverrideContext.getLocalizationElementProperties(locale, processDefinitionEntity.getKey(), processDefinition.getId(), withLocalizationFallback);
        if (languageNode != null) {
            JsonNode languageNameNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_NAME);
            if (languageNameNode != null && !languageNameNode.isNull()) {
                processDefinitionEntity.setLocalizedName(languageNameNode.asText());
            }

            JsonNode languageDescriptionNode = languageNode.get(DynamicBpmnConstants.LOCALIZATION_DESCRIPTION);
            if (languageDescriptionNode != null && !languageDescriptionNode.isNull()) {
                processDefinitionEntity.setLocalizedDescription(languageDescriptionNode.asText());
            }
        }
    }
}
 
Example #24
Source File: ProcessDefinitionQueryByLatestTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void testQueryByLatestAndId() throws Exception {
    // Deploy
    List<String> xmlFileNameList = Arrays.asList("name_testProcess1_one.bpmn20.xml",
            "name_testProcess1_two.bpmn20.xml", "name_testProcess2_one.bpmn20.xml");
    List<String> deploymentIdList = deploy(xmlFileNameList);

    List<String> processDefinitionIdList = new ArrayList<>();
    for (String deploymentId : deploymentIdList) {
        String processDefinitionId = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).list().get(0).getId();
        processDefinitionIdList.add(processDefinitionId);
    }

    ProcessDefinitionQuery idQuery1 = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionIdList.get(0)).latestVersion();
    List<ProcessDefinition> processDefinitions = idQuery1.list();
    assertThat(processDefinitions).isEmpty();

    ProcessDefinitionQuery idQuery2 = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionIdList.get(1)).latestVersion();
    processDefinitions = idQuery2.list();
    assertThat(processDefinitions)
            .extracting(ProcessDefinition::getKey)
            .containsExactly("testProcess1");

    ProcessDefinitionQuery idQuery3 = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionIdList.get(2)).latestVersion();
    processDefinitions = idQuery3.list();
    assertThat(processDefinitions)
            .extracting(ProcessDefinition::getKey)
            .containsExactly("testProcess2");

    // Undeploy
    unDeploy(deploymentIdList);
}
 
Example #25
Source File: DeploymentManager.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public BpmnModel getBpmnModelById(String processDefinitionId) {
    if (processDefinitionId == null) {
        throw new ActivitiIllegalArgumentException("Invalid process definition id : null");
    }

    // first try the cache
    BpmnModel bpmnModel = bpmnModelCache.get(processDefinitionId);

    if (bpmnModel == null) {
        ProcessDefinition processDefinition = findDeployedProcessDefinitionById(processDefinitionId);
        if (processDefinition == null) {
            throw new ActivitiObjectNotFoundException("no deployed process definition found with id '" + processDefinitionId + "'", ProcessDefinition.class);
        }

        // Fetch the resource
        String resourceName = processDefinition.getResourceName();
        ResourceEntity resource = Context.getCommandContext().getResourceEntityManager()
                .findResourceByDeploymentIdAndResourceName(processDefinition.getDeploymentId(), resourceName);
        if (resource == null) {
            if (Context.getCommandContext().getDeploymentEntityManager().findDeploymentById(processDefinition.getDeploymentId()) == null) {
                throw new ActivitiObjectNotFoundException("deployment for process definition does not exist: "
                        + processDefinition.getDeploymentId(), Deployment.class);
            } else {
                throw new ActivitiObjectNotFoundException("no resource found with name '" + resourceName
                        + "' in deployment '" + processDefinition.getDeploymentId() + "'", InputStream.class);
            }
        }

        // Convert the bpmn 2.0 xml to a bpmn model
        BpmnXMLConverter bpmnXMLConverter = new BpmnXMLConverter();
        bpmnModel = bpmnXMLConverter.convertToBpmnModel(new BytesStreamSource(resource.getBytes()), false, false);
        bpmnModelCache.add(processDefinition.getId(), bpmnModel);
    }
    return bpmnModel;
}
 
Example #26
Source File: ProcessDefinitionResourceDataResource.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the {@link ProcessDefinition} that is requested. Throws the right exceptions when bad request was made or definition was not found.
 */
protected ProcessDefinition getProcessDefinitionFromRequest(String processDefinitionId) {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(processDefinitionId).singleResult();

    if (processDefinition == null) {
        throw new FlowableObjectNotFoundException("Could not find a process definition with id '" + processDefinitionId + "'.", ProcessDefinition.class);
    }
    
    if (restApiInterceptor != null) {
        restApiInterceptor.accessProcessDefinitionById(processDefinition);
    }
    
    return processDefinition;
}
 
Example #27
Source File: ProcessDefinitionFormType.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public Object convertFormValueToModelValue(String propertyValue) {
    if (propertyValue != null) {
        ProcessDefinition processDefinition = ProcessEngines.getDefaultProcessEngine().getRepositoryService().createProcessDefinitionQuery().processDefinitionId(propertyValue).singleResult();

        if (processDefinition == null) {
            throw new FlowableObjectNotFoundException("Process definition with id " + propertyValue + " does not exist", ProcessDefinitionEntity.class);
        }

        return processDefinition;
    }
    return null;
}
 
Example #28
Source File: FlowableProcessDefinitionService.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public FormInfo getProcessDefinitionStartForm(String processDefinitionId) {

        ProcessDefinition processDefinition = repositoryService.getProcessDefinition(processDefinitionId);

        try {
            return getStartForm(processDefinition);

        } catch (FlowableObjectNotFoundException aonfe) {
            // Process definition does not exist
            throw new NotFoundException("No process definition found with the given id: " + processDefinitionId);
        }
    }
 
Example #29
Source File: RuntimeServiceTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = { "org/flowable/engine/test/api/oneTaskProcess.bpmn20.xml" })
public void testProcessInstanceDefinitionInformation() {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().singleResult();
    ProcessInstanceBuilder processInstanceBuilder = runtimeService.createProcessInstanceBuilder();

    ProcessInstance processInstance = processInstanceBuilder.processDefinitionKey("oneTaskProcess").start();

    assertThat(processInstance).isNotNull();
    assertThat(processInstance.getDeploymentId()).isEqualTo(processDefinition.getDeploymentId());
    assertThat(processInstance.getProcessDefinitionId()).isEqualTo(processDefinition.getId());
    assertThat(processInstance.getProcessDefinitionKey()).isEqualTo(processDefinition.getKey());
    assertThat(processInstance.getProcessDefinitionVersion().intValue()).isEqualTo(processDefinition.getVersion());
    assertThat(processInstance.getProcessDefinitionName()).isEqualTo(processDefinition.getName());
}
 
Example #30
Source File: AbstractSetProcessDefinitionStateCmd.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected List<ProcessInstance> fetchProcessInstancesPage(CommandContext commandContext,
                                                          ProcessDefinition processDefinition, int currentPageStartIndex) {

    if (SuspensionState.ACTIVE.equals(getProcessDefinitionSuspensionState())) {
        return new ProcessInstanceQueryImpl(commandContext)
                .processDefinitionId(processDefinition.getId())
                .suspended()
                .listPage(currentPageStartIndex, commandContext.getProcessEngineConfiguration().getBatchSizeProcessInstances());
    } else {
        return new ProcessInstanceQueryImpl(commandContext)
                .processDefinitionId(processDefinition.getId())
                .active()
                .listPage(currentPageStartIndex, commandContext.getProcessEngineConfiguration().getBatchSizeProcessInstances());
    }
}