From 589ee63ba6be386fbcee502338da2ca0ba1195cb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pedro=20Bail=C3=A3o?=
Date: Wed, 10 Jan 2024 13:26:36 +0000
Subject: [PATCH 01/12] post request edc/token to get token
---
.../controllers/DemandCategoryController.java | 1 -
.../controllers/EDCController.java | 20 +
.../services/EDCService.java | 7 +-
.../services/impl/EDCServiceImpl.java | 352 +++++++++++-------
.../src/main/resources/openapi.yml | 33 +-
5 files changed, 263 insertions(+), 150 deletions(-)
create mode 100644 demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/DemandCategoryController.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/DemandCategoryController.java
index 237814f5..b7ee6dfa 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/DemandCategoryController.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/DemandCategoryController.java
@@ -24,7 +24,6 @@
import eclipse.tractusx.demand_capacity_mgmt_specification.api.DemandCategoryApi;
import eclipse.tractusx.demand_capacity_mgmt_specification.model.DemandCategoryResponse;
-import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import java.util.List;
import lombok.AllArgsConstructor;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.DemandCategoryService;
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
new file mode 100644
index 00000000..3df2e049
--- /dev/null
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
@@ -0,0 +1,20 @@
+package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.controllers;
+
+import eclipse.tractusx.demand_capacity_mgmt_specification.api.EdcApi;
+import eclipse.tractusx.demand_capacity_mgmt_specification.model.AccessTokenResponse;
+import lombok.AllArgsConstructor;
+import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.EDCService;
+import org.springframework.http.ResponseEntity;
+import org.springframework.web.bind.annotation.RestController;
+
+@RestController
+@AllArgsConstructor
+public class EDCController implements EdcApi {
+
+ private final EDCService edcService;
+
+ @Override
+ public ResponseEntity getAccessToken() throws Exception {
+ return ResponseEntity.ok(edcService.getAccessToken().block());
+ }
+}
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java
index 0e3acd25..88c7e582 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java
@@ -1,12 +1,11 @@
package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services;
import eclipse.tractusx.demand_capacity_mgmt_specification.model.*;
+import javax.xml.catalog.Catalog;
import org.springframework.http.ResponseEntity;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
-import javax.xml.catalog.Catalog;
-
public interface EDCService {
Mono createAsset(AssetInput dto);
@@ -46,6 +45,8 @@ public interface EDCService {
Mono createEDR(NegotiateEdrRequest dto);
+ Mono getAccessToken();
+
Mono getEDR(String edrId);
Mono deleteEDR(String edrId);
@@ -53,6 +54,4 @@ public interface EDCService {
Mono createAASRequest(AssetRequest dto);
Mono getEDRSByParameters(String agreementId, String assetId, String providerId);
-
-
}
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
index db91a957..f166b8e5 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
@@ -1,275 +1,339 @@
package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl;
import eclipse.tractusx.demand_capacity_mgmt_specification.model.*;
+import java.time.Duration;
+import java.time.Instant;
+import javax.xml.catalog.Catalog;
+import lombok.RequiredArgsConstructor;
+import lombok.extern.slf4j.Slf4j;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.EDCService;
import org.springframework.http.*;
+import org.springframework.stereotype.Service;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.util.retry.Retry;
-import javax.xml.catalog.Catalog;
-import java.time.Duration;
-
+@RequiredArgsConstructor
+@Service
+@Slf4j
public class EDCServiceImpl implements EDCService {
- private final WebClient webClient = WebClient.create("http://localhost:8081/");
+ private final WebClient webClient = WebClient.create("https://materialpass.int.demo.catena-x.net/BPNL000000000000");
+ private String accessToken;
+ private Instant tokenExpiration;
+
+ public Mono getToken() {
+ if (accessToken != null && !isTokenExpired()) {
+ return Mono.just(accessToken);
+ } else {
+ return getAccessToken().map(AccessTokenResponse::getAccessToken);
+ }
+ }
@Override
- public Mono createAsset(AssetInput dto) {
- return webClient
- .post()
- .uri(uriBuilder -> uriBuilder.path("/v3/assets").build())
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
+ public Mono getAccessToken() {
+ String tokenEndpoint =
+ "https://centralidp.int.demo.catena-x.net/auth/realms/CX-Central/protocol/openid-connect/token";
+ // Set the client credentials
+ String clientId = "sa574";
+ String clientSecret = "Lh0ctCMQQitoS8qxwKVx9BgbwYOhNJns";
+ String grantType = "client_credentials";
+
+ WebClient client = WebClient.builder()
+ .baseUrl(tokenEndpoint)
+ .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
+ .build();
+
+ return client.post()
+ .body(BodyInserters.fromFormData("grant_type", grantType)
+ .with("client_id", clientId)
+ .with("client_secret", clientSecret))
.retrieve()
- .bodyToMono(IdResponse.class)
- .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
+ .bodyToMono(AccessTokenResponse.class)
+ .doOnSuccess(response -> {
+ accessToken = response.getAccessToken();
+ // Set token expiration time (assuming response provides expiresIn in seconds)
+ tokenExpiration = Instant.now().plusSeconds(response.getExpiresIn().longValue());
+ });
+ }
+
+ private boolean isTokenExpired() {
+ return tokenExpiration != null && Instant.now().isAfter(tokenExpiration);
+ }
+
+ @Override
+ public Mono createAsset(AssetInput dto) {
+ return getToken()
+ .flatMap(
+ accessToken -> {
+ return webClient
+ .post()
+ .uri(uriBuilder -> uriBuilder.path("/management/v2/assets").build())
+ .header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken)
+ .contentType(MediaType.APPLICATION_JSON)
+ .body(BodyInserters.fromValue(dto))
+ .retrieve()
+ .bodyToMono(IdResponse.class);
+ }
+ )
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
}
@Override
public Flux createAssetRequest(QuerySpec dto) {
return webClient
- .post()
- .uri(uriBuilder -> uriBuilder.path("/v3/assets/request").build())
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
- .retrieve()
- .bodyToFlux(AssetOutput.class)
- .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
+ .post()
+ .uri(uriBuilder -> uriBuilder.path("/management/v2/assets/request").build())
+ .contentType(MediaType.APPLICATION_JSON)
+ .body(BodyInserters.fromValue(dto))
+ .retrieve()
+ .bodyToFlux(AssetOutput.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
}
@Override
public Mono getAsset(String assetId) {
return webClient
- .get()
- .uri(uriBuilder -> uriBuilder.pathSegment("/v3/assets", "{id}").build(assetId))
- .retrieve()
- .toEntity(AssetOutput.class)
- .flatMap(responseEntity -> Mono.justOrEmpty(responseEntity.getBody()));
+ .get()
+ .uri(uriBuilder -> uriBuilder.pathSegment("/management/v2/assets", "{id}").build(assetId))
+ .retrieve()
+ .toEntity(AssetOutput.class)
+ .flatMap(responseEntity -> Mono.justOrEmpty(responseEntity.getBody()));
}
@Override
public Mono deleteAsset(String assetId) {
return webClient
- .delete()
- .uri(uriBuilder -> uriBuilder.pathSegment("/v3/assets", "{id}").build(assetId))
- .retrieve()
- .bodyToMono(Void.class);
+ .delete()
+ .uri(uriBuilder -> uriBuilder.pathSegment("/management/v2/assets", "{id}").build(assetId))
+ .retrieve()
+ .bodyToMono(Void.class);
}
@Override
public Mono createPolicy(PolicyDefinitionInput dto) {
return webClient
- .post()
- .uri(uriBuilder -> uriBuilder.path("/v2/policydefinitions").build())
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
- .retrieve()
- .bodyToMono(IdResponse.class)
- .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
+ .post()
+ .uri(uriBuilder -> uriBuilder.path("/management/v2/policydefinitions").build())
+ .contentType(MediaType.APPLICATION_JSON)
+ .body(BodyInserters.fromValue(dto))
+ .retrieve()
+ .bodyToMono(IdResponse.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
}
@Override
public Flux createPolicyRequest(QuerySpec dto) {
return webClient
- .post()
- .uri(uriBuilder -> uriBuilder.path("/v2/policydefinitions/request").build())
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
- .retrieve()
- .bodyToFlux(PolicyDefinitionOutput.class)
- .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
+ .post()
+ .uri(uriBuilder -> uriBuilder.path("/management/v2/policydefinitions/request").build())
+ .contentType(MediaType.APPLICATION_JSON)
+ .body(BodyInserters.fromValue(dto))
+ .retrieve()
+ .bodyToFlux(PolicyDefinitionOutput.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
}
@Override
public Mono getPolicy(String policyId) {
return webClient
- .get()
- .uri(uriBuilder -> uriBuilder.pathSegment("/v2/policydefinitions", "{id}").build(policyId))
- .retrieve()
- .toEntity(PolicyDefinitionOutput.class)
- .flatMap(responseEntity -> Mono.justOrEmpty(responseEntity.getBody()));
+ .get()
+ .uri(uriBuilder -> uriBuilder.pathSegment("/management/v2/policydefinitions", "{id}").build(policyId))
+ .retrieve()
+ .toEntity(PolicyDefinitionOutput.class)
+ .flatMap(responseEntity -> Mono.justOrEmpty(responseEntity.getBody()));
}
@Override
public Mono deletePolicy(String policyId) {
return webClient
- .delete()
- .uri(uriBuilder -> uriBuilder.pathSegment("/v2/policydefinitions", "{id}").build(policyId))
- .retrieve()
- .bodyToMono(Void.class);
+ .delete()
+ .uri(uriBuilder -> uriBuilder.pathSegment("/management/v2policydefinitions", "{id}").build(policyId))
+ .retrieve()
+ .bodyToMono(Void.class);
}
@Override
public Mono createContractDef(ContractDefinitionInput dto) {
return webClient
- .post()
- .uri(uriBuilder -> uriBuilder.path("/v2/contractdefinitions").build())
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
- .retrieve()
- .bodyToMono(IdResponse.class)
- .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
+ .post()
+ .uri(uriBuilder -> uriBuilder.path("/management/v2/contractdefinitions").build())
+ .contentType(MediaType.APPLICATION_JSON)
+ .body(BodyInserters.fromValue(dto))
+ .retrieve()
+ .bodyToMono(IdResponse.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
}
@Override
public Flux createContractDefRequest(QuerySpec dto) {
return webClient
- .post()
- .uri(uriBuilder -> uriBuilder.path("/v2/contractdefinitions/request").build())
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
- .retrieve()
- .bodyToFlux(ContractDefinitionOutput.class)
- .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
+ .post()
+ .uri(uriBuilder -> uriBuilder.path("/management/v2/contractdefinitions/request").build())
+ .contentType(MediaType.APPLICATION_JSON)
+ .body(BodyInserters.fromValue(dto))
+ .retrieve()
+ .bodyToFlux(ContractDefinitionOutput.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
}
@Override
public Mono getContractDef(String contractDefId) {
return webClient
- .get()
- .uri(uriBuilder -> uriBuilder.pathSegment("/v2/contractdefinitions/{id}", "{id}").build(contractDefId))
- .retrieve()
- .toEntity(ContractDefinitionOutput.class)
- .flatMap(responseEntity -> Mono.justOrEmpty(responseEntity.getBody()));
+ .get()
+ .uri(
+ uriBuilder ->
+ uriBuilder.pathSegment("/management/v2/contractdefinitions/{id}", "{id}").build(contractDefId)
+ )
+ .retrieve()
+ .toEntity(ContractDefinitionOutput.class)
+ .flatMap(responseEntity -> Mono.justOrEmpty(responseEntity.getBody()));
}
@Override
public Mono deleteContractDef(String contractDefId) {
return webClient
- .delete()
- .uri(uriBuilder -> uriBuilder.pathSegment("/v2/contractdefinitions/{id}", "{id}").build(contractDefId))
- .retrieve()
- .bodyToMono(Void.class);
+ .delete()
+ .uri(
+ uriBuilder ->
+ uriBuilder.pathSegment("/management/v2/contractdefinitions/{id}", "{id}").build(contractDefId)
+ )
+ .retrieve()
+ .bodyToMono(Void.class);
}
@Override
public Mono createCatalogRequest(CatalogRequest dto) {
return webClient
- .post()
- .uri(uriBuilder -> uriBuilder.path("/v2/catalog/request").build())
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
- .retrieve()
- .bodyToMono(Catalog.class)
- .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
+ .post()
+ .uri(uriBuilder -> uriBuilder.path("/management/v2/catalog/request").build())
+ .contentType(MediaType.APPLICATION_JSON)
+ .body(BodyInserters.fromValue(dto))
+ .retrieve()
+ .bodyToMono(Catalog.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
}
@Override
public Mono createContractNeg(ContractRequest dto) {
return webClient
- .post()
- .uri(uriBuilder -> uriBuilder.path("/v2/contractnegotiations").build())
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
- .retrieve()
- .bodyToMono(IdResponse.class)
- .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
+ .post()
+ .uri(uriBuilder -> uriBuilder.path("/management/v2/contractnegotiations").build())
+ .contentType(MediaType.APPLICATION_JSON)
+ .body(BodyInserters.fromValue(dto))
+ .retrieve()
+ .bodyToMono(IdResponse.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
}
@Override
public Flux createContractNegRequest(QuerySpec dto) {
return webClient
- .post()
- .uri(uriBuilder -> uriBuilder.path("/v2/contractnegotiations/request").build())
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
- .retrieve()
- .bodyToFlux(ContractNegotiation.class)
- .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
+ .post()
+ .uri(uriBuilder -> uriBuilder.path("/management/v2/contractnegotiations/request").build())
+ .contentType(MediaType.APPLICATION_JSON)
+ .body(BodyInserters.fromValue(dto))
+ .retrieve()
+ .bodyToFlux(ContractNegotiation.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
}
@Override
public Mono createTransferProcess(TransferRequest dto) {
return webClient
- .post()
- .uri(uriBuilder -> uriBuilder.path("/v2/transferprocesses").build())
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
- .retrieve()
- .bodyToMono(IdResponse.class)
- .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
+ .post()
+ .uri(uriBuilder -> uriBuilder.path("/management/v2/transferprocesses").build())
+ .contentType(MediaType.APPLICATION_JSON)
+ .body(BodyInserters.fromValue(dto))
+ .retrieve()
+ .bodyToMono(IdResponse.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
}
@Override
public Flux createTransferProcessRequest(QuerySpec dto) {
return webClient
- .post()
- .uri(uriBuilder -> uriBuilder.path("/v2/transferprocesses/request").build())
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
- .retrieve()
- .bodyToFlux(TransferProcess.class)
- .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
+ .post()
+ .uri(uriBuilder -> uriBuilder.path("/management/v2/transferprocesses/request").build())
+ .contentType(MediaType.APPLICATION_JSON)
+ .body(BodyInserters.fromValue(dto))
+ .retrieve()
+ .bodyToFlux(TransferProcess.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
}
@Override
public Mono getTransferProcess(String transferProcessId) {
return webClient
- .get()
- .uri(uriBuilder -> uriBuilder.pathSegment("/v2/contractdefinitions/{id}", "{id}").build(transferProcessId))
- .retrieve()
- .toEntity(TransferProcess.class)
- .flatMap(responseEntity -> Mono.justOrEmpty(responseEntity.getBody()));
+ .get()
+ .uri(
+ uriBuilder ->
+ uriBuilder.pathSegment("/management/v2/contractdefinitions/{id}", "{id}").build(transferProcessId)
+ )
+ .retrieve()
+ .toEntity(TransferProcess.class)
+ .flatMap(responseEntity -> Mono.justOrEmpty(responseEntity.getBody()));
}
@Override
public Mono createEDR(NegotiateEdrRequest dto) {
return webClient
- .post()
- .uri(uriBuilder -> uriBuilder.path("/edrs").build())
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
- .retrieve()
- .bodyToMono(IdResponse.class)
- .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
+ .post()
+ .uri(uriBuilder -> uriBuilder.path("/management/edrs").build())
+ .contentType(MediaType.APPLICATION_JSON)
+ .body(BodyInserters.fromValue(dto))
+ .retrieve()
+ .bodyToMono(IdResponse.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
}
@Override
public Mono getEDR(String edrId) {
return webClient
- .get()
- .uri(uriBuilder -> uriBuilder.pathSegment("/edrs", "{id}").build(edrId))
- .retrieve()
- .toEntity(DataAddress.class)
- .flatMap(responseEntity -> Mono.justOrEmpty(responseEntity.getBody()));
+ .get()
+ .uri(uriBuilder -> uriBuilder.pathSegment("/management/edrs", "{id}").build(edrId))
+ .retrieve()
+ .toEntity(DataAddress.class)
+ .flatMap(responseEntity -> Mono.justOrEmpty(responseEntity.getBody()));
}
@Override
public Mono deleteEDR(String edrId) {
return webClient
- .delete()
- .uri(uriBuilder -> uriBuilder.pathSegment("/edrs", "{id}").build(edrId))
- .retrieve()
- .bodyToMono(Void.class);
+ .delete()
+ .uri(uriBuilder -> uriBuilder.pathSegment("/management/edrs", "{id}").build(edrId))
+ .retrieve()
+ .bodyToMono(Void.class);
}
@Override
public Mono createAASRequest(AssetRequest dto) {
return webClient
- .post()
- .uri(uriBuilder -> uriBuilder.path("/aas/request").build())
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
- .retrieve()
- .bodyToMono(AssetRequest.class)
- .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
+ .post()
+ .uri(uriBuilder -> uriBuilder.path("/management/aas/request").build())
+ .contentType(MediaType.APPLICATION_JSON)
+ .body(BodyInserters.fromValue(dto))
+ .retrieve()
+ .bodyToMono(AssetRequest.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
}
@Override
public Mono getEDRSByParameters(String agreementId, String assetId, String providerId) {
return webClient
- .get()
- .uri(uriBuilder -> uriBuilder.path("/edrs")
+ .get()
+ .uri(
+ uriBuilder ->
+ uriBuilder
+ .path("/management/edrs")
.queryParam("agreementId", agreementId)
.queryParam("assetId", assetId)
.queryParam("providerId", providerId)
- .build())
- .retrieve()
- .bodyToMono(EndpointDataReferenceEntry.class);
+ .build()
+ )
+ .retrieve()
+ .bodyToMono(EndpointDataReferenceEntry.class);
}
-
-
}
diff --git a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
index 01925067..80bb86c6 100644
--- a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
+++ b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
@@ -29,6 +29,21 @@ servers:
paths:
+
+ /edc/token:
+ post:
+ tags:
+ - EDC
+ summary: Get Access Token
+ operationId: getAccessToken
+ responses:
+ '200':
+ description: Access token retrieved successfully
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/AccessTokenResponse'
+
/token/login:
post:
tags:
@@ -3141,4 +3156,20 @@ components:
'@context':
edc: https://w3id.org/edc/v0.0.1/ns/
'@type': https://w3id.org/edc/v0.0.1/ns/TransferState
- state: STARTED
\ No newline at end of file
+ state: STARTED
+
+ AccessTokenResponse:
+ type: object
+ properties:
+ access_token:
+ type: string
+ expires_in:
+ type: long
+ refresh_expires_in:
+ type: long
+ token_type:
+ type: string
+ not-before-policy:
+ type: long
+ scope:
+ type: string
\ No newline at end of file
From 6b9100e1ceef89b5aa7b253ad461130681b63f5d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pedro=20Bail=C3=A3o?=
Date: Fri, 12 Jan 2024 13:42:31 +0000
Subject: [PATCH 02/12] createAssetRequest Method working
---
.../controllers/EDCController.java | 14 ++-
.../services/EDCService.java | 5 +-
.../services/impl/EDCServiceImpl.java | 98 ++++++++++++-------
.../src/main/resources/openapi.yml | 94 ++++++++++++++----
4 files changed, 153 insertions(+), 58 deletions(-)
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
index 3df2e049..0d592c47 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
@@ -1,11 +1,13 @@
package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.controllers;
import eclipse.tractusx.demand_capacity_mgmt_specification.api.EdcApi;
-import eclipse.tractusx.demand_capacity_mgmt_specification.model.AccessTokenResponse;
+import eclipse.tractusx.demand_capacity_mgmt_specification.model.*;
+import java.util.List;
import lombok.AllArgsConstructor;
import org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.EDCService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RestController;
+import reactor.core.publisher.Flux;
@RestController
@AllArgsConstructor
@@ -13,8 +15,18 @@ public class EDCController implements EdcApi {
private final EDCService edcService;
+ @Override
+ public ResponseEntity> createAssetRequest(QuerySpec querySpec) throws Exception {
+ return ResponseEntity.ok(edcService.createAssetRequest(querySpec));
+ }
+
@Override
public ResponseEntity getAccessToken() throws Exception {
return ResponseEntity.ok(edcService.getAccessToken().block());
}
+
+ @Override
+ public ResponseEntity registerAsset(AssetEntryNewDto assetInput) throws Exception {
+ return ResponseEntity.ok(edcService.createAsset(assetInput).block());
+ }
}
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java
index 88c7e582..49dde4ba 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java
@@ -1,15 +1,16 @@
package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services;
import eclipse.tractusx.demand_capacity_mgmt_specification.model.*;
+import java.util.List;
import javax.xml.catalog.Catalog;
import org.springframework.http.ResponseEntity;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
public interface EDCService {
- Mono createAsset(AssetInput dto);
+ Mono createAsset(AssetEntryNewDto dto);
- Flux createAssetRequest(QuerySpec dto);
+ List createAssetRequest(QuerySpec dto);
Mono getAsset(String assetId);
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
index f166b8e5..6a65c86f 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
@@ -3,6 +3,7 @@
import eclipse.tractusx.demand_capacity_mgmt_specification.model.*;
import java.time.Duration;
import java.time.Instant;
+import java.util.List;
import javax.xml.catalog.Catalog;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -24,6 +25,8 @@ public class EDCServiceImpl implements EDCService {
private String accessToken;
private Instant tokenExpiration;
+ private String apiKey = "ZWRjX2RjbV9hZXNfZW5ja2V5Cg==";
+
public Mono getToken() {
if (accessToken != null && !isTokenExpired()) {
return Mono.just(accessToken);
@@ -35,28 +38,35 @@ public Mono getToken() {
@Override
public Mono getAccessToken() {
String tokenEndpoint =
- "https://centralidp.int.demo.catena-x.net/auth/realms/CX-Central/protocol/openid-connect/token";
+ "https://centralidp.int.demo.catena-x.net/auth/realms/CX-Central/protocol/openid-connect/token";
// Set the client credentials
String clientId = "sa574";
String clientSecret = "Lh0ctCMQQitoS8qxwKVx9BgbwYOhNJns";
String grantType = "client_credentials";
- WebClient client = WebClient.builder()
- .baseUrl(tokenEndpoint)
- .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
- .build();
-
- return client.post()
- .body(BodyInserters.fromFormData("grant_type", grantType)
- .with("client_id", clientId)
- .with("client_secret", clientSecret))
- .retrieve()
- .bodyToMono(AccessTokenResponse.class)
- .doOnSuccess(response -> {
+ WebClient client = WebClient
+ .builder()
+ .baseUrl(tokenEndpoint)
+ .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_FORM_URLENCODED_VALUE)
+ .build();
+
+ return client
+ .post()
+ .body(
+ BodyInserters
+ .fromFormData("grant_type", grantType)
+ .with("client_id", clientId)
+ .with("client_secret", clientSecret)
+ )
+ .retrieve()
+ .bodyToMono(AccessTokenResponse.class)
+ .doOnSuccess(
+ response -> {
accessToken = response.getAccessToken();
// Set token expiration time (assuming response provides expiresIn in seconds)
tokenExpiration = Instant.now().plusSeconds(response.getExpiresIn().longValue());
- });
+ }
+ );
}
private boolean isTokenExpired() {
@@ -64,33 +74,51 @@ private boolean isTokenExpired() {
}
@Override
- public Mono createAsset(AssetInput dto) {
- return getToken()
- .flatMap(
- accessToken -> {
- return webClient
- .post()
- .uri(uriBuilder -> uriBuilder.path("/management/v2/assets").build())
- .header(HttpHeaders.AUTHORIZATION, "Bearer " + accessToken)
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
- .retrieve()
- .bodyToMono(IdResponse.class);
- }
- )
+ public Mono createAsset(AssetEntryNewDto dto) {
+ WebClient client = WebClient
+ .builder()
+ .baseUrl("https://dcm.dev.demo.catena-x.net/BPNL000000000000/management/v2/assets")
+ .defaultHeader(HttpHeaders.CONTENT_TYPE)
+ .build();
+
+ return client
+ .post()
+ .header("X-Api-Key", apiKey)
+ .contentType(MediaType.APPLICATION_JSON)
+ .bodyValue(dto)
+ .retrieve()
+ .bodyToMono(IdResponse.class)
.retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
}
@Override
- public Flux createAssetRequest(QuerySpec dto) {
- return webClient
+ public List createAssetRequest(QuerySpec dto) {
+ WebClient client = WebClient
+ .builder()
+ .baseUrl("https://dcm.dev.demo.catena-x.net/BPNL000000000000/management/v2/assets/request")
+ .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
+ .build();
+
+ return client
.post()
- .uri(uriBuilder -> uriBuilder.path("/management/v2/assets/request").build())
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
+ .header("x-api-key", apiKey)
.retrieve()
- .bodyToFlux(AssetOutput.class)
- .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
+ .bodyToFlux(Asset.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)))
+ .doOnNext(
+ response -> {
+ // Log the received response
+ log.info("Received response: {}", response);
+ }
+ )
+ .doOnError(this::logErrorDetails)
+ .collectList()
+ .block(); // Blocking to get the List
+ }
+
+ private void logErrorDetails(Throwable error) {
+ // Log error details
+ System.err.println("Error occurred while making the request: " + error.getMessage());
}
@Override
diff --git a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
index 80bb86c6..7c8ec5e3 100644
--- a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
+++ b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
@@ -43,6 +43,46 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/AccessTokenResponse'
+ /edc/asset:
+ post:
+ tags:
+ - EDC
+ summary: create an asset
+ operationId: registerAsset
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/AssetEntryNewDto'
+ responses:
+ 200:
+ description: General greeting
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/IdResponse'
+ /edc/asset/request:
+ post:
+ tags:
+ - EDC
+ summary: Create an asset
+ operationId: createAssetRequest
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/QuerySpec'
+ responses:
+ 200:
+ description: Successful response
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ $ref: '#/components/schemas/Asset'
/token/login:
post:
@@ -1996,31 +2036,45 @@ components:
type: string
example: null
example: null
- Asset:
+
+ Asset: # Define your Asset schema
type: object
properties:
- createdAt:
- type: integer
- format: int64
- example: null
- dataAddress:
- $ref: '#/components/schemas/DataAddress'
- id:
+ "@id":
type: string
- example: null
- privateProperties:
- type: object
- additionalProperties:
- type: object
- example: null
- example: null
- properties:
+ description: The identifier of the asset
+ "@type":
+ type: string
+ description: The type of the asset
+ "edc:properties":
+ $ref: '#/components/schemas/AssetProperties'
+ "@context":
type: object
additionalProperties:
- type: object
- example: null
- example: null
- example: null
+ type: string
+ description: Context information
+ required:
+ - id
+ - type
+ - properties
+ - context
+
+ AssetProperties: # Define your AssetProperties schema
+ type: object
+ properties:
+ "edc:description":
+ type: string
+ description: The description of the asset
+ "edc:id":
+ type: string
+ description: The identifier of the asset
+ "edc:contenttype":
+ type: string
+ description: The content type of the asset
+ required:
+ - id
+
+
AssetEntryNewDto:
type: object
properties:
From 2fc7480c91cebdf89b31e609ed1b3079aee172a0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pedro=20Bail=C3=A3o?=
Date: Fri, 12 Jan 2024 13:51:00 +0000
Subject: [PATCH 03/12] Refactor createAssetRequest
---
.../services/impl/EDCServiceImpl.java | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
index 6a65c86f..1cdc9406 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
@@ -22,6 +22,8 @@
public class EDCServiceImpl implements EDCService {
private final WebClient webClient = WebClient.create("https://materialpass.int.demo.catena-x.net/BPNL000000000000");
+
+ private static final String BASE_URL = "https://dcm.dev.demo.catena-x.net/BPNL000000000000";
private String accessToken;
private Instant tokenExpiration;
@@ -95,7 +97,7 @@ public Mono createAsset(AssetEntryNewDto dto) {
public List createAssetRequest(QuerySpec dto) {
WebClient client = WebClient
.builder()
- .baseUrl("https://dcm.dev.demo.catena-x.net/BPNL000000000000/management/v2/assets/request")
+ .baseUrl(BASE_URL + "/management/v2/assets/request")
.defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.build();
From 84523fdd6293f6d0c5c540b04c238d1d86e3ccc8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pedro=20Bail=C3=A3o?=
Date: Mon, 15 Jan 2024 15:49:55 +0000
Subject: [PATCH 04/12] get policies request
---
.../controllers/EDCController.java | 5 ++
.../services/EDCService.java | 2 +-
.../services/impl/EDCServiceImpl.java | 54 ++++++++++---------
.../src/main/resources/openapi.yml | 53 +++++++++++-------
4 files changed, 71 insertions(+), 43 deletions(-)
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
index 0d592c47..25b7ae51 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
@@ -20,6 +20,11 @@ public ResponseEntity> createAssetRequest(QuerySpec querySpec) throw
return ResponseEntity.ok(edcService.createAssetRequest(querySpec));
}
+ @Override
+ public ResponseEntity> createPolicyRequest(QuerySpec querySpec) throws Exception {
+ return ResponseEntity.ok(edcService.createPolicyRequest(querySpec));
+ }
+
@Override
public ResponseEntity getAccessToken() throws Exception {
return ResponseEntity.ok(edcService.getAccessToken().block());
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java
index 49dde4ba..e145d810 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java
@@ -18,7 +18,7 @@ public interface EDCService {
Mono createPolicy(PolicyDefinitionInput dto);
- Flux createPolicyRequest(QuerySpec dto);
+ List createPolicyRequest(QuerySpec dto);
Mono getPolicy(String policyId);
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
index 1cdc9406..cc655376 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
@@ -1,5 +1,8 @@
package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl;
+import ch.qos.logback.core.net.SyslogOutputStream;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
import eclipse.tractusx.demand_capacity_mgmt_specification.model.*;
import java.time.Duration;
import java.time.Instant;
@@ -75,33 +78,29 @@ private boolean isTokenExpired() {
return tokenExpiration != null && Instant.now().isAfter(tokenExpiration);
}
+ private WebClient webClientCreation(String path) {
+ return WebClient.builder().baseUrl(BASE_URL + path).defaultHeader(HttpHeaders.CONTENT_TYPE).build();
+ }
+
@Override
public Mono createAsset(AssetEntryNewDto dto) {
- WebClient client = WebClient
- .builder()
- .baseUrl("https://dcm.dev.demo.catena-x.net/BPNL000000000000/management/v2/assets")
- .defaultHeader(HttpHeaders.CONTENT_TYPE)
- .build();
-
- return client
+ return webClientCreation("/management/v2/assets")
.post()
- .header("X-Api-Key", apiKey)
- .contentType(MediaType.APPLICATION_JSON)
- .bodyValue(dto)
+ .header("x-api-key", apiKey)
.retrieve()
.bodyToMono(IdResponse.class)
- .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)))
+ .doOnNext(
+ response -> {
+ // Log the received response
+ log.info("Received response: {}", response);
+ }
+ );
}
@Override
public List createAssetRequest(QuerySpec dto) {
- WebClient client = WebClient
- .builder()
- .baseUrl(BASE_URL + "/management/v2/assets/request")
- .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
- .build();
-
- return client
+ return webClientCreation("/management/v2/assets/request")
.post()
.header("x-api-key", apiKey)
.retrieve()
@@ -155,15 +154,22 @@ public Mono createPolicy(PolicyDefinitionInput dto) {
}
@Override
- public Flux createPolicyRequest(QuerySpec dto) {
- return webClient
+ public List createPolicyRequest(QuerySpec dto) {
+ return webClientCreation("/management/v2/policydefinitions/request")
.post()
- .uri(uriBuilder -> uriBuilder.path("/management/v2/policydefinitions/request").build())
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
+ .header("x-api-key", apiKey)
.retrieve()
.bodyToFlux(PolicyDefinitionOutput.class)
- .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)))
+ .doOnNext(
+ response -> {
+ // Log the received response
+ log.info("Received response: {}", response);
+ }
+ )
+ .doOnError(this::logErrorDetails)
+ .collectList()
+ .block();
}
@Override
diff --git a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
index 7c8ec5e3..da641176 100644
--- a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
+++ b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
@@ -84,6 +84,28 @@ paths:
items:
$ref: '#/components/schemas/Asset'
+ /edc/policy/request:
+ post:
+ tags:
+ - EDC
+ summary: Create an asset
+ operationId: createPolicyRequest
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/QuerySpec'
+ responses:
+ 200:
+ description: Successful response
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ $ref: '#/components/schemas/PolicyDefinitionOutput'
+
/token/login:
post:
tags:
@@ -2915,25 +2937,20 @@ components:
'@type':
type: string
example: https://w3id.org/edc/v0.0.1/ns/PolicyDefinition
- policy:
+ "edc:createdAt":
+ type: long
+ "edc:policy":
$ref: '#/components/schemas/Policy'
- example:
- '@context':
- edc: https://w3id.org/edc/v0.0.1/ns/
- '@id': definition-id
- policy:
- '@context': http://www.w3.org/ns/odrl.jsonld
- '@type': Set
- uid: http://example.com/policy:1010
- permission:
- - target: http://example.com/asset:9898.movie
- action: display
- constraint:
- - leftOperand: spatial
- operator: eq
- rightOperand: https://www.wikidata.org/wiki/Q183
- comment: i.e Germany
- createdAt: 1688465655
+ "@context":
+ type: object
+ additionalProperties:
+ type: string
+ description: Context information
+ required:
+ - id
+ - type
+ - properties
+ - context
ProvisionerWebhookRequest:
type: object
properties:
From be1f76daab0de1684f0fbc67859b57d2fe43b3c1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pedro=20Bail=C3=A3o?=
Date: Mon, 15 Jan 2024 17:39:25 +0000
Subject: [PATCH 05/12] get contracts request
---
.../controllers/EDCController.java | 5 ++
.../services/EDCService.java | 2 +-
.../services/impl/EDCServiceImpl.java | 19 +++++---
.../src/main/resources/openapi.yml | 48 ++++++++++++-------
4 files changed, 51 insertions(+), 23 deletions(-)
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
index 25b7ae51..f1a3e81c 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
@@ -20,6 +20,11 @@ public ResponseEntity> createAssetRequest(QuerySpec querySpec) throw
return ResponseEntity.ok(edcService.createAssetRequest(querySpec));
}
+ @Override
+ public ResponseEntity> createContractRequest(QuerySpec querySpec) throws Exception {
+ return ResponseEntity.ok(edcService.createContractDefRequest(querySpec));
+ }
+
@Override
public ResponseEntity> createPolicyRequest(QuerySpec querySpec) throws Exception {
return ResponseEntity.ok(edcService.createPolicyRequest(querySpec));
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java
index e145d810..1096aec4 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java
@@ -26,7 +26,7 @@ public interface EDCService {
Mono createContractDef(ContractDefinitionInput dto);
- Flux createContractDefRequest(QuerySpec dto);
+ List createContractDefRequest(QuerySpec dto);
Mono getContractDef(String contractDefId);
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
index cc655376..1a25a8f2 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
@@ -204,15 +204,22 @@ public Mono createContractDef(ContractDefinitionInput dto) {
}
@Override
- public Flux createContractDefRequest(QuerySpec dto) {
- return webClient
+ public List createContractDefRequest(QuerySpec dto) {
+ return webClientCreation("/management/v2/contractdefinitions/request")
.post()
- .uri(uriBuilder -> uriBuilder.path("/management/v2/contractdefinitions/request").build())
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
+ .header("x-api-key", apiKey)
.retrieve()
.bodyToFlux(ContractDefinitionOutput.class)
- .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)))
+ .doOnNext(
+ response -> {
+ // Log the received response
+ log.info("Received response: {}", response);
+ }
+ )
+ .doOnError(this::logErrorDetails)
+ .collectList()
+ .block();
}
@Override
diff --git a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
index da641176..6e40cc5e 100644
--- a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
+++ b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
@@ -106,6 +106,28 @@ paths:
items:
$ref: '#/components/schemas/PolicyDefinitionOutput'
+ /edc/contract/request:
+ post:
+ tags:
+ - EDC
+ summary: Create an asset
+ operationId: createContractRequest
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/QuerySpec'
+ responses:
+ 200:
+ description: Successful response
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ $ref: '#/components/schemas/ContractDefinitionOutput'
+
/token/login:
post:
tags:
@@ -2379,29 +2401,23 @@ components:
'@type':
type: string
example: https://w3id.org/edc/v0.0.1/ns/ContractDefinition
- accessPolicyId:
+ "edc:accessPolicyId":
type: string
example: null
- assetsSelector:
- type: array
+ "edc:assetsSelector":
+ type: object
example: null
items:
$ref: '#/components/schemas/Criterion'
- contractPolicyId:
+ "edc:contractPolicyId":
type: string
example: null
- createdAt:
- type: integer
- format: int64
- example: null
- example:
- '@context':
- edc: https://w3id.org/edc/v0.0.1/ns/
- '@id': definition-id
- edc:accessPolicyId: asset-policy-id
- edc:contractPolicyId: contract-policy-id
- edc:assetsSelector: []
- edc:createdAt: 1688465655
+ "@context":
+ type: object
+ additionalProperties:
+ type: string
+ description: Context information
+
ContractNegotiation:
type: object
properties:
From 7520efcb16e6a5a0d20c3d88b029b799613184b7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pedro=20Bail=C3=A3o?=
Date: Tue, 16 Jan 2024 10:54:22 +0000
Subject: [PATCH 06/12] get and delete of Assets and Policies
---
.../controllers/EDCController.java | 20 ++++
.../services/EDCService.java | 9 +-
.../services/impl/EDCServiceImpl.java | 67 +++++++------
.../src/main/resources/openapi.yml | 93 +++++++++++++++----
4 files changed, 130 insertions(+), 59 deletions(-)
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
index f1a3e81c..cffa5e31 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
@@ -30,11 +30,31 @@ public ResponseEntity> createPolicyRequest(QuerySpe
return ResponseEntity.ok(edcService.createPolicyRequest(querySpec));
}
+ @Override
+ public ResponseEntity deleteAssetById(String assetId) throws Exception {
+ return ResponseEntity.ok(edcService.deleteAsset(assetId));
+ }
+
+ @Override
+ public ResponseEntity deletePolicyById(String policyId) throws Exception {
+ return ResponseEntity.ok(edcService.deletePolicy(policyId));
+ }
+
@Override
public ResponseEntity getAccessToken() throws Exception {
return ResponseEntity.ok(edcService.getAccessToken().block());
}
+ @Override
+ public ResponseEntity getAssetById(String assetId) throws Exception {
+ return ResponseEntity.ok(edcService.getAsset(assetId));
+ }
+
+ @Override
+ public ResponseEntity getPolicyById(String policyId) throws Exception {
+ return ResponseEntity.ok(edcService.getPolicy(policyId));
+ }
+
@Override
public ResponseEntity registerAsset(AssetEntryNewDto assetInput) throws Exception {
return ResponseEntity.ok(edcService.createAsset(assetInput).block());
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java
index 1096aec4..63c04461 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java
@@ -3,7 +3,6 @@
import eclipse.tractusx.demand_capacity_mgmt_specification.model.*;
import java.util.List;
import javax.xml.catalog.Catalog;
-import org.springframework.http.ResponseEntity;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
@@ -12,17 +11,17 @@ public interface EDCService {
List createAssetRequest(QuerySpec dto);
- Mono getAsset(String assetId);
+ Asset getAsset(String assetId);
- Mono deleteAsset(String assetId);
+ Void deleteAsset(String assetId);
Mono createPolicy(PolicyDefinitionInput dto);
List createPolicyRequest(QuerySpec dto);
- Mono getPolicy(String policyId);
+ PolicyDefinitionOutput getPolicy(String policyId);
- Mono deletePolicy(String policyId);
+ Void deletePolicy(String policyId);
Mono createContractDef(ContractDefinitionInput dto);
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
index 1a25a8f2..29fb0fa4 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
@@ -1,8 +1,5 @@
package org.eclipse.tractusx.demandcapacitymgmt.demandcapacitymgmtbackend.services.impl;
-import ch.qos.logback.core.net.SyslogOutputStream;
-import com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
import eclipse.tractusx.demand_capacity_mgmt_specification.model.*;
import java.time.Duration;
import java.time.Instant;
@@ -30,7 +27,7 @@ public class EDCServiceImpl implements EDCService {
private String accessToken;
private Instant tokenExpiration;
- private String apiKey = "ZWRjX2RjbV9hZXNfZW5ja2V5Cg==";
+ private final String apiKey = "ZWRjX2RjbV9hZXNfZW5ja2V5Cg==";
public Mono getToken() {
if (accessToken != null && !isTokenExpired()) {
@@ -89,13 +86,7 @@ public Mono createAsset(AssetEntryNewDto dto) {
.header("x-api-key", apiKey)
.retrieve()
.bodyToMono(IdResponse.class)
- .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)))
- .doOnNext(
- response -> {
- // Log the received response
- log.info("Received response: {}", response);
- }
- );
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
}
@Override
@@ -106,12 +97,6 @@ public List createAssetRequest(QuerySpec dto) {
.retrieve()
.bodyToFlux(Asset.class)
.retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)))
- .doOnNext(
- response -> {
- // Log the received response
- log.info("Received response: {}", response);
- }
- )
.doOnError(this::logErrorDetails)
.collectList()
.block(); // Blocking to get the List
@@ -123,22 +108,28 @@ private void logErrorDetails(Throwable error) {
}
@Override
- public Mono getAsset(String assetId) {
- return webClient
+ public Asset getAsset(String assetId) {
+ return webClientCreation("/management/v2/assets/" + assetId)
.get()
- .uri(uriBuilder -> uriBuilder.pathSegment("/management/v2/assets", "{id}").build(assetId))
+ .header("x-api-key", apiKey)
.retrieve()
- .toEntity(AssetOutput.class)
- .flatMap(responseEntity -> Mono.justOrEmpty(responseEntity.getBody()));
+ .bodyToMono(Asset.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)))
+ .doOnError(this::logErrorDetails)
+ .block(); // Blocking to get the List
}
@Override
- public Mono deleteAsset(String assetId) {
- return webClient
+ public Void deleteAsset(String assetId) {
+ webClientCreation("/management/v2/assets/" + assetId)
.delete()
- .uri(uriBuilder -> uriBuilder.pathSegment("/management/v2/assets", "{id}").build(assetId))
+ .header("x-api-key", apiKey)
.retrieve()
- .bodyToMono(Void.class);
+ .bodyToMono(Asset.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)))
+ .doOnError(this::logErrorDetails)
+ .block();
+ return null;
}
@Override
@@ -173,22 +164,28 @@ public List createPolicyRequest(QuerySpec dto) {
}
@Override
- public Mono getPolicy(String policyId) {
- return webClient
+ public PolicyDefinitionOutput getPolicy(String policyId) {
+ return webClientCreation("/management/v2/policydefinitions/" + policyId)
.get()
- .uri(uriBuilder -> uriBuilder.pathSegment("/management/v2/policydefinitions", "{id}").build(policyId))
+ .header("x-api-key", apiKey)
.retrieve()
- .toEntity(PolicyDefinitionOutput.class)
- .flatMap(responseEntity -> Mono.justOrEmpty(responseEntity.getBody()));
+ .bodyToMono(PolicyDefinitionOutput.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)))
+ .doOnError(this::logErrorDetails)
+ .block();
}
@Override
- public Mono deletePolicy(String policyId) {
- return webClient
+ public Void deletePolicy(String policyId) {
+ webClientCreation("/management/v2/policydefinitions/" + policyId)
.delete()
- .uri(uriBuilder -> uriBuilder.pathSegment("/management/v2policydefinitions", "{id}").build(policyId))
+ .header("x-api-key", apiKey)
.retrieve()
- .bodyToMono(Void.class);
+ .bodyToMono(PolicyDefinitionOutput.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)))
+ .doOnError(this::logErrorDetails)
+ .block();
+ return null;
}
@Override
diff --git a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
index 6e40cc5e..1a450996 100644
--- a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
+++ b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
@@ -62,6 +62,41 @@ paths:
application/json:
schema:
$ref: '#/components/schemas/IdResponse'
+
+ /edc/asset/{asset_id}:
+ get:
+ tags:
+ - EDC
+ summary: get asset by Id
+ operationId: getAssetById
+ parameters:
+ - in: 'path'
+ name: 'asset_id'
+ schema:
+ type: string
+ required: true
+ responses:
+ 200:
+ description: get asset by Id
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/Asset'
+ delete:
+ tags:
+ - EDC
+ summary: delete asset by Id
+ operationId: deleteAssetById
+ parameters:
+ - in: 'path'
+ name: 'asset_id'
+ schema:
+ type: string
+ required: true
+ responses:
+ 200:
+ description: Delete asset with id
+
/edc/asset/request:
post:
tags:
@@ -105,6 +140,39 @@ paths:
type: array
items:
$ref: '#/components/schemas/PolicyDefinitionOutput'
+ /edc/policy/{policy_id}:
+ get:
+ tags:
+ - EDC
+ summary: get policy by Id
+ operationId: getPolicyById
+ parameters:
+ - in: 'path'
+ name: 'policy_id'
+ schema:
+ type: string
+ required: true
+ responses:
+ 200:
+ description: get policy by Id
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/PolicyDefinitionOutput'
+ delete:
+ tags:
+ - EDC
+ summary: delete policy by Id
+ operationId: deletePolicyById
+ parameters:
+ - in: 'path'
+ name: 'policy_id'
+ schema:
+ type: string
+ required: true
+ responses:
+ 200:
+ description: Delete policy with id
/edc/contract/request:
post:
@@ -2123,10 +2191,11 @@ components:
type: object
properties:
asset:
- $ref: '#/components/schemas/Asset'
+ $ref: '#/components/schemas/AssetInput'
dataAddress:
$ref: '#/components/schemas/DataAddress'
example: null
+
AssetInput:
type: object
properties:
@@ -2136,30 +2205,14 @@ components:
'@type':
type: string
example: https://w3id.org/edc/v0.0.1/ns/Asset
- dataAddress:
- $ref: '#/components/schemas/DataAddress'
- privateProperties:
- type: object
- additionalProperties:
- type: object
- example: null
- example: null
properties:
type: object
additionalProperties:
type: object
example: null
example: null
- example:
- '@context':
- edc: https://w3id.org/edc/v0.0.1/ns/
- '@id': asset-id
- properties:
- key: value
- privateProperties:
- privateKey: privateValue
- dataAddress:
- type: HttpData
+
+
AssetOutput:
type: object
properties:
@@ -2581,6 +2634,8 @@ components:
type: string
example: null
example: null
+
+
DataFlowRequest:
type: object
properties:
From ec2052606337608182dc22e7b413bedc269882e0 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pedro=20Bail=C3=A3o?=
Date: Tue, 16 Jan 2024 11:19:05 +0000
Subject: [PATCH 07/12] contract definition: get and delete working
---
.../controllers/EDCController.java | 10 +++++
.../services/EDCService.java | 4 +-
.../services/impl/EDCServiceImpl.java | 30 +++++++-------
.../src/main/resources/openapi.yml | 40 +++++++++++++++++--
4 files changed, 64 insertions(+), 20 deletions(-)
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
index cffa5e31..1cdeaceb 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
@@ -35,6 +35,11 @@ public ResponseEntity deleteAssetById(String assetId) throws Exception {
return ResponseEntity.ok(edcService.deleteAsset(assetId));
}
+ @Override
+ public ResponseEntity deleteContractById(String contractId) throws Exception {
+ return ResponseEntity.ok(edcService.deleteContractDef(contractId));
+ }
+
@Override
public ResponseEntity deletePolicyById(String policyId) throws Exception {
return ResponseEntity.ok(edcService.deletePolicy(policyId));
@@ -50,6 +55,11 @@ public ResponseEntity getAssetById(String assetId) throws Exception {
return ResponseEntity.ok(edcService.getAsset(assetId));
}
+ @Override
+ public ResponseEntity getContractById(String contractId) throws Exception {
+ return ResponseEntity.ok(edcService.getContractDef(contractId));
+ }
+
@Override
public ResponseEntity getPolicyById(String policyId) throws Exception {
return ResponseEntity.ok(edcService.getPolicy(policyId));
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java
index 63c04461..23bd8734 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/EDCService.java
@@ -27,9 +27,9 @@ public interface EDCService {
List createContractDefRequest(QuerySpec dto);
- Mono getContractDef(String contractDefId);
+ ContractDefinitionOutput getContractDef(String contractDefId);
- Mono deleteContractDef(String contractDefId);
+ Void deleteContractDef(String contractDefId);
Mono createCatalogRequest(CatalogRequest dto);
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
index 29fb0fa4..9ebe3810 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
@@ -220,28 +220,28 @@ public List createContractDefRequest(QuerySpec dto) {
}
@Override
- public Mono getContractDef(String contractDefId) {
- return webClient
+ public ContractDefinitionOutput getContractDef(String contractDefId) {
+ return webClientCreation("/management/v2/contractdefinitions/" + contractDefId)
.get()
- .uri(
- uriBuilder ->
- uriBuilder.pathSegment("/management/v2/contractdefinitions/{id}", "{id}").build(contractDefId)
- )
+ .header("x-api-key", apiKey)
.retrieve()
- .toEntity(ContractDefinitionOutput.class)
- .flatMap(responseEntity -> Mono.justOrEmpty(responseEntity.getBody()));
+ .bodyToMono(ContractDefinitionOutput.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)))
+ .doOnError(this::logErrorDetails)
+ .block();
}
@Override
- public Mono deleteContractDef(String contractDefId) {
- return webClient
+ public Void deleteContractDef(String contractDefId) {
+ webClientCreation("/management/v2/contractdefinitions/" + contractDefId)
.delete()
- .uri(
- uriBuilder ->
- uriBuilder.pathSegment("/management/v2/contractdefinitions/{id}", "{id}").build(contractDefId)
- )
+ .header("x-api-key", apiKey)
.retrieve()
- .bodyToMono(Void.class);
+ .bodyToMono(ContractDefinitionOutput.class)
+ .retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)))
+ .doOnError(this::logErrorDetails)
+ .block();
+ return null;
}
@Override
diff --git a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
index 1a450996..f3cfc7a3 100644
--- a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
+++ b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
@@ -196,6 +196,40 @@ paths:
items:
$ref: '#/components/schemas/ContractDefinitionOutput'
+ /edc/contract/{contract_id}:
+ get:
+ tags:
+ - EDC
+ summary: get contract by Id
+ operationId: getContractById
+ parameters:
+ - in: 'path'
+ name: 'contract_id'
+ schema:
+ type: string
+ required: true
+ responses:
+ 200:
+ description: get contract by Id
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ContractDefinitionOutput'
+ delete:
+ tags:
+ - EDC
+ summary: delete contract by Id
+ operationId: deleteContractById
+ parameters:
+ - in: 'path'
+ name: 'contract_id'
+ schema:
+ type: string
+ required: true
+ responses:
+ 200:
+ description: Delete contract with id
+
/token/login:
post:
tags:
@@ -2459,9 +2493,9 @@ components:
example: null
"edc:assetsSelector":
type: object
- example: null
- items:
- $ref: '#/components/schemas/Criterion'
+ additionalProperties:
+ type: string
+ description: Context information
"edc:contractPolicyId":
type: string
example: null
From 68d3fd04d423a0551e6568759ea376176c8c33ee Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pedro=20Bail=C3=A3o?=
Date: Tue, 16 Jan 2024 11:49:34 +0000
Subject: [PATCH 08/12] retrive log prints
---
.../services/impl/EDCServiceImpl.java | 12 ------------
1 file changed, 12 deletions(-)
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
index 9ebe3810..6e0d21a4 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
@@ -152,12 +152,6 @@ public List createPolicyRequest(QuerySpec dto) {
.retrieve()
.bodyToFlux(PolicyDefinitionOutput.class)
.retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)))
- .doOnNext(
- response -> {
- // Log the received response
- log.info("Received response: {}", response);
- }
- )
.doOnError(this::logErrorDetails)
.collectList()
.block();
@@ -208,12 +202,6 @@ public List createContractDefRequest(QuerySpec dto) {
.retrieve()
.bodyToFlux(ContractDefinitionOutput.class)
.retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)))
- .doOnNext(
- response -> {
- // Log the received response
- log.info("Received response: {}", response);
- }
- )
.doOnError(this::logErrorDetails)
.collectList()
.block();
From b1487bd53c5de53e0ef3a45eb5abe3f7879294c6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pedro=20Bail=C3=A3o?=
Date: Tue, 16 Jan 2024 12:53:24 +0000
Subject: [PATCH 09/12] create asset method
---
.../services/impl/EDCServiceImpl.java | 1 +
.../src/main/resources/openapi.yml | 40 +++++++++++++------
2 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
index 6e0d21a4..3202b2d9 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
@@ -84,6 +84,7 @@ public Mono createAsset(AssetEntryNewDto dto) {
return webClientCreation("/management/v2/assets")
.post()
.header("x-api-key", apiKey)
+ .bodyValue(dto)
.retrieve()
.bodyToMono(IdResponse.class)
.retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
diff --git a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
index f3cfc7a3..f527ff83 100644
--- a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
+++ b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
@@ -2224,6 +2224,8 @@ components:
AssetEntryNewDto:
type: object
properties:
+ '@context':
+ type: object
asset:
$ref: '#/components/schemas/AssetInput'
dataAddress:
@@ -2240,12 +2242,19 @@ components:
type: string
example: https://w3id.org/edc/v0.0.1/ns/Asset
properties:
- type: object
- additionalProperties:
- type: object
- example: null
+ $ref: '#/components/schemas/Props'
example: null
+ Props:
+ type: object
+ properties:
+ description:
+ type: string
+
+ contenttype:
+ type: string
+
+
AssetOutput:
type: object
@@ -2666,7 +2675,16 @@ components:
example: https://w3id.org/edc/v0.0.1/ns/DataAddress
type:
type: string
- example: null
+ proxyPath:
+ type: string
+ proxyBody:
+ type: string
+ proxyMethod:
+ type: string
+ proxyQueryParams:
+ type: string
+ baseUrl:
+ type: string
example: null
@@ -2899,18 +2917,14 @@ components:
IdResponse:
type: object
properties:
+ '@type':
+ type: string
'@id':
type: string
- example: null
- createdAt:
+ 'edc:createdAt':
type: integer
format: int64
- example: null
- example:
- '@context':
- edc: https://w3id.org/edc/v0.0.1/ns/
- '@id': id-value
- createdAt: 1688465655
+
List:
type: object
properties:
From d5231214806f43b2178d6203dd8d70993ca8df76 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pedro=20Bail=C3=A3o?=
Date: Tue, 16 Jan 2024 15:09:58 +0000
Subject: [PATCH 10/12] create contract definition request
---
.../controllers/EDCController.java | 10 ++++
.../services/impl/EDCServiceImpl.java | 22 ++++---
.../src/main/resources/openapi.yml | 58 ++++++++++++++++---
3 files changed, 75 insertions(+), 15 deletions(-)
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
index 1cdeaceb..f188c369 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/controllers/EDCController.java
@@ -20,11 +20,21 @@ public ResponseEntity> createAssetRequest(QuerySpec querySpec) throw
return ResponseEntity.ok(edcService.createAssetRequest(querySpec));
}
+ @Override
+ public ResponseEntity createContract(ContractDefinitionInput contractDefinitionInput) throws Exception {
+ return ResponseEntity.ok(edcService.createContractDef(contractDefinitionInput).block());
+ }
+
@Override
public ResponseEntity> createContractRequest(QuerySpec querySpec) throws Exception {
return ResponseEntity.ok(edcService.createContractDefRequest(querySpec));
}
+ @Override
+ public ResponseEntity createPolicy(PolicyDefinitionInput policyDefinitionInput) throws Exception {
+ return ResponseEntity.ok(edcService.createPolicy(policyDefinitionInput).block());
+ }
+
@Override
public ResponseEntity> createPolicyRequest(QuerySpec querySpec) throws Exception {
return ResponseEntity.ok(edcService.createPolicyRequest(querySpec));
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
index 3202b2d9..46a1fe1d 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
@@ -135,11 +135,10 @@ public Void deleteAsset(String assetId) {
@Override
public Mono createPolicy(PolicyDefinitionInput dto) {
- return webClient
+ return webClientCreation("/management/v2/policydefinitions")
.post()
- .uri(uriBuilder -> uriBuilder.path("/management/v2/policydefinitions").build())
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
+ .header("x-api-key", apiKey)
+ .bodyValue(dto)
.retrieve()
.bodyToMono(IdResponse.class)
.retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
@@ -185,13 +184,20 @@ public Void deletePolicy(String policyId) {
@Override
public Mono createContractDef(ContractDefinitionInput dto) {
- return webClient
+ return webClientCreation("/management/v2/contractdefinitions")
.post()
- .uri(uriBuilder -> uriBuilder.path("/management/v2/contractdefinitions").build())
- .contentType(MediaType.APPLICATION_JSON)
- .body(BodyInserters.fromValue(dto))
+ .header("x-api-key", apiKey)
+ .bodyValue(dto)
.retrieve()
.bodyToMono(IdResponse.class)
+ .doOnRequest(
+ request -> {
+ // Log request details before sending
+
+ System.out.println("Request Body: " + dto.toString()); // You can customize this based on your DTO structure
+ }
+ )
+ .log()
.retryWhen(Retry.fixedDelay(3, Duration.ofSeconds(3)));
}
diff --git a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
index f527ff83..eebbf29d 100644
--- a/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
+++ b/demand-capacity-mgmt-specification/src/main/resources/openapi.yml
@@ -118,7 +118,25 @@ paths:
type: array
items:
$ref: '#/components/schemas/Asset'
-
+ /edc/policy:
+ post:
+ tags:
+ - EDC
+ summary: create a Policy
+ operationId: createPolicy
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/PolicyDefinitionInput'
+ responses:
+ 200:
+ description: General greeting
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/IdResponse'
/edc/policy/request:
post:
tags:
@@ -174,6 +192,26 @@ paths:
200:
description: Delete policy with id
+ /edc/contract:
+ post:
+ tags:
+ - EDC
+ summary: create an contract definition
+ operationId: createContract
+ requestBody:
+ required: true
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ContractDefinitionInput'
+ responses:
+ 200:
+ description: General greeting
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/IdResponse'
+
/edc/contract/request:
post:
tags:
@@ -2243,7 +2281,7 @@ components:
example: https://w3id.org/edc/v0.0.1/ns/Asset
properties:
$ref: '#/components/schemas/Props'
- example: null
+
Props:
type: object
@@ -2464,6 +2502,8 @@ components:
ContractDefinitionInput:
type: object
properties:
+ '@context':
+ type: object
'@id':
type: string
example: null
@@ -2474,10 +2514,7 @@ components:
type: string
example: null
assetsSelector:
- type: array
- example: null
- items:
- $ref: '#/components/schemas/Criterion'
+ $ref: '#/components/schemas/Criterion'
contractPolicyId:
type: string
example: null
@@ -2487,7 +2524,11 @@ components:
'@id': definition-id
accessPolicyId: asset-policy-id
contractPolicyId: contract-policy-id
- assetsSelector: []
+ assetsSelector:
+ '@type': CriterionDto
+ operandLeft: https://w3id.org/edc/v0.0.1/ns/id
+ operator: "="
+ operandRight: digital-twin-registry
ContractDefinitionOutput:
type: object
properties:
@@ -3020,9 +3061,12 @@ components:
rightOperand: value
prohibition: []
obligation: []
+
PolicyDefinitionInput:
type: object
properties:
+ '@context':
+ type: object
'@id':
type: string
example: null
From 46ce2c1044c5fc4707697afa1e3c3717086ebbab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pedro=20Bail=C3=A3o?=
Date: Mon, 29 Jan 2024 11:28:56 +0000
Subject: [PATCH 11/12] add .env file to backend
---
.gitignore | 1 -
demand-capacity-mgmt-backend/.env | 2 ++
demand-capacity-mgmt-backend/pom.xml | 6 ++++++
.../services/impl/EDCServiceImpl.java | 12 ++++++++----
4 files changed, 16 insertions(+), 5 deletions(-)
create mode 100644 demand-capacity-mgmt-backend/.env
diff --git a/.gitignore b/.gitignore
index 4c4fa3c7..069f0125 100644
--- a/.gitignore
+++ b/.gitignore
@@ -39,7 +39,6 @@ target/
.idea/*
demand-capacity-mgmt-backend/.mvn/wrapper/maven-wrapper.jar
-.env
keycloak/generate-secret.sh
keycloak/init-db.sql
keycloak/realm-export.json
diff --git a/demand-capacity-mgmt-backend/.env b/demand-capacity-mgmt-backend/.env
new file mode 100644
index 00000000..b0d302d3
--- /dev/null
+++ b/demand-capacity-mgmt-backend/.env
@@ -0,0 +1,2 @@
+BASE_URL=
+API_KEY=
\ No newline at end of file
diff --git a/demand-capacity-mgmt-backend/pom.xml b/demand-capacity-mgmt-backend/pom.xml
index c2e0f240..0ea3b07e 100644
--- a/demand-capacity-mgmt-backend/pom.xml
+++ b/demand-capacity-mgmt-backend/pom.xml
@@ -45,6 +45,12 @@
+
+ io.github.cdimascio
+ java-dotenv
+ 5.2.2
+
+
org.springframework.boot
spring-boot-starter-webflux
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
index 46a1fe1d..09e4cff8 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
@@ -15,19 +15,23 @@
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.util.retry.Retry;
+import io.github.cdimascio.dotenv.Dotenv;
@RequiredArgsConstructor
@Service
@Slf4j
public class EDCServiceImpl implements EDCService {
- private final WebClient webClient = WebClient.create("https://materialpass.int.demo.catena-x.net/BPNL000000000000");
-
- private static final String BASE_URL = "https://dcm.dev.demo.catena-x.net/BPNL000000000000";
+ private static final String BASE_URL = getEnv("BASE_URL");
+ private final String apiKey = getEnv("API_KEY");
+ private final WebClient webClient = WebClient.create(BASE_URL);
private String accessToken;
private Instant tokenExpiration;
- private final String apiKey = "ZWRjX2RjbV9hZXNfZW5ja2V5Cg==";
+ private static String getEnv(String key) {
+ Dotenv dotenv = Dotenv.configure().load();
+ return dotenv.get(key);
+ }
public Mono getToken() {
if (accessToken != null && !isTokenExpired()) {
From f4884ba85ed188acdc2765bd0f78f16afa9b6728 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pedro=20Bail=C3=A3o?=
Date: Mon, 29 Jan 2024 12:31:39 +0000
Subject: [PATCH 12/12] Add more variables to .env file
---
demand-capacity-mgmt-backend/.env | 7 ++++++-
.../services/impl/EDCServiceImpl.java | 11 +++++------
2 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/demand-capacity-mgmt-backend/.env b/demand-capacity-mgmt-backend/.env
index b0d302d3..18bc2ced 100644
--- a/demand-capacity-mgmt-backend/.env
+++ b/demand-capacity-mgmt-backend/.env
@@ -1,2 +1,7 @@
BASE_URL=
-API_KEY=
\ No newline at end of file
+API_KEY=
+
+TOKEN_ENDPOINT=
+CLIENT_ID=
+CLIENT_SECRET=
+GRANT_TYPE=
\ No newline at end of file
diff --git a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
index 09e4cff8..9221d058 100644
--- a/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
+++ b/demand-capacity-mgmt-backend/src/main/java/org/eclipse/tractusx/demandcapacitymgmt/demandcapacitymgmtbackend/services/impl/EDCServiceImpl.java
@@ -28,6 +28,11 @@ public class EDCServiceImpl implements EDCService {
private String accessToken;
private Instant tokenExpiration;
+ private final String tokenEndpoint = getEnv("TOKEN_ENDPOINT");
+ private final String clientId = getEnv("CLIENT_ID");
+ private final String clientSecret = getEnv("CLIENT_SECRET");
+ private final String grantType = getEnv("GRANT_TYPE");
+
private static String getEnv(String key) {
Dotenv dotenv = Dotenv.configure().load();
return dotenv.get(key);
@@ -43,12 +48,6 @@ public Mono getToken() {
@Override
public Mono getAccessToken() {
- String tokenEndpoint =
- "https://centralidp.int.demo.catena-x.net/auth/realms/CX-Central/protocol/openid-connect/token";
- // Set the client credentials
- String clientId = "sa574";
- String clientSecret = "Lh0ctCMQQitoS8qxwKVx9BgbwYOhNJns";
- String grantType = "client_credentials";
WebClient client = WebClient
.builder()