From 48cd207683517f3838a9089a804419f7b614e63a Mon Sep 17 00:00:00 2001 From: Jan Ridderbusch <36418748+jridderbusch@users.noreply.github.com> Date: Fri, 8 Dec 2023 10:14:41 +0100 Subject: [PATCH] fix: Add downwards compatibility for AP API (#337) --- CHANGELOG.md | 4 +- .../api/BrokerServerResource.java | 10 +++++ .../api/model/DataOfferCountResult.java | 21 ++++++++++ .../broker-server-api/client-ts/README.md | 2 +- .../BrokerServerResourceImpl.java | 6 +++ ...rityPortalConnectorMetadataApiService.java | 18 +++++++++ ...horityPortalConnectorMetadataApiTest.java} | 40 ++++++++++++++++++- 7 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 extensions/broker-server-api/api/src/main/java/de/sovity/edc/ext/brokerserver/api/model/DataOfferCountResult.java rename extensions/broker-server/src/test/java/de/sovity/edc/ext/brokerserver/services/api/{ConnectorMetadataApiTest.java => AuthorityPortalConnectorMetadataApiTest.java} (83%) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5f1d108..d9ceb358 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 #### Minor -#### Patch +- Authority Portal API: Re-added the deprecated data offer endpoint: `authority-portal-api/data-offer-counts` ### Deployment Migration Notes @@ -49,7 +49,7 @@ EDC 0 / MDS 2.0 bugfix release, Authority Portal API Connector Metadata Endpoint - The DAPS needs to contain the claim `referringConnector=broker` for the broker. The expected value `broker` could be overridden by specifying a different value for `MY_EDC_PARTICIPANT_ID`. - Authority Portal API: The data offer count endpoint was removed in favor of the new Connector Metadata - Endpoint: `wrapper/broker/authority-portal-api/connectors`, used to be ~~``authority-portal-api/data-offer-counts``~~. + Endpoint: `authority-portal-api/connectors`, used to be ~~``authority-portal-api/data-offer-counts``~~. #### Compatible Versions diff --git a/extensions/broker-server-api/api/src/main/java/de/sovity/edc/ext/brokerserver/api/BrokerServerResource.java b/extensions/broker-server-api/api/src/main/java/de/sovity/edc/ext/brokerserver/api/BrokerServerResource.java index d87b4f68..d0fcede7 100644 --- a/extensions/broker-server-api/api/src/main/java/de/sovity/edc/ext/brokerserver/api/BrokerServerResource.java +++ b/extensions/broker-server-api/api/src/main/java/de/sovity/edc/ext/brokerserver/api/BrokerServerResource.java @@ -21,6 +21,7 @@ import de.sovity.edc.ext.brokerserver.api.model.ConnectorPageQuery; import de.sovity.edc.ext.brokerserver.api.model.ConnectorPageResult; import de.sovity.edc.ext.brokerserver.api.model.AuthorityPortalConnectorInfo; +import de.sovity.edc.ext.brokerserver.api.model.DataOfferCountResult; import de.sovity.edc.ext.brokerserver.api.model.DataOfferDetailPageQuery; import de.sovity.edc.ext.brokerserver.api.model.DataOfferDetailPageResult; import io.swagger.v3.oas.annotations.Operation; @@ -86,4 +87,13 @@ public interface BrokerServerResource { @Produces(MediaType.APPLICATION_JSON) @Operation(description = "Provide Connector metadata by provided Connector Endpoints") List getConnectorMetadata(List endpoints, @QueryParam("adminApiKey") String adminApiKey); + + @POST + @Deprecated + @Path("authority-portal-api/data-offer-counts") + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) + @Operation(description = "Query the amount of public Data Offers by provided Connector URLs." + + "This endpoint has been replaced by the Authority Portal Connector Metadata endpoint and will be removed in the near future.") + DataOfferCountResult dataOfferCount(List endpoints); } diff --git a/extensions/broker-server-api/api/src/main/java/de/sovity/edc/ext/brokerserver/api/model/DataOfferCountResult.java b/extensions/broker-server-api/api/src/main/java/de/sovity/edc/ext/brokerserver/api/model/DataOfferCountResult.java new file mode 100644 index 00000000..061644ef --- /dev/null +++ b/extensions/broker-server-api/api/src/main/java/de/sovity/edc/ext/brokerserver/api/model/DataOfferCountResult.java @@ -0,0 +1,21 @@ +package de.sovity.edc.ext.brokerserver.api.model; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +import java.util.Map; + +@Getter +@Setter +@ToString +@NoArgsConstructor +@AllArgsConstructor +@Schema(description = "Number of Data Offers per Connector endpoint.", requiredMode = Schema.RequiredMode.REQUIRED) +public class DataOfferCountResult { + @Schema(description = "Map from endpoint URL to Data Offer count", requiredMode = Schema.RequiredMode.REQUIRED) + private Map dataOfferCount; +} diff --git a/extensions/broker-server-api/client-ts/README.md b/extensions/broker-server-api/client-ts/README.md index ad2997a9..85741fb4 100644 --- a/extensions/broker-server-api/client-ts/README.md +++ b/extensions/broker-server-api/client-ts/README.md @@ -38,7 +38,7 @@ import { } from '@sovity.de/broker-server-client'; const brokerServerClient: BrokerServerClient = buildBrokerServerClient({ - managementApiUrl: 'http://localhost:11002/api/v1/management', + managementApiUrl: 'http://localhost:11002/api/management', managementApiKey: 'ApiKeyDefaultValue', }); diff --git a/extensions/broker-server/src/main/java/de/sovity/edc/ext/brokerserver/BrokerServerResourceImpl.java b/extensions/broker-server/src/main/java/de/sovity/edc/ext/brokerserver/BrokerServerResourceImpl.java index 0bdd80d2..040a649b 100644 --- a/extensions/broker-server/src/main/java/de/sovity/edc/ext/brokerserver/BrokerServerResourceImpl.java +++ b/extensions/broker-server/src/main/java/de/sovity/edc/ext/brokerserver/BrokerServerResourceImpl.java @@ -22,6 +22,7 @@ import de.sovity.edc.ext.brokerserver.api.model.ConnectorDetailPageResult; import de.sovity.edc.ext.brokerserver.api.model.ConnectorPageQuery; import de.sovity.edc.ext.brokerserver.api.model.ConnectorPageResult; +import de.sovity.edc.ext.brokerserver.api.model.DataOfferCountResult; import de.sovity.edc.ext.brokerserver.api.model.DataOfferDetailPageQuery; import de.sovity.edc.ext.brokerserver.api.model.DataOfferDetailPageResult; import de.sovity.edc.ext.brokerserver.db.DslContextFactory; @@ -88,4 +89,9 @@ public List getConnectorMetadata(List endp adminApiKeyValidator.validateAdminApiKey(adminApiKey); return dslContextFactory.transactionResult(dsl -> authorityPortalConnectorMetadataApiService.getMetadataByEndpoints(dsl, endpoints)); } + + @Override + public DataOfferCountResult dataOfferCount(List endpoints) { + return dslContextFactory.transactionResult(dsl -> authorityPortalConnectorMetadataApiService.countByEndpoints(dsl, endpoints)); + } } diff --git a/extensions/broker-server/src/main/java/de/sovity/edc/ext/brokerserver/services/api/AuthorityPortalConnectorMetadataApiService.java b/extensions/broker-server/src/main/java/de/sovity/edc/ext/brokerserver/services/api/AuthorityPortalConnectorMetadataApiService.java index 60d103be..68d726f1 100644 --- a/extensions/broker-server/src/main/java/de/sovity/edc/ext/brokerserver/services/api/AuthorityPortalConnectorMetadataApiService.java +++ b/extensions/broker-server/src/main/java/de/sovity/edc/ext/brokerserver/services/api/AuthorityPortalConnectorMetadataApiService.java @@ -15,10 +15,17 @@ package de.sovity.edc.ext.brokerserver.services.api; import de.sovity.edc.ext.brokerserver.api.model.AuthorityPortalConnectorInfo; +import de.sovity.edc.ext.brokerserver.api.model.DataOfferCountResult; +import de.sovity.edc.ext.brokerserver.dao.utils.PostgresqlUtils; +import de.sovity.edc.ext.brokerserver.db.jooq.Tables; import lombok.RequiredArgsConstructor; import org.jooq.DSLContext; +import org.jooq.impl.DSL; import java.util.List; +import java.util.function.Function; + +import static java.util.stream.Collectors.toMap; @RequiredArgsConstructor public class AuthorityPortalConnectorMetadataApiService { @@ -37,4 +44,15 @@ public List getMetadataByEndpoints(DSLContext dsl, )) .toList(); } + + public DataOfferCountResult countByEndpoints(DSLContext dsl, List endpoints) { + var connectorMetadata = getMetadataByEndpoints(dsl, endpoints); + + var numDataOffers = connectorMetadata.stream().distinct().collect(toMap( + AuthorityPortalConnectorInfo::getConnectorEndpoint, + AuthorityPortalConnectorInfo::getDataOfferCount + )); + + return new DataOfferCountResult(numDataOffers); + } } diff --git a/extensions/broker-server/src/test/java/de/sovity/edc/ext/brokerserver/services/api/ConnectorMetadataApiTest.java b/extensions/broker-server/src/test/java/de/sovity/edc/ext/brokerserver/services/api/AuthorityPortalConnectorMetadataApiTest.java similarity index 83% rename from extensions/broker-server/src/test/java/de/sovity/edc/ext/brokerserver/services/api/ConnectorMetadataApiTest.java rename to extensions/broker-server/src/test/java/de/sovity/edc/ext/brokerserver/services/api/AuthorityPortalConnectorMetadataApiTest.java index 26cd6287..51eb4f19 100644 --- a/extensions/broker-server/src/test/java/de/sovity/edc/ext/brokerserver/services/api/ConnectorMetadataApiTest.java +++ b/extensions/broker-server/src/test/java/de/sovity/edc/ext/brokerserver/services/api/AuthorityPortalConnectorMetadataApiTest.java @@ -44,7 +44,7 @@ @ApiTest @ExtendWith(EdcExtension.class) -class ConnectorMetadataApiTest { +class AuthorityPortalConnectorMetadataApiTest { @RegisterExtension private static final TestDatabase TEST_DATABASE = TestDatabaseFactory.getTestDatabase(); @@ -100,6 +100,44 @@ void testConnectorMetadataByEndpoints() { }); } + @Test + void testCountByEndpoints() { + TEST_DATABASE.testTransaction(dsl -> { + // arrange + var now = OffsetDateTime.now().withNano(0); + + createConnector(dsl, now, 1); + createDataOffer(dsl, now, 1, 1); + createDataOffer(dsl, now, 1, 2); + + createConnector(dsl, now, 2); + createDataOffer(dsl, now, 2, 1); + + createConnector(dsl, now, 3); + createDataOffer(dsl, now, 3, 1); + + createConnector(dsl, now, 4); + + // act + var actual = brokerServerClient().brokerServerApi().dataOfferCount( + Arrays.asList( + getEndpoint(1), + getEndpoint(1), // having this twice should not crash the query + getEndpoint(2), + getEndpoint(4), + getEndpoint(5) // having this not existing should not crash the query + )); + + // assert + var dataOfferCountMap = actual.getDataOfferCount(); + assertThat(dataOfferCountMap).isEqualTo(Map.of( + getEndpoint(1), 2, + getEndpoint(2), 1, + getEndpoint(4), 0 + )); + }); + } + private AuthorityPortalConnectorInfo forConnector(List actual, int iConnector) { return actual.stream() .filter(connectorMetadata ->