use of org.finra.herd.model.api.xml.BusinessObjectFormatKey in project herd by FINRAOS.
the class UploadDownloadRestControllerTest method testInitiateUploadSingle.
@Test
public void testInitiateUploadSingle() {
// Create business object format keys.
BusinessObjectFormatKey sourceBusinessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION);
BusinessObjectFormatKey targetBusinessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE_2, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2);
// Create a file object.
File file = new File(LOCAL_FILE, FILE_SIZE);
// Create a request.
UploadSingleInitiationRequest request = new UploadSingleInitiationRequest(sourceBusinessObjectFormatKey, targetBusinessObjectFormatKey, Arrays.asList(new Attribute(ATTRIBUTE_NAME_1_MIXED_CASE, ATTRIBUTE_VALUE_1)), file, STORAGE_NAME);
// Create business object data keys.
BusinessObjectDataKey sourceBusinessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION);
BusinessObjectDataKey targetBusinessObjectDataKey = new BusinessObjectDataKey(BDEF_NAMESPACE_2, BDEF_NAME_2, FORMAT_USAGE_CODE_2, FORMAT_FILE_TYPE_CODE_2, FORMAT_VERSION_2, PARTITION_VALUE_2, SUBPARTITION_VALUES_2, DATA_VERSION_2);
// Create a business object data objects.
BusinessObjectData sourceBusinessObjectData = new BusinessObjectData();
sourceBusinessObjectData.setId(ID);
sourceBusinessObjectData.setStatus(BDATA_STATUS);
sourceBusinessObjectData.setStorageUnits(Arrays.asList(new StorageUnit(new Storage(STORAGE_NAME, STORAGE_PLATFORM_CODE, NO_ATTRIBUTES), NO_STORAGE_DIRECTORY, NO_STORAGE_FILES, STORAGE_UNIT_STATUS, NO_STORAGE_UNIT_STATUS_HISTORY, NO_STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS, NO_RESTORE_EXPIRATION_ON)));
BusinessObjectData targetBusinessObjectData = new BusinessObjectData();
targetBusinessObjectData.setId(ID_2);
targetBusinessObjectData.setStatus(BDATA_STATUS_2);
targetBusinessObjectData.setStorageUnits(Arrays.asList(new StorageUnit(new Storage(STORAGE_NAME_2, STORAGE_PLATFORM_CODE, NO_ATTRIBUTES), NO_STORAGE_DIRECTORY, NO_STORAGE_FILES, STORAGE_UNIT_STATUS_2, NO_STORAGE_UNIT_STATUS_HISTORY, NO_STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS, NO_RESTORE_EXPIRATION_ON)));
// Create a response.
UploadSingleInitiationResponse response = new UploadSingleInitiationResponse(sourceBusinessObjectData, targetBusinessObjectData, file, UUID_VALUE, AWS_ASSUMED_ROLE_ACCESS_KEY, AWS_ASSUMED_ROLE_SECRET_KEY, AWS_ASSUMED_ROLE_SESSION_TOKEN, AWS_ASSUMED_ROLE_SESSION_EXPIRATION_TIME, AWS_KMS_KEY_ID, STORAGE_NAME);
// Mock the external calls.
when(uploadDownloadService.initiateUploadSingle(request)).thenReturn(response);
when(businessObjectDataHelper.getBusinessObjectDataKey(sourceBusinessObjectData)).thenReturn(sourceBusinessObjectDataKey);
when(businessObjectDataHelper.getBusinessObjectDataKey(targetBusinessObjectData)).thenReturn(targetBusinessObjectDataKey);
// Call the method under test.
UploadSingleInitiationResponse result = uploadDownloadRestController.initiateUploadSingle(request);
// Verify the external calls.
verify(uploadDownloadService).initiateUploadSingle(request);
verify(businessObjectDataHelper).getBusinessObjectDataKey(sourceBusinessObjectData);
verify(businessObjectDataHelper).getBusinessObjectDataKey(targetBusinessObjectData);
verify(notificationEventService).processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN, sourceBusinessObjectDataKey, BDATA_STATUS, null);
verify(notificationEventService).processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_STTS_CHG, sourceBusinessObjectDataKey, BDATA_STATUS, null);
verify(notificationEventService).processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, sourceBusinessObjectDataKey, STORAGE_NAME, STORAGE_UNIT_STATUS, null);
verify(notificationEventService).processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_RGSTN, targetBusinessObjectDataKey, BDATA_STATUS_2, null);
verify(notificationEventService).processBusinessObjectDataNotificationEventAsync(NotificationEventTypeEntity.EventTypesBdata.BUS_OBJCT_DATA_STTS_CHG, targetBusinessObjectDataKey, BDATA_STATUS_2, null);
verify(notificationEventService).processStorageUnitNotificationEventAsync(NotificationEventTypeEntity.EventTypesStorageUnit.STRGE_UNIT_STTS_CHG, targetBusinessObjectDataKey, STORAGE_NAME_2, STORAGE_UNIT_STATUS_2, null);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(response, result);
}
use of org.finra.herd.model.api.xml.BusinessObjectFormatKey in project herd by FINRAOS.
the class BusinessObjectFormatServiceImpl method createBusinessObjectFormat.
@PublishNotificationMessages
@NamespacePermission(fields = "#request.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public BusinessObjectFormat createBusinessObjectFormat(BusinessObjectFormatCreateRequest request) {
// Perform the validation of the request parameters, except for the alternate key.
validateBusinessObjectFormatCreateRequest(request);
// Get business object format key from the request.
BusinessObjectFormatKey businessObjectFormatKey = getBusinessObjectFormatKey(request);
// Get the business object definition and ensure it exists.
BusinessObjectDefinitionEntity businessObjectDefinitionEntity = businessObjectDefinitionDaoHelper.getBusinessObjectDefinitionEntity(new BusinessObjectDefinitionKey(businessObjectFormatKey.getNamespace(), businessObjectFormatKey.getBusinessObjectDefinitionName()));
// Get business object format file type and ensure it exists.
FileTypeEntity fileTypeEntity = fileTypeDaoHelper.getFileTypeEntity(request.getBusinessObjectFormatFileType());
// Get the latest format version for this business format, if it exists.
BusinessObjectFormatEntity latestVersionBusinessObjectFormatEntity = businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey);
// If the latest version exists, perform the additive schema validation and update the latest entity.
if (latestVersionBusinessObjectFormatEntity != null) {
// Get the latest version business object format model object.
BusinessObjectFormat latestVersionBusinessObjectFormat = businessObjectFormatHelper.createBusinessObjectFormatFromEntity(latestVersionBusinessObjectFormatEntity);
// If the latest version format has schema, check the new format version schema is "additive" to the previous format version.
if (latestVersionBusinessObjectFormat.getSchema() != null) {
validateNewSchemaIsAdditiveToOldSchema(request.getSchema(), latestVersionBusinessObjectFormat.getSchema());
}
// Update the latest entity.
latestVersionBusinessObjectFormatEntity.setLatestVersion(false);
businessObjectFormatDao.saveAndRefresh(latestVersionBusinessObjectFormatEntity);
}
// Create a business object format entity from the request information.
Integer businessObjectFormatVersion = latestVersionBusinessObjectFormatEntity == null ? 0 : latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatVersion() + 1;
BusinessObjectFormatEntity newBusinessObjectFormatEntity = createBusinessObjectFormatEntity(request, businessObjectDefinitionEntity, fileTypeEntity, businessObjectFormatVersion, null);
// latest version format is the descriptive format for the bdef, update the bdef descriptive format to the newly created one
if (latestVersionBusinessObjectFormatEntity != null && latestVersionBusinessObjectFormatEntity.equals(businessObjectDefinitionEntity.getDescriptiveBusinessObjectFormat())) {
businessObjectDefinitionEntity.setDescriptiveBusinessObjectFormat(newBusinessObjectFormatEntity);
businessObjectDefinitionDao.saveAndRefresh(businessObjectDefinitionEntity);
}
// latest version business object exists, carry the retention information to the new entity
if (latestVersionBusinessObjectFormatEntity != null) {
// for each of the previous version's child, remove the parent link to the previous version and set the parent to the new version
for (BusinessObjectFormatEntity childFormatEntity : latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatChildren()) {
childFormatEntity.getBusinessObjectFormatParents().remove(latestVersionBusinessObjectFormatEntity);
childFormatEntity.getBusinessObjectFormatParents().add(newBusinessObjectFormatEntity);
newBusinessObjectFormatEntity.getBusinessObjectFormatChildren().add(childFormatEntity);
businessObjectFormatDao.saveAndRefresh(childFormatEntity);
}
// for each of the previous version's parent, remove the child link to the previous version and set the child link to the new version
for (BusinessObjectFormatEntity parentFormatEntity : latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatParents()) {
parentFormatEntity.getBusinessObjectFormatChildren().remove(latestVersionBusinessObjectFormatEntity);
parentFormatEntity.getBusinessObjectFormatChildren().add(newBusinessObjectFormatEntity);
newBusinessObjectFormatEntity.getBusinessObjectFormatParents().add(parentFormatEntity);
businessObjectFormatDao.saveAndRefresh(parentFormatEntity);
}
// mark the latest version business object format
latestVersionBusinessObjectFormatEntity.setBusinessObjectFormatParents(null);
latestVersionBusinessObjectFormatEntity.setBusinessObjectFormatChildren(null);
// carry the retention information from the latest entity to the new entity
newBusinessObjectFormatEntity.setRetentionPeriodInDays(latestVersionBusinessObjectFormatEntity.getRetentionPeriodInDays());
newBusinessObjectFormatEntity.setRecordFlag(latestVersionBusinessObjectFormatEntity.isRecordFlag());
newBusinessObjectFormatEntity.setRetentionType(latestVersionBusinessObjectFormatEntity.getRetentionType());
businessObjectFormatDao.saveAndRefresh(newBusinessObjectFormatEntity);
// reset the retention information of the latest version business object format
latestVersionBusinessObjectFormatEntity.setRetentionType(null);
latestVersionBusinessObjectFormatEntity.setRecordFlag(null);
latestVersionBusinessObjectFormatEntity.setRetentionPeriodInDays(null);
businessObjectFormatDao.saveAndRefresh(latestVersionBusinessObjectFormatEntity);
}
// Notify the search index that a business object definition must be updated.
searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectDefinitionEntity, SEARCH_INDEX_UPDATE_TYPE_UPDATE);
// Create a version change notification to be sent on create business object format event.
messageNotificationEventService.processBusinessObjectFormatVersionChangeNotificationEvent(businessObjectFormatHelper.getBusinessObjectFormatKey(newBusinessObjectFormatEntity), latestVersionBusinessObjectFormatEntity != null ? latestVersionBusinessObjectFormatEntity.getBusinessObjectFormatVersion().toString() : "");
// Create and return the business object format object from the persisted entity.
return businessObjectFormatHelper.createBusinessObjectFormatFromEntity(newBusinessObjectFormatEntity);
}
use of org.finra.herd.model.api.xml.BusinessObjectFormatKey in project herd by FINRAOS.
the class BusinessObjectFormatServiceImpl method updateBusinessObjectFormatParents.
@NamespacePermissions({ @NamespacePermission(fields = "#businessObjectFormatKey.namespace", permissions = NamespacePermissionEnum.WRITE), @NamespacePermission(fields = "#businessObjectFormatParentsUpdateRequest?.businessObjectFormatParents?.![namespace]", permissions = NamespacePermissionEnum.READ) })
@Override
public BusinessObjectFormat updateBusinessObjectFormatParents(BusinessObjectFormatKey businessObjectFormatKey, BusinessObjectFormatParentsUpdateRequest businessObjectFormatParentsUpdateRequest) {
Assert.notNull(businessObjectFormatParentsUpdateRequest, "A Business Object Format Parents 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.");
// Perform validation and trim for the business object format parents
validateBusinessObjectFormatParents(businessObjectFormatParentsUpdateRequest.getBusinessObjectFormatParents());
// Retrieve and ensure that a business object format exists.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey);
// Retrieve and ensure that business object format parents exist. A set is used to ignore duplicate business object format parents.
Set<BusinessObjectFormatEntity> businessObjectFormatParents = new HashSet<>();
for (BusinessObjectFormatKey businessObjectFormatParent : businessObjectFormatParentsUpdateRequest.getBusinessObjectFormatParents()) {
// Retrieve and ensure that a business object format exists.
BusinessObjectFormatEntity businessObjectFormatEntityParent = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatParent);
businessObjectFormatParents.add(businessObjectFormatEntityParent);
}
// Set the business object format parents.
businessObjectFormatEntity.setBusinessObjectFormatParents(new ArrayList<>(businessObjectFormatParents));
// Persist and refresh the entity.
businessObjectFormatEntity = businessObjectFormatDao.saveAndRefresh(businessObjectFormatEntity);
// Notify the search index that a business object definition must be updated.
searchIndexUpdateHelper.modifyBusinessObjectDefinitionInSearchIndex(businessObjectFormatEntity.getBusinessObjectDefinition(), SEARCH_INDEX_UPDATE_TYPE_UPDATE);
// Create and return the business object format object from the persisted entity.
return businessObjectFormatHelper.createBusinessObjectFormatFromEntity(businessObjectFormatEntity);
}
use of org.finra.herd.model.api.xml.BusinessObjectFormatKey in project herd by FINRAOS.
the class BusinessObjectFormatServiceImpl method validateBusinessObjectFormatParents.
/**
* Validate the business object format parents
*
* @param businessObjectFormatParents business object format parents
*/
private void validateBusinessObjectFormatParents(List<BusinessObjectFormatKey> businessObjectFormatParents) {
// Validate parents business object format.
if (!CollectionUtils.isEmpty(businessObjectFormatParents)) {
for (BusinessObjectFormatKey parentBusinessObjectFormatKey : businessObjectFormatParents) {
Assert.notNull(parentBusinessObjectFormatKey, "Parent object format must be specified.");
businessObjectFormatHelper.validateBusinessObjectFormatKey(parentBusinessObjectFormatKey, false);
Assert.isNull(parentBusinessObjectFormatKey.getBusinessObjectFormatVersion(), "Business object format version must not be specified.");
}
}
}
use of org.finra.herd.model.api.xml.BusinessObjectFormatKey in project herd by FINRAOS.
the class BusinessObjectDataInitiateDestroyHelperServiceImpl method validateBusinessObjectData.
/**
* Validate that business object data is supported by the business object data destroy feature.
*
* @param businessObjectDataEntity the business object data entity
* @param businessObjectDataKey the business object data key
*/
protected void validateBusinessObjectData(BusinessObjectDataEntity businessObjectDataEntity, BusinessObjectDataKey businessObjectDataKey) {
// Get business object format for this business object data.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectDataEntity.getBusinessObjectFormat();
// Create a version-less key for the business object format.
BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(businessObjectDataKey.getNamespace(), businessObjectDataKey.getBusinessObjectDefinitionName(), businessObjectDataKey.getBusinessObjectFormatUsage(), businessObjectDataKey.getBusinessObjectFormatFileType(), null);
// Get the latest version of the format to retrieve retention information.
BusinessObjectFormatEntity latestVersionBusinessObjectFormatEntity = businessObjectFormatEntity.getLatestVersion() ? businessObjectFormatEntity : businessObjectFormatDao.getBusinessObjectFormatByAltKey(businessObjectFormatKey);
// Get retention information.
String retentionType = latestVersionBusinessObjectFormatEntity.getRetentionType() != null ? latestVersionBusinessObjectFormatEntity.getRetentionType().getCode() : null;
Integer retentionPeriodInDays = latestVersionBusinessObjectFormatEntity.getRetentionPeriodInDays();
// Validate that retention information is specified for this business object format.
if (StringUtils.isBlank(retentionType) || retentionPeriodInDays == null) {
throw new IllegalArgumentException(String.format("Retention information is not configured for the business object format. Business object format: {%s}", businessObjectFormatHelper.businessObjectFormatKeyToString(businessObjectFormatKey)));
}
// Validate the retention type.
if (!RetentionTypeEntity.PARTITION_VALUE.equals(retentionType)) {
throw new IllegalArgumentException(String.format("Retention type \"%s\" is not supported by the business object data destroy feature. Business object format: {%s}", retentionType, businessObjectFormatHelper.businessObjectFormatKeyToString(businessObjectFormatKey)));
}
// Try to convert business object data primary partition value to a timestamp. If conversion is not successful, the method returns a null value.
Date primaryPartitionValue = businessObjectDataHelper.getDateFromString(businessObjectDataEntity.getPartitionValue());
// If primary partition values is not a date, this business object data is not supported by the business object data destroy feature.
if (primaryPartitionValue == null) {
throw new IllegalArgumentException(String.format("Primary partition value \"%s\" cannot get converted to a valid date. Business object data: {%s}", businessObjectDataEntity.getPartitionValue(), businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)));
}
// Get the current timestamp from the database.
Timestamp currentTimestamp = herdDao.getCurrentTimestamp();
// Compute the relative primary partition value threshold date based on the current timestamp and retention period value.
Date primaryPartitionValueThreshold = new Date(HerdDateUtils.addDays(currentTimestamp, -retentionPeriodInDays).getTime());
// Validate that this business object data has it's primary partition value before or equal to the threshold date.
if (primaryPartitionValue.compareTo(primaryPartitionValueThreshold) > 0) {
throw new IllegalArgumentException(String.format("Business object data fails retention threshold check for retention type \"%s\" with retention period of %d days. Business object data: {%s}", retentionType, retentionPeriodInDays, businessObjectDataHelper.businessObjectDataKeyToString(businessObjectDataKey)));
}
}
Aggregations