org.flowable.engine.RepositoryService Java Examples

The following examples show how to use org.flowable.engine.RepositoryService. 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: 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 #2
Source File: MuleVMTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void send() throws Exception {
    Assert.assertTrue(muleContext.isStarted());

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RepositoryService repositoryService = processEngine.getRepositoryService();
    Deployment deployment = repositoryService.createDeployment().addClasspathResource("org/flowable/mule/testVM.bpmn20.xml").deploy();

    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("muleProcess");
    Assert.assertFalse(processInstance.isEnded());
    Object result = runtimeService.getVariable(processInstance.getProcessInstanceId(), "theVariable");
    Assert.assertEquals(30, result);
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");

    processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
    repositoryService.deleteDeployment(deployment.getId());
    assertAndEnsureCleanDb(processEngine);
    ProcessEngines.destroy();
}
 
Example #3
Source File: DefaultAutoDeploymentStrategy.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
protected void deployResourcesInternal(String deploymentNameHint, Resource[] resources, ProcessEngine engine) {
    RepositoryService repositoryService = engine.getRepositoryService();

    // Create a single deployment for all resources using the name hint as the literal name
    final DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering().name(deploymentNameHint);

    for (final Resource resource : resources) {
        addResource(resource, deploymentBuilder);
    }

    try {
        deploymentBuilder.deploy();
    } catch (RuntimeException e) {
        if (isThrowExceptionOnDeploymentFailure()) {
            throw e;
        } else {
            LOGGER.warn("Exception while autodeploying process definitions. "
                + "This exception can be ignored if the root cause indicates a unique constraint violation, "
                + "which is typically caused by two (or more) servers booting up at the exact same time and deploying the same definitions. ", e);
        }
    }

}
 
Example #4
Source File: SingleResourceAutoDeploymentStrategy.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Override
protected void deployResourcesInternal(String deploymentNameHint, Resource[] resources, ProcessEngine engine) {
    // Create a separate deployment for each resource using the resource name
    RepositoryService repositoryService = engine.getRepositoryService();

    for (final Resource resource : resources) {

        final String resourceName = determineResourceName(resource);
        final DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering().name(resourceName);
        addResource(resource, resourceName, deploymentBuilder);
        try {
            deploymentBuilder.deploy();
        } catch (RuntimeException e) {
            if (isThrowExceptionOnDeploymentFailure()) {
                throw e;
            } else {
                LOGGER.warn(
                    "Exception while autodeploying process definitions for resource {}. This exception can be ignored if the root cause indicates a unique constraint violation, which is typically caused by two (or more) servers booting up at the exact same time and deploying the same definitions. ",
                    resource, e);
            }
        }
    }
}
 
Example #5
Source File: MuleVMTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void send() throws Exception {
    Assert.assertTrue(muleContext.isStarted());

    ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine();
    RepositoryService repositoryService = processEngine.getRepositoryService();
    Deployment deployment = repositoryService.createDeployment()
            .addClasspathResource("org/activiti/mule/testVM.bpmn20.xml")
            .deploymentProperty(DeploymentProperties.DEPLOY_AS_FLOWABLE5_PROCESS_DEFINITION, Boolean.TRUE)
            .deploy();

    RuntimeService runtimeService = processEngine.getRuntimeService();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey("muleProcess");
    Assert.assertFalse(processInstance.isEnded());
    Object result = runtimeService.getVariable(processInstance.getProcessInstanceId(), "theVariable");
    Assert.assertEquals(30, result);
    runtimeService.deleteProcessInstance(processInstance.getId(), "test");

    processEngine.getHistoryService().deleteHistoricProcessInstance(processInstance.getId());
    repositoryService.deleteDeployment(deployment.getId());
    assertAndEnsureCleanDb(processEngine);
    ProcessEngines.destroy();
}
 
