Skip to content

Commit

Permalink
Renamed ReportObj to Report
Browse files Browse the repository at this point in the history
  • Loading branch information
knighto82 committed Jan 13, 2025
1 parent 8e16938 commit b4c4963
Show file tree
Hide file tree
Showing 35 changed files with 115 additions and 123 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

import com.github.tomakehurst.wiremock.client.WireMock;
import io.github.jpmorganchase.fusion.model.Application;
import io.github.jpmorganchase.fusion.model.Dataset;
import io.github.jpmorganchase.fusion.model.Flow;
import io.github.jpmorganchase.fusion.model.ReportObj;
import io.github.jpmorganchase.fusion.model.Report;
import io.github.jpmorganchase.fusion.test.TestUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
Expand All @@ -29,7 +27,7 @@ public void testCreateReport() {
.withHeader("Content-Type", "application/json")
.withStatus(200)));

ReportObj report = reportSrOne();
Report report = reportSrOne();

// When & Then
Assertions.assertDoesNotThrow(report::create);
Expand All @@ -45,7 +43,7 @@ public void testCreateReportOverrideDefaultCatalog() {
.withHeader("Content-Type", "application/json")
.withStatus(200)));

ReportObj report = reportSrOne().toBuilder().catalogIdentifier("foobar").build();
Report report = reportSrOne().toBuilder().catalogIdentifier("foobar").build();

// When & Then
Assertions.assertDoesNotThrow(report::create);
Expand All @@ -62,7 +60,7 @@ public void testUpdateReport() {
.withStatus(200)));


ReportObj report = reportSrOne().toBuilder().description("Updated Sample report description 1").build();
Report report = reportSrOne().toBuilder().description("Updated Sample report description 1").build();


// When & Then
Expand All @@ -85,11 +83,11 @@ public void testUpdateReportRetrievedFromListReports() {
.withHeader("Content-Type", "application/json")
.withStatus(200)));

Map<String, ReportObj> reports = getSdk().listReports("common", "SR0001", true);
ReportObj originalReport = reports.get("SR0001");
Map<String, Report> reports = getSdk().listReports("common", "SR0001", true);
Report originalReport = reports.get("SR0001");

// When
ReportObj amendedReport = originalReport
Report amendedReport = originalReport
.toBuilder()
.description("Updated Sample report description 1")
.build();
Expand All @@ -108,7 +106,7 @@ public void testDeleteReport() {
.withHeader("Content-Type", "application/json")
.withStatus(200)));

ReportObj report = getSdk().builders().report()
Report report = getSdk().builders().report()
.identifier("SR0001")
.build();

Expand All @@ -124,7 +122,7 @@ public void testDeleteReportWithCatalogOverride() {
.withHeader("Content-Type", "application/json")
.withStatus(200)));

ReportObj report = getSdk().builders().report()
Report report = getSdk().builders().report()
.identifier("SR0001")
.catalogIdentifier("foobar")
.build();
Expand All @@ -143,7 +141,7 @@ public void testListReports() {
.withBodyFile("report/multiple-reports-response.json")));

// When
Map<String, ReportObj> reports = getSdk().listReports();
Map<String, Report> reports = getSdk().listReports();

// Then Verify the response
assertThat(reports.size(), is(equalTo(2)));
Expand All @@ -161,14 +159,14 @@ public void testListReportsUsingIdContains() {
.withBodyFile("report/multiple-reports-response.json")));

// When
Map<String, ReportObj> reports = getSdk().listReports("common", "SR0001", true);
Map<String, Report> reports = getSdk().listReports("common", "SR0001", true);

// Then Verify the response
assertThat(reports.size(), is(equalTo(1)));
assertThat(reports.containsKey("SR0001"), is(equalTo(true)));
}

