use of uk.gov.homeoffice.cop.workflow.data.DataUploadFailedException in project workflow-service by UKHomeOffice.
the class ElasticSearchUploader method upload.
public void upload(String key, String businessKey, Form form) {
try {
log.info("Saving data to ES");
IndexRequest indexRequest = indexRequestFactory.toIndexRequest(key, businessKey, form);
RequestOptions.Builder builder = RequestOptions.DEFAULT.toBuilder();
builder.addHeader("Content-Type", "application/json");
IndexResponse index = elasticsearchClient.index(indexRequest, builder.build());
log.info("Document uploaded result response '{}'", index.getResult().getLowercase());
} catch (IOException e) {
log.error("Failed to create a document in ES due to '{}'", e.getMessage());
throw new DataUploadFailedException(e);
}
}
use of uk.gov.homeoffice.cop.workflow.data.DataUploadFailedException in project workflow-service by UKHomeOffice.
the class S3Uploader method upload.
public boolean upload(String objectKey, String bucketName, ObjectMetadata metadata, Form form) {
File tempFile = null;
try {
tempFile = writeToTemporaryFile(form);
PutObjectRequest request = new PutObjectRequest(bucketName, objectKey, tempFile);
request.setMetadata(metadata);
log.info("uploading object with key {} to bucket {}", objectKey, bucketName);
PutObjectResult result = amazonS3.putObject(request);
log.info("Uploaded to S3 '{}'", result.getETag());
return true;
} catch (IOException | AmazonServiceException e) {
throw new DataUploadFailedException(e);
} finally {
if (tempFile != null && tempFile.exists()) {
tempFile.delete();
}
}
}
Aggregations