use of org.finra.herd.model.api.xml.BusinessObjectDataStorageFilesCreateResponse in project herd by FINRAOS.
the class DataBridgeWebClientTest method testGetBusinessObjectDataStorageFilesCreateResponse200BadContentReturnsNull.
@Test
public void testGetBusinessObjectDataStorageFilesCreateResponse200BadContentReturnsNull() throws Exception {
CloseableHttpResponse httpResponse = new MockCloseableHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "testReasonPhrase"), false);
httpResponse.setEntity(new StringEntity("invalid xml"));
executeWithoutLogging(DataBridgeWebClient.class, () -> {
BusinessObjectDataStorageFilesCreateResponse businessObjectDataStorageFilesCreateResponse = dataBridgeWebClient.getBusinessObjectDataStorageFilesCreateResponse(httpResponse);
assertNull("businessObjectDataStorageFilesCreateResponse", businessObjectDataStorageFilesCreateResponse);
});
}
use of org.finra.herd.model.api.xml.BusinessObjectDataStorageFilesCreateResponse in project herd by FINRAOS.
the class DataBridgeWebClientTest method testAddStorageFilesResponse200BadContentReturnsNull.
@Test
public void testAddStorageFilesResponse200BadContentReturnsNull() throws Exception {
dataBridgeWebClient.regServerAccessParamsDto.setRegServerHost(MockHttpClientOperationsImpl.HOSTNAME_RESPOND_WITH_STATUS_CODE_200_AND_INVALID_CONTENT);
dataBridgeWebClient.regServerAccessParamsDto.setUseSsl(false);
BusinessObjectDataKey businessObjectDataKey = new BusinessObjectDataKey();
UploaderInputManifestDto manifest = getUploaderInputManifestDto();
S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto = new S3FileTransferRequestParamsDto();
String storageName = "testStorage";
BusinessObjectDataStorageFilesCreateResponse businessObjectDataStorageFilesCreateResponse = dataBridgeWebClient.addStorageFiles(businessObjectDataKey, manifest, s3FileTransferRequestParamsDto, storageName);
assertNull("businessObjectDataStorageFilesCreateResponse", businessObjectDataStorageFilesCreateResponse);
}
use of org.finra.herd.model.api.xml.BusinessObjectDataStorageFilesCreateResponse in project herd by FINRAOS.
the class DataBridgeWebClientTest method testGetBusinessObjectDataStorageFilesCreateResponse200ValidResponseHttpResponseThrowsExceptionOnClose.
@Test
public void testGetBusinessObjectDataStorageFilesCreateResponse200ValidResponseHttpResponseThrowsExceptionOnClose() throws Exception {
CloseableHttpResponse httpResponse = new MockCloseableHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "testReasonPhrase"), true);
httpResponse.setEntity(new StringEntity(xmlHelper.objectToXml(new BusinessObjectDataStorageFilesCreateResponse())));
executeWithoutLogging(DataBridgeWebClient.class, () -> {
BusinessObjectDataStorageFilesCreateResponse businessObjectDataStorageFilesCreateResponse = dataBridgeWebClient.getBusinessObjectDataStorageFilesCreateResponse(httpResponse);
assertNotNull("businessObjectDataStorageFilesCreateResponse", businessObjectDataStorageFilesCreateResponse);
});
}
use of org.finra.herd.model.api.xml.BusinessObjectDataStorageFilesCreateResponse in project herd by FINRAOS.
the class AddBusinessObjectDataStorageFiles method executeImpl.
@Override
public void executeImpl(DelegateExecution execution) throws Exception {
String contentTypeString = activitiHelper.getRequiredExpressionVariableAsString(contentType, execution, "ContentType").trim();
String requestString = activitiHelper.getRequiredExpressionVariableAsString(businessObjectDataStorageFilesCreateRequest, execution, "BusinessObjectDataCreateRequest").trim();
BusinessObjectDataStorageFilesCreateRequest request = getRequestObject(contentTypeString, requestString, BusinessObjectDataStorageFilesCreateRequest.class);
// Call the BusinessObjectDataStorageFiles service.
BusinessObjectDataStorageFilesCreateResponse businessObjectDataStorageFilesCreateResponse = businessObjectDataStorageFileService.createBusinessObjectDataStorageFiles(request);
// Set the JSON response as a workflow variable.
setJsonResponseAsWorkflowVariable(businessObjectDataStorageFilesCreateResponse, execution);
}
use of org.finra.herd.model.api.xml.BusinessObjectDataStorageFilesCreateResponse in project herd by FINRAOS.
the class DataBridgeWebClient method addStorageFiles.
/**
* Calls the registration server to add storage files to the business object data.
*
* @param businessObjectDataKey the business object data key
* @param manifest the uploader input manifest file
* @param s3FileTransferRequestParamsDto the S3 file transfer request parameters to be used to retrieve local path and S3 key prefix values
* @param storageName the storage name
*
* @return the business object data create storage files response turned 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 BusinessObjectDataStorageFilesCreateResponse addStorageFiles(BusinessObjectDataKey businessObjectDataKey, UploaderInputManifestDto manifest, S3FileTransferRequestParamsDto s3FileTransferRequestParamsDto, String storageName) throws IOException, JAXBException, URISyntaxException {
LOGGER.info("Adding storage files to the business object data ...");
BusinessObjectDataStorageFilesCreateRequest request = new BusinessObjectDataStorageFilesCreateRequest();
request.setNamespace(businessObjectDataKey.getNamespace());
request.setBusinessObjectDefinitionName(businessObjectDataKey.getBusinessObjectDefinitionName());
request.setBusinessObjectFormatUsage(businessObjectDataKey.getBusinessObjectFormatUsage());
request.setBusinessObjectFormatFileType(businessObjectDataKey.getBusinessObjectFormatFileType());
request.setBusinessObjectFormatVersion(businessObjectDataKey.getBusinessObjectFormatVersion());
request.setPartitionValue(businessObjectDataKey.getPartitionValue());
request.setSubPartitionValues(businessObjectDataKey.getSubPartitionValues());
request.setBusinessObjectDataVersion(businessObjectDataKey.getBusinessObjectDataVersion());
request.setStorageName(storageName);
List<StorageFile> storageFiles = new ArrayList<>();
request.setStorageFiles(storageFiles);
String localPath = s3FileTransferRequestParamsDto.getLocalPath();
String s3KeyPrefix = s3FileTransferRequestParamsDto.getS3KeyPrefix();
List<ManifestFile> localFiles = manifest.getManifestFiles();
for (ManifestFile manifestFile : localFiles) {
StorageFile storageFile = new StorageFile();
storageFiles.add(storageFile);
// Since the S3 key prefix represents a directory it is expected to contain a trailing '/' character.
storageFile.setFilePath((s3KeyPrefix + manifestFile.getFileName()).replaceAll("\\\\", "/"));
storageFile.setFileSizeBytes(Paths.get(localPath, manifestFile.getFileName()).toFile().length());
storageFile.setRowCount(manifestFile.getRowCount());
}
// Create a JAXB context and marshaller
JAXBContext requestContext = JAXBContext.newInstance(BusinessObjectDataStorageFilesCreateRequest.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);
BusinessObjectDataStorageFilesCreateResponse businessObjectDataStorageFilesCreateResponse;
try (CloseableHttpClient client = httpClientOperations.createHttpClient()) {
URI uri = new URIBuilder().setScheme(getUriScheme()).setHost(regServerAccessParamsDto.getRegServerHost()).setPort(regServerAccessParamsDto.getRegServerPort()).setPath(HERD_APP_REST_URI_PREFIX + "/businessObjectDataStorageFiles").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()));
// getBusinessObjectDataStorageFilesCreateResponse() might return a null. That happens when the web client gets status code 200 back from
// the service (add storage files is a success), but it fails to retrieve or deserialize the actual HTTP response.
// Please note that processXmlHttpResponse() is responsible for logging the exception info as a warning.
businessObjectDataStorageFilesCreateResponse = getBusinessObjectDataStorageFilesCreateResponse(httpClientOperations.execute(client, post));
}
LOGGER.info("Successfully added storage files to the registered business object data.");
return businessObjectDataStorageFilesCreateResponse;
}
Aggregations