From f901a6ae29ecd2e2fed873f096e804641167d684 Mon Sep 17 00:00:00 2001 From: ndr_brt Date: Mon, 8 May 2023 16:12:02 +0200 Subject: [PATCH] feat: add json ld api endpoints for `TransferProcess` (#2888) feat: add json ld api endpoints for TransferProcess --- .../TransferProcessServiceImpl.java | 2 +- .../TransferProcessEventDispatchTest.java | 7 +- .../TransferProcessServiceImplTest.java | 6 +- .../process/TransferProcessManagerImpl.java | 52 +-- data-protocols/dsp/build.gradle.kts | 1 + .../JsonObjectFromDataAddressTransformer.java | 2 +- .../org/eclipse/edc/api/ApiCoreExtension.java | 15 + .../edc/api}/model/DataAddressDto.java | 6 +- .../eclipse/edc/api/model/IdResponseDto.java | 6 + ...ataAddressDtoToDataAddressTransformer.java | 7 +- ...ataAddressToDataAddressDtoTransformer.java | 7 +- ...nObjectFromCallbackAddressTransformer.java | 2 +- ...onObjectFromDataAddressDtoTransformer.java | 42 ++ ...sonObjectFromIdResponseDtoTransformer.java | 47 ++ ...ObjectToCallbackAddressDtoTransformer.java | 2 +- ...ddressDtoToDataAddressTransformerTest.java | 6 +- ...ectFromCallbackAddressTransformerTest.java | 4 +- ...jectFromDataAddressDtoTransformerTest.java | 79 ++++ ...bjectFromIdResponseDtoTransformerTest.java | 57 +++ ...ctToCallbackAddressDtoTransformerTest.java | 4 +- .../testfixtures/RestControllerTestBase.java | 2 +- .../api/management/asset/AssetApi.java | 2 +- .../management/asset/AssetApiController.java | 2 +- .../management/asset/AssetApiExtension.java | 4 - .../api/management/asset/AssetNewApi.java | 2 +- .../asset/AssetNewApiController.java | 2 +- .../management/asset/model/AssetEntryDto.java | 1 + .../asset/model/AssetEntryNewDto.java | 1 + .../asset/AssetApiControllerTest.java | 2 +- .../asset/AssetNewApiControllerTest.java | 2 +- ...AssetCreationRequestDtoValidationTest.java | 1 + .../asset/model/AssetEntryDtoTest.java | 1 + .../asset/model/AssetEntryNewDtoTest.java | 1 + .../asset/model/DataAddressDtoTest.java | 1 + .../ContractNegotiationApiExtension.java | 4 - .../transfer-process-api/build.gradle.kts | 2 + .../transferprocess/TransferProcessApi.java | 1 + .../TransferProcessApiController.java | 2 +- .../TransferProcessApiExtension.java | 34 +- .../TransferProcessNewApi.java | 118 +++++ .../TransferProcessNewApiController.java | 163 +++++++ .../model/DataAddressInformationDto.java | 59 --- .../transferprocess/model/DataRequestDto.java | 8 + .../model/TerminateTransferDto.java | 5 + .../model/TransferProcessDto.java | 33 +- .../model/TransferRequestDto.java | 12 + .../transferprocess/model/TransferState.java | 6 + ...onObjectFromDataRequestDtoTransformer.java | 55 +++ ...jectFromTransferProcessDtoTransformer.java | 75 ++++ ...sonObjectFromTransferStateTransformer.java | 46 ++ ...jectToTerminateTransferDtoTransformer.java | 46 ++ ...ObjectToTransferRequestDtoTransformer.java | 72 +++ ...rocessToTransferProcessDtoTransformer.java | 20 +- .../TransferProcessApiControllerTest.java | 3 +- .../TransferProcessNewApiControllerTest.java | 422 ++++++++++++++++++ ...jectFromDataRequestDtoTransformerTest.java | 62 +++ ...FromTransferProcessDtoTransformerTest.java | 94 ++++ ...bjectFromTransferStateTransformerTest.java | 52 +++ ...ToTerminateTransferDtoTransformerTest.java | 52 +++ ...ctToTransferRequestDtoTransformerTest.java | 90 ++++ ...ssToTransferProcessDtoTransformerTest.java | 10 +- .../TransferProcessTransformerTestData.java | 8 +- resources/openapi/openapi.yaml | 271 ++++++++++- .../management-api/transfer-process-api.yaml | 309 ++++++++++++- .../edc/spi/types/domain/DataAddress.java | 11 +- .../AbstractJsonLdTransformer.java | 22 +- .../spi/exception/ServiceResultHandler.java | 11 + .../TransferProcessService.java | 4 +- .../transfer/spi/TransferProcessManager.java | 3 +- .../build.gradle.kts | 1 + .../TransferProcessApiEndToEndTest.java | 162 +++++++ .../file-transfer-consumer/build.gradle.kts | 2 +- .../file-transfer-provider/build.gradle.kts | 7 +- 73 files changed, 2535 insertions(+), 200 deletions(-) rename extensions/{control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset => common/api/api-core/src/main/java/org/eclipse/edc/api}/model/DataAddressDto.java (91%) rename extensions/{control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/transform => common/api/api-core/src/main/java/org/eclipse/edc/api/transformer}/DataAddressDtoToDataAddressTransformer.java (80%) rename extensions/{control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/transform => common/api/api-core/src/main/java/org/eclipse/edc/api/transformer}/DataAddressToDataAddressDtoTransformer.java (80%) rename extensions/{control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform => common/api/api-core/src/main/java/org/eclipse/edc/api/transformer}/JsonObjectFromCallbackAddressTransformer.java (96%) create mode 100644 extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/JsonObjectFromDataAddressDtoTransformer.java create mode 100644 extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/JsonObjectFromIdResponseDtoTransformer.java rename extensions/{control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform => common/api/api-core/src/main/java/org/eclipse/edc/api/transformer}/JsonObjectToCallbackAddressDtoTransformer.java (96%) rename extensions/{control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/transform => common/api/api-core/src/test/java/org/eclipse/edc/api/transformer}/DataAddressDtoToDataAddressTransformerTest.java (86%) rename extensions/{control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform => common/api/api-core/src/test/java/org/eclipse/edc/api/transformer}/JsonObjectFromCallbackAddressTransformerTest.java (95%) create mode 100644 extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectFromDataAddressDtoTransformerTest.java create mode 100644 extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectFromIdResponseDtoTransformerTest.java rename extensions/{control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform => common/api/api-core/src/test/java/org/eclipse/edc/api/transformer}/JsonObjectToCallbackAddressDtoTransformerTest.java (96%) create mode 100644 extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessNewApi.java create mode 100644 extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessNewApiController.java delete mode 100644 extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/DataAddressInformationDto.java create mode 100644 extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromDataRequestDtoTransformer.java create mode 100644 extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromTransferProcessDtoTransformer.java create mode 100644 extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromTransferStateTransformer.java create mode 100644 extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTerminateTransferDtoTransformer.java create mode 100644 extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTransferRequestDtoTransformer.java create mode 100644 extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessNewApiControllerTest.java create mode 100644 extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromDataRequestDtoTransformerTest.java create mode 100644 extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromTransferProcessDtoTransformerTest.java create mode 100644 extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromTransferStateTransformerTest.java create mode 100644 extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTerminateTransferDtoTransformerTest.java create mode 100644 extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTransferRequestDtoTransformerTest.java create mode 100644 system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/TransferProcessApiEndToEndTest.java diff --git a/core/control-plane/control-plane-aggregate-services/src/main/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessServiceImpl.java b/core/control-plane/control-plane-aggregate-services/src/main/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessServiceImpl.java index bdfa85bded0..7eaeb7e5c4a 100644 --- a/core/control-plane/control-plane-aggregate-services/src/main/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessServiceImpl.java +++ b/core/control-plane/control-plane-aggregate-services/src/main/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessServiceImpl.java @@ -107,7 +107,7 @@ public ServiceResult> query(QuerySpec query) { } @Override - public @NotNull ServiceResult initiateTransfer(TransferRequest request) { + public @NotNull ServiceResult initiateTransfer(TransferRequest request) { var validDestination = dataAddressValidator.validate(request.getDataRequest().getDataDestination()); if (validDestination.failed()) { return ServiceResult.badRequest(validDestination.getFailureMessages().toArray(new String[]{})); diff --git a/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessEventDispatchTest.java b/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessEventDispatchTest.java index 060dfbd9f17..d171d16c23f 100644 --- a/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessEventDispatchTest.java +++ b/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessEventDispatchTest.java @@ -152,13 +152,14 @@ void shouldDispatchEventsOnTransferProcessStateChanges(TransferProcessService se .usingRecursiveComparison().isEqualTo(dataAddress); }); - service.complete(initiateResult.getContent()); + var transferProcess = initiateResult.getContent(); + service.complete(transferProcess.getId()); await().untilAsserted(() -> { verify(eventSubscriber).on(argThat(isEnvelopeOf(TransferProcessCompleted.class))); }); - service.deprovision(initiateResult.getContent()); + service.deprovision(transferProcess.getId()); await().untilAsserted(() -> { verify(eventSubscriber).on(argThat(isEnvelopeOf(TransferProcessDeprovisioned.class))); @@ -218,7 +219,7 @@ void shouldDispatchEventOnTransferProcessTerminated(TransferProcessService servi var initiateResult = service.initiateTransfer(transferRequest); - service.terminate(initiateResult.getContent(), "any reason"); + service.terminate(initiateResult.getContent().getId(), "any reason"); await().untilAsserted(() -> verify(eventSubscriber).on(argThat(isEnvelopeOf(TransferProcessTerminated.class)))); } diff --git a/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessServiceImplTest.java b/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessServiceImplTest.java index cd0edaf47bd..39de0fa9935 100644 --- a/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessServiceImplTest.java +++ b/core/control-plane/control-plane-aggregate-services/src/test/java/org/eclipse/edc/connector/service/transferprocess/TransferProcessServiceImplTest.java @@ -128,14 +128,14 @@ void getState_whenNotFound() { @Test void initiateTransfer() { var transferRequest = transferRequest(); - String processId = "processId"; + var transferProcess = transferProcess(); when(dataAddressValidator.validate(any())).thenReturn(Result.success()); - when(manager.initiateConsumerRequest(transferRequest)).thenReturn(StatusResult.success(processId)); + when(manager.initiateConsumerRequest(transferRequest)).thenReturn(StatusResult.success(transferProcess)); var result = service.initiateTransfer(transferRequest); assertThat(result.succeeded()).isTrue(); - assertThat(result.getContent()).isEqualTo(processId); + assertThat(result.getContent()).isEqualTo(transferProcess); verify(transactionContext).execute(any(TransactionContext.ResultTransactionBlock.class)); } diff --git a/core/control-plane/transfer-core/src/main/java/org/eclipse/edc/connector/transfer/process/TransferProcessManagerImpl.java b/core/control-plane/transfer-core/src/main/java/org/eclipse/edc/connector/transfer/process/TransferProcessManagerImpl.java index 0599ffe8869..018f7c35018 100644 --- a/core/control-plane/transfer-core/src/main/java/org/eclipse/edc/connector/transfer/process/TransferProcessManagerImpl.java +++ b/core/control-plane/transfer-core/src/main/java/org/eclipse/edc/connector/transfer/process/TransferProcessManagerImpl.java @@ -169,8 +169,30 @@ public void stop() { */ @WithSpan @Override - public StatusResult initiateConsumerRequest(TransferRequest transferRequest) { - return initiateRequest(CONSUMER, transferRequest); + public StatusResult initiateConsumerRequest(TransferRequest transferRequest) { + // make the request idempotent: if the process exists, return + var dataRequest = transferRequest.getDataRequest(); + var processId = transferProcessStore.processIdForDataRequestId(dataRequest.getId()); + if (processId != null) { + return StatusResult.success(transferProcessStore.findById(processId)); + } + var id = randomUUID().toString(); + var process = TransferProcess.Builder.newInstance() + .id(id) + .dataRequest(dataRequest) + .type(CONSUMER) + .clock(clock) + .properties(dataRequest.getProperties()) + .callbackAddresses(transferRequest.getCallbackAddresses()) + .traceContext(telemetry.getCurrentTraceContext()) + .build(); + + observable.invokeForEach(l -> l.preCreated(process)); + update(process); + observable.invokeForEach(l -> l.initiated(process)); + monitor.debug("Process " + process.getId() + " is now " + TransferProcessStates.from(process.getState())); + + return StatusResult.success(process); } @Override @@ -256,32 +278,6 @@ private void handleDeprovisionResult(TransferProcess transferProcess, List initiateRequest(TransferProcess.Type type, TransferRequest transferRequest) { - // make the request idempotent: if the process exists, return - var dataRequest = transferRequest.getDataRequest(); - var processId = transferProcessStore.processIdForDataRequestId(dataRequest.getId()); - if (processId != null) { - return StatusResult.success(processId); - } - var id = randomUUID().toString(); - var process = TransferProcess.Builder.newInstance() - .id(id) - .dataRequest(dataRequest) - .type(type) - .clock(clock) - .properties(dataRequest.getProperties()) - .callbackAddresses(transferRequest.getCallbackAddresses()) - .traceContext(telemetry.getCurrentTraceContext()) - .build(); - - observable.invokeForEach(l -> l.preCreated(process)); - update(process); - observable.invokeForEach(l -> l.initiated(process)); - monitor.debug("Process " + process.getId() + " is now " + TransferProcessStates.from(process.getState())); - - return StatusResult.success(process.getId()); - } - /** * Process INITIAL transfer

set it to PROVISIONING * diff --git a/data-protocols/dsp/build.gradle.kts b/data-protocols/dsp/build.gradle.kts index 60143a42189..ab9a78d1843 100644 --- a/data-protocols/dsp/build.gradle.kts +++ b/data-protocols/dsp/build.gradle.kts @@ -27,6 +27,7 @@ dependencies { api(project(":data-protocols:dsp:dsp-http-spi")) api(project(":data-protocols:dsp:dsp-negotiation")) api(project(":data-protocols:dsp:dsp-transfer-process")) + api(project(":data-protocols:dsp:dsp-transfer-process:dsp-transfer-process-transform")) api(project(":data-protocols:dsp:dsp-transform")) } diff --git a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/from/JsonObjectFromDataAddressTransformer.java b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/from/JsonObjectFromDataAddressTransformer.java index a04276706cf..de327dc74d3 100644 --- a/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/from/JsonObjectFromDataAddressTransformer.java +++ b/data-protocols/dsp/dsp-transfer-process/dsp-transfer-process-transform/src/main/java/org/eclipse/edc/protocol/dsp/transferprocess/transformer/type/from/JsonObjectFromDataAddressTransformer.java @@ -39,4 +39,4 @@ public JsonObjectFromDataAddressTransformer(JsonBuilderFactory jsonBuilderFactor return builder.build(); } -} \ No newline at end of file +} diff --git a/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/ApiCoreExtension.java b/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/ApiCoreExtension.java index 3d86caf5e76..4efe8c976fc 100644 --- a/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/ApiCoreExtension.java +++ b/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/ApiCoreExtension.java @@ -18,7 +18,13 @@ import org.eclipse.edc.api.transformer.CallbackAddressDtoToCallbackAddressTransformer; import org.eclipse.edc.api.transformer.CriterionDtoToCriterionTransformer; import org.eclipse.edc.api.transformer.CriterionToCriterionDtoTransformer; +import org.eclipse.edc.api.transformer.DataAddressDtoToDataAddressTransformer; +import org.eclipse.edc.api.transformer.DataAddressToDataAddressDtoTransformer; +import org.eclipse.edc.api.transformer.JsonObjectFromCallbackAddressTransformer; import org.eclipse.edc.api.transformer.JsonObjectFromCriterionDtoTransformer; +import org.eclipse.edc.api.transformer.JsonObjectFromDataAddressDtoTransformer; +import org.eclipse.edc.api.transformer.JsonObjectFromIdResponseDtoTransformer; +import org.eclipse.edc.api.transformer.JsonObjectToCallbackAddressDtoTransformer; import org.eclipse.edc.api.transformer.JsonObjectToCriterionDtoTransformer; import org.eclipse.edc.api.transformer.QuerySpecDtoToQuerySpecTransformer; import org.eclipse.edc.runtime.metamodel.annotation.Extension; @@ -54,9 +60,18 @@ public void initialize(ServiceExtensionContext context) { transformerRegistry.register(new CriterionToCriterionDtoTransformer()); transformerRegistry.register(new CriterionDtoToCriterionTransformer()); transformerRegistry.register(new CallbackAddressDtoToCallbackAddressTransformer()); + transformerRegistry.register(new DataAddressDtoToDataAddressTransformer()); + transformerRegistry.register(new DataAddressToDataAddressDtoTransformer()); + var mapper = typeManager.getMapper(JSON_LD); var jsonFactory = Json.createBuilderFactory(Map.of()); + + transformerRegistry.register(new JsonObjectFromCallbackAddressTransformer(jsonFactory)); transformerRegistry.register(new JsonObjectFromCriterionDtoTransformer(jsonFactory, mapper)); + transformerRegistry.register(new JsonObjectFromDataAddressDtoTransformer(jsonFactory)); + transformerRegistry.register(new JsonObjectFromIdResponseDtoTransformer(jsonFactory)); + + transformerRegistry.register(new JsonObjectToCallbackAddressDtoTransformer()); transformerRegistry.register(new JsonObjectToCriterionDtoTransformer()); } } diff --git a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/model/DataAddressDto.java b/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/model/DataAddressDto.java similarity index 91% rename from extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/model/DataAddressDto.java rename to extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/model/DataAddressDto.java index 045d0695091..74256e161de 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/model/DataAddressDto.java +++ b/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/model/DataAddressDto.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 ZF Friedrichshafen AG + * Copyright (c) 2022 - 2023 ZF Friedrichshafen AG * * This program and the accompanying materials are made available under the * terms of the Apache License, Version 2.0 which is available at @@ -8,11 +8,11 @@ * SPDX-License-Identifier: Apache-2.0 * * Contributors: - * ZF Friedrichshafen AG - Initial API and Implementation + * ZF Friedrichshafen AG - initial API and implementation * */ -package org.eclipse.edc.connector.api.management.asset.model; +package org.eclipse.edc.api.model; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; diff --git a/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/model/IdResponseDto.java b/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/model/IdResponseDto.java index ac368076992..cc74c4aab24 100644 --- a/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/model/IdResponseDto.java +++ b/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/model/IdResponseDto.java @@ -18,8 +18,14 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; + @JsonDeserialize(builder = IdResponseDto.Builder.class) public class IdResponseDto extends BaseResponseDto { + + public static final String EDC_ID_RESPONSE_DTO_TYPE = EDC_NAMESPACE + "IdResponseDto"; + public static final String EDC_ID_RESPONSE_DTO_CREATED_AT = EDC_NAMESPACE + "createdAt"; + private String id; public IdResponseDto() { diff --git a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/transform/DataAddressDtoToDataAddressTransformer.java b/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/DataAddressDtoToDataAddressTransformer.java similarity index 80% rename from extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/transform/DataAddressDtoToDataAddressTransformer.java rename to extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/DataAddressDtoToDataAddressTransformer.java index 3652b287e1a..81f8fcdafb8 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/transform/DataAddressDtoToDataAddressTransformer.java +++ b/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/DataAddressDtoToDataAddressTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2022 - 2023 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 @@ -12,10 +12,9 @@ * */ -package org.eclipse.edc.connector.api.management.asset.transform; +package org.eclipse.edc.api.transformer; -import org.eclipse.edc.api.transformer.DtoTransformer; -import org.eclipse.edc.connector.api.management.asset.model.DataAddressDto; +import org.eclipse.edc.api.model.DataAddressDto; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.transform.spi.TransformerContext; import org.jetbrains.annotations.NotNull; diff --git a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/transform/DataAddressToDataAddressDtoTransformer.java b/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/DataAddressToDataAddressDtoTransformer.java similarity index 80% rename from extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/transform/DataAddressToDataAddressDtoTransformer.java rename to extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/DataAddressToDataAddressDtoTransformer.java index 503325ac3a9..4bb53a3577a 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/transform/DataAddressToDataAddressDtoTransformer.java +++ b/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/DataAddressToDataAddressDtoTransformer.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2022 - 2023 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 @@ -12,10 +12,9 @@ * */ -package org.eclipse.edc.connector.api.management.asset.transform; +package org.eclipse.edc.api.transformer; -import org.eclipse.edc.api.transformer.DtoTransformer; -import org.eclipse.edc.connector.api.management.asset.model.DataAddressDto; +import org.eclipse.edc.api.model.DataAddressDto; import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.transform.spi.TransformerContext; import org.jetbrains.annotations.NotNull; diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromCallbackAddressTransformer.java b/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/JsonObjectFromCallbackAddressTransformer.java similarity index 96% rename from extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromCallbackAddressTransformer.java rename to extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/JsonObjectFromCallbackAddressTransformer.java index f1d9da6d0b1..a3e6f758469 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromCallbackAddressTransformer.java +++ b/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/JsonObjectFromCallbackAddressTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.connector.api.management.contractnegotiation.transform; +package org.eclipse.edc.api.transformer; import jakarta.json.JsonArrayBuilder; import jakarta.json.JsonBuilderFactory; diff --git a/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/JsonObjectFromDataAddressDtoTransformer.java b/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/JsonObjectFromDataAddressDtoTransformer.java new file mode 100644 index 00000000000..784246c1915 --- /dev/null +++ b/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/JsonObjectFromDataAddressDtoTransformer.java @@ -0,0 +1,42 @@ +/* + * 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.api.transformer; + +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; +import org.eclipse.edc.api.model.DataAddressDto; +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; + +public class JsonObjectFromDataAddressDtoTransformer extends AbstractJsonLdTransformer { + + private final JsonBuilderFactory jsonBuilderFactory; + + public JsonObjectFromDataAddressDtoTransformer(JsonBuilderFactory jsonBuilderFactory) { + super(DataAddressDto.class, JsonObject.class); + this.jsonBuilderFactory = jsonBuilderFactory; + } + + @Override + public @Nullable JsonObject transform(@NotNull DataAddressDto dataAddress, @NotNull TransformerContext context) { + var builder = jsonBuilderFactory.createObjectBuilder(); + + dataAddress.getProperties().forEach(builder::add); + + return builder.build(); + } +} diff --git a/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/JsonObjectFromIdResponseDtoTransformer.java b/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/JsonObjectFromIdResponseDtoTransformer.java new file mode 100644 index 00000000000..a871dfd3d14 --- /dev/null +++ b/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/JsonObjectFromIdResponseDtoTransformer.java @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2023 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.api.transformer; + +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; +import org.eclipse.edc.api.model.IdResponseDto; +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 static org.eclipse.edc.api.model.IdResponseDto.EDC_ID_RESPONSE_DTO_CREATED_AT; +import static org.eclipse.edc.api.model.IdResponseDto.EDC_ID_RESPONSE_DTO_TYPE; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; + +public class JsonObjectFromIdResponseDtoTransformer extends AbstractJsonLdTransformer { + + private final JsonBuilderFactory builderFactory; + + public JsonObjectFromIdResponseDtoTransformer(JsonBuilderFactory builderFactory) { + super(IdResponseDto.class, JsonObject.class); + this.builderFactory = builderFactory; + } + + @Override + public @Nullable JsonObject transform(@NotNull IdResponseDto input, @NotNull TransformerContext context) { + return builderFactory.createObjectBuilder() + .add(TYPE, EDC_ID_RESPONSE_DTO_TYPE) + .add(ID, input.getId()) + .add(EDC_ID_RESPONSE_DTO_CREATED_AT, input.getCreatedAt()) + .build(); + } +} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToCallbackAddressDtoTransformer.java b/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/JsonObjectToCallbackAddressDtoTransformer.java similarity index 96% rename from extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToCallbackAddressDtoTransformer.java rename to extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/JsonObjectToCallbackAddressDtoTransformer.java index 47611ecbea6..8817aee5fc5 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToCallbackAddressDtoTransformer.java +++ b/extensions/common/api/api-core/src/main/java/org/eclipse/edc/api/transformer/JsonObjectToCallbackAddressDtoTransformer.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.connector.api.management.contractnegotiation.transform; +package org.eclipse.edc.api.transformer; import jakarta.json.JsonObject; import jakarta.json.JsonValue; diff --git a/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/transform/DataAddressDtoToDataAddressTransformerTest.java b/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/DataAddressDtoToDataAddressTransformerTest.java similarity index 86% rename from extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/transform/DataAddressDtoToDataAddressTransformerTest.java rename to extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/DataAddressDtoToDataAddressTransformerTest.java index 297dd9b7025..bc38806a360 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/transform/DataAddressDtoToDataAddressTransformerTest.java +++ b/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/DataAddressDtoToDataAddressTransformerTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG) + * Copyright (c) 2022 - 2023 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 @@ -12,9 +12,9 @@ * */ -package org.eclipse.edc.connector.api.management.asset.transform; +package org.eclipse.edc.api.transformer; -import org.eclipse.edc.connector.api.management.asset.model.DataAddressDto; +import org.eclipse.edc.api.model.DataAddressDto; import org.eclipse.edc.transform.spi.TransformerContext; import org.junit.jupiter.api.Test; diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromCallbackAddressTransformerTest.java b/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectFromCallbackAddressTransformerTest.java similarity index 95% rename from extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromCallbackAddressTransformerTest.java rename to extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectFromCallbackAddressTransformerTest.java index bfe1a8b3e76..1b29acab4b2 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectFromCallbackAddressTransformerTest.java +++ b/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectFromCallbackAddressTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.connector.api.management.contractnegotiation.transform; +package org.eclipse.edc.api.transformer; import jakarta.json.Json; @@ -53,4 +53,4 @@ void transform() { assertThat(json.get(IS_TRANSACTIONAL).toString()).isEqualTo("true"); assertThat(json.getJsonArray(EVENTS)).hasSize(3); } -} \ No newline at end of file +} diff --git a/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectFromDataAddressDtoTransformerTest.java b/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectFromDataAddressDtoTransformerTest.java new file mode 100644 index 00000000000..28c05553e89 --- /dev/null +++ b/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectFromDataAddressDtoTransformerTest.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2023 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.api.transformer; + +import jakarta.json.Json; +import jakarta.json.JsonBuilderFactory; +import org.eclipse.edc.api.model.DataAddressDto; +import org.eclipse.edc.spi.types.domain.DataAddress; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; + + +class JsonObjectFromDataAddressDtoTransformerTest { + private static final String TEST_KEY = "region"; + private static final String TEST_VALUE = "europe"; + private final String type = "testType"; + private final String key = "testKey"; + private final JsonBuilderFactory jsonFactory = Json.createBuilderFactory(Map.of()); + private final TransformerContext context = mock(TransformerContext.class); + + private final JsonObjectFromDataAddressDtoTransformer transformer = new JsonObjectFromDataAddressDtoTransformer(jsonFactory); + + @Test + void transform() { + var message = DataAddressDto.Builder.newInstance() + .properties(Map.of( + "type", type, + "keyName", key, + TEST_KEY, TEST_VALUE + )) + .build(); + + var result = transformer.transform(message, context); + + assertThat(result).isNotNull(); + assertThat(result.getJsonString(TEST_KEY).getString()).isEqualTo(TEST_VALUE); + assertThat(result.getJsonString(DataAddress.TYPE).getString()).isEqualTo(type); + assertThat(result.getJsonString(DataAddress.KEY_NAME).getString()).isEqualTo(key); + + verify(context, never()).reportProblem(anyString()); + } + + @Test + void transform_withNamespace() { + var schema = "https://some.custom.org/schema/"; + var message = DataAddressDto.Builder.newInstance() + .properties(Map.of( + "type", type, + "keyName", key, + schema + TEST_KEY, TEST_VALUE + )) + .build(); + + var result = transformer.transform(message, context); + assertThat(result).isNotNull(); + assertThat(result.getJsonString(schema + TEST_KEY).getString()).isEqualTo(TEST_VALUE); + verify(context, never()).reportProblem(anyString()); + } +} diff --git a/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectFromIdResponseDtoTransformerTest.java b/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectFromIdResponseDtoTransformerTest.java new file mode 100644 index 00000000000..b1d0d37eb51 --- /dev/null +++ b/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectFromIdResponseDtoTransformerTest.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2023 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.api.transformer; + +import jakarta.json.Json; +import jakarta.json.JsonObject; +import org.eclipse.edc.api.model.IdResponseDto; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.Test; + +import static java.util.Collections.emptyMap; +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.api.model.IdResponseDto.EDC_ID_RESPONSE_DTO_CREATED_AT; +import static org.eclipse.edc.api.model.IdResponseDto.EDC_ID_RESPONSE_DTO_TYPE; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.mockito.Mockito.mock; + +class JsonObjectFromIdResponseDtoTransformerTest { + + private final JsonObjectFromIdResponseDtoTransformer transformer = new JsonObjectFromIdResponseDtoTransformer(Json.createBuilderFactory(emptyMap())); + private final TransformerContext context = mock(TransformerContext.class); + + @Test + void types() { + assertThat(transformer.getInputType()).isEqualTo(IdResponseDto.class); + assertThat(transformer.getOutputType()).isEqualTo(JsonObject.class); + } + + @Test + void transform() { + var input = IdResponseDto.Builder.newInstance() + .id("id") + .createdAt(1234) + .build(); + + var result = transformer.transform(input, context); + + assertThat(result).isNotNull(); + assertThat(result.getString(ID)).isEqualTo("id"); + assertThat(result.getString(TYPE)).isEqualTo(EDC_ID_RESPONSE_DTO_TYPE); + assertThat(result.getInt(EDC_ID_RESPONSE_DTO_CREATED_AT)).isEqualTo(1234); + } + +} diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToCallbackAddressDtoTransformerTest.java b/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectToCallbackAddressDtoTransformerTest.java similarity index 96% rename from extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToCallbackAddressDtoTransformerTest.java rename to extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectToCallbackAddressDtoTransformerTest.java index 05c132725ea..b50181cd0b5 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/test/java/org/eclipse/edc/connector/api/management/contractnegotiation/transform/JsonObjectToCallbackAddressDtoTransformerTest.java +++ b/extensions/common/api/api-core/src/test/java/org/eclipse/edc/api/transformer/JsonObjectToCallbackAddressDtoTransformerTest.java @@ -12,7 +12,7 @@ * */ -package org.eclipse.edc.connector.api.management.contractnegotiation.transform; +package org.eclipse.edc.api.transformer; import jakarta.json.Json; import org.eclipse.edc.jsonld.transformer.to.JsonValueToGenericTypeTransformer; @@ -62,4 +62,4 @@ void transform() { assertThat(cba.getUri()).isEqualTo("http://test.local/"); assertThat(cba.isTransactional()).isTrue(); } -} \ No newline at end of file +} diff --git a/extensions/common/http/jersey-core/src/testFixtures/java/org/eclipse/edc/web/jersey/testfixtures/RestControllerTestBase.java b/extensions/common/http/jersey-core/src/testFixtures/java/org/eclipse/edc/web/jersey/testfixtures/RestControllerTestBase.java index fab8a76d9da..8c9e7dbf4ba 100644 --- a/extensions/common/http/jersey-core/src/testFixtures/java/org/eclipse/edc/web/jersey/testfixtures/RestControllerTestBase.java +++ b/extensions/common/http/jersey-core/src/testFixtures/java/org/eclipse/edc/web/jersey/testfixtures/RestControllerTestBase.java @@ -36,7 +36,7 @@ public abstract class RestControllerTestBase { protected final int port = getFreePort(); - protected Monitor monitor = mock(Monitor.class); + protected final Monitor monitor = mock(Monitor.class); private JettyService jetty; @BeforeEach diff --git a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetApi.java b/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetApi.java index 8a266343dbd..d582f301fae 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetApi.java +++ b/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetApi.java @@ -22,12 +22,12 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.eclipse.edc.api.model.DataAddressDto; import org.eclipse.edc.api.model.IdResponseDto; import org.eclipse.edc.api.query.QuerySpecDto; import org.eclipse.edc.connector.api.management.asset.model.AssetEntryDto; import org.eclipse.edc.connector.api.management.asset.model.AssetResponseDto; import org.eclipse.edc.connector.api.management.asset.model.AssetUpdateRequestDto; -import org.eclipse.edc.connector.api.management.asset.model.DataAddressDto; import org.eclipse.edc.web.spi.ApiErrorDetail; import java.util.List; diff --git a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetApiController.java b/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetApiController.java index 1e69ea6c9f0..d478d4fb1f0 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetApiController.java +++ b/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetApiController.java @@ -27,13 +27,13 @@ import jakarta.ws.rs.PathParam; import jakarta.ws.rs.Produces; import jakarta.ws.rs.core.MediaType; +import org.eclipse.edc.api.model.DataAddressDto; import org.eclipse.edc.api.model.IdResponseDto; import org.eclipse.edc.api.query.QuerySpecDto; import org.eclipse.edc.connector.api.management.asset.model.AssetEntryDto; import org.eclipse.edc.connector.api.management.asset.model.AssetResponseDto; import org.eclipse.edc.connector.api.management.asset.model.AssetUpdateRequestDto; import org.eclipse.edc.connector.api.management.asset.model.AssetUpdateRequestWrapperDto; -import org.eclipse.edc.connector.api.management.asset.model.DataAddressDto; import org.eclipse.edc.connector.spi.asset.AssetService; import org.eclipse.edc.spi.asset.DataAddressResolver; import org.eclipse.edc.spi.monitor.Monitor; diff --git a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetApiExtension.java b/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetApiExtension.java index 1a6feaf06a3..a109964341e 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetApiExtension.java +++ b/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetApiExtension.java @@ -19,8 +19,6 @@ import org.eclipse.edc.connector.api.management.asset.transform.AssetRequestDtoToAssetTransformer; import org.eclipse.edc.connector.api.management.asset.transform.AssetToAssetResponseDtoTransformer; import org.eclipse.edc.connector.api.management.asset.transform.AssetUpdateRequestWrapperDtoToAssetTransformer; -import org.eclipse.edc.connector.api.management.asset.transform.DataAddressDtoToDataAddressTransformer; -import org.eclipse.edc.connector.api.management.asset.transform.DataAddressToDataAddressDtoTransformer; import org.eclipse.edc.connector.api.management.configuration.ManagementApiConfiguration; import org.eclipse.edc.connector.spi.asset.AssetService; import org.eclipse.edc.jsonld.spi.JsonLd; @@ -67,8 +65,6 @@ public void initialize(ServiceExtensionContext context) { transformerRegistry.register(new AssetRequestDtoToAssetTransformer()); transformerRegistry.register(new AssetUpdateRequestWrapperDtoToAssetTransformer()); transformerRegistry.register(new AssetToAssetResponseDtoTransformer()); - transformerRegistry.register(new DataAddressDtoToDataAddressTransformer()); - transformerRegistry.register(new DataAddressToDataAddressDtoTransformer()); webService.registerResource(config.getContextAlias(), new AssetApiController(monitor, assetService, dataAddressResolver, transformerRegistry)); webService.registerResource(config.getContextAlias(), new AssetNewApiController(assetService, dataAddressResolver, transformerRegistry, jsonLdService)); diff --git a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetNewApi.java b/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetNewApi.java index a5fcb0aa3bd..8e60cf3e1a3 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetNewApi.java +++ b/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetNewApi.java @@ -23,13 +23,13 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; import jakarta.validation.Valid; +import org.eclipse.edc.api.model.DataAddressDto; import org.eclipse.edc.api.model.IdResponseDto; import org.eclipse.edc.api.query.QuerySpecDto; import org.eclipse.edc.connector.api.management.asset.model.AssetEntryNewDto; import org.eclipse.edc.connector.api.management.asset.model.AssetResponseDto; import org.eclipse.edc.connector.api.management.asset.model.AssetResponseNewDto; import org.eclipse.edc.connector.api.management.asset.model.AssetUpdateRequestDto; -import org.eclipse.edc.connector.api.management.asset.model.DataAddressDto; import org.eclipse.edc.web.spi.ApiErrorDetail; import java.util.List; diff --git a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetNewApiController.java b/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetNewApiController.java index 9c062056a2c..829da8bd75b 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetNewApiController.java +++ b/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/AssetNewApiController.java @@ -24,13 +24,13 @@ import jakarta.ws.rs.Path; import jakarta.ws.rs.PathParam; import jakarta.ws.rs.Produces; +import org.eclipse.edc.api.model.DataAddressDto; import org.eclipse.edc.api.model.IdResponseDto; import org.eclipse.edc.api.query.QuerySpecDto; import org.eclipse.edc.connector.api.management.asset.model.AssetEntryNewDto; import org.eclipse.edc.connector.api.management.asset.model.AssetResponseNewDto; import org.eclipse.edc.connector.api.management.asset.model.AssetUpdateRequestDto; import org.eclipse.edc.connector.api.management.asset.model.AssetUpdateRequestWrapperDto; -import org.eclipse.edc.connector.api.management.asset.model.DataAddressDto; import org.eclipse.edc.connector.spi.asset.AssetService; import org.eclipse.edc.jsonld.spi.JsonLd; import org.eclipse.edc.spi.EdcException; diff --git a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/model/AssetEntryDto.java b/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/model/AssetEntryDto.java index 84a3db557db..cf2d1902c01 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/model/AssetEntryDto.java +++ b/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/model/AssetEntryDto.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; +import org.eclipse.edc.api.model.DataAddressDto; @JsonDeserialize(builder = AssetEntryDto.Builder.class) public class AssetEntryDto { diff --git a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/model/AssetEntryNewDto.java b/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/model/AssetEntryNewDto.java index 3f3eaff87d5..d9c0a060b68 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/model/AssetEntryNewDto.java +++ b/extensions/control-plane/api/management-api/asset-api/src/main/java/org/eclipse/edc/connector/api/management/asset/model/AssetEntryNewDto.java @@ -21,6 +21,7 @@ import jakarta.json.JsonObject; import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; +import org.eclipse.edc.api.model.DataAddressDto; @JsonDeserialize(builder = AssetEntryNewDto.Builder.class) public class AssetEntryNewDto { diff --git a/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/AssetApiControllerTest.java b/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/AssetApiControllerTest.java index 254d432fc06..a2061acb975 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/AssetApiControllerTest.java +++ b/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/AssetApiControllerTest.java @@ -16,13 +16,13 @@ package org.eclipse.edc.connector.api.management.asset; import io.restassured.specification.RequestSpecification; +import org.eclipse.edc.api.model.DataAddressDto; import org.eclipse.edc.api.query.QuerySpecDto; import org.eclipse.edc.connector.api.management.asset.model.AssetCreationRequestDto; import org.eclipse.edc.connector.api.management.asset.model.AssetEntryDto; import org.eclipse.edc.connector.api.management.asset.model.AssetResponseDto; import org.eclipse.edc.connector.api.management.asset.model.AssetUpdateRequestDto; import org.eclipse.edc.connector.api.management.asset.model.AssetUpdateRequestWrapperDto; -import org.eclipse.edc.connector.api.management.asset.model.DataAddressDto; import org.eclipse.edc.connector.spi.asset.AssetService; import org.eclipse.edc.junit.annotations.ApiTest; import org.eclipse.edc.service.spi.result.ServiceResult; diff --git a/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/AssetNewApiControllerTest.java b/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/AssetNewApiControllerTest.java index 437ae079a5f..ecf3c37eee7 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/AssetNewApiControllerTest.java +++ b/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/AssetNewApiControllerTest.java @@ -18,13 +18,13 @@ import jakarta.json.Json; import jakarta.json.JsonObject; import jakarta.json.JsonObjectBuilder; +import org.eclipse.edc.api.model.DataAddressDto; import org.eclipse.edc.api.query.QuerySpecDto; import org.eclipse.edc.connector.api.management.asset.model.AssetEntryNewDto; import org.eclipse.edc.connector.api.management.asset.model.AssetResponseDto; import org.eclipse.edc.connector.api.management.asset.model.AssetResponseNewDto; import org.eclipse.edc.connector.api.management.asset.model.AssetUpdateRequestDto; import org.eclipse.edc.connector.api.management.asset.model.AssetUpdateRequestWrapperDto; -import org.eclipse.edc.connector.api.management.asset.model.DataAddressDto; import org.eclipse.edc.connector.spi.asset.AssetService; import org.eclipse.edc.jsonld.TitaniumJsonLd; import org.eclipse.edc.junit.annotations.ApiTest; diff --git a/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/model/AssetCreationRequestDtoValidationTest.java b/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/model/AssetCreationRequestDtoValidationTest.java index 5c7e789623d..670d378b9ab 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/model/AssetCreationRequestDtoValidationTest.java +++ b/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/model/AssetCreationRequestDtoValidationTest.java @@ -17,6 +17,7 @@ import jakarta.validation.Validation; import jakarta.validation.Validator; import jakarta.validation.ValidatorFactory; +import org.eclipse.edc.api.model.DataAddressDto; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/model/AssetEntryDtoTest.java b/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/model/AssetEntryDtoTest.java index d63924a008c..0d516b64914 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/model/AssetEntryDtoTest.java +++ b/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/model/AssetEntryDtoTest.java @@ -16,6 +16,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.eclipse.edc.api.model.DataAddressDto; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/model/AssetEntryNewDtoTest.java b/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/model/AssetEntryNewDtoTest.java index 05235befdb5..77c06cf6a74 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/model/AssetEntryNewDtoTest.java +++ b/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/model/AssetEntryNewDtoTest.java @@ -16,6 +16,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.eclipse.edc.api.model.DataAddressDto; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/model/DataAddressDtoTest.java b/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/model/DataAddressDtoTest.java index a8ea0866acc..65a59c1859a 100644 --- a/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/model/DataAddressDtoTest.java +++ b/extensions/control-plane/api/management-api/asset-api/src/test/java/org/eclipse/edc/connector/api/management/asset/model/DataAddressDtoTest.java @@ -16,6 +16,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import org.eclipse.edc.api.model.DataAddressDto; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiExtension.java b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiExtension.java index 0f63673ffea..da52f9cc978 100644 --- a/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiExtension.java +++ b/extensions/control-plane/api/management-api/contract-negotiation-api/src/main/java/org/eclipse/edc/connector/api/management/contractnegotiation/ContractNegotiationApiExtension.java @@ -19,10 +19,8 @@ import org.eclipse.edc.connector.api.management.configuration.ManagementApiConfiguration; import org.eclipse.edc.connector.api.management.contractnegotiation.transform.ContractAgreementToContractAgreementDtoTransformer; import org.eclipse.edc.connector.api.management.contractnegotiation.transform.ContractNegotiationToContractNegotiationDtoTransformer; -import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectFromCallbackAddressTransformer; import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectFromContractAgreementDtoTransformer; import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectFromContractNegotiationDtoTransformer; -import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectToCallbackAddressDtoTransformer; import org.eclipse.edc.connector.api.management.contractnegotiation.transform.JsonObjectToNegotiationInitiateRequestDtoTransformer; import org.eclipse.edc.connector.api.management.contractnegotiation.transform.NegotiationInitiateRequestDtoToDataRequestTransformer; import org.eclipse.edc.connector.spi.contractnegotiation.ContractNegotiationService; @@ -72,10 +70,8 @@ public void initialize(ServiceExtensionContext context) { transformerRegistry.register(new NegotiationInitiateRequestDtoToDataRequestTransformer(clock)); var factory = Json.createBuilderFactory(Map.of()); transformerRegistry.register(new JsonObjectFromContractNegotiationDtoTransformer(factory)); - transformerRegistry.register(new JsonObjectFromCallbackAddressTransformer(factory)); transformerRegistry.register(new JsonObjectFromContractAgreementDtoTransformer(factory)); transformerRegistry.register(new JsonObjectToNegotiationInitiateRequestDtoTransformer()); - transformerRegistry.register(new JsonObjectToCallbackAddressDtoTransformer()); var monitor = context.getMonitor(); diff --git a/extensions/control-plane/api/management-api/transfer-process-api/build.gradle.kts b/extensions/control-plane/api/management-api/transfer-process-api/build.gradle.kts index 22c8193b1b0..6e98360e03e 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/build.gradle.kts +++ b/extensions/control-plane/api/management-api/transfer-process-api/build.gradle.kts @@ -17,6 +17,7 @@ plugins { } dependencies { + api(project(":spi:common:json-ld-spi")) api(project(":spi:common:transaction-spi")) api(project(":spi:control-plane:transfer-spi")) api(project(":spi:control-plane:control-plane-spi")) @@ -30,6 +31,7 @@ dependencies { 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) diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApi.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApi.java index d1be5777897..2e57dd969e4 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApi.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApi.java @@ -36,6 +36,7 @@ @OpenAPIDefinition @Tag(name = "Transfer Process") +@Deprecated(since = "milestone9") public interface TransferProcessApi { @Operation(description = "Returns all transfer process according to a query", responses = { diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiController.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiController.java index 4b1f8567488..239f3a1c08d 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiController.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiController.java @@ -138,7 +138,7 @@ public IdResponseDto initiateTransfer(@Valid TransferRequestDto transferRequest) var dataRequest = transformResult.getContent(); var result = service.initiateTransfer(dataRequest).orElseThrow(exceptionMapper(TransferProcess.class, transferRequest.getId())); return IdResponseDto.Builder.newInstance() - .id(result) + .id(result.getId()) //To be accurate createdAt should come from the transfer object .createdAt(Clock.systemUTC().millis()) .build(); diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiExtension.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiExtension.java index 4019aa8ced1..f8b2a21ca98 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiExtension.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiExtension.java @@ -14,18 +14,29 @@ package org.eclipse.edc.connector.api.management.transferprocess; +import jakarta.json.Json; import org.eclipse.edc.connector.api.management.configuration.ManagementApiConfiguration; import org.eclipse.edc.connector.api.management.transferprocess.transform.DataRequestToDataRequestDtoTransformer; +import org.eclipse.edc.connector.api.management.transferprocess.transform.JsonObjectFromDataRequestDtoTransformer; +import org.eclipse.edc.connector.api.management.transferprocess.transform.JsonObjectFromTransferProcessDtoTransformer; +import org.eclipse.edc.connector.api.management.transferprocess.transform.JsonObjectFromTransferStateTransformer; +import org.eclipse.edc.connector.api.management.transferprocess.transform.JsonObjectToTerminateTransferDtoTransformer; +import org.eclipse.edc.connector.api.management.transferprocess.transform.JsonObjectToTransferRequestDtoTransformer; import org.eclipse.edc.connector.api.management.transferprocess.transform.TransferProcessToTransferProcessDtoTransformer; import org.eclipse.edc.connector.api.management.transferprocess.transform.TransferRequestDtoToTransferRequestTransformer; import org.eclipse.edc.connector.spi.transferprocess.TransferProcessService; +import org.eclipse.edc.jsonld.spi.JsonLd; 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 org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.web.spi.WebService; +import static java.util.Collections.emptyMap; +import static org.eclipse.edc.spi.CoreConstants.JSON_LD; + @Extension(value = TransferProcessApiExtension.NAME) public class TransferProcessApiExtension implements ServiceExtension { public static final String NAME = "Management API: Transfer Process"; @@ -41,6 +52,12 @@ public class TransferProcessApiExtension implements ServiceExtension { @Inject private TransferProcessService service; + @Inject + private JsonLd jsonLd; + + @Inject + private TypeManager typeManager; + @Override public String name() { return NAME; @@ -48,11 +65,24 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - var controller = new TransferProcessApiController(context.getMonitor(), service, transformerRegistry); - webService.registerResource(configuration.getContextAlias(), controller); + var mapper = typeManager.getMapper(JSON_LD); transformerRegistry.register(new DataRequestToDataRequestDtoTransformer()); transformerRegistry.register(new TransferProcessToTransferProcessDtoTransformer()); transformerRegistry.register(new TransferRequestDtoToTransferRequestTransformer()); + + var builderFactory = Json.createBuilderFactory(emptyMap()); + transformerRegistry.register(new JsonObjectFromDataRequestDtoTransformer(builderFactory)); + transformerRegistry.register(new JsonObjectFromTransferProcessDtoTransformer(builderFactory, mapper)); + transformerRegistry.register(new JsonObjectFromTransferStateTransformer(builderFactory)); + + transformerRegistry.register(new JsonObjectToTerminateTransferDtoTransformer()); + transformerRegistry.register(new JsonObjectToTransferRequestDtoTransformer()); + + var controller = new TransferProcessApiController(context.getMonitor(), service, transformerRegistry); + webService.registerResource(configuration.getContextAlias(), controller); + + var newController = new TransferProcessNewApiController(context.getMonitor(), service, transformerRegistry, jsonLd); + webService.registerResource(configuration.getContextAlias(), newController); } } diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessNewApi.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessNewApi.java new file mode 100644 index 00000000000..17495a29538 --- /dev/null +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessNewApi.java @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2022 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) - improvements + * + */ + +package org.eclipse.edc.connector.api.management.transferprocess; + +import io.swagger.v3.oas.annotations.OpenAPIDefinition; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.links.Link; +import io.swagger.v3.oas.annotations.links.LinkParameter; +import io.swagger.v3.oas.annotations.media.ArraySchema; +import io.swagger.v3.oas.annotations.media.Content; +import io.swagger.v3.oas.annotations.media.Schema; +import io.swagger.v3.oas.annotations.parameters.RequestBody; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.json.JsonObject; +import jakarta.validation.Valid; +import org.eclipse.edc.api.model.IdResponseDto; +import org.eclipse.edc.api.query.QuerySpecDto; +import org.eclipse.edc.connector.api.management.transferprocess.model.TerminateTransferDto; +import org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto; +import org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto; +import org.eclipse.edc.connector.api.management.transferprocess.model.TransferState; +import org.eclipse.edc.web.spi.ApiErrorDetail; + +import java.util.List; + +@OpenAPIDefinition +@Tag(name = "Transfer Process") +public interface TransferProcessNewApi { + @Operation(description = "Returns all transfer process according to a query", + requestBody = @RequestBody(content = @Content(schema = @Schema(implementation = QuerySpecDto.class))), + responses = { + @ApiResponse(responseCode = "200", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = TransferProcessDto.class)))), + @ApiResponse(responseCode = "400", description = "Request was malformed", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))) } + ) + List queryTransferProcesses(@Valid JsonObject querySpecDto); + + @Operation(description = "Gets an transfer process with the given ID", + responses = { + @ApiResponse(responseCode = "200", description = "The transfer process", + content = @Content(schema = @Schema(implementation = TransferProcessDto.class))), + @ApiResponse(responseCode = "400", description = "Request was malformed, e.g. id was null", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))), + @ApiResponse(responseCode = "404", description = "A transfer process with the given ID does not exist", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))) + } + ) + JsonObject getTransferProcess(String id); + + @Operation(description = "Gets the state of a transfer process with the given ID", + operationId = "getTransferProcessState", + responses = { + @ApiResponse(responseCode = "200", description = "The transfer process's state", + content = @Content(schema = @Schema(implementation = TransferState.class))), + @ApiResponse(responseCode = "400", description = "Request was malformed, e.g. id was null", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))), + @ApiResponse(responseCode = "404", description = "An transfer process with the given ID does not exist", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))) + } + ) + JsonObject getTransferProcessState(String id); + + @Operation(description = "Initiates a data transfer with the given parameters. Please note that successfully invoking this endpoint " + + "only means that the transfer was initiated. Clients must poll the /{id}/state endpoint to track the state", + requestBody = @RequestBody(content = @Content(schema = @Schema(implementation = TransferRequestDto.class))), + responses = { + @ApiResponse(responseCode = "200", description = "The transfer was successfully initiated. Returns the transfer process ID and created timestamp", + content = @Content(schema = @Schema(implementation = IdResponseDto.class)), + links = @Link(name = "poll-state", operationId = "getTransferProcessState", parameters = { + @LinkParameter(name = "id", expression = "$response.body#/id") + }) + ), + @ApiResponse(responseCode = "400", description = "Request body was malformed", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))), + }) + JsonObject initiateTransferProcess(@Valid JsonObject transferRequestDto); + + @Operation(description = "Requests the deprovisioning of resources associated with a transfer process. Due to the asynchronous nature of transfers, a successful " + + "response only indicates that the request was successfully received. This may take a long time, so clients must poll the /{id}/state endpoint to track the state.", + responses = { + @ApiResponse(responseCode = "200", description = "Request to deprovision the transfer process was successfully received", + links = @Link(name = "poll-state", operationId = "getTransferProcessState")), + @ApiResponse(responseCode = "400", description = "Request was malformed, e.g. id was null", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))), + @ApiResponse(responseCode = "404", description = "A contract negotiation with the given ID does not exist", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))) + }) + void deprovisionTransferProcess(String id); + + @Operation(description = "Requests the termination of a transfer process. Due to the asynchronous nature of transfers, a successful " + + "response only indicates that the request was successfully received. Clients must poll the /{id}/state endpoint to track the state.", + requestBody = @RequestBody(content = @Content(schema = @Schema(implementation = TerminateTransferDto.class))), + responses = { + @ApiResponse(responseCode = "200", description = "Request to cancel the transfer process was successfully received", + links = @Link(name = "poll-state", operationId = "getTransferProcessState")), + @ApiResponse(responseCode = "400", description = "Request was malformed, e.g. id was null", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))), + @ApiResponse(responseCode = "404", description = "A contract negotiation with the given ID does not exist", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))), + @ApiResponse(responseCode = "409", description = "Could not terminate transfer process, because it is already completed or terminated.", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))) + }) + void terminateTransferProcess(String id, JsonObject terminateTransferDto); +} diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessNewApiController.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessNewApiController.java new file mode 100644 index 00000000000..e033fabb7e7 --- /dev/null +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessNewApiController.java @@ -0,0 +1,163 @@ +/* + * Copyright (c) 2023 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.management.transferprocess; + +import jakarta.json.JsonObject; +import jakarta.ws.rs.Consumes; +import jakarta.ws.rs.GET; +import jakarta.ws.rs.POST; +import jakarta.ws.rs.Path; +import jakarta.ws.rs.PathParam; +import jakarta.ws.rs.Produces; +import org.eclipse.edc.api.model.IdResponseDto; +import org.eclipse.edc.api.query.QuerySpecDto; +import org.eclipse.edc.connector.api.management.transferprocess.model.TerminateTransferDto; +import org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto; +import org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto; +import org.eclipse.edc.connector.api.management.transferprocess.model.TransferState; +import org.eclipse.edc.connector.policy.spi.PolicyDefinition; +import org.eclipse.edc.connector.spi.transferprocess.TransferProcessService; +import org.eclipse.edc.connector.transfer.spi.types.TransferProcess; +import org.eclipse.edc.connector.transfer.spi.types.TransferRequest; +import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.spi.EdcException; +import org.eclipse.edc.spi.monitor.Monitor; +import org.eclipse.edc.spi.query.QuerySpec; +import org.eclipse.edc.spi.result.Result; +import org.eclipse.edc.transform.spi.TypeTransformerRegistry; +import org.eclipse.edc.web.spi.exception.InvalidRequestException; +import org.eclipse.edc.web.spi.exception.ObjectNotFoundException; + +import java.util.List; +import java.util.Optional; + +import static jakarta.ws.rs.core.MediaType.APPLICATION_JSON; +import static java.lang.String.format; +import static java.util.stream.Collectors.toList; +import static org.eclipse.edc.web.spi.exception.ServiceResultHandler.exceptionMapper; +import static org.eclipse.edc.web.spi.exception.ServiceResultHandler.mapToException; + +@Consumes(APPLICATION_JSON) +@Produces(APPLICATION_JSON) +@Path("/v2/transferprocesses") +public class TransferProcessNewApiController implements TransferProcessNewApi { + + private final Monitor monitor; + private final TransferProcessService service; + private final TypeTransformerRegistry transformerRegistry; + private final JsonLd jsonLd; + + public TransferProcessNewApiController(Monitor monitor, TransferProcessService service, TypeTransformerRegistry transformerRegistry, JsonLd jsonLd) { + this.monitor = monitor; + this.service = service; + this.transformerRegistry = transformerRegistry; + this.jsonLd = jsonLd; + } + + @POST + @Path("request") + @Override + public List queryTransferProcesses(JsonObject querySpecDto) { + var querySpec = jsonLd.expand(querySpecDto) + .compose(expanded -> transformerRegistry.transform(expanded, QuerySpecDto.class)) + .compose(dto -> transformerRegistry.transform(dto, QuerySpec.class)) + .orElseThrow(InvalidRequestException::new); + + try (var stream = service.query(querySpec).orElseThrow(exceptionMapper(PolicyDefinition.class))) { + return stream + .map(policyDefinition -> transformerRegistry.transform(policyDefinition, TransferProcessDto.class) + .compose(dto -> transformerRegistry.transform(dto, JsonObject.class) + .compose(jsonLd::compact)) + .onFailure(f -> monitor.warning(f.getFailureDetail()))) + .filter(Result::succeeded) + .map(Result::getContent) + .collect(toList()); + } + } + + @GET + @Path("{id}") + @Override + public JsonObject getTransferProcess(@PathParam("id") String id) { + var definition = service.findById(id); + if (definition == null) { + throw new ObjectNotFoundException(PolicyDefinition.class, id); + } + + return transformerRegistry.transform(definition, TransferProcessDto.class) + .compose(dto -> transformerRegistry.transform(dto, JsonObject.class)) + .compose(jsonLd::compact) + .onFailure(f -> monitor.warning(f.getFailureDetail())) + .orElseThrow(failure -> new ObjectNotFoundException(PolicyDefinition.class, id)); + } + + @GET + @Path("/{id}/state") + @Override + public JsonObject getTransferProcessState(@PathParam("id") String id) { + return Optional.of(id) + .map(service::getState) + .map(TransferState::new) + .map(state -> transformerRegistry.transform(state, JsonObject.class) + .compose(jsonLd::compact) + .onFailure(f -> monitor.warning(f.getFailureDetail())) + .orElseThrow(failure -> new ObjectNotFoundException(TransferProcess.class, id))) + .orElseThrow(() -> new ObjectNotFoundException(TransferProcess.class, id)); + } + + @POST + @Override + public JsonObject initiateTransferProcess(JsonObject request) { + var transferRequest = jsonLd.expand(request) + .compose(json -> transformerRegistry.transform(json, TransferRequestDto.class)) + .compose(dto -> transformerRegistry.transform(dto, TransferRequest.class)) + .orElseThrow(InvalidRequestException::new); + + var createdTransfer = service.initiateTransfer(transferRequest) + .onSuccess(d -> monitor.debug(format("Policy Definition created %s", d.getId()))) + .orElseThrow(it -> mapToException(it, TransferProcess.class)); + + var responseDto = IdResponseDto.Builder.newInstance() + .id(createdTransfer.getId()) + .createdAt(createdTransfer.getCreatedAt()) + .build(); + + return transformerRegistry.transform(responseDto, JsonObject.class) + .compose(jsonLd::compact) + .orElseThrow(f -> new EdcException("Error creating response body: " + f.getFailureDetail())); + } + + @POST + @Path("/{id}/deprovision") + @Override + public void deprovisionTransferProcess(@PathParam("id") String id) { + service.deprovision(id) + .onSuccess(tp -> monitor.debug(format("Deprovision requested for TransferProcess with ID %s", tp.getId()))) + .orElseThrow(exceptionMapper(TransferProcess.class, id)); + } + + @POST + @Path("/{id}/terminate") + @Override + public void terminateTransferProcess(@PathParam("id") String id, JsonObject requestBody) { + var dto = jsonLd.expand(requestBody) + .compose(json -> transformerRegistry.transform(requestBody, TerminateTransferDto.class)) + .orElseThrow(InvalidRequestException::new); + + service.terminate(id, dto.getReason()) + .onSuccess(tp -> monitor.debug(format("Termination requested for TransferProcess with ID %s", tp.getId()))) + .orElseThrow(failure -> mapToException(failure, TransferProcess.class, id)); + } +} diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/DataAddressInformationDto.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/DataAddressInformationDto.java deleted file mode 100644 index cf463021203..00000000000 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/DataAddressInformationDto.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2022 Microsoft Corporation - * - * 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: - * Microsoft Corporation - initial API and implementation - * - */ - -package org.eclipse.edc.connector.api.management.transferprocess.model; - -import com.fasterxml.jackson.annotation.JsonCreator; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; - -import java.util.Map; - -@JsonDeserialize(builder = DataAddressInformationDto.Builder.class) -public class DataAddressInformationDto { - - private Map properties; - - private DataAddressInformationDto() { - } - - public Map getProperties() { - return properties; - } - - @JsonPOJOBuilder(withPrefix = "") - public static final class Builder { - - private final DataAddressInformationDto dataAddressDto; - - private Builder() { - dataAddressDto = new DataAddressInformationDto(); - } - - @JsonCreator - public static Builder newInstance() { - return new Builder(); - } - - public Builder properties(Map properties) { - dataAddressDto.properties = properties; - return this; - } - - public DataAddressInformationDto build() { - return dataAddressDto; - } - - } -} diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/DataRequestDto.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/DataRequestDto.java index b36339be934..fa47bbf8bd9 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/DataRequestDto.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/DataRequestDto.java @@ -18,8 +18,16 @@ import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; + @JsonDeserialize(builder = DataRequestDto.Builder.class) public class DataRequestDto { + + public static final String EDC_DATA_REQUEST_DTO_TYPE = EDC_NAMESPACE + "DataRequestDto"; + public static final String EDC_DATA_REQUEST_DTO_ASSET_ID = EDC_NAMESPACE + "assetId"; + public static final String EDC_DATA_REQUEST_DTO_CONTRACT_ID = EDC_NAMESPACE + "contractId"; + public static final String EDC_DATA_REQUEST_DTO_CONNECTOR_ID = EDC_NAMESPACE + "connectorId"; + private String id; private String assetId; private String contractId; diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/TerminateTransferDto.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/TerminateTransferDto.java index 14639efba34..54e1e0c86cc 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/TerminateTransferDto.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/TerminateTransferDto.java @@ -18,8 +18,13 @@ import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; import jakarta.validation.constraints.NotEmpty; +import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; + public class TerminateTransferDto { + public static final String EDC_TERMINATE_TRANSFER_TYPE = EDC_NAMESPACE + "TerminateTransfer"; + public static final String EDC_TERMINATE_TRANSFER_REASON = EDC_NAMESPACE + "reason"; + @NotEmpty(message = "transfer process termination reason cannot be null nor empty") private String reason; diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/TransferProcessDto.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/TransferProcessDto.java index d0bbe945b99..4d6a44dcdab 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/TransferProcessDto.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/TransferProcessDto.java @@ -17,26 +17,39 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonPOJOBuilder; +import org.eclipse.edc.api.model.CallbackAddressDto; +import org.eclipse.edc.api.model.DataAddressDto; import org.eclipse.edc.api.model.MutableDto; -import org.eclipse.edc.spi.types.domain.callback.CallbackAddress; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; + @JsonDeserialize(builder = TransferProcessDto.Builder.class) public class TransferProcessDto extends MutableDto { + + public static final String EDC_TRANSFER_PROCESS_DTO_TYPE = EDC_NAMESPACE + "TransferProcessDto"; + public static final String EDC_TRANSFER_PROCESS_DTO_STATE = EDC_NAMESPACE + "state"; + public static final String EDC_TRANSFER_PROCESS_DTO_STATE_TIMESTAMP = EDC_NAMESPACE + "stateTimestamp"; + public static final String EDC_TRANSFER_PROCESS_DTO_PROPERTIES = EDC_NAMESPACE + "properties"; + public static final String EDC_TRANSFER_PROCESS_DTO_TYPE_TYPE = EDC_NAMESPACE + "type"; + public static final String EDC_TRANSFER_PROCESS_DTO_ERROR_DETAIL = EDC_NAMESPACE + "errorDetail"; + public static final String EDC_TRANSFER_PROCESS_DTO_DATA_REQUEST = EDC_NAMESPACE + "dataRequest"; + public static final String EDC_TRANSFER_PROCESS_DTO_DATA_DESTINATION = EDC_NAMESPACE + "dataDestination"; + public static final String EDC_TRANSFER_PROCESS_DTO_CALLBACK_ADDRESSES = EDC_NAMESPACE + "callbackAddresses"; + private String id; private String type; private String state; private Long stateTimestamp; private String errorDetail; private DataRequestDto dataRequest; - private DataAddressInformationDto dataDestination; - + private DataAddressDto dataDestination; private Map properties = new HashMap<>(); - private List callbackAddresses = new ArrayList<>(); + private List callbackAddresses = new ArrayList<>(); private TransferProcessDto() { } @@ -61,15 +74,19 @@ public String getErrorDetail() { return errorDetail; } + public Map getProperties() { + return properties; + } + public DataRequestDto getDataRequest() { return dataRequest; } - public List getCallbackAddresses() { + public List getCallbackAddresses() { return callbackAddresses; } - public DataAddressInformationDto getDataDestination() { + public DataAddressDto getDataDestination() { return dataDestination; } @@ -115,7 +132,7 @@ public Builder dataRequest(DataRequestDto dataRequest) { return this; } - public Builder dataDestination(DataAddressInformationDto dataDestination) { + public Builder dataDestination(DataAddressDto dataDestination) { dto.dataDestination = dataDestination; return this; } @@ -125,7 +142,7 @@ public Builder properties(Map properties) { return this; } - public Builder callbackAddresses(List callbackAddresses) { + public Builder callbackAddresses(List callbackAddresses) { dto.callbackAddresses = callbackAddresses; return this; } diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/TransferRequestDto.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/TransferRequestDto.java index 636dd7727f0..46e02f14016 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/TransferRequestDto.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/TransferRequestDto.java @@ -26,9 +26,21 @@ import java.util.List; import java.util.Map; +import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; + @JsonDeserialize(builder = TransferRequestDto.Builder.class) public class TransferRequestDto { + public static final String EDC_TRANSFER_REQUEST_DTO_TYPE = EDC_NAMESPACE + "TransferRequestDto"; + public static final String EDC_TRANSFER_REQUEST_DTO_CONNECTOR_ADDRESS = EDC_NAMESPACE + "connectorAddress"; + public static final String EDC_TRANSFER_REQUEST_DTO_CONTRACT_ID = EDC_NAMESPACE + "contractId"; + public static final String EDC_TRANSFER_REQUEST_DTO_DATA_DESTINATION = EDC_NAMESPACE + "dataDestination"; + public static final String EDC_TRANSFER_REQUEST_DTO_MANAGED_RESOURCES = EDC_NAMESPACE + "managedResources"; + public static final String EDC_TRANSFER_REQUEST_DTO_PROPERTIES = EDC_NAMESPACE + "properties"; + public static final String EDC_TRANSFER_REQUEST_DTO_PROTOCOL = EDC_NAMESPACE + "protocol"; + public static final String EDC_TRANSFER_REQUEST_DTO_CONNECTOR_ID = EDC_NAMESPACE + "connectorId"; + public static final String EDC_TRANSFER_REQUEST_DTO_ASSET_ID = EDC_NAMESPACE + "assetId"; + private String id; @NotNull(message = "connectorAddress cannot be null") private String connectorAddress; // TODO change to callbackAddress diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/TransferState.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/TransferState.java index d275c9663f1..785b2dd7fb1 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/TransferState.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/model/TransferState.java @@ -16,10 +16,16 @@ import org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates; +import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; + /** * Wrapper for {@link TransferProcessStates} formatted as String. Used to format a simple string as JSON. */ public class TransferState { + + public static final String EDC_TRANSFER_STATE_TYPE = EDC_NAMESPACE + "TransferState"; + public static final String EDC_TRANSFER_STATE_STATE = EDC_NAMESPACE + "state"; + private final String state; public TransferState(String state) { diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromDataRequestDtoTransformer.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromDataRequestDtoTransformer.java new file mode 100644 index 00000000000..931c76c130a --- /dev/null +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromDataRequestDtoTransformer.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2023 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.management.transferprocess.transform; + +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.api.management.transferprocess.model.DataRequestDto; +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.api.management.transferprocess.model.DataRequestDto.EDC_DATA_REQUEST_DTO_ASSET_ID; +import static org.eclipse.edc.connector.api.management.transferprocess.model.DataRequestDto.EDC_DATA_REQUEST_DTO_CONNECTOR_ID; +import static org.eclipse.edc.connector.api.management.transferprocess.model.DataRequestDto.EDC_DATA_REQUEST_DTO_CONTRACT_ID; +import static org.eclipse.edc.connector.api.management.transferprocess.model.DataRequestDto.EDC_DATA_REQUEST_DTO_TYPE; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; + +public class JsonObjectFromDataRequestDtoTransformer extends AbstractJsonLdTransformer { + + private final JsonBuilderFactory builderFactory; + + public JsonObjectFromDataRequestDtoTransformer(JsonBuilderFactory builderFactory) { + super(DataRequestDto.class, JsonObject.class); + this.builderFactory = builderFactory; + } + + @Override + public @Nullable JsonObject transform(@NotNull DataRequestDto input, @NotNull TransformerContext context) { + var builder = builderFactory.createObjectBuilder() + .add(TYPE, EDC_DATA_REQUEST_DTO_TYPE) + .add(ID, input.getId()); + + Optional.ofNullable(input.getAssetId()).ifPresent(it -> builder.add(EDC_DATA_REQUEST_DTO_ASSET_ID, it)); + Optional.ofNullable(input.getContractId()).ifPresent(it -> builder.add(EDC_DATA_REQUEST_DTO_CONTRACT_ID, it)); + Optional.ofNullable(input.getConnectorId()).ifPresent(it -> builder.add(EDC_DATA_REQUEST_DTO_CONNECTOR_ID, it)); + + return builder.build(); + } +} diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromTransferProcessDtoTransformer.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromTransferProcessDtoTransformer.java new file mode 100644 index 00000000000..c21c979ba48 --- /dev/null +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromTransferProcessDtoTransformer.java @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2023 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.management.transferprocess.transform; + +import com.fasterxml.jackson.databind.ObjectMapper; +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto; +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 java.util.stream.Collectors.collectingAndThen; +import static java.util.stream.Collectors.toList; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto.EDC_TRANSFER_PROCESS_DTO_CALLBACK_ADDRESSES; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto.EDC_TRANSFER_PROCESS_DTO_DATA_DESTINATION; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto.EDC_TRANSFER_PROCESS_DTO_DATA_REQUEST; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto.EDC_TRANSFER_PROCESS_DTO_ERROR_DETAIL; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto.EDC_TRANSFER_PROCESS_DTO_STATE; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto.EDC_TRANSFER_PROCESS_DTO_STATE_TIMESTAMP; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto.EDC_TRANSFER_PROCESS_DTO_TYPE; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto.EDC_TRANSFER_PROCESS_DTO_TYPE_TYPE; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; + +public class JsonObjectFromTransferProcessDtoTransformer extends AbstractJsonLdTransformer { + + private final JsonBuilderFactory builderFactory; + private final ObjectMapper mapper; + + public JsonObjectFromTransferProcessDtoTransformer(JsonBuilderFactory builderFactory, ObjectMapper mapper) { + super(TransferProcessDto.class, JsonObject.class); + this.builderFactory = builderFactory; + this.mapper = mapper; + } + + @Override + public @Nullable JsonObject transform(@NotNull TransferProcessDto input, @NotNull TransformerContext context) { + var callbackAddresses = input.getCallbackAddresses().stream() + .map(it -> context.transform(it, JsonObject.class)) + .collect(collectingAndThen(toList(), l -> builderFactory.createArrayBuilder(l).build())); + + var builder = builderFactory.createObjectBuilder() + .add(ID, input.getId()) + .add(TYPE, EDC_TRANSFER_PROCESS_DTO_TYPE) + .add(EDC_TRANSFER_PROCESS_DTO_STATE, input.getState()) + .add(EDC_TRANSFER_PROCESS_DTO_STATE_TIMESTAMP, input.getStateTimestamp()) + .add(EDC_TRANSFER_PROCESS_DTO_TYPE_TYPE, input.getType()) + .add(EDC_TRANSFER_PROCESS_DTO_CALLBACK_ADDRESSES, callbackAddresses) + .add(EDC_TRANSFER_PROCESS_DTO_DATA_DESTINATION, context.transform(input.getDataDestination(), JsonObject.class)) + .add(EDC_TRANSFER_PROCESS_DTO_DATA_REQUEST, context.transform(input.getDataRequest(), JsonObject.class)); + + Optional.ofNullable(input.getErrorDetail()).ifPresent(it -> builder.add(EDC_TRANSFER_PROCESS_DTO_ERROR_DETAIL, it)); + + transformProperties(input.getProperties(), builder, mapper, context); + + return builder.build(); + } + +} diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromTransferStateTransformer.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromTransferStateTransformer.java new file mode 100644 index 00000000000..10aca327edb --- /dev/null +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromTransferStateTransformer.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 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.management.transferprocess.transform; + +import jakarta.json.JsonBuilderFactory; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.api.management.transferprocess.model.TransferState; +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 static org.eclipse.edc.connector.api.management.transferprocess.model.TransferState.EDC_TRANSFER_STATE_STATE; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferState.EDC_TRANSFER_STATE_TYPE; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; + +public class JsonObjectFromTransferStateTransformer extends AbstractJsonLdTransformer { + + private final JsonBuilderFactory builderFactory; + + public JsonObjectFromTransferStateTransformer(JsonBuilderFactory builderFactory) { + super(TransferState.class, JsonObject.class); + this.builderFactory = builderFactory; + } + + @Override + public @Nullable JsonObject transform(@NotNull TransferState input, @NotNull TransformerContext context) { + var builder = builderFactory.createObjectBuilder(); + builder.add(TYPE, EDC_TRANSFER_STATE_TYPE); + builder.add(EDC_TRANSFER_STATE_STATE, input.getState()); + return builder.build(); + } + +} diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTerminateTransferDtoTransformer.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTerminateTransferDtoTransformer.java new file mode 100644 index 00000000000..3e92c76cf51 --- /dev/null +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTerminateTransferDtoTransformer.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023 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.management.transferprocess.transform; + +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.api.management.transferprocess.model.TerminateTransferDto; +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 static org.eclipse.edc.connector.api.management.transferprocess.model.TerminateTransferDto.EDC_TERMINATE_TRANSFER_REASON; + +public class JsonObjectToTerminateTransferDtoTransformer extends AbstractJsonLdTransformer { + + public JsonObjectToTerminateTransferDtoTransformer() { + super(JsonObject.class, TerminateTransferDto.class); + } + + @Override + public @Nullable TerminateTransferDto transform(@NotNull JsonObject input, @NotNull TransformerContext context) { + var builder = TerminateTransferDto.Builder.newInstance(); + + visitProperties(input, key -> { + if (key.equals(EDC_TERMINATE_TRANSFER_REASON)) { + return v -> builder.reason(transformString(v, context)); + } + return doNothing(); + }); + + return builder.build(); + } + +} diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTransferRequestDtoTransformer.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTransferRequestDtoTransformer.java new file mode 100644 index 00000000000..eadf1d15464 --- /dev/null +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTransferRequestDtoTransformer.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2023 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.management.transferprocess.transform; + +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto; +import org.eclipse.edc.jsonld.spi.transformer.AbstractJsonLdTransformer; +import org.eclipse.edc.spi.types.domain.DataAddress; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; + +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto.EDC_TRANSFER_REQUEST_DTO_ASSET_ID; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto.EDC_TRANSFER_REQUEST_DTO_CONNECTOR_ADDRESS; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto.EDC_TRANSFER_REQUEST_DTO_CONNECTOR_ID; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto.EDC_TRANSFER_REQUEST_DTO_CONTRACT_ID; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto.EDC_TRANSFER_REQUEST_DTO_DATA_DESTINATION; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto.EDC_TRANSFER_REQUEST_DTO_MANAGED_RESOURCES; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto.EDC_TRANSFER_REQUEST_DTO_PROPERTIES; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto.EDC_TRANSFER_REQUEST_DTO_PROTOCOL; + +public class JsonObjectToTransferRequestDtoTransformer extends AbstractJsonLdTransformer { + + public JsonObjectToTransferRequestDtoTransformer() { + super(JsonObject.class, TransferRequestDto.class); + } + + @Override + public @Nullable TransferRequestDto transform(@NotNull JsonObject input, @NotNull TransformerContext context) { + var builder = TransferRequestDto.Builder.newInstance(); + + builder.id(nodeId(input)); + visitProperties(input, k -> { + switch (k) { + case EDC_TRANSFER_REQUEST_DTO_CONNECTOR_ADDRESS: + return v -> builder.connectorAddress(transformString(v, context)); + case EDC_TRANSFER_REQUEST_DTO_CONTRACT_ID: + return (v) -> builder.contractId(transformString(v, context)); + case EDC_TRANSFER_REQUEST_DTO_DATA_DESTINATION: + return (v) -> builder.dataDestination(transformObject(v, DataAddress.class, context)); + case EDC_TRANSFER_REQUEST_DTO_MANAGED_RESOURCES: + return (v) -> builder.managedResources(transformBoolean(v, context)); + case EDC_TRANSFER_REQUEST_DTO_PROPERTIES: + return (v) -> builder.properties(context.transform(v, Map.class)); + case EDC_TRANSFER_REQUEST_DTO_PROTOCOL: + return (v) -> builder.protocol(transformString(v, context)); + case EDC_TRANSFER_REQUEST_DTO_CONNECTOR_ID: + return (v) -> builder.connectorId(transformString(v, context)); + case EDC_TRANSFER_REQUEST_DTO_ASSET_ID: + return (v) -> builder.assetId(transformString(v, context)); + default: + return doNothing(); + } + }); + + return builder.build(); + } +} diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/TransferProcessToTransferProcessDtoTransformer.java b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/TransferProcessToTransferProcessDtoTransformer.java index 437821bf882..c0ee66f26f8 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/TransferProcessToTransferProcessDtoTransformer.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/main/java/org/eclipse/edc/connector/api/management/transferprocess/transform/TransferProcessToTransferProcessDtoTransformer.java @@ -14,16 +14,24 @@ package org.eclipse.edc.connector.api.management.transferprocess.transform; +import org.eclipse.edc.api.model.CallbackAddressDto; +import org.eclipse.edc.api.model.DataAddressDto; import org.eclipse.edc.api.transformer.DtoTransformer; -import org.eclipse.edc.connector.api.management.transferprocess.model.DataAddressInformationDto; import org.eclipse.edc.connector.api.management.transferprocess.model.DataRequestDto; import org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto; +import org.eclipse.edc.connector.transfer.spi.types.DataRequest; import org.eclipse.edc.connector.transfer.spi.types.TransferProcess; import org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates; +import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.transform.spi.TransformerContext; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import java.util.Collections; +import java.util.Optional; + +import static java.util.stream.Collectors.toList; + public class TransferProcessToTransferProcessDtoTransformer implements DtoTransformer { @Override @@ -38,6 +46,8 @@ public Class getOutputType() { @Override public @Nullable TransferProcessDto transform(@NotNull TransferProcess object, @NotNull TransformerContext context) { + var dataRequest = object.getDataRequest(); + var dataRequestProperties = Optional.ofNullable(dataRequest).map(DataRequest::getDataDestination).map(DataAddress::getProperties).orElseGet(Collections::emptyMap); return TransferProcessDto.Builder.newInstance() .id(object.getId()) .type(object.getType().name()) @@ -46,12 +56,12 @@ public Class getOutputType() { .errorDetail(object.getErrorDetail()) .createdAt(object.getCreatedAt()) .updatedAt(object.getUpdatedAt()) - .dataRequest(context.transform(object.getDataRequest(), DataRequestDto.class)) + .dataRequest(context.transform(dataRequest, DataRequestDto.class)) .properties(object.getProperties()) - .callbackAddresses(object.getCallbackAddresses()) + .callbackAddresses(object.getCallbackAddresses().stream().map(it -> context.transform(it, CallbackAddressDto.class)).collect(toList())) .dataDestination( - DataAddressInformationDto.Builder.newInstance() - .properties(object.getDataRequest().getDataDestination().getProperties()) + DataAddressDto.Builder.newInstance() + .properties(dataRequestProperties) .build()) .build(); } diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiControllerTest.java b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiControllerTest.java index 9e2b93c99e4..1d239a5bb24 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiControllerTest.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessApiControllerTest.java @@ -268,9 +268,10 @@ void initiateTransfer() { var processId = "processId"; var tr = transferRequest(transferReqDto); var dr = tr.getDataRequest(); + var transferProcess = TransferProcess.Builder.newInstance().id(processId).build(); when(transformerRegistry.transform(isA(TransferRequestDto.class), eq(TransferRequest.class))).thenReturn(Result.success(tr)); - when(service.initiateTransfer(any())).thenReturn(ServiceResult.success(processId)); + when(service.initiateTransfer(any())).thenReturn(ServiceResult.success(transferProcess)); var result = controller.initiateTransfer(transferReqDto); diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessNewApiControllerTest.java b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessNewApiControllerTest.java new file mode 100644 index 00000000000..113c5f08084 --- /dev/null +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/TransferProcessNewApiControllerTest.java @@ -0,0 +1,422 @@ +/* + * Copyright (c) 2023 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.management.transferprocess; + +import jakarta.json.Json; +import jakarta.json.JsonObject; +import org.eclipse.edc.api.model.IdResponseDto; +import org.eclipse.edc.api.query.QuerySpecDto; +import org.eclipse.edc.connector.api.management.transferprocess.model.TerminateTransferDto; +import org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto; +import org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto; +import org.eclipse.edc.connector.spi.transferprocess.TransferProcessService; +import org.eclipse.edc.connector.transfer.spi.types.DataRequest; +import org.eclipse.edc.connector.transfer.spi.types.TransferProcess; +import org.eclipse.edc.connector.transfer.spi.types.TransferRequest; +import org.eclipse.edc.jsonld.spi.JsonLd; +import org.eclipse.edc.junit.annotations.ApiTest; +import org.eclipse.edc.service.spi.result.ServiceResult; +import org.eclipse.edc.spi.query.QuerySpec; +import org.eclipse.edc.spi.result.Result; +import org.eclipse.edc.spi.types.domain.DataAddress; +import org.eclipse.edc.transform.spi.TypeTransformerRegistry; +import org.eclipse.edc.web.jersey.testfixtures.RestControllerTestBase; +import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.Test; + +import java.util.UUID; +import java.util.stream.Stream; + +import static io.restassured.RestAssured.given; +import static io.restassured.http.ContentType.JSON; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.hamcrest.Matchers.is; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; +import static org.mockito.Mockito.when; + +@ApiTest +class TransferProcessNewApiControllerTest extends RestControllerTestBase { + + private final TypeTransformerRegistry transformerRegistry = mock(TypeTransformerRegistry.class); + private final JsonLd jsonLd = mock(JsonLd.class); + private final TransferProcessService service = mock(TransferProcessService.class); + + @Override + protected Object controller() { + return new TransferProcessNewApiController(monitor, service, transformerRegistry, jsonLd); + } + + @Test + void get_shouldReturnTransferProcess() { + var transferProcess = createTransferProcess().id("id").build(); + var dto = TransferProcessDto.Builder.newInstance().id("id").createdAt(1234).build(); + var expandedBody = Json.createObjectBuilder().add("id", "id").add("createdAt", 1234).build(); + var responseBody = Json.createObjectBuilder().add("id", "id").add("createdAt", 1234).build(); + when(service.findById(any())).thenReturn(transferProcess); + when(transformerRegistry.transform(any(), eq(TransferProcessDto.class))).thenReturn(Result.success(dto)); + when(transformerRegistry.transform(any(), eq(JsonObject.class))).thenReturn(Result.success(expandedBody)); + when(jsonLd.compact(any())).thenReturn(Result.success(responseBody)); + + given() + .port(port) + .get("/v2/transferprocesses/id") + .then() + .statusCode(200) + .contentType(JSON) + .body("id", is("id")) + .body("createdAt", is(1234)); + verify(service).findById("id"); + verify(transformerRegistry).transform(transferProcess, TransferProcessDto.class); + verify(transformerRegistry).transform(dto, JsonObject.class); + verify(jsonLd).compact(expandedBody); + } + + @Test + void get_shouldReturnNotFound_whenNotFound() { + when(service.findById(any())).thenReturn(null); + + given() + .port(port) + .get("/v2/transferprocesses/id") + .then() + .statusCode(404) + .contentType(JSON); + verifyNoInteractions(transformerRegistry); + } + + @Test + void get_shouldReturnNotFound_whenTransformFails() { + when(service.findById(any())).thenReturn(createTransferProcess().build()); + when(transformerRegistry.transform(any(), any())).thenReturn(Result.failure("error")); + + given() + .port(port) + .get("/v2/transferprocesses/id") + .then() + .statusCode(404) + .contentType(JSON); + } + + @Test + void getState_shouldReturnTheState() { + when(service.getState(any())).thenReturn("INITIAL"); + var expanded = Json.createObjectBuilder().build(); + var compacted = Json.createObjectBuilder().add("state", "INITIAL").build(); + when(transformerRegistry.transform(any(), eq(JsonObject.class))).thenReturn(Result.success(expanded)); + when(jsonLd.compact(any())).thenReturn(Result.success(compacted)); + + given() + .port(port) + .get("/v2/transferprocesses/id/state") + .then() + .statusCode(200) + .contentType(JSON) + .body("state", is("INITIAL")); + verify(service).getState("id"); + } + + @Test + void getState_shouldReturnNotFound_whenTransferProcessIsNotFound() { + when(service.getState(any())).thenReturn(null); + + given() + .port(port) + .get("/v2/transferprocesses/id/state") + .then() + .statusCode(404); + verify(service).getState("id"); + verifyNoInteractions(transformerRegistry, jsonLd); + } + + @Test + void query_shouldReturnQueriedTransferProcesses() { + var querySpec = QuerySpec.none(); + var querySpecDto = QuerySpecDto.Builder.newInstance().build(); + var expandedRequestBody = Json.createObjectBuilder().build(); + var transferProcess = createTransferProcess().id("id").build(); + var dto = TransferProcessDto.Builder.newInstance().id("id").createdAt(1234).build(); + var expandedResponseBody = Json.createObjectBuilder().add("id", "id").add("createdAt", 1234).build(); + var responseBody = Json.createObjectBuilder().add("id", "id").add("createdAt", 1234).build(); + when(jsonLd.expand(any())).thenReturn(Result.success(expandedRequestBody)); + when(transformerRegistry.transform(any(), eq(QuerySpecDto.class))).thenReturn(Result.success(querySpecDto)); + when(transformerRegistry.transform(any(), eq(QuerySpec.class))).thenReturn(Result.success(querySpec)); + when(service.query(any())).thenReturn(ServiceResult.success(Stream.of(transferProcess))); + when(transformerRegistry.transform(any(), eq(TransferProcessDto.class))).thenReturn(Result.success(dto)); + when(transformerRegistry.transform(any(), eq(JsonObject.class))).thenReturn(Result.success(expandedResponseBody)); + when(jsonLd.compact(any())).thenReturn(Result.success(responseBody)); + var requestBody = Json.createObjectBuilder().build(); + + given() + .port(port) + .body(requestBody) + .contentType(JSON) + .post("/v2/transferprocesses/request") + .then() + .statusCode(200) + .contentType(JSON) + .body("size()", is(1)) + .body("[0].id", is("id")) + .body("[0].createdAt", is(1234)); + verify(jsonLd).expand(any()); + verify(transformerRegistry).transform(expandedRequestBody, QuerySpecDto.class); + verify(transformerRegistry).transform(querySpecDto, QuerySpec.class); + verify(service).query(querySpec); + verify(transformerRegistry).transform(transferProcess, TransferProcessDto.class); + verify(transformerRegistry).transform(dto, JsonObject.class); + verify(jsonLd).compact(responseBody); + } + + @Test + void query_shouldReturn400_whenQuerySpecTransformFails() { + var expandedRequestBody = Json.createObjectBuilder().build(); + when(jsonLd.expand(any())).thenReturn(Result.success(expandedRequestBody)); + when(transformerRegistry.transform(any(), eq(QuerySpecDto.class))).thenReturn(Result.failure("error")); + var requestBody = Json.createObjectBuilder().build(); + + given() + .port(port) + .body(requestBody) + .contentType(JSON) + .post("/v2/transferprocesses/request") + .then() + .statusCode(400); + verifyNoInteractions(service); + } + + @Test + void query_shouldReturnBadRequest_whenServiceReturnsBadRequest() { + var querySpec = QuerySpec.none(); + var querySpecDto = QuerySpecDto.Builder.newInstance().build(); + var expandedRequestBody = Json.createObjectBuilder().build(); + when(jsonLd.expand(any())).thenReturn(Result.success(expandedRequestBody)); + when(transformerRegistry.transform(any(), eq(QuerySpecDto.class))).thenReturn(Result.success(querySpecDto)); + when(transformerRegistry.transform(any(), eq(QuerySpec.class))).thenReturn(Result.success(querySpec)); + when(service.query(any())).thenReturn(ServiceResult.badRequest("error")); + var requestBody = Json.createObjectBuilder().build(); + + given() + .port(port) + .body(requestBody) + .contentType(JSON) + .post("/v2/transferprocesses/request") + .then() + .statusCode(400) + .contentType(JSON); + } + + @Test + void query_shouldFilterOutResults_whenTransformFails() { + var querySpec = QuerySpec.none(); + var querySpecDto = QuerySpecDto.Builder.newInstance().build(); + var expandedRequestBody = Json.createObjectBuilder().build(); + var transferProcess = createTransferProcess().id("id").build(); + when(jsonLd.expand(any())).thenReturn(Result.success(expandedRequestBody)); + when(transformerRegistry.transform(any(), eq(QuerySpecDto.class))).thenReturn(Result.success(querySpecDto)); + when(transformerRegistry.transform(any(), eq(QuerySpec.class))).thenReturn(Result.success(querySpec)); + when(service.query(any())).thenReturn(ServiceResult.success(Stream.of(transferProcess))); + when(transformerRegistry.transform(any(), eq(TransferProcessDto.class))).thenReturn(Result.failure("error")); + var requestBody = Json.createObjectBuilder().build(); + + given() + .port(port) + .body(requestBody) + .contentType(JSON) + .post("/v2/transferprocesses/request") + .then() + .statusCode(200) + .contentType(JSON) + .body("size()", is(0)); + } + + @Test + void initiate_shouldReturnId() { + var dto = TransferRequestDto.Builder.newInstance().build(); + var transferRequest = TransferRequest.Builder.newInstance().dataRequest(createDataRequest()).build(); + var transferProcess = createTransferProcess().id("id").build(); + var expandedOutput = Json.createObjectBuilder().build(); + var responseBody = Json.createObjectBuilder().add(ID, "transferProcessId").build(); + when(jsonLd.expand(any())).thenReturn(Result.success(Json.createObjectBuilder().build())); + when(transformerRegistry.transform(any(), eq(TransferRequestDto.class))).thenReturn(Result.success(dto)); + when(transformerRegistry.transform(any(), eq(TransferRequest.class))).thenReturn(Result.success(transferRequest)); + when(service.initiateTransfer(any())).thenReturn(ServiceResult.success(transferProcess)); + when(transformerRegistry.transform(any(), eq(JsonObject.class))).thenReturn(Result.success(expandedOutput)); + when(jsonLd.compact(any())).thenReturn(Result.success(responseBody)); + var requestBody = Json.createObjectBuilder().build(); + + given() + .port(port) + .body(requestBody) + .contentType(JSON) + .post("/v2/transferprocesses") + .then() + .statusCode(200) + .contentType(JSON) + .body(ID, is("transferProcessId")); + verify(jsonLd).expand(isA(JsonObject.class)); + verify(transformerRegistry).transform(isA(JsonObject.class), eq(TransferRequestDto.class)); + verify(transformerRegistry).transform(dto, TransferRequest.class); + verify(service).initiateTransfer(transferRequest); + verify(transformerRegistry).transform(isA(IdResponseDto.class), eq(JsonObject.class)); + verify(jsonLd).compact(expandedOutput); + } + + @Test + void initiate_shouldReturnBadRequest_whenTransformationFails() { + when(jsonLd.expand(any())).thenReturn(Result.success(Json.createObjectBuilder().build())); + when(transformerRegistry.transform(any(), any())).thenReturn(Result.failure("error")); + var requestBody = Json.createObjectBuilder().build(); + + given() + .port(port) + .body(requestBody) + .contentType(JSON) + .post("/v2/transferprocesses") + .then() + .statusCode(400) + .contentType(JSON); + verifyNoInteractions(service); + } + + @Test + void initiate_shouldReturnConflict_whenItAlreadyExists() { + var dto = TransferRequestDto.Builder.newInstance().build(); + var transferRequest = TransferRequest.Builder.newInstance().dataRequest(createDataRequest()).build(); + when(jsonLd.expand(any())).thenReturn(Result.success(Json.createObjectBuilder().build())); + when(transformerRegistry.transform(any(), eq(TransferRequestDto.class))).thenReturn(Result.success(dto)); + when(transformerRegistry.transform(any(), eq(TransferRequest.class))).thenReturn(Result.success(transferRequest)); + when(service.initiateTransfer(any())).thenReturn(ServiceResult.conflict("already exists")); + var requestBody = Json.createObjectBuilder().build(); + + given() + .port(port) + .body(requestBody) + .contentType(JSON) + .post("/v2/transferprocesses") + .then() + .statusCode(409) + .contentType(JSON); + } + + @Test + void deprovision() { + var transferProcess = createTransferProcess().build(); + when(service.deprovision(any())).thenReturn(ServiceResult.success(transferProcess)); + + given() + .port(port) + .contentType(JSON) + .post("/v2/transferprocesses/id/deprovision") + .then() + .statusCode(204); + verify(service).deprovision("id"); + } + + @Test + void deprovision_conflict() { + when(service.deprovision(any())).thenReturn(ServiceResult.conflict("conflict")); + + given() + .port(port) + .contentType(JSON) + .post("/v2/transferprocesses/id/deprovision") + .then() + .statusCode(409); + } + + @Test + void deprovision_NotFound() { + when(service.deprovision(any())).thenReturn(ServiceResult.notFound("not found")); + + given() + .port(port) + .contentType(JSON) + .post("/v2/transferprocesses/id/deprovision") + .then() + .statusCode(404); + } + + @Test + void terminate() { + var transferProcess = createTransferProcess().build(); + var expanded = Json.createObjectBuilder().build(); + var dto = TerminateTransferDto.Builder.newInstance().reason("anyReason").build(); + when(jsonLd.expand(any())).thenReturn(Result.success(expanded)); + when(transformerRegistry.transform(any(), eq(TerminateTransferDto.class))).thenReturn(Result.success(dto)); + when(service.terminate(any(), any())).thenReturn(ServiceResult.success(transferProcess)); + + given() + .port(port) + .contentType(JSON) + .body(Json.createObjectBuilder().build()) + .post("/v2/transferprocesses/id/terminate") + .then() + .statusCode(204); + verify(jsonLd).expand(any()); + verify(transformerRegistry).transform(expanded, TerminateTransferDto.class); + verify(service).terminate("id", "anyReason"); + } + + @Test + void terminate_shouldReturnBadRequest_whenTransformFail() { + when(jsonLd.expand(any())).thenReturn(Result.success(Json.createObjectBuilder().build())); + when(transformerRegistry.transform(any(), eq(TerminateTransferDto.class))).thenReturn(Result.failure("failure")); + + given() + .port(port) + .contentType(JSON) + .body(Json.createObjectBuilder().build()) + .post("/v2/transferprocesses/id/terminate") + .then() + .statusCode(400); + verifyNoInteractions(service); + } + + @Test + void terminate_shouldReturnConflict_whenServiceReturnsConflict() { + var expanded = Json.createObjectBuilder().build(); + var dto = TerminateTransferDto.Builder.newInstance().reason("anyReason").build(); + when(jsonLd.expand(any())).thenReturn(Result.success(expanded)); + when(transformerRegistry.transform(any(), eq(TerminateTransferDto.class))).thenReturn(Result.success(dto)); + when(service.terminate(any(), any())).thenReturn(ServiceResult.conflict("conflict")); + + given() + .port(port) + .contentType(JSON) + .post("/v2/transferprocesses/id/terminate") + .then() + .statusCode(409); + } + + @NotNull + private TransferProcess.Builder createTransferProcess() { + return TransferProcess.Builder.newInstance().id(UUID.randomUUID().toString()); + } + + private DataRequest createDataRequest() { + return DataRequest.Builder.newInstance() + .id(UUID.randomUUID().toString()) + .dataDestination(DataAddress.Builder.newInstance() + .type("type") + .build()) + .protocol("dataspace-protocol-http") + .processId(UUID.randomUUID().toString()) + .build(); + } +} diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromDataRequestDtoTransformerTest.java b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromDataRequestDtoTransformerTest.java new file mode 100644 index 00000000000..2dc04f4175f --- /dev/null +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromDataRequestDtoTransformerTest.java @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2023 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.management.transferprocess.transform; + +import jakarta.json.Json; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.api.management.transferprocess.model.DataRequestDto; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.Test; + +import static java.util.Collections.emptyMap; +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.connector.api.management.transferprocess.model.DataRequestDto.EDC_DATA_REQUEST_DTO_ASSET_ID; +import static org.eclipse.edc.connector.api.management.transferprocess.model.DataRequestDto.EDC_DATA_REQUEST_DTO_CONNECTOR_ID; +import static org.eclipse.edc.connector.api.management.transferprocess.model.DataRequestDto.EDC_DATA_REQUEST_DTO_CONTRACT_ID; +import static org.eclipse.edc.connector.api.management.transferprocess.model.DataRequestDto.EDC_DATA_REQUEST_DTO_TYPE; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.mockito.Mockito.mock; + +class JsonObjectFromDataRequestDtoTransformerTest { + + private final JsonObjectFromDataRequestDtoTransformer transformer = new JsonObjectFromDataRequestDtoTransformer(Json.createBuilderFactory(emptyMap())); + private final TransformerContext context = mock(TransformerContext.class); + + @Test + void types() { + assertThat(transformer.getInputType()).isEqualTo(DataRequestDto.class); + assertThat(transformer.getOutputType()).isEqualTo(JsonObject.class); + } + + @Test + void transform() { + var dto = DataRequestDto.Builder.newInstance() + .id("id") + .assetId("assetId") + .connectorId("connectorId") + .contractId("contractId") + .build(); + + var result = transformer.transform(dto, context); + + assertThat(result).isNotNull(); + assertThat(result.getString(ID)).isEqualTo("id"); + assertThat(result.getString(TYPE)).isEqualTo(EDC_DATA_REQUEST_DTO_TYPE); + assertThat(result.getString(EDC_DATA_REQUEST_DTO_ASSET_ID)).isEqualTo("assetId"); + assertThat(result.getString(EDC_DATA_REQUEST_DTO_CONNECTOR_ID)).isEqualTo("connectorId"); + assertThat(result.getString(EDC_DATA_REQUEST_DTO_CONTRACT_ID)).isEqualTo("contractId"); + } +} diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromTransferProcessDtoTransformerTest.java b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromTransferProcessDtoTransformerTest.java new file mode 100644 index 00000000000..75e49cca925 --- /dev/null +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromTransferProcessDtoTransformerTest.java @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2023 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.management.transferprocess.transform; + +import jakarta.json.Json; +import jakarta.json.JsonObject; +import org.eclipse.edc.api.model.CallbackAddressDto; +import org.eclipse.edc.api.model.DataAddressDto; +import org.eclipse.edc.connector.api.management.transferprocess.model.DataRequestDto; +import org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.Map; + +import static java.util.Collections.emptyMap; +import static java.util.Collections.emptySet; +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto.EDC_TRANSFER_PROCESS_DTO_CALLBACK_ADDRESSES; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto.EDC_TRANSFER_PROCESS_DTO_DATA_DESTINATION; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto.EDC_TRANSFER_PROCESS_DTO_DATA_REQUEST; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto.EDC_TRANSFER_PROCESS_DTO_ERROR_DETAIL; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto.EDC_TRANSFER_PROCESS_DTO_STATE; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto.EDC_TRANSFER_PROCESS_DTO_STATE_TIMESTAMP; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto.EDC_TRANSFER_PROCESS_DTO_TYPE; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto.EDC_TRANSFER_PROCESS_DTO_TYPE_TYPE; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.eclipse.edc.jsonld.util.JacksonJsonLd.createObjectMapper; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.isA; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class JsonObjectFromTransferProcessDtoTransformerTest { + + private final JsonObjectFromTransferProcessDtoTransformer transformer = new JsonObjectFromTransferProcessDtoTransformer(Json.createBuilderFactory(emptyMap()), createObjectMapper()); + private final TransformerContext context = mock(TransformerContext.class); + + @Test + void types() { + assertThat(transformer.getInputType()).isEqualTo(TransferProcessDto.class); + assertThat(transformer.getOutputType()).isEqualTo(JsonObject.class); + } + + @Test + void transform() { + var dataDestinationJson = Json.createObjectBuilder().build(); + var dataRequestJson = Json.createObjectBuilder().build(); + var callbackAddresJson = Json.createObjectBuilder().build(); + when(context.transform(isA(DataAddressDto.class), any())).thenReturn(dataDestinationJson); + when(context.transform(isA(DataRequestDto.class), any())).thenReturn(dataRequestJson); + when(context.transform(isA(CallbackAddressDto.class), any())).thenReturn(callbackAddresJson); + var input = TransferProcessDto.Builder.newInstance() + .id("transferProcessId") + .state("STATE") + .stateTimestamp(1234L) + .properties(Map.of("foo", "bar")) + .type("CONSUMER") + .dataDestination(DataAddressDto.Builder.newInstance().properties(Map.of("bar", "foo")).build()) + .dataRequest(DataRequestDto.Builder.newInstance().build()) + .callbackAddresses(List.of(CallbackAddressDto.Builder.newInstance().uri("http://any").events(emptySet()).build())) + .errorDetail("an error") + .build(); + + var result = transformer.transform(input, context); + + assertThat(result).isNotNull(); + assertThat(result.getString(ID)).isEqualTo("transferProcessId"); + assertThat(result.getString(TYPE)).isEqualTo(EDC_TRANSFER_PROCESS_DTO_TYPE); + assertThat(result.getString(EDC_TRANSFER_PROCESS_DTO_STATE)).isEqualTo("STATE"); + assertThat(result.getJsonNumber(EDC_TRANSFER_PROCESS_DTO_STATE_TIMESTAMP).longValue()).isEqualTo(1234L); + assertThat(result.getString("foo")).isEqualTo("bar"); + assertThat(result.getString(EDC_TRANSFER_PROCESS_DTO_TYPE_TYPE)).isEqualTo("CONSUMER"); + assertThat(result.getJsonObject(EDC_TRANSFER_PROCESS_DTO_DATA_DESTINATION)).isSameAs(dataDestinationJson); + assertThat(result.getJsonObject(EDC_TRANSFER_PROCESS_DTO_DATA_REQUEST)).isSameAs(dataRequestJson); + assertThat(result.getJsonArray(EDC_TRANSFER_PROCESS_DTO_CALLBACK_ADDRESSES).get(0)).isSameAs(callbackAddresJson); + assertThat(result.getString(EDC_TRANSFER_PROCESS_DTO_ERROR_DETAIL)).isEqualTo("an error"); + } + +} diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromTransferStateTransformerTest.java b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromTransferStateTransformerTest.java new file mode 100644 index 00000000000..07bb03492f1 --- /dev/null +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectFromTransferStateTransformerTest.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023 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.management.transferprocess.transform; + +import jakarta.json.Json; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.api.management.transferprocess.model.TransferState; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.Test; + +import static java.util.Collections.emptyMap; +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferState.EDC_TRANSFER_STATE_STATE; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferState.EDC_TRANSFER_STATE_TYPE; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.mockito.Mockito.mock; + +class JsonObjectFromTransferStateTransformerTest { + + private final JsonObjectFromTransferStateTransformer transformer = new JsonObjectFromTransferStateTransformer(Json.createBuilderFactory(emptyMap())); + private final TransformerContext context = mock(TransformerContext.class); + + @Test + void types() { + assertThat(transformer.getInputType()).isEqualTo(TransferState.class); + assertThat(transformer.getOutputType()).isEqualTo(JsonObject.class); + } + + @Test + void transform() { + var input = new TransferState("state"); + + var result = transformer.transform(input, context); + + assertThat(result).isNotNull(); + assertThat(result.getString(TYPE)).isEqualTo(EDC_TRANSFER_STATE_TYPE); + assertThat(result.getString(EDC_TRANSFER_STATE_STATE)).isEqualTo("state"); + } + +} diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTerminateTransferDtoTransformerTest.java b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTerminateTransferDtoTransformerTest.java new file mode 100644 index 00000000000..c279a32780f --- /dev/null +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTerminateTransferDtoTransformerTest.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023 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.management.transferprocess.transform; + +import jakarta.json.Json; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.api.management.transferprocess.model.TerminateTransferDto; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TerminateTransferDto.EDC_TERMINATE_TRANSFER_REASON; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TerminateTransferDto.EDC_TERMINATE_TRANSFER_TYPE; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.mockito.Mockito.mock; + +class JsonObjectToTerminateTransferDtoTransformerTest { + + private final JsonObjectToTerminateTransferDtoTransformer transformer = new JsonObjectToTerminateTransferDtoTransformer(); + private final TransformerContext context = mock(TransformerContext.class); + + @Test + void types() { + assertThat(transformer.getInputType()).isEqualTo(JsonObject.class); + assertThat(transformer.getOutputType()).isEqualTo(TerminateTransferDto.class); + } + + @Test + void transform() { + var json = Json.createObjectBuilder() + .add(TYPE, EDC_TERMINATE_TRANSFER_TYPE) + .add(EDC_TERMINATE_TRANSFER_REASON, "reason") + .build(); + + var result = transformer.transform(json, context); + + assertThat(result).isNotNull(); + assertThat(result.getReason()).isEqualTo("reason"); + } +} diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTransferRequestDtoTransformerTest.java b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTransferRequestDtoTransformerTest.java new file mode 100644 index 00000000000..5ecf380e247 --- /dev/null +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/JsonObjectToTransferRequestDtoTransformerTest.java @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2023 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.management.transferprocess.transform; + +import jakarta.json.Json; +import jakarta.json.JsonObject; +import org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto; +import org.eclipse.edc.spi.types.domain.DataAddress; +import org.eclipse.edc.transform.spi.TransformerContext; +import org.junit.jupiter.api.Test; + +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto.EDC_TRANSFER_REQUEST_DTO_ASSET_ID; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto.EDC_TRANSFER_REQUEST_DTO_CONNECTOR_ADDRESS; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto.EDC_TRANSFER_REQUEST_DTO_CONNECTOR_ID; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto.EDC_TRANSFER_REQUEST_DTO_CONTRACT_ID; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto.EDC_TRANSFER_REQUEST_DTO_DATA_DESTINATION; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto.EDC_TRANSFER_REQUEST_DTO_MANAGED_RESOURCES; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto.EDC_TRANSFER_REQUEST_DTO_PROPERTIES; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto.EDC_TRANSFER_REQUEST_DTO_PROTOCOL; +import static org.eclipse.edc.connector.api.management.transferprocess.model.TransferRequestDto.EDC_TRANSFER_REQUEST_DTO_TYPE; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +class JsonObjectToTransferRequestDtoTransformerTest { + + private final JsonObjectToTransferRequestDtoTransformer transformer = new JsonObjectToTransferRequestDtoTransformer(); + private final TransformerContext context = mock(TransformerContext.class); + + @Test + void types() { + assertThat(transformer.getInputType()).isEqualTo(JsonObject.class); + assertThat(transformer.getOutputType()).isEqualTo(TransferRequestDto.class); + } + + @Test + void transform() { + var dataDestinationJson = Json.createObjectBuilder().build(); + var propertiesJson = Json.createObjectBuilder().build(); + var dataDestination = DataAddress.Builder.newInstance().type("type").build(); + var properties = Map.of("foo", "bar"); + when(context.transform(any(), eq(DataAddress.class))).thenReturn(dataDestination); + when(context.transform(any(), eq(Map.class))).thenReturn(properties); + + var json = Json.createObjectBuilder() + .add(TYPE, EDC_TRANSFER_REQUEST_DTO_TYPE) + .add(ID, "id") + .add(EDC_TRANSFER_REQUEST_DTO_CONNECTOR_ADDRESS, "address") + .add(EDC_TRANSFER_REQUEST_DTO_CONTRACT_ID, "contractId") + .add(EDC_TRANSFER_REQUEST_DTO_DATA_DESTINATION, dataDestinationJson) + .add(EDC_TRANSFER_REQUEST_DTO_MANAGED_RESOURCES, false) + .add(EDC_TRANSFER_REQUEST_DTO_PROPERTIES, propertiesJson) + .add(EDC_TRANSFER_REQUEST_DTO_PROTOCOL, "protocol") + .add(EDC_TRANSFER_REQUEST_DTO_CONNECTOR_ID, "connectorId") + .add(EDC_TRANSFER_REQUEST_DTO_ASSET_ID, "assetId") + .build(); + + var result = transformer.transform(json, context); + + assertThat(result).isNotNull(); + assertThat(result.getId()).isEqualTo("id"); + assertThat(result.getConnectorAddress()).isEqualTo("address"); + assertThat(result.getContractId()).isEqualTo("contractId"); + assertThat(result.getDataDestination()).isSameAs(dataDestination); + assertThat(result.isManagedResources()).isFalse(); + assertThat(result.getProperties()).isSameAs(properties); + assertThat(result.getProtocol()).isEqualTo("protocol"); + assertThat(result.getConnectorId()).isEqualTo("connectorId"); + assertThat(result.getAssetId()).isEqualTo("assetId"); + } + +} diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/TransferProcessToTransferProcessDtoTransformerTest.java b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/TransferProcessToTransferProcessDtoTransformerTest.java index 146c1b759ba..07ecb47ddd5 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/TransferProcessToTransferProcessDtoTransformerTest.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/TransferProcessToTransferProcessDtoTransformerTest.java @@ -14,7 +14,8 @@ package org.eclipse.edc.connector.api.management.transferprocess.transform; -import org.eclipse.edc.connector.api.management.transferprocess.model.DataAddressInformationDto; +import org.eclipse.edc.api.model.CallbackAddressDto; +import org.eclipse.edc.api.model.DataAddressDto; import org.eclipse.edc.connector.api.management.transferprocess.model.DataRequestDto; import org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto; import org.eclipse.edc.connector.transfer.spi.types.DataRequest; @@ -55,6 +56,7 @@ void getOutputType() { @Test void transform() { when(context.transform(any(), eq(DataRequestDto.class))).thenReturn(data.dataRequestDto); + when(context.transform(any(), eq(CallbackAddressDto.class))).thenReturn(data.callbackAddressDto); var result = transformer.transform(data.entity.build(), context); @@ -67,12 +69,11 @@ void transform() { @Test void transform_whenInvalidState() { when(context.transform(any(), eq(DataRequestDto.class))).thenReturn(data.dataRequestDto); + when(context.transform(any(), eq(CallbackAddressDto.class))).thenReturn(data.callbackAddressDto); data.entity.state(invalidStateCode()); data.dto.state(null); - when(context.transform(any(), eq(DataRequestDto.class))).thenReturn(data.dataRequestDto); - var result = transformer.transform(data.entity.build(), context); verify(context).reportProblem("Invalid value for TransferProcess.state"); @@ -84,6 +85,7 @@ void transform_whenInvalidState() { @Test void transform_whenMinimalData() { when(context.transform(any(), eq(DataRequestDto.class))).thenReturn(data.dataRequestDto); + when(context.transform(any(), eq(CallbackAddressDto.class))).thenReturn(data.callbackAddressDto); data.dto.state(INITIAL.name()); data.dataDestination = DataAddress.Builder.newInstance().type(data.dataDestinationType); @@ -100,7 +102,7 @@ void transform_whenMinimalData() { .dataRequest(data.dataRequest); data.dto .dataDestination( - DataAddressInformationDto.Builder.newInstance() + DataAddressDto.Builder.newInstance() .properties(Map.of("type", data.dataDestinationType)) .build()) .state("INITIAL") diff --git a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/TransferProcessTransformerTestData.java b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/TransferProcessTransformerTestData.java index 17d3eed0691..781e507efb6 100644 --- a/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/TransferProcessTransformerTestData.java +++ b/extensions/control-plane/api/management-api/transfer-process-api/src/test/java/org/eclipse/edc/connector/api/management/transferprocess/transform/TransferProcessTransformerTestData.java @@ -14,7 +14,8 @@ package org.eclipse.edc.connector.api.management.transferprocess.transform; -import org.eclipse.edc.connector.api.management.transferprocess.model.DataAddressInformationDto; +import org.eclipse.edc.api.model.CallbackAddressDto; +import org.eclipse.edc.api.model.DataAddressDto; import org.eclipse.edc.connector.api.management.transferprocess.model.DataRequestDto; import org.eclipse.edc.connector.api.management.transferprocess.model.TransferProcessDto; import org.eclipse.edc.connector.transfer.spi.types.DataRequest; @@ -54,6 +55,7 @@ public class TransferProcessTransformerTestData { .dataRequest(dataRequest) .callbackAddresses(List.of(callbackAddress)); DataRequestDto dataRequestDto = DataRequestDto.Builder.newInstance().build(); + CallbackAddressDto callbackAddressDto = CallbackAddressDto.Builder.newInstance().uri("local://test").build(); TransferProcessDto.Builder dto = TransferProcessDto.Builder.newInstance() .id(id) .type(type.name()) @@ -63,9 +65,9 @@ public class TransferProcessTransformerTestData { .dataRequest(dataRequestDto) .createdAt(createdTimestamp) .updatedAt(createdTimestamp) - .callbackAddresses(List.of(callbackAddress)) + .callbackAddresses(List.of(callbackAddressDto)) .dataDestination( - DataAddressInformationDto.Builder.newInstance() + DataAddressDto.Builder.newInstance() .properties(mapWith(dataDestinationProperties, "type", dataDestinationType)) .build()); diff --git a/resources/openapi/openapi.yaml b/resources/openapi/openapi.yaml index f2cbf7a2a22..8b4fe68584b 100644 --- a/resources/openapi/openapi.yaml +++ b/resources/openapi/openapi.yaml @@ -2183,6 +2183,7 @@ paths: example: null items: $ref: '#/components/schemas/ApiErrorDetail' + deprecated: true /transferprocess/request: post: tags: @@ -2212,6 +2213,7 @@ paths: example: null items: $ref: '#/components/schemas/ApiErrorDetail' + deprecated: true /transferprocess/{id}: get: tags: @@ -2252,6 +2254,7 @@ paths: example: null items: $ref: '#/components/schemas/ApiErrorDetail' + deprecated: true /transferprocess/{id}/cancel: post: tags: @@ -2339,6 +2342,7 @@ paths: example: null items: $ref: '#/components/schemas/ApiErrorDetail' + deprecated: true /transferprocess/{id}/state: get: tags: @@ -2379,6 +2383,7 @@ paths: example: null items: $ref: '#/components/schemas/ApiErrorDetail' + deprecated: true /transferprocess/{id}/terminate: post: tags: @@ -2436,6 +2441,7 @@ paths: example: null items: $ref: '#/components/schemas/ApiErrorDetail' + deprecated: true /transferprocess/{processId}/complete: post: tags: @@ -3523,6 +3529,251 @@ paths: example: null items: $ref: '#/components/schemas/ApiErrorDetail' + /v2/transferprocesses: + post: + tags: + - Transfer Process + description: "Initiates a data transfer with the given parameters. Please note\ + \ that successfully invoking this endpoint only means that the transfer was\ + \ initiated. Clients must poll the /{id}/state endpoint to track the state" + operationId: initiateTransferProcess + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/TransferRequestDto' + responses: + "200": + description: The transfer was successfully initiated. Returns the transfer + process ID and created timestamp + content: + application/json: + schema: + $ref: '#/components/schemas/IdResponseDto' + links: + poll-state: + operationId: getTransferProcessState + parameters: + id: $response.body#/id + "400": + description: Request body was malformed + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + /v2/transferprocesses/request: + post: + tags: + - Transfer Process + description: Returns all transfer process according to a query + operationId: queryTransferProcesses + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/QuerySpecDto' + responses: + "200": + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/TransferProcessDto' + "400": + description: Request was malformed + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + /v2/transferprocesses/{id}: + get: + tags: + - Transfer Process + description: Gets an transfer process with the given ID + operationId: getTransferProcess_1 + parameters: + - name: id + in: path + required: true + style: simple + explode: false + schema: + type: string + example: null + responses: + "200": + description: The transfer process + content: + application/json: + schema: + $ref: '#/components/schemas/TransferProcessDto' + "400": + description: "Request was malformed, e.g. id was null" + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + "404": + description: A transfer process with the given ID does not exist + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + /v2/transferprocesses/{id}/deprovision: + post: + tags: + - Transfer Process + description: "Requests the deprovisioning of resources associated with a transfer\ + \ process. Due to the asynchronous nature of transfers, a successful response\ + \ only indicates that the request was successfully received. This may take\ + \ a long time, so clients must poll the /{id}/state endpoint to track the\ + \ state." + operationId: deprovisionTransferProcess_1 + parameters: + - name: id + in: path + required: true + style: simple + explode: false + schema: + type: string + example: null + responses: + "200": + description: Request to deprovision the transfer process was successfully + received + links: + poll-state: + operationId: getTransferProcessState + "400": + description: "Request was malformed, e.g. id was null" + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + "404": + description: A contract negotiation with the given ID does not exist + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + /v2/transferprocesses/{id}/state: + get: + tags: + - Transfer Process + description: Gets the state of a transfer process with the given ID + operationId: getTransferProcessState_1 + parameters: + - name: id + in: path + required: true + style: simple + explode: false + schema: + type: string + example: null + responses: + "200": + description: The transfer process's state + content: + application/json: + schema: + $ref: '#/components/schemas/TransferState' + "400": + description: "Request was malformed, e.g. id was null" + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + "404": + description: An transfer process with the given ID does not exist + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + /v2/transferprocesses/{id}/terminate: + post: + tags: + - Transfer Process + description: "Requests the termination of a transfer process. Due to the asynchronous\ + \ nature of transfers, a successful response only indicates that the request\ + \ was successfully received. Clients must poll the /{id}/state endpoint to\ + \ track the state." + operationId: terminateTransferProcess_1 + parameters: + - name: id + in: path + required: true + style: simple + explode: false + schema: + type: string + example: null + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/TerminateTransferDto' + responses: + "200": + description: Request to cancel the transfer process was successfully received + links: + poll-state: + operationId: getTransferProcessState + "400": + description: "Request was malformed, e.g. id was null" + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + "404": + description: A contract negotiation with the given ID does not exist + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + "409": + description: "Could not terminate transfer process, because it is already\ + \ completed or terminated." + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' /{any}: get: tags: @@ -4003,16 +4254,6 @@ components: example: null example: null example: null - DataAddressInformationDto: - type: object - properties: - properties: - type: object - additionalProperties: - type: string - example: null - example: null - example: null DataFlowRequest: type: object properties: @@ -4522,13 +4763,13 @@ components: type: array example: null items: - $ref: '#/components/schemas/CallbackAddress' + $ref: '#/components/schemas/CallbackAddressDto' createdAt: type: integer format: int64 example: null dataDestination: - $ref: '#/components/schemas/DataAddressInformationDto' + $ref: '#/components/schemas/DataAddressDto' dataRequest: $ref: '#/components/schemas/DataRequestDto' errorDetail: @@ -4537,6 +4778,12 @@ components: id: type: string example: null + properties: + type: object + additionalProperties: + type: string + example: null + example: null state: type: string example: null diff --git a/resources/openapi/yaml/management-api/transfer-process-api.yaml b/resources/openapi/yaml/management-api/transfer-process-api.yaml index bc85f2a0549..7f07187d4c7 100644 --- a/resources/openapi/yaml/management-api/transfer-process-api.yaml +++ b/resources/openapi/yaml/management-api/transfer-process-api.yaml @@ -57,6 +57,7 @@ paths: tags: - Transfer Process post: + deprecated: true description: "Initiates a data transfer with the given parameters. Please note\ \ that successfully invoking this endpoint only means that the transfer was\ \ initiated. Clients must poll the /{id}/state endpoint to track the state" @@ -92,6 +93,7 @@ paths: - Transfer Process /transferprocess/request: post: + deprecated: true description: Returns all transfer process according to a query operationId: queryAllTransferProcesses requestBody: @@ -121,6 +123,7 @@ paths: - Transfer Process /transferprocess/{id}: get: + deprecated: true description: Gets an transfer process with the given ID operationId: getTransferProcess parameters: @@ -200,6 +203,7 @@ paths: - Transfer Process /transferprocess/{id}/deprovision: post: + deprecated: true description: "Requests the deprovisioning of resources associated with a transfer\ \ process. Due to the asynchronous nature of transfers, a successful response\ \ only indicates that the request was successfully received. This may take\ @@ -242,6 +246,7 @@ paths: - Transfer Process /transferprocess/{id}/state: get: + deprecated: true description: Gets the state of a transfer process with the given ID operationId: getTransferProcessState parameters: @@ -280,6 +285,7 @@ paths: - Transfer Process /transferprocess/{id}/terminate: post: + deprecated: true description: "Requests the termination of a transfer process. Due to the asynchronous\ \ nature of transfers, a successful response only indicates that the request\ \ was successfully received. Clients must poll the /{id}/state endpoint to\ @@ -333,6 +339,243 @@ paths: \ completed or terminated." tags: - Transfer Process + /v2/transferprocesses: + post: + description: "Initiates a data transfer with the given parameters. Please note\ + \ that successfully invoking this endpoint only means that the transfer was\ + \ initiated. Clients must poll the /{id}/state endpoint to track the state" + operationId: initiateTransferProcess + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/TransferRequestDto' + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/IdResponseDto' + description: The transfer was successfully initiated. Returns the transfer + process ID and created timestamp + links: + poll-state: + operationId: getTransferProcessState + parameters: + id: $response.body#/id + "400": + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + description: Request body was malformed + tags: + - Transfer Process + /v2/transferprocesses/request: + post: + description: Returns all transfer process according to a query + operationId: queryTransferProcesses + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/QuerySpecDto' + responses: + "200": + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/TransferProcessDto' + "400": + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + description: Request was malformed + tags: + - Transfer Process + /v2/transferprocesses/{id}: + get: + description: Gets an transfer process with the given ID + operationId: getTransferProcess_1 + parameters: + - in: path + name: id + required: true + schema: + type: string + example: null + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/TransferProcessDto' + description: The transfer process + "400": + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + description: "Request was malformed, e.g. id was null" + "404": + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + description: A transfer process with the given ID does not exist + tags: + - Transfer Process + /v2/transferprocesses/{id}/deprovision: + post: + description: "Requests the deprovisioning of resources associated with a transfer\ + \ process. Due to the asynchronous nature of transfers, a successful response\ + \ only indicates that the request was successfully received. This may take\ + \ a long time, so clients must poll the /{id}/state endpoint to track the\ + \ state." + operationId: deprovisionTransferProcess_1 + parameters: + - in: path + name: id + required: true + schema: + type: string + example: null + responses: + "200": + description: Request to deprovision the transfer process was successfully + received + links: + poll-state: + operationId: getTransferProcessState + "400": + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + description: "Request was malformed, e.g. id was null" + "404": + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + description: A contract negotiation with the given ID does not exist + tags: + - Transfer Process + /v2/transferprocesses/{id}/state: + get: + description: Gets the state of a transfer process with the given ID + operationId: getTransferProcessState_1 + parameters: + - in: path + name: id + required: true + schema: + type: string + example: null + responses: + "200": + content: + application/json: + schema: + $ref: '#/components/schemas/TransferState' + description: The transfer process's state + "400": + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + description: "Request was malformed, e.g. id was null" + "404": + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + description: An transfer process with the given ID does not exist + tags: + - Transfer Process + /v2/transferprocesses/{id}/terminate: + post: + description: "Requests the termination of a transfer process. Due to the asynchronous\ + \ nature of transfers, a successful response only indicates that the request\ + \ was successfully received. Clients must poll the /{id}/state endpoint to\ + \ track the state." + operationId: terminateTransferProcess_1 + parameters: + - in: path + name: id + required: true + schema: + type: string + example: null + requestBody: + content: + application/json: + schema: + $ref: '#/components/schemas/TerminateTransferDto' + responses: + "200": + description: Request to cancel the transfer process was successfully received + links: + poll-state: + operationId: getTransferProcessState + "400": + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + description: "Request was malformed, e.g. id was null" + "404": + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + description: A contract negotiation with the given ID does not exist + "409": + content: + application/json: + schema: + type: array + example: null + items: + $ref: '#/components/schemas/ApiErrorDetail' + description: "Could not terminate transfer process, because it is already\ + \ completed or terminated." + tags: + - Transfer Process components: schemas: ApiErrorDetail: @@ -351,23 +594,6 @@ components: type: type: string example: null - CallbackAddress: - type: object - example: null - properties: - events: - type: array - example: null - items: - type: string - example: null - uniqueItems: true - transactional: - type: boolean - example: null - uri: - type: string - example: null CallbackAddressDto: type: object example: null @@ -414,7 +640,7 @@ components: type: string example: null example: null - DataAddressInformationDto: + DataAddressDto: type: object example: null properties: @@ -424,6 +650,8 @@ components: type: string example: null example: null + required: + - properties DataRequestDto: type: object example: null @@ -451,6 +679,41 @@ components: id: type: string example: null + JsonObject: + type: object + additionalProperties: + $ref: '#/components/schemas/JsonValue' + example: null + properties: + empty: + type: boolean + example: null + valueType: + type: string + enum: + - ARRAY + - OBJECT + - STRING + - NUMBER + - "TRUE" + - "FALSE" + - "NULL" + example: null + JsonValue: + type: object + example: null + properties: + valueType: + type: string + enum: + - ARRAY + - OBJECT + - STRING + - NUMBER + - "TRUE" + - "FALSE" + - "NULL" + example: null QuerySpecDto: type: object example: null @@ -497,13 +760,13 @@ components: type: array example: null items: - $ref: '#/components/schemas/CallbackAddress' + $ref: '#/components/schemas/CallbackAddressDto' createdAt: type: integer format: int64 example: null dataDestination: - $ref: '#/components/schemas/DataAddressInformationDto' + $ref: '#/components/schemas/DataAddressDto' dataRequest: $ref: '#/components/schemas/DataRequestDto' errorDetail: @@ -512,6 +775,12 @@ components: id: type: string example: null + properties: + type: object + additionalProperties: + type: string + example: null + example: null state: type: string example: null diff --git a/spi/common/core-spi/src/main/java/org/eclipse/edc/spi/types/domain/DataAddress.java b/spi/common/core-spi/src/main/java/org/eclipse/edc/spi/types/domain/DataAddress.java index fbce8bace06..026083c7036 100644 --- a/spi/common/core-spi/src/main/java/org/eclipse/edc/spi/types/domain/DataAddress.java +++ b/spi/common/core-spi/src/main/java/org/eclipse/edc/spi/types/domain/DataAddress.java @@ -48,7 +48,7 @@ protected DataAddress() { @NotNull public String getType() { - return Optional.ofNullable(properties.get(EDC_NAMESPACE + TYPE)).orElseGet(() -> properties.get(TYPE)); + return getProperty(TYPE); } @JsonIgnore @@ -58,12 +58,13 @@ public void setType(String type) { } public String getProperty(String key) { - return properties.get(key); + return getProperty(key, null); } public String getProperty(String key, String defaultValue) { - if (properties.containsKey(key)) { - return properties.get(key); + var value = Optional.ofNullable(properties.get(EDC_NAMESPACE + key)).orElseGet(() -> properties.get(key)); + if (value != null) { + return value; } return defaultValue; @@ -74,7 +75,7 @@ public Map getProperties() { } public String getKeyName() { - return Optional.ofNullable(properties.get(EDC_NAMESPACE + KEY_NAME)).orElseGet(() -> properties.get(KEY_NAME)); + return getProperty(KEY_NAME); } @JsonIgnore diff --git a/spi/common/json-ld-spi/src/main/java/org/eclipse/edc/jsonld/spi/transformer/AbstractJsonLdTransformer.java b/spi/common/json-ld-spi/src/main/java/org/eclipse/edc/jsonld/spi/transformer/AbstractJsonLdTransformer.java index 23245d62c67..c744744372a 100644 --- a/spi/common/json-ld-spi/src/main/java/org/eclipse/edc/jsonld/spi/transformer/AbstractJsonLdTransformer.java +++ b/spi/common/json-ld-spi/src/main/java/org/eclipse/edc/jsonld/spi/transformer/AbstractJsonLdTransformer.java @@ -70,7 +70,7 @@ public Class getOutputType() { * @param mapper the mapper for converting the properties * @param context the transformer context */ - protected void transformProperties(Map properties, JsonObjectBuilder builder, ObjectMapper mapper, TransformerContext context) { + protected void transformProperties(Map properties, JsonObjectBuilder builder, ObjectMapper mapper, TransformerContext context) { if (properties == null) { return; } @@ -172,6 +172,26 @@ protected int transformInt(JsonValue value, TransformerContext context) { } } + /** + * Transforms a JsonValue to boolean. If the value parameter is not of type JsonObject or JsonArray, + * a problem is reported to the context. + * + * @param value the value to transform + * @param context the transformer context + * @return the int value + */ + protected boolean transformBoolean(JsonValue value, TransformerContext context) { + if (value instanceof JsonObject) { + return value.asJsonObject().getBoolean(VALUE); + } else if (value instanceof JsonArray) { + return transformBoolean(value.asJsonArray().get(0), context); + } else { + context.reportProblem(format("Invalid property. Expected JsonObject or JsonArray but got %s", + value.getClass().getSimpleName())); + return false; + } + } + /** * Transforms a JsonValue to the desired output type. The result can be a single instance or a * list of that type, depending on whether the given value is a JsonObject or a JsonArray. The diff --git a/spi/common/web-spi/src/main/java/org/eclipse/edc/web/spi/exception/ServiceResultHandler.java b/spi/common/web-spi/src/main/java/org/eclipse/edc/web/spi/exception/ServiceResultHandler.java index 82552075b9a..e82ea965d08 100644 --- a/spi/common/web-spi/src/main/java/org/eclipse/edc/web/spi/exception/ServiceResultHandler.java +++ b/spi/common/web-spi/src/main/java/org/eclipse/edc/web/spi/exception/ServiceResultHandler.java @@ -24,6 +24,17 @@ public class ServiceResultHandler { + /** + * Utility method for calling {@link #mapToException(ServiceFailure, Class, String)} when id is null. + * + * @param failure The {@link ServiceFailure} + * @param clazz The type in whose context the failure occurred. Must not be null. + * @return Exception mapped from failure reason. + */ + public static EdcException mapToException(@NotNull ServiceFailure failure, @NotNull Class clazz) { + return mapToException(failure, clazz, null); + } + /** * Interprets a {@link ServiceResult#reason()} property and returns the * appropriate exception: diff --git a/spi/control-plane/control-plane-spi/src/main/java/org/eclipse/edc/connector/spi/transferprocess/TransferProcessService.java b/spi/control-plane/control-plane-spi/src/main/java/org/eclipse/edc/connector/spi/transferprocess/TransferProcessService.java index 1670bea395e..dc67851c774 100644 --- a/spi/control-plane/control-plane-spi/src/main/java/org/eclipse/edc/connector/spi/transferprocess/TransferProcessService.java +++ b/spi/control-plane/control-plane-spi/src/main/java/org/eclipse/edc/connector/spi/transferprocess/TransferProcessService.java @@ -127,10 +127,10 @@ default ServiceResult fail(String transferProcessId, String err * Initiate transfer request for type consumer. * * @param request for the transfer. - * @return a result that is successful if the transfer process was initiated with id of created transferProcess. + * @return a result that is successful if the transfer process was initiated with the created TransferProcess. */ @NotNull - ServiceResult initiateTransfer(TransferRequest request); + ServiceResult initiateTransfer(TransferRequest request); /** * Asynchronously informs the system that the {@link DeprovisionedResource} has been provisioned diff --git a/spi/control-plane/transfer-spi/src/main/java/org/eclipse/edc/connector/transfer/spi/TransferProcessManager.java b/spi/control-plane/transfer-spi/src/main/java/org/eclipse/edc/connector/transfer/spi/TransferProcessManager.java index 2669c181044..abdfca7b7d6 100644 --- a/spi/control-plane/transfer-spi/src/main/java/org/eclipse/edc/connector/transfer/spi/TransferProcessManager.java +++ b/spi/control-plane/transfer-spi/src/main/java/org/eclipse/edc/connector/transfer/spi/TransferProcessManager.java @@ -14,6 +14,7 @@ package org.eclipse.edc.connector.transfer.spi; +import org.eclipse.edc.connector.transfer.spi.types.TransferProcess; import org.eclipse.edc.connector.transfer.spi.types.TransferRequest; import org.eclipse.edc.connector.transfer.spi.types.command.TransferProcessCommand; import org.eclipse.edc.runtime.metamodel.annotation.ExtensionPoint; @@ -29,7 +30,7 @@ public interface TransferProcessManager { /** * Initiates a data transfer process on the consumer. */ - StatusResult initiateConsumerRequest(TransferRequest transferRequest); + StatusResult initiateConsumerRequest(TransferRequest transferRequest); /** * Adds a single Command to the queue which is processed sequentially. diff --git a/system-tests/management-api/management-api-test-runner/build.gradle.kts b/system-tests/management-api/management-api-test-runner/build.gradle.kts index f1fef172f00..f38c56d4ded 100644 --- a/system-tests/management-api/management-api-test-runner/build.gradle.kts +++ b/system-tests/management-api/management-api-test-runner/build.gradle.kts @@ -24,6 +24,7 @@ dependencies { //useful for generic DTOs etc. testImplementation(project(":extensions:common:api:api-core")) testImplementation(project(":spi:control-plane:policy-spi")) + testImplementation(project(":spi:control-plane:transfer-spi")) //we need the JacksonJsonLd util class testImplementation(project(":extensions:common:json-ld")) diff --git a/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/TransferProcessApiEndToEndTest.java b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/TransferProcessApiEndToEndTest.java new file mode 100644 index 00000000000..3e02d160e99 --- /dev/null +++ b/system-tests/management-api/management-api-test-runner/src/test/java/org/eclipse/edc/test/e2e/managementapi/TransferProcessApiEndToEndTest.java @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2023 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.test.e2e.managementapi; + +import io.restassured.specification.RequestSpecification; +import jakarta.json.Json; +import org.eclipse.edc.connector.transfer.spi.store.TransferProcessStore; +import org.eclipse.edc.connector.transfer.spi.types.DataRequest; +import org.eclipse.edc.connector.transfer.spi.types.TransferProcess; +import org.eclipse.edc.junit.annotations.EndToEndTest; +import org.eclipse.edc.spi.types.domain.DataAddress; +import org.junit.jupiter.api.Test; + +import java.util.UUID; + +import static io.restassured.RestAssured.given; +import static io.restassured.http.ContentType.JSON; +import static org.assertj.core.api.Assertions.assertThat; +import static org.eclipse.edc.connector.transfer.spi.types.TransferProcessStates.COMPLETED; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; +import static org.hamcrest.CoreMatchers.anyOf; +import static org.hamcrest.Matchers.is; + +@EndToEndTest +public class TransferProcessApiEndToEndTest extends BaseManagementApiEndToEndTest { + + @Test + void getAll() { + getStore().updateOrCreate(createTransferProcess("tp1")); + getStore().updateOrCreate(createTransferProcess("tp2")); + var requestBody = Json.createObjectBuilder().build(); + + baseRequest() + .contentType(JSON) + .body(requestBody) + .post("/request") + .then() + .statusCode(200) + .body("size()", is(2)) + .body("[0].@id", anyOf(is("tp1"), is("tp2"))) + .body("[1].@id", anyOf(is("tp1"), is("tp2"))); + } + + @Test + void getById() { + getStore().updateOrCreate(createTransferProcess("tp1")); + getStore().updateOrCreate(createTransferProcess("tp2")); + + baseRequest() + .get("/tp2") + .then() + .statusCode(200) + .body("@id", is("tp2")) + .body(TYPE, is("edc:TransferProcessDto")); + } + + @Test + void getState() { + getStore().updateOrCreate(createTransferProcessBuilder("tp2").state(COMPLETED.code()).build()); + + baseRequest() + .get("/tp2/state") + .then() + .statusCode(200) + .contentType(JSON) + .body(TYPE, is("edc:TransferState")) + .body("'edc:state'", is("COMPLETED")); + } + + @Test + void create() { + var requestBody = Json.createObjectBuilder() + .add(TYPE, EDC_NAMESPACE + "TransferRequestDto") + .add(EDC_NAMESPACE + "dataDestination", Json.createObjectBuilder() + .add(TYPE, EDC_NAMESPACE + "DataAddress") + .add(EDC_NAMESPACE + "type", "HttpData") + .add(EDC_NAMESPACE + "properties", Json.createObjectBuilder() + .add(EDC_NAMESPACE + "baseUrl", "http://any") + .build()) + .build() + ) + .add(EDC_NAMESPACE + "protocol", "dataspace-protocol-http") + .add(EDC_NAMESPACE + "assetId", "assetId") + .build(); + + var id = baseRequest() + .contentType(JSON) + .body(requestBody) + .post("/") + .then() + .statusCode(200) + .extract().jsonPath().getString(ID); + + assertThat(getStore().findById(id)).isNotNull(); + } + + @Test + void deprovision() { + var id = UUID.randomUUID().toString(); + getStore().updateOrCreate(createTransferProcessBuilder(id).state(COMPLETED.code()).build()); + + baseRequest() + .contentType(JSON) + .post("/" + id + "/deprovision") + .then() + .statusCode(204); + } + + @Test + void terminate() { + var id = UUID.randomUUID().toString(); + getStore().updateOrCreate(createTransferProcess(id)); + + baseRequest() + .contentType(JSON) + .body(Json.createObjectBuilder().build()) + .post("/" + id + "/terminate") + .then() + .statusCode(204); + } + + private TransferProcessStore getStore() { + return controlPlane.getContext().getService(TransferProcessStore.class); + } + + private TransferProcess createTransferProcess(String id) { + return createTransferProcessBuilder(id).build(); + } + + private TransferProcess.Builder createTransferProcessBuilder(String id) { + return TransferProcess.Builder.newInstance() + .id(id) + .dataRequest(DataRequest.Builder.newInstance() + .id(UUID.randomUUID().toString()) + .dataDestination(DataAddress.Builder.newInstance() + .type("type") + .build()) + .protocol("dataspace-protocol-http") + .processId(id) + .build()); + } + + private RequestSpecification baseRequest() { + return given() + .baseUri("http://localhost:" + PORT + "/management/v2/transferprocesses") + .when(); + } +} diff --git a/system-tests/runtimes/file-transfer-consumer/build.gradle.kts b/system-tests/runtimes/file-transfer-consumer/build.gradle.kts index b53c9f63ff3..b154942a70d 100644 --- a/system-tests/runtimes/file-transfer-consumer/build.gradle.kts +++ b/system-tests/runtimes/file-transfer-consumer/build.gradle.kts @@ -24,11 +24,11 @@ dependencies { implementation(project(":core:data-plane-selector:data-plane-selector-core")) implementation(project(":core:common:util")) implementation(project(":data-protocols:ids")) - implementation(project(":extensions:control-plane:api:management-api")) implementation(project(":extensions:common:api:api-observability")) implementation(project(":extensions:common:configuration:configuration-filesystem")) implementation(project(":extensions:common:iam:iam-mock")) + implementation(project(":extensions:common:json-ld")) api(libs.jakarta.rsApi) } diff --git a/system-tests/runtimes/file-transfer-provider/build.gradle.kts b/system-tests/runtimes/file-transfer-provider/build.gradle.kts index 2173b62496b..113e0916e87 100644 --- a/system-tests/runtimes/file-transfer-provider/build.gradle.kts +++ b/system-tests/runtimes/file-transfer-provider/build.gradle.kts @@ -30,15 +30,14 @@ dependencies { implementation(project(":extensions:data-plane-selector:data-plane-selector-client")) implementation(project(":core:data-plane-selector:data-plane-selector-core")) - implementation(libs.jakarta.rsApi) - implementation(libs.opentelemetry.annotations) - implementation(project(":extensions:common:api:api-observability")) - implementation(project(":extensions:common:configuration:configuration-filesystem")) implementation(project(":extensions:common:iam:iam-mock")) implementation(project(":extensions:common:json-ld")) + implementation(libs.jakarta.rsApi) + implementation(libs.opentelemetry.annotations) + implementation(project(":data-protocols:ids")) }