use of bio.terra.service.job.exception.JobResponseException in project jade-data-repo by DataBiosphere.
the class JobService method retrieveJobResultWorker.
private <T> JobResultWithStatus<T> retrieveJobResultWorker(String jobId, Class<T> resultClass) throws StairwayException, InterruptedException {
FlightState flightState = stairway.getFlightState(jobId);
FlightMap resultMap = flightState.getResultMap().orElse(null);
if (resultMap == null) {
throw new InvalidResultStateException("No result map returned from flight");
}
switch(flightState.getFlightStatus()) {
case FATAL:
case ERROR:
if (flightState.getException().isPresent()) {
Exception exception = flightState.getException().get();
if (exception instanceof RuntimeException) {
throw (RuntimeException) exception;
} else {
throw new JobResponseException("wrap non-runtime exception", exception);
}
}
throw new InvalidResultStateException("Failed operation with no exception reported");
case SUCCESS:
HttpStatus statusCode = resultMap.get(JobMapKeys.STATUS_CODE.getKeyName(), HttpStatus.class);
if (statusCode == null) {
statusCode = HttpStatus.OK;
}
return new JobResultWithStatus<T>().statusCode(statusCode).result(resultMap.get(JobMapKeys.RESPONSE.getKeyName(), resultClass));
case RUNNING:
throw new JobNotCompleteException("Attempt to retrieve job result before job is complete; job id: " + flightState.getFlightId());
default:
throw new InvalidResultStateException("Impossible case reached");
}
}
Aggregations