Search in sources :

Example 1 with CloudProcessStartedEvent

use of org.activiti.cloud.api.process.model.events.CloudProcessStartedEvent in project activiti-cloud by Activiti.

the class MapBuilder method testGraphqlWsSubprotocolServerStartStopSubscription.

@Test
public void testGraphqlWsSubprotocolServerStartStopSubscription() throws JsonProcessingException {
    ReplayProcessor<String> data = ReplayProcessor.create();
    keycloakTokenProducer.setKeycloakTestUser(TESTADMIN);
    final String auth = keycloakTokenProducer.authorizationHeaders().getFirst(AUTHORIZATION);
    Map<String, Object> variables = mapBuilder().put("appName", "default-app").put("eventTypes", Arrays.array("PROCESS_CREATED", "PROCESS_STARTED")).get();
    Map<String, Object> payload = mapBuilder().put("query", "subscription($appName: String!, $eventTypes: [EngineEventType!]) { " + "  engineEvents(appName: [$appName], eventType: $eventTypes) { " + "    processInstanceId  " + "    eventType " + "  } " + "}").put("variables", variables).get();
    GraphQLMessage start = GraphQLMessage.builder().type(GraphQLMessageType.START).id("1").payload(payload).build();
    String startMessage = objectMapper.writeValueAsString(start);
    // given
    CloudProcessCreatedEvent event1 = new CloudProcessCreatedEventImpl() {

        {
            setAppName("default-app");
            setServiceName("rb-my-app");
            setServiceFullName("serviceFullName");
            setServiceType("runtime-bundle");
            setServiceVersion("");
            setProcessInstanceId("processInstanceId");
            setProcessDefinitionId("processDefinitionId");
            setProcessDefinitionKey("processDefinitionKey");
            setProcessDefinitionVersion(1);
            setBusinessKey("businessKey");
        }
    };
    CloudProcessStartedEvent event2 = new CloudProcessStartedEventImpl() {

        {
            setAppName("default-app");
            setServiceName("rb-my-app");
            setServiceType("runtime-bundle");
            setServiceFullName("serviceFullName");
            setServiceType("runtime-bundle");
            setServiceVersion("");
            setProcessInstanceId("processInstanceId");
            setProcessDefinitionId("processDefinitionId");
            setProcessDefinitionKey("processDefinitionKey");
            setProcessDefinitionVersion(1);
            setBusinessKey("businessKey");
        }
    };
    WebsocketSender client = HttpClient.create().baseUrl("ws://localhost:" + port).wiretap(true).headers(h -> h.add(AUTHORIZATION, auth)).websocket(GRAPHQL_WS).uri(WS_GRAPHQL_URI);
    // start subscription
    client.handle((i, o) -> {
        o.options(NettyPipeline.SendOptions::flushOnEach).sendString(Mono.just(startMessage)).then().log("start").subscribe();
        return i.receive().asString().log("data").take(1).doOnSubscribe(s -> producerChannel.output().send(MessageBuilder.withPayload(Arrays.array(event1, event2)).setHeader("routingKey", "eventProducer").build())).delaySubscription(Duration.ofSeconds(1)).subscribeWith(data);
    }).collectList().subscribe();
    // then
    Map<String, Object> message = Maps.of("data", Maps.of("engineEvents", Arrays.array(Maps.of("processInstanceId", "processInstanceId", "eventType", "PROCESS_CREATED"), Maps.of("processInstanceId", "processInstanceId", "eventType", "PROCESS_STARTED"))));
    String dataMessage = objectMapper.writeValueAsString(GraphQLMessage.builder().type(GraphQLMessageType.DATA).id("1").payload(message).build());
    StepVerifier.create(data).expectNext(dataMessage).expectComplete().verify(TIMEOUT);
}
Also used : CloudProcessStartedEvent(org.activiti.cloud.api.process.model.events.CloudProcessStartedEvent) CloudProcessCreatedEvent(org.activiti.cloud.api.process.model.events.CloudProcessCreatedEvent) CloudProcessStartedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessStartedEventImpl) CloudProcessCreatedEventImpl(org.activiti.cloud.api.process.model.impl.events.CloudProcessCreatedEventImpl) WebsocketSender(reactor.netty.http.client.HttpClient.WebsocketSender) GraphQLMessage(org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage) Test(org.junit.jupiter.api.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Example 2 with CloudProcessStartedEvent

use of org.activiti.cloud.api.process.model.events.CloudProcessStartedEvent in project activiti-cloud by Activiti.

the class ProcessStartedEventHandler method handle.

@Override
public void handle(CloudRuntimeEvent<?, ?> event) {
    CloudProcessStartedEvent startedEvent = (CloudProcessStartedEvent) event;
    String processInstanceId = startedEvent.getEntity().getId();
    LOGGER.debug("Handling start of process Instance " + processInstanceId);
    Optional<ProcessInstanceEntity> findResult = processInstanceRepository.findById(processInstanceId);
    ProcessInstanceEntity processInstanceEntity = findResult.orElseThrow(() -> new QueryException("Unable to find process instance with the given id: " + processInstanceId));
    if (ProcessInstance.ProcessInstanceStatus.CREATED.equals(processInstanceEntity.getStatus())) {
        processInstanceEntity.setStatus(ProcessInstance.ProcessInstanceStatus.RUNNING);
        // instance name is not available in ProcessCreatedEvent, so we need to updated it here
        processInstanceEntity.setName(startedEvent.getEntity().getName());
        processInstanceEntity.setLastModified(new Date(startedEvent.getTimestamp()));
        processInstanceEntity.setStartDate(startedEvent.getEntity().getStartDate());
        processInstanceRepository.save(processInstanceEntity);
    }
}
Also used : ProcessInstanceEntity(org.activiti.cloud.services.query.model.ProcessInstanceEntity) CloudProcessStartedEvent(org.activiti.cloud.api.process.model.events.CloudProcessStartedEvent) QueryException(org.activiti.cloud.services.query.model.QueryException) Date(java.util.Date)

Example 3 with CloudProcessStartedEvent

use of org.activiti.cloud.api.process.model.events.CloudProcessStartedEvent in project activiti-cloud by Activiti.

the class ProcessStartedEventHandlerTest method handleShouldUpdateProcessInstanceStatusToRunningAndUpdateInstanceName.

@Test
public void handleShouldUpdateProcessInstanceStatusToRunningAndUpdateInstanceName() {
    // given
    CloudProcessStartedEvent event = buildProcessStartedEvent();
    ProcessInstanceEntity currentProcessInstanceEntity = mock(ProcessInstanceEntity.class);
    given(currentProcessInstanceEntity.getStatus()).willReturn(ProcessInstance.ProcessInstanceStatus.CREATED);
    given(processInstanceRepository.findById(event.getEntity().getId())).willReturn(Optional.of(currentProcessInstanceEntity));
    // when
    handler.handle(event);
    // then
    verify(processInstanceRepository).save(currentProcessInstanceEntity);
    verify(currentProcessInstanceEntity).setStatus(ProcessInstance.ProcessInstanceStatus.RUNNING);
    verify(currentProcessInstanceEntity).setName(event.getEntity().getName());
    verify(currentProcessInstanceEntity).setStartDate(event.getEntity().getStartDate());
}
Also used : ProcessInstanceEntity(org.activiti.cloud.services.query.model.ProcessInstanceEntity) CloudProcessStartedEvent(org.activiti.cloud.api.process.model.events.CloudProcessStartedEvent) Test(org.junit.jupiter.api.Test)

Example 4 with CloudProcessStartedEvent

use of org.activiti.cloud.api.process.model.events.CloudProcessStartedEvent in project activiti-cloud by Activiti.

the class ToCloudProcessRuntimeEventConverterTest method fromShouldConvertInternalProcessStartedEventToExternalEvent.

@Test
public void fromShouldConvertInternalProcessStartedEventToExternalEvent() {
    // given
    ProcessInstanceImpl processInstance = new ProcessInstanceImpl();
    processInstance.setId("10");
    processInstance.setProcessDefinitionId("myProcessDef");
    ProcessStartedEventImpl event = new ProcessStartedEventImpl(processInstance);
    event.setNestedProcessDefinitionId("myParentProcessDef");
    event.setNestedProcessInstanceId("2");
    // when
    CloudProcessStartedEvent processStarted = converter.from(event);
    // then
    assertThat(processStarted).isInstanceOf(CloudProcessStartedEvent.class);
    assertThat(processStarted.getEntity().getId()).isEqualTo("10");
    assertThat(processStarted.getEntity().getProcessDefinitionId()).isEqualTo("myProcessDef");
    assertThat(processStarted.getNestedProcessDefinitionId()).isEqualTo("myParentProcessDef");
    assertThat(processStarted.getNestedProcessInstanceId()).isEqualTo("2");
    verify(runtimeBundleInfoAppender).appendRuntimeBundleInfoTo(any(CloudRuntimeEventImpl.class));
}
Also used : CloudProcessStartedEvent(org.activiti.cloud.api.process.model.events.CloudProcessStartedEvent) CloudRuntimeEventImpl(org.activiti.cloud.api.model.shared.impl.events.CloudRuntimeEventImpl) ProcessInstanceImpl(org.activiti.api.runtime.model.impl.ProcessInstanceImpl) ProcessStartedEventImpl(org.activiti.runtime.api.event.impl.ProcessStartedEventImpl) Test(org.junit.jupiter.api.Test)

Example 5 with CloudProcessStartedEvent

use of org.activiti.cloud.api.process.model.events.CloudProcessStartedEvent in project activiti-cloud by Activiti.

the class ProcessStartedEventHandlerTest method handleShouldThrowExceptionWhenRelatedProcessInstanceIsNotFound.

@Test
public void handleShouldThrowExceptionWhenRelatedProcessInstanceIsNotFound() {
    // given
    CloudProcessStartedEvent event = buildProcessStartedEvent();
    given(processInstanceRepository.findById("200")).willReturn(Optional.empty());
    // then
    // when
    assertThatExceptionOfType(QueryException.class).isThrownBy(() -> handler.handle(event)).withMessageContaining("Unable to find process instance with the given id: ");
}
Also used : CloudProcessStartedEvent(org.activiti.cloud.api.process.model.events.CloudProcessStartedEvent) Test(org.junit.jupiter.api.Test)

Aggregations

CloudProcessStartedEvent (org.activiti.cloud.api.process.model.events.CloudProcessStartedEvent)6 Test (org.junit.jupiter.api.Test)5 ProcessInstanceEntity (org.activiti.cloud.services.query.model.ProcessInstanceEntity)3 Date (java.util.Date)1 ProcessInstanceImpl (org.activiti.api.runtime.model.impl.ProcessInstanceImpl)1 CloudRuntimeEventImpl (org.activiti.cloud.api.model.shared.impl.events.CloudRuntimeEventImpl)1 CloudProcessCreatedEvent (org.activiti.cloud.api.process.model.events.CloudProcessCreatedEvent)1 CloudProcessCreatedEventImpl (org.activiti.cloud.api.process.model.impl.events.CloudProcessCreatedEventImpl)1 CloudProcessStartedEventImpl (org.activiti.cloud.api.process.model.impl.events.CloudProcessStartedEventImpl)1 GraphQLMessage (org.activiti.cloud.services.notifications.graphql.ws.api.GraphQLMessage)1 QueryException (org.activiti.cloud.services.query.model.QueryException)1 ProcessStartedEventImpl (org.activiti.runtime.api.event.impl.ProcessStartedEventImpl)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 WebsocketSender (reactor.netty.http.client.HttpClient.WebsocketSender)1