Search in sources :

Example 86 with BusinessObjectFormatEntity

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);
}
Also used : BusinessObjectDataStatusEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusEntity) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity)

Example 87 with BusinessObjectFormatEntity

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)));
}
Also used : BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) Test(org.junit.Test)

Example 88 with BusinessObjectFormatEntity

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"));
    }
}
Also used : BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) Test(org.junit.Test)

Example 89 with BusinessObjectFormatEntity

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);
}
Also used : BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) Test(org.junit.Test)

Example 90 with BusinessObjectFormatEntity

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);
}
Also used : Attribute(org.finra.herd.model.api.xml.Attribute) SchemaColumnEntity(org.finra.herd.model.jpa.SchemaColumnEntity) ArrayList(java.util.ArrayList) SchemaColumn(org.finra.herd.model.api.xml.SchemaColumn) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) BusinessObjectFormatAttributeEntity(org.finra.herd.model.jpa.BusinessObjectFormatAttributeEntity)

Aggregations

BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)181 Test (org.junit.Test)100 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)72 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)53 ArrayList (java.util.ArrayList)43 StorageEntity (org.finra.herd.model.jpa.StorageEntity)37 BusinessObjectFormat (org.finra.herd.model.api.xml.BusinessObjectFormat)32 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)32 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)28 Predicate (javax.persistence.criteria.Predicate)25 DescriptiveBusinessObjectFormat (org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormat)25 FileTypeEntity (org.finra.herd.model.jpa.FileTypeEntity)25 BusinessObjectDefinitionColumnKey (org.finra.herd.model.api.xml.BusinessObjectDefinitionColumnKey)23 Attribute (org.finra.herd.model.api.xml.Attribute)22 StorageUnitEntity (org.finra.herd.model.jpa.StorageUnitEntity)22 BusinessObjectDefinitionColumn (org.finra.herd.model.api.xml.BusinessObjectDefinitionColumn)20 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)20 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)19 SchemaColumn (org.finra.herd.model.api.xml.SchemaColumn)18 BusinessObjectDefinitionColumnEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionColumnEntity)18