use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class BusinessObjectDataServiceImplTest method testDestroyBusinessObjectData.
@Test
public void testDestroyBusinessObjectData() {
// 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, SUBPARTITION_VALUES, DATA_VERSION);
// Create multiple states of business object data destroy parameters DTO.
List<BusinessObjectDataDestroyDto> businessObjectDataDestroyDtoStates = Arrays.asList(new BusinessObjectDataDestroyDto(businessObjectDataKey, STORAGE_NAME, BusinessObjectDataStatusEntity.DELETED, BusinessObjectDataStatusEntity.VALID, StorageUnitStatusEntity.DISABLING, StorageUnitStatusEntity.ENABLED, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME, BDATA_FINAL_DESTROY_DELAY_IN_DAYS), new BusinessObjectDataDestroyDto(businessObjectDataKey, STORAGE_NAME, BusinessObjectDataStatusEntity.DELETED, BusinessObjectDataStatusEntity.VALID, StorageUnitStatusEntity.DISABLED, StorageUnitStatusEntity.DISABLING, S3_ENDPOINT, S3_BUCKET_NAME, S3_KEY_PREFIX, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME, BDATA_FINAL_DESTROY_DELAY_IN_DAYS));
// Create a business object data.
BusinessObjectData businessObjectData = new BusinessObjectData();
businessObjectData.setId(ID);
// Mock the external calls.
doAnswer(invocation -> {
BusinessObjectDataDestroyDto businessObjectDataDestroyDto = (BusinessObjectDataDestroyDto) invocation.getArguments()[0];
businessObjectDataDestroyDtoStates.get(0).copyTo(businessObjectDataDestroyDto);
return null;
}).when(businessObjectDataInitiateDestroyHelperService).prepareToInitiateDestroy(new BusinessObjectDataDestroyDto(), businessObjectDataKey);
doAnswer(invocation -> {
BusinessObjectDataDestroyDto businessObjectDataDestroyDto = (BusinessObjectDataDestroyDto) invocation.getArguments()[0];
businessObjectDataDestroyDtoStates.get(1).copyTo(businessObjectDataDestroyDto);
return null;
}).when(businessObjectDataInitiateDestroyHelperService).executeInitiateDestroyAfterStep(any(BusinessObjectDataDestroyDto.class));
when(businessObjectDataInitiateDestroyHelperService.executeInitiateDestroyAfterStep(any(BusinessObjectDataDestroyDto.class))).thenReturn(businessObjectData);
// Call the method under test.
BusinessObjectData result = businessObjectDataServiceImpl.destroyBusinessObjectData(businessObjectDataKey);
// Verify the external calls.
verify(businessObjectDataInitiateDestroyHelperService).prepareToInitiateDestroy(any(BusinessObjectDataDestroyDto.class), any(BusinessObjectDataKey.class));
verify(businessObjectDataInitiateDestroyHelperService).executeS3SpecificSteps(any(BusinessObjectDataDestroyDto.class));
verify(businessObjectDataInitiateDestroyHelperService).executeInitiateDestroyAfterStep(any(BusinessObjectDataDestroyDto.class));
verify(notificationEventService, times(2)).processStorageUnitNotificationEventAsync(any(NotificationEventTypeEntity.EventTypesStorageUnit.class), any(BusinessObjectDataKey.class), any(String.class), any(String.class), any(String.class));
verify(notificationEventService).processBusinessObjectDataNotificationEventAsync(any(NotificationEventTypeEntity.EventTypesBdata.class), any(BusinessObjectDataKey.class), any(String.class), any(String.class));
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(businessObjectData, result);
}
use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class BusinessObjectDataInitiateDestroyHelperServiceImplTest method testExecuteInitiateDestroyAfterStep.
@Test
public void testExecuteInitiateDestroyAfterStep() {
// 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 business object data status entity.
BusinessObjectDataStatusEntity businessObjectDataStatusEntity = new BusinessObjectDataStatusEntity();
businessObjectDataStatusEntity.setCode(BusinessObjectDataStatusEntity.VALID);
// Create a business object data entity.
BusinessObjectDataEntity businessObjectDataEntity = new BusinessObjectDataEntity();
businessObjectDataEntity.setStatus(businessObjectDataStatusEntity);
// Create a storage unit status entity.
StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity();
storageUnitStatusEntity.setCode(StorageUnitStatusEntity.DISABLING);
// Create a storage unit entity.
StorageUnitEntity storageUnitEntity = new StorageUnitEntity();
storageUnitEntity.setStatus(storageUnitStatusEntity);
// Create a business object data destroy parameters DTO.
BusinessObjectDataDestroyDto businessObjectDataDestroyDto = new BusinessObjectDataDestroyDto(businessObjectDataKey, STORAGE_NAME, BusinessObjectDataStatusEntity.DELETED, BusinessObjectDataStatusEntity.VALID, StorageUnitStatusEntity.DISABLING, StorageUnitStatusEntity.ENABLED, S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME, BDATA_FINAL_DESTROY_DELAY_IN_DAYS);
// Create a business object data.
BusinessObjectData businessObjectData = new BusinessObjectData();
businessObjectData.setId(ID);
// Mock the external calls.
when(businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey)).thenReturn(businessObjectDataEntity);
when(storageUnitDaoHelper.getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity)).thenReturn(storageUnitEntity);
doAnswer(new Answer<Void>() {
public Void answer(InvocationOnMock invocation) {
// Get the new storage unit status.
String storageUnitStatus = (String) invocation.getArguments()[1];
// Create a storage unit status entity for the new storage unit status.
StorageUnitStatusEntity storageUnitStatusEntity = new StorageUnitStatusEntity();
storageUnitStatusEntity.setCode(storageUnitStatus);
// Update the storage unit with the new status.
StorageUnitEntity storageUnitEntity = (StorageUnitEntity) invocation.getArguments()[0];
storageUnitEntity.setStatus(storageUnitStatusEntity);
return null;
}
}).when(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.DISABLED, StorageUnitStatusEntity.DISABLED);
when(businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity)).thenReturn(businessObjectData);
// Call the method under test.
BusinessObjectData result = businessObjectDataInitiateDestroyHelperServiceImpl.executeInitiateDestroyAfterStep(businessObjectDataDestroyDto);
// Verify the external calls.
verify(businessObjectDataDaoHelper).getBusinessObjectDataEntity(businessObjectDataKey);
verify(storageUnitDaoHelper).getStorageUnitEntity(STORAGE_NAME, businessObjectDataEntity);
verify(storageUnitDaoHelper).updateStorageUnitStatus(storageUnitEntity, StorageUnitStatusEntity.DISABLED, StorageUnitStatusEntity.DISABLED);
verify(businessObjectDataHelper).createBusinessObjectDataFromEntity(businessObjectDataEntity);
verifyNoMoreInteractionsHelper();
// Validate the results.
assertEquals(businessObjectData, result);
assertEquals(new BusinessObjectDataDestroyDto(businessObjectDataKey, STORAGE_NAME, BusinessObjectDataStatusEntity.DELETED, BusinessObjectDataStatusEntity.VALID, StorageUnitStatusEntity.DISABLED, StorageUnitStatusEntity.DISABLING, S3_ENDPOINT, S3_BUCKET_NAME, TEST_S3_KEY_PREFIX, S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE, S3_OBJECT_TAGGER_ROLE_ARN, S3_OBJECT_TAGGER_ROLE_SESSION_NAME, BDATA_FINAL_DESTROY_DELAY_IN_DAYS), businessObjectDataDestroyDto);
}
use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class RetentionExpirationDestroyerWebClient method destroyBusinessObjectData.
/**
* Retrieves business object definition from the herd registration server.
*
* @param businessObjectDataKey the name of the business object data key
*
* @return the business object definition
* @throws IOException if an I/O error was encountered
* @throws JAXBException if a JAXB error was encountered
* @throws URISyntaxException if an URI syntax error was encountered
*/
public BusinessObjectData destroyBusinessObjectData(BusinessObjectDataKey businessObjectDataKey) throws IOException, JAXBException, URISyntaxException {
String uriPath = HERD_APP_REST_URI_PREFIX + "/businessObjectData/destroy" + "/namespaces/" + businessObjectDataKey.getNamespace() + "/businessObjectDefinitionNames/" + businessObjectDataKey.getBusinessObjectDefinitionName() + "/businessObjectFormatUsages/" + businessObjectDataKey.getBusinessObjectFormatUsage() + "/businessObjectFormatFileTypes/" + businessObjectDataKey.getBusinessObjectFormatFileType() + "/businessObjectFormatVersions/" + businessObjectDataKey.getBusinessObjectFormatVersion() + "/partitionValues/" + businessObjectDataKey.getPartitionValue() + "/businessObjectDataVersions/" + businessObjectDataKey.getBusinessObjectDataVersion();
URIBuilder uriBuilder = new URIBuilder().setScheme(getUriScheme()).setHost(regServerAccessParamsDto.getRegServerHost()).setPort(regServerAccessParamsDto.getRegServerPort()).setPath(uriPath);
if (CollectionUtils.isNotEmpty(businessObjectDataKey.getSubPartitionValues())) {
uriBuilder.setParameter("subPartitionValues", herdStringHelper.join(businessObjectDataKey.getSubPartitionValues(), "|", "\\"));
}
URI uri = uriBuilder.build();
try (CloseableHttpClient client = httpClientOperations.createHttpClient()) {
HttpPost request = new HttpPost(uri);
request.addHeader("Content-Type", DEFAULT_CONTENT_TYPE);
request.addHeader("Accepts", DEFAULT_ACCEPT);
// If SSL is enabled, set the client authentication header.
if (regServerAccessParamsDto.isUseSsl()) {
request.addHeader(getAuthorizationHeader());
}
LOGGER.info(String.format(" HTTP POST URI: %s", request.getURI().toString()));
LOGGER.info(String.format(" HTTP POST Headers: %s", Arrays.toString(request.getAllHeaders())));
BusinessObjectData businessObjectData = destroyBusinessObjectData(httpClientOperations.execute(client, request));
LOGGER.info("Successfully destroyed business object data from the registration server.");
return businessObjectData;
}
}
use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class RetentionExpirationExporterController method performRetentionExpirationExport.
/**
* Executes the retention expiration exporter workflow.
*
* @param namespace the namespace of business object data
* @param businessObjectDefinitionName the business object definition name of business object data
* @param localOutputFile the local output file
* @param regServerAccessParamsDto the DTO for the parameters required to communicate with the registration server
* @param udcServerHost the hostname of the UDC application server
*
* @throws Exception if any problems were encountered
*/
void performRetentionExpirationExport(String namespace, String businessObjectDefinitionName, File localOutputFile, RegServerAccessParamsDto regServerAccessParamsDto, String udcServerHost) throws Exception {
// Fail if local output file already exists.
if (localOutputFile.exists()) {
throw new IllegalArgumentException(String.format("The specified local output file \"%s\" already exists.", localOutputFile.toString()));
}
// Initialize the web client.
retentionExpirationExporterWebClient.setRegServerAccessParamsDto(regServerAccessParamsDto);
// Validate that specified business object definition exists.
BusinessObjectDefinition businessObjectDefinition = retentionExpirationExporterWebClient.getBusinessObjectDefinition(namespace, businessObjectDefinitionName);
// Get business object display name.
String businessObjectDefinitionDisplayName = getBusinessObjectDefinitionDisplayName(businessObjectDefinition);
// Create a search request for business object data with the filter on retention expiration option.
BusinessObjectDataSearchKey businessObjectDataSearchKey = new BusinessObjectDataSearchKey();
businessObjectDataSearchKey.setNamespace(namespace);
businessObjectDataSearchKey.setBusinessObjectDefinitionName(businessObjectDefinitionName);
businessObjectDataSearchKey.setFilterOnRetentionExpiration(true);
List<BusinessObjectDataSearchKey> businessObjectDataSearchKeys = new ArrayList<>();
businessObjectDataSearchKeys.add(businessObjectDataSearchKey);
BusinessObjectDataSearchFilter businessObjectDataSearchFilter = new BusinessObjectDataSearchFilter(businessObjectDataSearchKeys);
BusinessObjectDataSearchRequest request = new BusinessObjectDataSearchRequest(Collections.singletonList(businessObjectDataSearchFilter));
// Create a result list for business object data.
List<BusinessObjectData> businessObjectDataList = new ArrayList<>();
// Fetch business object data from server until no records found.
int pageNumber = 1;
BusinessObjectDataSearchResult businessObjectDataSearchResult = retentionExpirationExporterWebClient.searchBusinessObjectData(request, pageNumber);
while (CollectionUtils.isNotEmpty(businessObjectDataSearchResult.getBusinessObjectDataElements())) {
LOGGER.info("Fetched {} business object data records from the registration server.", CollectionUtils.size(businessObjectDataSearchResult.getBusinessObjectDataElements()));
businessObjectDataList.addAll(businessObjectDataSearchResult.getBusinessObjectDataElements());
pageNumber++;
businessObjectDataSearchResult = retentionExpirationExporterWebClient.searchBusinessObjectData(request, pageNumber);
}
// Write business object data to the output CSV file.
writeToCsvFile(localOutputFile, businessObjectDefinition.getNamespace(), businessObjectDefinition.getBusinessObjectDefinitionName(), businessObjectDefinitionDisplayName, udcServerHost, businessObjectDataList);
}
use of org.finra.herd.model.api.xml.BusinessObjectData in project herd by FINRAOS.
the class DownloaderControllerTest method testCreateDownloaderOutputManifestDtoAssertOutputFilesEmptyWhenStorageFilesNull.
@Test
public void testCreateDownloaderOutputManifestDtoAssertOutputFilesEmptyWhenStorageFilesNull() {
BusinessObjectData businessObjectData = new BusinessObjectData();
StorageUnit storageUnit = new StorageUnit(new Storage("storageName", null, null), null, null, StorageUnitStatusEntity.ENABLED, null, null, null);
String s3KeyPrefix = "s3KeyPrefix";
DownloaderOutputManifestDto actual = downloaderController.createDownloaderOutputManifestDto(businessObjectData, storageUnit, s3KeyPrefix);
assertEquals(0, actual.getManifestFiles().size());
}
Aggregations