use of org.finra.herd.model.jpa.PartitionKeyGroupEntity in project herd by FINRAOS.
the class ExpectedPartitionValueServiceTest method testLargeNumberOfExpectedPartitionValues.
@Test
public void testLargeNumberOfExpectedPartitionValues() {
// Define some constants.
final int MAX_PARTITION_VALUES = 1000;
final int LAST_ELEMENT_INDEX = MAX_PARTITION_VALUES - 1;
// Create and persist a partition key group entity.
PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP);
// Add expected partition values to this partition key group.
List<String> testUnsortedExpectedPartitionValues = expectedPartitionValueDaoTestHelper.getTestUnsortedExpectedPartitionValues(MAX_PARTITION_VALUES);
List<String> testSortedExpectedPartitionValues = expectedPartitionValueDaoTestHelper.getTestSortedExpectedPartitionValues(MAX_PARTITION_VALUES);
ExpectedPartitionValuesCreateRequest createRequest = expectedPartitionValueServiceTestHelper.createExpectedPartitionValuesCreateRequest(PARTITION_KEY_GROUP, testUnsortedExpectedPartitionValues);
ExpectedPartitionValuesInformation resultPartitionValuesInformation = expectedPartitionValueService.createExpectedPartitionValues(createRequest);
// Validate the returned object.
expectedPartitionValueServiceTestHelper.validateExpectedPartitionValuesInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues, resultPartitionValuesInformation);
// Validate that the expected partition value entities got created.
assertEquals(testUnsortedExpectedPartitionValues.size(), partitionKeyGroupEntity.getExpectedPartitionValues().size());
// Get expected partition value without an offset.
ExpectedPartitionValueInformation resultPartitionValueInformation = expectedPartitionValueService.getExpectedPartitionValue(new ExpectedPartitionValueKey(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(MAX_PARTITION_VALUES / 2)), null);
// Validate the returned object.
expectedPartitionValueServiceTestHelper.validateExpectedPartitionValueInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(MAX_PARTITION_VALUES / 2), resultPartitionValueInformation);
// Get expected partition value by passing a large positive offset.
resultPartitionValueInformation = expectedPartitionValueService.getExpectedPartitionValue(new ExpectedPartitionValueKey(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(0)), LAST_ELEMENT_INDEX);
// Validate the returned object.
expectedPartitionValueServiceTestHelper.validateExpectedPartitionValueInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(LAST_ELEMENT_INDEX), resultPartitionValueInformation);
// Get expected partition value by passing a large negative offset.
resultPartitionValueInformation = expectedPartitionValueService.getExpectedPartitionValue(new ExpectedPartitionValueKey(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(LAST_ELEMENT_INDEX)), -LAST_ELEMENT_INDEX);
// Validate the returned object.
expectedPartitionValueServiceTestHelper.validateExpectedPartitionValueInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(0), resultPartitionValueInformation);
// Get a range of expected partition values.
resultPartitionValuesInformation = expectedPartitionValueService.getExpectedPartitionValues(new PartitionKeyGroupKey(PARTITION_KEY_GROUP), new PartitionValueRange(testSortedExpectedPartitionValues.get(0), testSortedExpectedPartitionValues.get(LAST_ELEMENT_INDEX)));
// Validate the returned object.
expectedPartitionValueServiceTestHelper.validateExpectedPartitionValuesInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues, resultPartitionValuesInformation);
// Delete expected partition values from this partition key group.
ExpectedPartitionValuesDeleteRequest deleteRequest = expectedPartitionValueServiceTestHelper.createExpectedPartitionValuesDeleteRequest(PARTITION_KEY_GROUP, testUnsortedExpectedPartitionValues);
ExpectedPartitionValuesInformation deleteResultPartitionValuesInformation = expectedPartitionValueService.deleteExpectedPartitionValues(deleteRequest);
// Validate the returned object.
expectedPartitionValueServiceTestHelper.validateExpectedPartitionValuesInformation(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues, deleteResultPartitionValuesInformation);
// Validate that the expected partition value entities got deleted.
assertEquals(0, partitionKeyGroupEntity.getExpectedPartitionValues().size());
}
use of org.finra.herd.model.jpa.PartitionKeyGroupEntity in project herd by FINRAOS.
the class ExpectedPartitionValueServiceImpl method createExpectedPartitionValues.
/**
* Creates a list of expected partition values for an existing partition key group.
*
* @param expectedPartitionValuesCreateRequest the information needed to create the expected partition values
*
* @return the newly created expected partition values
*/
@Override
public ExpectedPartitionValuesInformation createExpectedPartitionValues(ExpectedPartitionValuesCreateRequest expectedPartitionValuesCreateRequest) {
// Perform request validation and trim request parameters.
validateExpectedPartitionValuesCreateRequest(expectedPartitionValuesCreateRequest);
// Retrieve and ensure that a partition key group exists with the specified name.
PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDaoHelper.getPartitionKeyGroupEntity(expectedPartitionValuesCreateRequest.getPartitionKeyGroupKey());
// Load all existing expected partition value entities into a map for quick access.
Map<String, ExpectedPartitionValueEntity> expectedPartitionValueEntityMap = getExpectedPartitionValueEntityMap(partitionKeyGroupEntity.getExpectedPartitionValues());
// Fail if any of the expected partition values to be created already exist.
for (String expectedPartitionValue : expectedPartitionValuesCreateRequest.getExpectedPartitionValues()) {
if (expectedPartitionValueEntityMap.containsKey(expectedPartitionValue)) {
throw new AlreadyExistsException(String.format("Expected partition value \"%s\" already exists in \"%s\" partition key group.", expectedPartitionValue, partitionKeyGroupEntity.getPartitionKeyGroupName()));
}
}
// Create and persist the expected partition value entities.
Collection<ExpectedPartitionValueEntity> createdExpectedPartitionValueEntities = new ArrayList<>();
for (String expectedPartitionValue : expectedPartitionValuesCreateRequest.getExpectedPartitionValues()) {
ExpectedPartitionValueEntity expectedPartitionValueEntity = new ExpectedPartitionValueEntity();
createdExpectedPartitionValueEntities.add(expectedPartitionValueEntity);
expectedPartitionValueEntity.setPartitionKeyGroup(partitionKeyGroupEntity);
partitionKeyGroupEntity.getExpectedPartitionValues().add(expectedPartitionValueEntity);
expectedPartitionValueEntity.setPartitionValue(expectedPartitionValue);
expectedPartitionValueDao.saveAndRefresh(expectedPartitionValueEntity);
}
return createExpectedPartitionValuesInformationFromEntities(partitionKeyGroupEntity, createdExpectedPartitionValueEntities);
}
use of org.finra.herd.model.jpa.PartitionKeyGroupEntity in project herd by FINRAOS.
the class GetExpectedPartitionValueTest method testGetExpectedPartitionValueMissingOptionalParameters.
/**
* This unit test does not pass optional parameters.
*/
@Test
public void testGetExpectedPartitionValueMissingOptionalParameters() throws Exception {
// Create and persist a partition key group entity.
PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP);
// Create and persist a list of expected partition values.
expectedPartitionValueDaoTestHelper.createExpectedPartitionValueEntities(partitionKeyGroupEntity, expectedPartitionValueDaoTestHelper.getTestUnsortedExpectedPartitionValues());
// Get a sorted list of expected partition values.
List<String> testSortedExpectedPartitionValues = expectedPartitionValueDaoTestHelper.getTestSortedExpectedPartitionValues();
List<FieldExtension> fieldExtensionList = new ArrayList<>();
fieldExtensionList.add(buildFieldExtension(GetExpectedPartitionValue.VARIABLE_PARTITION_KEY_GROUP_NAME, "${partitionKeyGroupName}"));
fieldExtensionList.add(buildFieldExtension(GetExpectedPartitionValue.VARIABLE_EXPECTED_PARTITION_VALUE, "${expectedPartitionValue}"));
List<Parameter> parameters = new ArrayList<>();
parameters.add(buildParameter(GetExpectedPartitionValue.VARIABLE_PARTITION_KEY_GROUP_NAME, PARTITION_KEY_GROUP));
parameters.add(buildParameter(GetExpectedPartitionValue.VARIABLE_EXPECTED_PARTITION_VALUE, testSortedExpectedPartitionValues.get(TEST_EXPECTED_PARTITION_VALUE_INDEX)));
// Retrieve and validate the expected partition value information.
Map<String, Object> variableValuesToValidate = new HashMap<>();
variableValuesToValidate.put(GetExpectedPartitionValue.VARIABLE_PARTITION_KEY_GROUP_NAME, PARTITION_KEY_GROUP);
variableValuesToValidate.put(GetExpectedPartitionValue.VARIABLE_EXPECTED_PARTITION_VALUE, testSortedExpectedPartitionValues.get(TEST_EXPECTED_PARTITION_VALUE_INDEX));
testActivitiServiceTaskSuccess(GetExpectedPartitionValue.class.getCanonicalName(), fieldExtensionList, parameters, variableValuesToValidate);
}
use of org.finra.herd.model.jpa.PartitionKeyGroupEntity in project herd by FINRAOS.
the class PartitionKeyGroupServiceImpl method createPartitionKeyGroupEntity.
/**
* Creates a new partition key group entity from the request information.
*
* @param request the partition key group create request
*
* @return the newly created partition key group entity
*/
private PartitionKeyGroupEntity createPartitionKeyGroupEntity(PartitionKeyGroupCreateRequest request) {
// Create a new entity.
PartitionKeyGroupEntity partitionKeyGroupEntity = new PartitionKeyGroupEntity();
partitionKeyGroupEntity.setPartitionKeyGroupName(request.getPartitionKeyGroupKey().getPartitionKeyGroupName());
return partitionKeyGroupEntity;
}
use of org.finra.herd.model.jpa.PartitionKeyGroupEntity in project herd by FINRAOS.
the class PartitionKeyGroupServiceImpl method createPartitionKeyGroup.
/**
* Creates a new partition key group.
*
* @param request the information needed to create a partition key group
*
* @return the newly created partition key group information
*/
@Override
public PartitionKeyGroup createPartitionKeyGroup(PartitionKeyGroupCreateRequest request) {
// Perform the validation.
partitionKeyGroupHelper.validatePartitionKeyGroupKey(request.getPartitionKeyGroupKey());
// Ensure a partition key group with the specified name doesn't already exist.
PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDao.getPartitionKeyGroupByKey(request.getPartitionKeyGroupKey());
if (partitionKeyGroupEntity != null) {
throw new AlreadyExistsException(String.format("Unable to create partition key group with name \"%s\" because it already exists.", request.getPartitionKeyGroupKey().getPartitionKeyGroupName()));
}
// Create a partition key group entity from the request information.
partitionKeyGroupEntity = createPartitionKeyGroupEntity(request);
// Persist the new entity.
partitionKeyGroupEntity = partitionKeyGroupDao.saveAndRefresh(partitionKeyGroupEntity);
// Create and return the partition key group object from the persisted entity.
return createPartitionKeyGroupFromEntity(partitionKeyGroupEntity);
}
Aggregations