use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.
the class StorageFileHelper method validateS3Files.
/**
* Validates S3 files per list of expected storage files.
*
* @param expectedStorageFiles the list of expected S3 files represented by storage files
* @param actualS3Files the list of actual S3 files represented by S3 object summaries
* @param storageName the storage name
* @param businessObjectDataKey the business object data key
* @param fileDescription the file description (i.e. "registered" or "copied") to be used in the relative error messages
*/
private void validateS3Files(List<StorageFile> expectedStorageFiles, List<S3ObjectSummary> actualS3Files, String storageName, BusinessObjectDataKey businessObjectDataKey, String fileDescription) {
// Load all actual S3 files into a map for easy access.
Map<String, StorageFile> actualFilesMap = getStorageFilesMapFromS3ObjectSummaries(actualS3Files);
// Validate existence and file size for all expected files.
for (StorageFile expectedFile : expectedStorageFiles) {
if (!actualFilesMap.containsKey(expectedFile.getFilePath())) {
throw new ObjectNotFoundException(String.format("%s file \"%s\" does not exist in \"%s\" storage.", StringUtils.capitalize(fileDescription), expectedFile.getFilePath(), storageName));
} else {
// Validate the file size.
StorageFile actualFile = actualFilesMap.get(expectedFile.getFilePath());
if (!Objects.equals(actualFile.getFileSizeBytes(), expectedFile.getFileSizeBytes())) {
throw new IllegalStateException(String.format("Specified file size of %d bytes for %s \"%s\" S3 file in \"%s\" storage does not match file size of %d bytes reported by S3.", expectedFile.getFileSizeBytes(), fileDescription, expectedFile.getFilePath(), storageName, actualFile.getFileSizeBytes()));
}
}
}
// Get a list of actual S3 file paths.
List<String> actualFilePaths = new ArrayList<>(actualFilesMap.keySet());
// Get a list of expected file paths.
List<String> expectedFilePaths = getFilePathsFromStorageFiles(expectedStorageFiles);
// Validate that no other files in S3 bucket except for expected files have the same S3 key prefix.
if (!expectedFilePaths.containsAll(actualFilePaths)) {
actualFilePaths.removeAll(expectedFilePaths);
throw new IllegalStateException(String.format("Found unexpected S3 file \"%s\" in \"%s\" storage while validating %s S3 files. Business object data {%s}", actualFilePaths.get(0), storageName, fileDescription, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)));
}
}
use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.
the class SampleDataJmsMessageListener method processMessage.
/**
* Processes a JMS message.
*
* @param payload the message payload
* @param allHeaders the JMS headers
*/
@JmsListener(id = HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE, containerFactory = "jmsListenerContainerFactory", destination = HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE)
public void processMessage(String payload, @Headers Map<Object, Object> allHeaders) {
LOGGER.info("Message received from the JMS queue. jmsQueueName=\"{}\" jmsMessageHeaders=\"{}\" jmsMessagePayload={}", HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE, allHeaders, payload);
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);
long fileSize = s3EventNotification.getRecords().get(0).getS3().getObject().getSizeAsLong();
// parse the objectKey, it should be in the format of namespace/businessObjectDefinitionName/fileName
String[] objectKeyArrays = objectKey.split("/");
Assert.isTrue(objectKeyArrays.length == 3, String.format("S3 notification message %s is not in expected format", objectKey));
String namespace = objectKeyArrays[0];
String businessObjectDefinitionName = objectKeyArrays[1];
String fileName = objectKeyArrays[2];
String path = namespace + "/" + businessObjectDefinitionName + "/";
BusinessObjectDefinitionSampleFileUpdateDto businessObjectDefinitionSampleFileUpdateDto = new BusinessObjectDefinitionSampleFileUpdateDto(path, fileName, fileSize);
String convertedNamespaece = convertS3KeyFormat(namespace);
String convertedBusinessObjectDefinitionName = convertS3KeyFormat(businessObjectDefinitionName);
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(convertedNamespaece, convertedBusinessObjectDefinitionName);
try {
businessObjectDefinitionService.updateBusinessObjectDefinitionEntitySampleFile(businessObjectDefinitionKey, businessObjectDefinitionSampleFileUpdateDto);
} catch (ObjectNotFoundException ex) {
LOGGER.info("Failed to find the business object definition, next try the original namespace and business oject defination name " + ex);
// if Business object definition is not found, use the original name space and bdef name
businessObjectDefinitionKey = new BusinessObjectDefinitionKey(namespace, businessObjectDefinitionName);
businessObjectDefinitionService.updateBusinessObjectDefinitionEntitySampleFile(businessObjectDefinitionKey, businessObjectDefinitionSampleFileUpdateDto);
}
} catch (RuntimeException | IOException e) {
LOGGER.error("Failed to process message from the JMS queue. jmsQueueName=\"{}\" jmsMessagePayload={}", HerdJmsDestinationResolver.SQS_DESTINATION_SAMPLE_DATA_QUEUE, payload, e);
}
}
use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.
the class BusinessObjectFormatServiceTest method testGenerateBusinessObjectFormatDdlInvalidParameters.
@Test
public void testGenerateBusinessObjectFormatDdlInvalidParameters() {
// Prepare test data.
businessObjectFormatServiceTestHelper.createDatabaseEntitiesForBusinessObjectFormatDdlTesting();
BusinessObjectFormatDdlRequest request;
// Try to retrieve business object format ddl using non-existing format.
request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
request.setBusinessObjectDefinitionName("I_DO_NOT_EXIST");
try {
businessObjectFormatService.generateBusinessObjectFormatDdl(request);
fail("Should throw an ObjectNotFoundException when non-existing business object format is used.");
} catch (ObjectNotFoundException e) {
assertEquals(businessObjectFormatServiceTestHelper.getExpectedBusinessObjectFormatNotFoundErrorMessage(request.getNamespace(), request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(), request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion()), e.getMessage());
}
// Try to retrieve business object format ddl using non-existing custom ddl.
request = businessObjectFormatServiceTestHelper.getTestBusinessObjectFormatDdlRequest(CUSTOM_DDL_NAME);
request.setCustomDdlName("I_DO_NOT_EXIST");
try {
businessObjectFormatService.generateBusinessObjectFormatDdl(request);
fail("Should throw an ObjectNotFoundException when non-existing custom ddl is used.");
} catch (ObjectNotFoundException e) {
assertEquals(String.format("Custom DDL with name \"%s\" does not exist for business object format with namespace \"%s\", " + "business object definition name \"%s\", format usage \"%s\", format file type \"%s\", and format version \"%d\".", request.getCustomDdlName(), request.getNamespace(), request.getBusinessObjectDefinitionName(), request.getBusinessObjectFormatUsage(), request.getBusinessObjectFormatFileType(), request.getBusinessObjectFormatVersion()), e.getMessage());
}
}
use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.
the class CustomDdlServiceTest method testUpdateCustomDdlCustomDdlNoExists.
@Test
public void testUpdateCustomDdlCustomDdlNoExists() {
// Try to update a non-existing custom DDL.
try {
customDdlService.updateCustomDdl(new CustomDdlKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, CUSTOM_DDL_NAME), customDdlServiceTestHelper.createCustomDdlUpdateRequest(TEST_DDL));
fail("Should throw an ObjectNotFoundException when custom DDL does not exist.");
} catch (ObjectNotFoundException e) {
assertEquals(String.format("Custom DDL with name \"%s\" does not exist for business object format with namespace \"%s\", " + "business object definition name \"%s\", format usage \"%s\", format file type \"%s\", and format version \"%d\".", CUSTOM_DDL_NAME, NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION), e.getMessage());
}
}
use of org.finra.herd.model.ObjectNotFoundException in project herd by FINRAOS.
the class BusinessObjectDefinitionServiceTest method testDeleteBusinessObjectDefinitionNoExists.
@Test
public void testDeleteBusinessObjectDefinitionNoExists() throws Exception {
// Try to get a non-existing business object definition.
try {
businessObjectDefinitionService.deleteBusinessObjectDefinition(new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME));
fail("Should throw an ObjectNotFoundException when business object definition doesn't exist.");
} catch (ObjectNotFoundException e) {
assertEquals(String.format("Business object definition with name \"%s\" doesn't exist for namespace \"%s\".", BDEF_NAME, NAMESPACE), e.getMessage());
}
}
Aggregations