Search in sources :

Example 6 with S3EventNotificationRecord

use of com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord in project bender by Nextdoor.

the class S3SnsNotifier method getS3Notification.

public static S3EventNotification getS3Notification(String key, String bucket, long size) {
    S3ObjectEntity objEntity = new S3ObjectEntity(key, size, null, null);
    S3BucketEntity bucketEntity = new S3BucketEntity(bucket, null, null);
    S3Entity entity = new S3Entity(null, bucketEntity, objEntity, null);
    String timestamp = formatter.print(System.currentTimeMillis());
    S3EventNotificationRecord rec = new S3EventNotificationRecord(null, null, null, timestamp, null, null, null, entity, null);
    List<S3EventNotificationRecord> notifications = new ArrayList<S3EventNotificationRecord>(1);
    notifications.add(rec);
    return new S3EventNotification(notifications);
}
Also used : S3EventNotification(com.amazonaws.services.s3.event.S3EventNotification) S3ObjectEntity(com.amazonaws.services.s3.event.S3EventNotification.S3ObjectEntity) S3Entity(com.amazonaws.services.s3.event.S3EventNotification.S3Entity) S3EventNotificationRecord(com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord) ArrayList(java.util.ArrayList) S3BucketEntity(com.amazonaws.services.s3.event.S3EventNotification.S3BucketEntity)

Example 7 with S3EventNotificationRecord

use of com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord in project herd by FINRAOS.

the class SampleDataJmsMessageListenerTest method testS3Message.

