use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class BusinessObjectDataDaoTestHelper method createBusinessObjectDataEntity.
/**
* Creates and persists a new business object data entity.
*
* @return the newly created business object data entity.
*/
public BusinessObjectDataEntity createBusinessObjectDataEntity(String namespaceCode, String businessObjectDefinitionName, String businessObjectFormatUsage, String businessObjectFormatFileType, Integer businessObjectFormatVersion, String businessObjectDataPartitionValue, List<String> businessObjectDataSubPartitionValues, Integer businessObjectDataVersion, Boolean businessObjectDataLatestVersion, String businessObjectDataStatusCode) {
// Create a business object format entity if it does not exist.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(namespaceCode, businessObjectDefinitionName, businessObjectFormatUsage, businessObjectFormatFileType, businessObjectFormatVersion));
if (businessObjectFormatEntity == null) {
businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(namespaceCode, businessObjectDefinitionName, businessObjectFormatUsage, businessObjectFormatFileType, businessObjectFormatVersion, AbstractDaoTest.FORMAT_DESCRIPTION, true, AbstractDaoTest.PARTITION_KEY);
}
// Create a business object data status entity if it does not exist.
BusinessObjectDataStatusEntity businessObjectDataStatusEntity = businessObjectDataStatusDao.getBusinessObjectDataStatusByCode(businessObjectDataStatusCode);
if (businessObjectDataStatusEntity == null) {
businessObjectDataStatusEntity = businessObjectDataStatusDaoTestHelper.createBusinessObjectDataStatusEntity(businessObjectDataStatusCode);
}
return createBusinessObjectDataEntity(businessObjectFormatEntity, businessObjectDataPartitionValue, businessObjectDataSubPartitionValues, businessObjectDataVersion, businessObjectDataLatestVersion, businessObjectDataStatusEntity);
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class BusinessObjectFormatDaoTest method testGetBusinessObjectFormatByAltKeyAllParamsSpecified.
@Test
public void testGetBusinessObjectFormatByAltKeyAllParamsSpecified() {
// Create relative database entities.
businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION);
fileTypeDaoTestHelper.createFileTypeEntity(FORMAT_FILE_TYPE_CODE, "Description of " + FORMAT_FILE_TYPE_CODE);
businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, 0, "Test format 0", false, PARTITION_KEY);
businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, 1, "Test format 1", true, PARTITION_KEY);
businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, 2, "Test format 2", false, PARTITION_KEY);
for (int businessObjectFormatVersion = 0; businessObjectFormatVersion < 3; businessObjectFormatVersion++) {
// Retrieve business object format entity by specifying values for all alternate key fields.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, businessObjectFormatVersion));
// Validate the results.
assertNotNull(businessObjectFormatEntity);
assertTrue(businessObjectFormatEntity.getBusinessObjectDefinition().getName().equals(BDEF_NAME));
assertTrue(businessObjectFormatEntity.getUsage().equals(FORMAT_USAGE_CODE));
assertTrue(businessObjectFormatEntity.getFileType().getCode().equals(FORMAT_FILE_TYPE_CODE));
assertTrue(businessObjectFormatEntity.getBusinessObjectFormatVersion() == businessObjectFormatVersion);
assertTrue(businessObjectFormatEntity.getLatestVersion() == (businessObjectFormatVersion == 1));
assertTrue(businessObjectFormatEntity.getPartitionKey().equals(PARTITION_KEY));
assertTrue(businessObjectFormatEntity.getDescription().equals(String.format("Test format %d", businessObjectFormatVersion)));
}
// Try invalid values for all input parameters.
assertNull(businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey("I_DO_NOT_EXIST", BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, 0)));
assertNull(businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(NAMESPACE, "I_DO_NOT_EXIST", FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, 0)));
assertNull(businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, "I_DO_NOT_EXIST", FORMAT_FILE_TYPE_CODE, 0)));
assertNull(businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, "I_DO_NOT_EXIST", 0)));
assertNull(businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, 4)));
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class BusinessObjectFormatDaoTest method testGetBusinessObjectFormatByAltKeyFormatVersionNotSpecified.
@Test
public void testGetBusinessObjectFormatByAltKeyFormatVersionNotSpecified() {
// Create relative database entities.
businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION);
fileTypeDaoTestHelper.createFileTypeEntity(FORMAT_FILE_TYPE_CODE, "Description of " + FORMAT_FILE_TYPE_CODE);
businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, 0, "Test format 0", false, PARTITION_KEY);
businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, 1, "Test format 1", true, PARTITION_KEY);
businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, 2, "Test format 2", false, PARTITION_KEY);
// Retrieve business object format entity by specifying all values for the alternate key fields except for the format version.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, null));
// Validate the results.
assertNotNull(businessObjectFormatEntity);
assertTrue(businessObjectFormatEntity.getBusinessObjectDefinition().getName().equals(BDEF_NAME));
assertTrue(businessObjectFormatEntity.getUsage().equals(FORMAT_USAGE_CODE));
assertTrue(businessObjectFormatEntity.getFileType().getCode().equals(FORMAT_FILE_TYPE_CODE));
assertTrue(businessObjectFormatEntity.getBusinessObjectFormatVersion() == 1);
assertTrue(businessObjectFormatEntity.getLatestVersion());
assertTrue(businessObjectFormatEntity.getPartitionKey().equals(PARTITION_KEY));
assertTrue(businessObjectFormatEntity.getDescription().equals(String.format("Test format 1")));
// Let add a second LATEST format version.
businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, 3, "Test format 3", true, PARTITION_KEY);
try {
// Now we should get an exception, since there are more than one format with the Latest Version flag set to TRUE.
businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, null));
fail("Should throw an IllegalArgumentException if finds more than one business object format marked as latest.");
} catch (IllegalArgumentException e) {
assertTrue(e.getMessage().startsWith("Found more than one business object format"));
}
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class BusinessObjectFormatDaoTest method testGetBusinessObjectFormatEntitiesByBusinessObjectDefinition.
@Test
public void testGetBusinessObjectFormatEntitiesByBusinessObjectDefinition() {
// Create relative database entities.
businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE.toLowerCase(), BDEF_NAME.toLowerCase(), DATA_PROVIDER_NAME.toLowerCase(), BDEF_DESCRIPTION);
fileTypeDaoTestHelper.createFileTypeEntity(FORMAT_FILE_TYPE_CODE.toLowerCase(), "Description of " + FORMAT_FILE_TYPE_CODE);
businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE_2.toLowerCase(), BDEF_NAME_2.toLowerCase(), DATA_PROVIDER_NAME_2.toLowerCase(), BDEF_DESCRIPTION_2);
businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE_2, BDEF_NAME_2.toLowerCase(), FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE.toLowerCase(), INITIAL_FORMAT_VERSION, "Test format 0", Boolean.FALSE, PARTITION_KEY);
BusinessObjectFormatEntity businessObjectFormatEntityV0 = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME.toLowerCase(), FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE.toLowerCase(), INITIAL_FORMAT_VERSION, "Test format 0", Boolean.FALSE, PARTITION_KEY);
BusinessObjectFormatEntity businessObjectFormatEntityV1 = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME.toLowerCase(), FORMAT_USAGE_CODE.toLowerCase(), FORMAT_FILE_TYPE_CODE.toLowerCase(), SECOND_FORMAT_VERSION, "Test format 0", Boolean.TRUE, PARTITION_KEY);
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(NAMESPACE, BDEF_NAME);
// Retrieve business object format entity by specifying values for all text alternate key fields in upper case.
List<BusinessObjectFormatEntity> businessObjectFormatList = businessObjectFormatDao.getLatestVersionBusinessObjectFormatsByBusinessObjectDefinition(businessObjectDefinitionKey);
assertEquals(businessObjectFormatList.size(), 1);
assertEquals(businessObjectFormatList.get(0), businessObjectFormatEntityV1);
}
use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.
the class BusinessObjectFormatDaoTestHelper method createBusinessObjectFormatEntity.
/**
* Creates and persists a new business object format entity.
*
* @return the newly created business object format entity.
*/
public BusinessObjectFormatEntity createBusinessObjectFormatEntity(BusinessObjectDefinitionEntity businessObjectDefinitionEntity, String businessObjectFormatUsage, FileTypeEntity fileTypeEntity, Integer businessObjectFormatVersion, String businessObjectFormatDescription, Boolean businessObjectFormatLatestVersion, String businessObjectFormatPartitionKey, PartitionKeyGroupEntity partitionKeyGroupEntity, List<Attribute> attributes, String schemaDelimiterCharacter, String schemaEscapeCharacter, String schemaNullValue, List<SchemaColumn> schemaColumns, List<SchemaColumn> partitionColumns) {
BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
businessObjectFormatEntity.setBusinessObjectDefinition(businessObjectDefinitionEntity);
businessObjectFormatEntity.setDescription(businessObjectFormatDescription);
businessObjectFormatEntity.setFileType(fileTypeEntity);
businessObjectFormatEntity.setBusinessObjectFormatVersion(businessObjectFormatVersion);
businessObjectFormatEntity.setLatestVersion(businessObjectFormatLatestVersion);
businessObjectFormatEntity.setUsage(businessObjectFormatUsage);
businessObjectFormatEntity.setPartitionKey(businessObjectFormatPartitionKey);
businessObjectFormatEntity.setPartitionKeyGroup(partitionKeyGroupEntity);
// Create the attributes if they are specified.
if (!CollectionUtils.isEmpty(attributes)) {
List<BusinessObjectFormatAttributeEntity> attributeEntities = new ArrayList<>();
businessObjectFormatEntity.setAttributes(attributeEntities);
for (Attribute attribute : attributes) {
BusinessObjectFormatAttributeEntity attributeEntity = new BusinessObjectFormatAttributeEntity();
attributeEntities.add(attributeEntity);
attributeEntity.setBusinessObjectFormat(businessObjectFormatEntity);
attributeEntity.setName(attribute.getName());
attributeEntity.setValue(attribute.getValue());
}
}
if (schemaColumns != null && !schemaColumns.isEmpty()) {
businessObjectFormatEntity.setDelimiter(schemaDelimiterCharacter);
businessObjectFormatEntity.setEscapeCharacter(schemaEscapeCharacter);
businessObjectFormatEntity.setNullValue(schemaNullValue);
List<SchemaColumnEntity> schemaColumnEntities = new ArrayList<>();
businessObjectFormatEntity.setSchemaColumns(schemaColumnEntities);
int columnPosition = 1;
for (SchemaColumn schemaColumn : schemaColumns) {
SchemaColumnEntity schemaColumnEntity = new SchemaColumnEntity();
schemaColumnEntities.add(schemaColumnEntity);
schemaColumnEntity.setBusinessObjectFormat(businessObjectFormatEntity);
schemaColumnEntity.setPosition(columnPosition);
schemaColumnEntity.setPartitionLevel(null);
schemaColumnEntity.setName(schemaColumn.getName());
schemaColumnEntity.setType(schemaColumn.getType());
schemaColumnEntity.setSize(schemaColumn.getSize());
schemaColumnEntity.setDescription(schemaColumn.getDescription());
schemaColumnEntity.setRequired(schemaColumn.isRequired());
schemaColumnEntity.setDefaultValue(schemaColumn.getDefaultValue());
columnPosition++;
}
if (partitionColumns != null && !partitionColumns.isEmpty()) {
int partitionLevel = 1;
for (SchemaColumn schemaColumn : partitionColumns) {
// Check if this partition column belongs to the list of regular schema columns.
int schemaColumnIndex = schemaColumns.indexOf(schemaColumn);
if (schemaColumnIndex >= 0) {
// Retrieve the relative column entity and set its partition level.
schemaColumnEntities.get(schemaColumnIndex).setPartitionLevel(partitionLevel);
} else {
// Add this partition column as a new schema column entity.
SchemaColumnEntity schemaColumnEntity = new SchemaColumnEntity();
schemaColumnEntities.add(schemaColumnEntity);
schemaColumnEntity.setBusinessObjectFormat(businessObjectFormatEntity);
schemaColumnEntity.setPosition(null);
schemaColumnEntity.setPartitionLevel(partitionLevel);
schemaColumnEntity.setName(schemaColumn.getName());
schemaColumnEntity.setType(schemaColumn.getType());
schemaColumnEntity.setSize(schemaColumn.getSize());
schemaColumnEntity.setDescription(schemaColumn.getDescription());
schemaColumnEntity.setRequired(schemaColumn.isRequired());
schemaColumnEntity.setDefaultValue(schemaColumn.getDefaultValue());
}
partitionLevel++;
}
}
}
return businessObjectFormatDao.saveAndRefresh(businessObjectFormatEntity);
}
Aggregations