Search in sources :

Example 1 with CloudRuntimeEvent

use of org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent in project activiti-cloud by Activiti.

the class AuditSteps method checkTaskVariableEvent.

@Step
public void checkTaskVariableEvent(String processInstanceId, String taskId, String variableName, VariableEvent.VariableEvents eventType) throws Exception {
    Collection<CloudRuntimeEvent> events = getEventsByProcessInstanceIdAndEventType(processInstanceId, eventType.name());
    await().untilAsserted(() -> {
        assertThat(events).isNotEmpty();
        assertThat(events).extracting(e -> e.getEventType()).containsOnly(eventType);
        List<CloudRuntimeEvent> varEvents = events.stream().filter(e -> variableName.equals(((CloudVariableEvent) e).getEntity().getName()) && taskId.equals(((CloudVariableEvent) e).getEntity().getTaskId())).collect(Collectors.toList());
        // could be more than one if there are multiple vars with same name
        assertThat(varEvents.size()).isGreaterThanOrEqualTo(1);
        CloudRuntimeEvent resultingEvent = varEvents.get(0);
        assertThat(resultingEvent).isNotNull();
        assertThat(resultingEvent).isInstanceOf(CloudVariableEvent.class);
        assertThat(((CloudVariableEvent) resultingEvent).getEntity().getName()).isEqualTo(variableName);
        assertThat(resultingEvent.getServiceName()).isNotEmpty();
        assertThat(resultingEvent.getServiceFullName()).isNotEmpty();
    });
}
Also used : VariableEvent(org.activiti.api.model.shared.event.VariableEvent) CloudProcessRuntimeEvent(org.activiti.cloud.api.process.model.events.CloudProcessRuntimeEvent) CloudVariableEvent(org.activiti.cloud.api.model.shared.events.CloudVariableEvent) Awaitility.await(org.awaitility.Awaitility.await) ProcessRuntimeEvent(org.activiti.api.process.model.events.ProcessRuntimeEvent) Task(org.activiti.api.task.model.Task) Collection(java.util.Collection) RuntimeEvent(org.activiti.api.model.shared.event.RuntimeEvent) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) BPMNActivityEvent(org.activiti.api.process.model.events.BPMNActivityEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) BPMNTimerEvent(org.activiti.api.process.model.events.BPMNTimerEvent) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) AuditService(org.activiti.cloud.acc.core.services.audit.AuditService) Condition(org.assertj.core.api.Condition) Assertions(org.assertj.core.api.Assertions) Step(net.thucydides.core.annotations.Step) TaskRuntimeEvent(org.activiti.api.task.model.events.TaskRuntimeEvent) CloudTaskRuntimeEvent(org.activiti.cloud.api.task.model.events.CloudTaskRuntimeEvent) EnableRuntimeFeignContext(org.activiti.cloud.acc.core.rest.feign.EnableRuntimeFeignContext) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Step(net.thucydides.core.annotations.Step)

Example 2 with CloudRuntimeEvent

use of org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent in project activiti-cloud by Activiti.

the class AuditSteps method checkProcessInstanceVariableEvent.

