Search in sources :

Example 26 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project amazon-s3-object-lambda-default-configuration by aws-samples.

the class GetObjectResponseHandler method writeObjectResponse.

public void writeObjectResponse(HttpResponse<InputStream> presignedResponse, byte[] responseObjectByteArray) {
    Checksum checksum;
    try {
        checksum = this.checksumGenerator.getChecksum(responseObjectByteArray);
    } catch (Exception e) {
        this.logger.error("Error while writing object response" + e);
        writeErrorResponse("Error while writing object response.", Error.SERVER_ERROR);
        return;
    }
    var checksumMap = new HashMap<String, String>();
    checksumMap.put("algorithm", checksum.getAlgorithm());
    checksumMap.put("digest", checksum.getChecksum());
    var checksumObjectMetaData = new ObjectMetadata();
    checksumObjectMetaData.setUserMetadata(checksumMap);
    this.s3Client.writeGetObjectResponse(new WriteGetObjectResponseRequest().withRequestRoute(event.outputRoute()).withRequestToken(event.outputToken()).withInputStream(new ByteArrayInputStream(responseObjectByteArray)).withMetadata(checksumObjectMetaData).withStatusCode(presignedResponse.statusCode()));
}
Also used : WriteGetObjectResponseRequest(com.amazonaws.services.s3.model.WriteGetObjectResponseRequest) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) Checksum(com.example.s3objectlambda.checksum.Checksum) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) IOException(java.io.IOException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXException(org.xml.sax.SAXException)

Example 27 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project core-geonetwork by geonetwork.

the class S3Store method getResourceDescription.

@Override
public MetadataResource getResourceDescription(final ServiceContext context, final String metadataUuid, final MetadataResourceVisibility visibility, final String filename, Boolean approved) throws Exception {
    int metadataId = getAndCheckMetadataId(metadataUuid, approved);
    final String key = getKey(metadataUuid, metadataId, visibility, filename);
    try {
        final ObjectMetadata metadata = s3.getClient().getObjectMetadata(s3.getBucket(), key);
        return createResourceDescription(metadataUuid, visibility, filename, metadata.getContentLength(), metadata.getLastModified(), metadataId, approved);
    } catch (AmazonServiceException e) {
        return null;
    }
}
Also used : AmazonServiceException(com.amazonaws.AmazonServiceException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 28 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project core-geonetwork by geonetwork.

the class S3Store method patchResourceStatus.

@Override
public MetadataResource patchResourceStatus(final ServiceContext context, final String metadataUuid, final String resourceId, final MetadataResourceVisibility visibility, Boolean approved) throws Exception {
    int metadataId = canEdit(context, metadataUuid, approved);
    String sourceKey = null;
    ObjectMetadata metadata = null;
    for (MetadataResourceVisibility sourceVisibility : MetadataResourceVisibility.values()) {
        final String key = getKey(metadataUuid, metadataId, sourceVisibility, resourceId);
        try {
            metadata = s3.getClient().getObjectMetadata(s3.getBucket(), key);
            if (sourceVisibility != visibility) {
                sourceKey = key;
                break;
            } else {
                // already the good visibility
                return createResourceDescription(metadataUuid, visibility, resourceId, metadata.getContentLength(), metadata.getLastModified(), metadataId, approved);
            }
        } catch (AmazonServiceException ignored) {
        // ignored
        }
    }
    if (sourceKey != null) {
        final String destKey = getKey(metadataUuid, metadataId, visibility, resourceId);
        final CopyObjectResult copyResult = s3.getClient().copyObject(s3.getBucket(), sourceKey, s3.getBucket(), destKey);
        s3.getClient().deleteObject(s3.getBucket(), sourceKey);
        return createResourceDescription(metadataUuid, visibility, resourceId, metadata.getContentLength(), copyResult.getLastModifiedDate(), metadataId, approved);
    } else {
        throw new ResourceNotFoundException(String.format("Metadata resource '%s' not found for metadata '%s'", resourceId, metadataUuid));
    }
}
Also used : CopyObjectResult(com.amazonaws.services.s3.model.CopyObjectResult) AmazonServiceException(com.amazonaws.AmazonServiceException) MetadataResourceVisibility(org.fao.geonet.domain.MetadataResourceVisibility) ResourceNotFoundException(org.fao.geonet.api.exception.ResourceNotFoundException) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 29 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project aws-swf-flow-library by aws.

the class AverageCalculatorActivitiesImpl method computeDataSizeForInputData.

@Override
public int computeDataSizeForInputData(String bucketName, String filename) {
    ObjectMetadata metadata = storage.getObjectMetadata(bucketName, filename);
    long size = metadata.getContentLength();
    return (int) size / ROW_SIZE;
}
Also used : ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Example 30 with ObjectMetadata

use of com.ibm.watson.visual_recognition.v4.model.ObjectMetadata in project goobi-workflow by intranda.

the class S3FileUtils method getLastModifiedDate.

@Override
public long getLastModifiedDate(Path path) throws IOException {
    if (getPathStorageType(path) == StorageType.LOCAL) {
        return nio.getLastModifiedDate(path);
    }
    ObjectMetadata om = s3.getObjectMetadata(getBucket(), path2Key(path));
    if (om == null) {
        // check everything inside prefix.
        long lastModified = 0;
        ObjectListing listing = s3.listObjects(getBucket(), path2Key(path));
        for (S3ObjectSummary os : listing.getObjectSummaries()) {
            if (os.getLastModified().getTime() > lastModified) {
                lastModified = os.getLastModified().getTime();
            }
        }
        while (listing.isTruncated()) {
            listing = s3.listNextBatchOfObjects(listing);
            for (S3ObjectSummary os : listing.getObjectSummaries()) {
                if (os.getLastModified().getTime() > lastModified) {
                    lastModified = os.getLastModified().getTime();
                }
            }
        }
        return lastModified;
    } else {
        // return lastModified of object
        return om.getLastModified().getTime();
    }
}
Also used : ObjectListing(com.amazonaws.services.s3.model.ObjectListing) S3ObjectSummary(com.amazonaws.services.s3.model.S3ObjectSummary) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata)

Aggregations

ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)566 PutObjectRequest (com.amazonaws.services.s3.model.PutObjectRequest)191 ByteArrayInputStream (java.io.ByteArrayInputStream)157 Test (org.junit.Test)143 IOException (java.io.IOException)101 InputStream (java.io.InputStream)80 File (java.io.File)62 AmazonClientException (com.amazonaws.AmazonClientException)61 AmazonServiceException (com.amazonaws.AmazonServiceException)61 S3Object (com.amazonaws.services.s3.model.S3Object)59 AmazonS3 (com.amazonaws.services.s3.AmazonS3)54 Date (java.util.Date)46 S3FileTransferRequestParamsDto (org.finra.herd.model.dto.S3FileTransferRequestParamsDto)34 GetObjectMetadataRequest (com.amazonaws.services.s3.model.GetObjectMetadataRequest)33 PutObjectResult (com.amazonaws.services.s3.model.PutObjectResult)32 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)30 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)29 Upload (com.amazonaws.services.s3.transfer.Upload)26 SdkClientException (com.amazonaws.SdkClientException)24 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)24