@Test public void handleShouldIgnoreEventIfProcessInstanceIsAlreadyInRunningStatus() { CloudProcessStartedEvent event = buildProcessStartedEvent(); ProcessInstanceEntity currentProcessInstanceEntity = mock(ProcessInstanceEntity.class); given(currentProcessInstanceEntity.getStatus()).willReturn(ProcessInstance.ProcessInstanceStatus.RUNNING); given(processInstanceRepository.findById(event.getEntity().getId())).willReturn(Optional.of(currentProcessInstanceEntity)); handler.handle(event); verify(processInstanceRepository, never()).save(currentProcessInstanceEntity); verify(currentProcessInstanceEntity, never()).setStatus(ProcessInstance.ProcessInstanceStatus.RUNNING); }
@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); processInstanceEntity.setName(startedEvent.getEntity().getName()); processInstanceEntity.setLastModified(new Date(startedEvent.getTimestamp())); processInstanceRepository.save(processInstanceEntity); } }
ProcessStartedEventHandler implements QueryEventHandler { @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); processInstanceEntity.setName(startedEvent.getEntity().getName()); processInstanceEntity.setLastModified(new Date(startedEvent.getTimestamp())); processInstanceRepository.save(processInstanceEntity); } } }
ProcessStartedEventHandler implements QueryEventHandler { @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); processInstanceEntity.setName(startedEvent.getEntity().getName()); processInstanceEntity.setLastModified(new Date(startedEvent.getTimestamp())); processInstanceRepository.save(processInstanceEntity); } } ProcessStartedEventHandler(ProcessInstanceRepository processInstanceRepository); }
ProcessStartedEventHandler implements QueryEventHandler { @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); processInstanceEntity.setName(startedEvent.getEntity().getName()); processInstanceEntity.setLastModified(new Date(startedEvent.getTimestamp())); processInstanceRepository.save(processInstanceEntity); } } ProcessStartedEventHandler(ProcessInstanceRepository processInstanceRepository); @Override void handle(CloudRuntimeEvent<?, ?> event); @Override String getHandledEvent(); }
ProcessStartedEventHandler implements QueryEventHandler { @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); processInstanceEntity.setName(startedEvent.getEntity().getName()); processInstanceEntity.setLastModified(new Date(startedEvent.getTimestamp())); processInstanceRepository.save(processInstanceEntity); } } ProcessStartedEventHandler(ProcessInstanceRepository processInstanceRepository); @Override void handle(CloudRuntimeEvent<?, ?> event); @Override String getHandledEvent();  }