use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class RelationalTableRegistrationServiceTest method testCreateRelationalTableRegistrationWithAppendToExistingBusinessObjectDefinitionSetToTrue.
@Test
public void testCreateRelationalTableRegistrationWithAppendToExistingBusinessObjectDefinitionSetToTrue() {
// Create an existing business object definition.
BusinessObjectDefinitionEntity existingBusinessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, DESCRIPTION, BDEF_DISPLAY_NAME, new ArrayList<>());
// Create database entities required for relational table registration testing.
relationalTableRegistrationServiceTestHelper.createDatabaseEntitiesForRelationalTableRegistrationTesting(STORAGE_NAME);
// Pick one of the in-memory database tables to be registered as a relational table.
String relationalSchemaName = "PUBLIC";
String relationalTableName = BusinessObjectDefinitionEntity.TABLE_NAME.toUpperCase();
// Create a relational table registration create request for a table that is part of the in-memory database setup as part of DAO mocks.
RelationalTableRegistrationCreateRequest relationalTableRegistrationCreateRequest = new RelationalTableRegistrationCreateRequest(BDEF_NAMESPACE, BDEF_NAME, BDEF_DISPLAY_NAME, FORMAT_USAGE_CODE, DATA_PROVIDER_NAME, relationalSchemaName, relationalTableName, STORAGE_NAME);
// Create a relational table registration.
BusinessObjectData businessObjectData = relationalTableRegistrationService.createRelationalTableRegistration(relationalTableRegistrationCreateRequest, APPEND_TO_EXISTING_BUSINESS_OBJECT_DEFINTION_TRUE);
// Create an expected storage unit.
StorageUnit expectedStorageUnit = new StorageUnit();
expectedStorageUnit.setStorage(new Storage(STORAGE_NAME, StoragePlatformEntity.RELATIONAL, relationalTableRegistrationServiceTestHelper.getStorageAttributes()));
expectedStorageUnit.setStorageUnitStatus(StorageUnitStatusEntity.ENABLED);
// Create an expected business object data.
BusinessObjectData expectedBusinessObjectData = new BusinessObjectData();
expectedBusinessObjectData.setId(businessObjectData.getId());
expectedBusinessObjectData.setNamespace(BDEF_NAMESPACE);
expectedBusinessObjectData.setBusinessObjectDefinitionName(BDEF_NAME);
expectedBusinessObjectData.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE);
expectedBusinessObjectData.setBusinessObjectFormatFileType(FileTypeEntity.RELATIONAL_TABLE_FILE_TYPE);
expectedBusinessObjectData.setBusinessObjectFormatVersion(INITIAL_FORMAT_VERSION);
expectedBusinessObjectData.setPartitionValue(BusinessObjectDataServiceImpl.NO_PARTITIONING_PARTITION_VALUE);
expectedBusinessObjectData.setSubPartitionValues(new ArrayList<>());
expectedBusinessObjectData.setVersion(INITIAL_DATA_VERSION);
expectedBusinessObjectData.setPartitionKey(BusinessObjectDataServiceImpl.NO_PARTITIONING_PARTITION_KEY);
expectedBusinessObjectData.setLatestVersion(LATEST_VERSION_FLAG_SET);
expectedBusinessObjectData.setStatus(BusinessObjectDataStatusEntity.VALID);
expectedBusinessObjectData.setStorageUnits(Collections.singletonList(expectedStorageUnit));
expectedBusinessObjectData.setAttributes(new ArrayList<>());
expectedBusinessObjectData.setBusinessObjectDataParents(new ArrayList<>());
expectedBusinessObjectData.setBusinessObjectDataChildren(new ArrayList<>());
// Validate the response.
assertEquals(expectedBusinessObjectData, businessObjectData);
// Create a business object format key.
BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.RELATIONAL_TABLE_FILE_TYPE, INITIAL_FORMAT_VERSION);
// Retrieve business object format that was created as part of the relational table registration.
BusinessObjectFormat businessObjectFormat = businessObjectFormatService.getBusinessObjectFormat(businessObjectFormatKey);
// Create an expected schema.
Schema expectedSchema = new Schema();
expectedSchema.setColumns(relationalTableRegistrationServiceTestHelper.getExpectedSchemaColumns());
expectedSchema.setNullValue(EMPTY_STRING);
// Build an expected business object format.
BusinessObjectFormat expectedBusinessObjectFormat = new BusinessObjectFormat();
expectedBusinessObjectFormat.setId(businessObjectFormat.getId());
expectedBusinessObjectFormat.setNamespace(BDEF_NAMESPACE);
expectedBusinessObjectFormat.setBusinessObjectDefinitionName(BDEF_NAME);
expectedBusinessObjectFormat.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE);
expectedBusinessObjectFormat.setBusinessObjectFormatFileType(FileTypeEntity.RELATIONAL_TABLE_FILE_TYPE);
expectedBusinessObjectFormat.setBusinessObjectFormatVersion(INITIAL_FORMAT_VERSION);
expectedBusinessObjectFormat.setLatestVersion(LATEST_VERSION_FLAG_SET);
expectedBusinessObjectFormat.setPartitionKey(BusinessObjectDataServiceImpl.NO_PARTITIONING_PARTITION_KEY);
expectedBusinessObjectFormat.setBusinessObjectFormatParents(new ArrayList<>());
expectedBusinessObjectFormat.setBusinessObjectFormatChildren(new ArrayList<>());
expectedBusinessObjectFormat.setAttributeDefinitions(new ArrayList<>());
expectedBusinessObjectFormat.setAttributes(Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_FORMAT_ATTRIBUTE_NAME_RELATIONAL_SCHEMA_NAME), relationalSchemaName), new Attribute(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_FORMAT_ATTRIBUTE_NAME_RELATIONAL_TABLE_NAME), relationalTableName)));
expectedBusinessObjectFormat.setSchema(expectedSchema);
// Validate the newly created business object format.
assertEquals(expectedBusinessObjectFormat, businessObjectFormat);
// Create a business object definition key.
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME);
// Retrieve business object definition that was created as part of the relational table registration.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDao.getBusinessObjectDefinitionByKey(businessObjectDefinitionKey);
// Validate the newly created business object definition.
assertEquals(existingBusinessObjectDefinitionEntity, businessObjectDefinitionEntity);
}
use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class BusinessObjectDataInvalidateUnregisteredHelper method getResponseBusinessObjectDatas.
/**
* Constructs the response business object data from the given list of entities.
*
* @param registeredBusinessObjectDataEntities list of {@link BusinessObjectDataEntity}
*
* @return list of {@link BusinessObjectData} to be included in the response
*/
private List<BusinessObjectData> getResponseBusinessObjectDatas(List<BusinessObjectDataEntity> registeredBusinessObjectDataEntities) {
List<BusinessObjectData> responseBusinessObjectDatas = new ArrayList<>();
for (BusinessObjectDataEntity businessObjectDataEntity : registeredBusinessObjectDataEntities) {
BusinessObjectData responseBusinessObjectData = businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity);
responseBusinessObjectDatas.add(responseBusinessObjectData);
}
return responseBusinessObjectDatas;
}
use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class BusinessObjectDataInitiateDestroyHelperServiceImpl method executeInitiateDestroyAfterStepImpl.
/**
* Executes an after step for initiation of a business object data destroy. This method also updates business object data destroy DTO passed as a
* parameter.
*
* @param businessObjectDataDestroyDto the DTO that holds various parameters needed to initiate a business object data destroy
*
* @return the business object data information
*/
protected BusinessObjectData executeInitiateDestroyAfterStepImpl(BusinessObjectDataDestroyDto businessObjectDataDestroyDto) {
// Get the business object data key.
BusinessObjectDataKey businessObjectDataKey = businessObjectDataDestroyDto.getBusinessObjectDataKey();
// Retrieve the business object data and ensure it exists.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey);
// Retrieve storage unit and ensure it exists.
StorageUnitEntity storageUnitEntity = storageUnitDaoHelper.getStorageUnitEntity(businessObjectDataDestroyDto.getStorageName(), businessObjectDataEntity);
// Validate that storage unit status is DISABLING.
if (!StorageUnitStatusEntity.DISABLING.equals(storageUnitEntity.getStatus().getCode())) {
throw new IllegalArgumentException(String.format("Storage unit status is \"%s\", but must be \"%s\". Storage: {%s}, business object data: {%s}", storageUnitEntity.getStatus().getCode(), StorageUnitStatusEntity.DISABLING, businessObjectDataDestroyDto.getStorageName(), businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)));
}
// Set timestamp of when it is OK to finalize deletion of the business object data.
Timestamp currentTime = new Timestamp(System.currentTimeMillis());
storageUnitEntity.setFinalDestroyOn(HerdDateUtils.addDays(currentTime, businessObjectDataDestroyDto.getFinalDestroyInDays()));
// Change the storage unit status to DISABLED and update the DTO.
String reason = StorageUnitStatusEntity.DISABLED;
businessObjectDataDestroyDto.setOldStorageUnitStatus(storageUnitEntity.getStatus().getCode());
storageUnitDaoHelper.updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.DISABLED, reason);
businessObjectDataDestroyDto.setNewStorageUnitStatus(storageUnitEntity.getStatus().getCode());
// Create and return the business object data object from the entity.
BusinessObjectData businessObjectData = businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity);
// Return the business object data information.
return businessObjectData;
}
use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class BusinessObjectDataInvalidateUnregisteredHelperTest method testInvalidateUnregisteredBusinessObjectDataS32Herd1.
/**
* Test case where S3 has 2 objects, and herd has 1 object registered. Expects one new registration in INVALID status.
*/
@Test
public void testInvalidateUnregisteredBusinessObjectDataS32Herd1() throws Exception {
BusinessObjectDataInvalidateUnregisteredRequest request = new BusinessObjectDataInvalidateUnregisteredRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, StorageEntity.MANAGED_STORAGE);
// Given a business object format
// Given 1 business object data registered
// Given 2 S3 objects
BusinessObjectFormatEntity businessObjectFormatEntity;
try {
businessObjectFormatEntity = businessObjectFormatServiceTestHelper.createBusinessObjectFormat(request);
createBusinessObjectDataEntityFromBusinessObjectDataInvalidateUnregisteredRequest(businessObjectFormatEntity, request, 0, true);
businessObjectDataServiceTestHelper.createS3Object(businessObjectFormatEntity, request, 0);
businessObjectDataServiceTestHelper.createS3Object(businessObjectFormatEntity, request, 1);
} catch (Exception e) {
throw new IllegalArgumentException("Test failed during setup. Most likely setup or developer error.", e);
}
// Call API
BusinessObjectDataInvalidateUnregisteredResponse actualResponse = businessObjectDataInvalidateUnregisteredHelper.invalidateUnregisteredBusinessObjectData(request);
// Make assertions
Assert.assertNotNull("response business object datas is null", actualResponse.getRegisteredBusinessObjectDataList());
Assert.assertEquals("response business object datas size", 1, actualResponse.getRegisteredBusinessObjectDataList().size());
{
BusinessObjectData businessObjectData = actualResponse.getRegisteredBusinessObjectDataList().get(0);
Assert.assertEquals("response business object data[0] version", 1, businessObjectData.getVersion());
Assert.assertEquals("response business object data[0] status", BusinessObjectDataInvalidateUnregisteredHelper.UNREGISTERED_STATUS, businessObjectData.getStatus());
Assert.assertNotNull("response business object data[0] storage units is null", businessObjectData.getStorageUnits());
Assert.assertEquals("response business object data[0] storage units size", 1, businessObjectData.getStorageUnits().size());
{
String expectedS3KeyPrefix = s3KeyPrefixHelper.buildS3KeyPrefix(S3_KEY_PREFIX_VELOCITY_TEMPLATE, businessObjectFormatEntity, businessObjectDataHelper.createBusinessObjectDataKey(businessObjectData), STORAGE_NAME);
StorageUnit storageUnit = businessObjectData.getStorageUnits().get(0);
Assert.assertNotNull("response business object data[0] storage unit[0] storage directory is null", storageUnit.getStorageDirectory());
Assert.assertEquals("response business object data[0] storage unit[0] storage directory path", expectedS3KeyPrefix, storageUnit.getStorageDirectory().getDirectoryPath());
}
}
}
use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class BusinessObjectDataInvalidateUnregisteredHelperTest method testInvalidateUnregisteredBusinessObjectDataS32Herd0.
/**
* Test case where S3 has 2 objects, but herd has no object registered. Expects 2 new registrations in INVALID status.
*/
@Test
public void testInvalidateUnregisteredBusinessObjectDataS32Herd0() throws Exception {
BusinessObjectDataInvalidateUnregisteredRequest request = new BusinessObjectDataInvalidateUnregisteredRequest(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, StorageEntity.MANAGED_STORAGE);
// Given a business object format
// Given 1 business object data registered
// Given 2 S3 objects
BusinessObjectFormatEntity businessObjectFormatEntity;
try {
businessObjectFormatEntity = businessObjectFormatServiceTestHelper.createBusinessObjectFormat(request);
businessObjectDataServiceTestHelper.createS3Object(businessObjectFormatEntity, request, 0);
businessObjectDataServiceTestHelper.createS3Object(businessObjectFormatEntity, request, 1);
} catch (Exception e) {
throw new IllegalArgumentException("Test failed during setup. Most likely setup or developer error.", e);
}
// Call API
BusinessObjectDataInvalidateUnregisteredResponse actualResponse = businessObjectDataInvalidateUnregisteredHelper.invalidateUnregisteredBusinessObjectData(request);
// Make assertions
Assert.assertNotNull("response business object datas is null", actualResponse.getRegisteredBusinessObjectDataList());
Assert.assertEquals("response business object datas size", 2, actualResponse.getRegisteredBusinessObjectDataList().size());
// Assert first data registered
{
BusinessObjectData businessObjectData = actualResponse.getRegisteredBusinessObjectDataList().get(0);
Assert.assertEquals("response business object data[0] version", 0, businessObjectData.getVersion());
Assert.assertEquals("response business object data[0] status", BusinessObjectDataInvalidateUnregisteredHelper.UNREGISTERED_STATUS, businessObjectData.getStatus());
Assert.assertNotNull("response business object data[0] storage units is null", businessObjectData.getStorageUnits());
Assert.assertEquals("response business object data[0] storage units size", 1, businessObjectData.getStorageUnits().size());
{
String expectedS3KeyPrefix = s3KeyPrefixHelper.buildS3KeyPrefix(S3_KEY_PREFIX_VELOCITY_TEMPLATE, businessObjectFormatEntity, businessObjectDataHelper.createBusinessObjectDataKey(businessObjectData), STORAGE_NAME);
StorageUnit storageUnit = businessObjectData.getStorageUnits().get(0);
Assert.assertNotNull("response business object data[0] storage unit[0] storage directory is null", storageUnit.getStorageDirectory());
Assert.assertEquals("response business object data[0] storage unit[0] storage directory path", expectedS3KeyPrefix, storageUnit.getStorageDirectory().getDirectoryPath());
}
}
// Assert second data registered
{
BusinessObjectData businessObjectData = actualResponse.getRegisteredBusinessObjectDataList().get(1);
Assert.assertEquals("response business object data[1] version", 1, businessObjectData.getVersion());
Assert.assertEquals("response business object data[1] status", BusinessObjectDataInvalidateUnregisteredHelper.UNREGISTERED_STATUS, businessObjectData.getStatus());
Assert.assertNotNull("response business object data[1] storage units is null", businessObjectData.getStorageUnits());
Assert.assertEquals("response business object data[1] storage units size", 1, businessObjectData.getStorageUnits().size());
{
String expectedS3KeyPrefix = s3KeyPrefixHelper.buildS3KeyPrefix(S3_KEY_PREFIX_VELOCITY_TEMPLATE, businessObjectFormatEntity, businessObjectDataHelper.createBusinessObjectDataKey(businessObjectData), STORAGE_NAME);
StorageUnit storageUnit = businessObjectData.getStorageUnits().get(0);
Assert.assertNotNull("response business object data[1] storage unit[0] storage directory is null", storageUnit.getStorageDirectory());
Assert.assertEquals("response business object data[1] storage unit[0] storage directory path", expectedS3KeyPrefix, storageUnit.getStorageDirectory().getDirectoryPath());
}
}
}
Aggregations