@Step
public void checkProcessInstanceVariableEvent(String processInstanceId, String variableName, VariableEvent.VariableEvents eventType) throws Exception {
    await().untilAsserted(() -> {
        Collection<CloudRuntimeEvent> events = getEventsByProcessInstanceIdAndEventType(processInstanceId, eventType.name());
        assertThat(events).isNotEmpty();
        assertThat(events).extracting(e -> e.getEventType()).containsOnly(eventType);
        List<CloudRuntimeEvent> processInstanceTasks = events.stream().filter(e -> variableName.equals(((CloudVariableEvent) e).getEntity().getName()) && processInstanceId.equals(((CloudVariableEvent) e).getEntity().getProcessInstanceId()) && !((CloudVariableEvent) e).getEntity().isTaskVariable()).collect(Collectors.toList());
        // could be more than one if there are multiple vars
        assertThat(processInstanceTasks).hasSize(1);
        CloudRuntimeEvent resultingEvent = processInstanceTasks.get(0);
        assertThat(resultingEvent).isNotNull();
        assertThat(resultingEvent).isInstanceOf(CloudVariableEvent.class);
        assertThat(((CloudVariableEvent) resultingEvent).getEntity().getName()).isEqualTo(variableName);
        assertThat(resultingEvent.getServiceName()).isNotEmpty();
        assertThat(resultingEvent.getServiceFullName()).isNotEmpty();
    });
}
Also used : VariableEvent(org.activiti.api.model.shared.event.VariableEvent) CloudProcessRuntimeEvent(org.activiti.cloud.api.process.model.events.CloudProcessRuntimeEvent) CloudVariableEvent(org.activiti.cloud.api.model.shared.events.CloudVariableEvent) Awaitility.await(org.awaitility.Awaitility.await) ProcessRuntimeEvent(org.activiti.api.process.model.events.ProcessRuntimeEvent) Task(org.activiti.api.task.model.Task) Collection(java.util.Collection) RuntimeEvent(org.activiti.api.model.shared.event.RuntimeEvent) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) BPMNActivityEvent(org.activiti.api.process.model.events.BPMNActivityEvent) Autowired(org.springframework.beans.factory.annotation.Autowired) Collectors(java.util.stream.Collectors) BPMNTimerEvent(org.activiti.api.process.model.events.BPMNTimerEvent) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) AuditService(org.activiti.cloud.acc.core.services.audit.AuditService) Condition(org.assertj.core.api.Condition) Assertions(org.assertj.core.api.Assertions) Step(net.thucydides.core.annotations.Step) TaskRuntimeEvent(org.activiti.api.task.model.events.TaskRuntimeEvent) CloudTaskRuntimeEvent(org.activiti.cloud.api.task.model.events.CloudTaskRuntimeEvent) EnableRuntimeFeignContext(org.activiti.cloud.acc.core.rest.feign.EnableRuntimeFeignContext) CloudVariableEvent(org.activiti.cloud.api.model.shared.events.CloudVariableEvent) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Step(net.thucydides.core.annotations.Step)

Example 3 with CloudRuntimeEvent

use of org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent in project activiti-cloud by Activiti.

the class AuditSteps method checkProcessInstanceEvent.

@Step
public void checkProcessInstanceEvent(String processInstanceId, ProcessRuntimeEvent.ProcessEvents eventType, long timeoutSeconds) throws Exception {
    Collection<CloudRuntimeEvent> events = getEventsByProcessInstanceIdAndEventType(processInstanceId, eventType.name());
    await().atMost(timeoutSeconds, TimeUnit.SECONDS).untilAsserted(() -> {
        assertThat(events).isNotEmpty();
        CloudRuntimeEvent resultingEvent = events.iterator().next();
        assertThat(resultingEvent).isNotNull();
        assertThat(resultingEvent).isInstanceOf(CloudProcessRuntimeEvent.class);
        assertThat(resultingEvent.getServiceName()).isNotEmpty();
        assertThat(resultingEvent.getServiceFullName()).isNotEmpty();
    });
}
Also used : CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) Step(net.thucydides.core.annotations.Step)

Example 4 with CloudRuntimeEvent

use of org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent in project activiti-cloud by Activiti.

the class AuditEventsControllerImpl method findAll.

