Search in sources :

Example 1 with IntegrationContextImpl

use of org.activiti.api.runtime.model.impl.IntegrationContextImpl in project Activiti by Activiti.

the class IntegrationContextBuilder method buildFromExecution.

private IntegrationContextImpl buildFromExecution(DelegateExecution execution) {
    IntegrationContextImpl integrationContext = new IntegrationContextImpl();
    integrationContext.setProcessInstanceId(execution.getProcessInstanceId());
    integrationContext.setProcessDefinitionId(execution.getProcessDefinitionId());
    integrationContext.setBusinessKey(execution.getProcessInstanceBusinessKey());
    integrationContext.setClientId(execution.getCurrentActivityId());
    integrationContext.setExecutionId(execution.getId());
    if (ExecutionEntity.class.isInstance(execution)) {
        ExecutionContext executionContext = new ExecutionContext(ExecutionEntity.class.cast(execution));
        ExecutionEntity processInstance = executionContext.getProcessInstance();
        if (processInstance != null) {
            integrationContext.setParentProcessInstanceId(processInstance.getParentProcessInstanceId());
            integrationContext.setAppVersion(Objects.toString(processInstance.getAppVersion(), "1"));
        }
        // Let's try to resolve process definition attributes
        ProcessDefinition processDefinition = executionContext.getProcessDefinition();
        if (processDefinition != null) {
            integrationContext.setProcessDefinitionKey(processDefinition.getKey());
            integrationContext.setProcessDefinitionVersion(processDefinition.getVersion());
        }
    }
    ServiceTask serviceTask = (ServiceTask) execution.getCurrentFlowElement();
    if (serviceTask != null) {
        integrationContext.setConnectorType(serviceTask.getImplementation());
        integrationContext.setClientName(serviceTask.getName());
        integrationContext.setClientType(ServiceTask.class.getSimpleName());
    }
    integrationContext.setInBoundVariables(inboundVariablesProvider.calculateInputVariables(execution));
    return integrationContext;
}
Also used : ServiceTask(org.activiti.bpmn.model.ServiceTask) ExecutionContext(org.activiti.engine.impl.context.ExecutionContext) ExecutionEntity(org.activiti.engine.impl.persistence.entity.ExecutionEntity) IntegrationContextImpl(org.activiti.api.runtime.model.impl.IntegrationContextImpl) ProcessDefinition(org.activiti.engine.repository.ProcessDefinition)

Example 2 with IntegrationContextImpl

use of org.activiti.api.runtime.model.impl.IntegrationContextImpl in project activiti-cloud by Activiti.

the class IntegrationResultChannelResolverImplTest method shouldResolveDestination.

@Test
public void shouldResolveDestination() {
    // given
    IntegrationContextImpl integrationContext = new IntegrationContextImpl();
    IntegrationRequestImpl integrationRequest = new IntegrationRequestImpl(integrationContext);
    integrationRequest.setServiceFullName("myApp");
    integrationRequest.setAppName("myAppName");
    integrationRequest.setAppVersion("1.0");
    integrationRequest.setServiceType("RUNTIME_BUNDLE");
    integrationRequest.setServiceVersion("1.0");
    // when
    MessageChannel resut = subject.resolveDestination(integrationRequest);
    // then
    assertThat(resut).isEqualTo(messageChannel);
    verify(builder).buildDestination(integrationRequest);
}
Also used : IntegrationRequestImpl(org.activiti.cloud.api.process.model.impl.IntegrationRequestImpl) MessageChannel(org.springframework.messaging.MessageChannel) IntegrationContextImpl(org.activiti.api.runtime.model.impl.IntegrationContextImpl) Test(org.junit.jupiter.api.Test)

Example 3 with IntegrationContextImpl

use of org.activiti.api.runtime.model.impl.IntegrationContextImpl in project activiti-cloud by Activiti.

the class IntegrationErrorBuilderTest method shouldBuildIntegrationErrorBasedOnInformationFromIntegrationRequest.

@Test
public void shouldBuildIntegrationErrorBasedOnInformationFromIntegrationRequest() throws Exception {
    // given
    Throwable error = new Error("Boom!");
    IntegrationContextImpl integrationContext = new IntegrationContextImpl();
    integrationContext.setClientId(ACTIVITY_ELEMENT_ID);
    integrationContext.setInBoundVariables(Collections.emptyMap());
    integrationContext.setProcessDefinitionId(PROC_DEF_ID);
    integrationContext.setProcessInstanceId(PROC_INST_ID);
    IntegrationRequestImpl integrationRequestEvent = new IntegrationRequestImpl(integrationContext);
    integrationRequestEvent.setAppName(RB_NAME);
    // when
    IntegrationError integrationError = IntegrationErrorBuilder.errorFor(integrationRequestEvent, connectorProperties, error).build();
    // then
    assertThat(integrationError).hasIntegrationContext(integrationContext).hasIntegrationRequest(integrationRequestEvent).hasErrorClassName("java.lang.Error").hasErrorMessage("Boom!").hasStackTraceElements(error.getStackTrace());
    assertThat(integrationContext).hasClientId(ACTIVITY_ELEMENT_ID);
}
Also used : IntegrationRequestImpl(org.activiti.cloud.api.process.model.impl.IntegrationRequestImpl) IntegrationError(org.activiti.cloud.api.process.model.IntegrationError) IntegrationContextImpl(org.activiti.api.runtime.model.impl.IntegrationContextImpl) IntegrationError(org.activiti.cloud.api.process.model.IntegrationError) Test(org.junit.jupiter.api.Test)

