Skip to content

Commit

Permalink
Post Sample dataset @Asset.json to local run datahub endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
xdxxxdx committed Aug 30, 2023
1 parent 95bcd0d commit b0d0eb1
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ dependencies {
implementation("io.acryl:datahub-client:0.10.5-5")
implementation("org.apache.httpcomponents:httpclient:4.5")
implementation("org.apache.httpcomponents:httpasyncclient:4.1.5")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.7.2")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
testImplementation(project(":core:common:transform-core"))
testImplementation(project(":core:control-plane:control-plane-core"))
testImplementation(project(":core:common:transform-core"))
testImplementation(project(":core:control-plane:control-plane-core"))
testImplementation(project(":core:data-plane-selector:data-plane-selector-core"))
testImplementation(project(":extensions:common:http"))
testImplementation(project(":core:common:junit"))
testImplementation(testFixtures(project(":extensions:common:http:jersey-core")))
testImplementation(libs.restAssured)
testImplementation(libs.awaitility)

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
Expand All @@ -42,8 +43,9 @@ public class DatasetEntityIngestor extends DataSpaceCatalogIngestorBase {
private DatasetProperties _datasetProperties(Asset asset) {
var createdAt=new com.linkedin.common.TimeStamp();
createdAt.setTime(asset.getCreatedAt());
Map assetProps = (Map) ((Map) asset.getProperties().get("asset")).get("properties");
return new DatasetProperties()
.setDescription(asset.getDescription())
.setDescription(assetProps.get("name").toString())
.setCreated(createdAt);

}
Expand Down Expand Up @@ -80,8 +82,21 @@ public Urn _urn(Asset asset) throws URISyntaxException {
* */
public Urn emitMetadataChangeProposal(Asset asset)
throws URISyntaxException, IOException, ExecutionException, InterruptedException {
Urn datasetUrn = _urn(asset);
//Urn datasetUrn = _urn(asset);

//Extract EDC assets json properties.
Map assets = (Map) asset.getProperties().get("asset");
Map dataAddress = (Map) asset.getProperties().get("dataAddress");

// creat proper urn which can be feed to datahub api.
// need to be a data platfrom urn.
// Make asset id of edc data model become a part of the urn.

var urn = "urn:li:dataset:(urn:li:dataPlatform:EDIT_EDC_Platform,asset: "+(String) assets.get("@id")+",TEST)";
Urn datasetUrn = new Urn(urn);
log.info("Pushing dataset to data space catalog");

// Emit datasetProperties aspect
Future<MetadataWriteResponse> responseFuture = emitter.emit(_metadataChangeProposalWrapper(_datasetProperties(asset), entityType, datasetUrn));
if(responseFuture.isDone() && responseFuture.get().isSuccess()){
Future<MetadataWriteResponse> editablePropsFut = emitter.emit(_metadataChangeProposalWrapper(_editableDatasetProperties(asset), entityType, datasetUrn));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public MetadataChangeProposalWrapper _metadataChangeProposalWrapper(RecordTempla
* Use `conf` files to configure this.
* */
public DataPlatformUrn _platformUrn(String entityType) throws URISyntaxException {
return DataPlatformUrn.createFromUrn(DataPlatformUrn.createFromTuple(entityType, "test"));
return DataPlatformUrn.createFromUrn(DataPlatformUrn.createFromTuple(entityType, "test:PROD"));
}

/***
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package be.imec.edit.ds.catalog;

import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.json.Json;
import java.util.LinkedHashMap;
import java.util.Map;
import jakarta.json.JsonObject;
import jakarta.json.JsonReader;
import java.io.IOException;
Expand All @@ -10,9 +13,19 @@
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.concurrent.ExecutionException;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
import org.eclipse.edc.jsonld.util.JacksonJsonLd;
import org.eclipse.edc.core.transform.transformer.to.JsonObjectToAssetTransformer;
import org.eclipse.edc.core.transform.transformer.to.JsonObjectToDataAddressTransformer;
import org.eclipse.edc.core.transform.transformer.to.JsonValueToGenericTypeTransformer;
import org.eclipse.edc.spi.result.Result;
import org.eclipse.edc.spi.types.domain.asset.Asset;
import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
import org.eclipse.edc.core.transform.TypeTransformerRegistryImpl;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -21,8 +34,18 @@


public class DataSpaceCatalogTest extends DatasetEntityIngestor {
private final ObjectMapper objectMapper = JacksonJsonLd.createObjectMapper();
Logger log = LoggerFactory.getLogger(this.getClass().getName());
private final TypeTransformerRegistry transformerRegistry = mock(TypeTransformerRegistry.class);
//private final TypeTransformerRegistry transformerRegistry = mock(TypeTransformerRegistry.class);
private final TypeTransformerRegistry transformer = new TypeTransformerRegistryImpl();


@BeforeEach
void setUp() {
transformer.register(new JsonObjectToAssetTransformer());
transformer.register(new JsonValueToGenericTypeTransformer(objectMapper));
transformer.register(new JsonObjectToDataAddressTransformer());
}

@Test
void ingestDataSetEntity() throws URISyntaxException, IOException {
Expand All @@ -32,7 +55,9 @@ void ingestDataSetEntity() throws URISyntaxException, IOException {
try (JsonReader jsonReader = Json.createReader(new StringReader(Files.readString(Paths.get(resource.toURI()))))) {

JsonObject readObject = jsonReader.readObject();
Result<Asset> asset = transformerRegistry.transform(readObject, Asset.class);

//Transform the json object to Asset object
Result<Asset> asset = transformer.transform(readObject, Asset.class);
emitMetadataChangeProposal(asset.getContent());
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@
"edc": "https://w3id.org/edc/v0.0.1/ns/"
},
"asset": {
"@id": "${assetId}",
"@id": "VSDS-IMEC-Test-Asset-ttl",
"properties": {
"name": "product description",
"contenttype": "application/json"
"name": "LDES Server endpoint for blue-bilke data",
"contenttype": "text/turtle"
}
},
"dataAddress": {
"name": "Test asset",
"baseUrl": "${source}",
"type": "HttpData"
"type": "HttpData",
"name": "VSDS-IMEC-Test",
"baseUrl": "https://openplanner.ilabt.imec.be/ldes/blue-bike",
"proxyPath": "true"
}
}

0 comments on commit b0d0eb1

Please sign in to comment.