Skip to content

Commit

Permalink
Added capability for client to provider headers when uploading distri…
Browse files Browse the repository at this point in the history
…butions
  • Loading branch information
knighto82 committed Jun 25, 2024
1 parent 996d968 commit 2c64d92
Show file tree
Hide file tree
Showing 8 changed files with 551 additions and 100 deletions.
147 changes: 142 additions & 5 deletions src/main/java/io/github/jpmorganchase/fusion/Fusion.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
Expand Down Expand Up @@ -469,6 +470,7 @@ public InputStream downloadStream(String catalogName, String dataset, String ser
* @param fromDate the earliest date for which there is data in the distribution
* @param toDate the latest date for which there is data in the distribution
* @param createdDate the creation date for the distribution
* @param headers http headers to be provided in the request. For the headers with multiple instances, the value should be a comm-separated list
* @throws ApiInputValidationException if the specified file cannot be read
* @throws APICallException if the call to the Fusion API fails
* @throws FileUploadException if there is an issue handling the response from Fusion API
Expand All @@ -482,15 +484,44 @@ public void upload(
String filename,
LocalDate fromDate,
LocalDate toDate,
LocalDate createdDate) {
LocalDate createdDate,
Map<String, String> headers) {

String url = String.format(
"%scatalogs/%s/datasets/%s/datasetseries/%s/distributions/%s",
this.rootURL, catalogName, dataset, seriesMember, distribution);
String strFromDate = fromDate.format(dateTimeFormatter);
String strToDate = toDate.format(dateTimeFormatter);
String strCreatedDate = createdDate.format(dateTimeFormatter);
this.api.callAPIFileUpload(url, filename, catalogName, dataset, strFromDate, strToDate, strCreatedDate);
this.api.callAPIFileUpload(url, filename, catalogName, dataset, strFromDate, strToDate, strCreatedDate, headers);
}

/**
* Upload a new dataset series member to a catalog.
*
* @param catalogName identifier of the catalog to upload data into
* @param dataset the dataset identifier to upload against.
* @param seriesMember the series member identifier to add or replace
* @param distribution the distribution identifier, this is the file extension.
* @param filename a path to the file containing the data to upload
* @param fromDate the earliest date for which there is data in the distribution
* @param toDate the latest date for which there is data in the distribution
* @param createdDate the creation date for the distribution
* @throws ApiInputValidationException if the specified file cannot be read
* @throws APICallException if the call to the Fusion API fails
* @throws FileUploadException if there is an issue handling the response from Fusion API
* @throws OAuthException if a token could not be retrieved for authentication
**/
public void upload(
String catalogName,
String dataset,
String seriesMember,
String distribution,
String filename,
LocalDate fromDate,
LocalDate toDate,
LocalDate createdDate) {
this.upload(catalogName, dataset, seriesMember, distribution, filename, fromDate, toDate, createdDate, new HashMap<>());
}

/**
Expand All @@ -514,7 +545,33 @@ public void upload(
String distribution,
String filename,
LocalDate dataDate) {
this.upload(catalogName, dataset, seriesMember, distribution, filename, dataDate, dataDate, dataDate);
this.upload(catalogName, dataset, seriesMember, distribution, filename, dataDate, dataDate, dataDate, new HashMap<>());
}

/**
* Upload a new dataset series member to a catalog.
*
* @param catalogName identifier of the catalog to upload data into
* @param dataset the dataset identifier to upload against.
* @param seriesMember the series member identifier to add or replace
* @param distribution the distribution identifier, this is the file extension.
* @param filename a path to the file containing the data to upload
* @param dataDate the earliest, latest, and created date are all the same.
* @param headers http headers to be provided in the request. For the headers with multiple instances, the value should be a comm-separated list
* @throws ApiInputValidationException if the specified file cannot be read
* @throws APICallException if the call to the Fusion API fails
* @throws FileUploadException if there is an issue handling the response from Fusion API
* @throws OAuthException if a token could not be retrieved for authentication
**/
public void upload(
String catalogName,
String dataset,
String seriesMember,
String distribution,
String filename,
LocalDate dataDate,
Map<String, String> headers) {
this.upload(catalogName, dataset, seriesMember, distribution, filename, dataDate, dataDate, dataDate, headers);
}

/**
Expand All @@ -528,6 +585,7 @@ public void upload(
* @param fromDate the earliest date for which there is data in the distribution
* @param toDate the latest date for which there is data in the distribution
* @param createdDate the creation date for the distribution
* @param headers http headers to be provided in the request. For the headers with multiple instances, the value should be a comm-separated list
* @throws ApiInputValidationException if the specified stream cannot be read
* @throws APICallException if the call to the Fusion API fails
* @throws FileUploadException if there is an issue handling the response from Fusion API
Expand All @@ -541,15 +599,94 @@ public void upload(
InputStream data,
LocalDate fromDate,
LocalDate toDate,
LocalDate createdDate) {
LocalDate createdDate,
Map<String, String> headers) {

String url = String.format(
"%scatalogs/%s/datasets/%s/datasetseries/%s/distributions/%s",
this.rootURL, catalogName, dataset, seriesMember, distribution);
String strFromDate = fromDate.format(dateTimeFormatter);
String strToDate = toDate.format(dateTimeFormatter);
String strCreatedDate = createdDate.format(dateTimeFormatter);
this.api.callAPIFileUpload(url, data, catalogName, dataset, strFromDate, strToDate, strCreatedDate);
this.api.callAPIFileUpload(url, data, catalogName, dataset, strFromDate, strToDate, strCreatedDate, headers);
}

/**
* Upload a new dataset series member to a catalog.
*
* @param catalogName identifier of the catalog to upload data into
* @param dataset the dataset identifier to upload against.
* @param seriesMember the series member identifier to add or replace
* @param distribution the distribution identifier, this is the file extension.
* @param data am InputStream of the data to be uploaded
* @param fromDate the earliest date for which there is data in the distribution
* @param toDate the latest date for which there is data in the distribution
* @param createdDate the creation date for the distribution
* @throws ApiInputValidationException if the specified stream cannot be read
* @throws APICallException if the call to the Fusion API fails
* @throws FileUploadException if there is an issue handling the response from Fusion API
* @throws OAuthException if a token could not be retrieved for authentication
**/
public void upload(
String catalogName,
String dataset,
String seriesMember,
String distribution,
InputStream data,
LocalDate fromDate,
LocalDate toDate,
LocalDate createdDate) {
this.upload(catalogName, dataset, seriesMember, distribution, data, fromDate, toDate, createdDate, new HashMap<>());
}

/**
* Upload a new dataset series member to a catalog.
*
* @param catalogName identifier of the catalog to upload data into
* @param dataset the dataset identifier to upload against.
* @param seriesMember the series member identifier to add or replace
* @param distribution the distribution identifier, this is the file extension.
* @param data am InputStream of the data to be uploaded
* @param dataDate the earliest, latest, and created date are all the same.
* @throws ApiInputValidationException if the specified stream cannot be read
* @throws APICallException if the call to the Fusion API fails
* @throws FileUploadException if there is an issue handling the response from Fusion API
* @throws OAuthException if a token could not be retrieved for authentication
**/
public void upload(
String catalogName,
String dataset,
String seriesMember,
String distribution,
InputStream data,
LocalDate dataDate) {
this.upload(catalogName, dataset, seriesMember, distribution, data, dataDate, dataDate, dataDate, new HashMap<>());
}

/**
* Upload a new dataset series member to a catalog.
*
* @param catalogName identifier of the catalog to upload data into
* @param dataset the dataset identifier to upload against.
* @param seriesMember the series member identifier to add or replace
* @param distribution the distribution identifier, this is the file extension.
* @param data am InputStream of the data to be uploaded
* @param dataDate the earliest, latest, and created date are all the same.
* @param headers http headers to be provided in the request. For the headers with multiple instances, the value should be a comm-separated list
* @throws ApiInputValidationException if the specified stream cannot be read
* @throws APICallException if the call to the Fusion API fails
* @throws FileUploadException if there is an issue handling the response from Fusion API
* @throws OAuthException if a token could not be retrieved for authentication
**/
public void upload(
String catalogName,
String dataset,
String seriesMember,
String distribution,
InputStream data,
LocalDate dataDate,
Map<String, String> headers) {
this.upload(catalogName, dataset, seriesMember, distribution, data, dataDate, dataDate, dataDate, headers);
}

public static FusionBuilder builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ public void callAPIFileUpload(
String dataset,
String fromDate,
String toDate,
String createdDate)
String createdDate,
Map<String, String> headers)
throws APICallException {
uploader.callAPIFileUpload(apiPath, fileName, catalogName, dataset, fromDate, toDate, createdDate);
uploader.callAPIFileUpload(apiPath, fileName, catalogName, dataset, fromDate, toDate, createdDate, headers);
}

