Skip to content

Commit

Permalink
feat: add isOwnConnector field to UiAsset (#719)
Browse files Browse the repository at this point in the history
  • Loading branch information
kulgg committed Jan 17, 2024
1 parent 82c5dd1 commit 45d1524
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ please see [changelog_updates.md](docs/dev/changelog_updates.md).
- UI API: New endpoint `editAssetMetadata`
- Added `JWKS-Extension`, which provides an endpoint in the default API, that returns the JWKS of the connector.
- Added shortDescriptionText to `UiAsset`
- Added isOwnConnector to `UiAsset`

#### Patch Changes

Expand Down
4 changes: 4 additions & 0 deletions docs/sovity-edc-api-wrapper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,7 @@ components:
- assetId
- connectorEndpoint
- creatorOrganizationName
- isOwnConnector
- participantId
- title
type: object
Expand Down Expand Up @@ -823,6 +824,9 @@ components:
type: string
description: Asset Description Short Text generated from description. Contains
no markdown.
isOwnConnector:
type: boolean
description: Flag that indicates whether this asset is created by this connector.
publisherHomepage:
type: string
description: Asset Homepage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ public class UiAsset {
@Schema(description = "Asset Description Short Text generated from description. Contains no markdown.", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String descriptionShortText;

@Schema(description = "Flag that indicates whether this asset is created by this connector.", requiredMode = Schema.RequiredMode.REQUIRED)
private Boolean isOwnConnector;

@Schema(description = "Asset Homepage", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String publisherHomepage;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2022 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.wrapper.api.common.mappers.utils;

@FunctionalInterface
public interface OwnConnectorEndpointService {
boolean isOwnConnectorEndpoint(String endpoint);
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public class UiAssetMapper {
private final AssetJsonLdUtils assetJsonLdUtils;
private final MarkdownToTextConverter markdownToTextConverter;
private final TextUtils textUtils;
private final OwnConnectorEndpointService ownConnectorEndpointService;

public UiAsset buildUiAsset(JsonObject assetJsonLd, String connectorEndpoint, String participantId) {
var properties = JsonLdUtils.object(assetJsonLd, Prop.Edc.PROPERTIES);
Expand All @@ -67,6 +68,7 @@ public UiAsset buildUiAsset(JsonObject assetJsonLd, String connectorEndpoint, St
uiAsset.setLicenseUrl(JsonLdUtils.string(properties, Prop.Dcterms.LICENSE));
uiAsset.setDescription(description);
uiAsset.setDescriptionShortText(buildShortDescription(description));
uiAsset.setIsOwnConnector(ownConnectorEndpointService.isOwnConnectorEndpoint(connectorEndpoint));
uiAsset.setLanguage(JsonLdUtils.string(properties, Prop.Dcterms.LANGUAGE));
uiAsset.setVersion(JsonLdUtils.string(properties, Prop.Dcat.VERSION));
uiAsset.setMediaType(JsonLdUtils.string(properties, Prop.Dcat.MEDIATYPE));
Expand Down Expand Up @@ -275,7 +277,7 @@ private String buildShortDescription(String description) {
if (description == null) {
return null;
}

var text = markdownToTextConverter.extractText(description);
return textUtils.abbreviate(text, 300);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class AssetMapperTest {
void setup() {
var jsonLd = new TitaniumJsonLd(mock(Monitor.class));
var typeTransformerRegistry = mock(TypeTransformerRegistry.class);
var uiAssetBuilder = new UiAssetMapper(new EdcPropertyUtils(), new AssetJsonLdUtils(), new MarkdownToTextConverter(), new TextUtils());
var uiAssetBuilder = new UiAssetMapper(new EdcPropertyUtils(), new AssetJsonLdUtils(), new MarkdownToTextConverter(), new TextUtils(), x -> endpoint.equals(x));
assetMapper = new AssetMapper(typeTransformerRegistry, uiAssetBuilder, jsonLd);
}

Expand All @@ -55,6 +55,7 @@ void test_buildAssetDto() {
assertThat(uiAsset.getLanguage()).isEqualTo("https://w3id.org/idsa/code/EN");
assertThat(uiAsset.getDescription()).isEqualTo("# Lorem Ipsum...\n## h2 title\n[Link text Here](example.com) 0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789");
assertThat(uiAsset.getDescriptionShortText()).isEqualTo("Lorem Ipsum... h2 title Link text Here 012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890");
assertThat(uiAsset.getIsOwnConnector()).isEqualTo(true);
assertThat(uiAsset.getCreatorOrganizationName()).isEqualTo("My Organization Name");
assertThat(uiAsset.getPublisherHomepage()).isEqualTo("https://data-source.my-org/about");
assertThat(uiAsset.getLicenseUrl()).isEqualTo("https://data-source.my-org/license");
Expand Down Expand Up @@ -196,4 +197,19 @@ void test_noBooleanValue() {
assertThat(uiAsset).isNotNull();
assertThat(uiAsset.getHttpDatasourceHintsProxyMethod()).isNull();
}

@Test
void test_isNotOwnConnector() {
// Arrange
var assetJsonLd = createObjectBuilder()
.add(Prop.ID, "my-asset-1")
.build();

// Act
var uiAsset = assetMapper.buildUiAsset(assetJsonLd, "https://other-connector/api/dsp", participantId);

// Assert
assertThat(uiAsset).isNotNull();
assertThat(uiAsset.getIsOwnConnector()).isFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import de.sovity.edc.ext.wrapper.api.ui.pages.dashboard.services.DapsConfigService;
import de.sovity.edc.ext.wrapper.api.ui.pages.dashboard.services.DashboardDataFetcher;
import de.sovity.edc.ext.wrapper.api.ui.pages.dashboard.services.MiwConfigService;
import de.sovity.edc.ext.wrapper.api.ui.pages.dashboard.services.OwnConnectorEndpointServiceImpl;
import de.sovity.edc.ext.wrapper.api.ui.pages.dashboard.services.SelfDescriptionService;
import de.sovity.edc.ext.wrapper.api.ui.pages.policy.PolicyDefinitionApiService;
import de.sovity.edc.ext.wrapper.api.ui.pages.transferhistory.TransferHistoryPageApiService;
Expand Down Expand Up @@ -133,10 +134,11 @@ public static WrapperExtensionContext buildContext(
var assetJsonLdUtils = new AssetJsonLdUtils();
var markdownToTextConverter = new MarkdownToTextConverter();
var textUtils = new TextUtils();
var uiAssetMapper = new UiAssetMapper(edcPropertyUtils, assetJsonLdUtils, markdownToTextConverter, textUtils);
var selfDescriptionService = new SelfDescriptionService(config, monitor);
var ownConnectorEndpointService = new OwnConnectorEndpointServiceImpl(selfDescriptionService);
var uiAssetMapper = new UiAssetMapper(edcPropertyUtils, assetJsonLdUtils, markdownToTextConverter, textUtils, ownConnectorEndpointService);
var assetMapper = new AssetMapper(typeTransformerRegistry, uiAssetMapper, jsonLd);
var transferProcessStateService = new TransferProcessStateService();
var selfDescriptionService = new SelfDescriptionService(config, monitor);
var contractNegotiationUtils = new ContractNegotiationUtils(
contractNegotiationService,
selfDescriptionService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package de.sovity.edc.ext.wrapper.api.ui.pages.dashboard;

import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementDirection;
import de.sovity.edc.ext.wrapper.api.ui.model.DashboardPage;
import de.sovity.edc.ext.wrapper.api.ui.model.DashboardTransferAmounts;
import de.sovity.edc.ext.wrapper.api.ui.pages.dashboard.services.DapsConfigService;
Expand All @@ -31,8 +30,6 @@
import java.util.List;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static de.sovity.edc.ext.wrapper.api.ui.model.TransferProcessSimplifiedState.ERROR;
import static de.sovity.edc.ext.wrapper.api.ui.model.TransferProcessSimplifiedState.OK;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2022 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.wrapper.api.ui.pages.dashboard.services;

import de.sovity.edc.ext.wrapper.api.common.mappers.utils.OwnConnectorEndpointService;
import lombok.RequiredArgsConstructor;

@RequiredArgsConstructor
public class OwnConnectorEndpointServiceImpl implements OwnConnectorEndpointService {
private final SelfDescriptionService selfDescriptionService;

@Override
public boolean isOwnConnectorEndpoint(String endpoint) {
return selfDescriptionService.getConnectorEndpoint().equals(endpoint);
}
}

0 comments on commit 45d1524

Please sign in to comment.