@Test public void handleShouldThrowExceptionWhenRelatedProcessInstanceIsNotFound() { CloudProcessCompletedEvent event = createProcessCompletedEvent(); given(processInstanceRepository.findById("200")).willReturn(Optional.empty()); expectedException.expect(QueryException.class); expectedException.expectMessage("Unable to find process instance with the given id: "); handler.handle(event); }
@Override public void handle(CloudRuntimeEvent<?, ?> event) { CloudProcessCompletedEvent completedEvent = (CloudProcessCompletedEvent) event; String processInstanceId = completedEvent.getEntity().getId(); Optional<ProcessInstanceEntity> findResult = processInstanceRepository.findById(processInstanceId); if (findResult.isPresent()) { ProcessInstanceEntity processInstanceEntity = findResult.get(); processInstanceEntity.setStatus(ProcessInstance.ProcessInstanceStatus.COMPLETED); processInstanceEntity.setLastModified(new Date(completedEvent.getTimestamp())); processInstanceRepository.save(processInstanceEntity); } else { throw new QueryException("Unable to find process instance with the given id: " + processInstanceId); } }
ProcessCompletedEventHandler implements QueryEventHandler { @Override public void handle(CloudRuntimeEvent<?, ?> event) { CloudProcessCompletedEvent completedEvent = (CloudProcessCompletedEvent) event; String processInstanceId = completedEvent.getEntity().getId(); Optional<ProcessInstanceEntity> findResult = processInstanceRepository.findById(processInstanceId); if (findResult.isPresent()) { ProcessInstanceEntity processInstanceEntity = findResult.get(); processInstanceEntity.setStatus(ProcessInstance.ProcessInstanceStatus.COMPLETED); processInstanceEntity.setLastModified(new Date(completedEvent.getTimestamp())); processInstanceRepository.save(processInstanceEntity); } else { throw new QueryException("Unable to find process instance with the given id: " + processInstanceId); } } }
ProcessCompletedEventHandler implements QueryEventHandler { @Override public void handle(CloudRuntimeEvent<?, ?> event) { CloudProcessCompletedEvent completedEvent = (CloudProcessCompletedEvent) event; String processInstanceId = completedEvent.getEntity().getId(); Optional<ProcessInstanceEntity> findResult = processInstanceRepository.findById(processInstanceId); if (findResult.isPresent()) { ProcessInstanceEntity processInstanceEntity = findResult.get(); processInstanceEntity.setStatus(ProcessInstance.ProcessInstanceStatus.COMPLETED); processInstanceEntity.setLastModified(new Date(completedEvent.getTimestamp())); processInstanceRepository.save(processInstanceEntity); } else { throw new QueryException("Unable to find process instance with the given id: " + processInstanceId); } } ProcessCompletedEventHandler(ProcessInstanceRepository processInstanceRepository); }
ProcessCompletedEventHandler implements QueryEventHandler { @Override public void handle(CloudRuntimeEvent<?, ?> event) { CloudProcessCompletedEvent completedEvent = (CloudProcessCompletedEvent) event; String processInstanceId = completedEvent.getEntity().getId(); Optional<ProcessInstanceEntity> findResult = processInstanceRepository.findById(processInstanceId); if (findResult.isPresent()) { ProcessInstanceEntity processInstanceEntity = findResult.get(); processInstanceEntity.setStatus(ProcessInstance.ProcessInstanceStatus.COMPLETED); processInstanceEntity.setLastModified(new Date(completedEvent.getTimestamp())); processInstanceRepository.save(processInstanceEntity); } else { throw new QueryException("Unable to find process instance with the given id: " + processInstanceId); } } ProcessCompletedEventHandler(ProcessInstanceRepository processInstanceRepository); @Override void handle(CloudRuntimeEvent<?, ?> event); @Override String getHandledEvent(); }
ProcessCompletedEventHandler implements QueryEventHandler { @Override public void handle(CloudRuntimeEvent<?, ?> event) { CloudProcessCompletedEvent completedEvent = (CloudProcessCompletedEvent) event; String processInstanceId = completedEvent.getEntity().getId(); Optional<ProcessInstanceEntity> findResult = processInstanceRepository.findById(processInstanceId); if (findResult.isPresent()) { ProcessInstanceEntity processInstanceEntity = findResult.get(); processInstanceEntity.setStatus(ProcessInstance.ProcessInstanceStatus.COMPLETED); processInstanceEntity.setLastModified(new Date(completedEvent.getTimestamp())); processInstanceRepository.save(processInstanceEntity); } else { throw new QueryException("Unable to find process instance with the given id: " + processInstanceId); } } ProcessCompletedEventHandler(ProcessInstanceRepository processInstanceRepository); @Override void handle(CloudRuntimeEvent<?, ?> event); @Override String getHandledEvent();  }