@Test
public void testS3Message() throws Exception {
    // Create and persist database entities required for testing.
    businessObjectDefinitionServiceTestHelper.createDatabaseEntitiesForBusinessObjectDefinitionTesting();
    storageDaoTestHelper.createStorageEntity(StorageEntity.SAMPLE_DATA_FILE_STORAGE, Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.S3_ATTRIBUTE_NAME_BUCKET_NAME), S3_BUCKET_NAME)));
    // Create a business object definition.
    BusinessObjectDefinitionCreateRequest request = new BusinessObjectDefinitionCreateRequest(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, BDEF_DISPLAY_NAME, businessObjectDefinitionServiceTestHelper.getNewAttributes());
    businessObjectDefinitionService.createBusinessObjectDefinition(request);
    // Get the business object definition entity.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME));
    assertNotNull(businessObjectDefinitionEntity);
    String fileName = "test1.csv";
    String filePath = NAMESPACE + "/" + BDEF_NAME + "/" + fileName;
    long fileSize = 1024L;
    S3Entity s3Entity = new S3Entity(null, null, new S3ObjectEntity(filePath, fileSize, null, null), null);
    List<S3EventNotificationRecord> records = new ArrayList<>();
    records.add(new S3EventNotificationRecord(null, null, null, null, null, null, null, s3Entity, null));
    S3EventNotification s3EventNotification = new S3EventNotification(records);
    sampleDataJmsMessageListener.processMessage(jsonHelper.objectToJson(s3EventNotification), null);
    BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME);
    BusinessObjectDefinition updatedBusinessObjectDefinition = businessObjectDefinitionService.getBusinessObjectDefinition(businessObjectDefinitionKey, false);
    List<SampleDataFile> sampleDataFiles = Arrays.asList(new SampleDataFile(NAMESPACE + "/" + BDEF_NAME + "/", fileName));
    // Validate the returned object.
    assertEquals(new BusinessObjectDefinition(updatedBusinessObjectDefinition.getId(), NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, NO_BDEF_SHORT_DESCRIPTION, BDEF_DISPLAY_NAME, businessObjectDefinitionServiceTestHelper.getNewAttributes(), NO_DESCRIPTIVE_BUSINESS_OBJECT_FORMAT, sampleDataFiles, businessObjectDefinitionEntity.getCreatedBy(), businessObjectDefinitionEntity.getUpdatedBy(), HerdDateUtils.getXMLGregorianCalendarValue(businessObjectDefinitionEntity.getUpdatedOn()), NO_BUSINESS_OBJECT_DEFINITION_CHANGE_EVENTS), updatedBusinessObjectDefinition);
}
Also used : S3Entity(com.amazonaws.services.s3.event.S3EventNotification.S3Entity) BusinessObjectDefinition(org.finra.herd.model.api.xml.BusinessObjectDefinition) SampleDataFile(org.finra.herd.model.api.xml.SampleDataFile) Attribute(org.finra.herd.model.api.xml.Attribute) BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) ArrayList(java.util.ArrayList) BusinessObjectDefinitionCreateRequest(org.finra.herd.model.api.xml.BusinessObjectDefinitionCreateRequest) S3EventNotification(com.amazonaws.services.s3.event.S3EventNotification) S3ObjectEntity(com.amazonaws.services.s3.event.S3EventNotification.S3ObjectEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) S3EventNotificationRecord(com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 8 with S3EventNotificationRecord

use of com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord in project herd by FINRAOS.

the class HerdJmsMessageListenerTest method testS3MessageS3FileNoExists.

@Test
public void testS3MessageS3FileNoExists() throws Exception {
    setLogLevel(UploadDownloadHelperServiceImpl.class, LogLevel.OFF);
    uploadDownloadServiceTestHelper.createDatabaseEntitiesForUploadDownloadTesting();
    UploadSingleInitiationResponse resultUploadSingleInitiationResponse = uploadDownloadService.initiateUploadSingle(uploadDownloadServiceTestHelper.createUploadSingleInitiationRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, NAMESPACE, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2, TARGET_S3_KEY));
    String filePath = resultUploadSingleInitiationResponse.getSourceBusinessObjectData().getStorageUnits().get(0).getStorageFiles().get(0).getFilePath();
    S3Entity s3Entity = new S3Entity(null, null, new S3ObjectEntity(filePath, 0L, null, null), null);
    List<S3EventNotificationRecord> records = new ArrayList<>();
    records.add(new S3EventNotificationRecord(null, null, null, null, null, null, null, s3Entity, null));
    S3EventNotification s3EventNotification = new S3EventNotification(records);
    setLogLevel(UploadDownloadServiceImpl.class, LogLevel.OFF);
    setLogLevel(HerdJmsMessageListener.class, LogLevel.OFF);
    // Try to process an S3 JMS message, when source S3 file does not exist.
    herdJmsMessageListener.processMessage(jsonHelper.objectToJson(s3EventNotification), null);
}
Also used : S3EventNotification(com.amazonaws.services.s3.event.S3EventNotification) S3Entity(com.amazonaws.services.s3.event.S3EventNotification.S3Entity) S3ObjectEntity(com.amazonaws.services.s3.event.S3EventNotification.S3ObjectEntity) S3EventNotificationRecord(com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord) ArrayList(java.util.ArrayList) UploadSingleInitiationResponse(org.finra.herd.model.api.xml.UploadSingleInitiationResponse) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 9 with S3EventNotificationRecord

use of com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord in project herd by FINRAOS.

the class HerdJmsMessageListenerTest method testS3Message.