private ReportObj reportSrOne() {
private Report reportSrOne() {
return getSdk().builders().report()
.identifier("SR0001")
.description("Sample report description 1")
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/github/jpmorganchase/fusion/Fusion.java
Original file line number Diff line number Diff line change
Expand Up @@ -372,11 +372,11 @@ public Map<String, Map<String, Object>> datasetResources(String catalogName, Str
* @throws ParsingException if the response from Fusion could not be parsed successfully
* @throws OAuthException if a token could not be retrieved for authentication
*/
public Map<String, ReportObj> listReports(String catalogName, String contains, boolean idContains) {
public Map<String, Report> listReports(String catalogName, String contains, boolean idContains) {
String url = String.format("%1scatalogs/%2s/datasets", this.rootURL, catalogName);
String json = this.api.callAPI(url);

Map<String, ReportObj> datasets =
Map<String, Report> datasets =
filterDatasets(responseParser.parseReportResponse(json, catalogName), contains, idContains);
return filterByType(datasets, "Report");
}
Expand All @@ -389,7 +389,7 @@ public Map<String, ReportObj> listReports(String catalogName, String contains, b
* @throws ParsingException if the response from Fusion could not be parsed successfully
* @throws OAuthException if a token could not be retrieved for authentication
*/
public Map<String, ReportObj> listReports(String catalogName) {
public Map<String, Report> listReports(String catalogName) {
return listReports(catalogName, null, false);
}

Expand All @@ -400,7 +400,7 @@ public Map<String, ReportObj> listReports(String catalogName) {
* @throws ParsingException if the response from Fusion could not be parsed successfully
* @throws OAuthException if a token could not be retrieved for authentication
*/
public Map<String, ReportObj> listReports() {
public Map<String, Report> listReports() {
return listReports(this.getDefaultCatalog(), null, false);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public Dataset.DatasetBuilder dataset() {
}

@Override
public ReportObj.ReportObjBuilder report() {
return ReportObj.builder().fusion(fusion).type(DatasetType.REPORT.getLabel());
public Report.ReportBuilder report() {
return Report.builder().fusion(fusion).type(DatasetType.REPORT.getLabel());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public interface Builders {
Dataset.DatasetBuilder dataset();

/**
* Returns a builder for creating a {@link io.github.jpmorganchase.fusion.model.ReportObj} object.
* Returns a builder for creating a {@link Report} object.
* The builder can be used to set properties and then create / update an instance of ReportObj.
*
* @return {@link io.github.jpmorganchase.fusion.model.ReportObj.ReportObjBuilder} the report builder
* @return {@link Report.ReportBuilder} the report builder
*/
ReportObj.ReportObjBuilder report();
Report.ReportBuilder report();

/**
* Returns a builder for creating a {@link DataDictionaryAttribute} object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ protected String getApiPath() {
@Override
public Set<String> getRegisteredAttributes() {
Set<String> exclusions = super.getRegisteredAttributes();
return VarArgsHelper.getFieldNames(exclusions, Attribute.class);
exclusions.addAll(VarArgsHelper.getFieldNames(Attribute.class));
return exclusions;
}

public static class AttributeBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ protected String getApiPath() {
@Override
public Set<String> getRegisteredAttributes() {
Set<String> exclusions = super.getRegisteredAttributes();
return VarArgsHelper.getFieldNames(exclusions, AttributeLineages.class);
exclusions.addAll(VarArgsHelper.getFieldNames(AttributeLineages.class));
return exclusions;
}

public static class AttributeLineagesBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ public String delete() {
@Override
public Set<String> getRegisteredAttributes() {
Set<String> exclusions = super.getRegisteredAttributes();
return VarArgsHelper.getFieldNames(exclusions, Attributes.class);
exclusions.addAll(VarArgsHelper.getFieldNames(Attributes.class));
return exclusions;
}

public static class AttributesBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ protected String getApiPath() {
@Override
public Set<String> getRegisteredAttributes() {
Set<String> exclusions = super.getRegisteredAttributes();
return VarArgsHelper.getFieldNames(exclusions, Catalog.class);
exclusions.addAll(VarArgsHelper.getFieldNames(Catalog.class));
return exclusions;
}

public static class CatalogBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.google.gson.annotations.Expose;
import io.github.jpmorganchase.fusion.Fusion;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import lombok.EqualsAndHashCode;
Expand Down Expand Up @@ -75,7 +74,7 @@ public Map<String, Object> getVarArgs() {
* @return set of attributes registered against this CatalogResource
*/
public Set<String> getRegisteredAttributes() {
Set<String> registered = VarArgsHelper.getFieldNames(new HashSet<>(), CatalogResource.class);
Set<String> registered = VarArgsHelper.getFieldNames(CatalogResource.class);
registered.addAll(Arrays.asList("@id", "@context", "@base"));
return registered;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ protected String getApiPath() {
@Override
public Set<String> getRegisteredAttributes() {
Set<String> exclusions = super.getRegisteredAttributes();
return VarArgsHelper.getFieldNames(exclusions, DataDictionaryAttribute.class);
exclusions.addAll(VarArgsHelper.getFieldNames(DataDictionaryAttribute.class));
return exclusions;
}

public static class DataDictionaryAttributeBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public String delete() {
@Override
public Set<String> getRegisteredAttributes() {
Set<String> exclusions = super.getRegisteredAttributes();
return VarArgsHelper.getFieldNames(exclusions, DataDictionaryAttributes.class);
exclusions.addAll(VarArgsHelper.getFieldNames(DataDictionaryAttributes.class));
return exclusions;
}

public static class DataDictionaryAttributesBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ protected String getApiPath() {
@Override
public Set<String> getRegisteredAttributes() {
Set<String> exclusions = super.getRegisteredAttributes();
return VarArgsHelper.getFieldNames(exclusions, DataProduct.class);
exclusions.addAll(VarArgsHelper.getFieldNames(DataProduct.class));
return exclusions;
}

public static class DataProductBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ protected String getApiPath() {
@Override
public Set<String> getRegisteredAttributes() {
Set<String> exclusions = super.getRegisteredAttributes();
return VarArgsHelper.getFieldNames(exclusions, Dataset.class);
exclusions.addAll(VarArgsHelper.getFieldNames(Dataset.class));
return exclusions;
}

public static class DatasetBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public DatasetSeries(
@Override
public Set<String> getRegisteredAttributes() {
Set<String> exclusions = super.getRegisteredAttributes();
return VarArgsHelper.getFieldNames(exclusions, DatasetSeries.class);
exclusions.addAll(VarArgsHelper.getFieldNames(DatasetSeries.class));
return exclusions;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ protected String getApiPath() {
@Override
public Set<String> getRegisteredAttributes() {
Set<String> exclusions = super.getRegisteredAttributes();
return VarArgsHelper.getFieldNames(exclusions, Distribution.class);
exclusions.addAll(VarArgsHelper.getFieldNames(Distribution.class));
return exclusions;
}

public static class DistributionBuilder {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
@Getter
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class ReportObj extends Dataset {
public class Report extends Dataset {

ReportDetail report;
String tier;

@Builder(toBuilder = true)
public ReportObj(
public Report(
@Builder.ObtainVia(method = "getIdentifier") String identifier,
@Builder.ObtainVia(method = "getVarArgs") Map<String, Object> varArgs,
@Builder.ObtainVia(method = "getFusion") Fusion fusion,
Expand Down Expand Up @@ -57,28 +57,29 @@ public ReportObj(
@Override
public Set<String> getRegisteredAttributes() {
Set<String> exclusions = super.getRegisteredAttributes();
return VarArgsHelper.getFieldNames(exclusions, ReportObj.class);
exclusions.addAll(VarArgsHelper.getFieldNames(Report.class));
return exclusions;
}

public static class ReportObjBuilder extends DatasetBuilder {
public static class ReportBuilder extends DatasetBuilder {
@SuppressWarnings("FieldCanBeLocal")
private Map<String, Object> varArgs;

private ReportObj.ReportObjBuilder report(ReportDetail report) {
private Report.ReportBuilder report(ReportDetail report) {
return this;
}

public ReportObj.ReportObjBuilder varArg(String key, Object value) {
public Report.ReportBuilder varArg(String key, Object value) {
this.varArgs = VarArgsHelper.varArg(key, value, this.varArgs);
return this;
}

public ReportObj.ReportObjBuilder varArgs(Map<String, Object> varArgs) {
public Report.ReportBuilder varArgs(Map<String, Object> varArgs) {
this.varArgs = VarArgsHelper.copyMap(varArgs);
return this;
}

public ReportObj.ReportObjBuilder tier(String tier) {
public Report.ReportBuilder tier(String tier) {
this.tier = tier;
if (null != tier && !tier.isEmpty()) {
this.report = ReportDetail.builder().tier(tier).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,11 @@ public static Map<String, Object> initializeMap() {
return new HashMap<>();
}

public static Set<String> getFieldNames(Set<String> exclusions, Class<?> resourceClass) {
Set<String> mutated = new HashSet<>(exclusions);
if (null != resourceClass) {
mutated.addAll(Arrays.stream(resourceClass.getDeclaredFields())
.map(Field::getName)
.filter(n -> !"this$0".equals(n))
.collect(Collectors.toSet()));
}
return mutated;
public static Set<String> getFieldNames(Class<?> resourceClass) {
if (null == resourceClass) return new HashSet<>();
return Arrays.stream(resourceClass.getDeclaredFields())
.map(Field::getName)
.filter(n -> !"this$0".equals(n))
.collect(Collectors.toSet());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public interface APIResponseParser {

Map<String, Dataset> parseDatasetResponse(String json, String catalog);

Map<String, ReportObj> parseReportResponse(String json, String catalog);
Map<String, Report> parseReportResponse(String json, String catalog);

Map<String, Attribute> parseAttributeResponse(String json, String catalog, String dataset);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,18 @@ public Map<String, Dataset> parseDatasetResponse(String json, String catalog) {
/**
* Parses a JSON response to extract a map of reports.
* <p>
* This method deserializes the given JSON string into a map of {@link ReportObj} objects.
* This method deserializes the given JSON string into a map of {@link Report} objects.
* Each report is enriched with additional context, such as variable arguments and the
* {@code fusion} configuration, using the builder pattern.
* </p>
*
* @param json the JSON response containing dataset information to be parsed.
* @return a map where the keys represent dataset identifiers (or relevant keys from the JSON structure),
* and the values are {@link ReportObj} objects enriched with context.
* and the values are {@link Report} objects enriched with context.
*/
@Override
public Map<String, ReportObj> parseReportResponse(String json, String catalog) {
return parseResourcesWithVarArgsFromResponse(json, ReportObj.class, (resource, mc) -> resource.toBuilder()
public Map<String, Report> parseReportResponse(String json, String catalog) {
return parseResourcesWithVarArgsFromResponse(json, Report.class, (resource, mc) -> resource.toBuilder()
.varArgs(mc.getVarArgs())
.fusion(fusion)
.catalogIdentifier(catalog)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class GsonAPIRequestSerializer implements APIRequestSerializer {
public GsonAPIRequestSerializer() {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(Dataset.class, new DatasetSerializer());
gsonBuilder.registerTypeAdapter(ReportObj.class, new ReportSerializer());
gsonBuilder.registerTypeAdapter(Report.class, new ReportSerializer());
gsonBuilder.registerTypeAdapter(DataDictionaryAttribute.class, new DataDictionaryAttributeSerializer());
gsonBuilder.registerTypeAdapter(DataDictionaryAttributes.class, new DataDictionaryAttributesSerializer());
gsonBuilder.registerTypeAdapter(Attribute.class, new AttributeSerializer());
Expand Down
Loading

0 comments on commit b4c4963

Please sign in to comment.