Example #6
Source File: IntegrationAutoConfigurationTest.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
@Test
public void testLaunchingGatewayProcessDefinition() throws Exception {
    RepositoryService repositoryService = applicationContext.getBean(RepositoryService.class);
    RuntimeService runtimeService = applicationContext.getBean(RuntimeService.class);
    ProcessEngine processEngine = applicationContext.getBean(ProcessEngine.class);

    assertThat(processEngine).as("the process engine should not be null").isNotNull();
    assertThat(repositoryService).as("we should have a default repositoryService included").isNotNull();
    String integrationGatewayProcess = "integrationGatewayProcess";
    List<ProcessDefinition> processDefinitionList = repositoryService.createProcessDefinitionQuery()
            .processDefinitionKey(integrationGatewayProcess)
            .list();
    ProcessDefinition processDefinition = processDefinitionList.iterator().next();
    assertThat(processDefinition.getKey()).isEqualTo(integrationGatewayProcess);
    Map<String, Object> vars = new HashMap<>();
    vars.put("customerId", 232);
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(integrationGatewayProcess, vars);
    assertThat(processInstance).as("the processInstance should not be null").isNotNull();
    assertThat(applicationContext.getBean(Application.AnalysingService.class)
            .getStringAtomicReference().get()).isEqualTo(projectId);
}
 
Example #7
Source File: UpdateModelKeyCmd.java    From plumdo-work with Apache License 2.0 6 votes vote down vote up
@Override
public Void execute(CommandContext commandContext) {
    RepositoryService repositoryService = CommandContextUtil.getProcessEngineConfiguration(commandContext).getRepositoryService();
    Model model = repositoryService.getModel(modelId);
    if (model == null) {
        return null;
    }
    
    List<Model> models = repositoryService.createModelQuery().modelKey(model.getKey()).list();
    for (Model updateModel : models) {
        if (!updateModel.getId().equals(modelId)) {
            updateModel.setKey(modelKey);
            repositoryService.saveModel(updateModel);
        }
    }

    return null;
}
 
Example #8
Source File: CleanTestExecutionListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void afterTestClass(TestContext testContext) throws Exception {
    RepositoryService repositoryService = testContext.getApplicationContext().getBean(RepositoryService.class);
    for (Deployment deployment : repositoryService.createDeploymentQuery().list()) {
        repositoryService.deleteDeployment(deployment.getId(), true);
    }
}
 
Example #9
Source File: ProcessWithFormTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void throwExceptionValidationOnStartProcessWithoutVariables(RuntimeService runtimeService, RepositoryService repositoryService) {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("oneTaskWithFormSideEffectProcess")
        .singleResult();
    assertThatThrownBy(() -> runtimeService.startProcessInstanceWithForm(processDefinition.getId(), "COMPLETE", null, "test"))
            .isInstanceOf(RuntimeException.class)
            .hasMessageContaining("validation failed");

    assertThat(SideEffectExecutionListener.getSideEffect()).isZero();
}
 
Example #10
Source File: ProcessWithFormTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void throwExceptionValidationOnStartProcess(RuntimeService runtimeService, RepositoryService repositoryService) {
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("oneTaskWithFormSideEffectProcess")
        .singleResult();
    assertThatThrownBy(() -> runtimeService.startProcessInstanceWithForm(processDefinition.getId(), "COMPLETE", Collections.singletonMap("name", "nameValue"), "test"))
            .isInstanceOf(RuntimeException.class)
            .hasMessageContaining("validation failed");

    assertThat(SideEffectExecutionListener.getSideEffect()).isZero();
}
 
Example #11
Source File: ProcessEngineAutoConfigurationTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private void assertAutoDeployment(ApplicationContext context) {
    RepositoryService repositoryService = context.getBean(RepositoryService.class);

    List<ProcessDefinition> definitions = repositoryService.createProcessDefinitionQuery().orderByProcessDefinitionKey().asc().list();
    assertThat(definitions)
        .extracting(ProcessDefinition::getKey)
        .containsExactly("integrationGatewayProcess", "waiter");
    List<Deployment> deployments = repositoryService.createDeploymentQuery().list();

    assertThat(deployments)
        .hasSize(1)
        .first()
        .satisfies(deployment -> assertThat(deployment.getName()).isEqualTo("SpringBootAutoDeployment"));
}
 
