Skip to content

Commit

Permalink
feat: Data Offer & Connector Detail Page (#157)
Browse files Browse the repository at this point in the history
* feat: dataOfferDetailPage

* feat: connectorDetailPage

* feat: detail pages

* feat: detail pages

* feat: detail pages

* test: detail pages

* refactor: minor refactorings

* refactor: minor refactorings

* refactor: minor test refactorings

* refactor: minor test refactorings

* refactor: minor test refactorings

* refactor: minor test refactorings

* refactor: DataOfferDetailPageQueryService

* refactor: DataOfferDetailPageQueryService

* refactor: DataOfferDetailPageQueryService

* refactor: changed models slightly, improved tests

---------

Co-authored-by: Tim Berthold <[email protected]>
Co-authored-by: Tim Berthold <[email protected]>
  • Loading branch information
3 people authored Jun 27, 2023
1 parent b4b394e commit d8a3d91
Show file tree
Hide file tree
Showing 18 changed files with 539 additions and 55 deletions.
2 changes: 1 addition & 1 deletion extensions/broker-server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ dependencies {
testImplementation("org.testcontainers:junit-jupiter:${testcontainersVersion}")
testImplementation("org.testcontainers:postgresql:${testcontainersVersion}")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.3")
testImplementation("org.skyscreamer:jsonassert:1.5.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.9.3")
testImplementation("org.json:json:20230618")

implementation("org.quartz-scheduler:quartz:2.3.2")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import de.sovity.edc.ext.brokerserver.dao.pages.catalog.CatalogQueryService;
import de.sovity.edc.ext.brokerserver.dao.pages.catalog.CatalogQuerySortingService;
import de.sovity.edc.ext.brokerserver.dao.pages.connector.ConnectorPageQueryService;
import de.sovity.edc.ext.brokerserver.dao.pages.dataoffer.DataOfferDetailPageQueryService;
import de.sovity.edc.ext.brokerserver.db.DataSourceFactory;
import de.sovity.edc.ext.brokerserver.db.DslContextFactory;
import de.sovity.edc.ext.brokerserver.services.BrokerServerInitializer;
Expand All @@ -32,6 +33,7 @@
import de.sovity.edc.ext.brokerserver.services.api.AssetPropertyParser;
import de.sovity.edc.ext.brokerserver.services.api.CatalogApiService;
import de.sovity.edc.ext.brokerserver.services.api.ConnectorApiService;
import de.sovity.edc.ext.brokerserver.services.api.DataOfferDetailApiService;
import de.sovity.edc.ext.brokerserver.services.api.PaginationMetadataUtils;
import de.sovity.edc.ext.brokerserver.services.api.PolicyDtoBuilder;
import de.sovity.edc.ext.brokerserver.services.api.filtering.CatalogFilterAttributeDefinitionService;
Expand Down Expand Up @@ -108,6 +110,7 @@ public static BrokerServerExtensionContext buildContext(
brokerServerSettings
);
var connectorPageQueryService = new ConnectorPageQueryService();
var dataOfferDetailPageQueryService = new DataOfferDetailPageQueryService(catalogQueryContractOfferFetcher, brokerServerSettings);


// Services
Expand Down Expand Up @@ -189,10 +192,18 @@ public static BrokerServerExtensionContext buildContext(
connectorPageQueryService,
paginationMetadataUtils
);

var dataOfferDetailApiService = new DataOfferDetailApiService(
dataOfferDetailPageQueryService,
policyDtoBuilder,
assetPropertyParser
);

var brokerServerResource = new BrokerServerResourceImpl(
dslContextFactory,
connectorApiService,
catalogApiService
catalogApiService,
dataOfferDetailApiService
);
return new BrokerServerExtensionContext(
brokerServerResource,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import de.sovity.edc.ext.brokerserver.db.DslContextFactory;
import de.sovity.edc.ext.brokerserver.services.api.CatalogApiService;
import de.sovity.edc.ext.brokerserver.services.api.ConnectorApiService;
import de.sovity.edc.ext.brokerserver.services.api.DataOfferDetailApiService;
import de.sovity.edc.ext.wrapper.api.broker.BrokerServerResource;
import de.sovity.edc.ext.wrapper.api.broker.model.CatalogPageQuery;
import de.sovity.edc.ext.wrapper.api.broker.model.CatalogPageResult;
Expand All @@ -37,6 +38,7 @@ public class BrokerServerResourceImpl implements BrokerServerResource {
private final DslContextFactory dslContextFactory;
private final ConnectorApiService connectorApiService;
private final CatalogApiService catalogApiService;
private final DataOfferDetailApiService dataOfferDetailApiService;

@Override
public CatalogPageResult catalogPage(CatalogPageQuery query) {
Expand All @@ -49,12 +51,12 @@ public ConnectorPageResult connectorPage(ConnectorPageQuery query) {
}

@Override
public DataOfferDetailPageResult dataOfferDetailPage(DataOfferDetailPageQuery dataOfferDetailPageQuery) {
throw new IllegalStateException("Not yet implemented!");
public DataOfferDetailPageResult dataOfferDetailPage(DataOfferDetailPageQuery query) {
return dslContextFactory.transactionResult(dsl -> dataOfferDetailApiService.dataOfferDetailPage(dsl, query));
}

@Override
public ConnectorDetailPageResult connectorDetailPage(ConnectorDetailPageQuery connectorDetailPageQuery) {
throw new IllegalStateException("Not yet implemented!");
public ConnectorDetailPageResult connectorDetailPage(ConnectorDetailPageQuery query) {
return dslContextFactory.transactionResult(dsl -> connectorApiService.connectorDetailPage(dsl, query));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

package de.sovity.edc.ext.brokerserver.dao.pages.catalog;

import de.sovity.edc.ext.brokerserver.dao.pages.catalog.models.ContractOfferRs;
import de.sovity.edc.ext.brokerserver.dao.pages.dataoffer.model.ContractOfferRs;
import de.sovity.edc.ext.brokerserver.dao.utils.MultisetUtils;
import de.sovity.edc.ext.brokerserver.db.jooq.Tables;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
package de.sovity.edc.ext.brokerserver.dao.pages.catalog;

import de.sovity.edc.ext.brokerserver.dao.pages.catalog.models.CatalogQueryFilter;
import de.sovity.edc.ext.brokerserver.dao.pages.catalog.models.DataOfferRs;
import de.sovity.edc.ext.brokerserver.dao.pages.catalog.models.DataOfferListEntryRs;
import de.sovity.edc.ext.brokerserver.dao.pages.catalog.models.PageQuery;
import de.sovity.edc.ext.brokerserver.dao.utils.MultisetUtils;
import de.sovity.edc.ext.wrapper.api.broker.model.CatalogPageSortingType;
Expand All @@ -42,9 +42,9 @@ public class CatalogQueryDataOfferFetcher {
* @param filters filters (queries + filter clauses)
* @param sorting sorting
* @param pageQuery pagination
* @return {@link Field} of {@link DataOfferRs}s
* @return {@link Field} of {@link DataOfferListEntryRs}s
*/
public Field<List<DataOfferRs>> queryDataOffers(
public Field<List<DataOfferListEntryRs>> queryDataOffers(
CatalogQueryFields fields,
String searchQuery,
List<CatalogQueryFilter> filters,
Expand All @@ -70,7 +70,7 @@ public Field<List<DataOfferRs>> queryDataOffers(
.orderBy(catalogQuerySortingService.getOrderBy(fields, sorting))
.limit(pageQuery.offset(), pageQuery.limit());

return MultisetUtils.multiset(query, DataOfferRs.class);
return MultisetUtils.multiset(query, DataOfferListEntryRs.class);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@
@FieldDefaults(level = AccessLevel.PRIVATE)
public class CatalogPageRs {
String availableFilterValues;
List<DataOfferRs> dataOffers;
List<DataOfferListEntryRs> dataOffers;
int numTotalDataOffers;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright (c) 2023 sovity GmbH
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* sovity GmbH - initial API and implementation
*
*/

package de.sovity.edc.ext.brokerserver.dao.pages.catalog.models;

import de.sovity.edc.ext.brokerserver.dao.pages.dataoffer.model.ContractOfferRs;
import de.sovity.edc.ext.brokerserver.db.jooq.enums.ConnectorOnlineStatus;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.FieldDefaults;

import java.time.OffsetDateTime;
import java.util.List;

@Getter
@Setter
@FieldDefaults(level = AccessLevel.PRIVATE)
public class DataOfferListEntryRs {
String assetId;
String assetPropertiesJson;
OffsetDateTime createdAt;
OffsetDateTime updatedAt;
List<ContractOfferRs> contractOffers;
String connectorEndpoint;
ConnectorOnlineStatus connectorOnlineStatus;
OffsetDateTime connectorOfflineSinceOrLastUpdatedAt;
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ public List<ConnectorRs> queryConnectorPage(DSLContext dsl, String searchQuery,
.fetchInto(ConnectorRs.class);
}

public ConnectorRs queryConnectorDetailPage(DSLContext dsl, String connectorEndpoint) {
var c = Tables.CONNECTOR;
var filterBySearchQuery = SearchUtils.simpleSearch(connectorEndpoint, List.of(c.ENDPOINT, c.CONNECTOR_ID));

return dsl.select(c.asterisk(), dataOfferCount(c.ENDPOINT).as("numDataOffers"))
.from(c)
.where(filterBySearchQuery)
.fetchOneInto(ConnectorRs.class);
}

@NotNull
private List<OrderField<?>> sortConnectorPage(Connector c, ConnectorPageSortingType sorting) {
var alphabetically = c.ENDPOINT.asc();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2023 sovity GmbH
*
* This program and the accompanying materials are made available under the
* terms of the Apache License, Version 2.0 which is available at
* https://www.apache.org/licenses/LICENSE-2.0
*
* SPDX-License-Identifier: Apache-2.0
*
* Contributors:
* sovity GmbH - initial API and implementation
*
*/

package de.sovity.edc.ext.brokerserver.dao.pages.dataoffer;

import de.sovity.edc.ext.brokerserver.dao.pages.catalog.CatalogQueryContractOfferFetcher;
import de.sovity.edc.ext.brokerserver.dao.pages.catalog.CatalogQueryFields;
import de.sovity.edc.ext.brokerserver.dao.pages.dataoffer.model.DataOfferDetailRs;
import de.sovity.edc.ext.brokerserver.db.jooq.Tables;
import de.sovity.edc.ext.brokerserver.services.config.BrokerServerSettings;
import lombok.RequiredArgsConstructor;
import org.jooq.DSLContext;

@RequiredArgsConstructor
public class DataOfferDetailPageQueryService {
private final CatalogQueryContractOfferFetcher catalogQueryContractOfferFetcher;
private final BrokerServerSettings brokerServerSettings;

public DataOfferDetailRs queryDataOfferDetailsPage(DSLContext dsl, String assetId, String endpoint) {
// We are re-using the catalog page query stuff as long as we can get away with it
var fields = new CatalogQueryFields(
Tables.CONNECTOR,
Tables.DATA_OFFER,
brokerServerSettings.getDataSpaceConfig()
);

var d = fields.getDataOfferTable();
var c = fields.getConnectorTable();

return dsl.select(
d.ASSET_ID,
d.ASSET_PROPERTIES.cast(String.class).as("assetPropertiesJson"),
d.CREATED_AT,
d.UPDATED_AT,
catalogQueryContractOfferFetcher.getContractOffers(fields).as("contractOffers"),
fields.getOfflineSinceOrLastUpdatedAt().as("connectorOfflineSinceOrLastUpdatedAt"),
c.ENDPOINT.as("connectorEndpoint"),
c.ONLINE_STATUS.as("connectorOnlineStatus"))
.from(d).leftJoin(c).on(c.ENDPOINT.eq(d.CONNECTOR_ENDPOINT))
.where(d.ASSET_ID.eq(assetId).or(d.CONNECTOR_ENDPOINT.eq(endpoint)))
.fetchOneInto(DataOfferDetailRs.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
*/

package de.sovity.edc.ext.brokerserver.dao.pages.catalog.models;
package de.sovity.edc.ext.brokerserver.dao.pages.dataoffer.model;

import lombok.AccessLevel;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*
*/

package de.sovity.edc.ext.brokerserver.dao.pages.catalog.models;
package de.sovity.edc.ext.brokerserver.dao.pages.dataoffer.model;

import de.sovity.edc.ext.brokerserver.db.jooq.enums.ConnectorOnlineStatus;
import lombok.AccessLevel;
Expand All @@ -26,7 +26,7 @@
@Getter
@Setter
@FieldDefaults(level = AccessLevel.PRIVATE)
public class DataOfferRs {
public class DataOfferDetailRs {
String assetId;
String assetPropertiesJson;
OffsetDateTime createdAt;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@
package de.sovity.edc.ext.brokerserver.services.api;

import de.sovity.edc.ext.brokerserver.dao.pages.catalog.CatalogQueryService;
import de.sovity.edc.ext.brokerserver.dao.pages.catalog.models.ContractOfferRs;
import de.sovity.edc.ext.brokerserver.dao.pages.catalog.models.DataOfferRs;
import de.sovity.edc.ext.brokerserver.dao.pages.catalog.models.DataOfferListEntryRs;
import de.sovity.edc.ext.brokerserver.dao.pages.dataoffer.model.ContractOfferRs;
import de.sovity.edc.ext.brokerserver.services.api.filtering.CatalogFilterService;
import de.sovity.edc.ext.brokerserver.services.config.BrokerServerSettings;
import de.sovity.edc.ext.wrapper.api.broker.model.CatalogContractOffer;
import de.sovity.edc.ext.wrapper.api.broker.model.CatalogDataOffer;
import de.sovity.edc.ext.wrapper.api.broker.model.CatalogPageQuery;
import de.sovity.edc.ext.wrapper.api.broker.model.CatalogPageResult;
import de.sovity.edc.ext.wrapper.api.broker.model.CatalogPageSortingItem;
import de.sovity.edc.ext.wrapper.api.broker.model.CatalogPageSortingType;
import de.sovity.edc.ext.wrapper.api.broker.model.ConnectorOnlineStatus;
import de.sovity.edc.ext.wrapper.api.broker.model.DataOfferListEntry;
import de.sovity.edc.ext.wrapper.api.broker.model.DataOfferListEntryContractOffer;
import lombok.RequiredArgsConstructor;
import org.jooq.DSLContext;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Stream;

@RequiredArgsConstructor
public class CatalogApiService {
Expand Down Expand Up @@ -73,45 +73,45 @@ public CatalogPageResult catalogPage(DSLContext dsl, CatalogPageQuery query) {
result.setAvailableSortings(buildAvailableSortings());
result.setPaginationMetadata(paginationMetadata);
result.setAvailableFilters(catalogFilterService.buildAvailableFilters(catalogPageRs.getAvailableFilterValues()));
result.setDataOffers(buildDataOfferListEntries(catalogPageRs.getDataOffers()));
result.setDataOffers(buildCatalogDataOffers(catalogPageRs.getDataOffers()));
return result;
}

private List<DataOfferListEntry> buildDataOfferListEntries(List<DataOfferRs> dataOfferRs) {
private List<CatalogDataOffer> buildCatalogDataOffers(List<DataOfferListEntryRs> dataOfferRs) {
return dataOfferRs.stream()
.map(this::buildDataOfferListEntry)
.map(this::buildCatalogDataOffer)
.toList();
}

private DataOfferListEntry buildDataOfferListEntry(DataOfferRs dataOfferRs) {
var dataOffer = new DataOfferListEntry();
private CatalogDataOffer buildCatalogDataOffer(DataOfferListEntryRs dataOfferRs) {
var dataOffer = new CatalogDataOffer();
dataOffer.setAssetId(dataOfferRs.getAssetId());
dataOffer.setCreatedAt(dataOfferRs.getCreatedAt());
dataOffer.setUpdatedAt(dataOfferRs.getUpdatedAt());
dataOffer.setProperties(assetPropertyParser.parsePropertiesFromJsonString(dataOfferRs.getAssetPropertiesJson()));
dataOffer.setContractOffers(buildDataOfferListEntryContractOffers(dataOfferRs));
dataOffer.setContractOffers(buildCatalogContractOffers(dataOfferRs));
dataOffer.setConnectorEndpoint(dataOfferRs.getConnectorEndpoint());
dataOffer.setConnectorOfflineSinceOrLastUpdatedAt(dataOfferRs.getConnectorOfflineSinceOrLastUpdatedAt());
dataOffer.setConnectorOnlineStatus(getOnlineStatus(dataOfferRs));
return dataOffer;
}

private List<DataOfferListEntryContractOffer> buildDataOfferListEntryContractOffers(DataOfferRs dataOfferRs) {
private List<CatalogContractOffer> buildCatalogContractOffers(DataOfferListEntryRs dataOfferRs) {
return dataOfferRs.getContractOffers().stream()
.map(this::buildDataOfferListEntryContractOffer)
.map(this::buildCatalogContractOffer)
.toList();
}

private DataOfferListEntryContractOffer buildDataOfferListEntryContractOffer(ContractOfferRs contractOfferDbRow) {
var contractOffer = new DataOfferListEntryContractOffer();
private CatalogContractOffer buildCatalogContractOffer(ContractOfferRs contractOfferDbRow) {
var contractOffer = new CatalogContractOffer();
contractOffer.setContractOfferId(contractOfferDbRow.getContractOfferId());
contractOffer.setContractPolicy(policyDtoBuilder.buildPolicyFromJson(contractOfferDbRow.getPolicyJson()));
contractOffer.setCreatedAt(contractOfferDbRow.getCreatedAt());
contractOffer.setUpdatedAt(contractOfferDbRow.getUpdatedAt());
return contractOffer;
}

private ConnectorOnlineStatus getOnlineStatus(DataOfferRs dataOfferRs) {
private ConnectorOnlineStatus getOnlineStatus(DataOfferListEntryRs dataOfferRs) {
return switch (dataOfferRs.getConnectorOnlineStatus()) {
case ONLINE -> ConnectorOnlineStatus.ONLINE;
case OFFLINE -> ConnectorOnlineStatus.OFFLINE;
Expand All @@ -120,6 +120,10 @@ private ConnectorOnlineStatus getOnlineStatus(DataOfferRs dataOfferRs) {
}

private static List<CatalogPageSortingItem> buildAvailableSortings() {
return Arrays.stream(CatalogPageSortingType.values()).map(it -> new CatalogPageSortingItem(it, it.getTitle())).toList();
return Stream.of(
CatalogPageSortingType.MOST_RECENT,
CatalogPageSortingType.TITLE,
CatalogPageSortingType.ORIGINATOR
).map(it -> new CatalogPageSortingItem(it, it.getTitle())).toList();
}
}
Loading

0 comments on commit d8a3d91

Please sign in to comment.