Search in sources :

Example 6 with PartitionKeyGroupEntity

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);
}
Also used : ExpectedPartitionValueEntity(org.finra.herd.model.jpa.ExpectedPartitionValueEntity) PartitionKeyGroupEntity(org.finra.herd.model.jpa.PartitionKeyGroupEntity)

Example 7 with PartitionKeyGroupEntity

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);
}
Also used : PartitionKeyGroupEntity(org.finra.herd.model.jpa.PartitionKeyGroupEntity)

Example 8 with 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;
}
Also used : ExpectedPartitionValueEntity(org.finra.herd.model.jpa.ExpectedPartitionValueEntity) ArrayList(java.util.ArrayList) PartitionKeyGroupEntity(org.finra.herd.model.jpa.PartitionKeyGroupEntity)

Example 9 with PartitionKeyGroupEntity

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));
}
Also used : PartitionKeyGroupEntity(org.finra.herd.model.jpa.PartitionKeyGroupEntity) PartitionKeyGroupKey(org.finra.herd.model.api.xml.PartitionKeyGroupKey) Test(org.junit.Test)

Example 10 with PartitionKeyGroupEntity

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));
    }
}
Also used : ExpectedPartitionValueEntity(org.finra.herd.model.jpa.ExpectedPartitionValueEntity) PartitionKeyGroupEntity(org.finra.herd.model.jpa.PartitionKeyGroupEntity) ExpectedPartitionValueKey(org.finra.herd.model.api.xml.ExpectedPartitionValueKey) Test(org.junit.Test)

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