Example #12
Source File: BpmnDeployer.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void deploy(EngineDeployment deployment, Map<String, Object> deploymentSettings) {
    if (!deployment.isNew()) {
        return;
    }

    LOGGER.debug("BpmnDeployer: processing deployment {}", deployment.getName());

    DeploymentBuilder bpmnDeploymentBuilder = null;
    Map<String, EngineResource> resources = deployment.getResources();
    for (String resourceName : resources.keySet()) {
        if (isBpmnResource(resourceName)) {
            LOGGER.info("BpmnDeployer: processing resource {}", resourceName);
            if (bpmnDeploymentBuilder == null) {
                RepositoryService repositoryService = CommandContextUtil.getProcessEngineConfiguration().getRepositoryService();
                bpmnDeploymentBuilder = repositoryService.createDeployment().name(deployment.getName());
            }
            bpmnDeploymentBuilder.addBytes(resourceName, resources.get(resourceName).getBytes());
        }
    }

    if (bpmnDeploymentBuilder != null) {
        bpmnDeploymentBuilder.parentDeploymentId(deployment.getId());
        bpmnDeploymentBuilder.key(deployment.getKey());
        if (deployment.getTenantId() != null && deployment.getTenantId().length() > 0) {
            bpmnDeploymentBuilder.tenantId(deployment.getTenantId());
        }
        bpmnDeploymentBuilder.deploy();
    }
}
 
Example #13
Source File: ProcessWithFormTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void completeTaskWithValidationOnMissingModelLevel(ProcessEngineConfiguration processEngineConfiguration, RuntimeService runtimeService,
    TaskService taskService, RepositoryService repositoryService) {

    repositoryService.createDeployment().
        addString("oneTaskWithFormKeySideEffectProcess.bpmn20.xml",
            ONE_TASK_PROCESS.
                replace("flowable:formFieldValidation=\"START_EVENT_VALIDATION\"", "").
                replace("flowable:formFieldValidation=\"USER_TASK_VALIDATION\"", "")
        ).
        deploy();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(
        "oneTaskWithFormSideEffectProcess",
        Collections.emptyMap()
    );
    SideEffectExecutionListener.reset();

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

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

    assertThatThrownBy(() -> taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), "__COMPLETE", Collections.singletonMap("initiator", "someInitiator")))
            .isInstanceOf(RuntimeException.class)
            .hasMessage("validation failed");

    assertThat(SideEffectExecutionListener.getSideEffect()).isZero();
}
 
Example #14
Source File: ProcessWithFormTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void completeTaskWithValidationOnModelLevelStringExpression(ProcessEngineConfiguration processEngineConfiguration, RuntimeService runtimeService,
    TaskService taskService, RepositoryService repositoryService) {

    repositoryService.createDeployment().
        addString("oneTaskWithFormKeySideEffectProcess.bpmn20.xml",
            ONE_TASK_PROCESS.
                replace("START_EVENT_VALIDATION", "true").
                replace("USER_TASK_VALIDATION", "${true}")
        ).
        deploy();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(
        "oneTaskWithFormSideEffectProcess",
        Collections.emptyMap()
    );
    SideEffectExecutionListener.reset();

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

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

    assertThatThrownBy(() -> taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), "__COMPLETE", Collections.singletonMap("initiator", "someInitiator")))
            .isInstanceOf(RuntimeException.class)
            .hasMessage("validation failed");

    assertThat(SideEffectExecutionListener.getSideEffect()).isZero();
}
 
Example #15
Source File: PlaybackRunTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
private void checkStatus(ProcessEngine processEngine) {
    HistoryService historyService = processEngine.getHistoryService();
    final HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().finished().includeProcessVariables().singleResult();
    assertNotNull(historicProcessInstance);
    RepositoryService repositoryService = processEngine.getRepositoryService();
    final ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionId(historicProcessInstance.getProcessDefinitionId()).singleResult();
    assertEquals(SIMPLEST_PROCESS, processDefinition.getKey());

    assertEquals(1, historicProcessInstance.getProcessVariables().size());
    assertEquals(TEST_VALUE, historicProcessInstance.getProcessVariables().get(TEST_VARIABLE));
    assertEquals(BUSINESS_KEY, historicProcessInstance.getBusinessKey());
}
 
