use of com.amazonaws.services.s3.event.S3EventNotification 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);
}
use of com.amazonaws.services.s3.event.S3EventNotification 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);
}
use of com.amazonaws.services.s3.event.S3EventNotification in project herd by FINRAOS.
the class HerdJmsMessageListener method processS3Notification.
/**
* Process the message as S3 notification.
*
* @param payload the JMS message payload.
*
* @return boolean whether message was processed.
*/
private boolean processS3Notification(String payload) {
boolean messageProcessed = false;
try {
// Process messages coming from S3 bucket.
S3EventNotification s3EventNotification = S3EventNotification.parseJson(payload);
String objectKey = URLDecoder.decode(s3EventNotification.getRecords().get(0).getS3().getObject().getKey(), CharEncoding.UTF_8);
// Perform the complete upload single file.
CompleteUploadSingleMessageResult completeUploadSingleMessageResult = uploadDownloadService.performCompleteUploadSingleMessage(objectKey);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("completeUploadSingleMessageResult={}", jsonHelper.objectToJson(completeUploadSingleMessageResult));
}
messageProcessed = true;
} catch (RuntimeException | UnsupportedEncodingException e) {
// The logging is set to DEBUG level, since the method is expected to fail when message is not of the expected type.
LOGGER.debug("Failed to process message from the JMS queue for an S3 notification. jmsQueueName=\"{}\" jmsMessagePayload={}", HerdJmsDestinationResolver.SQS_DESTINATION_HERD_INCOMING, payload, e);
}
return messageProcessed;
}
use of com.amazonaws.services.s3.event.S3EventNotification in project herd by FINRAOS.
the class SampleDataJmsMessageListenerTest method testS3MessageWithDashCharacterName.
@Test
public void testS3MessageWithDashCharacterName() throws Exception {
String namespace = "testnamespace-1";
String businessObjectDefinitionName = "testbdefname-1";
// Create and persist database entities required for testing.
businessObjectDefinitionServiceTestHelper.createDatabaseEntitiesForBusinessObjectDefinitionTesting(namespace, DATA_PROVIDER_NAME);
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, businessObjectDefinitionName, 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, businessObjectDefinitionName));
assertNotNull(businessObjectDefinitionEntity);
String fileName = "test1.csv";
String filePath = namespace + "/" + businessObjectDefinitionName + "/" + 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, businessObjectDefinitionName);
BusinessObjectDefinition updatedBusinessObjectDefinition = businessObjectDefinitionService.getBusinessObjectDefinition(businessObjectDefinitionKey, false);
List<SampleDataFile> sampleDataFiles = Arrays.asList(new SampleDataFile(namespace + "/" + businessObjectDefinitionName + "/", fileName));
// Validate the returned object.
assertEquals(new BusinessObjectDefinition(updatedBusinessObjectDefinition.getId(), namespace, businessObjectDefinitionName, 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);
}
use of com.amazonaws.services.s3.event.S3EventNotification in project herd by FINRAOS.
the class SampleDataJmsMessageListenerTest method testS3MessageWithWrongFormat.
@Test
public void testS3MessageWithWrongFormat() 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);
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);
try {
sampleDataJmsMessageListener.processMessage(jsonHelper.objectToJson(s3EventNotification), null);
} catch (IllegalArgumentException ex) {
// this exception should be caught inside the processMessage method
fail();
}
}
Aggregations