Search in sources :

Example 1 with PartitionKeyGroupEntity

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

the class JsonHelperTest method testObjectToJsonValidateJsonIgnoreOnExpectedPartitionValues.

@Test
public void testObjectToJsonValidateJsonIgnoreOnExpectedPartitionValues() {
    // Create a business object definition entity.
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoTestHelper.createBusinessObjectDefinitionEntity(BDEF_NAMESPACE, BDEF_NAME, DATA_PROVIDER_NAME, BDEF_DESCRIPTION, NO_ATTRIBUTES);
    // Create a partition key group entity.
    PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP);
    // Create a list of expected partition values.
    expectedPartitionValueDaoTestHelper.createExpectedPartitionValueEntities(partitionKeyGroupEntity, Arrays.asList(PARTITION_VALUE, PARTITION_VALUE_2, PARTITION_VALUE_3));
    // Create a business object format entity.
    businessObjectFormatDaoTestHelper.createBusinessObjectFormatEntity(businessObjectDefinitionEntity, FORMAT_USAGE_CODE, fileTypeDaoTestHelper.createFileTypeEntity(FORMAT_FILE_TYPE_CODE, null), FORMAT_VERSION, FORMAT_DESCRIPTION, LATEST_VERSION_FLAG_SET, PARTITION_KEY, partitionKeyGroupEntity, NO_ATTRIBUTES, SCHEMA_DELIMITER_COMMA, SCHEMA_ESCAPE_CHARACTER_BACKSLASH, SCHEMA_NULL_VALUE_BACKSLASH_N, NO_COLUMNS, NO_PARTITION_COLUMNS);
    // Create a JSON object from the business object definition entity.
    String result = jsonHelper.objectToJson(businessObjectDefinitionEntity);
    // Validate the results.
    assertNotNull(result);
    assertTrue(result.contains("partitionKeyGroup"));
    assertFalse(result.contains("expectedPartitionValues"));
    assertFalse(result.contains(PARTITION_VALUE));
    assertFalse(result.contains(PARTITION_VALUE_2));
    assertFalse(result.contains(PARTITION_VALUE_3));
}
Also used : BusinessObjectDefinitionEntity(org.finra.herd.model.jpa.BusinessObjectDefinitionEntity) PartitionKeyGroupEntity(org.finra.herd.model.jpa.PartitionKeyGroupEntity) Test(org.junit.Test) AbstractDaoTest(org.finra.herd.dao.AbstractDaoTest)

Example 2 with PartitionKeyGroupEntity

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

the class PartitionKeyGroupServiceImpl method deletePartitionKeyGroup.

/**
 * Deletes an existing partition key group by key.
 *
 * @param partitionKeyGroupKey the partition key group key
 *
 * @return the partition key group that got deleted
 */
@Override
public PartitionKeyGroup deletePartitionKeyGroup(PartitionKeyGroupKey partitionKeyGroupKey) {
    // Perform validation and trim.
    partitionKeyGroupHelper.validatePartitionKeyGroupKey(partitionKeyGroupKey);
    // Retrieve and ensure that a partition key group already exists with the specified name.
    PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDaoHelper.getPartitionKeyGroupEntity(partitionKeyGroupKey);
    // Check if we are allowed to delete this business object format.
    if (businessObjectFormatDao.getBusinessObjectFormatCount(partitionKeyGroupEntity) > 0L) {
        throw new IllegalArgumentException(String.format("Can not delete \"%s\" partition key group since it is being used by a business object format.", partitionKeyGroupKey.getPartitionKeyGroupName()));
    }
    // Delete the partition key group.
    partitionKeyGroupDao.delete(partitionKeyGroupEntity);
    // Create and return the partition key group object from the deleted entity.
    return createPartitionKeyGroupFromEntity(partitionKeyGroupEntity);
}
Also used : PartitionKeyGroupEntity(org.finra.herd.model.jpa.PartitionKeyGroupEntity)

