String result = checkTaskKey(request, scanQueueTaskId);
if (!result.equals(TASK_KEY_SUCCESS)) {
return RestResponse.failure(result);
}
ScanQueueTask myTask = this.scanQueueService.retrieveById(scanQueueTaskId);
Application taskApp = myTask.getApplication();
// TODO - Add some checking so you can't just upload any file as the result of a specific scanner's task
// For now, passing NULL should force the calculation
Integer myChannelId = scanTypeCalculationService.calculateScanType(taskApp.getId(), file, null);
try {
String fileName = scanTypeCalculationService.saveFile(myChannelId, file);
ScanCheckResultBean returnValue = scanService.checkFile(myChannelId, fileName);
if (ScanImportStatus.SUCCESSFUL_SCAN == returnValue.getScanCheckResult()) {
scanMergeService.saveRemoteScanAndRun(myChannelId, fileName);
// Scan has been saved. Let's update the ScanQueueTask
this.scanQueueService.completeTask(scanQueueTaskId);
log.info("Results from scan queue task: " + myTask.getId() + " saved successfully.");
return RestResponse.success(myTask);
} else if (ScanImportStatus.EMPTY_SCAN_ERROR == returnValue.getScanCheckResult()) {
String message = "Task appeared to complete successfully, but results provided were empty.";
this.scanQueueService.failTask(scanQueueTaskId, message);
log.warn("When saving scan queue task: " + myTask.getId() + ": " + message);
return RestResponse.failure(message);
} else {
String message = "Task appeared to complete successfully, but the scan upload attempt returned this message: " + returnValue.getScanCheckResult();
this.scanQueueService.failTask(scanQueueTaskId, message);
log.warn("When saving scan queue task: " + myTask.getId() + ": " + message);
return RestResponse.failure(message);
}
} catch (Exception e) {
// Something went wrong trying to save the file. Mark the scan as a failure.
String message = "Exception thrown while trying to save scan.";