Example #16
Source File: ProcessWithFormTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void completeTaskWithoutValidationOnModelLevelBadExpression(ProcessEngineConfiguration processEngineConfiguration, RuntimeService runtimeService,
    TaskService taskService, RepositoryService repositoryService) {

    repositoryService.createDeployment().
        addString("oneTaskWithFormKeySideEffectProcess.bpmn20.xml",
            ONE_TASK_PROCESS.
                replace("START_EVENT_VALIDATION", "true").
                replace("USER_TASK_VALIDATION", "${BAD_EXPRESSION}")
        ).
        deploy();
    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(
        "oneTaskWithFormSideEffectProcess",
        Collections.emptyMap()
    );
    SideEffectExecutionListener.reset();

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

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

    assertThatThrownBy(() -> taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), "__COMPLETE", Collections.singletonMap("initiator", "someInitiator")))
            .isInstanceOf(FlowableException.class)
            .hasMessage("Unknown property used in expression: ${BAD_EXPRESSION}");
    assertThat(SideEffectExecutionListener.getSideEffect()).isZero();
}
 
Example #17
Source File: ProcessWithFormTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void completeTaskWithoutValidationOnModelLevelExpression(ProcessEngineConfiguration processEngineConfiguration, RuntimeService runtimeService,
    TaskService taskService, RepositoryService repositoryService) {

    Deployment deployment = repositoryService.createDeployment().
        addString("oneTaskWithFormKeySideEffectProcess.bpmn20.xml",
            ONE_TASK_PROCESS.
                replace("START_EVENT_VALIDATION", "${true}").
                replace("USER_TASK_VALIDATION", "${allowValidation}")
        ).
        deploy();
    ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deployment.getId()).singleResult();

    assertThatThrownBy(() -> runtimeService.startProcessInstanceWithForm(processDefinition.getId(), "__COMPLETE",
            Collections.singletonMap("allowValidation", Boolean.TRUE),"oneTaskWithFormSideEffectProcess"))
            .isInstanceOf(RuntimeException.class)
            .hasMessageContaining("validation failed");

    assertThat(SideEffectExecutionListener.getSideEffect()).isZero();

    ProcessInstance processInstance = runtimeService.startProcessInstanceByKey(
        "oneTaskWithFormSideEffectProcess",
        Collections.singletonMap("allowValidation", Boolean.TRUE)
    );
    SideEffectExecutionListener.reset();

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

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

    assertThatThrownBy(() -> taskService.completeTaskWithForm(task.getId(), formDefinition.getId(), "__COMPLETE", Collections.singletonMap("initiator", "someInitiator")))
            .isInstanceOf(RuntimeException.class);

    assertThat(SideEffectExecutionListener.getSideEffect()).isZero();
}
 
Example #18
Source File: ProcessWithFormTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
public void startProcessWithFormWithoutValidationOnConfiguration(ProcessEngineConfiguration processEngineConfiguration, RuntimeService runtimeService, RepositoryService repositoryService) {
    ((ProcessEngineConfigurationImpl) processEngineConfiguration).setFormFieldValidationEnabled(false);
    try {
        ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey("oneTaskWithFormSideEffectProcess")
            .singleResult();
        ProcessInstance processInstance = runtimeService
            .startProcessInstanceWithForm(processDefinition.getId(), "COMPLETE", Collections.singletonMap("name", "nameValue"), "test");
        assertThat(processInstance).isNotNull();
        assertThat(SideEffectExecutionListener.getSideEffect()).isEqualTo(1);
    } finally {
        ((ProcessEngineConfigurationImpl) processEngineConfiguration).setFormFieldValidationEnabled(true);
    }
}
 
Example #19
Source File: ProcessWithFormTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@BeforeEach
public void deployModels(RepositoryService repositoryService) {
    repositoryService.createDeployment().
        addClasspathResource("org/flowable/form/engine/test/deployment/simple.form")
            .addString("oneTaskWithFormKeySideEffectProcess.bpmn20.xml", ONE_TASK_PROCESS
                    .replace("START_EVENT_VALIDATION", "true")
                    .replace("USER_TASK_VALIDATION", "true")
        ).
        deploy();
}
 
