Search in sources :

Example 6 with RetentionTypeEntity

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

the class RetentionTypeDaoImpl method getRetentionTypeByCode.

@Override
public RetentionTypeEntity getRetentionTypeByCode(String code) {
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<RetentionTypeEntity> criteria = builder.createQuery(RetentionTypeEntity.class);
    // The criteria root is the retention type
    Root<RetentionTypeEntity> retentionType = criteria.from(RetentionTypeEntity.class);
    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate businessObjectDataStatusCodeRestriction = builder.equal(builder.upper(retentionType.get(RetentionTypeEntity_.code)), code.toUpperCase());
    criteria.select(retentionType).where(businessObjectDataStatusCodeRestriction);
    return executeSingleResultQuery(criteria, String.format("Found more than one retention type with code \"%s\".", code));
}
Also used : CriteriaBuilder(javax.persistence.criteria.CriteriaBuilder) RetentionTypeEntity(org.finra.herd.model.jpa.RetentionTypeEntity) Predicate(javax.persistence.criteria.Predicate)

Example 7 with RetentionTypeEntity

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

the class BusinessObjectFormatServiceImpl method updateBusinessObjectFormatRetentionInformation.

@NamespacePermission(fields = "#businessObjectFormatKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public BusinessObjectFormat updateBusinessObjectFormatRetentionInformation(BusinessObjectFormatKey businessObjectFormatKey, BusinessObjectFormatRetentionInformationUpdateRequest updateRequest) {
    Assert.notNull(updateRequest, "A Business Object Format Retention Information Update Request is required.");
    Assert.notNull(updateRequest.isRecordFlag(), "A Record Flag in Business Object Format Retention Information Update Request is required.");
    // Perform validation and trim the alternate key parameters.
    businessObjectFormatHelper.validateBusinessObjectFormatKey(businessObjectFormatKey, false);
    Assert.isNull(businessObjectFormatKey.getBusinessObjectFormatVersion(), "Business object format version must not be specified.");
    // Retrieve and ensure that record retention type exists if the request's retention type is not null
    RetentionTypeEntity recordRetentionTypeEntity = null;
    if (updateRequest.getRetentionType() != null) {
        Assert.notNull(updateRequest.getRetentionPeriodInDays(), "A retention period in days must be specified when retention type is present.");
        Assert.isTrue(updateRequest.getRetentionPeriodInDays() > 0, "A positive retention period in days must be specified.");
        // Perform trim business object format retention in update request
        updateRequest.setRetentionType(updateRequest.getRetentionType().trim());
        // Retrieve the retention type entity
        recordRetentionTypeEntity = businessObjectFormatDaoHelper.getRecordRetentionTypeEntity(updateRequest.getRetentionType());
    }
    // Retrieve and ensure that a business object format exists.
    BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey);
    businessObjectFormatEntity.setRecordFlag(BooleanUtils.isTrue(updateRequest.isRecordFlag()));
    businessObjectFormatEntity.setRetentionPeriodInDays(updateRequest.getRetentionPeriodInDays());
    businessObjectFormatEntity.setRetentionType(recordRetentionTypeEntity);
    // Persist and refresh the entity.
    businessObjectFormatEntity = businessObjectFormatDao.saveAndRefresh(businessObjectFormatEntity);
    // Create and return the business object format object from the persisted entity.
    return businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity);
}
Also used : BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) RetentionTypeEntity(org.finra.herd.model.jpa.RetentionTypeEntity) NamespacePermission(org.finra.herd.model.annotation.NamespacePermission)

Example 8 with RetentionTypeEntity

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

the class BusinessObjectDataInitiateDestroyHelperServiceImplTest method testValidateBusinessObjectDataInvalidRetentionType.

@Test
public void testValidateBusinessObjectDataInvalidRetentionType() {
    // Create a version-less business object format key.
    BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, NO_FORMAT_VERSION);
    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION);
    // Create a retention type entity.
    RetentionTypeEntity retentionTypeEntity = new RetentionTypeEntity();
    retentionTypeEntity.setCode(INVALID_VALUE);
    // Create a business object format entity.
    BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
    businessObjectFormatEntity.setLatestVersion(true);
    businessObjectFormatEntity.setRetentionType(retentionTypeEntity);
    businessObjectFormatEntity.setRetentionPeriodInDays(RETENTION_PERIOD_DAYS);
    // Create a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
    businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
    businessObjectDataEntity.setPartitionValue(PARTITION_VALUE);
    // Mock the external calls.
    when(businessObjectFormatHelper.businessObjectFormatKeyToString(businessObjectFormatKey)).thenReturn(BUSINESS_OBJECT_FORMAT_KEY_AS_STRING);
    // Try to call the method under test.
    try {
        businessObjectDataInitiateDestroyHelperServiceImpl.validateBusinessObjectData(businessObjectDataEntity, businessObjectDataKey);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Retention type \"%s\" is not supported by the business object data destroy feature. Business object format: {%s}", INVALID_VALUE, BUSINESS_OBJECT_FORMAT_KEY_AS_STRING), e.getMessage());
    }
    // Verify the external calls.
    verify(businessObjectFormatHelper).businessObjectFormatKeyToString(businessObjectFormatKey);
    verifyNoMoreInteractionsHelper();
}
Also used : BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) RetentionTypeEntity(org.finra.herd.model.jpa.RetentionTypeEntity) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 9 with RetentionTypeEntity

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