Example 4 with IntegrationContextImpl

use of org.activiti.api.runtime.model.impl.IntegrationContextImpl in project activiti-cloud by Activiti.

the class ActivitiCloudConnectorServiceIT method integrationEventShouldBePickedByConnectorMock.

@Test
public void integrationEventShouldBePickedByConnectorMock() throws Exception {
    // given
    Map<String, Object> variables = new HashMap<>();
    variables.put("var1", "value1");
    variables.put("var2", 1L);
    IntegrationContextImpl integrationContext = new IntegrationContextImpl();
    integrationContext.setId(INTEGRATION_ID);
    integrationContext.setProcessInstanceId(PROCESS_INSTANCE_ID);
    integrationContext.setProcessDefinitionId(PROCESS_DEFINITION_ID);
    integrationContext.setInBoundVariables(variables);
    IntegrationRequestImpl integrationRequest = new IntegrationRequestImpl(integrationContext);
    integrationRequest.setAppName("mock-rb");
    integrationRequest.setServiceFullName("mock-rb");
    integrationRequest.setServiceType("runtime-bundle");
    integrationRequest.setServiceVersion("1");
    integrationRequest.setAppVersion("1");
    Message<IntegrationRequest> message = MessageBuilder.<IntegrationRequest>withPayload(integrationRequest).setHeader("type", "Mock").build();
    integrationEventsProducer.send(message);
    message = MessageBuilder.<IntegrationRequest>withPayload(integrationRequest).setHeader("type", "MockProcessRuntime").build();
    integrationEventsProducer.send(message);
    await("Should receive at least 2 integration results").untilAsserted(() -> assertThat(streamHandler.getIntegrationResultEventsCounter().get()).isGreaterThanOrEqualTo(1));
}
Also used : IntegrationRequest(org.activiti.cloud.api.process.model.IntegrationRequest) IntegrationRequestImpl(org.activiti.cloud.api.process.model.impl.IntegrationRequestImpl) HashMap(java.util.HashMap) IntegrationContextImpl(org.activiti.api.runtime.model.impl.IntegrationContextImpl) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 5 with IntegrationContextImpl

use of org.activiti.api.runtime.model.impl.IntegrationContextImpl in project activiti-cloud by Activiti.

the class ActivitiCloudConnectorServiceIT method mockIntegrationRequest.

private IntegrationRequest mockIntegrationRequest() {
    IntegrationContextImpl integrationContext = new IntegrationContextImpl();
    integrationContext.setId(INTEGRATION_ID);
    integrationContext.setProcessInstanceId(PROCESS_INSTANCE_ID);
    integrationContext.setProcessDefinitionId(PROCESS_DEFINITION_ID);
    IntegrationRequestImpl integrationRequest = new IntegrationRequestImpl(integrationContext);
    integrationRequest.setAppName("mock-rb");
    integrationRequest.setServiceFullName("mock-rb");
    integrationRequest.setServiceType("runtime-bundle");
    integrationRequest.setServiceVersion("1");
    integrationRequest.setAppVersion("1");
    return integrationRequest;
}
Also used : IntegrationRequestImpl(org.activiti.cloud.api.process.model.impl.IntegrationRequestImpl) IntegrationContextImpl(org.activiti.api.runtime.model.impl.IntegrationContextImpl)

Aggregations

IntegrationContextImpl (org.activiti.api.runtime.model.impl.IntegrationContextImpl)21 IntegrationRequestImpl (org.activiti.cloud.api.process.model.impl.IntegrationRequestImpl)15 Test (org.junit.jupiter.api.Test)14 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 IntegrationResultImpl (org.activiti.cloud.api.process.model.impl.IntegrationResultImpl)5 IntegrationContextEntityImpl (org.activiti.engine.impl.persistence.entity.integration.IntegrationContextEntityImpl)5 IntegrationError (org.activiti.cloud.api.process.model.IntegrationError)4 IntegrationResult (org.activiti.cloud.api.process.model.IntegrationResult)4 IntegrationErrorImpl (org.activiti.cloud.api.process.model.impl.IntegrationErrorImpl)2 CloudIntegrationErrorReceivedEventImpl (org.activiti.cloud.api.process.model.impl.events.CloudIntegrationErrorReceivedEventImpl)2 CloudIntegrationResultReceivedEventImpl (org.activiti.cloud.api.process.model.impl.events.CloudIntegrationResultReceivedEventImpl)2 Message (org.springframework.messaging.Message)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 BPMNActivityImpl (org.activiti.api.runtime.model.impl.BPMNActivityImpl)1 ProcessInstanceImpl (org.activiti.api.runtime.model.impl.ProcessInstanceImpl)1 TaskImpl (org.activiti.api.task.model.impl.TaskImpl)1 ServiceTask (org.activiti.bpmn.model.ServiceTask)1 CloudRuntimeEvent (org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent)1 IntegrationRequest (org.activiti.cloud.api.process.model.IntegrationRequest)1