use of com.synopsys.integration.alert.common.descriptor.config.field.validation.ValidationResult in project hub-alert by blackducksoftware.
the class AbstractUploadAction method writeFile.
private ActionResponse<Void> writeFile(Resource fileResource) {
try {
String targetFilename = target.getFilename();
String tempFilename = "temp_" + targetFilename;
Optional<UploadValidationFunction> validationFunction = target.getValidationFunction();
if (validationFunction.isPresent()) {
writeFile(tempFilename, fileResource);
File tempFileToValidate = filePersistenceUtil.createUploadsFile(tempFilename);
ValidationResult validationResult = validationFunction.get().apply(tempFileToValidate);
filePersistenceUtil.delete(tempFileToValidate);
if (validationResult.hasErrors()) {
return new ActionResponse<>(HttpStatus.BAD_REQUEST, validationResult.combineErrorMessages());
}
}
writeFile(targetFilename, fileResource);
} catch (IOException ex) {
logger.error("Error uploading file - file: {}, context: {}, descriptor: {} ", target.getFilename(), target.getContext(), target.getDescriptorKey().getUniversalKey());
logger.error("Error uploading file caused by: ", ex);
return new ActionResponse<>(HttpStatus.INTERNAL_SERVER_ERROR, "Error uploading file to server.");
}
return new ActionResponse<>(HttpStatus.NO_CONTENT);
}
Aggregations