use of org.finra.herd.model.jpa.PartitionKeyGroupEntity in project herd by FINRAOS.
the class ExpectedPartitionValueServiceImpl method getExpectedPartitionValues.
/**
* Retrieves a range of existing expected partition values.
*
* @param partitionKeyGroupKey the partition key group key
* @param partitionValueRange the partition value range
*
* @return the expected partition values
*/
@Override
public ExpectedPartitionValuesInformation getExpectedPartitionValues(PartitionKeyGroupKey partitionKeyGroupKey, PartitionValueRange partitionValueRange) {
// Perform validation and trim of the input parameters.
partitionKeyGroupHelper.validatePartitionKeyGroupKey(partitionKeyGroupKey);
// Trim the start expected partition value for the expected partition value range.
if (StringUtils.isNotBlank(partitionValueRange.getStartPartitionValue())) {
partitionValueRange.setStartPartitionValue(partitionValueRange.getStartPartitionValue().trim());
}
// Trim the end expected partition value for the expected partition value range.
if (StringUtils.isNotBlank(partitionValueRange.getEndPartitionValue())) {
partitionValueRange.setEndPartitionValue(partitionValueRange.getEndPartitionValue().trim());
}
// Validate that we are not missing both start and end expected partition values for the range.
if (StringUtils.isBlank(partitionValueRange.getStartPartitionValue()) && StringUtils.isBlank(partitionValueRange.getEndPartitionValue())) {
throw new IllegalArgumentException("At least one start or end expected partition value must be specified.");
}
// Using string compare, validate that start expected partition value is less than or equal to end expected partition value.
if (StringUtils.isNotBlank(partitionValueRange.getStartPartitionValue()) && StringUtils.isNotBlank(partitionValueRange.getEndPartitionValue()) && partitionValueRange.getStartPartitionValue().compareTo(partitionValueRange.getEndPartitionValue()) > 0) {
throw new IllegalArgumentException(String.format("The start expected partition value \"%s\" cannot be greater than the end expected partition value \"%s\".", partitionValueRange.getStartPartitionValue(), partitionValueRange.getEndPartitionValue()));
}
// Retrieve and ensure that a partition key group exists with the specified name.
PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDaoHelper.getPartitionKeyGroupEntity(partitionKeyGroupKey);
// Retrieve a list of expected partition values.
Collection<ExpectedPartitionValueEntity> expectedPartitionValueEntities = expectedPartitionValueDao.getExpectedPartitionValuesByGroupAndRange(partitionKeyGroupKey.getPartitionKeyGroupName(), partitionValueRange);
return createExpectedPartitionValuesInformationFromEntities(partitionKeyGroupEntity, expectedPartitionValueEntities);
}
use of org.finra.herd.model.jpa.PartitionKeyGroupEntity in project herd by FINRAOS.
the class PartitionKeyGroupDaoTestHelper method createPartitionKeyGroupEntity.
/**
* Creates and persists a new partition key group entity.
*
* @param partitionKeyGroupName the name of the partition key group
*
* @return the newly created partition key group entity.
*/
public PartitionKeyGroupEntity createPartitionKeyGroupEntity(String partitionKeyGroupName) {
PartitionKeyGroupEntity partitionKeyGroupEntity = new PartitionKeyGroupEntity();
partitionKeyGroupEntity.setPartitionKeyGroupName(partitionKeyGroupName);
return partitionKeyGroupDao.saveAndRefresh(partitionKeyGroupEntity);
}
use of org.finra.herd.model.jpa.PartitionKeyGroupEntity in project herd by FINRAOS.
the class ExpectedPartitionValueDaoTestHelper method createExpectedPartitionValueEntities.
/**
* Creates and persists specified partition value entities. This method also creates and persists a partition key group entity, if it does not exist.
*
* @param partitionKeyGroupName the partition key group name
* @param expectedPartitionValues the list of expected partition values
*
* @return the list of expected partition value entities
*/
public List<ExpectedPartitionValueEntity> createExpectedPartitionValueEntities(String partitionKeyGroupName, List<String> expectedPartitionValues) {
// Create partition key group if it does not exist.
PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDao.getPartitionKeyGroupByName(partitionKeyGroupName);
if (partitionKeyGroupEntity == null) {
partitionKeyGroupEntity = partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(partitionKeyGroupName);
}
// Initialize the return list.
List<ExpectedPartitionValueEntity> expectedPartitionValueEntities = new ArrayList<>();
// infinite loop in case the end date is before the start date.
for (String expectedPartitionValue : expectedPartitionValues) {
ExpectedPartitionValueEntity expectedPartitionValueEntity = new ExpectedPartitionValueEntity();
expectedPartitionValueEntity.setPartitionKeyGroup(partitionKeyGroupEntity);
expectedPartitionValueEntity.setPartitionValue(expectedPartitionValue);
expectedPartitionValueEntities.add(expectedPartitionValueDao.saveAndRefresh(expectedPartitionValueEntity));
}
// Return the list of entities.
return expectedPartitionValueEntities;
}
use of org.finra.herd.model.jpa.PartitionKeyGroupEntity in project herd by FINRAOS.
the class PartitionKeyGroupDaoTest method testGetPartitionKeyGroupByKey.
@Test
public void testGetPartitionKeyGroupByKey() {
// Create relative database entities.
partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP);
// Retrieve partition key group entity.
PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDao.getPartitionKeyGroupByKey(new PartitionKeyGroupKey(PARTITION_KEY_GROUP));
// Validate the results.
assertNotNull(partitionKeyGroupEntity);
assertTrue(partitionKeyGroupEntity.getPartitionKeyGroupName().equals(PARTITION_KEY_GROUP));
}
use of org.finra.herd.model.jpa.PartitionKeyGroupEntity in project herd by FINRAOS.
the class ExpectedPartitionValueDaoTest method testGetExpectedPartitionValue.
@Test
public void testGetExpectedPartitionValue() {
// Create and persist a partition key group entity.
PartitionKeyGroupEntity partitionKeyGroupEntity = partitionKeyGroupDaoTestHelper.createPartitionKeyGroupEntity(PARTITION_KEY_GROUP);
// Create and persist a list of test expected partition values.
expectedPartitionValueDaoTestHelper.createExpectedPartitionValueEntities(partitionKeyGroupEntity, expectedPartitionValueDaoTestHelper.getTestUnsortedExpectedPartitionValues());
// Get expected partition value for different offset values.
List<String> testSortedExpectedPartitionValues = expectedPartitionValueDaoTestHelper.getTestSortedExpectedPartitionValues();
int testExpectedPartitionValueIndex = 3;
for (Integer offset : Arrays.asList(-2, 0, 2)) {
ExpectedPartitionValueEntity resultExpectedPartitionValueEntity = expectedPartitionValueDao.getExpectedPartitionValue(new ExpectedPartitionValueKey(PARTITION_KEY_GROUP, testSortedExpectedPartitionValues.get(testExpectedPartitionValueIndex)), offset);
// Validate the returned object.
resultExpectedPartitionValueEntity.getPartitionValue().equals(testSortedExpectedPartitionValues.get(testExpectedPartitionValueIndex + offset));
}
}
Aggregations