@Test
public void testS3Message() throws Exception {
    setLogLevel(UploadDownloadHelperServiceImpl.class, LogLevel.OFF);
    uploadDownloadServiceTestHelper.createDatabaseEntitiesForUploadDownloadTesting();
    UploadSingleInitiationResponse resultUploadSingleInitiationResponse = uploadDownloadService.initiateUploadSingle(uploadDownloadServiceTestHelper.createUploadSingleInitiationRequest());
    String filePath = resultUploadSingleInitiationResponse.getSourceBusinessObjectData().getStorageUnits().get(0).getStorageFiles().get(0).getFilePath();
    S3Entity s3Entity = new S3Entity(null, null, new S3ObjectEntity(filePath, 0L, null, null), null);
    List<S3EventNotificationRecord> records = new ArrayList<>();
    records.add(new S3EventNotificationRecord(null, null, null, null, null, null, null, s3Entity, null));
    S3EventNotification s3EventNotification = new S3EventNotification(records);
    setLogLevel(UploadDownloadServiceImpl.class, LogLevel.OFF);
    setLogLevel(HerdJmsMessageListener.class, LogLevel.DEBUG);
    herdJmsMessageListener.processMessage(jsonHelper.objectToJson(s3EventNotification), null);
}
Also used : S3EventNotification(com.amazonaws.services.s3.event.S3EventNotification) S3Entity(com.amazonaws.services.s3.event.S3EventNotification.S3Entity) S3ObjectEntity(com.amazonaws.services.s3.event.S3EventNotification.S3ObjectEntity) S3EventNotificationRecord(com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord) ArrayList(java.util.ArrayList) UploadSingleInitiationResponse(org.finra.herd.model.api.xml.UploadSingleInitiationResponse) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 10 with S3EventNotificationRecord

use of com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord in project herd by FINRAOS.

the class HerdJmsMessageListenerTest method testS3MessageNoKey.

@Test
public void testS3MessageNoKey() throws Exception {
    S3Entity s3Entity = new S3Entity(null, null, new S3ObjectEntity("key_does_not_exist", 0L, null, null), null);
    List<S3EventNotificationRecord> records = new ArrayList<>();
    records.add(new S3EventNotificationRecord(null, null, null, null, null, null, null, s3Entity, null));
    S3EventNotification s3EventNotification = new S3EventNotification(records);
    setLogLevel(UploadDownloadServiceImpl.class, LogLevel.OFF);
    setLogLevel(HerdJmsMessageListener.class, LogLevel.OFF);
    herdJmsMessageListener.processMessage(jsonHelper.objectToJson(s3EventNotification), null);
}
Also used : S3EventNotification(com.amazonaws.services.s3.event.S3EventNotification) S3Entity(com.amazonaws.services.s3.event.S3EventNotification.S3Entity) S3ObjectEntity(com.amazonaws.services.s3.event.S3EventNotification.S3ObjectEntity) S3EventNotificationRecord(com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord) ArrayList(java.util.ArrayList) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Aggregations

S3EventNotificationRecord (com.amazonaws.services.s3.event.S3EventNotification.S3EventNotificationRecord)14 ArrayList (java.util.ArrayList)13 S3EventNotification (com.amazonaws.services.s3.event.S3EventNotification)12 S3Entity (com.amazonaws.services.s3.event.S3EventNotification.S3Entity)11 S3ObjectEntity (com.amazonaws.services.s3.event.S3EventNotification.S3ObjectEntity)11 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)6 Test (org.junit.Test)6 S3BucketEntity (com.amazonaws.services.s3.event.S3EventNotification.S3BucketEntity)5 InputStreamReader (java.io.InputStreamReader)5 SNSRecord (com.amazonaws.services.lambda.runtime.events.SNSEvent.SNSRecord)3 Attribute (org.finra.herd.model.api.xml.Attribute)3 BusinessObjectDefinitionCreateRequest (org.finra.herd.model.api.xml.BusinessObjectDefinitionCreateRequest)3 SNSEvent (com.amazonaws.services.lambda.runtime.events.SNSEvent)2 SourceNotFoundException (com.nextdoor.bender.utils.SourceUtils.SourceNotFoundException)2 BusinessObjectDefinition (org.finra.herd.model.api.xml.BusinessObjectDefinition)2 BusinessObjectDefinitionKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionKey)2 SampleDataFile (org.finra.herd.model.api.xml.SampleDataFile)2 UploadSingleInitiationResponse (org.finra.herd.model.api.xml.UploadSingleInitiationResponse)2 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)2 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)1