Skip to content

Commit

Permalink
fix: policy transformation processing expanded Json-Ld (#2990)
Browse files Browse the repository at this point in the history
* Fix policy transformation issues with expanded Json-Ld

* Formatting
  • Loading branch information
jimmarino authored May 12, 2023
1 parent 20793ff commit 38a158c
Show file tree
Hide file tree
Showing 40 changed files with 690 additions and 667 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@
import static org.eclipse.edc.protocol.dsp.transferprocess.api.TransferProcessApiPaths.TRANSFER_START;
import static org.eclipse.edc.protocol.dsp.transferprocess.api.TransferProcessApiPaths.TRANSFER_SUSPENSION;
import static org.eclipse.edc.protocol.dsp.transferprocess.api.TransferProcessApiPaths.TRANSFER_TERMINATION;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFERPROCESS_REQUEST_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFER_COMPLETION_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFER_PROCESS_REQUEST_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFER_START_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFER_TERMINATION_TYPE;
import static org.eclipse.edc.protocol.dsp.transform.util.TypeUtil.isOfExpectedType;
Expand All @@ -65,8 +65,8 @@
* Provides the endpoints for receiving messages regarding transfers, like initiating, completing
* and terminating a transfer process.
*/
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
@Path(BASE_PATH)
public class DspTransferProcessApiController {

Expand Down Expand Up @@ -113,7 +113,7 @@ public JsonObject getTransferProcess(@PathParam("id") String id) {
@POST
@Path(TRANSFER_INITIAL_REQUEST)
public Map<String, Object> initiateTransferProcess(JsonObject jsonObject, @HeaderParam(HttpHeaders.AUTHORIZATION) String token) {
var transferProcess = handleMessage(jsonObject, Optional.empty(), token, DSPACE_TRANSFERPROCESS_REQUEST_TYPE, TransferRequestMessage.class, protocolService::notifyRequested);
var transferProcess = handleMessage(jsonObject, Optional.empty(), token, DSPACE_TRANSFER_PROCESS_REQUEST_TYPE, TransferRequestMessage.class, protocolService::notifyRequested);

var transferProcessJson = registry.transform(transferProcess, JsonObject.class)
.orElseThrow(failure -> new EdcException(format("Response could not be created: %s", failure.getFailureDetail())));
Expand Down Expand Up @@ -193,8 +193,8 @@ public void transferProcessSuspension(@PathParam("id") String id) {
* @return the transfer process returned by the service call
*/
private <M extends TransferRemoteMessage> TransferProcess handleMessage(JsonObject request, Optional<String> processId, String token, String expectedType,
Class<M> messageClass, BiFunction<M, ClaimToken, ServiceResult<TransferProcess>> serviceCall) {
processId.ifPresentOrElse(id -> monitor.debug(() -> format("DSP: Incoming %s for transfer process %s", messageClass.getSimpleName(), id)),
Class<M> messageClass, BiFunction<M, ClaimToken, ServiceResult<TransferProcess>> serviceCall) {
processId.ifPresentOrElse(id -> monitor.debug(() -> format("DSP: Incoming %s for transfer process %s", messageClass.getSimpleName(), id)),
() -> monitor.debug(() -> format("DSP: Incoming %s for initiating a transfer process", messageClass.getSimpleName())));

var claimToken = checkAuthToken(token);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@
import static org.eclipse.edc.protocol.dsp.transferprocess.api.TransferProcessApiPaths.TRANSFER_START;
import static org.eclipse.edc.protocol.dsp.transferprocess.api.TransferProcessApiPaths.TRANSFER_SUSPENSION;
import static org.eclipse.edc.protocol.dsp.transferprocess.api.TransferProcessApiPaths.TRANSFER_TERMINATION;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFERPROCESS_REQUEST_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFER_COMPLETION_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFER_PROCESS_REQUEST_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFER_START_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFER_TERMINATION_TYPE;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -87,7 +87,7 @@ private static ClaimToken token() {
}

private static JsonObject transferRequestJson() {
return Json.createObjectBuilder().add(TYPE, DSPACE_TRANSFERPROCESS_REQUEST_TYPE).build();
return Json.createObjectBuilder().add(TYPE, DSPACE_TRANSFER_PROCESS_REQUEST_TYPE).build();
}

private static JsonObject transferStartJson() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@
*/
public interface DspTransferProcessPropertyAndTypeNames {

String DSPACE_TRANSFERPROCESS_REQUEST_TYPE = DSPACE_SCHEMA + "TransferRequestMessage";
String DSPACE_TRANSFER_PROCESS_REQUEST_TYPE = DSPACE_SCHEMA + "TransferRequestMessage";

String DSPACE_TRANSFER_START_TYPE = DSPACE_SCHEMA + "TransferStartMessage";

String DSPACE_TRANSFER_COMPLETION_TYPE = DSPACE_SCHEMA + "TransferCompletionMessage";

String DSPACE_TRANSFER_TERMINATION_TYPE = DSPACE_SCHEMA + "TransferTerminationMessage";

String DSPACE_TRANSFERPROCESS_TYPE = DSPACE_SCHEMA + "TransferProcess";
String DSPACE_TRANSFER_PROCESS_TYPE = DSPACE_SCHEMA + "TransferProcess";

String DSPACE_CONTRACT_AGREEMENT_TYPE = DSPACE_SCHEMA + "agreementId";
String DSPACE_CONTRACT_AGREEMENT_ID = DSPACE_SCHEMA + "agreementId";

String DSPACE_CALLBACK_ADDRESS_TYPE = DSPACE_SCHEMA + "callbackAddress";
String DSPACE_CALLBACK_ADDRESS = DSPACE_SCHEMA + "callbackAddress";

String DSPACE_PROCESSID_TYPE = DSPACE_SCHEMA + "processId";
String DSPACE_PROCESS_ID = DSPACE_SCHEMA + "processId";

String DSPACE_DATA_ADDRESS_TYPE = DSPACE_SCHEMA + "dataAddress";
String DSPACE_DATA_ADDRESS = DSPACE_SCHEMA + "dataAddress";

String DSPACE_CORRELATIONID_TYPE = DSPACE_SCHEMA + "correlationId";
String DSPACE_CORRELATION_ID = DSPACE_SCHEMA + "correlationId";

String DSPACE_STATE_TYPE = DSPACE_SCHEMA + "state";
String DSPACE_STATE = DSPACE_SCHEMA + "state";

String DSPACE_REASON_TYPE = DSPACE_SCHEMA + "reason";
String DSPACE_REASON = DSPACE_SCHEMA + "reason";

String DSPACE_CODE_TYPE = DSPACE_SCHEMA + "code";
String DSPACE_CODE = DSPACE_SCHEMA + "code";
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_PROCESSID_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_PROCESS_ID;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFER_COMPLETION_TYPE;


Expand All @@ -45,7 +45,7 @@ public JsonObjectFromTransferCompletionMessageTransformer(JsonBuilderFactory jso

builder.add(ID, String.valueOf(UUID.randomUUID()));
builder.add(TYPE, DSPACE_TRANSFER_COMPLETION_TYPE);
builder.add(DSPACE_PROCESSID_TYPE, transferCompletionMessage.getProcessId());
builder.add(DSPACE_PROCESS_ID, transferCompletionMessage.getProcessId());

return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@

import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_CORRELATIONID_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_STATE_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFERPROCESS_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_CORRELATION_ID;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_STATE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFER_PROCESS_TYPE;

public class JsonObjectFromTransferProcessTransformer extends AbstractJsonLdTransformer<TransferProcess, JsonObject> {

Expand All @@ -43,9 +43,9 @@ public JsonObjectFromTransferProcessTransformer(JsonBuilderFactory jsonBuilderFa
var builder = jsonBuilderFactory.createObjectBuilder();

builder.add(ID, transferProcess.getId());
builder.add(TYPE, DSPACE_TRANSFERPROCESS_TYPE);
builder.add(DSPACE_CORRELATIONID_TYPE, transferProcess.getCorrelationId());
builder.add(DSPACE_STATE_TYPE, TransferProcessStates.from(transferProcess.getState()).name());
builder.add(TYPE, DSPACE_TRANSFER_PROCESS_TYPE);
builder.add(DSPACE_CORRELATION_ID, transferProcess.getCorrelationId());
builder.add(DSPACE_STATE, TransferProcessStates.from(transferProcess.getState()).name());

return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import java.util.UUID;

import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCT_FORMAT_ATTRIBUTE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_CALLBACK_ADDRESS_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_CONTRACT_AGREEMENT_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_DATA_ADDRESS_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_PROCESSID_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFERPROCESS_REQUEST_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_CALLBACK_ADDRESS;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_CONTRACT_AGREEMENT_ID;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_DATA_ADDRESS;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_PROCESS_ID;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFER_PROCESS_REQUEST_TYPE;


public class JsonObjectFromTransferRequestMessageTransformer extends AbstractJsonLdTransformer<TransferRequestMessage, JsonObject> {
Expand All @@ -48,15 +48,15 @@ public JsonObjectFromTransferRequestMessageTransformer(JsonBuilderFactory jsonBu
var builder = jsonBuilderFactory.createObjectBuilder();

builder.add(JsonLdKeywords.ID, String.valueOf(UUID.randomUUID()));
builder.add(JsonLdKeywords.TYPE, DSPACE_TRANSFERPROCESS_REQUEST_TYPE);
builder.add(JsonLdKeywords.TYPE, DSPACE_TRANSFER_PROCESS_REQUEST_TYPE);

builder.add(DSPACE_CONTRACT_AGREEMENT_TYPE, transferRequestMessage.getContractId());
builder.add(DSPACE_CONTRACT_AGREEMENT_ID, transferRequestMessage.getContractId());
builder.add(DCT_FORMAT_ATTRIBUTE, transferRequestMessage.getDataDestination().getType());
builder.add(DSPACE_CALLBACK_ADDRESS_TYPE, transferRequestMessage.getCallbackAddress());
builder.add(DSPACE_PROCESSID_TYPE, transferRequestMessage.getProcessId());
builder.add(DSPACE_CALLBACK_ADDRESS, transferRequestMessage.getCallbackAddress());
builder.add(DSPACE_PROCESS_ID, transferRequestMessage.getProcessId());

if (transferRequestMessage.getDataDestination().getProperties().size() > 1) {
builder.add(DSPACE_DATA_ADDRESS_TYPE, context.transform(transferRequestMessage.getDataDestination(), JsonObject.class));
builder.add(DSPACE_DATA_ADDRESS, context.transform(transferRequestMessage.getDataDestination(), JsonObject.class));
}
return builder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@

import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_DATA_ADDRESS_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_PROCESSID_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_DATA_ADDRESS;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_PROCESS_ID;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFER_START_TYPE;

public class JsonObjectFromTransferStartMessageTransformer extends AbstractJsonLdTransformer<TransferStartMessage, JsonObject> {
Expand All @@ -45,9 +45,9 @@ public JsonObjectFromTransferStartMessageTransformer(JsonBuilderFactory jsonBuil

builder.add(ID, UUID.randomUUID().toString());
builder.add(TYPE, DSPACE_TRANSFER_START_TYPE);
builder.add(DSPACE_PROCESSID_TYPE, transferStartMessage.getProcessId());
builder.add(DSPACE_PROCESS_ID, transferStartMessage.getProcessId());
if (transferStartMessage.getDataAddress() != null) {
builder.add(DSPACE_DATA_ADDRESS_TYPE, context.transform(transferStartMessage.getDataAddress(), JsonObject.class));
builder.add(DSPACE_DATA_ADDRESS, context.transform(transferStartMessage.getDataAddress(), JsonObject.class));
}

return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@

import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_CODE_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_PROCESSID_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_REASON_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_CODE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_PROCESS_ID;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_REASON;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_TRANSFER_TERMINATION_TYPE;

public class JsonObjectFromTransferTerminationMessageTransformer extends AbstractJsonLdTransformer<TransferTerminationMessage, JsonObject> {
Expand All @@ -46,12 +46,12 @@ public JsonObjectFromTransferTerminationMessageTransformer(JsonBuilderFactory js

builder.add(ID, String.valueOf(UUID.randomUUID()));
builder.add(TYPE, DSPACE_TRANSFER_TERMINATION_TYPE);
builder.add(DSPACE_PROCESSID_TYPE, transferTerminationMessage.getProcessId());
builder.add(DSPACE_PROCESS_ID, transferTerminationMessage.getProcessId());
if (transferTerminationMessage.getCode() != null) {
builder.add(DSPACE_CODE_TYPE, transferTerminationMessage.getCode());
builder.add(DSPACE_CODE, transferTerminationMessage.getCode());
}
if (transferTerminationMessage.getReason() != null) {
builder.add(DSPACE_REASON_TYPE, transferTerminationMessage.getReason());
builder.add(DSPACE_REASON, transferTerminationMessage.getReason());
}

return builder.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import org.jetbrains.annotations.Nullable;

import static org.eclipse.edc.protocol.dsp.spi.types.HttpMessageProtocol.DATASPACE_PROTOCOL_HTTP;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_PROCESSID_TYPE;
import static org.eclipse.edc.protocol.dsp.transferprocess.transformer.DspTransferProcessPropertyAndTypeNames.DSPACE_PROCESS_ID;

public class JsonObjectToTransferCompletionMessageTransformer extends AbstractJsonLdTransformer<JsonObject, TransferCompletionMessage> {

Expand All @@ -36,7 +36,7 @@ public JsonObjectToTransferCompletionMessageTransformer() {

transferCompletionMessageBuilder.protocol(DATASPACE_PROTOCOL_HTTP);

transformString(messageObject.get(DSPACE_PROCESSID_TYPE), transferCompletionMessageBuilder::processId, context);
transformString(messageObject.get(DSPACE_PROCESS_ID), transferCompletionMessageBuilder::processId, context);

return transferCompletionMessageBuilder.build();

Expand Down
Loading

0 comments on commit 38a158c

Please sign in to comment.