@Test public void handleShouldThrowExceptionWhenRelatedProcessInstanceIsNotFound() { CloudProcessSuspendedEvent event = buildProcessSuspendedEvent(); 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) { CloudProcessSuspendedEvent suspendedEvent = (CloudProcessSuspendedEvent) event; String processInstanceId = suspendedEvent.getEntity().getId(); ProcessInstanceEntity processInstanceEntity = processInstanceRepository.findById(processInstanceId) .orElseThrow( () -> new QueryException("Unable to find process instance with the given id: " + processInstanceId) ); processInstanceEntity.setStatus(ProcessInstance.ProcessInstanceStatus.SUSPENDED); processInstanceEntity.setLastModified(new Date(suspendedEvent.getTimestamp())); processInstanceRepository.save(processInstanceEntity); }
ProcessSuspendedEventHandler implements QueryEventHandler { @Override public void handle(CloudRuntimeEvent<?, ?> event) { CloudProcessSuspendedEvent suspendedEvent = (CloudProcessSuspendedEvent) event; String processInstanceId = suspendedEvent.getEntity().getId(); ProcessInstanceEntity processInstanceEntity = processInstanceRepository.findById(processInstanceId) .orElseThrow( () -> new QueryException("Unable to find process instance with the given id: " + processInstanceId) ); processInstanceEntity.setStatus(ProcessInstance.ProcessInstanceStatus.SUSPENDED); processInstanceEntity.setLastModified(new Date(suspendedEvent.getTimestamp())); processInstanceRepository.save(processInstanceEntity); } }
ProcessSuspendedEventHandler implements QueryEventHandler { @Override public void handle(CloudRuntimeEvent<?, ?> event) { CloudProcessSuspendedEvent suspendedEvent = (CloudProcessSuspendedEvent) event; String processInstanceId = suspendedEvent.getEntity().getId(); ProcessInstanceEntity processInstanceEntity = processInstanceRepository.findById(processInstanceId) .orElseThrow( () -> new QueryException("Unable to find process instance with the given id: " + processInstanceId) ); processInstanceEntity.setStatus(ProcessInstance.ProcessInstanceStatus.SUSPENDED); processInstanceEntity.setLastModified(new Date(suspendedEvent.getTimestamp())); processInstanceRepository.save(processInstanceEntity); } ProcessSuspendedEventHandler(ProcessInstanceRepository processInstanceRepository); }
ProcessSuspendedEventHandler implements QueryEventHandler { @Override public void handle(CloudRuntimeEvent<?, ?> event) { CloudProcessSuspendedEvent suspendedEvent = (CloudProcessSuspendedEvent) event; String processInstanceId = suspendedEvent.getEntity().getId(); ProcessInstanceEntity processInstanceEntity = processInstanceRepository.findById(processInstanceId) .orElseThrow( () -> new QueryException("Unable to find process instance with the given id: " + processInstanceId) ); processInstanceEntity.setStatus(ProcessInstance.ProcessInstanceStatus.SUSPENDED); processInstanceEntity.setLastModified(new Date(suspendedEvent.getTimestamp())); processInstanceRepository.save(processInstanceEntity); } ProcessSuspendedEventHandler(ProcessInstanceRepository processInstanceRepository); @Override void handle(CloudRuntimeEvent<?, ?> event); @Override String getHandledEvent(); }
ProcessSuspendedEventHandler implements QueryEventHandler { @Override public void handle(CloudRuntimeEvent<?, ?> event) { CloudProcessSuspendedEvent suspendedEvent = (CloudProcessSuspendedEvent) event; String processInstanceId = suspendedEvent.getEntity().getId(); ProcessInstanceEntity processInstanceEntity = processInstanceRepository.findById(processInstanceId) .orElseThrow( () -> new QueryException("Unable to find process instance with the given id: " + processInstanceId) ); processInstanceEntity.setStatus(ProcessInstance.ProcessInstanceStatus.SUSPENDED); processInstanceEntity.setLastModified(new Date(suspendedEvent.getTimestamp())); processInstanceRepository.save(processInstanceEntity); } ProcessSuspendedEventHandler(ProcessInstanceRepository processInstanceRepository); @Override void handle(CloudRuntimeEvent<?, ?> event); @Override String getHandledEvent();  }