Search in sources :

Example 26 with BusinessObjectFormatEntity

use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.

the class BusinessObjectDataDaoImpl method getMaximumBusinessObjectDataVersionSubQuery.

/**
 * Creates a sub query for the maximum business object data version.
 *
 * @param builder criteria builder
 * @param criteria criteria query
 * @param businessObjectDataEntity business object data entity
 * @param businessObjectFormatEntity business object format entity
 * @param businessObjectDataStatus business object status
 *
 * @return max business object data version sub query
 */
private Subquery<Integer> getMaximumBusinessObjectDataVersionSubQuery(CriteriaBuilder builder, CriteriaQuery<?> criteria, From<?, BusinessObjectDataEntity> businessObjectDataEntity, From<?, BusinessObjectFormatEntity> businessObjectFormatEntity, String businessObjectDataStatus) {
    Subquery<Integer> subQuery = criteria.subquery(Integer.class);
    // The criteria root is the business object data.
    Root<BusinessObjectDataEntity> subBusinessObjectDataEntity = subQuery.from(BusinessObjectDataEntity.class);
    // Join to the other tables we can filter on.
    Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> subBusinessObjectFormatEntity = subBusinessObjectDataEntity.join(BusinessObjectDataEntity_.businessObjectFormat);
    // Add a standard restriction on business object format.
    Predicate subQueryRestriction = builder.equal(subBusinessObjectFormatEntity, businessObjectFormatEntity);
    // Create and add standard restrictions on primary and sub-partition values.
    subQueryRestriction = builder.and(subQueryRestriction, getQueryRestrictionOnPartitionValues(builder, subBusinessObjectDataEntity, businessObjectDataEntity));
    // If specified, create and add a standard restriction on business object data status.
    if (businessObjectDataStatus != null) {
        Join<BusinessObjectDataEntity, BusinessObjectDataStatusEntity> subBusinessObjectDataStatusEntity = subBusinessObjectDataEntity.join(BusinessObjectDataEntity_.status);
        subQueryRestriction = builder.and(subQueryRestriction, builder.equal(builder.upper(subBusinessObjectDataStatusEntity.get(BusinessObjectDataStatusEntity_.code)), businessObjectDataStatus.toUpperCase()));
    }
    subQuery.select(builder.max(subBusinessObjectDataEntity.get(BusinessObjectDataEntity_.version))).where(subQueryRestriction);
    return subQuery;
}
Also used : BusinessObjectDataStatusEntity(org.finra.herd.model.jpa.BusinessObjectDataStatusEntity) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) Predicate(javax.persistence.criteria.Predicate)

Example 27 with BusinessObjectFormatEntity

use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.

the class BusinessObjectDataDaoImpl method createPartitionValueFilters.

/**
 * Creates a predicate for partition value filters.
 *
 * @param businessDataSearchKey businessDataSearchKey
 * @param businessObjectDataEntity businessObjectDataEntity
 * @param businessObjectFormatEntity businessObjectFormatEntity
 * @param builder builder
 * @param predicatePram predicate parameter
 *
 * @return the predicate
 */
