use of org.finra.herd.model.api.xml.Attribute 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.Attribute in project herd by FINRAOS.
the class BusinessObjectFormatServiceImpl method updateBusinessObjectFormatAttributeDefinitionsHelper.
/**
* Updates business object format attribute definitions
*
* @param businessObjectFormatEntity the business object format entity
* @param attributeDefinitions the attributes
*/
private void updateBusinessObjectFormatAttributeDefinitionsHelper(BusinessObjectFormatEntity businessObjectFormatEntity, List<AttributeDefinition> attributeDefinitions) {
// Update the attribute definitions.
// Load all existing attribute definition entities in a map with a "lowercase" attribute definition name as the key for case insensitivity.
Map<String, BusinessObjectDataAttributeDefinitionEntity> existingAttributeDefinitionEntities = businessObjectFormatEntity.getAttributeDefinitions().stream().collect(Collectors.toMap(attributeDefinition -> attributeDefinition.getName().toLowerCase(), attributeDefinition -> attributeDefinition));
// Process the list of attribute definitions to determine that business object definition attribute entities should be created, updated, or deleted.
List<BusinessObjectDataAttributeDefinitionEntity> createdAttributeDefinitionEntities = new ArrayList<>();
List<BusinessObjectDataAttributeDefinitionEntity> retainedAttributeDefinitionEntities = new ArrayList<>();
for (AttributeDefinition attributeDefinition : attributeDefinitions) {
// Use a "lowercase" attribute name for case insensitivity.
String lowercaseAttributeName = attributeDefinition.getName().toLowerCase();
if (existingAttributeDefinitionEntities.containsKey(lowercaseAttributeName)) {
// Check if the attribute definition value needs to be updated.
BusinessObjectDataAttributeDefinitionEntity businessObjectDataAttributeDefinitionEntity = existingAttributeDefinitionEntities.get(lowercaseAttributeName);
if (!attributeDefinition.isPublish().equals(businessObjectDataAttributeDefinitionEntity.getPublish())) {
// Update the business object attribute entity.
businessObjectDataAttributeDefinitionEntity.setPublish(attributeDefinition.isPublish());
}
// Add this entity to the list of business object definition attribute entities to be retained.
retainedAttributeDefinitionEntities.add(businessObjectDataAttributeDefinitionEntity);
} else {
// Create a new business object attribute entity.
BusinessObjectDataAttributeDefinitionEntity businessObjectDataAttributeDefinitionEntity = new BusinessObjectDataAttributeDefinitionEntity();
businessObjectFormatEntity.getAttributeDefinitions().add(businessObjectDataAttributeDefinitionEntity);
businessObjectDataAttributeDefinitionEntity.setBusinessObjectFormat(businessObjectFormatEntity);
businessObjectDataAttributeDefinitionEntity.setName(attributeDefinition.getName());
businessObjectDataAttributeDefinitionEntity.setPublish(BooleanUtils.isTrue(attributeDefinition.isPublish()));
// Add this entity to the list of the newly created business object definition attribute entities.
createdAttributeDefinitionEntities.add(businessObjectDataAttributeDefinitionEntity);
}
}
// Remove any of the currently existing attribute entities that did not get onto the retained entities list.
businessObjectFormatEntity.getAttributeDefinitions().retainAll(retainedAttributeDefinitionEntities);
// Add all of the newly created business object definition attribute entities.
businessObjectFormatEntity.getAttributeDefinitions().addAll(createdAttributeDefinitionEntities);
}
use of org.finra.herd.model.api.xml.Attribute in project herd by FINRAOS.
the class BusinessObjectFormatServiceImpl method updateBusinessObjectFormatAttributes.
@NamespacePermission(fields = "#businessObjectFormatKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public BusinessObjectFormat updateBusinessObjectFormatAttributes(BusinessObjectFormatKey businessObjectFormatKey, BusinessObjectFormatAttributesUpdateRequest businessObjectFormatAttributesUpdateRequest) {
// Perform validation and trim the alternate key parameters.
businessObjectFormatHelper.validateBusinessObjectFormatKey(businessObjectFormatKey);
Assert.notNull(businessObjectFormatAttributesUpdateRequest, "A business object format attributes update request is required.");
Assert.notNull(businessObjectFormatAttributesUpdateRequest.getAttributes(), "A business object format attributes list is required.");
List<Attribute> attributes = businessObjectFormatAttributesUpdateRequest.getAttributes();
// Validate optional attributes. This is also going to trim the attribute names.
attributeHelper.validateFormatAttributes(attributes);
// Retrieve and ensure that a business object format exists.
BusinessObjectFormatEntity businessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(businessObjectFormatKey);
// Update the business object format attributes
updateBusinessObjectFormatAttributesHelper(businessObjectFormatEntity, attributes);
// 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.api.xml.Attribute in project herd by FINRAOS.
the class BusinessObjectDataServiceImpl method updateBusinessObjectDataAttributes.
@NamespacePermission(fields = "#businessObjectDataKey.namespace", permissions = NamespacePermissionEnum.WRITE)
@Override
public BusinessObjectData updateBusinessObjectDataAttributes(BusinessObjectDataKey businessObjectDataKey, BusinessObjectDataAttributesUpdateRequest businessObjectDataAttributesUpdateRequest) {
// Validate and trim the business object data key.
businessObjectDataHelper.validateBusinessObjectDataKey(businessObjectDataKey, true, true);
// Validate the update request.
Assert.notNull(businessObjectDataAttributesUpdateRequest, "A business object data attributes update request must be specified.");
Assert.notNull(businessObjectDataAttributesUpdateRequest.getAttributes(), "A list of business object data attributes must be specified.");
List<Attribute> attributes = businessObjectDataAttributesUpdateRequest.getAttributes();
// Validate attributes. This is also going to trim the attribute names.
attributeHelper.validateAttributes(attributes);
// Retrieve the business object data and ensure it exists.
BusinessObjectDataEntity businessObjectDataEntity = businessObjectDataDaoHelper.getBusinessObjectDataEntity(businessObjectDataKey);
// Validate attributes against attribute definitions.
attributeDaoHelper.validateAttributesAgainstBusinessObjectDataAttributeDefinitions(attributes, businessObjectDataEntity.getBusinessObjectFormat().getAttributeDefinitions());
// Update the attributes.
attributeDaoHelper.updateBusinessObjectDataAttributes(businessObjectDataEntity, attributes);
// Persist and refresh the entity.
businessObjectDataEntity = businessObjectDataDao.saveAndRefresh(businessObjectDataEntity);
// Create and return the business object data object from the persisted entity.
return businessObjectDataHelper.createBusinessObjectDataFromEntity(businessObjectDataEntity);
}
use of org.finra.herd.model.api.xml.Attribute 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;
}
Aggregations