@RequestMapping(method = RequestMethod.GET)
public PagedResources<Resource<CloudRuntimeEvent<?, CloudRuntimeEventType>>> findAll(@RequestParam(value = "search", required = false) String search, Pageable pageable) {
    Specification<AuditEventEntity> spec = createSearchSpec(search);
    spec = securityPoliciesApplicationService.createSpecWithSecurity(spec, SecurityPolicyAccess.READ);
    Page<AuditEventEntity> allAuditInPage = eventsRepository.findAll(spec, pageable);
    List<CloudRuntimeEvent<?, CloudRuntimeEventType>> events = new ArrayList<>();
    for (AuditEventEntity aee : allAuditInPage.getContent()) {
        EventToEntityConverter converterByEventTypeName = eventConverters.getConverterByEventTypeName(aee.getEventType());
        if (converterByEventTypeName != null) {
            events.add(converterByEventTypeName.convertToAPI(aee));
        } else {
            LOGGER.warn("Converter not found for Event Type: " + aee.getEventType());
        }
    }
    return pagedResourcesAssembler.toResource(pageable, new PageImpl<>(events, pageable, allAuditInPage.getTotalElements()), eventResourceAssembler);
}
Also used : AuditEventEntity(org.activiti.cloud.services.audit.jpa.events.AuditEventEntity) EventToEntityConverter(org.activiti.cloud.services.audit.api.converters.EventToEntityConverter) ArrayList(java.util.ArrayList) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with CloudRuntimeEvent

use of org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent in project activiti-cloud by Activiti.

the class AuditEventsControllerImpl method findById.

@RequestMapping(value = "/{eventId}", method = RequestMethod.GET)
public Resource<CloudRuntimeEvent<?, CloudRuntimeEventType>> findById(@PathVariable String eventId) {
    Optional<AuditEventEntity> findResult = eventsRepository.findByEventId(eventId);
    if (!findResult.isPresent()) {
        throw new NotFoundException("Unable to find event for the given id:'" + eventId + "'");
    }
    AuditEventEntity auditEventEntity = findResult.get();
    if (!securityPoliciesApplicationService.canRead(auditEventEntity.getProcessDefinitionId(), auditEventEntity.getServiceFullName())) {
        throw new ActivitiForbiddenException("Operation not permitted for " + auditEventEntity.getProcessDefinitionId());
    }
    CloudRuntimeEvent cloudRuntimeEvent = eventConverters.getConverterByEventTypeName(auditEventEntity.getEventType()).convertToAPI(auditEventEntity);
    return eventResourceAssembler.toResource(cloudRuntimeEvent);
}
Also used : ActivitiForbiddenException(org.activiti.core.common.spring.security.policies.ActivitiForbiddenException) AuditEventEntity(org.activiti.cloud.services.audit.jpa.events.AuditEventEntity) NotFoundException(org.activiti.api.runtime.shared.NotFoundException) CloudRuntimeEvent(org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

CloudRuntimeEvent (org.activiti.cloud.api.model.shared.events.CloudRuntimeEvent)65 Test (org.junit.jupiter.api.Test)47 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)39 Awaitility.await (org.awaitility.Awaitility.await)24 List (java.util.List)23 Autowired (org.springframework.beans.factory.annotation.Autowired)23 PagedResources (org.springframework.hateoas.PagedResources)23 CloudProcessInstance (org.activiti.cloud.api.process.model.CloudProcessInstance)21 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)21 Assertions.tuple (org.assertj.core.api.Assertions.tuple)21 ResponseEntity (org.springframework.http.ResponseEntity)20 DirtiesContext (org.springframework.test.annotation.DirtiesContext)20 TestPropertySource (org.springframework.test.context.TestPropertySource)20 ArrayList (java.util.ArrayList)18 Collectors (java.util.stream.Collectors)15 Task (org.activiti.api.task.model.Task)15 StartProcessPayloadBuilder (org.activiti.api.process.model.builders.StartProcessPayloadBuilder)14 ACTIVITY_COMPLETED (org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_COMPLETED)14 ACTIVITY_STARTED (org.activiti.api.process.model.events.BPMNActivityEvent.ActivityEvents.ACTIVITY_STARTED)14 CloudBPMNActivityStartedEvent (org.activiti.cloud.api.process.model.events.CloudBPMNActivityStartedEvent)14