-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: dataspace protocol negotiation transformer (#2771)
--------- Co-authored-by: Jan Peter Meyer <[email protected]> Co-authored-by: Ronja Quensel <[email protected]>
- Loading branch information
1 parent
70a44e4
commit b19024e
Showing
30 changed files
with
1,882 additions
and
47 deletions.
There are no files selected for viewing
21 changes: 0 additions & 21 deletions
21
data-protocols/dsp/dsp-negotiation/dsp-negotiation-spi/build.gradle.kts
This file was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
.../org.eclipse.edc.protocol.dsp.negotiation.transform/DspNegotiationTransformExtension.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,74 @@ | ||
/* | ||
* Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering | ||
* | ||
* 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: | ||
* Fraunhofer Institute for Software and Systems Engineering - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.protocol.dsp.negotiation.transform; | ||
|
||
import jakarta.json.Json; | ||
import org.eclipse.edc.jsonld.spi.transformer.JsonLdTransformerRegistry; | ||
import org.eclipse.edc.protocol.dsp.negotiation.transform.from.JsonObjectFromContractAgreementMessageTransformer; | ||
import org.eclipse.edc.protocol.dsp.negotiation.transform.from.JsonObjectFromContractAgreementVerificationMessageTransformer; | ||
import org.eclipse.edc.protocol.dsp.negotiation.transform.from.JsonObjectFromContractNegotiationEventMessageTransformer; | ||
import org.eclipse.edc.protocol.dsp.negotiation.transform.from.JsonObjectFromContractNegotiationTerminationMessageTransformer; | ||
import org.eclipse.edc.protocol.dsp.negotiation.transform.from.JsonObjectFromContractNegotiationTransformer; | ||
import org.eclipse.edc.protocol.dsp.negotiation.transform.from.JsonObjectFromContractRequestTransformer; | ||
import org.eclipse.edc.protocol.dsp.negotiation.transform.to.JsonObjectToContractAgreementMessageTransformer; | ||
import org.eclipse.edc.protocol.dsp.negotiation.transform.to.JsonObjectToContractAgreementVerificationMessageTransformer; | ||
import org.eclipse.edc.protocol.dsp.negotiation.transform.to.JsonObjectToContractNegotiationEventMessageTransformer; | ||
import org.eclipse.edc.protocol.dsp.negotiation.transform.to.JsonObjectToContractNegotiationTerminationMessageTransformer; | ||
import org.eclipse.edc.protocol.dsp.negotiation.transform.to.JsonObjectToContractRequestMessageTransformer; | ||
import org.eclipse.edc.runtime.metamodel.annotation.Extension; | ||
import org.eclipse.edc.runtime.metamodel.annotation.Inject; | ||
import org.eclipse.edc.spi.system.ServiceExtension; | ||
import org.eclipse.edc.spi.system.ServiceExtensionContext; | ||
import org.eclipse.edc.spi.types.TypeManager; | ||
|
||
import java.util.Map; | ||
|
||
/** | ||
* Provides the transformers for negotiation message types via the {@link JsonLdTransformerRegistry}. | ||
*/ | ||
@Extension(value = DspNegotiationTransformExtension.NAME) | ||
public class DspNegotiationTransformExtension implements ServiceExtension { | ||
|
||
public static final String NAME = "Dataspace Protocol Negotiation Transform Extension"; | ||
|
||
@Inject | ||
private TypeManager typeManager; | ||
|
||
@Inject | ||
private JsonLdTransformerRegistry registry; | ||
|
||
@Override | ||
public String name() { | ||
return NAME; | ||
} | ||
|
||
@Override | ||
public void initialize(ServiceExtensionContext context) { | ||
var builderFactory = Json.createBuilderFactory(Map.of()); | ||
|
||
registry.register(new JsonObjectFromContractAgreementMessageTransformer(builderFactory)); | ||
registry.register(new JsonObjectFromContractAgreementVerificationMessageTransformer(builderFactory)); | ||
registry.register(new JsonObjectFromContractNegotiationEventMessageTransformer(builderFactory)); | ||
registry.register(new JsonObjectFromContractNegotiationTerminationMessageTransformer(builderFactory)); | ||
registry.register(new JsonObjectFromContractNegotiationTransformer(builderFactory)); | ||
registry.register(new JsonObjectFromContractRequestTransformer(builderFactory)); | ||
|
||
registry.register(new JsonObjectToContractAgreementMessageTransformer()); | ||
registry.register(new JsonObjectToContractAgreementVerificationMessageTransformer()); | ||
registry.register(new JsonObjectToContractNegotiationEventMessageTransformer()); | ||
registry.register(new JsonObjectToContractRequestMessageTransformer()); | ||
registry.register(new JsonObjectToContractNegotiationTerminationMessageTransformer()); | ||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...col.dsp.negotiation.transform/from/JsonObjectFromContractAgreementMessageTransformer.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,64 @@ | ||
/* | ||
* Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering | ||
* | ||
* 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: | ||
* Fraunhofer Institute for Software and Systems Engineering - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.protocol.dsp.negotiation.transform.from; | ||
|
||
import jakarta.json.JsonBuilderFactory; | ||
import jakarta.json.JsonObject; | ||
import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreementMessage; | ||
import org.eclipse.edc.jsonld.spi.JsonLdKeywords; | ||
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.UUID; | ||
|
||
import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_AGREEMENT_MESSAGE; | ||
import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_AGREEMENT; | ||
import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; | ||
|
||
|
||
/** | ||
* Creates a dspace:ContractAgreementMessage as {@link JsonObject} from {@link ContractAgreementMessage}. | ||
*/ | ||
public class JsonObjectFromContractAgreementMessageTransformer extends AbstractJsonLdTransformer<ContractAgreementMessage, JsonObject> { | ||
|
||
private final JsonBuilderFactory jsonFactory; | ||
|
||
public JsonObjectFromContractAgreementMessageTransformer(JsonBuilderFactory jsonFactory) { | ||
super(ContractAgreementMessage.class, JsonObject.class); | ||
this.jsonFactory = jsonFactory; | ||
} | ||
|
||
@Override | ||
public @Nullable JsonObject transform(@NotNull ContractAgreementMessage object, @NotNull TransformerContext context) { | ||
var builder = jsonFactory.createObjectBuilder(); | ||
builder.add(JsonLdKeywords.ID, String.valueOf(UUID.randomUUID())); | ||
builder.add(JsonLdKeywords.TYPE, DSPACE_NEGOTIATION_AGREEMENT_MESSAGE); | ||
|
||
builder.add(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID, object.getProcessId()); | ||
|
||
var policy = context.transform(object.getContractAgreement().getPolicy(), JsonObject.class); | ||
if (policy == null) { | ||
context.reportProblem("Cannot transform from ContractAgreementMessage with null policy"); | ||
return null; | ||
} | ||
|
||
builder.add(DSPACE_NEGOTIATION_PROPERTY_AGREEMENT, policy); | ||
|
||
return builder.build(); | ||
} | ||
|
||
} |
54 changes: 54 additions & 0 deletions
54
...tiation.transform/from/JsonObjectFromContractAgreementVerificationMessageTransformer.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,54 @@ | ||
/* | ||
* Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering | ||
* | ||
* 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: | ||
* Fraunhofer Institute for Software and Systems Engineering - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.protocol.dsp.negotiation.transform.from; | ||
|
||
import jakarta.json.JsonBuilderFactory; | ||
import jakarta.json.JsonObject; | ||
import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreementVerificationMessage; | ||
import org.eclipse.edc.jsonld.spi.JsonLdKeywords; | ||
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.UUID; | ||
|
||
import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_AGREEMENT_VERIFICATION_MESSAGE; | ||
import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; | ||
|
||
/** | ||
* Creates a {@link JsonObject} from a {@link ContractAgreementVerificationMessage}. | ||
*/ | ||
public class JsonObjectFromContractAgreementVerificationMessageTransformer extends AbstractJsonLdTransformer<ContractAgreementVerificationMessage, JsonObject> { | ||
|
||
private final JsonBuilderFactory jsonFactory; | ||
|
||
public JsonObjectFromContractAgreementVerificationMessageTransformer(JsonBuilderFactory jsonFactory) { | ||
super(ContractAgreementVerificationMessage.class, JsonObject.class); | ||
this.jsonFactory = jsonFactory; | ||
} | ||
|
||
@Override | ||
public @Nullable JsonObject transform(@NotNull ContractAgreementVerificationMessage object, @NotNull TransformerContext context) { | ||
var builder = jsonFactory.createObjectBuilder(); | ||
builder.add(JsonLdKeywords.ID, String.valueOf(UUID.randomUUID())); | ||
builder.add(JsonLdKeywords.TYPE, DSPACE_NEGOTIATION_AGREEMENT_VERIFICATION_MESSAGE); | ||
|
||
builder.add(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID, object.getProcessId()); | ||
// TODO add mapping of cred:credentialSubject for signature processes | ||
|
||
return builder.build(); | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
....negotiation.transform/from/JsonObjectFromContractNegotiationEventMessageTransformer.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,81 @@ | ||
/* | ||
* Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering | ||
* | ||
* 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: | ||
* Fraunhofer Institute for Software and Systems Engineering - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.protocol.dsp.negotiation.transform.from; | ||
|
||
import jakarta.json.JsonBuilderFactory; | ||
import jakarta.json.JsonObject; | ||
import org.eclipse.edc.connector.contract.spi.types.agreement.ContractNegotiationEventMessage; | ||
import org.eclipse.edc.jsonld.spi.JsonLdKeywords; | ||
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.UUID; | ||
|
||
import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_EVENT_MESSAGE; | ||
import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_CHECKSUM; | ||
import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE; | ||
import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_ACCEPTED; | ||
import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_FINALIZED; | ||
import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; | ||
|
||
|
||
/** | ||
* Creates a {@link JsonObject} from a {@link ContractNegotiationEventMessage}. | ||
*/ | ||
public class JsonObjectFromContractNegotiationEventMessageTransformer extends AbstractJsonLdTransformer<ContractNegotiationEventMessage, JsonObject> { | ||
|
||
private final JsonBuilderFactory jsonFactory; | ||
|
||
public JsonObjectFromContractNegotiationEventMessageTransformer(JsonBuilderFactory jsonFactory) { | ||
super(ContractNegotiationEventMessage.class, JsonObject.class); | ||
this.jsonFactory = jsonFactory; | ||
} | ||
|
||
@Override | ||
public @Nullable JsonObject transform(@NotNull ContractNegotiationEventMessage object, @NotNull TransformerContext context) { | ||
var builder = jsonFactory.createObjectBuilder(); | ||
builder.add(JsonLdKeywords.ID, String.valueOf(UUID.randomUUID())); | ||
builder.add(JsonLdKeywords.TYPE, DSPACE_NEGOTIATION_EVENT_MESSAGE); | ||
|
||
builder.add(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID, object.getProcessId()); | ||
builder.add(DSPACE_NEGOTIATION_PROPERTY_CHECKSUM, object.getChecksum()); | ||
|
||
var eventType = eventType(object, context); | ||
if (eventType == null) { | ||
return null; | ||
} | ||
|
||
builder.add(DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE, eventType); | ||
|
||
|
||
return builder.build(); | ||
} | ||
|
||
private String eventType(ContractNegotiationEventMessage message, TransformerContext context) { | ||
switch (message.getType()) { | ||
case ACCEPTED: | ||
return DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_ACCEPTED; | ||
case FINALIZED: | ||
return DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_FINALIZED; | ||
default: | ||
context.reportProblem(String.format("Could not map eventType %s to %s or %s in ContractNegotiationEventMessage", message.getType(), | ||
DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_ACCEPTED, DSPACE_NEGOTIATION_PROPERTY_EVENT_TYPE_FINALIZED)); | ||
return null; | ||
} | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
...iation.transform/from/JsonObjectFromContractNegotiationTerminationMessageTransformer.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,58 @@ | ||
/* | ||
* Copyright (c) 2023 Fraunhofer Institute for Software and Systems Engineering | ||
* | ||
* 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: | ||
* Fraunhofer Institute for Software and Systems Engineering - initial API and implementation | ||
* | ||
*/ | ||
|
||
package org.eclipse.edc.protocol.dsp.negotiation.transform.from; | ||
|
||
import jakarta.json.JsonBuilderFactory; | ||
import jakarta.json.JsonObject; | ||
import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiationTerminationMessage; | ||
import org.eclipse.edc.jsonld.spi.JsonLdKeywords; | ||
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.UUID; | ||
|
||
import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_CODE; | ||
import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID; | ||
import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_PROPERTY_REASON; | ||
import static org.eclipse.edc.protocol.dsp.negotiation.transform.DspNegotiationPropertyAndTypeNames.DSPACE_NEGOTIATION_TERMINATION_MESSAGE; | ||
|
||
/** | ||
* Creates a {@link JsonObject} from a {@link ContractNegotiationTerminationMessage}. | ||
*/ | ||
public class JsonObjectFromContractNegotiationTerminationMessageTransformer extends AbstractJsonLdTransformer<ContractNegotiationTerminationMessage, JsonObject> { | ||
|
||
private final JsonBuilderFactory jsonFactory; | ||
|
||
public JsonObjectFromContractNegotiationTerminationMessageTransformer(JsonBuilderFactory jsonFactory) { | ||
super(ContractNegotiationTerminationMessage.class, JsonObject.class); | ||
this.jsonFactory = jsonFactory; | ||
} | ||
|
||
@Override | ||
public @Nullable JsonObject transform(@NotNull ContractNegotiationTerminationMessage object, @NotNull TransformerContext context) { | ||
var builder = jsonFactory.createObjectBuilder(); | ||
builder.add(JsonLdKeywords.ID, String.valueOf(UUID.randomUUID())); | ||
builder.add(JsonLdKeywords.TYPE, DSPACE_NEGOTIATION_TERMINATION_MESSAGE); | ||
|
||
builder.add(DSPACE_NEGOTIATION_PROPERTY_PROCESS_ID, object.getProcessId()); | ||
builder.add(DSPACE_NEGOTIATION_PROPERTY_REASON, object.getRejectionReason()); | ||
builder.add(DSPACE_NEGOTIATION_PROPERTY_CODE, object.getCode()); | ||
|
||
return builder.build(); | ||
} | ||
|
||
} |
Oops, something went wrong.