private Predicate createPartitionValueFilters(BusinessObjectDataSearchKey businessDataSearchKey, Root<BusinessObjectDataEntity> businessObjectDataEntity, Join<BusinessObjectDataEntity, BusinessObjectFormatEntity> businessObjectFormatEntity, CriteriaBuilder builder, Predicate predicatePram) {
    Predicate predicate = predicatePram;
    if (businessDataSearchKey.getPartitionValueFilters() != null && !businessDataSearchKey.getPartitionValueFilters().isEmpty()) {
        for (PartitionValueFilter partitionFilter : businessDataSearchKey.getPartitionValueFilters()) {
            Join<BusinessObjectFormatEntity, SchemaColumnEntity> schemaEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.schemaColumns);
            List<String> partitionValues = partitionFilter.getPartitionValues();
            predicate = builder.and(predicate, builder.equal(builder.upper(schemaEntity.get(SchemaColumnEntity_.name)), partitionFilter.getPartitionKey().toUpperCase()));
            predicate = builder.and(predicate, builder.isNotNull(schemaEntity.get(SchemaColumnEntity_.partitionLevel)));
            if (partitionValues != null && !partitionValues.isEmpty()) {
                predicate = builder.and(predicate, builder.or(builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 1), businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue).in(partitionValues)), builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 2), businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue2).in(partitionValues)), builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 3), businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue3).in(partitionValues)), builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 4), businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue4).in(partitionValues)), builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 5), businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue5).in(partitionValues))));
            } else if (partitionFilter.getPartitionValueRange() != null) {
                PartitionValueRange partitionRange = partitionFilter.getPartitionValueRange();
                String startPartitionValue = partitionRange.getStartPartitionValue();
                String endPartitionValue = partitionRange.getEndPartitionValue();
                predicate = builder.and(predicate, builder.or(builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 1), builder.greaterThanOrEqualTo(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue), startPartitionValue), builder.lessThanOrEqualTo(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue), endPartitionValue)), builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 2), builder.greaterThanOrEqualTo(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue2), startPartitionValue), builder.lessThanOrEqualTo(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue2), endPartitionValue)), builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 3), builder.greaterThanOrEqualTo(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue3), startPartitionValue), builder.lessThanOrEqualTo(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue3), endPartitionValue)), builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 4), builder.greaterThanOrEqualTo(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue4), startPartitionValue), builder.lessThanOrEqualTo(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue4), endPartitionValue)), builder.and(builder.equal(schemaEntity.get(SchemaColumnEntity_.partitionLevel), 5), builder.greaterThanOrEqualTo(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue5), startPartitionValue), builder.lessThanOrEqualTo(businessObjectDataEntity.get(BusinessObjectDataEntity_.partitionValue5), endPartitionValue))));
            }
        }
    }
    return predicate;
}
Also used : PartitionValueRange(org.finra.herd.model.api.xml.PartitionValueRange) SchemaColumnEntity(org.finra.herd.model.jpa.SchemaColumnEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) PartitionValueFilter(org.finra.herd.model.api.xml.PartitionValueFilter) Predicate(javax.persistence.criteria.Predicate)

Example 28 with BusinessObjectFormatEntity

use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.

the class SchemaColumnDaoTest method testGetSchemaColumnsWithDescriptiveFormat.

@Test
public void testGetSchemaColumnsWithDescriptiveFormat() {
    // Create a business object definition column key.
    BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME);
    // Create a business object definition entity.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(businessObjectDefinitionKey, DATA_PROVIDER_NAME, BDEF_DESCRIPTION);
    // Create a file type entity.
    FileTypeEntity fileTypeEntity = fileTypeDaoTestHelper.createFileTypeEntity(FORMAT_FILE_TYPE_CODE);
    // Create and persist database entities required for testing.
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(businessObjectDefinitionEntity, FORMAT_USAGE_CODE, fileTypeEntity, INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION, LATEST_VERSION_FLAG_SET, PARTITION_KEY, null, NO_ATTRIBUTES, SCHEMA_DELIMITER_PIPE, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, SCHEMA_NULL_VALUE_BACKSLASH_N, schemaColumnDaoTestHelper.getTestSchemaColumns(), NO_PARTITION_COLUMNS);
    // Update business object definition entity
    businessObjectDefinitionEntity.setDescriptiveBusinessObjectFormat(businessObjectFormatEntity);
    businessObjectDefinitionDao.saveAndRefresh(businessObjectDefinitionEntity);
    // Get a list of schema columns from the business object definition matching to the first column name.
    assertEquals(1, schemaColumnDao.getSchemaColumns(businessObjectDefinitionEntity, FIRST_COLUMN_NAME).size());
    // Get a list of schema columns by passing all case-insensitive parameters in uppercase.
    assertEquals(1, schemaColumnDao.getSchemaColumns(businessObjectDefinitionEntity, FIRST_COLUMN_NAME.toUpperCase()).size());
    // Get business object definition column by passing all case-insensitive parameters in lowercase.
    assertEquals(1, schemaColumnDao.getSchemaColumns(businessObjectDefinitionEntity, FIRST_COLUMN_NAME.toLowerCase()).size());
    // Try invalid values for all input parameters.
    assertEquals(0, schemaColumnDao.getSchemaColumns(businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME_2, DATA_PROVIDER_NAME, DESCRIPTION), FIRST_COLUMN_NAME).size());
    assertEquals(0, schemaColumnDao.getSchemaColumns(businessObjectDefinitionEntity, "I_DO_NOT_EXIST").size());
}
Also used : BusinessObjectDefinitionKey(org.finra.herd.model.api.xml.BusinessObjectDefinitionKey) FileTypeEntity(org.finra.herd.model.jpa.FileTypeEntity) BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) Test(org.junit.Test)