Example #20
Source File: XmlNamespaceProcessScopeTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@After
public void after() {
    RepositoryService repositoryService = this.processEngine.getRepositoryService();
    for (Deployment deployment : repositoryService.createDeploymentQuery().list()) {
        repositoryService.deleteDeployment(deployment.getId(), true);
    }
}
 
Example #21
Source File: FlowableComponent.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void setCamelContext(CamelContext context) {
    super.setCamelContext(context);
    identityService = getByType(context, IdentityService.class);
    runtimeService = getByType(context, RuntimeService.class);
    repositoryService = getByType(context, RepositoryService.class);
    managementService = getByType(context, ManagementService.class);
}
 
Example #22
Source File: SerializableVariablesDiabledTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Before
public void setupServer() {
    if (serverUrlPrefix == null) {
        TestServer testServer = TestServerUtil.createAndStartServer(ObjectVariableSerializationDisabledApplicationConfiguration.class);
        serverUrlPrefix = testServer.getServerUrlPrefix();

        this.repositoryService = testServer.getApplicationContext().getBean(RepositoryService.class);
        this.runtimeService = testServer.getApplicationContext().getBean(RuntimeService.class);
        this.identityService = testServer.getApplicationContext().getBean(IdentityService.class);
        this.taskService = testServer.getApplicationContext().getBean(TaskService.class);

        User user = identityService.newUser("kermit");
        user.setFirstName("Kermit");
        user.setLastName("the Frog");
        user.setPassword("kermit");
        identityService.saveUser(user);

        Group group = identityService.newGroup("admin");
        group.setName("Administrators");
        identityService.saveGroup(group);

        identityService.createMembership(user.getId(), group.getId());

        this.testUserId = user.getId();
        this.testGroupId = group.getId();
    }
}
 
Example #23
Source File: FlowableJupiterTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Test
@Deployment(resources = "org/flowable/standalone/testing/FlowableJupiterTest.extensionUsageExample.bpmn20.xml")
void extensionUsageDeploymentIdExample(@DeploymentId String deploymentId, FlowableTestHelper testHelper, RepositoryService repositoryService) {
    assertThat(deploymentId).as("deploymentId parameter").isEqualTo(testHelper.getDeploymentIdFromDeploymentAnnotation());

    org.flowable.engine.repository.Deployment deployment = repositoryService.createDeploymentQuery().singleResult();

    assertThat(deployment.getId()).as("queried deployment").isEqualTo(deploymentId);
}
 
Example #24
Source File: ResourceParentFolderAutoDeploymentStrategy.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
protected void deployResourcesInternal(String deploymentNameHint, Resource[] resources, ProcessEngine engine) {

    RepositoryService repositoryService = engine.getRepositoryService();
    // Create a deployment for each distinct parent folder using the namehint as a prefix
    final Map<String, Set<Resource>> resourcesMap = createMap(resources);
    for (final Entry<String, Set<Resource>> group : resourcesMap.entrySet()) {

        final String deploymentName = determineDeploymentName(deploymentNameHint, group.getKey());
        final DeploymentBuilder deploymentBuilder = repositoryService.createDeployment().enableDuplicateFiltering().name(deploymentName);

        for (final Resource resource : group.getValue()) {
            addResource(resource, deploymentBuilder);
        }

        try {
            deploymentBuilder.deploy();
        } catch (Exception e) {
            if (isThrowExceptionOnDeploymentFailure()) {
                throw e;
            } else {
                LOGGER.warn("Exception while autodeploying process definitions. "
                    + "This exception can be ignored if the root cause indicates a unique constraint violation, "
                    + "which is typically caused by two (or more) servers booting up at the exact same time and deploying the same definitions. ", e);
            }
        }
    }

}
 
Example #25
Source File: CleanTestExecutionListener.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@Override
public void afterTestClass(TestContext testContext) throws Exception {
    RepositoryService repositoryService = testContext.getApplicationContext().getBean(RepositoryService.class);
    for (Deployment deployment : repositoryService.createDeploymentQuery().list()) {
        try {
            repositoryService.deleteDeployment(deployment.getId(), true);
        } catch (FlowableOptimisticLockingException flowableOptimisticLockingException) {
            LOGGER.warn("Caught exception, retrying", flowableOptimisticLockingException);
            repositoryService.deleteDeployment(deployment.getId(), true);
        }
    }
}
 
