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));
}
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);
}
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);
}
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);
}
}
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);
}
Aggregations