the class BusinessObjectDataInitiateDestroyHelperServiceImplTest method testValidateBusinessObjectDataNoRetentionInformation.

@Test
public void testValidateBusinessObjectDataNoRetentionInformation() {
    // Create a version-less business object format key.
    BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, NO_FORMAT_VERSION);
    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, INITIAL_FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION);
    // Create a retention type entity.
    RetentionTypeEntity retentionTypeEntity = new RetentionTypeEntity();
    retentionTypeEntity.setCode(PARTITION_VALUE);
    // Create a business object format entity which is not the latest format version.
    BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
    businessObjectFormatEntity.setBusinessObjectFormatVersion(INITIAL_FORMAT_VERSION);
    businessObjectFormatEntity.setLatestVersion(false);
    // Create a latest version business object format entity with missing retention type.
    BusinessObjectFormatEntity latestVersionBusinessObjectFormatEntity = new BusinessObjectFormatEntity();
    latestVersionBusinessObjectFormatEntity.setBusinessObjectFormatVersion(INITIAL_FORMAT_VERSION);
    latestVersionBusinessObjectFormatEntity.setLatestVersion(true);
    latestVersionBusinessObjectFormatEntity.setRetentionType(null);
    latestVersionBusinessObjectFormatEntity.setRetentionPeriodInDays(RETENTION_PERIOD_DAYS);
    // Create a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
    businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
    businessObjectDataEntity.setPartitionValue(PARTITION_VALUE);
    // Mock the external calls.
    when(businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey)).thenReturn(latestVersionBusinessObjectFormatEntity);
    when(businessObjectFormatHelper.businessObjectFormatKeyToString(businessObjectFormatKey)).thenReturn(BUSINESS_OBJECT_FORMAT_KEY_AS_STRING);
    // Try to call the method under test.
    try {
        businessObjectDataInitiateDestroyHelperServiceImpl.validateBusinessObjectData(businessObjectDataEntity, businessObjectDataKey);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Retention information is not configured for the business object format. Business object format: {%s}", BUSINESS_OBJECT_FORMAT_KEY_AS_STRING), e.getMessage());
    }
    // Update the latest business object format version to have retention type specified but without a retention period.
    latestVersionBusinessObjectFormatEntity.setRetentionType(retentionTypeEntity);
    latestVersionBusinessObjectFormatEntity.setRetentionPeriodInDays(null);
    // Try to call the method under test.
    try {
        businessObjectDataInitiateDestroyHelperServiceImpl.validateBusinessObjectData(businessObjectDataEntity, businessObjectDataKey);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Retention information is not configured for the business object format. Business object format: {%s}", BUSINESS_OBJECT_FORMAT_KEY_AS_STRING), e.getMessage());
    }
    // Verify the external calls.
    verify(businessObjectFormatDao, times(2)).getBusinessObjectFormatByAltKey(businessObjectFormatKey);
    verify(businessObjectFormatHelper, times(2)).businessObjectFormatKeyToString(businessObjectFormatKey);
    verifyNoMoreInteractionsHelper();
}
Also used : BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) RetentionTypeEntity(org.finra.herd.model.jpa.RetentionTypeEntity) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Example 10 with RetentionTypeEntity

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

the class BusinessObjectDataInitiateDestroyHelperServiceImplTest method testValidateBusinessObjectDataRetentionThresholdCheckFails.

