Skip to content

Commit

Permalink
chore: use of ContractRequest in edrs API + old edrs schema and migra…
Browse files Browse the repository at this point in the history
…tion removal (#1172)
  • Loading branch information
wolf4ood authored Mar 30, 2024
1 parent b12d05a commit 62600ad
Show file tree
Hide file tree
Showing 26 changed files with 241 additions and 1,303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@
import jakarta.json.JsonObject;
import org.eclipse.edc.api.model.ApiCoreSchema;
import org.eclipse.edc.connector.api.management.configuration.ManagementApiSchema;
import org.eclipse.edc.connector.controlplane.api.management.contractnegotiation.ContractNegotiationApi;
import org.eclipse.edc.edr.spi.types.EndpointDataReferenceEntry;
import org.eclipse.edc.web.spi.ApiErrorDetail;
import org.eclipse.tractusx.edc.api.edr.v2.schema.EdrSchema;

import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID;
import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE;
Expand All @@ -51,7 +51,7 @@ public interface EdrCacheApi {
@ApiResponse(responseCode = "400", description = "Request body was malformed",
content = @Content(array = @ArraySchema(schema = @Schema(implementation = ApiErrorDetail.class)))),
})
JsonObject initiateEdrNegotiation(@Schema(implementation = EdrSchema.NegotiateEdrRequestSchema.class) JsonObject dto);
JsonObject initiateEdrNegotiation(@Schema(implementation = ContractNegotiationApi.ContractRequestSchema.class) JsonObject dto);

@Operation(description = "Request all Edr entries according to a particular query",
requestBody = @RequestBody(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,14 @@
import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry;
import org.eclipse.edc.web.spi.exception.InvalidRequestException;
import org.eclipse.edc.web.spi.exception.ValidationFailureException;
import org.eclipse.tractusx.edc.api.edr.v2.dto.NegotiateEdrRequestDto;
import org.eclipse.tractusx.edc.edr.spi.service.EdrService;
import org.eclipse.tractusx.edc.edr.spi.types.NegotiateEdrRequest;

import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static jakarta.json.stream.JsonCollectors.toJsonArray;
import static org.eclipse.edc.connector.controlplane.contract.spi.types.negotiation.ContractRequest.CONTRACT_REQUEST_TYPE;
import static org.eclipse.edc.spi.query.QuerySpec.EDC_QUERY_SPEC_TYPE;
import static org.eclipse.edc.web.spi.exception.ServiceResultHandler.exceptionMapper;
import static org.eclipse.tractusx.edc.edr.spi.types.RefreshMode.AUTO_REFRESH;
Expand Down Expand Up @@ -95,13 +94,14 @@ public EdrCacheApiController(EndpointDataReferenceStore edrStore,
@POST
@Override
public JsonObject initiateEdrNegotiation(JsonObject requestObject) {
validator.validate(NegotiateEdrRequestDto.EDR_REQUEST_DTO_TYPE, requestObject).orElseThrow(ValidationFailureException::new);

var edrNegotiationRequest = transformerRegistry.transform(requestObject, NegotiateEdrRequestDto.class)
.compose(dto -> transformerRegistry.transform(dto, NegotiateEdrRequest.class))
validator.validate(CONTRACT_REQUEST_TYPE, requestObject)
.orElseThrow(ValidationFailureException::new);

var contractRequest = transformerRegistry.transform(requestObject, ContractRequest.class)
.orElseThrow(InvalidRequestException::new);

var contractNegotiation = contractNegotiationService.initiateNegotiation(createContractRequest(edrNegotiationRequest));
var contractNegotiation = contractNegotiationService.initiateNegotiation(enrichContractRequest(contractRequest));

var idResponse = IdResponse.Builder.newInstance()
.id(contractNegotiation.getId())
Expand Down Expand Up @@ -170,12 +170,12 @@ public JsonObject refreshEdr(@PathParam("transferProcessId") String transferProc
.orElseThrow(f -> new EdcException(f.getFailureDetail()));
}

private ContractRequest createContractRequest(NegotiateEdrRequest request) {
private ContractRequest enrichContractRequest(ContractRequest request) {
var callbacks = Stream.concat(request.getCallbackAddresses().stream(), Stream.of(LOCAL_CALLBACK)).collect(Collectors.toList());

return ContractRequest.Builder.newInstance()
.counterPartyAddress(request.getConnectorAddress())
.contractOffer(request.getOffer())
.counterPartyAddress(request.getCounterPartyAddress())
.contractOffer(request.getContractOffer())
.protocol(request.getProtocol())
.callbackAddresses(callbacks).build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,7 @@
import org.eclipse.edc.transform.spi.TypeTransformerRegistry;
import org.eclipse.edc.validator.spi.JsonObjectValidatorRegistry;
import org.eclipse.edc.web.spi.WebService;
import org.eclipse.tractusx.edc.api.edr.v2.dto.NegotiateEdrRequestDto;
import org.eclipse.tractusx.edc.api.edr.v2.transform.JsonObjectFromEndpointDataReferenceEntryTransformer;
import org.eclipse.tractusx.edc.api.edr.v2.transform.JsonObjectToNegotiateEdrRequestDtoTransformer;
import org.eclipse.tractusx.edc.api.edr.v2.transform.NegotiateEdrRequestDtoToNegotiatedEdrRequestTransformer;
import org.eclipse.tractusx.edc.api.edr.v2.validation.NegotiateEdrRequestDtoValidator;
import org.eclipse.tractusx.edc.edr.spi.service.EdrService;

import java.util.Map;
Expand Down Expand Up @@ -74,10 +70,7 @@ public class EdrCacheApiExtension implements ServiceExtension {
public void initialize(ServiceExtensionContext context) {
jsonLdService.registerNamespace(TX_PREFIX, TX_NAMESPACE);
var mgmtApiTransformerRegistry = transformerRegistry.forContext("management-api");
mgmtApiTransformerRegistry.register(new NegotiateEdrRequestDtoToNegotiatedEdrRequestTransformer());
mgmtApiTransformerRegistry.register(new JsonObjectToNegotiateEdrRequestDtoTransformer());
mgmtApiTransformerRegistry.register(new JsonObjectFromEndpointDataReferenceEntryTransformer(Json.createBuilderFactory(Map.of())));
validatorRegistry.register(NegotiateEdrRequestDto.EDR_REQUEST_DTO_TYPE, NegotiateEdrRequestDtoValidator.instance());
webService.registerResource(apiConfig.getContextAlias(), new EdrCacheApiController(edrStore, mgmtApiTransformerRegistry, validatorRegistry, monitor, edrService, contractNegotiationService));
}
}

This file was deleted.

This file was deleted.

Loading

0 comments on commit 62600ad

Please sign in to comment.