@Override
Expand All @@ -84,9 +85,10 @@ public void callAPIFileUpload(
String dataset,
String fromDate,
String toDate,
String createdDate)
String createdDate,
Map<String, String> headers)
throws APICallException {
uploader.callAPIFileUpload(apiPath, data, catalogName, dataset, fromDate, toDate, createdDate);
uploader.callAPIFileUpload(apiPath, data, catalogName, dataset, fromDate, toDate, createdDate, headers);
}

public static FusionAPIManagerBuilder builder() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.jpmorganchase.fusion.api.exception.APICallException;
import java.io.InputStream;
import java.util.Map;

public interface APIUploadOperations {

Expand All @@ -12,7 +13,8 @@ default void callAPIFileUpload(
String dataset,
String fromDate,
String toDate,
String createdDate)
String createdDate,
Map<String, String> headers)
throws APICallException {}

default void callAPIFileUpload(
Expand All @@ -22,6 +24,7 @@ default void callAPIFileUpload(
String dataset,
String fromDate,
String toDate,
String createdDate)
String createdDate,
Map<String, String> headers)
throws APICallException {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public class FusionAPIUploadOperations implements APIUploadOperations {
* @param fromDate the earliest date that data is contained in the upload (in form yyyy-MM-dd).
* @param toDate the latest date that data is contained in the upload (in form yyyy-MM-dd).
* @param createdDate the creation date for the data is contained in the upload (in form yyyy-MM-dd).
* @param headers http headers to be provided in the request. For the headers with multiple instances, the value should be a comm-separated list
* @throws ApiInputValidationException if the specified file cannot be read
* @throws APICallException if the call to the Fusion API fails
* @throws FileUploadException if there is an issue handling the response from Fusion API
Expand All @@ -109,7 +110,8 @@ public void callAPIFileUpload(
String dataset,
String fromDate,
String toDate,
String createdDate)
String createdDate,
Map<String, String> headers)
throws APICallException {

callAPIFileUpload(UploadRequest.builder()
Expand All @@ -121,6 +123,7 @@ public void callAPIFileUpload(
.toDate(toDate)
.createdDate(createdDate)
.maxSinglePartFileSize(singlePartUploadSizeLimit)
.headers(headers)
.build());
}

Expand All @@ -132,6 +135,7 @@ public void callAPIFileUpload(
* @param fromDate the earliest date that data is contained in the upload (in form yyyy-MM-dd).
* @param toDate the latest date that data is contained in the upload (in form yyyy-MM-dd).
* @param createdDate the creation date for the data is contained in the upload (in form yyyy-MM-dd).
* @param headers http headers to be provided in the request. For the headers with multiple instances, the value should be a comm-separated list
* @throws ApiInputValidationException if the specified file cannot be read
* @throws APICallException if the call to the Fusion API fails
* @throws FileUploadException if there is an issue handling the response from Fusion API
Expand All @@ -145,7 +149,8 @@ public void callAPIFileUpload(
String dataset,
String fromDate,
String toDate,
String createdDate)
String createdDate,
Map<String, String> headers)
throws APICallException {

callAPIFileUpload(UploadRequest.builder()
Expand All @@ -157,6 +162,7 @@ public void callAPIFileUpload(
.toDate(toDate)
.createdDate(createdDate)
.maxSinglePartFileSize(singlePartUploadSizeLimit)
.headers(headers)
.build());
}

Expand All @@ -172,7 +178,7 @@ protected void performSinglePartUpload(UploadRequest ur) {

DigestDescriptor upload = digestProducer.execute(ur.getData());

Map<String, String> requestHeaders = new HashMap<>();
Map<String, String> requestHeaders = ur.getHeaders();
requestHeaders.put("accept", "*/*");
requestHeaders.put("Content-Type", "application/octet-stream");
requestHeaders.put("Content-Length", String.valueOf(upload.getSize()));
Expand Down Expand Up @@ -204,7 +210,7 @@ protected void performMultiPartUpload(UploadRequest ur) {
protected MultipartTransferContext callAPIToInitiateMultiPartUpload(UploadRequest ur) {
String startUploadPath = ur.getApiPath() + INITIATE_MULTIPART_UPLOAD_PATH;

Map<String, String> requestHeaders = new HashMap<>();
Map<String, String> requestHeaders = ur.getHeaders();
requestHeaders.put("accept", "*/*");
setSecurityHeaders(ur, requestHeaders);

Expand Down Expand Up @@ -287,7 +293,7 @@ protected UploadedPartContext callAPIToUploadPart(
DigestDescriptor digestOfPart = digestProducer.execute(
new ByteArrayInputStream(ByteBuffer.wrap(part, 0, read).array()));

Map<String, String> requestHeaders = new HashMap<>();
Map<String, String> requestHeaders = ur.getHeaders();
setSecurityHeaders(ur, requestHeaders);
requestHeaders.put("accept", "*/*");
requestHeaders.put("Content-Type", "application/octet-stream");
Expand All @@ -314,7 +320,7 @@ protected MultipartTransferContext callAPIToCompleteMultiPartUpload(
mtx.getOperation().getOperationId());
DigestDescriptor digestOfDigests = digestProducer.execute(mtx.digests());

Map<String, String> requestHeaders = new HashMap<>();
Map<String, String> requestHeaders = ur.getHeaders();
requestHeaders.put("Content-Type", "application/json");
setSecurityHeaders(ur, requestHeaders);
setDistributionHeaders(ur, digestOfDigests, requestHeaders);
Expand All @@ -332,7 +338,7 @@ protected MultipartTransferContext callAPIToAbortMultiPartUpload(MultipartTransf
ur.getApiPath(),
mtx.getOperation().getOperationId());

Map<String, String> requestHeaders = new HashMap<>();
Map<String, String> requestHeaders = ur.getHeaders();
setSecurityHeaders(ur, requestHeaders);

HttpResponse<String> completeResponse = httpClient.delete(completeTransferPath, requestHeaders, null);
Expand Down
Loading

0 comments on commit 2c64d92

Please sign in to comment.