use of org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest in project herd by FINRAOS.
the class RegisterBusinessObjectDataTest method testRegisterBusinessObjectDataJson.
@Test
public void testRegisterBusinessObjectDataJson() throws Exception {
BusinessObjectDataCreateRequest businessObjectDataCreateRequest = businessObjectDataServiceTestHelper.getNewBusinessObjectDataCreateRequest();
List<FieldExtension> fieldExtensionList = new ArrayList<>();
fieldExtensionList.add(buildFieldExtension("contentType", "${contentType}"));
fieldExtensionList.add(buildFieldExtension("businessObjectDataCreateRequest", "${businessObjectDataCreateRequest}"));
List<Parameter> parameters = new ArrayList<>();
parameters.add(buildParameter("contentType", "json"));
parameters.add(buildParameter("businessObjectDataCreateRequest", jsonHelper.objectToJson(businessObjectDataCreateRequest)));
Map<String, Object> variableValuesToValidate = new HashMap<>();
variableValuesToValidate.put(RegisterBusinessObjectData.VARIABLE_ID, VARIABLE_VALUE_NOT_NULL);
variableValuesToValidate.put(BaseJavaDelegate.VARIABLE_JSON_RESPONSE, VARIABLE_VALUE_NOT_NULL);
testActivitiServiceTaskSuccess(RegisterBusinessObjectData.class.getCanonicalName(), fieldExtensionList, parameters, variableValuesToValidate);
}
use of org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest in project herd by FINRAOS.
the class UploadDownloadServiceImpl method initiateUploadSingle.
@PublishNotificationMessages
@NamespacePermission(fields = { "#uploadSingleInitiationRequest?.sourceBusinessObjectFormatKey?.namespace", "#uploadSingleInitiationRequest?.targetBusinessObjectFormatKey?.namespace" }, permissions = NamespacePermissionEnum.WRITE)
@Override
public UploadSingleInitiationResponse initiateUploadSingle(UploadSingleInitiationRequest uploadSingleInitiationRequest) {
// Validate and trim the request parameters.
validateUploadSingleInitiationRequest(uploadSingleInitiationRequest);
// Get the business object format for the specified parameters and make sure it exists.
BusinessObjectFormatEntity sourceBusinessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(uploadSingleInitiationRequest.getSourceBusinessObjectFormatKey());
// Get the target business object format entity for the specified parameters and make sure it exists.
BusinessObjectFormatEntity targetBusinessObjectFormatEntity = businessObjectFormatDaoHelper.getBusinessObjectFormatEntity(uploadSingleInitiationRequest.getTargetBusinessObjectFormatKey());
// Get the S3 managed "loading dock" storage entity and make sure it exists.
StorageEntity sourceStorageEntity = storageDaoHelper.getStorageEntity(StorageEntity.MANAGED_LOADING_DOCK_STORAGE);
// Get S3 bucket name for the storage. Please note that since those values are required we pass a "true" flag.
String s3BucketName = storageHelper.getStorageBucketName(sourceStorageEntity);
// Get the S3 managed "external" storage entity and make sure it exists.
String targetStorageName;
if (uploadSingleInitiationRequest.getTargetStorageName() != null) {
targetStorageName = uploadSingleInitiationRequest.getTargetStorageName();
} else {
targetStorageName = configurationHelper.getProperty(ConfigurationValue.S3_EXTERNAL_STORAGE_NAME_DEFAULT);
}
StorageEntity targetStorageEntity = storageDaoHelper.getStorageEntity(targetStorageName);
assertTargetStorageEntityValid(targetStorageEntity);
// Generate a random UUID value.
String uuid = UUID.randomUUID().toString();
// Create business object data key with partition value set to the generated UUID.
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey(uploadSingleInitiationRequest.getSourceBusinessObjectFormatKey().getNamespace(), uploadSingleInitiationRequest.getSourceBusinessObjectFormatKey().getBusinessObjectDefinitionName(), uploadSingleInitiationRequest.getSourceBusinessObjectFormatKey().getBusinessObjectFormatUsage(), uploadSingleInitiationRequest.getSourceBusinessObjectFormatKey().getBusinessObjectFormatFileType(), uploadSingleInitiationRequest.getSourceBusinessObjectFormatKey().getBusinessObjectFormatVersion(), uuid, null, BusinessObjectDataEntity.BUSINESS_OBJECT_DATA_INITIAL_VERSION);
// Get a file upload specific S3 key prefix for the source storage based on the generated UUID.
String sourceStorageDirectoryPath = s3KeyPrefixHelper.buildS3KeyPrefix(sourceStorageEntity, sourceBusinessObjectFormatEntity, businessObjectDataKey);
String sourceStorageFilePath = String.format("%s/%s", sourceStorageDirectoryPath, uploadSingleInitiationRequest.getFile().getFileName());
// Create a business object data create request.
BusinessObjectDataCreateRequest sourceBusinessObjectDataCreateRequest = businessObjectDataHelper.createBusinessObjectDataCreateRequest(sourceBusinessObjectFormatEntity, uuid, BusinessObjectDataStatusEntity.UPLOADING, uploadSingleInitiationRequest.getBusinessObjectDataAttributes(), sourceStorageEntity, sourceStorageDirectoryPath, sourceStorageFilePath, uploadSingleInitiationRequest.getFile().getFileSizeBytes(), null);
// Create a new business object data instance. Set the flag to false, since for the file upload service the file size value is optional.
BusinessObjectData sourceBusinessObjectData = businessObjectDataDaoHelper.createBusinessObjectData(sourceBusinessObjectDataCreateRequest, false);
// Get a file upload specific S3 key prefix for the target storage based on the generated UUID.
String targetStorageDirectoryPath = s3KeyPrefixHelper.buildS3KeyPrefix(targetStorageEntity, targetBusinessObjectFormatEntity, businessObjectDataKey);
String targetStorageFilePath = String.format("%s/%s", targetStorageDirectoryPath, uploadSingleInitiationRequest.getFile().getFileName());
uploadDownloadHelperService.assertS3ObjectKeyDoesNotExist(storageHelper.getStorageBucketName(targetStorageEntity), targetStorageFilePath);
// Create a target business object data based on the source business object data and target business object format.
BusinessObjectDataCreateRequest targetBusinessObjectDataCreateRequest = businessObjectDataHelper.createBusinessObjectDataCreateRequest(targetBusinessObjectFormatEntity, uuid, BusinessObjectDataStatusEntity.UPLOADING, uploadSingleInitiationRequest.getBusinessObjectDataAttributes(), targetStorageEntity, targetStorageDirectoryPath, targetStorageFilePath, uploadSingleInitiationRequest.getFile().getFileSizeBytes(), null);
// Create a target business object data instance. Set the flag to false, since for the file upload service the file size value is optional.
BusinessObjectData targetBusinessObjectData = businessObjectDataDaoHelper.createBusinessObjectData(targetBusinessObjectDataCreateRequest, false);
// Get decrypted AWS ARN of the role that is required to provide access to S3_MANAGED_LOADING_DOCK storage.
String awsRoleArn = getStorageUploadRoleArn(sourceStorageEntity);
// Get expiration interval for the pre-signed URL to be generated.
Integer awsRoleDurationSeconds = getStorageUploadSessionDuration(sourceStorageEntity);
String awsKmsKeyId = storageHelper.getStorageKmsKeyId(sourceStorageEntity);
// Get the temporary security credentials to access S3_MANAGED_STORAGE.
Credentials assumedSessionCredentials = stsDao.getTemporarySecurityCredentials(awsHelper.getAwsParamsDto(), String.valueOf(sourceBusinessObjectData.getId()), awsRoleArn, awsRoleDurationSeconds, createUploaderPolicy(s3BucketName, sourceStorageFilePath, awsKmsKeyId));
// Create the response.
UploadSingleInitiationResponse response = new UploadSingleInitiationResponse();
response.setSourceBusinessObjectData(sourceBusinessObjectData);
response.setTargetBusinessObjectData(targetBusinessObjectData);
response.setFile(uploadSingleInitiationRequest.getFile());
response.setUuid(uuid);
response.setAwsAccessKey(assumedSessionCredentials.getAccessKeyId());
response.setAwsSecretKey(assumedSessionCredentials.getSecretAccessKey());
response.setAwsSessionToken(assumedSessionCredentials.getSessionToken());
response.setAwsSessionExpirationTime(HerdDateUtils.getXMLGregorianCalendarValue(assumedSessionCredentials.getExpiration()));
response.setAwsKmsKeyId(awsKmsKeyId);
response.setTargetStorageName(targetStorageName);
return response;
}
use of org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest in project herd by FINRAOS.
the class DataBridgeWebClient method preRegisterBusinessObjectData.
/**
* Pre-registers business object data with the registration server.
*
* @param manifest the uploader input manifest file
* @param storageName the storage name
* @param createNewVersion if not set, only initial version of the business object data is allowed to be created
*
* @return the business object data returned by the registration server.
* @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.
*/
@SuppressFBWarnings(value = "VA_FORMAT_STRING_USES_NEWLINE", justification = "We will use the standard carriage return character.")
public BusinessObjectData preRegisterBusinessObjectData(UploaderInputManifestDto manifest, String storageName, Boolean createNewVersion) throws IOException, JAXBException, URISyntaxException {
LOGGER.info("Pre-registering business object data with the registration server...");
BusinessObjectDataCreateRequest request = new BusinessObjectDataCreateRequest();
request.setNamespace(manifest.getNamespace());
request.setBusinessObjectDefinitionName(manifest.getBusinessObjectDefinitionName());
request.setBusinessObjectFormatUsage(manifest.getBusinessObjectFormatUsage());
request.setBusinessObjectFormatFileType(manifest.getBusinessObjectFormatFileType());
request.setBusinessObjectFormatVersion(Integer.parseInt(manifest.getBusinessObjectFormatVersion()));
request.setPartitionKey(manifest.getPartitionKey());
request.setPartitionValue(manifest.getPartitionValue());
request.setSubPartitionValues(manifest.getSubPartitionValues());
request.setCreateNewVersion(createNewVersion);
request.setStatus(BusinessObjectDataStatusEntity.UPLOADING);
List<StorageUnitCreateRequest> storageUnits = new ArrayList<>();
request.setStorageUnits(storageUnits);
StorageUnitCreateRequest storageUnit = new StorageUnitCreateRequest();
storageUnits.add(storageUnit);
storageUnit.setStorageName(storageName);
// Add business object data attributes, if any.
if (manifest.getAttributes() != null) {
List<Attribute> attributes = new ArrayList<>();
request.setAttributes(attributes);
for (Map.Entry<String, String> entry : manifest.getAttributes().entrySet()) {
Attribute attribute = new Attribute();
attributes.add(attribute);
attribute.setName(entry.getKey());
attribute.setValue(entry.getValue());
}
}
// Add business object data parents, if any.
request.setBusinessObjectDataParents(manifest.getBusinessObjectDataParents());
// Create a JAXB context and marshaller
JAXBContext requestContext = JAXBContext.newInstance(BusinessObjectDataCreateRequest.class);
Marshaller requestMarshaller = requestContext.createMarshaller();
requestMarshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name());
requestMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
StringWriter sw = new StringWriter();
requestMarshaller.marshal(request, sw);
BusinessObjectData businessObjectData;
try (CloseableHttpClient client = httpClientOperations.createHttpClient()) {
URI uri = new URIBuilder().setScheme(getUriScheme()).setHost(regServerAccessParamsDto.getRegServerHost()).setPort(regServerAccessParamsDto.getRegServerPort()).setPath(HERD_APP_REST_URI_PREFIX + "/businessObjectData").build();
HttpPost post = new HttpPost(uri);
post.addHeader("Content-Type", DEFAULT_CONTENT_TYPE);
post.addHeader("Accepts", DEFAULT_ACCEPT);
// If SSL is enabled, set the client authentication header.
if (regServerAccessParamsDto.isUseSsl()) {
post.addHeader(getAuthorizationHeader());
}
post.setEntity(new StringEntity(sw.toString()));
LOGGER.info(String.format(" HTTP POST URI: %s", post.getURI().toString()));
LOGGER.info(String.format(" HTTP POST Headers: %s", Arrays.toString(post.getAllHeaders())));
LOGGER.info(String.format(" HTTP POST Entity Content:%n%s", sw.toString()));
businessObjectData = getBusinessObjectData(httpClientOperations.execute(client, post), "register business object data with the registration server");
}
LOGGER.info(String.format("Successfully pre-registered business object data with the registration server. businessObjectDataId=%s", businessObjectData.getId()));
return businessObjectData;
}
use of org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest in project herd by FINRAOS.
the class BusinessObjectDataHelper method createBusinessObjectDataCreateRequest.
/**
* Validates the upload single initiation request. This method also trims the request parameters.
*
* @param businessObjectFormatEntity the business object format entity
* @param uuid the UUID
* @param businessObjectDataStatus the status of the business object data
* @param attributes the list of attributes
* @param storageEntity the storage entity
* @param storageDirectoryPath the storage directory path
* @param storageFilePath the storage file path
* @param storageFileSizeBytes the storage file size in bytes
* @param storageFileRowCount the storage file row count
*
* @return the business object data create request.
*/
public BusinessObjectDataCreateRequest createBusinessObjectDataCreateRequest(BusinessObjectFormatEntity businessObjectFormatEntity, String uuid, String businessObjectDataStatus, List<Attribute> attributes, StorageEntity storageEntity, String storageDirectoryPath, String storageFilePath, Long storageFileSizeBytes, Long storageFileRowCount) {
BusinessObjectDataCreateRequest request = new BusinessObjectDataCreateRequest();
// Set the values required for the business object data partition key.
request.setNamespace(businessObjectFormatEntity.getBusinessObjectDefinition().getNamespace().getCode());
request.setBusinessObjectDefinitionName(businessObjectFormatEntity.getBusinessObjectDefinition().getName());
request.setBusinessObjectFormatUsage(businessObjectFormatEntity.getUsage());
request.setBusinessObjectFormatFileType(businessObjectFormatEntity.getFileType().getCode());
request.setBusinessObjectFormatVersion(businessObjectFormatEntity.getBusinessObjectFormatVersion());
request.setPartitionKey(businessObjectFormatEntity.getPartitionKey());
request.setPartitionValue(uuid);
// Set the business object data status.
request.setStatus(businessObjectDataStatus);
// Add a storage unit.
StorageUnitCreateRequest storageUnitCreateRequest = new StorageUnitCreateRequest();
request.setStorageUnits(Arrays.asList(storageUnitCreateRequest));
storageUnitCreateRequest.setStorageName(storageEntity.getName());
storageUnitCreateRequest.setStorageDirectory(new StorageDirectory(storageDirectoryPath));
storageUnitCreateRequest.setStorageFiles(Arrays.asList(new StorageFile(storageFilePath, storageFileSizeBytes, storageFileRowCount)));
// Set the attributes if any are specified.
request.setAttributes(attributes);
// Since we are using UUID as our partition value, set the flag to only allow business object data initial version creation.
request.setCreateNewVersion(false);
return request;
}
use of org.finra.herd.model.api.xml.BusinessObjectDataCreateRequest in project herd by FINRAOS.
the class BusinessObjectDataServiceTest method testBusinessObjectDataServiceMethodsNewTx.
/**
* This method is to get the coverage for the business object data service method that starts the new transaction.
*/
@Test
public void testBusinessObjectDataServiceMethodsNewTx() throws Exception {
BusinessObjectDataAvailabilityRequest businessObjectDataAvailabilityRequest = new BusinessObjectDataAvailabilityRequest();
try {
businessObjectDataServiceImpl.checkBusinessObjectDataAvailability(businessObjectDataAvailabilityRequest);
fail("Should throw an IllegalArgumentException.");
} catch (IllegalArgumentException e) {
assertEquals("A namespace must be specified.", e.getMessage());
}
BusinessObjectDataAvailabilityCollectionRequest businessObjectDataAvailabilityCollectionRequest = new BusinessObjectDataAvailabilityCollectionRequest();
try {
businessObjectDataServiceImpl.checkBusinessObjectDataAvailabilityCollection(businessObjectDataAvailabilityCollectionRequest);
fail("Should throw an IllegalArgumentException.");
} catch (IllegalArgumentException e) {
assertEquals("At least one business object data availability request must be specified.", e.getMessage());
}
BusinessObjectDataCreateRequest businessObjectDataCreateRequest = new BusinessObjectDataCreateRequest();
try {
businessObjectDataServiceImpl.createBusinessObjectData(businessObjectDataCreateRequest);
fail("Should throw an IllegalArgumentException.");
} catch (IllegalArgumentException e) {
assertEquals("A namespace must be specified.", e.getMessage());
}
try {
businessObjectDataServiceImpl.getBusinessObjectData(new BusinessObjectDataKey(), null, NO_BDATA_STATUS, NO_INCLUDE_BUSINESS_OBJECT_DATA_STATUS_HISTORY, NO_INCLUDE_STORAGE_UNIT_STATUS_HISTORY);
fail("Should throw an IllegalArgumentException.");
} catch (IllegalArgumentException e) {
assertEquals("A namespace must be specified.", e.getMessage());
}
try {
businessObjectDataServiceImpl.generateBusinessObjectDataDdl(new BusinessObjectDataDdlRequest());
fail("Should throw an IllegalArgumentException.");
} catch (IllegalArgumentException e) {
assertEquals("A namespace must be specified.", e.getMessage());
}
try {
businessObjectDataServiceImpl.generateBusinessObjectDataDdlCollection(new BusinessObjectDataDdlCollectionRequest());
fail("Should throw an IllegalArgumentException.");
} catch (IllegalArgumentException e) {
assertEquals("At least one business object data DDL request must be specified.", e.getMessage());
}
try {
businessObjectDataServiceImpl.invalidateUnregisteredBusinessObjectData(new BusinessObjectDataInvalidateUnregisteredRequest());
} catch (IllegalArgumentException e) {
assertEquals("The namespace is required", e.getMessage());
}
try {
businessObjectDataServiceImpl.retryStoragePolicyTransition(new BusinessObjectDataKey(), new BusinessObjectDataRetryStoragePolicyTransitionRequest());
} catch (IllegalArgumentException e) {
assertEquals("A namespace must be specified.", e.getMessage());
}
try {
businessObjectDataServiceImpl.restoreBusinessObjectData(new BusinessObjectDataKey(), EXPIRATION_IN_DAYS);
} catch (IllegalArgumentException e) {
assertEquals("A namespace must be specified.", e.getMessage());
}
}
Aggregations