-
Notifications
You must be signed in to change notification settings - Fork 244
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: introduce DPS-API JSON-LD transformer registry (#3939)
- Loading branch information
1 parent
4ec736b
commit c3176a6
Showing
29 changed files
with
614 additions
and
31 deletions.
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
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
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
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
38 changes: 38 additions & 0 deletions
38
extensions/data-plane/data-plane-signaling/data-plane-signaling-transform/build.gradle.kts
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,38 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* 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: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
|
||
plugins { | ||
`java-library` | ||
} | ||
|
||
dependencies { | ||
api(project(":spi:common:json-ld-spi")) | ||
api(project(":spi:common:web-spi")) | ||
api(project(":spi:data-plane:data-plane-spi")) | ||
|
||
implementation(project(":core:common:transform-core")) // for the transformer registry impl | ||
implementation(project(":core:common:jersey-providers")) | ||
implementation(libs.jakarta.rsApi) | ||
|
||
testImplementation(project(":core:common:junit")) | ||
testImplementation(project(":extensions:common:json-ld")) | ||
} | ||
edcBuild { | ||
swagger { | ||
apiGroup.set("control-api") | ||
} | ||
} | ||
|
||
|
23 changes: 23 additions & 0 deletions
23
...va/org/eclipse/edc/connector/api/signaling/transform/SignalingApiTransformerRegistry.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,23 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* 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: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.connector.api.signaling.transform; | ||
|
||
import org.eclipse.edc.transform.spi.TypeTransformerRegistry; | ||
|
||
/** | ||
* Type transformer used in the data plane signaling api context | ||
*/ | ||
public interface SignalingApiTransformerRegistry extends TypeTransformerRegistry { | ||
} |
38 changes: 38 additions & 0 deletions
38
...rg/eclipse/edc/connector/api/signaling/transform/SignalingApiTransformerRegistryImpl.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,38 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* 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: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.connector.api.signaling.transform; | ||
|
||
import org.eclipse.edc.core.transform.TypeTransformerRegistryImpl; | ||
import org.eclipse.edc.spi.EdcException; | ||
import org.eclipse.edc.transform.spi.TypeTransformer; | ||
import org.eclipse.edc.transform.spi.TypeTransformerRegistry; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class SignalingApiTransformerRegistryImpl extends TypeTransformerRegistryImpl implements SignalingApiTransformerRegistry { | ||
private final TypeTransformerRegistry fallback; | ||
|
||
public SignalingApiTransformerRegistryImpl(TypeTransformerRegistry fallback) { | ||
this.fallback = fallback; | ||
} | ||
|
||
@Override | ||
public @NotNull <INPUT, OUTPUT> TypeTransformer<INPUT, OUTPUT> transformerFor(@NotNull INPUT input, @NotNull Class<OUTPUT> outputType) { | ||
try { | ||
return super.transformerFor(input, outputType); | ||
} catch (EdcException exception) { | ||
return fallback.transformerFor(input, outputType); | ||
} | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...connector/api/signaling/transform/from/JsonObjectFromDataFlowStartMessageTransformer.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,66 @@ | ||
/* | ||
* Copyright (c) 2024 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) | ||
* | ||
* 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: | ||
* Bayerische Motoren Werke Aktiengesellschaft (BMW AG) - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.connector.api.signaling.transform.from; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import jakarta.json.JsonBuilderFactory; | ||
import jakarta.json.JsonObject; | ||
import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; | ||
import org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage; | ||
import org.eclipse.edc.transform.spi.TransformerContext; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; | ||
import static org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage.EDC_DATA_FLOW_START_MESSAGE_AGREEMENT_ID; | ||
import static org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage.EDC_DATA_FLOW_START_MESSAGE_DATASET_ID; | ||
import static org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage.EDC_DATA_FLOW_START_MESSAGE_DESTINATION_CALLBACK_ADDRESS; | ||
import static org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage.EDC_DATA_FLOW_START_MESSAGE_DESTINATION_DATA_ADDRESS; | ||
import static org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage.EDC_DATA_FLOW_START_MESSAGE_FLOW_TYPE; | ||
import static org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage.EDC_DATA_FLOW_START_MESSAGE_PARTICIPANT_ID; | ||
import static org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage.EDC_DATA_FLOW_START_MESSAGE_PROPERTIES; | ||
import static org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage.EDC_DATA_FLOW_START_MESSAGE_SOURCE_DATA_ADDRESS; | ||
import static org.eclipse.edc.spi.types.domain.transfer.DataFlowStartMessage.EDC_DATA_FLOW_START_MESSAGE_TYPE; | ||
|
||
/** | ||
* Converts from a {@link DataFlowStartMessage} to a {@link JsonObject} in JSON-LD expanded form . | ||
*/ | ||
public class JsonObjectFromDataFlowStartMessageTransformer extends AbstractJsonLdTransformer<DataFlowStartMessage, JsonObject> { | ||
private final JsonBuilderFactory jsonFactory; | ||
private final ObjectMapper mapper; | ||
|
||
public JsonObjectFromDataFlowStartMessageTransformer(JsonBuilderFactory jsonFactory, ObjectMapper mapper) { | ||
super(DataFlowStartMessage.class, JsonObject.class); | ||
this.jsonFactory = jsonFactory; | ||
this.mapper = mapper; | ||
} | ||
|
||
@Override | ||
public @Nullable JsonObject transform(@NotNull DataFlowStartMessage message, @NotNull TransformerContext context) { | ||
var propertiesBuilder = jsonFactory.createObjectBuilder(); | ||
transformProperties(message.getProperties(), propertiesBuilder, mapper, context); | ||
return jsonFactory.createObjectBuilder() | ||
.add(TYPE, EDC_DATA_FLOW_START_MESSAGE_TYPE) | ||
.add(EDC_DATA_FLOW_START_MESSAGE_FLOW_TYPE, message.getFlowType().toString()) | ||
.add(EDC_DATA_FLOW_START_MESSAGE_AGREEMENT_ID, message.getAgreementId()) | ||
.add(EDC_DATA_FLOW_START_MESSAGE_DATASET_ID, message.getAssetId()) | ||
.add(EDC_DATA_FLOW_START_MESSAGE_PROPERTIES, propertiesBuilder) | ||
.add(EDC_DATA_FLOW_START_MESSAGE_DESTINATION_CALLBACK_ADDRESS, message.getCallbackAddress().toString()) | ||
.add(EDC_DATA_FLOW_START_MESSAGE_DESTINATION_DATA_ADDRESS, context.transform(message.getDestinationDataAddress(), JsonObject.class)) | ||
.add(EDC_DATA_FLOW_START_MESSAGE_SOURCE_DATA_ADDRESS, context.transform(message.getSourceDataAddress(), JsonObject.class)) | ||
.add(EDC_DATA_FLOW_START_MESSAGE_PARTICIPANT_ID, message.getParticipantId()) | ||
.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
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.