Skip to content

Commit

Permalink
chore(build): updates to EDC 0.1.3 (#569)
Browse files Browse the repository at this point in the history
* chore(deps): upgrade to EDC 0.1.3

* chore(deps): fix tests

* chore(deps): updates changelog
  • Loading branch information
wolf4ood authored Jul 5, 2023
1 parent d31eebe commit d98d5cd
Show file tree
Hide file tree
Showing 14 changed files with 298 additions and 221 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.5.0-rc4] - 2023-07-04

### Changed

Upgraded to EDC 0.1.3

## [0.5.0-rc4] - 2023-07-04

### Removed

Removed the interim solution `observability-api-customization` and use the upstream extension `Observability API` instead
Expand Down
282 changes: 136 additions & 146 deletions DEPENDENCIES

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
import org.eclipse.edc.web.spi.WebService;
import org.eclipse.tractusx.edc.api.cp.adapter.transform.EndpointDataReferenceToDataAddressTransformer;
import org.eclipse.tractusx.edc.api.cp.adapter.transform.JsonObjectFromEndpointDataReferenceEntryTransformer;
import org.eclipse.tractusx.edc.api.cp.adapter.transform.JsonObjectToNegotiateEdrRequestDtoTransformer;
import org.eclipse.tractusx.edc.api.cp.adapter.transform.NegotiateEdrRequestDtoToNegotiatedEdrRequestTransformer;
Expand Down Expand Up @@ -51,6 +52,7 @@ public void initialize(ServiceExtensionContext context) {
transformerRegistry.register(new NegotiateEdrRequestDtoToNegotiatedEdrRequestTransformer());
transformerRegistry.register(new JsonObjectToNegotiateEdrRequestDtoTransformer());
transformerRegistry.register(new JsonObjectFromEndpointDataReferenceEntryTransformer());
transformerRegistry.register(new EndpointDataReferenceToDataAddressTransformer());
webService.registerResource(apiConfig.getContextAlias(), new AdapterEdrController(adapterTransferProcessService, jsonLdService, transformerRegistry));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.eclipse.edc.spi.EdcException;
import org.eclipse.edc.spi.monitor.Monitor;
import org.eclipse.edc.spi.result.Result;
import org.eclipse.edc.spi.types.domain.edr.EndpointDataAddressConstants;
import org.eclipse.edc.spi.types.domain.DataAddress;
import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference;
import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
import org.eclipse.edc.web.spi.exception.InvalidRequestException;
Expand All @@ -42,8 +42,8 @@

import static org.eclipse.edc.web.spi.exception.ServiceResultHandler.exceptionMapper;

@Consumes({MediaType.APPLICATION_JSON})
@Produces({MediaType.APPLICATION_JSON})
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Path("/adapter/edrs")
public class AdapterEdrController implements AdapterEdrApi {

Expand Down Expand Up @@ -79,17 +79,6 @@ public JsonObject initiateEdrNegotiation(JsonObject requestObject) {
.orElseThrow(f -> new EdcException("Error creating response body: " + f.getFailureDetail()));
}

@GET
@Path("/{id}")
@Override
public JsonObject getEdr(@PathParam("id") String transferProcessId) {
var edr = adapterTransferProcessService.findByTransferProcessId(transferProcessId).orElseThrow(exceptionMapper(EndpointDataReference.class, transferProcessId));

return transformerRegistry.transform(EndpointDataAddressConstants.from(edr), JsonObject.class)
.compose(jsonLdService::compact)
.orElseThrow(f -> new EdcException("Error creating response body: " + f.getFailureDetail()));
}

@GET
@Override
public List<JsonObject> queryEdrs(@QueryParam("assetId") String assetId, @QueryParam("agreementId") String agreementId) {
Expand All @@ -107,6 +96,17 @@ public List<JsonObject> queryEdrs(@QueryParam("assetId") String assetId, @QueryP
.collect(Collectors.toList());
}

@GET
@Path("/{id}")
@Override
public JsonObject getEdr(@PathParam("id") String transferProcessId) {
var edr = adapterTransferProcessService.findByTransferProcessId(transferProcessId).orElseThrow(exceptionMapper(EndpointDataReference.class, transferProcessId));
return transformerRegistry.transform(edr, DataAddress.class)
.compose(dataAddress -> transformerRegistry.transform(dataAddress, JsonObject.class))
.compose(jsonLdService::compact)
.orElseThrow(f -> new EdcException("Error creating response body: " + f.getFailureDetail()));
}

private void logIfError(Result<?> result) {
result.onFailure(f -> monitor.warning(f.getFailureDetail()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

package org.eclipse.tractusx.edc.api.cp.adapter.dto;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import org.eclipse.edc.connector.api.management.contractnegotiation.model.ContractOfferDescription;
import org.eclipse.edc.spi.types.domain.callback.CallbackAddress;

Expand All @@ -35,16 +33,12 @@ public class NegotiateEdrRequestDto {
public static final String EDR_REQUEST_DTO_OFFER = EDC_NAMESPACE + "offer";
public static final String EDR_REQUEST_DTO_CALLBACK_ADDRESSES = EDC_NAMESPACE + "callbackAddresses";

@NotBlank(message = "connectorAddress is mandatory")
private String connectorAddress;
@NotBlank(message = "protocol is mandatory")
private String protocol = "ids-multipart";
@NotBlank(message = "connectorId is mandatory")
private String connectorId;

private String providerId;

@NotNull(message = "offer cannot be null")
private ContractOfferDescription offer;
private List<CallbackAddress> callbackAddresses = new ArrayList<>();

Expand Down
Original file line number Diff line number Diff line change
@@ -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.tractusx.edc.api.cp.adapter.transform;

import org.eclipse.edc.spi.types.domain.DataAddress;
import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference;
import org.eclipse.edc.transform.spi.TransformerContext;
import org.eclipse.edc.transform.spi.TypeTransformer;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import static org.eclipse.edc.spi.types.domain.edr.EndpointDataReference.AUTH_CODE;
import static org.eclipse.edc.spi.types.domain.edr.EndpointDataReference.AUTH_KEY;
import static org.eclipse.edc.spi.types.domain.edr.EndpointDataReference.EDR_SIMPLE_TYPE;
import static org.eclipse.edc.spi.types.domain.edr.EndpointDataReference.ENDPOINT;
import static org.eclipse.edc.spi.types.domain.edr.EndpointDataReference.ID;

public class EndpointDataReferenceToDataAddressTransformer implements TypeTransformer<EndpointDataReference, DataAddress> {
@Override
public Class<EndpointDataReference> getInputType() {
return EndpointDataReference.class;
}

@Override
public Class<DataAddress> getOutputType() {
return DataAddress.class;
}

@Override
public @Nullable DataAddress transform(@NotNull EndpointDataReference edr, @NotNull TransformerContext context) {
return DataAddress.Builder.newInstance()
.type(EDR_SIMPLE_TYPE)
.property(ID, edr.getId())
.property(AUTH_CODE, edr.getAuthCode())
.property(AUTH_KEY, edr.getAuthKey())
.property(ENDPOINT, edr.getEndpoint())
.properties(edr.getProperties())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ void getEdr_shouldReturnDataAddress_whenFound() {
.add(EndpointDataReference.ID, edr.getId())
.build();

var dataAddress = DataAddress.Builder.newInstance().type("HttpData").build();
when(adapterTransferProcessService.findByTransferProcessId(transferProcessId)).thenReturn(ServiceResult.success(edr));
when(transformerRegistry.transform(any(EndpointDataReference.class), eq(DataAddress.class))).thenReturn(Result.success(dataAddress));
when(transformerRegistry.transform(any(DataAddress.class), eq(JsonObject.class))).thenReturn(Result.success(response));

baseRequest()
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.tractusx.edc.api.cp.adapter.transform;

import org.eclipse.edc.transform.spi.TransformerContext;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.eclipse.edc.spi.types.domain.edr.EndpointDataReference.AUTH_CODE;
import static org.eclipse.edc.spi.types.domain.edr.EndpointDataReference.AUTH_KEY;
import static org.eclipse.edc.spi.types.domain.edr.EndpointDataReference.Builder;
import static org.eclipse.edc.spi.types.domain.edr.EndpointDataReference.EDR_SIMPLE_TYPE;
import static org.eclipse.edc.spi.types.domain.edr.EndpointDataReference.ENDPOINT;
import static org.eclipse.edc.spi.types.domain.edr.EndpointDataReference.ID;
import static org.mockito.Mockito.mock;

public class EndpointDataReferenceToDataAddressTransformerTest {

private final TransformerContext context = mock(TransformerContext.class);
private EndpointDataReferenceToDataAddressTransformer transformer;

@BeforeEach
void setUp() {
transformer = new EndpointDataReferenceToDataAddressTransformer();
}

@Test
void transform() {

var dto = Builder.newInstance()
.id("dataRequestId")
.authCode("authCode")
.authKey("authKey")
.endpoint("http://endpoint")
.build();

var dataAddress = transformer.transform(dto, context);

assertThat(dataAddress).isNotNull();
assertThat(dataAddress.getType()).isEqualTo(EDR_SIMPLE_TYPE);
assertThat(dataAddress.getProperty(ID)).isEqualTo(dto.getId());
assertThat(dataAddress.getProperty(ENDPOINT)).isEqualTo(dto.getEndpoint());
assertThat(dataAddress.getProperty(AUTH_KEY)).isEqualTo(dto.getAuthKey());
assertThat(dataAddress.getProperty(AUTH_CODE)).isEqualTo(dto.getAuthCode());

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.transaction.spi.TransactionContext;
import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
import org.eclipse.tractusx.edc.edr.spi.EndpointDataReferenceCache;
import org.eclipse.tractusx.edc.spi.cp.adapter.callback.InProcessCallbackRegistry;
import org.eclipse.tractusx.edc.spi.cp.adapter.service.AdapterTransferProcessService;
Expand Down Expand Up @@ -67,6 +68,9 @@ public class LocalCallbackExtension implements ServiceExtension {
@Inject
private EndpointDataReferenceCache endpointDataReferenceCache;

@Inject
private TypeTransformerRegistry transformerRegistry;

@Override
public String name() {
return NAME;
Expand All @@ -76,7 +80,7 @@ public String name() {
public void initialize(ServiceExtensionContext context) {

callbackRegistry.registerHandler(new ContractNegotiationCallback(transferProcessService, monitor));
callbackRegistry.registerHandler(new TransferProcessLocalCallback(edrCache, transferProcessStore, transactionContext));
callbackRegistry.registerHandler(new TransferProcessLocalCallback(edrCache, transferProcessStore, transformerRegistry, transactionContext));

resolverRegistry.registerResolver(this::resolveProtocol);
registry.register(new InProcessCallbackMessageDispatcher(callbackRegistry));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
import org.eclipse.edc.connector.transfer.spi.store.TransferProcessStore;
import org.eclipse.edc.spi.event.Event;
import org.eclipse.edc.spi.result.Result;
import org.eclipse.edc.spi.types.domain.edr.EndpointDataAddressConstants;
import org.eclipse.edc.spi.types.domain.edr.EndpointDataReference;
import org.eclipse.edc.transaction.spi.TransactionContext;
import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
import org.eclipse.tractusx.edc.edr.spi.EndpointDataReferenceCache;
import org.eclipse.tractusx.edc.edr.spi.EndpointDataReferenceEntry;
import org.eclipse.tractusx.edc.spi.cp.adapter.callback.InProcessCallback;
Expand All @@ -32,20 +32,22 @@ public class TransferProcessLocalCallback implements InProcessCallback {

private final EndpointDataReferenceCache edrCache;
private final TransferProcessStore transferProcessStore;
private final TypeTransformerRegistry transformerRegistry;

private final TransactionContext transactionContext;

public TransferProcessLocalCallback(EndpointDataReferenceCache edrCache, TransferProcessStore transferProcessStore, TransactionContext transactionContext) {
public TransferProcessLocalCallback(EndpointDataReferenceCache edrCache, TransferProcessStore transferProcessStore, TypeTransformerRegistry transformerRegistry, TransactionContext transactionContext) {
this.edrCache = edrCache;
this.transferProcessStore = transferProcessStore;
this.transformerRegistry = transformerRegistry;
this.transactionContext = transactionContext;
}

@Override
public <T extends Event> Result<Void> invoke(CallbackEventRemoteMessage<T> message) {
if (message.getEventEnvelope().getPayload() instanceof TransferProcessStarted transferProcessStarted) {
if (transferProcessStarted.getDataAddress() != null) {
return EndpointDataAddressConstants.to(transferProcessStarted.getDataAddress())
return transformerRegistry.transform(transferProcessStarted.getDataAddress(), EndpointDataReference.class)
.compose(this::storeEdr)
.mapTo();
}
Expand Down
Loading

0 comments on commit d98d5cd

Please sign in to comment.