Skip to content

Commit

Permalink
fix: Add downwards compatibility for AP API (#337)
Browse files Browse the repository at this point in the history
  • Loading branch information
jridderbusch authored Dec 8, 2023
1 parent 8958ea4 commit 48cd207
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 4 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -86,4 +87,13 @@ public interface BrokerServerResource {
@Produces(MediaType.APPLICATION_JSON)
@Operation(description = "Provide Connector metadata by provided Connector Endpoints")
List<AuthorityPortalConnectorInfo> getConnectorMetadata(List<String> 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<String> endpoints);
}
Original file line number Diff line number Diff line change
@@ -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<String, Integer> dataOfferCount;
}
2 changes: 1 addition & 1 deletion extensions/broker-server-api/client-ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -88,4 +89,9 @@ public List<AuthorityPortalConnectorInfo> getConnectorMetadata(List<String> endp
adminApiKeyValidator.validateAdminApiKey(adminApiKey);
return dslContextFactory.transactionResult(dsl -> authorityPortalConnectorMetadataApiService.getMetadataByEndpoints(dsl, endpoints));
}

@Override
public DataOfferCountResult dataOfferCount(List<String> endpoints) {
return dslContextFactory.transactionResult(dsl -> authorityPortalConnectorMetadataApiService.countByEndpoints(dsl, endpoints));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -37,4 +44,15 @@ public List<AuthorityPortalConnectorInfo> getMetadataByEndpoints(DSLContext dsl,
))
.toList();
}

public DataOfferCountResult countByEndpoints(DSLContext dsl, List<String> endpoints) {
var connectorMetadata = getMetadataByEndpoints(dsl, endpoints);

var numDataOffers = connectorMetadata.stream().distinct().collect(toMap(
AuthorityPortalConnectorInfo::getConnectorEndpoint,
AuthorityPortalConnectorInfo::getDataOfferCount
));

return new DataOfferCountResult(numDataOffers);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

@ApiTest
@ExtendWith(EdcExtension.class)
class ConnectorMetadataApiTest {
class AuthorityPortalConnectorMetadataApiTest {

@RegisterExtension
private static final TestDatabase TEST_DATABASE = TestDatabaseFactory.getTestDatabase();
Expand Down Expand Up @@ -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<AuthorityPortalConnectorInfo> actual, int iConnector) {
return actual.stream()
.filter(connectorMetadata ->
Expand Down

0 comments on commit 48cd207

Please sign in to comment.