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));
}
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);
}
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();
}
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();
}
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();
}
Aggregations