Example 3 with PartitionKeyGroupEntity

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

the class PartitionKeyGroupServiceImpl method getPartitionKeyGroup.

/**
 * Gets an existing partition key group by key.
 *
 * @param partitionKeyGroupKey the partition key group key
 *
 * @return the partition key group information
 */
@Override
public PartitionKeyGroup getPartitionKeyGroup(PartitionKeyGroupKey partitionKeyGroupKey) {
    // Perform validation and trim.
    partitionKeyGroupHelper.validatePartitionKeyGroupKey(partitionKeyGroupKey);
    // Retrieve and ensure that a partition key group exists with the specified name.
    PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDaoHelper.getPartitionKeyGroupEntity(partitionKeyGroupKey);
    // Create and return the partition key group object from the persisted entity.
    return createPartitionKeyGroupFromEntity(partitionKeyGroupEntity);
}
Also used : PartitionKeyGroupEntity(org.finra.herd.model.jpa.PartitionKeyGroupEntity)

Example 4 with PartitionKeyGroupEntity

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

the class BusinessObjectFormatServiceImpl method populateBusinessObjectFormatSchema.

/**
 * Adds business object schema information to the business object format entity.
 *
 * @param businessObjectFormatEntity the business object format entity
 * @param schema the schema from the business object format create request
 */
private void populateBusinessObjectFormatSchema(BusinessObjectFormatEntity businessObjectFormatEntity, Schema schema) {
    // Add optional schema information.
    if (schema != null) {
        // If optional partition key group value is specified, get the partition key group entity and ensure it exists.
        PartitionKeyGroupEntity partitionKeyGroupEntity = null;
        if (StringUtils.isNotBlank(schema.getPartitionKeyGroup())) {
            partitionKeyGroupEntity = partitionKeyGroupDaoHelper.getPartitionKeyGroupEntity(schema.getPartitionKeyGroup());
        }
        businessObjectFormatEntity.setNullValue(schema.getNullValue());
        businessObjectFormatEntity.setDelimiter(schema.getDelimiter());
        businessObjectFormatEntity.setEscapeCharacter(schema.getEscapeCharacter());
        businessObjectFormatEntity.setPartitionKeyGroup(partitionKeyGroupEntity);
        // Create a schema column entities collection, if needed.
        Collection<SchemaColumnEntity> schemaColumnEntities = businessObjectFormatEntity.getSchemaColumns();
        if (schemaColumnEntities == null) {
            schemaColumnEntities = new ArrayList<>();
            businessObjectFormatEntity.setSchemaColumns(schemaColumnEntities);
        }
        // Create a map that will easily let us keep track of schema column entities we're creating by their column name.
        Map<String, SchemaColumnEntity> schemaColumnMap = new HashMap<>();
        // Create the schema columns for both the data columns and then the partition columns.
        // Since both lists share the same schema column entity list, we will use a common method to process them in the same way.
        createSchemaColumnEntities(schema.getColumns(), false, schemaColumnEntities, schemaColumnMap, businessObjectFormatEntity);
        createSchemaColumnEntities(schema.getPartitions(), true, schemaColumnEntities, schemaColumnMap, businessObjectFormatEntity);
    }
}
Also used : SchemaColumnEntity(org.finra.herd.model.jpa.SchemaColumnEntity) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PartitionKeyGroupEntity(org.finra.herd.model.jpa.PartitionKeyGroupEntity)

Example 5 with PartitionKeyGroupEntity

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

the class ExpectedPartitionValueServiceImpl method deleteExpectedPartitionValues.

/**
 * Deletes specified expected partition values from an existing partition key group which is identified by name.
 *
 * @param expectedPartitionValuesDeleteRequest the information needed to delete the expected partition values
 *
 * @return the expected partition values that got deleted
 */
