Search in sources :

Example 1 with DataUploadFailedException

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);
    }
}
Also used : DataUploadFailedException(uk.gov.homeoffice.cop.workflow.data.DataUploadFailedException) RequestOptions(org.elasticsearch.client.RequestOptions) IndexResponse(org.elasticsearch.action.index.IndexResponse) IOException(java.io.IOException) IndexRequest(org.elasticsearch.action.index.IndexRequest)

Example 2 with DataUploadFailedException

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();
        }
    }
}
Also used : DataUploadFailedException(uk.gov.homeoffice.cop.workflow.data.DataUploadFailedException) PutObjectResult(com.amazonaws.services.s3.model.PutObjectResult) AmazonServiceException(com.amazonaws.AmazonServiceException) IOException(java.io.IOException) File(java.io.File) PutObjectRequest(com.amazonaws.services.s3.model.PutObjectRequest)

Aggregations

IOException (java.io.IOException)2 DataUploadFailedException (uk.gov.homeoffice.cop.workflow.data.DataUploadFailedException)2 AmazonServiceException (com.amazonaws.AmazonServiceException)1 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)1 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)1 File (java.io.File)1 IndexRequest (org.elasticsearch.action.index.IndexRequest)1 IndexResponse (org.elasticsearch.action.index.IndexResponse)1 RequestOptions (org.elasticsearch.client.RequestOptions)1