Example #26
Source File: SimulationRunContext.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
public static RepositoryService getRepositoryService() {
    Stack<ProcessEngine> stack = getStack(processEngineThreadLocal);
    if (stack.isEmpty()) {
        return null;
    }
    return stack.peek().getRepositoryService();
}
 
Example #27
Source File: SpringAutoDeployTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void createAppContext(Map<String, Object> properties) {
    AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
    applicationContext.register(SpringAutoDeployTestConfiguration.class);
    applicationContext.getEnvironment().getPropertySources()
            .addLast(new MapPropertySource("springAutoDeploy", properties));
    applicationContext.refresh();
    this.applicationContext = applicationContext;
    this.repositoryService = applicationContext.getBean(RepositoryService.class);
}
 
Example #28
Source File: SaveModelEditorCmd.java    From plumdo-work with Apache License 2.0 5 votes vote down vote up
@Override
public Void execute(CommandContext commandContext) {
    ProcessEngineConfiguration processEngineConfiguration = CommandContextUtil.getProcessEngineConfiguration(commandContext);
    RepositoryService repositoryService = processEngineConfiguration.getRepositoryService();

    try {
        byte[] bytes = editorJson.getBytes("utf-8");
        repositoryService.addModelEditorSource(modelId, bytes);
        ObjectNode modelNode = (ObjectNode) new ObjectMapper().readTree(bytes);
        BpmnModel bpmnModel = new BpmnJsonConverter().convertToBpmnModel(modelNode);
        BpmnXMLConverter xmlConverter = new BpmnXMLConverter();
        byte[] bpmnBytes = xmlConverter.convertToXML(bpmnModel);
        XMLInputFactory xif = XMLInputFactory.newInstance();
        InputStreamReader xmlIn = new InputStreamReader(new ByteArrayInputStream(bpmnBytes), "UTF-8");
        XMLStreamReader xtr = xif.createXMLStreamReader(xmlIn);
        bpmnModel = new BpmnXMLConverter().convertToBpmnModel(xtr);

        ProcessDiagramGenerator diagramGenerator = processEngineConfiguration.getProcessDiagramGenerator();
        InputStream resource = diagramGenerator.generateDiagram(bpmnModel, "png",
                Collections.emptyList(), Collections.emptyList(),
                processEngineConfiguration.getActivityFontName(),
                processEngineConfiguration.getLabelFontName(),
                processEngineConfiguration.getAnnotationFontName(),
                processEngineConfiguration.getClassLoader(), 1.0);

        repositoryService.addModelEditorSourceExtra(modelId, IOUtils.toByteArray(resource));
    } catch (Exception e) {
        throw new FlowableException("create model exception :" + e.getMessage());
    }
    return null;
}
 
Example #29
Source File: InternalFlowableExtension.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
protected void removeDeployments(RepositoryService repositoryService) {
    for (org.flowable.engine.repository.Deployment deployment : repositoryService.createDeploymentQuery().list()) {
        try {
            repositoryService.deleteDeployment(deployment.getId(), true);
        } catch (FlowableOptimisticLockingException flowableOptimisticLockingException) {
            logger.warn("Caught exception, retrying", flowableOptimisticLockingException);
            repositoryService.deleteDeployment(deployment.getId(), true);
        }
    }
}
 
Example #30
Source File: ProcessWithFormTest.java    From flowable-engine with Apache License 2.0 5 votes vote down vote up
@AfterEach
public void resetSideEffect(RepositoryService repositoryService) {
    repositoryService.createDeploymentQuery().list().forEach(
        deployment -> repositoryService.deleteDeployment(deployment.getId(), true)
    );
    FormRepositoryService formRepositoryService = FormEngines.getDefaultFormEngine().getFormRepositoryService();
    formRepositoryService.createDeploymentQuery().list()
        .forEach(
            formDeployment -> formRepositoryService.deleteDeployment(formDeployment.getId(), true)
        );
    SideEffectExecutionListener.reset();
}