@Override
public ExpectedPartitionValuesInformation deleteExpectedPartitionValues(ExpectedPartitionValuesDeleteRequest expectedPartitionValuesDeleteRequest) {
    // Perform request validation and trim request parameters.
    validateExpectedPartitionValuesDeleteRequest(expectedPartitionValuesDeleteRequest);
    // Retrieve and ensure that a partition key group exists with the specified name.
    PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDaoHelper.getPartitionKeyGroupEntity(expectedPartitionValuesDeleteRequest.getPartitionKeyGroupKey());
    // Load all existing expected partition value entities into a map for quick access.
    Map<String, ExpectedPartitionValueEntity> expectedPartitionValueEntityMap = getExpectedPartitionValueEntityMap(partitionKeyGroupEntity.getExpectedPartitionValues());
    // Build a list of all expected partition value entities to be deleted.
    Collection<ExpectedPartitionValueEntity> deletedExpectedPartitionValueEntities = new ArrayList<>();
    for (String expectedPartitionValue : expectedPartitionValuesDeleteRequest.getExpectedPartitionValues()) {
        // Find the relative expected partition entity.
        ExpectedPartitionValueEntity expectedPartitionValueEntity = expectedPartitionValueEntityMap.get(expectedPartitionValue);
        if (expectedPartitionValueEntity != null) {
            deletedExpectedPartitionValueEntities.add(expectedPartitionValueEntity);
        } else {
            throw new ObjectNotFoundException(String.format("Expected partition value \"%s\" doesn't exist in \"%s\" partition key group.", expectedPartitionValue, partitionKeyGroupEntity.getPartitionKeyGroupName()));
        }
    }
    // Perform the actual deletion.
    for (ExpectedPartitionValueEntity expectedPartitionValueEntity : deletedExpectedPartitionValueEntities) {
        partitionKeyGroupEntity.getExpectedPartitionValues().remove(expectedPartitionValueEntity);
        expectedPartitionValueDao.delete(expectedPartitionValueEntity);
    }
    return createExpectedPartitionValuesInformationFromEntities(partitionKeyGroupEntity, deletedExpectedPartitionValueEntities);
}
Also used : ExpectedPartitionValueEntity(org.finra.herd.model.jpa.ExpectedPartitionValueEntity) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException) ArrayList(java.util.ArrayList) PartitionKeyGroupEntity(org.finra.herd.model.jpa.PartitionKeyGroupEntity)

Aggregations

PartitionKeyGroupEntity (org.finra.herd.model.jpa.PartitionKeyGroupEntity)40 Test (org.junit.Test)25 ExpectedPartitionValueKey (org.finra.herd.model.api.xml.ExpectedPartitionValueKey)9 PartitionKeyGroupKey (org.finra.herd.model.api.xml.PartitionKeyGroupKey)9 ExpectedPartitionValuesInformation (org.finra.herd.model.api.xml.ExpectedPartitionValuesInformation)8 ExpectedPartitionValueEntity (org.finra.herd.model.jpa.ExpectedPartitionValueEntity)7 ArrayList (java.util.ArrayList)6 ExpectedPartitionValueInformation (org.finra.herd.model.api.xml.ExpectedPartitionValueInformation)6 PartitionValueRange (org.finra.herd.model.api.xml.PartitionValueRange)6 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)4 HashMap (java.util.HashMap)3 Predicate (javax.persistence.criteria.Predicate)3 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)3 ExpectedPartitionValuesDeleteRequest (org.finra.herd.model.api.xml.ExpectedPartitionValuesDeleteRequest)3 Order (javax.persistence.criteria.Order)2 FieldExtension (org.activiti.bpmn.model.FieldExtension)2 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)2 ExpectedPartitionValuesCreateRequest (org.finra.herd.model.api.xml.ExpectedPartitionValuesCreateRequest)2 Parameter (org.finra.herd.model.api.xml.Parameter)2 BusinessObjectDefinitionEntity (org.finra.herd.model.jpa.BusinessObjectDefinitionEntity)2