Search in sources :

Example 11 with ExpectedPartitionValueEntity

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

the class BusinessObjectDataDaoHelper method processPartitionValueRangeFilterOption.

/**
 * Builds a list of partition values from a "partition value range" partition value filter option. The list of partition values will come from the expected
 * partition values table for values within the specified range. The list will be ordered ascending.
 *
 * @param partitionValueRange the partition value range
 * @param businessObjectFormatEntity the business object format entity
 *
 * @return the unique and sorted partition value list
 */
private List<String> processPartitionValueRangeFilterOption(PartitionValueRange partitionValueRange, BusinessObjectFormatEntity businessObjectFormatEntity) {
    List<String> resultPartitionValues = new ArrayList<>();
    Assert.notNull(businessObjectFormatEntity.getPartitionKeyGroup(), String.format("A partition key group, which is required to use partition value ranges, is not specified for the business object format {%s}.", businessObjectFormatHelper.businessObjectFormatEntityAltKeyToString(businessObjectFormatEntity)));
    List<ExpectedPartitionValueEntity> expectedPartitionValueEntities = expectedPartitionValueDao.getExpectedPartitionValuesByGroupAndRange(businessObjectFormatEntity.getPartitionKeyGroup().getPartitionKeyGroupName(), partitionValueRange);
    // Populate the partition values returned from the range query.
    for (ExpectedPartitionValueEntity expectedPartitionValueEntity : expectedPartitionValueEntities) {
        String partitionValue = expectedPartitionValueEntity.getPartitionValue();
        // Validate that expected partition value does not match to one of the partition value tokens.
        Assert.isTrue(!partitionValue.equals(BusinessObjectDataService.MAX_PARTITION_VALUE_TOKEN) && !partitionValue.equals(BusinessObjectDataService.MIN_PARTITION_VALUE_TOKEN), "A partition value token cannot be specified as one of the expected partition values.");
        resultPartitionValues.add(partitionValue);
    }
    // Validate that our partition value range results in a non-empty partition value list.
    Assert.notEmpty(resultPartitionValues, String.format("Partition value range [\"%s\", \"%s\"] contains no valid partition values in partition key group \"%s\". Business object format: {%s}", partitionValueRange.getStartPartitionValue(), partitionValueRange.getEndPartitionValue(), businessObjectFormatEntity.getPartitionKeyGroup().getPartitionKeyGroupName(), businessObjectFormatHelper.businessObjectFormatEntityAltKeyToString(businessObjectFormatEntity)));
    return resultPartitionValues;
}
Also used : ExpectedPartitionValueEntity(org.finra.herd.model.jpa.ExpectedPartitionValueEntity) ArrayList(java.util.ArrayList)

Example 12 with ExpectedPartitionValueEntity

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

Example 13 with ExpectedPartitionValueEntity

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

the class ExpectedPartitionValueServiceImpl method getExpectedPartitionValueImpl.

/**
 * Retrieves an existing expected partition value plus/minus an optional offset.
 *
 * @param expectedPartitionValueKey the expected partition value key
 * @param offset the optional positive or negative offset
 *
 * @return the expected partition value
 */
protected ExpectedPartitionValueInformation getExpectedPartitionValueImpl(ExpectedPartitionValueKey expectedPartitionValueKey, Integer offset) {
    // Perform validation and trim of the input parameters.
    expectedPartitionValueHelper.validateExpectedPartitionValueKey(expectedPartitionValueKey);
    // Retrieve and ensure that a partition key group exists with the specified name.
    partitionKeyGroupDaoHelper.getPartitionKeyGroupEntity(expectedPartitionValueKey.getPartitionKeyGroupName());
    // Retrieve the start expected partition value by passing 0 offset value.
    ExpectedPartitionValueEntity expectedPartitionValueEntity = expectedPartitionValueDao.getExpectedPartitionValue(expectedPartitionValueKey, 0);
    if (expectedPartitionValueEntity == null) {
        throw new ObjectNotFoundException(String.format("Expected partition value \"%s\" doesn't exist in \"%s\" partition key group.", expectedPartitionValueKey.getExpectedPartitionValue(), expectedPartitionValueKey.getPartitionKeyGroupName()));
    }
    // If we have a non-zero offset, retrieve the offset expected partition value.
    if (offset != null && offset != 0) {
        expectedPartitionValueEntity = expectedPartitionValueDao.getExpectedPartitionValue(expectedPartitionValueKey, offset);
        if (expectedPartitionValueEntity == null) {
            throw new ObjectNotFoundException(String.format("Expected partition value \"%s\" with offset %d doesn't exist in \"%s\" partition key group.", expectedPartitionValueKey.getExpectedPartitionValue(), offset, expectedPartitionValueKey.getPartitionKeyGroupName()));
        }
    }
    return createExpectedPartitionValueInformationFromEntity(expectedPartitionValueEntity);
}
Also used : ExpectedPartitionValueEntity(org.finra.herd.model.jpa.ExpectedPartitionValueEntity) ObjectNotFoundException(org.finra.herd.model.ObjectNotFoundException)

Aggregations

ExpectedPartitionValueEntity (org.finra.herd.model.jpa.ExpectedPartitionValueEntity)13 PartitionKeyGroupEntity (org.finra.herd.model.jpa.PartitionKeyGroupEntity)7 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)3 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)2 Order (javax.persistence.criteria.Order)2 Predicate (javax.persistence.criteria.Predicate)2 ObjectNotFoundException (org.finra.herd.model.ObjectNotFoundException)2 PartitionValueRange (org.finra.herd.model.api.xml.PartitionValueRange)2 AlreadyExistsException (org.finra.herd.model.AlreadyExistsException)1 ExpectedPartitionValueKey (org.finra.herd.model.api.xml.ExpectedPartitionValueKey)1 ExpectedPartitionValuesInformation (org.finra.herd.model.api.xml.ExpectedPartitionValuesInformation)1 PartitionKeyGroupKey (org.finra.herd.model.api.xml.PartitionKeyGroupKey)1