@Test
public void testValidateBusinessObjectDataRetentionThresholdCheckFails() {
    // Create a version-less business object format key.
    BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, NO_FORMAT_VERSION);
    // Create a business object data key.
    BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, NO_SUBPARTITION_VALUES, DATA_VERSION);
    // Create a retention type entity.
    RetentionTypeEntity retentionTypeEntity = new RetentionTypeEntity();
    retentionTypeEntity.setCode(RetentionTypeEntity.PARTITION_VALUE);
    // Create a business object format entity.
    BusinessObjectFormatEntity businessObjectFormatEntity = new BusinessObjectFormatEntity();
    businessObjectFormatEntity.setLatestVersion(true);
    businessObjectFormatEntity.setRetentionType(retentionTypeEntity);
    businessObjectFormatEntity.setRetentionPeriodInDays(RETENTION_PERIOD_DAYS);
    // Create a business object data entity.
    BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
    businessObjectDataEntity.setBusinessObjectFormat(businessObjectFormatEntity);
    businessObjectDataEntity.setPartitionValue(PARTITION_VALUE);
    // Create a current timestamp.
    Timestamp currentTimestamp = new Timestamp(new Date().getTime());
    // Create a date representing the primary partition value that does not satisfy the retention threshold check.
    Calendar calendar = Calendar.getInstance();
    calendar.add(Calendar.DATE, -(RETENTION_PERIOD_DAYS - 1));
    Date primaryPartitionValueDate = calendar.getTime();
    // Mock the external calls.
    when(businessObjectDataHelper.getDateFromString(PARTITION_VALUE)).thenReturn(primaryPartitionValueDate);
    when(herdDao.getCurrentTimestamp()).thenReturn(currentTimestamp);
    when(businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)).thenReturn(BUSINESS_OBJECT_DATA_KEY_AS_STRING);
    // Try to call the method under test.
    try {
        businessObjectDataInitiateDestroyHelperServiceImpl.validateBusinessObjectData(businessObjectDataEntity, businessObjectDataKey);
        fail();
    } catch (IllegalArgumentException e) {
        assertEquals(String.format("Business object data fails retention threshold check for retention type \"%s\" with retention period of %d days. Business object data: {%s}", RetentionTypeEntity.PARTITION_VALUE, RETENTION_PERIOD_DAYS, BUSINESS_OBJECT_DATA_KEY_AS_STRING), e.getMessage());
    }
    // Verify the external calls.
    verify(businessObjectDataHelper).getDateFromString(PARTITION_VALUE);
    verify(businessObjectDataHelper).businessObjectDataKeyToString(businessObjectDataKey);
    verify(herdDao).getCurrentTimestamp();
    verifyNoMoreInteractionsHelper();
}
Also used : Calendar(java.util.Calendar) BusinessObjectFormatKey(org.finra.herd.model.api.xml.BusinessObjectFormatKey) BusinessObjectDataEntity(org.finra.herd.model.jpa.BusinessObjectDataEntity) BusinessObjectDataKey(org.finra.herd.model.api.xml.BusinessObjectDataKey) BusinessObjectFormatEntity(org.finra.herd.model.jpa.BusinessObjectFormatEntity) Timestamp(java.sql.Timestamp) Date(java.util.Date) RetentionTypeEntity(org.finra.herd.model.jpa.RetentionTypeEntity) AbstractServiceTest(org.finra.herd.service.AbstractServiceTest) Test(org.junit.Test)

Aggregations

RetentionTypeEntity (org.finra.herd.model.jpa.RetentionTypeEntity)11 Test (org.junit.Test)8 BusinessObjectDataEntity (org.finra.herd.model.jpa.BusinessObjectDataEntity)7 BusinessObjectFormatEntity (org.finra.herd.model.jpa.BusinessObjectFormatEntity)6 BusinessObjectDataKey (org.finra.herd.model.api.xml.BusinessObjectDataKey)5 BusinessObjectFormatKey (org.finra.herd.model.api.xml.BusinessObjectFormatKey)5 AbstractServiceTest (org.finra.herd.service.AbstractServiceTest)5 Timestamp (java.sql.Timestamp)2 Calendar (java.util.Calendar)2 Date (java.util.Date)2 BusinessObjectData (org.finra.herd.model.api.xml.BusinessObjectData)2 BusinessObjectDataSearchKey (org.finra.herd.model.api.xml.BusinessObjectDataSearchKey)2 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)1 Predicate (javax.persistence.criteria.Predicate)1 NamespacePermission (org.finra.herd.model.annotation.NamespacePermission)1 StorageFile (org.finra.herd.model.api.xml.StorageFile)1 BusinessObjectDataDestroyDto (org.finra.herd.model.dto.BusinessObjectDataDestroyDto)1 BusinessObjectDataStatusEntity (org.finra.herd.model.jpa.BusinessObjectDataStatusEntity)1 StorageEntity (org.finra.herd.model.jpa.StorageEntity)1 StorageFileEntity (org.finra.herd.model.jpa.StorageFileEntity)1