Example 29 with BusinessObjectFormatEntity

use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.

the class BusinessObjectFormatServiceTest method testDeleteBusinessObjectFormatUsedAsDescriptiveFormat.

@Test
public void testDeleteBusinessObjectFormatUsedAsDescriptiveFormat() throws Exception {
    // Create a version of a business object format.
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, FORMAT_DESCRIPTION, LATEST_VERSION_FLAG_SET, PARTITION_KEY, NO_PARTITION_KEY_GROUP);
    // Set this format version as descriptive format on the business object definition.
    businessObjectFormatEntity.getBusinessObjectDefinition().setDescriptiveBusinessObjectFormat(businessObjectFormatEntity);
    businessObjectDefinitionDao.saveAndRefresh(businessObjectFormatEntity.getBusinessObjectDefinition());
    // Validate the existence of the business object format entity.
    assertNotNull(businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION)));
    // Delete the business object format.
    BusinessObjectFormat deletedBusinessObjectFormat = businessObjectFormatService.deleteBusinessObjectFormat(new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION));
    // Validate the returned object.
    businessObjectFormatServiceTestHelper.validateBusinessObjectFormat(businessObjectFormatEntity.getId(), BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, LATEST_VERSION_FLAG_SET, PARTITION_KEY, FORMAT_DESCRIPTION, NO_ATTRIBUTES, NO_ATTRIBUTE_DEFINITIONS, NO_SCHEMA, deletedBusinessObjectFormat);
    // Ensure that this business object format is no longer there.
    assertNull(businessObjectFormatDao.getBusinessObjectFormatByAltKey(new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION)));
}
Also used : BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) DescriptiveBusinessObjectFormat(org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormat) BusinessObjectFormat(org.finra.herd.model.api.xml.BusinessObjectFormat) Test(org.junit.Test)

Example 30 with BusinessObjectFormatEntity

use of org.finra.herd.model.jpa.BusinessObjectFormatEntity in project herd by FINRAOS.

the class BusinessObjectFormatServiceTest method testGetBusinessObjectFormatMissingOptionalParameters.

@Test
public void testGetBusinessObjectFormatMissingOptionalParameters() {
    // Create and persist a business object definition.
    businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION);
    // Create and persist a valid business object format.
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, FORMAT_DESCRIPTION, LATEST_VERSION_FLAG_SET, PARTITION_KEY);
    // Perform a get without specifying business object format version (passed as a null value) and namespace code.
    // Please note that HerdDaoTest.testGetBusinessObjectFormatByAltKeyFormatVersionNotSpecified
    // already validates the SQl select logic, so we do not have to go over it here.
    BusinessObjectFormat resultBusinessObjectFormat = businessObjectFormatService.getBusinessObjectFormat(new BusinessObjectFormatKey(NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, NO_FORMAT_VERSION));
    // Validate the returned object.
    businessObjectFormatServiceTestHelper.validateBusinessObjectFormat(businessObjectFormatEntity.getId(), NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, LATEST_VERSION_FLAG_SET, PARTITION_KEY, FORMAT_DESCRIPTION, NO_ATTRIBUTES, NO_ATTRIBUTE_DEFINITIONS, NO_SCHEMA, resultBusinessObjectFormat);
}
Also used : BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) DescriptiveBusinessObjectFormat(org.finra.herd.model.api.xml.DescriptiveBusinessObjectFormat) BusinessObjectFormat(org.finra.herd.model.api.xml.BusinessObjectFormat) Test(org.junit.Test)

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