Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added convenience for attribute registration #100

Merged
merged 1 commit into from
Jan 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,30 @@ public void testUpdateAttributeRetrieveFromListFunction() {
Assertions.assertDoesNotThrow(a::update);
}

@Test
public void testRegisterAttributeAsCriticalDataElement() {

// Given
wireMockRule.stubFor(WireMock.get(WireMock.urlEqualTo("/catalogs/common/datasets/SD0001/attributes"))
.willReturn(WireMock.aResponse()
.withHeader("Content-Type", "application/json")
.withStatus(200)
.withBodyFile("attribute/multiple-attribute-response.json")));

wireMockRule.stubFor(WireMock.post(WireMock.urlEqualTo("/catalogs/common/datasets/SD0001/attributes/A0001/registration"))
.withRequestBody(equalToJson(TestUtils.loadJsonForIt("attribute/attribute-registration-request.json")))
.withHeader("Content-Type", WireMock.equalTo("application/json"))
.willReturn(WireMock.aResponse()
.withHeader("Content-Type", "application/json")
.withStatus(200)));

Map<String, Attribute> attributes = getSdk().listAttributes("SD0001");
Attribute original = attributes.get("A0001");

// When & Then
Assertions.assertDoesNotThrow(original::register);
}

@Test
public void testDeleteAttribute() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,26 @@ protected String getApiPath() {
getFusion().getRootURL(), getCatalogIdentifier(), this.getDatasetIdentifier(), this.getIdentifier());
}

private String getApiPathForRegistration() {
return getApiPath() + "/registration";
}

/**
* Registers an attribute as a critical data element with the Fusion API.
* <p>
* This method sends a POST request to the Fusion API using the {@code create} method,
* specifying that the attribute being registered is a critical data element.
* </p>
*/
public void register() {
getFusion()
.create(
getApiPathForRegistration(),
AttributeRegistration.builder()
.isCriticalDataElement(true)
.build());
}

@Override
public Set<String> getRegisteredAttributes() {
Set<String> exclusions = super.getRegisteredAttributes();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.github.jpmorganchase.fusion.model;

import lombok.Builder;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import lombok.Value;

@Builder
@Value
@EqualsAndHashCode()
@ToString()
public class AttributeRegistration {
boolean isCriticalDataElement;
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ protected String getApiPathForLineage() {
return getApiPath() + "/lineage";
}

/**
* Creates a lineage in the Fusion API.
* <p>
* This method sends a POST request to the Fusion API to register the provided
* {@code DatasetLineage} object, establishing lineage information for a dataset.
* </p>
*
* @param lineage the {@code DatasetLineage} object representing the dataset lineage to be created
*/
public void createLineage(DatasetLineage lineage) {
getFusion().create(getApiPathForLineage(), lineage);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"isCriticalDataElement": true
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@
"isDatasetKey": false,
"sourceFieldId": "",
"title": "Term"
},
{
"id": 4,
"source": "Source System 1",
"term": "bizterm1",
"dataType": "String",
"description": "Description for A0001",
"identifier": "A0001",
"index": 1,
"isDatasetKey": false,
"sourceFieldId": "",
"title": "Title for A0001"
}
],
"title": "Attributes"
Expand Down