use of org.finra.herd.model.api.xml.Storage in project herd by FINRAOS.
the class StorageRestControllerTest method testCreateStorage.
@Test
public void testCreateStorage() {
// Create a storage create request.
StorageCreateRequest storageCreateRequest = new StorageCreateRequest(STORAGE_NAME, STORAGE_PLATFORM_CODE, NO_ATTRIBUTES);
// Create a storage.
Storage storage = new Storage(STORAGE_NAME, STORAGE_PLATFORM_CODE, NO_ATTRIBUTES);
// Mock the external calls.
when(storageService.createStorage(storageCreateRequest)).thenReturn(storage);
// Call the method under test.
Storage result = storageRestController.createStorage(storageCreateRequest);
// Verify the external calls.
verify(storageService).createStorage(storageCreateRequest);
verifyNoMoreInteractions(storageService);
// Validate the returned object.
assertEquals(storage, result);
}
use of org.finra.herd.model.api.xml.Storage 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.Storage in project herd by FINRAOS.
the class DataBridgeWebClient method getStorage.
/**
* Gets storage information from the registration server.
*
* @param storageName the storage name
*
* @return the storage information
* @throws IOException if an I/O error was encountered.
* @throws JAXBException if a JAXB error was encountered.
* @throws URISyntaxException if a URI syntax error was encountered.
*/
public Storage getStorage(String storageName) throws IOException, JAXBException, URISyntaxException {
LOGGER.info(String.format("Retrieving storage information for \"%s\" storage name from the registration server...", storageName));
final String URI_PATH = HERD_APP_REST_URI_PREFIX + "/storages/" + storageName;
URIBuilder uriBuilder = new URIBuilder().setScheme(getUriScheme()).setHost(regServerAccessParamsDto.getRegServerHost()).setPort(regServerAccessParamsDto.getRegServerPort()).setPath(URI_PATH);
Storage storage;
try (CloseableHttpClient client = httpClientOperations.createHttpClient()) {
HttpGet request = new HttpGet(uriBuilder.build());
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 GET URI: %s", request.getURI().toString()));
LOGGER.info(String.format(" HTTP GET Headers: %s", Arrays.toString(request.getAllHeaders())));
storage = getStorage(httpClientOperations.execute(client, request));
}
LOGGER.info("Successfully retrieved storage information from the registration server.");
LOGGER.info(" Storage name: " + storage.getName());
LOGGER.info(" Attributes: ");
for (Attribute attribute : storage.getAttributes()) {
LOGGER.info(String.format(" \"%s\"=\"%s\"", attribute.getName(), attribute.getValue()));
}
return storage;
}
use of org.finra.herd.model.api.xml.Storage in project herd by FINRAOS.
the class BusinessObjectDataServiceGetBusinessObjectDataTest method testGetBusinessObjectDataIncludeStorageUnitStatusHistory.
@Test
public void testGetBusinessObjectDataIncludeStorageUnitStatusHistory() {
// 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 a business object data storage unit key.
BusinessObjectDataStorageUnitKey businessObjectDataStorageUnitKey = new BusinessObjectDataStorageUnitKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, STORAGE_NAME);
// Create a storage unit entity.
StorageUnitEntity storageUnitEntity = storageUnitDaoTestHelper.createStorageUnitEntity(STORAGE_NAME, businessObjectDataKey, StorageUnitStatusEntity.DISABLED);
// Execute a storage unit status change.
businessObjectDataStorageUnitStatusService.updateBusinessObjectDataStorageUnitStatus(businessObjectDataStorageUnitKey, new BusinessObjectDataStorageUnitStatusUpdateRequest(StorageUnitStatusEntity.ENABLED));
// Retrieve the business object data with enabled include storage unit status history flag.
BusinessObjectData resultBusinessObjectData = businessObjectDataService.getBusinessObjectData(businessObjectDataKey, PARTITION_KEY, NO_BDATA_STATUS, NO_INCLUDE_BUSINESS_OBJECT_DATA_STATUS_HISTORY, INCLUDE_STORAGE_UNIT_STATUS_HISTORY);
// Build the expected response object. The storage unit history record is expected to have system username for the createdBy auditable field.
BusinessObjectData expectedBusinessObjectData = new BusinessObjectData(storageUnitEntity.getBusinessObjectData().getId(), BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FORMAT_FILE_TYPE_CODE, FORMAT_VERSION, PARTITION_KEY, PARTITION_VALUE, SUBPARTITION_VALUES, DATA_VERSION, LATEST_VERSION_FLAG_SET, BDATA_STATUS, Arrays.asList(new StorageUnit(new Storage(STORAGE_NAME, StoragePlatformEntity.S3, null), NO_STORAGE_DIRECTORY, null, StorageUnitStatusEntity.ENABLED, Arrays.asList(new StorageUnitStatusChangeEvent(StorageUnitStatusEntity.ENABLED, HerdDateUtils.getXMLGregorianCalendarValue(IterableUtils.get(storageUnitEntity.getHistoricalStatuses(), 0).getCreatedOn()), HerdDaoSecurityHelper.SYSTEM_USER)), NO_STORAGE_POLICY_TRANSITION_FAILED_ATTEMPTS, NO_RESTORE_EXPIRATION_ON)), NO_ATTRIBUTES, NO_BUSINESS_OBJECT_DATA_PARENTS, NO_BUSINESS_OBJECT_DATA_CHILDREN, NO_BUSINESS_OBJECT_DATA_STATUS_HISTORY);
// Validate the returned response object.
assertEquals(expectedBusinessObjectData, resultBusinessObjectData);
}
use of org.finra.herd.model.api.xml.Storage in project herd by FINRAOS.
the class RelationalTableRegistrationServiceTest method testCreateRelationalTableRegistration.
@Test
public void testCreateRelationalTableRegistration() {
// Create database entities required for relational table registration testing.
relationalTableRegistrationServiceTestHelper.createDatabaseEntitiesForRelationalTableRegistrationTesting(BDEF_NAMESPACE, DATA_PROVIDER_NAME, STORAGE_NAME);
// Pick one of the in-memory database tables to be registered as a relational table.
String relationalSchemaName = "PUBLIC";
String relationalTableName = BusinessObjectDefinitionEntity.TABLE_NAME.toUpperCase();
// Create a relational table registration create request for a table that is part of the in-memory database setup as part of DAO mocks.
RelationalTableRegistrationCreateRequest relationalTableRegistrationCreateRequest = new RelationalTableRegistrationCreateRequest(BDEF_NAMESPACE, BDEF_NAME, BDEF_DISPLAY_NAME, FORMAT_USAGE_CODE, DATA_PROVIDER_NAME, relationalSchemaName, relationalTableName, STORAGE_NAME);
// Create a relational table registration.
BusinessObjectData businessObjectData = relationalTableRegistrationService.createRelationalTableRegistration(relationalTableRegistrationCreateRequest, APPEND_TO_EXISTING_BUSINESS_OBJECT_DEFINTION_FALSE);
// Create an expected storage unit.
StorageUnit expectedStorageUnit = new StorageUnit();
expectedStorageUnit.setStorage(new Storage(STORAGE_NAME, StoragePlatformEntity.RELATIONAL, relationalTableRegistrationServiceTestHelper.getStorageAttributes()));
expectedStorageUnit.setStorageUnitStatus(StorageUnitStatusEntity.ENABLED);
// Create an expected business object data.
BusinessObjectData expectedBusinessObjectData = new BusinessObjectData();
expectedBusinessObjectData.setId(businessObjectData.getId());
expectedBusinessObjectData.setNamespace(BDEF_NAMESPACE);
expectedBusinessObjectData.setBusinessObjectDefinitionName(BDEF_NAME);
expectedBusinessObjectData.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE);
expectedBusinessObjectData.setBusinessObjectFormatFileType(FileTypeEntity.RELATIONAL_TABLE_FILE_TYPE);
expectedBusinessObjectData.setBusinessObjectFormatVersion(INITIAL_FORMAT_VERSION);
expectedBusinessObjectData.setPartitionValue(BusinessObjectDataServiceImpl.NO_PARTITIONING_PARTITION_VALUE);
expectedBusinessObjectData.setSubPartitionValues(new ArrayList<>());
expectedBusinessObjectData.setVersion(INITIAL_DATA_VERSION);
expectedBusinessObjectData.setPartitionKey(BusinessObjectDataServiceImpl.NO_PARTITIONING_PARTITION_KEY);
expectedBusinessObjectData.setLatestVersion(LATEST_VERSION_FLAG_SET);
expectedBusinessObjectData.setStatus(BusinessObjectDataStatusEntity.VALID);
expectedBusinessObjectData.setStorageUnits(Collections.singletonList(expectedStorageUnit));
expectedBusinessObjectData.setAttributes(new ArrayList<>());
expectedBusinessObjectData.setBusinessObjectDataParents(new ArrayList<>());
expectedBusinessObjectData.setBusinessObjectDataChildren(new ArrayList<>());
// Validate the response.
assertEquals(expectedBusinessObjectData, businessObjectData);
// Create a business object format key.
BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey(BDEF_NAMESPACE, BDEF_NAME, FORMAT_USAGE_CODE, FileTypeEntity.RELATIONAL_TABLE_FILE_TYPE, INITIAL_FORMAT_VERSION);
// Retrieve business object format that was created as part of the relational table registration.
BusinessObjectFormat businessObjectFormat = businessObjectFormatService.getBusinessObjectFormat(businessObjectFormatKey);
// Create an expected schema.
Schema expectedSchema = new Schema();
expectedSchema.setColumns(relationalTableRegistrationServiceTestHelper.getExpectedSchemaColumns());
expectedSchema.setNullValue(EMPTY_STRING);
// Build an expected business object format.
BusinessObjectFormat expectedBusinessObjectFormat = new BusinessObjectFormat();
expectedBusinessObjectFormat.setId(businessObjectFormat.getId());
expectedBusinessObjectFormat.setNamespace(BDEF_NAMESPACE);
expectedBusinessObjectFormat.setBusinessObjectDefinitionName(BDEF_NAME);
expectedBusinessObjectFormat.setBusinessObjectFormatUsage(FORMAT_USAGE_CODE);
expectedBusinessObjectFormat.setBusinessObjectFormatFileType(FileTypeEntity.RELATIONAL_TABLE_FILE_TYPE);
expectedBusinessObjectFormat.setBusinessObjectFormatVersion(INITIAL_FORMAT_VERSION);
expectedBusinessObjectFormat.setLatestVersion(LATEST_VERSION_FLAG_SET);
expectedBusinessObjectFormat.setPartitionKey(BusinessObjectDataServiceImpl.NO_PARTITIONING_PARTITION_KEY);
expectedBusinessObjectFormat.setBusinessObjectFormatParents(new ArrayList<>());
expectedBusinessObjectFormat.setBusinessObjectFormatChildren(new ArrayList<>());
expectedBusinessObjectFormat.setAttributeDefinitions(new ArrayList<>());
expectedBusinessObjectFormat.setAttributes(Arrays.asList(new Attribute(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_FORMAT_ATTRIBUTE_NAME_RELATIONAL_SCHEMA_NAME), relationalSchemaName), new Attribute(configurationHelper.getProperty(ConfigurationValue.BUSINESS_OBJECT_FORMAT_ATTRIBUTE_NAME_RELATIONAL_TABLE_NAME), relationalTableName)));
expectedBusinessObjectFormat.setSchema(expectedSchema);
// Validate the newly created business object format.
assertEquals(expectedBusinessObjectFormat, businessObjectFormat);
// Create a business object definition key.
BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey(BDEF_NAMESPACE, BDEF_NAME);
// Retrieve business object definition that was created as part of the relational table registration.
BusinessObjectDefinition businessObjectDefinition = businessObjectDefinitionService.getBusinessObjectDefinition(businessObjectDefinitionKey, true);
// Create an expected business object definition.
BusinessObjectDefinition expectedBusinessObjectDefinition = new BusinessObjectDefinition();
expectedBusinessObjectDefinition.setId(businessObjectDefinition.getId());
expectedBusinessObjectDefinition.setNamespace(BDEF_NAMESPACE);
expectedBusinessObjectDefinition.setBusinessObjectDefinitionName(BDEF_NAME);
expectedBusinessObjectDefinition.setDataProviderName(DATA_PROVIDER_NAME);
expectedBusinessObjectDefinition.setDisplayName(BDEF_DISPLAY_NAME);
expectedBusinessObjectDefinition.setAttributes(new ArrayList<>());
expectedBusinessObjectDefinition.setSampleDataFiles(new ArrayList<>());
expectedBusinessObjectDefinition.setCreatedByUserId(businessObjectDefinition.getCreatedByUserId());
expectedBusinessObjectDefinition.setLastUpdatedByUserId(businessObjectDefinition.getLastUpdatedByUserId());
expectedBusinessObjectDefinition.setLastUpdatedOn(businessObjectDefinition.getLastUpdatedOn());
expectedBusinessObjectDefinition.setBusinessObjectDefinitionChangeEvents(businessObjectDefinition.getBusinessObjectDefinitionChangeEvents());
// Validate the newly created business object definition.
assertEquals(expectedBusinessObjectDefinition, businessObjectDefinition);
}
Aggregations