-
Notifications
You must be signed in to change notification settings - Fork 246
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
refactor(api): expose dataplanes api v4alpha #4704
Open
ndr-brt
wants to merge
1
commit into
eclipse-edc:main
Choose a base branch
from
Think-iT-Labs:dataplane-instance-v4alpha
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...ipse/edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceV3Transformer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright (c) 2025 Cofinity-X | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Cofinity-X - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.transform.transformer.edc.from; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import jakarta.json.JsonBuilderFactory; | ||
import jakarta.json.JsonObject; | ||
import org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance; | ||
import org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstanceStates; | ||
import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; | ||
import org.eclipse.edc.transform.spi.TransformerContext; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_DEST_TYPES; | ||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_SOURCE_TYPES; | ||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_TRANSFER_TYPES; | ||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_STATE; | ||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_STATE_TIMESTAMP; | ||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.LAST_ACTIVE; | ||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.PROPERTIES; | ||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.TURN_COUNT; | ||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.URL; | ||
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; | ||
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; | ||
|
||
public class JsonObjectFromDataPlaneInstanceV3Transformer extends AbstractJsonLdTransformer<DataPlaneInstance, JsonObject> { | ||
private final JsonBuilderFactory jsonFactory; | ||
private final ObjectMapper mapper; | ||
|
||
public JsonObjectFromDataPlaneInstanceV3Transformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper) { | ||
super(DataPlaneInstance.class, JsonObject.class); | ||
this.jsonFactory = jsonFactory; | ||
this.mapper = mapper; | ||
} | ||
|
||
@Override | ||
public @Nullable JsonObject transform(@NotNull DataPlaneInstance dataPlaneInstance, @NotNull TransformerContext context) { | ||
var builder = jsonFactory.createObjectBuilder() | ||
.add(ID, dataPlaneInstance.getId()) | ||
.add(TYPE, DataPlaneInstance.DATAPLANE_INSTANCE_TYPE) | ||
.add(URL, dataPlaneInstance.getUrl().toString()) | ||
.add(LAST_ACTIVE, dataPlaneInstance.getLastActive()) | ||
.add(TURN_COUNT, dataPlaneInstance.getTurnCount()); | ||
|
||
if (dataPlaneInstance.getProperties() != null && !dataPlaneInstance.getProperties().isEmpty()) { | ||
var propBuilder = jsonFactory.createObjectBuilder(); | ||
transformProperties(dataPlaneInstance.getProperties(), propBuilder, mapper, context); | ||
builder.add(PROPERTIES, propBuilder); | ||
} | ||
|
||
var srcBldr = jsonFactory.createArrayBuilder(dataPlaneInstance.getAllowedSourceTypes()); | ||
builder.add(ALLOWED_SOURCE_TYPES, srcBldr); | ||
|
||
var dstBldr = jsonFactory.createArrayBuilder(dataPlaneInstance.getAllowedDestTypes()); | ||
Check notice Code scanning / CodeQL Deprecated method or constructor invocation Note
Invoking
DataPlaneInstance.getAllowedDestTypes Error loading related location Loading |
||
builder.add(ALLOWED_DEST_TYPES, dstBldr); | ||
|
||
var transferTypesBldr = jsonFactory.createArrayBuilder(dataPlaneInstance.getAllowedTransferTypes()); | ||
builder.add(ALLOWED_TRANSFER_TYPES, transferTypesBldr); | ||
|
||
var state = Optional.ofNullable(DataPlaneInstanceStates.from(dataPlaneInstance.getState())) | ||
.map(Enum::name) | ||
.orElse(null); | ||
|
||
addIfNotNull(state, DATAPLANE_INSTANCE_STATE, builder); | ||
|
||
builder.add(DATAPLANE_INSTANCE_STATE_TIMESTAMP, dataPlaneInstance.getStateTimestamp()); | ||
|
||
return builder.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
.../edc/transform/transformer/edc/from/JsonObjectFromDataPlaneInstanceV3TransformerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
/* | ||
* Copyright (c) 2025 Cofinity-X | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Apache License, Version 2.0 which is available at | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* Contributors: | ||
* Cofinity-X - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.transform.transformer.edc.from; | ||
|
||
import jakarta.json.Json; | ||
import jakarta.json.JsonString; | ||
import org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance; | ||
import org.eclipse.edc.transform.spi.TransformerContext; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Map; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_DEST_TYPES; | ||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_SOURCE_TYPES; | ||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.ALLOWED_TRANSFER_TYPES; | ||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_STATE; | ||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.DATAPLANE_INSTANCE_STATE_TIMESTAMP; | ||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.LAST_ACTIVE; | ||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.PROPERTIES; | ||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.TURN_COUNT; | ||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstance.URL; | ||
import static org.eclipse.edc.connector.dataplane.selector.spi.instance.DataPlaneInstanceStates.AVAILABLE; | ||
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; | ||
import static org.eclipse.edc.jsonld.util.JacksonJsonLd.createObjectMapper; | ||
import static org.mockito.Mockito.mock; | ||
|
||
class JsonObjectFromDataPlaneInstanceV3TransformerTest { | ||
|
||
private final TransformerContext context = mock(); | ||
private JsonObjectFromDataPlaneInstanceV3Transformer transformer; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
transformer = new JsonObjectFromDataPlaneInstanceV3Transformer(Json.createBuilderFactory(Map.of()), createObjectMapper()); | ||
} | ||
|
||
@Test | ||
void transform() { | ||
var dpi = DataPlaneInstance.Builder.newInstance() | ||
.id("test-id") | ||
.url("http://foo.bar") | ||
.allowedSourceType("test-source-type") | ||
.allowedDestType("test-dest-type") | ||
.allowedTransferType("test-transfer-type") | ||
.lastActive(15) | ||
.turnCount(42) | ||
.property("foo", "bar") | ||
.build(); | ||
|
||
var jsonObject = transformer.transform(dpi, context); | ||
|
||
assertThat(jsonObject).isNotNull(); | ||
assertThat(jsonObject.getString(ID)).isEqualTo("test-id"); | ||
assertThat(jsonObject.getString(URL)).isEqualTo("http://foo.bar"); | ||
assertThat(jsonObject.getJsonArray(ALLOWED_SOURCE_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-source-type")); | ||
assertThat(jsonObject.getJsonArray(ALLOWED_DEST_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-dest-type")); | ||
assertThat(jsonObject.getJsonArray(ALLOWED_TRANSFER_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-transfer-type")); | ||
assertThat(jsonObject.getJsonNumber(LAST_ACTIVE).intValue()).isEqualTo(15); | ||
assertThat(jsonObject.getJsonNumber(TURN_COUNT).intValue()).isEqualTo(42); | ||
assertThat(jsonObject.getJsonObject(PROPERTIES).getJsonString("foo").getString()).isEqualTo("bar"); | ||
|
||
} | ||
|
||
@Test | ||
void transform_withState() { | ||
var dpi = DataPlaneInstance.Builder.newInstance() | ||
.id("test-id") | ||
.url("http://foo.bar") | ||
.allowedSourceType("test-source-type") | ||
.allowedDestType("test-dest-type") | ||
.allowedTransferType("test-transfer-type") | ||
.lastActive(15) | ||
.turnCount(42) | ||
.state(AVAILABLE.code()) | ||
.property("foo", "bar") | ||
.build(); | ||
|
||
var jsonObject = transformer.transform(dpi, context); | ||
|
||
assertThat(jsonObject).isNotNull(); | ||
assertThat(jsonObject.getString(ID)).isEqualTo("test-id"); | ||
assertThat(jsonObject.getString(URL)).isEqualTo("http://foo.bar"); | ||
assertThat(jsonObject.getJsonArray(ALLOWED_SOURCE_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-source-type")); | ||
assertThat(jsonObject.getJsonArray(ALLOWED_DEST_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-dest-type")); | ||
assertThat(jsonObject.getJsonArray(ALLOWED_TRANSFER_TYPES)).hasSize(1).allMatch(v -> ((JsonString) v).getString().equals("test-transfer-type")); | ||
assertThat(jsonObject.getJsonNumber(LAST_ACTIVE).intValue()).isEqualTo(15); | ||
assertThat(jsonObject.getJsonNumber(TURN_COUNT).intValue()).isEqualTo(42); | ||
assertThat(jsonObject.getString(DATAPLANE_INSTANCE_STATE)).isEqualTo(AVAILABLE.name()); | ||
assertThat(jsonObject.getJsonNumber(DATAPLANE_INSTANCE_STATE_TIMESTAMP).longValue()).isEqualTo(dpi.getStateTimestamp()); | ||
assertThat(jsonObject.getJsonObject(PROPERTIES).getJsonString("foo").getString()).isEqualTo("bar"); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check notice
Code scanning / CodeQL
Deprecated method or constructor invocation Note