From 82dc775234dcd6a7ae8c3a6f3de241ce1baba679 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Tue, 5 Sep 2023 15:41:41 +0200 Subject: [PATCH 01/37] chore: Refactoring of Asset Dto --- .../common/model/UiAssetCreateRequest.java | 40 +++++++++++++ .../wrapper/api/common/model/UiAssetDto.java | 44 ++++++++++++++ .../wrapper-common-mappers/build.gradle.kts | 2 + .../api/common/mappers/AssetMapper.java | 59 +++++++++++++++++++ .../WrapperExtensionContextBuilder.java | 3 +- .../edc/ext/wrapper/api/ui/UiResource.java | 3 +- .../api/ui/model/ContractAgreementCard.java | 3 +- .../api/ui/pages/asset/AssetApiService.java | 10 ++-- .../ContractAgreementPageCardBuilder.java | 11 +--- 9 files changed, 159 insertions(+), 16 deletions(-) create mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java create mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetDto.java create mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java new file mode 100644 index 000000000..822b9ad69 --- /dev/null +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java @@ -0,0 +1,40 @@ +/* + * 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.model; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +import java.util.Map; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@Schema(description = "Type-Safe OpenAPI generator friendly Asset Create DTO that supports an opinionated\"\n" + + " + \" subset of the original EDC Asset Entity.") +public class UiAssetCreateRequest { + @Schema(description = "Data Address", requiredMode = Schema.RequiredMode.REQUIRED) + private Map dataAddressProperties; + + @Schema(description = "Properties of the Data Address", requiredMode = Schema.RequiredMode.REQUIRED) + private Map properties; + + @Schema(description = "Private Asset Properties", requiredMode = Schema.RequiredMode.REQUIRED) + private Map privateProperties; +} diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetDto.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetDto.java new file mode 100644 index 000000000..eb7f744b8 --- /dev/null +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetDto.java @@ -0,0 +1,44 @@ +/* + * 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.model; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +import java.time.OffsetDateTime; +import java.util.Map; + +@Getter +@Setter +@ToString +@AllArgsConstructor +@Builder(toBuilder = true) +@RequiredArgsConstructor +@Schema(description = "Asset Details") +public class UiAssetDto { + @Schema(description = "Asset JSON-LD", requiredMode = Schema.RequiredMode.REQUIRED) + private String assetJsonLd; + + @Schema(description = "a Map to capture any Additional properties", requiredMode = Schema.RequiredMode.REQUIRED) + private Map additionalProperties; + + @Schema(description = "a Map to capture any Additional JSON properties", requiredMode = Schema.RequiredMode.REQUIRED) + private Map additionalJsonProperties; +} diff --git a/extensions/wrapper/wrapper-common-mappers/build.gradle.kts b/extensions/wrapper/wrapper-common-mappers/build.gradle.kts index aeed32358..a28d4cd7a 100644 --- a/extensions/wrapper/wrapper-common-mappers/build.gradle.kts +++ b/extensions/wrapper/wrapper-common-mappers/build.gradle.kts @@ -15,6 +15,8 @@ dependencies { compileOnly("org.projectlombok:lombok:${lombokVersion}") api("${edcGroup}:policy-model:${edcVersion}") + api("${edcGroup}:core-spi:${edcVersion}") + api(project(":extensions:wrapper:wrapper")) api(project(":extensions:wrapper:wrapper-common-api")) implementation("org.apache.commons:commons-lang3:3.13.0") diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java new file mode 100644 index 000000000..46c4e86d0 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java @@ -0,0 +1,59 @@ +package de.sovity.edc.ext.wrapper.api.common.mappers; + +import com.fasterxml.jackson.databind.ObjectMapper; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.MappingErrors; +import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; +import de.sovity.edc.ext.wrapper.api.common.model.UiAssetDto; +import de.sovity.edc.ext.wrapper.utils.EdcPropertyUtils; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import org.eclipse.edc.spi.types.domain.asset.Asset; + +@RequiredArgsConstructor +public class AssetMapper { + /** + * This Object Mapper must be able to handle JSON-LD serialization / deserialization. + */ + private final EdcPropertyUtils edcPropertyUtils; + private final ObjectMapper jsonLdObjectMapper; + + + /** + * Builds a simplified UI Asset Model from a JSON-LD Asset. + *

+ * This operation is lossy. + * + * @param asset Asset in JSON-LD format + * @return ui asset + */ + @SneakyThrows + public UiAssetDto buildAssetDto(Asset asset) { + MappingErrors errors = MappingErrors.root(); + return UiAssetDto.builder() + .assetJsonLd(jsonLdObjectMapper.writeValueAsString(asset)) + .build(); + } + + /** + * Builds a JSON-LD Asset from our simplified UI Asset Model. + *

+ * This operation is lossless. + * + * @param assetCreateDto UI asset create request + * @return Asset in JSON-LD format + */ + @SneakyThrows + public Asset buildAsset(UiAssetCreateRequest assetCreateDto) { + + + var assetProperties = edcPropertyUtils.toMapOfObject(assetCreateDto.getProperties()); + var privateProperties = edcPropertyUtils.toMapOfObject(assetCreateDto.getPrivateProperties()); + + return Asset.Builder.newInstance() + .id(assetCreateDto.getProperties().get(Asset.PROPERTY_ID)) + .properties(assetProperties) + .privateProperties(privateProperties) + .dataAddress(edcPropertyUtils.buildDataAddress(assetCreateDto.getDataAddressProperties())) + .build(); + } +} diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java index d935accd7..cd7d1d1bf 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java @@ -15,6 +15,7 @@ package de.sovity.edc.ext.wrapper; import com.fasterxml.jackson.databind.ObjectMapper; +import de.sovity.edc.ext.wrapper.api.common.mappers.AssetMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.OperatorMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.PolicyMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.AtomicConstraintMapper; @@ -134,7 +135,7 @@ public static WrapperExtensionContext buildContext( var contractNegotiationUtils = new ContractNegotiationUtils(contractNegotiationService); var contractAgreementUtils = new ContractAgreementUtils(contractAgreementService); var edcPropertyUtils = new EdcPropertyUtils(); - var assetBuilder = new AssetBuilder(edcPropertyUtils); + var assetBuilder = new AssetMapper(edcPropertyUtils, objectMapper); var assetApiService = new AssetApiService(assetBuilder, assetService, edcPropertyUtils); var transferRequestBuilder = new TransferRequestBuilder( objectMapper, diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java index 622010318..87956d2d7 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java @@ -16,6 +16,7 @@ import de.sovity.edc.ext.wrapper.api.common.model.AssetDto; import de.sovity.edc.ext.wrapper.api.common.model.PolicyDefinitionCreateRequest; +import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import de.sovity.edc.ext.wrapper.api.ui.model.AssetPage; import de.sovity.edc.ext.wrapper.api.ui.model.AssetCreateRequest; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementPage; @@ -106,7 +107,7 @@ public AssetPage assetPage() { @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Operation(description = "Create a new Asset") - public IdResponseDto createAsset(AssetCreateRequest assetCreateRequest) { + public IdResponseDto createAsset(UiAssetCreateRequest assetCreateRequest) { return assetApiService.createAsset(assetCreateRequest); } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java index 4e8464185..8a5433ea6 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java @@ -15,6 +15,7 @@ package de.sovity.edc.ext.wrapper.api.ui.model; import de.sovity.edc.ext.wrapper.api.common.model.AssetDto; +import de.sovity.edc.ext.wrapper.api.common.model.UiAssetDto; import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyDto; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; @@ -58,7 +59,7 @@ public class ContractAgreementCard { private OffsetDateTime contractEndDate; @Schema(description = "Asset details", requiredMode = Schema.RequiredMode.REQUIRED) - private AssetDto asset; + private UiAssetDto asset; @Schema(description = "Contract Policy", requiredMode = Schema.RequiredMode.REQUIRED) private UiPolicyDto contractPolicy; diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java index 6d8dd9242..1324ae655 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java @@ -14,10 +14,10 @@ package de.sovity.edc.ext.wrapper.api.ui.pages.asset; -import de.sovity.edc.ext.wrapper.api.ui.model.AssetCreateRequest; +import de.sovity.edc.ext.wrapper.api.common.mappers.AssetMapper; +import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import de.sovity.edc.ext.wrapper.api.ui.model.AssetEntry; import de.sovity.edc.ext.wrapper.api.ui.model.IdResponseDto; -import de.sovity.edc.ext.wrapper.api.ui.pages.asset.services.AssetBuilder; import de.sovity.edc.ext.wrapper.utils.EdcPropertyUtils; import lombok.RequiredArgsConstructor; import org.eclipse.edc.connector.spi.asset.AssetService; @@ -30,7 +30,7 @@ @RequiredArgsConstructor public class AssetApiService { - private final AssetBuilder assetBuilder; + private final AssetMapper assetMapper; private final AssetService assetService; private final EdcPropertyUtils edcPropertyUtils; @@ -45,8 +45,8 @@ public List getAssets() { } @NotNull - public IdResponseDto createAsset(AssetCreateRequest request) { - var asset = assetBuilder.buildAsset(request); + public IdResponseDto createAsset(UiAssetCreateRequest request) { + var asset = assetMapper.buildAsset(request); asset = assetService.create(asset).getContent(); return new IdResponseDto(asset.getId()); } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/ContractAgreementPageCardBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/ContractAgreementPageCardBuilder.java index f3cd4c075..2cdb7f4d1 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/ContractAgreementPageCardBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/ContractAgreementPageCardBuilder.java @@ -20,6 +20,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; +import de.sovity.edc.ext.wrapper.api.common.mappers.AssetMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.PolicyMapper; import de.sovity.edc.ext.wrapper.api.common.model.AssetDto; import de.sovity.edc.ext.wrapper.api.common.model.PolicyDto; @@ -44,6 +45,7 @@ @RequiredArgsConstructor public class ContractAgreementPageCardBuilder { private final PolicyMapper policyMapper; + private final AssetMapper assetMapper; private final TransferProcessStateService transferProcessStateService; @NotNull @@ -60,7 +62,7 @@ public ContractAgreementCard buildContractAgreementCard( card.setCounterPartyAddress(negotiation.getCounterPartyAddress()); card.setCounterPartyId(negotiation.getCounterPartyId()); card.setContractSigningDate(utcSecondsToOffsetDateTime(agreement.getContractSigningDate())); - card.setAsset(buildAssetDto(asset)); + card.setAsset(assetMapper.buildAssetDto(asset)); card.setContractPolicy(policyMapper.buildPolicyDto(agreement.getPolicy())); card.setTransferProcesses(buildTransferProcesses(transferProcesses)); return card; @@ -89,11 +91,4 @@ private ContractAgreementTransferProcess buildContractAgreementTransfer( transferProcess.setErrorMessage(transferProcessEntity.getErrorDetail()); return transferProcess; } - - @NotNull - private AssetDto buildAssetDto(@NonNull Asset asset) { - var createdAt = utcMillisToOffsetDateTime(asset.getCreatedAt()); - var properties = mapValues(asset.getProperties(), Object::toString); - return new AssetDto(asset.getId(), createdAt, properties); - } } From fe98859f89c49d5b00351559dc508fd1df6e5907 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Fri, 8 Sep 2023 11:50:47 +0200 Subject: [PATCH 02/37] chore: Asset Deserializer --- .../api/common/model/UiAssetCreator.java | 29 +++++ .../api/common/model/UiAssetDistribution.java | 29 +++++ .../api/common/model/UiAssetHelperDto.java | 96 ++++++++++++++++ .../api/common/model/UiAssetPublisher.java | 29 +++++ .../model/utils/CustomDeserializer.java | 103 ++++++++++++++++++ .../api/common/mappers/AssetMapper.java | 68 +++++------- .../common/mappers/utils/UiAssetCreator.java | 29 +++++ .../mappers/utils/UiAssetDistribution.java | 29 +++++ .../mappers/utils/UiAssetHelperDto.java | 95 ++++++++++++++++ .../mappers/utils/UiAssetPublisher.java | 29 +++++ .../api/common/mappers/AssetMapperTest.java | 46 ++++++++ 11 files changed, 543 insertions(+), 39 deletions(-) create mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreator.java create mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetDistribution.java create mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetHelperDto.java create mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetPublisher.java create mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java create mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetCreator.java create mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetDistribution.java create mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetHelperDto.java create mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetPublisher.java create mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreator.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreator.java new file mode 100644 index 000000000..45fbd7be6 --- /dev/null +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreator.java @@ -0,0 +1,29 @@ +package de.sovity.edc.ext.wrapper.api.common.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; + + +@Getter +@Setter +@ToString +@AllArgsConstructor +@Builder(toBuilder = true) +@RequiredArgsConstructor +@Schema(description = "Asset Creator Details") +public class UiAssetCreator { + + @JsonProperty("@type") + @Schema(description = "Type", requiredMode = Schema.RequiredMode.REQUIRED) + private String type; + + @JsonProperty("http://xmlns.com/foaf/0.1/name") + @Schema(description = "Name", requiredMode = Schema.RequiredMode.REQUIRED) + private String name; +} diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetDistribution.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetDistribution.java new file mode 100644 index 000000000..f59a0d42e --- /dev/null +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetDistribution.java @@ -0,0 +1,29 @@ +package de.sovity.edc.ext.wrapper.api.common.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; + + +@Getter +@Setter +@ToString +@AllArgsConstructor +@Builder(toBuilder = true) +@RequiredArgsConstructor +@Schema(description = "Asset Distribution Details") +public class UiAssetDistribution { + + @JsonProperty("@type") + @Schema(description = "Type", requiredMode = Schema.RequiredMode.REQUIRED) + private String type; + + @JsonProperty("http://www.w3.org/ns/dcat#mediaType") + @Schema(description = "Media Type", requiredMode = Schema.RequiredMode.REQUIRED) + private String name; +} diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetHelperDto.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetHelperDto.java new file mode 100644 index 000000000..535a3521e --- /dev/null +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetHelperDto.java @@ -0,0 +1,96 @@ +package de.sovity.edc.ext.wrapper.api.common.model; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import de.sovity.edc.ext.wrapper.api.common.model.utils.CustomDeserializer; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +import java.util.List; + + +@Getter +@Setter +@ToString +@AllArgsConstructor +@Builder(toBuilder = true) +@RequiredArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class UiAssetHelperDto { + + @JsonProperty("https://w3id.org/edc/v0.0.1/ns/") + private String ns; + + @JsonProperty("http://purl.org/dc/terms/identifier") + private String identifier; + + @JsonProperty("http://purl.org/dc/terms/title") + @JsonDeserialize(using = CustomDeserializer.class) + private String title; + + @JsonProperty("http://purl.org/dc/terms/language") + private String language; + + @JsonProperty("http://purl.org/dc/terms/description") + private String description; + + @JsonProperty("http://purl.org/dc/terms/creator") + private UiAssetCreator creator; + + @JsonProperty("http://purl.org/dc/terms/publisher") + private UiAssetPublisher publisher; + + @JsonProperty("http://purl.org/dc/terms/license") + private String license; + + @JsonProperty("http://www.w3.org/ns/dcat#version") + private String version; + + @JsonProperty("http://www.w3.org/ns/dcat#keyword") + @JsonDeserialize(using = CustomDeserializer.class) + private List keywords; + + @JsonProperty("http://www.w3.org/ns/dcat#distribution") + private UiAssetDistribution distribution; + + @JsonProperty("http://www.w3.org/ns/dcat#landingPage") + private String landingPage; + + @JsonProperty("https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyMethod") + @JsonDeserialize(using = CustomDeserializer.class) + private Boolean httpDatasourceHintsProxyMethod; + + @JsonProperty("https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyPath") + @JsonDeserialize(using = CustomDeserializer.class) + private Boolean httpDatasourceHintsProxyPath; + + @JsonProperty("https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyQueryParams") + @JsonDeserialize(using = CustomDeserializer.class) + private Boolean httpDatasourceHintsProxyQueryParams; + + @JsonProperty("https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyBody") + @JsonDeserialize(using = CustomDeserializer.class) + private Boolean httpDatasourceHintsProxyBody; + + @JsonProperty("http://w3id.org/mds#dataCategory") + private String dataCategory; + + @JsonProperty("http://w3id.org/mds#dataSubcategory") + private String dataSubcategory; + + @JsonProperty("http://w3id.org/mds#dataModel") + private String dataModel; + + @JsonProperty("http://w3id.org/mds#geoReferenceMethod") + private String geoReferenceMethod; + + @JsonProperty("http://w3id.org/mds#transportMode") + private String transportMode; +} + diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetPublisher.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetPublisher.java new file mode 100644 index 000000000..56f0bb633 --- /dev/null +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetPublisher.java @@ -0,0 +1,29 @@ +package de.sovity.edc.ext.wrapper.api.common.model; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; + + +@Getter +@Setter +@ToString +@AllArgsConstructor +@Builder(toBuilder = true) +@RequiredArgsConstructor +@Schema(description = "Asset Publisher Details") +public class UiAssetPublisher { + + @JsonProperty("@type") + @Schema(description = "Type", requiredMode = Schema.RequiredMode.REQUIRED) + private String type; + + @JsonProperty("http://xmlns.com/foaf/0.1/homepage") + @Schema(description = "Homepage URL", requiredMode = Schema.RequiredMode.REQUIRED) + private String name; +} diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java new file mode 100644 index 000000000..e2798f34f --- /dev/null +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java @@ -0,0 +1,103 @@ +package de.sovity.edc.ext.wrapper.api.common.model.utils; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.BeanProperty; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JavaType; +import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.JsonMappingException; +import com.fasterxml.jackson.databind.deser.ContextualDeserializer; +import lombok.SneakyThrows; + +import java.util.Collections; +import java.util.LinkedHashMap; +import java.util.List; + +public class CustomDeserializer extends JsonDeserializer implements ContextualDeserializer { + + private JavaType type; + + public CustomDeserializer() { + } + + public CustomDeserializer(JavaType type) { + this.type = type; + } + + @Override + public JsonDeserializer createContextual(DeserializationContext deserializationContext, BeanProperty beanProperty) throws JsonMappingException { + //beanProperty is null when the type to deserialize is the top-level type or a generic type, not a type of a bean property + JavaType type = deserializationContext.getContextualType() != null + ? deserializationContext.getContextualType() + : beanProperty.getMember().getType(); + return new CustomDeserializer(type); + } + + @SneakyThrows + @Override + public Object deserialize(JsonParser p, DeserializationContext deserializationContext) { + if (type.isTypeOrSubTypeOf(String.class)) { + return parseString(p); + } else if (type.isTypeOrSubTypeOf(Boolean.class)) { + return parseBoolean(p); + } else if (type.isTypeOrSubTypeOf(List.class)) { + return parseList(p); + } + return p.readValueAs(Object.class); + } + + @SneakyThrows + private String parseString(JsonParser p) { + if (p.isExpectedStartArrayToken()) { + return getFirstValueFromList(p.readValueAs(List.class)); + } else if (p.isExpectedStartObjectToken()) { + return extractValueFromMap(p.readValueAs(LinkedHashMap.class)); + } + return p.getText(); + } + + @SneakyThrows + private Boolean parseBoolean(JsonParser p) { + String valueAsString = p.isExpectedStartArrayToken() ? getFirstValueFromList(p.readValueAs(List.class)) : p.getText(); + if ("true".equalsIgnoreCase(valueAsString)) { + return true; + } else if ("false".equalsIgnoreCase(valueAsString)) { + return false; + } + return null; + } + + @SneakyThrows + private List parseList(JsonParser p) { + if (p.isExpectedStartArrayToken()) { + return p.readValueAs(List.class); + } + return Collections.singletonList(p.getText()); + } + + private String getFirstValueFromList(List list) { + if (list.isEmpty()) { + return null; + } + Object firstItem = list.get(0); + if (firstItem instanceof List) { + return getFirstValueFromList((List) firstItem); + } else if (firstItem instanceof LinkedHashMap) { + return extractValueFromMap((LinkedHashMap) firstItem); + } + return firstItem.toString(); + } + + @SneakyThrows + private String extractValueFromMap(LinkedHashMap map) { + Object valueObject = map.get("@value"); + + if (valueObject instanceof List) { + return getFirstValueFromList((List) valueObject); + } else if (valueObject instanceof LinkedHashMap) { + return extractValueFromMap((LinkedHashMap) valueObject); + } + + return valueObject.toString(); + } +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java index 46c4e86d0..6995df11b 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java @@ -1,59 +1,49 @@ package de.sovity.edc.ext.wrapper.api.common.mappers; import com.fasterxml.jackson.databind.ObjectMapper; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.MappingErrors; -import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; -import de.sovity.edc.ext.wrapper.api.common.model.UiAssetDto; -import de.sovity.edc.ext.wrapper.utils.EdcPropertyUtils; +import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; +import de.sovity.edc.ext.wrapper.api.common.model.UiAssetHelperDto; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; -import org.eclipse.edc.spi.types.domain.asset.Asset; + @RequiredArgsConstructor public class AssetMapper { /** * This Object Mapper must be able to handle JSON-LD serialization / deserialization. */ - private final EdcPropertyUtils edcPropertyUtils; private final ObjectMapper jsonLdObjectMapper; - /** - * Builds a simplified UI Asset Model from a JSON-LD Asset. - *

- * This operation is lossy. - * - * @param asset Asset in JSON-LD format - * @return ui asset - */ - @SneakyThrows - public UiAssetDto buildAssetDto(Asset asset) { - MappingErrors errors = MappingErrors.root(); - return UiAssetDto.builder() - .assetJsonLd(jsonLdObjectMapper.writeValueAsString(asset)) + public UiAsset buildUiAsset(UiAssetHelperDto uiAssetHelperDto) { + + return UiAsset.builder() + .name(uiAssetHelperDto.getNs()) + .keywords(uiAssetHelperDto.getKeywords()) + .version(uiAssetHelperDto.getVersion()) + .license(uiAssetHelperDto.getLicense()) + .publisher(uiAssetHelperDto.getPublisher().getName()) + .creator(uiAssetHelperDto.getCreator().getName()) + .description(uiAssetHelperDto.getDescription()) + .language(uiAssetHelperDto.getLanguage()) + .title(uiAssetHelperDto.getTitle()) + .httpDatasourceHintsProxyMethod(uiAssetHelperDto.getHttpDatasourceHintsProxyMethod()) + .httpDatasourceHintsProxyPath(uiAssetHelperDto.getHttpDatasourceHintsProxyPath()) + .httpDatasourceHintsProxyQueryParams(uiAssetHelperDto.getHttpDatasourceHintsProxyQueryParams()) + .httpDatasourceHintsProxyBody(uiAssetHelperDto.getHttpDatasourceHintsProxyBody()) + .dataCategory(uiAssetHelperDto.getDataCategory()) + .dataSubcategory(uiAssetHelperDto.getDataSubcategory()) + .dataModel(uiAssetHelperDto.getDataModel()) + .geoReferenceMethod(uiAssetHelperDto.getGeoReferenceMethod()) + .transportMode(uiAssetHelperDto.getTransportMode()) + .landingPage(uiAssetHelperDto.getLandingPage()) + .distribution(uiAssetHelperDto.getDistribution().getName()) .build(); } - /** - * Builds a JSON-LD Asset from our simplified UI Asset Model. - *

- * This operation is lossless. - * - * @param assetCreateDto UI asset create request - * @return Asset in JSON-LD format - */ @SneakyThrows - public Asset buildAsset(UiAssetCreateRequest assetCreateDto) { - - - var assetProperties = edcPropertyUtils.toMapOfObject(assetCreateDto.getProperties()); - var privateProperties = edcPropertyUtils.toMapOfObject(assetCreateDto.getPrivateProperties()); - - return Asset.Builder.newInstance() - .id(assetCreateDto.getProperties().get(Asset.PROPERTY_ID)) - .properties(assetProperties) - .privateProperties(privateProperties) - .dataAddress(edcPropertyUtils.buildDataAddress(assetCreateDto.getDataAddressProperties())) - .build(); + public UiAssetHelperDto buildHelperDto(String assetJsonLd) { + ObjectMapper mapper = new ObjectMapper(); + return mapper.readValue(assetJsonLd, UiAssetHelperDto.class); } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetCreator.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetCreator.java new file mode 100644 index 000000000..a9f185d86 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetCreator.java @@ -0,0 +1,29 @@ +package de.sovity.edc.ext.wrapper.api.common.mappers.utils; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; + + +@Getter +@Setter +@ToString +@AllArgsConstructor +@Builder(toBuilder = true) +@RequiredArgsConstructor +@Schema(description = "Asset Creator Details") +public class UiAssetCreator { + + @JsonProperty("@type") + @Schema(description = "Type", requiredMode = Schema.RequiredMode.REQUIRED) + private String type; + + @JsonProperty("http://xmlns.com/foaf/0.1/name") + @Schema(description = "Name", requiredMode = Schema.RequiredMode.REQUIRED) + private String name; +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetDistribution.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetDistribution.java new file mode 100644 index 000000000..6f4c31fa8 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetDistribution.java @@ -0,0 +1,29 @@ +package de.sovity.edc.ext.wrapper.api.common.mappers.utils; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; + + +@Getter +@Setter +@ToString +@AllArgsConstructor +@Builder(toBuilder = true) +@RequiredArgsConstructor +@Schema(description = "Asset Distribution Details") +public class UiAssetDistribution { + + @JsonProperty("@type") + @Schema(description = "Type", requiredMode = Schema.RequiredMode.REQUIRED) + private String type; + + @JsonProperty("http://www.w3.org/ns/dcat#mediaType") + @Schema(description = "Media Type", requiredMode = Schema.RequiredMode.REQUIRED) + private String name; +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetHelperDto.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetHelperDto.java new file mode 100644 index 000000000..392421187 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetHelperDto.java @@ -0,0 +1,95 @@ +package de.sovity.edc.ext.wrapper.api.common.mappers.utils; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import de.sovity.edc.ext.wrapper.api.common.model.utils.CustomDeserializer; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +import java.util.List; + + +@Getter +@Setter +@ToString +@AllArgsConstructor +@Builder(toBuilder = true) +@RequiredArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class UiAssetHelperDto { + + @JsonProperty("https://w3id.org/edc/v0.0.1/ns/") + private String ns; + + @JsonProperty("http://purl.org/dc/terms/identifier") + private String identifier; + + @JsonProperty("http://purl.org/dc/terms/title") + @JsonDeserialize(using = CustomDeserializer.class) + private String title; + + @JsonProperty("http://purl.org/dc/terms/language") + private String language; + + @JsonProperty("http://purl.org/dc/terms/description") + private String description; + + @JsonProperty("http://purl.org/dc/terms/creator") + private UiAssetCreator creator; + + @JsonProperty("http://purl.org/dc/terms/publisher") + private UiAssetPublisher publisher; + + @JsonProperty("http://purl.org/dc/terms/license") + private String license; + + @JsonProperty("http://www.w3.org/ns/dcat#version") + private String version; + + @JsonProperty("http://www.w3.org/ns/dcat#keyword") + @JsonDeserialize(using = CustomDeserializer.class) + private List keywords; + + @JsonProperty("http://www.w3.org/ns/dcat#distribution") + private UiAssetDistribution distribution; + + @JsonProperty("http://www.w3.org/ns/dcat#landingPage") + private String landingPage; + + @JsonProperty("https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyMethod") + @JsonDeserialize(using = CustomDeserializer.class) + private Boolean httpDatasourceHintsProxyMethod; + + @JsonProperty("https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyPath") + @JsonDeserialize(using = CustomDeserializer.class) + private Boolean httpDatasourceHintsProxyPath; + + @JsonProperty("https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyQueryParams") + @JsonDeserialize(using = CustomDeserializer.class) + private Boolean httpDatasourceHintsProxyQueryParams; + + @JsonProperty("https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyBody") + @JsonDeserialize(using = CustomDeserializer.class) + private Boolean httpDatasourceHintsProxyBody; + + @JsonProperty("http://w3id.org/mds#dataCategory") + private String dataCategory; + + @JsonProperty("http://w3id.org/mds#dataSubcategory") + private String dataSubcategory; + + @JsonProperty("http://w3id.org/mds#dataModel") + private String dataModel; + + @JsonProperty("http://w3id.org/mds#geoReferenceMethod") + private String geoReferenceMethod; + + @JsonProperty("http://w3id.org/mds#transportMode") + private String transportMode; +} + diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetPublisher.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetPublisher.java new file mode 100644 index 000000000..f8e65edfa --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetPublisher.java @@ -0,0 +1,29 @@ +package de.sovity.edc.ext.wrapper.api.common.mappers.utils; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; + + +@Getter +@Setter +@ToString +@AllArgsConstructor +@Builder(toBuilder = true) +@RequiredArgsConstructor +@Schema(description = "Asset Publisher Details") +public class UiAssetPublisher { + + @JsonProperty("@type") + @Schema(description = "Type", requiredMode = Schema.RequiredMode.REQUIRED) + private String type; + + @JsonProperty("http://xmlns.com/foaf/0.1/homepage") + @Schema(description = "Homepage URL", requiredMode = Schema.RequiredMode.REQUIRED) + private String name; +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java new file mode 100644 index 000000000..bc523f43a --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java @@ -0,0 +1,46 @@ +package de.sovity.edc.ext.wrapper.api.common.mappers; + +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.SneakyThrows; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import java.nio.file.Files; +import java.nio.file.Paths; + +import static org.assertj.core.api.Assertions.assertThat; + +@ExtendWith(MockitoExtension.class) +class AssetMapperTest { + @Mock + ObjectMapper jsonLdObjectMapper; + + @InjectMocks + AssetMapper assetMapper; + + @Test + @SneakyThrows + void test_buildAssetDto() { + // Arrange + String jsonContent = new String(Files.readAllBytes(Paths.get(getClass().getResource("/sample.json").toURI()))); + + // Act + var uiAsset = assetMapper.buildUiAsset(assetMapper.buildHelperDto(jsonContent)); + + // Assert + assertThat(uiAsset).isNotNull(); + assertThat(uiAsset.getName()).isEqualTo("urn:artifact:my-asset"); + assertThat(uiAsset.getTitle()).isEqualTo("AssetName"); + + // Convert the UiAsset to a JSON string + ObjectMapper objectMapper = new ObjectMapper(); + String resultJson = objectMapper.writer().withDefaultPrettyPrinter().writeValueAsString(uiAsset); + + // Write the result to an external file + Files.write(Paths.get("result.json"), resultJson.getBytes()); + } +} + From 87e76925236615db75ea4935f6f968628f011e64 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Tue, 12 Sep 2023 08:35:46 +0200 Subject: [PATCH 03/37] chore: Asset Deserializer + Asset Mapper Test + Test Cases --- .../edc/client/AssetApiServiceTest.java | 4 +- .../wrapper-common-api/build.gradle.kts | 1 + .../ext/wrapper/api/common/model/UiAsset.java | 108 ++++++++++++++++++ .../wrapper/api/common/model/UiAssetDto.java | 44 ------- .../model/utils/CustomDeserializer.java | 2 +- .../wrapper-common-mappers/build.gradle.kts | 6 +- .../api/common/mappers/AssetMapperTest.java | 82 ++++++++++++- .../api/common/mappers/utils/JsonLdUtils.java | 68 +++++++++++ .../src/test/resources/BadBooleanValue.json | 38 ++++++ .../src/test/resources/KeywordCase.json | 38 ++++++ .../src/test/resources/NoBooleanValue.json | 37 ++++++ .../src/test/resources/StringAsList.json | 47 ++++++++ .../src/test/resources/StringAsMap.json | 41 +++++++ .../src/test/resources/sample.json | 38 ++++++ .../WrapperExtensionContextBuilder.java | 2 +- .../edc/ext/wrapper/api/ui/UiResource.java | 2 +- .../ext/wrapper/api/ui/model/AssetPage.java | 3 +- .../api/ui/model/ContractAgreementCard.java | 4 +- .../wrapper/api/ui/model/IdResponseDto.java | 6 +- .../api/ui/pages/asset/AssetApiService.java | 18 ++- .../ContractAgreementPageCardBuilder.java | 30 ++--- 21 files changed, 540 insertions(+), 79 deletions(-) create mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java delete mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetDto.java create mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonLdUtils.java create mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/resources/BadBooleanValue.json create mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/resources/KeywordCase.json create mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/resources/NoBooleanValue.json create mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/resources/StringAsList.json create mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/resources/StringAsMap.json create mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/resources/sample.json diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java index b7bac21dc..7f95c7e81 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java @@ -65,7 +65,7 @@ void assetPage(AssetService assetStore) { var assets = result.getAssets(); assertThat(assets).hasSize(1); var asset = assets.get(0); - assertThat(asset.getProperties()).isEqualTo(properties); + assertThat(asset.getAdditionalProperties()).isEqualTo(properties); assertThat(asset.getPrivateProperties()).isEqualTo(privateProperties); } @@ -83,7 +83,7 @@ void assetPageSorting(AssetService assetService) { // assert assertThat(result.getAssets()) - .extracting(asset -> asset.getProperties().get(Asset.PROPERTY_ID)) + .extracting(asset -> asset.getAdditionalProperties().get(Asset.PROPERTY_ID)) .containsExactly("asset-3", "asset-2", "asset-1"); } diff --git a/extensions/wrapper/wrapper-common-api/build.gradle.kts b/extensions/wrapper/wrapper-common-api/build.gradle.kts index b4856c153..56708d23b 100644 --- a/extensions/wrapper/wrapper-common-api/build.gradle.kts +++ b/extensions/wrapper/wrapper-common-api/build.gradle.kts @@ -9,6 +9,7 @@ dependencies { annotationProcessor("org.projectlombok:lombok:${lombokVersion}") compileOnly("org.projectlombok:lombok:${lombokVersion}") + api("jakarta.ws.rs:jakarta.ws.rs-api:3.1.0") api("jakarta.validation:jakarta.validation-api:3.0.2") api("io.swagger.core.v3:swagger-annotations-jakarta:2.2.15") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java new file mode 100644 index 000000000..76bcd623c --- /dev/null +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java @@ -0,0 +1,108 @@ +/* + * 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.model; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; + +import java.util.List; +import java.util.Map; + +@Getter +@Setter +@ToString +@AllArgsConstructor +@Builder(toBuilder = true) +@RequiredArgsConstructor +@Schema(description = "Asset Details") +public class UiAsset { + + @Schema(description = "Asset Name", requiredMode = Schema.RequiredMode.REQUIRED) + private String name; + + @Schema(description = "Asset Title", requiredMode = Schema.RequiredMode.REQUIRED) + private String title; + + @Schema(description = "Asset Language", requiredMode = Schema.RequiredMode.REQUIRED) + private String language; + + @Schema(description = "Asset Description", requiredMode = Schema.RequiredMode.REQUIRED) + private String description; + + @Schema(description = "Asset Creator", requiredMode = Schema.RequiredMode.REQUIRED) + private String creator; + + @Schema(description = "Asset Publisher", requiredMode = Schema.RequiredMode.REQUIRED) + private String publisher; + + @Schema(description = "License URL", requiredMode = Schema.RequiredMode.REQUIRED) + private String license; + + @Schema(description = "Version", requiredMode = Schema.RequiredMode.REQUIRED) + private String version; + + @Schema(description = "Asset Keywords", requiredMode = Schema.RequiredMode.REQUIRED) + private List keywords; + + @Schema(description = "Distribution", requiredMode = Schema.RequiredMode.REQUIRED) + private String distribution; + + @Schema(description = "Landing Page URL", requiredMode = Schema.RequiredMode.REQUIRED) + private String landingPage; + + @Schema(description = "HTTP Datasource Hints Proxy Method", requiredMode = Schema.RequiredMode.REQUIRED) + private Boolean httpDatasourceHintsProxyMethod; + + @Schema(description = "HTTP Datasource Hints Proxy Path", requiredMode = Schema.RequiredMode.REQUIRED) + private Boolean httpDatasourceHintsProxyPath; + + @Schema(description = "HTTP Datasource Hints Proxy Query Params", requiredMode = Schema.RequiredMode.REQUIRED) + private Boolean httpDatasourceHintsProxyQueryParams; + + @Schema(description = "HTTP Datasource Hints Proxy Body", requiredMode = Schema.RequiredMode.REQUIRED) + private Boolean httpDatasourceHintsProxyBody; + + @Schema(description = "Data Category", requiredMode = Schema.RequiredMode.REQUIRED) + private String dataCategory; + + @Schema(description = "Data Subcategory", requiredMode = Schema.RequiredMode.REQUIRED) + private String dataSubcategory; + + @Schema(description = "Data Model", requiredMode = Schema.RequiredMode.REQUIRED) + private String dataModel; + + @Schema(description = "Geo-Reference Method", requiredMode = Schema.RequiredMode.REQUIRED) + private String geoReferenceMethod; + + @Schema(description = "Transport Mode", requiredMode = Schema.RequiredMode.REQUIRED) + private String transportMode; + + @Schema(description = "Asset JsonLd", requiredMode = Schema.RequiredMode.REQUIRED) + private String assetJsonLd; + + @Schema(description = "Asset additional Properties", requiredMode = Schema.RequiredMode.REQUIRED) + private Map additionalProperties; + + @Schema(description = "Asset Private Properties", requiredMode = Schema.RequiredMode.REQUIRED) + private Map privateProperties; + + @Schema(description = "Asset Json Properties", requiredMode = Schema.RequiredMode.REQUIRED) + private Map additionalJsonProperties; +} diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetDto.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetDto.java deleted file mode 100644 index eb7f744b8..000000000 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetDto.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * 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.model; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -import java.time.OffsetDateTime; -import java.util.Map; - -@Getter -@Setter -@ToString -@AllArgsConstructor -@Builder(toBuilder = true) -@RequiredArgsConstructor -@Schema(description = "Asset Details") -public class UiAssetDto { - @Schema(description = "Asset JSON-LD", requiredMode = Schema.RequiredMode.REQUIRED) - private String assetJsonLd; - - @Schema(description = "a Map to capture any Additional properties", requiredMode = Schema.RequiredMode.REQUIRED) - private Map additionalProperties; - - @Schema(description = "a Map to capture any Additional JSON properties", requiredMode = Schema.RequiredMode.REQUIRED) - private Map additionalJsonProperties; -} diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java index e2798f34f..ff67b2b62 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java @@ -26,7 +26,6 @@ public CustomDeserializer(JavaType type) { @Override public JsonDeserializer createContextual(DeserializationContext deserializationContext, BeanProperty beanProperty) throws JsonMappingException { - //beanProperty is null when the type to deserialize is the top-level type or a generic type, not a type of a bean property JavaType type = deserializationContext.getContextualType() != null ? deserializationContext.getContextualType() : beanProperty.getMember().getType(); @@ -94,6 +93,7 @@ private String extractValueFromMap(LinkedHashMap map) { if (valueObject instanceof List) { return getFirstValueFromList((List) valueObject); + } else if (valueObject instanceof LinkedHashMap) { return extractValueFromMap((LinkedHashMap) valueObject); } diff --git a/extensions/wrapper/wrapper-common-mappers/build.gradle.kts b/extensions/wrapper/wrapper-common-mappers/build.gradle.kts index a28d4cd7a..3932bc968 100644 --- a/extensions/wrapper/wrapper-common-mappers/build.gradle.kts +++ b/extensions/wrapper/wrapper-common-mappers/build.gradle.kts @@ -16,11 +16,15 @@ dependencies { api("${edcGroup}:policy-model:${edcVersion}") api("${edcGroup}:core-spi:${edcVersion}") - api(project(":extensions:wrapper:wrapper")) + api("${edcGroup}:transform-core:${edcVersion}") + + api(project(":extensions:wrapper:wrapper-common-api")) implementation("org.apache.commons:commons-lang3:3.13.0") implementation("org.apache.commons:commons-collections4:4.4") + implementation("cz.cvut.kbss.jsonld:jb4jsonld-jackson:0.13.2") + testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}") testCompileOnly("org.projectlombok:lombok:${lombokVersion}") diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java index bc523f43a..94a4d7d44 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java @@ -10,17 +10,18 @@ import java.nio.file.Files; import java.nio.file.Paths; +import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class AssetMapperTest { - @Mock - ObjectMapper jsonLdObjectMapper; @InjectMocks AssetMapper assetMapper; + + //for sample and then the other edge cases @Test @SneakyThrows void test_buildAssetDto() { @@ -33,14 +34,87 @@ void test_buildAssetDto() { // Assert assertThat(uiAsset).isNotNull(); assertThat(uiAsset.getName()).isEqualTo("urn:artifact:my-asset"); - assertThat(uiAsset.getTitle()).isEqualTo("AssetName"); + assertThat(uiAsset.getTitle()).isEqualTo("My Asset"); + assertThat(uiAsset.getDescription()).isEqualTo("Lorem Ipsum ..."); + assertThat(uiAsset.getPublisher()).isEqualTo("https://data-source.my-org/about"); + assertThat(uiAsset.getCreator()).isEqualTo("My Organization Name"); + assertThat(uiAsset.getLicense()).isEqualTo("https://data-source.my-org/license"); + assertThat(uiAsset.getVersion()).isEqualTo("1.1"); + assertThat(uiAsset.getLanguage()).isEqualTo("https://w3id.org/idsa/code/EN"); + assertThat(uiAsset.getKeywords()).isEqualTo(List.of("some", "keywords")); + assertThat(uiAsset.getHttpDatasourceHintsProxyMethod()).isEqualTo(true); + assertThat(uiAsset.getHttpDatasourceHintsProxyPath()).isEqualTo(true); + assertThat(uiAsset.getDistribution()).isEqualTo("application/json"); // Convert the UiAsset to a JSON string ObjectMapper objectMapper = new ObjectMapper(); String resultJson = objectMapper.writer().withDefaultPrettyPrinter().writeValueAsString(uiAsset); - // Write the result to an external file Files.write(Paths.get("result.json"), resultJson.getBytes()); } + @Test + @SneakyThrows + void test_KeywordsAsSingleString() { + // Arrange + String jsonContent = new String(Files.readAllBytes(Paths.get(getClass().getResource("/KeywordCase.json").toURI()))); + // Act + var uiAsset = assetMapper.buildUiAsset(assetMapper.buildHelperDto(jsonContent)); + + // Assert + assertThat(uiAsset).isNotNull(); + assertThat(uiAsset.getKeywords()).isEqualTo(List.of("SingleElement")); + } + + @Test + @SneakyThrows + void test_StringsAsList() { + // Arrange + String jsonContent = new String(Files.readAllBytes(Paths.get(getClass().getResource("/StringAsList.json").toURI()))); + // Act + var uiAsset = assetMapper.buildUiAsset(assetMapper.buildHelperDto(jsonContent)); + + // Assert + assertThat(uiAsset).isNotNull(); + assertThat(uiAsset.getName()).isEqualTo("urn:artifact:my-asset"); + } + + @Test + @SneakyThrows + void test_StringsAsMap() { + // Arrange + String jsonContent = new String(Files.readAllBytes(Paths.get(getClass().getResource("/StringAsMap.json").toURI()))); + // Act + var uiAsset = assetMapper.buildUiAsset(assetMapper.buildHelperDto(jsonContent)); + + // Assert + assertThat(uiAsset).isNotNull(); + assertThat(uiAsset.getName()).isEqualTo("urn:artifact:my-asset"); + } + + @Test + @SneakyThrows + void test_badBooleanValue() { + // Arrange + String jsonContent = new String(Files.readAllBytes(Paths.get(getClass().getResource("/BadBooleanValue.json").toURI()))); + // Act + var uiAsset = assetMapper.buildUiAsset(assetMapper.buildHelperDto(jsonContent)); + + // Assert + assertThat(uiAsset).isNotNull(); + assertThat(uiAsset.getHttpDatasourceHintsProxyMethod()).isEqualTo(null); + } + + @Test + @SneakyThrows + void test_noBooleanValue() { + // Arrange + String jsonContent = new String(Files.readAllBytes(Paths.get(getClass().getResource("/NoBooleanValue.json").toURI()))); + // Act + var uiAsset = assetMapper.buildUiAsset(assetMapper.buildHelperDto(jsonContent)); + + // Assert + assertThat(uiAsset).isNotNull(); + assertThat(uiAsset.getHttpDatasourceHintsProxyMethod()).isEqualTo(null); + } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonLdUtils.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonLdUtils.java new file mode 100644 index 000000000..723583e3e --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonLdUtils.java @@ -0,0 +1,68 @@ +package de.sovity.edc.ext.wrapper.api.common.mappers.utils; + +public class JsonLdUtils { +/* + private static final ObjectMapper objectMapper = new ObjectMapper(); + + public static ValueType getValueType(String jsonLd, String propertyUri) throws Exception { + JsonNode rootNode = objectMapper.readTree(jsonLd); + JsonNode propertyNode = rootNode.get(propertyUri); + + if (propertyNode == null) { + throw new IllegalArgumentException("Property URI not found in provided JSON-LD."); + } + + if (propertyNode.isTextual()) { + return ValueType.STRING; + } + + if (propertyNode.isArray()) { + for (JsonNode node : propertyNode) { + if (!node.isTextual()) { + return ValueType.OTHER; + } + } + return ValueType.ARRAY_OF_STRINGS; + } + + return ValueType.OTHER; + } + + public enum ValueType { + STRING, + ARRAY_OF_STRINGS, + OTHER + } + + public Map inspectPropertyTypes() { + Map propertyTypes = new HashMap<>(); + + for (Field field : UiAssetHelperDto.class.getDeclaredFields()) { + JsonProperty jsonProperty = field.getAnnotation(JsonProperty.class); + if (jsonProperty != null) { + String uri = jsonProperty.value(); + ValueType valueType = determineValueType(field.getType()); + propertyTypes.put(uri, valueType); + } + } + + return propertyTypes; + } + + private ValueType determineValueType(Class type) { + if (type.equals(String.class)) { + return ValueType.STRING; + } else if (type.equals(List.class)) { + return ValueType.ARRAY_OF_STRINGS; + } else { + return ValueType.OTHER; + } + } + + public enum ValueType { + STRING, + ARRAY_OF_STRINGS, + OTHER + }*/ + +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/resources/BadBooleanValue.json b/extensions/wrapper/wrapper-common-mappers/src/test/resources/BadBooleanValue.json new file mode 100644 index 000000000..44bf1d0f2 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/test/resources/BadBooleanValue.json @@ -0,0 +1,38 @@ +{ + "https://w3id.org/edc/v0.0.1/ns/": "urn:artifact:my-asset", + + "http://purl.org/dc/terms/identifier": "urn:artifact:my-asset", + "http://purl.org/dc/terms/title": "My Asset", + "http://purl.org/dc/terms/language": "https://w3id.org/idsa/code/EN", + "http://purl.org/dc/terms/description": "Lorem Ipsum ...", + "http://purl.org/dc/terms/creator": { + "@type": "http://xmlns.com/foaf/0.1/Organization", + "http://xmlns.com/foaf/0.1/name": "My Organization Name" + }, + "http://purl.org/dc/terms/publisher": { + "@type": "http://xmlns.com/foaf/0.1/Organization", + "http://xmlns.com/foaf/0.1/homepage": "https://data-source.my-org/about" + }, + "http://purl.org/dc/terms/license": "https://data-source.my-org/license", + + "http://www.w3.org/ns/dcat#version": "1.1", + "http://www.w3.org/ns/dcat#keyword": ["some", "keywords"], + "http://www.w3.org/ns/dcat#distribution": { + "@type": "http://www.w3.org/ns/dcat#Distribution", + "http://www.w3.org/ns/dcat#mediaType": "application/json" + }, + "http://www.w3.org/ns/dcat#landingPage": "https://data-source.my-org/docs", + + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyMethod": "idk", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyPath": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyQueryParams": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyBody": "true", + + "http://w3id.org/mds#dataCategory": "Infrastructure and Logistics", + "http://w3id.org/mds#dataSubcategory": "General Information About Planning Of Routes", + "http://w3id.org/mds#dataModel": "my-data-model-001", + "http://w3id.org/mds#geoReferenceMethod": "my-geo-reference-method", + "http://w3id.org/mds#transportMode": "my-geo-reference-method", + + "http://unknown/some-custom-property": "test" +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/resources/KeywordCase.json b/extensions/wrapper/wrapper-common-mappers/src/test/resources/KeywordCase.json new file mode 100644 index 000000000..f10f6cdc8 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/test/resources/KeywordCase.json @@ -0,0 +1,38 @@ +{ + "https://w3id.org/edc/v0.0.1/ns/": "urn:artifact:my-asset", + + "http://purl.org/dc/terms/identifier": "urn:artifact:my-asset", + "http://purl.org/dc/terms/title": "My Asset", + "http://purl.org/dc/terms/language": "https://w3id.org/idsa/code/EN", + "http://purl.org/dc/terms/description": "Lorem Ipsum ...", + "http://purl.org/dc/terms/creator": { + "@type": "http://xmlns.com/foaf/0.1/Organization", + "http://xmlns.com/foaf/0.1/name": "My Organization Name" + }, + "http://purl.org/dc/terms/publisher": { + "@type": "http://xmlns.com/foaf/0.1/Organization", + "http://xmlns.com/foaf/0.1/homepage": "https://data-source.my-org/about" + }, + "http://purl.org/dc/terms/license": "https://data-source.my-org/license", + + "http://www.w3.org/ns/dcat#version": "1.1", + "http://www.w3.org/ns/dcat#keyword": "SingleElement", + "http://www.w3.org/ns/dcat#distribution": { + "@type": "http://www.w3.org/ns/dcat#Distribution", + "http://www.w3.org/ns/dcat#mediaType": "application/json" + }, + "http://www.w3.org/ns/dcat#landingPage": "https://data-source.my-org/docs", + + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyMethod": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyPath": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyQueryParams": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyBody": "true", + + "http://w3id.org/mds#dataCategory": "Infrastructure and Logistics", + "http://w3id.org/mds#dataSubcategory": "General Information About Planning Of Routes", + "http://w3id.org/mds#dataModel": "my-data-model-001", + "http://w3id.org/mds#geoReferenceMethod": "my-geo-reference-method", + "http://w3id.org/mds#transportMode": "my-geo-reference-method", + + "http://unknown/some-custom-property": "test" +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/resources/NoBooleanValue.json b/extensions/wrapper/wrapper-common-mappers/src/test/resources/NoBooleanValue.json new file mode 100644 index 000000000..da9cae757 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/test/resources/NoBooleanValue.json @@ -0,0 +1,37 @@ +{ + "https://w3id.org/edc/v0.0.1/ns/": "urn:artifact:my-asset", + + "http://purl.org/dc/terms/identifier": "urn:artifact:my-asset", + "http://purl.org/dc/terms/title": "My Asset", + "http://purl.org/dc/terms/language": "https://w3id.org/idsa/code/EN", + "http://purl.org/dc/terms/description": "Lorem Ipsum ...", + "http://purl.org/dc/terms/creator": { + "@type": "http://xmlns.com/foaf/0.1/Organization", + "http://xmlns.com/foaf/0.1/name": "My Organization Name" + }, + "http://purl.org/dc/terms/publisher": { + "@type": "http://xmlns.com/foaf/0.1/Organization", + "http://xmlns.com/foaf/0.1/homepage": "https://data-source.my-org/about" + }, + "http://purl.org/dc/terms/license": "https://data-source.my-org/license", + + "http://www.w3.org/ns/dcat#version": "1.1", + "http://www.w3.org/ns/dcat#keyword": ["some", "keywords"], + "http://www.w3.org/ns/dcat#distribution": { + "@type": "http://www.w3.org/ns/dcat#Distribution", + "http://www.w3.org/ns/dcat#mediaType": "application/json" + }, + "http://www.w3.org/ns/dcat#landingPage": "https://data-source.my-org/docs", + + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyPath": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyQueryParams": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyBody": "true", + + "http://w3id.org/mds#dataCategory": "Infrastructure and Logistics", + "http://w3id.org/mds#dataSubcategory": "General Information About Planning Of Routes", + "http://w3id.org/mds#dataModel": "my-data-model-001", + "http://w3id.org/mds#geoReferenceMethod": "my-geo-reference-method", + "http://w3id.org/mds#transportMode": "my-geo-reference-method", + + "http://unknown/some-custom-property": "test" +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/resources/StringAsList.json b/extensions/wrapper/wrapper-common-mappers/src/test/resources/StringAsList.json new file mode 100644 index 000000000..000075de2 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/test/resources/StringAsList.json @@ -0,0 +1,47 @@ +{ + "https://w3id.org/edc/v0.0.1/ns/": "urn:artifact:my-asset", + + "http://purl.org/dc/terms/identifier": "urn:artifact:my-asset", + "http://purl.org/dc/terms/title": [ + { + "@value": "Asset Name", + "@language": "en" + }, + { + "@value": "Asset Name in French cuz why not", + "@language": "fr" + } + ], + "http://purl.org/dc/terms/language": "https://w3id.org/idsa/code/EN", + "http://purl.org/dc/terms/description": "Lorem Ipsum ...", + "http://purl.org/dc/terms/creator": { + "@type": "http://xmlns.com/foaf/0.1/Organization", + "http://xmlns.com/foaf/0.1/name": "My Organization Name" + }, + "http://purl.org/dc/terms/publisher": { + "@type": "http://xmlns.com/foaf/0.1/Organization", + "http://xmlns.com/foaf/0.1/homepage": "https://data-source.my-org/about" + }, + "http://purl.org/dc/terms/license": "https://data-source.my-org/license", + + "http://www.w3.org/ns/dcat#version": "1.1", + "http://www.w3.org/ns/dcat#keyword": ["some", "keywords"], + "http://www.w3.org/ns/dcat#distribution": { + "@type": "http://www.w3.org/ns/dcat#Distribution", + "http://www.w3.org/ns/dcat#mediaType": "application/json" + }, + "http://www.w3.org/ns/dcat#landingPage": "https://data-source.my-org/docs", + + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyMethod": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyPath": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyQueryParams": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyBody": "true", + + "http://w3id.org/mds#dataCategory": "Infrastructure and Logistics", + "http://w3id.org/mds#dataSubcategory": "General Information About Planning Of Routes", + "http://w3id.org/mds#dataModel": "my-data-model-001", + "http://w3id.org/mds#geoReferenceMethod": "my-geo-reference-method", + "http://w3id.org/mds#transportMode": "my-geo-reference-method", + + "http://unknown/some-custom-property": "test" +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/resources/StringAsMap.json b/extensions/wrapper/wrapper-common-mappers/src/test/resources/StringAsMap.json new file mode 100644 index 000000000..149220811 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/test/resources/StringAsMap.json @@ -0,0 +1,41 @@ +{ + "https://w3id.org/edc/v0.0.1/ns/": "urn:artifact:my-asset", + + "http://purl.org/dc/terms/identifier": "urn:artifact:my-asset", + "http://purl.org/dc/terms/title": { + "@type": "https://idk-some-random-spec/special-title", + "@value": "Asset Name" + }, + "http://purl.org/dc/terms/language": "https://w3id.org/idsa/code/EN", + "http://purl.org/dc/terms/description": "Lorem Ipsum ...", + "http://purl.org/dc/terms/creator": { + "@type": "http://xmlns.com/foaf/0.1/Organization", + "http://xmlns.com/foaf/0.1/name": "My Organization Name" + }, + "http://purl.org/dc/terms/publisher": { + "@type": "http://xmlns.com/foaf/0.1/Organization", + "http://xmlns.com/foaf/0.1/homepage": "https://data-source.my-org/about" + }, + "http://purl.org/dc/terms/license": "https://data-source.my-org/license", + + "http://www.w3.org/ns/dcat#version": "1.1", + "http://www.w3.org/ns/dcat#keyword": ["some", "keywords"], + "http://www.w3.org/ns/dcat#distribution": { + "@type": "http://www.w3.org/ns/dcat#Distribution", + "http://www.w3.org/ns/dcat#mediaType": "application/json" + }, + "http://www.w3.org/ns/dcat#landingPage": "https://data-source.my-org/docs", + + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyMethod": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyPath": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyQueryParams": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyBody": "true", + + "http://w3id.org/mds#dataCategory": "Infrastructure and Logistics", + "http://w3id.org/mds#dataSubcategory": "General Information About Planning Of Routes", + "http://w3id.org/mds#dataModel": "my-data-model-001", + "http://w3id.org/mds#geoReferenceMethod": "my-geo-reference-method", + "http://w3id.org/mds#transportMode": "my-geo-reference-method", + + "http://unknown/some-custom-property": "test" +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/resources/sample.json b/extensions/wrapper/wrapper-common-mappers/src/test/resources/sample.json new file mode 100644 index 000000000..74588f668 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/test/resources/sample.json @@ -0,0 +1,38 @@ +{ + "https://w3id.org/edc/v0.0.1/ns/": "urn:artifact:my-asset", + + "http://purl.org/dc/terms/identifier": "urn:artifact:my-asset", + "http://purl.org/dc/terms/title": "My Asset", + "http://purl.org/dc/terms/language": "https://w3id.org/idsa/code/EN", + "http://purl.org/dc/terms/description": "Lorem Ipsum ...", + "http://purl.org/dc/terms/creator": { + "@type": "http://xmlns.com/foaf/0.1/Organization", + "http://xmlns.com/foaf/0.1/name": "My Organization Name" + }, + "http://purl.org/dc/terms/publisher": { + "@type": "http://xmlns.com/foaf/0.1/Organization", + "http://xmlns.com/foaf/0.1/homepage": "https://data-source.my-org/about" + }, + "http://purl.org/dc/terms/license": "https://data-source.my-org/license", + + "http://www.w3.org/ns/dcat#version": "1.1", + "http://www.w3.org/ns/dcat#keyword": ["some", "keywords"], + "http://www.w3.org/ns/dcat#distribution": { + "@type": "http://www.w3.org/ns/dcat#Distribution", + "http://www.w3.org/ns/dcat#mediaType": "application/json" + }, + "http://www.w3.org/ns/dcat#landingPage": "https://data-source.my-org/docs", + + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyMethod": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyPath": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyQueryParams": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyBody": "true", + + "http://w3id.org/mds#dataCategory": "Infrastructure and Logistics", + "http://w3id.org/mds#dataSubcategory": "General Information About Planning Of Routes", + "http://w3id.org/mds#dataModel": "my-data-model-001", + "http://w3id.org/mds#geoReferenceMethod": "my-geo-reference-method", + "http://w3id.org/mds#transportMode": "my-geo-reference-method", + + "http://unknown/some-custom-property": "test" +} diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java index cd7d1d1bf..fa831dcdb 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java @@ -135,7 +135,7 @@ public static WrapperExtensionContext buildContext( var contractNegotiationUtils = new ContractNegotiationUtils(contractNegotiationService); var contractAgreementUtils = new ContractAgreementUtils(contractAgreementService); var edcPropertyUtils = new EdcPropertyUtils(); - var assetBuilder = new AssetMapper(edcPropertyUtils, objectMapper); + var assetBuilder = new AssetBuilder(edcPropertyUtils); var assetApiService = new AssetApiService(assetBuilder, assetService, edcPropertyUtils); var transferRequestBuilder = new TransferRequestBuilder( objectMapper, diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java index 87956d2d7..e1c6170ac 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java @@ -107,7 +107,7 @@ public AssetPage assetPage() { @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Operation(description = "Create a new Asset") - public IdResponseDto createAsset(UiAssetCreateRequest assetCreateRequest) { + public IdResponseDto createAsset(AssetCreateRequest assetCreateRequest) { return assetApiService.createAsset(assetCreateRequest); } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetPage.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetPage.java index 91ac2d259..bcd792e22 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetPage.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetPage.java @@ -13,6 +13,7 @@ */ package de.sovity.edc.ext.wrapper.api.ui.model; +import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Data; @@ -24,5 +25,5 @@ @Schema(description = "All data for the Asset Page") public class AssetPage { @Schema(description = "Visible Assets", requiredMode = Schema.RequiredMode.REQUIRED) - private List assets; + private List assets; } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java index 8a5433ea6..0aa2cb00a 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java @@ -15,7 +15,7 @@ package de.sovity.edc.ext.wrapper.api.ui.model; import de.sovity.edc.ext.wrapper.api.common.model.AssetDto; -import de.sovity.edc.ext.wrapper.api.common.model.UiAssetDto; +import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyDto; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; @@ -59,7 +59,7 @@ public class ContractAgreementCard { private OffsetDateTime contractEndDate; @Schema(description = "Asset details", requiredMode = Schema.RequiredMode.REQUIRED) - private UiAssetDto asset; + private AssetDto asset; @Schema(description = "Contract Policy", requiredMode = Schema.RequiredMode.REQUIRED) private UiPolicyDto contractPolicy; diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/IdResponseDto.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/IdResponseDto.java index f9716fa4c..78b1f17a0 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/IdResponseDto.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/IdResponseDto.java @@ -15,7 +15,11 @@ package de.sovity.edc.ext.wrapper.api.ui.model; import io.swagger.v3.oas.annotations.media.Schema; -import lombok.*; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; import java.time.OffsetDateTime; diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java index 1324ae655..954f0019f 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java @@ -15,9 +15,12 @@ package de.sovity.edc.ext.wrapper.api.ui.pages.asset; import de.sovity.edc.ext.wrapper.api.common.mappers.AssetMapper; +import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; +import de.sovity.edc.ext.wrapper.api.ui.model.AssetCreateRequest; import de.sovity.edc.ext.wrapper.api.ui.model.AssetEntry; import de.sovity.edc.ext.wrapper.api.ui.model.IdResponseDto; +import de.sovity.edc.ext.wrapper.api.ui.pages.asset.services.AssetBuilder; import de.sovity.edc.ext.wrapper.utils.EdcPropertyUtils; import lombok.RequiredArgsConstructor; import org.eclipse.edc.connector.spi.asset.AssetService; @@ -30,23 +33,26 @@ @RequiredArgsConstructor public class AssetApiService { - private final AssetMapper assetMapper; + private final AssetBuilder assetBuilder; private final AssetService assetService; private final EdcPropertyUtils edcPropertyUtils; - public List getAssets() { + public List getAssets() { var assets = getAllAssets(); return assets.stream().sorted(Comparator.comparing(Asset::getCreatedAt).reversed()).map(asset -> { - var entry = new AssetEntry(); - entry.setProperties(edcPropertyUtils.truncateToMapOfString(asset.getProperties())); + var entry = new UiAsset(); + entry.setAdditionalProperties(edcPropertyUtils.truncateToMapOfString(asset.getProperties())); entry.setPrivateProperties(edcPropertyUtils.truncateToMapOfString(asset.getPrivateProperties())); + entry.setDescription(asset.getDescription()); + entry.setName(asset.getName()); + entry.setVersion(asset.getVersion()); return entry; }).toList(); } @NotNull - public IdResponseDto createAsset(UiAssetCreateRequest request) { - var asset = assetMapper.buildAsset(request); + public IdResponseDto createAsset(AssetCreateRequest request) { + var asset = assetBuilder.buildAsset(request); asset = assetService.create(asset).getContent(); return new IdResponseDto(asset.getId()); } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/ContractAgreementPageCardBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/ContractAgreementPageCardBuilder.java index 2cdb7f4d1..941e7ebb3 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/ContractAgreementPageCardBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/ContractAgreementPageCardBuilder.java @@ -14,38 +14,31 @@ package de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services; -import static de.sovity.edc.ext.wrapper.utils.EdcDateUtils.utcMillisToOffsetDateTime; -import static de.sovity.edc.ext.wrapper.utils.EdcDateUtils.utcSecondsToOffsetDateTime; -import static de.sovity.edc.ext.wrapper.utils.MapUtils.mapValues; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.ObjectMapper; -import de.sovity.edc.ext.wrapper.api.common.mappers.AssetMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.PolicyMapper; import de.sovity.edc.ext.wrapper.api.common.model.AssetDto; -import de.sovity.edc.ext.wrapper.api.common.model.PolicyDto; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementCard; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementDirection; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementTransferProcess; -import java.util.Comparator; -import java.util.List; - import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation; -import org.eclipse.edc.connector.contract.spi.types.offer.ContractDefinition; import org.eclipse.edc.connector.transfer.spi.types.TransferProcess; -import org.eclipse.edc.policy.model.Policy; import org.eclipse.edc.spi.types.domain.asset.Asset; import org.jetbrains.annotations.NotNull; +import java.util.Comparator; +import java.util.List; + +import static de.sovity.edc.ext.wrapper.utils.EdcDateUtils.utcMillisToOffsetDateTime; +import static de.sovity.edc.ext.wrapper.utils.EdcDateUtils.utcSecondsToOffsetDateTime; +import static de.sovity.edc.ext.wrapper.utils.MapUtils.mapValues; + @Slf4j @RequiredArgsConstructor public class ContractAgreementPageCardBuilder { private final PolicyMapper policyMapper; - private final AssetMapper assetMapper; private final TransferProcessStateService transferProcessStateService; @NotNull @@ -62,7 +55,7 @@ public ContractAgreementCard buildContractAgreementCard( card.setCounterPartyAddress(negotiation.getCounterPartyAddress()); card.setCounterPartyId(negotiation.getCounterPartyId()); card.setContractSigningDate(utcSecondsToOffsetDateTime(agreement.getContractSigningDate())); - card.setAsset(assetMapper.buildAssetDto(asset)); + card.setAsset(buildAssetDto(asset)); card.setContractPolicy(policyMapper.buildPolicyDto(agreement.getPolicy())); card.setTransferProcesses(buildTransferProcesses(transferProcesses)); return card; @@ -91,4 +84,11 @@ private ContractAgreementTransferProcess buildContractAgreementTransfer( transferProcess.setErrorMessage(transferProcessEntity.getErrorDetail()); return transferProcess; } + + @NotNull + private AssetDto buildAssetDto(@NonNull Asset asset) { + var createdAt = utcMillisToOffsetDateTime(asset.getCreatedAt()); + var properties = mapValues(asset.getProperties(), Object::toString); + return new AssetDto(asset.getId(), createdAt, properties); + } } From 6e96d182c4dffc9573f8efdb09de0e915eef9264 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Wed, 13 Sep 2023 14:04:46 +0200 Subject: [PATCH 04/37] fix: Refactor AssetMapperTest + minor fixes --- .../edc/client/AssetApiServiceTest.java | 11 +- .../sovity/edc/client/utils/AssetUtils.java | 39 ++++++ .../ext/wrapper/api/common/model/UiAsset.java | 61 +++++----- .../common/model/UiAssetCreateRequest.java | 3 +- .../api/common/model/UiAssetCreator.java | 29 ----- .../api/common/model/UiAssetDistribution.java | 29 ----- .../api/common/model/UiAssetHelperDto.java | 96 --------------- .../api/common/model/UiAssetPublisher.java | 29 ----- .../wrapper-common-mappers/build.gradle.kts | 1 - .../api/common/mappers/AssetMapper.java | 111 ++++++++++++++---- ...ssetHelperDto.java => AssetHelperDto.java} | 14 ++- .../common/mappers/utils/UiAssetCreator.java | 2 - .../mappers/utils/UiAssetDistribution.java | 2 - .../mappers/utils/UiAssetPublisher.java | 2 - .../api/common/mappers/AssetMapperTest.java | 53 ++++----- .../mappers/utils/JsonFormatMapper.java | 57 +++++++++ .../api/common/mappers/utils/JsonLdUtils.java | 68 ----------- .../src/test/resources/BadBooleanValue.json | 38 ------ .../src/test/resources/KeywordCase.json | 38 ------ .../src/test/resources/NoBooleanValue.json | 37 ------ .../src/test/resources/StringAsList.json | 47 -------- .../src/test/resources/StringAsMap.json | 41 ------- .../edc/ext/wrapper/WrapperExtension.java | 8 +- .../api/ui/pages/asset/AssetApiService.java | 11 +- 24 files changed, 278 insertions(+), 549 deletions(-) create mode 100644 extensions/wrapper/client/src/test/java/de/sovity/edc/client/utils/AssetUtils.java delete mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreator.java delete mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetDistribution.java delete mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetHelperDto.java delete mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetPublisher.java rename extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/{UiAssetHelperDto.java => AssetHelperDto.java} (81%) create mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonFormatMapper.java delete mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonLdUtils.java delete mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/resources/BadBooleanValue.json delete mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/resources/KeywordCase.json delete mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/resources/NoBooleanValue.json delete mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/resources/StringAsList.json delete mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/resources/StringAsMap.json diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java index 7f95c7e81..aa4f44fec 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java @@ -15,6 +15,7 @@ import de.sovity.edc.client.gen.model.AssetCreateRequest; +import de.sovity.edc.client.utils.AssetUtils; import de.sovity.edc.ext.wrapper.utils.EdcPropertyUtils; import lombok.SneakyThrows; import org.eclipse.edc.connector.spi.asset.AssetService; @@ -40,11 +41,14 @@ public class AssetApiServiceTest { public static final String DATA_SINK = "http://my-data-sink/api/stuff"; public static final String DATA_ADDRESS_TYPE = "HttpData"; EdcPropertyUtils edcPropertyUtils; + AssetUtils assetUtils; @BeforeEach void setUp(EdcExtension extension) { TestUtils.setupExtension(extension); edcPropertyUtils = new EdcPropertyUtils(); + assetUtils = new AssetUtils(); + } @Test @@ -54,7 +58,7 @@ void assetPage(AssetService assetStore) { var privateProperties = Map.of("random-private-prop", "456"); var properties = Map.of( Asset.PROPERTY_ID, "asset-1", - "random-prop", "123" + "landingPage", "https://data-source.my-org/docs" ); createAsset(assetStore, "2023-06-01", properties, privateProperties); @@ -65,7 +69,8 @@ void assetPage(AssetService assetStore) { var assets = result.getAssets(); assertThat(assets).hasSize(1); var asset = assets.get(0); - assertThat(asset.getAdditionalProperties()).isEqualTo(properties); + assertThat(asset.getId()).isEqualTo(properties.get(Asset.PROPERTY_ID)); + assertThat(asset.getLandingPageUrl()).isEqualTo(properties.get("landingPage")); assertThat(asset.getPrivateProperties()).isEqualTo(privateProperties); } @@ -83,7 +88,7 @@ void assetPageSorting(AssetService assetService) { // assert assertThat(result.getAssets()) - .extracting(asset -> asset.getAdditionalProperties().get(Asset.PROPERTY_ID)) + .extracting(asset -> asset.getId()) .containsExactly("asset-3", "asset-2", "asset-1"); } diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/utils/AssetUtils.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/utils/AssetUtils.java new file mode 100644 index 000000000..9a99f894a --- /dev/null +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/utils/AssetUtils.java @@ -0,0 +1,39 @@ +package de.sovity.edc.client.utils; + +import java.util.Map; + +import static io.restassured.http.ContentType.JSON; +import static jakarta.json.Json.createObjectBuilder; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.CONTEXT; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; +import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; +import static org.eclipse.edc.spi.CoreConstants.EDC_PREFIX; + +import de.sovity.edc.extension.e2e.connector.ConnectorRemote; +import de.sovity.edc.extension.e2e.connector.config.ConnectorRemoteConfig; + +public class AssetUtils { + + private ConnectorRemote connectorRemote; + + public void createAsset(String assetId) { + var requestBody = createObjectBuilder() + .add(CONTEXT, createObjectBuilder().add(EDC_PREFIX, EDC_NAMESPACE)) + .add("asset", createObjectBuilder() + .add(ID, assetId) + .add("name", "name") + .add("description", "description") + .add("properties", createObjectBuilder() + .add("description", "description"))) + .build(); + + connectorRemote.prepareManagementApiCall() + .contentType(JSON) + .body(requestBody) + .when() + .post("/v2/assets") + .then() + .statusCode(200) + .contentType(JSON); + } +} diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java index 76bcd623c..eb136d527 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java @@ -34,75 +34,78 @@ @Schema(description = "Asset Details") public class UiAsset { - @Schema(description = "Asset Name", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "Asset Id", requiredMode = Schema.RequiredMode.REQUIRED) + private String id; + + @Schema(description = "Asset Name", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String name; - @Schema(description = "Asset Title", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "Asset Title", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String title; - @Schema(description = "Asset Language", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "Asset Language", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String language; - @Schema(description = "Asset Description", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "Asset Description", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String description; - @Schema(description = "Asset Creator", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "Asset Organization Name", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String creator; - @Schema(description = "Asset Publisher", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "Asset Homepage", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String publisher; - @Schema(description = "License URL", requiredMode = Schema.RequiredMode.REQUIRED) - private String license; + @Schema(description = "License URL", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String licenseUrl; - @Schema(description = "Version", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "Version", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String version; - @Schema(description = "Asset Keywords", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "Asset Keywords", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private List keywords; - @Schema(description = "Distribution", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "Asset MediaType", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String distribution; - @Schema(description = "Landing Page URL", requiredMode = Schema.RequiredMode.REQUIRED) - private String landingPage; + @Schema(description = "Landing Page URL", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String landingPageUrl; - @Schema(description = "HTTP Datasource Hints Proxy Method", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "HTTP Datasource Hints Proxy Method", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private Boolean httpDatasourceHintsProxyMethod; - @Schema(description = "HTTP Datasource Hints Proxy Path", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "HTTP Datasource Hints Proxy Path", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private Boolean httpDatasourceHintsProxyPath; - @Schema(description = "HTTP Datasource Hints Proxy Query Params", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "HTTP Datasource Hints Proxy Query Params", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private Boolean httpDatasourceHintsProxyQueryParams; - @Schema(description = "HTTP Datasource Hints Proxy Body", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "HTTP Datasource Hints Proxy Body", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private Boolean httpDatasourceHintsProxyBody; - @Schema(description = "Data Category", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "Data Category", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String dataCategory; - @Schema(description = "Data Subcategory", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "Data Subcategory", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String dataSubcategory; - @Schema(description = "Data Model", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "Data Model", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String dataModel; - @Schema(description = "Geo-Reference Method", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "Geo-Reference Method", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String geoReferenceMethod; - @Schema(description = "Transport Mode", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "Transport Mode", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String transportMode; - @Schema(description = "Asset JsonLd", requiredMode = Schema.RequiredMode.REQUIRED) - private String assetJsonLd; - - @Schema(description = "Asset additional Properties", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "Asset additional Properties", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private Map additionalProperties; - @Schema(description = "Asset Private Properties", requiredMode = Schema.RequiredMode.REQUIRED) - private Map privateProperties; + @Schema(description = "Asset Private Properties", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private Map privateProperties; - @Schema(description = "Asset Json Properties", requiredMode = Schema.RequiredMode.REQUIRED) + @Schema(description = "Asset Json Properties", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private Map additionalJsonProperties; + + @Schema(description = "Contains the entire asset in its original expanded JSON-LD format", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String assetJsonLd; } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java index 822b9ad69..367edf222 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java @@ -26,8 +26,7 @@ @Setter @NoArgsConstructor @AllArgsConstructor -@Schema(description = "Type-Safe OpenAPI generator friendly Asset Create DTO that supports an opinionated\"\n" + - " + \" subset of the original EDC Asset Entity.") +@Schema(description = "Type-Safe OpenAPI generator friendly Asset Create DTO that supports an opinionated subset of the original EDC Asset Entity.") public class UiAssetCreateRequest { @Schema(description = "Data Address", requiredMode = Schema.RequiredMode.REQUIRED) private Map dataAddressProperties; diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreator.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreator.java deleted file mode 100644 index 45fbd7be6..000000000 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreator.java +++ /dev/null @@ -1,29 +0,0 @@ -package de.sovity.edc.ext.wrapper.api.common.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; -import lombok.ToString; - - -@Getter -@Setter -@ToString -@AllArgsConstructor -@Builder(toBuilder = true) -@RequiredArgsConstructor -@Schema(description = "Asset Creator Details") -public class UiAssetCreator { - - @JsonProperty("@type") - @Schema(description = "Type", requiredMode = Schema.RequiredMode.REQUIRED) - private String type; - - @JsonProperty("http://xmlns.com/foaf/0.1/name") - @Schema(description = "Name", requiredMode = Schema.RequiredMode.REQUIRED) - private String name; -} diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetDistribution.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetDistribution.java deleted file mode 100644 index f59a0d42e..000000000 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetDistribution.java +++ /dev/null @@ -1,29 +0,0 @@ -package de.sovity.edc.ext.wrapper.api.common.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; -import lombok.ToString; - - -@Getter -@Setter -@ToString -@AllArgsConstructor -@Builder(toBuilder = true) -@RequiredArgsConstructor -@Schema(description = "Asset Distribution Details") -public class UiAssetDistribution { - - @JsonProperty("@type") - @Schema(description = "Type", requiredMode = Schema.RequiredMode.REQUIRED) - private String type; - - @JsonProperty("http://www.w3.org/ns/dcat#mediaType") - @Schema(description = "Media Type", requiredMode = Schema.RequiredMode.REQUIRED) - private String name; -} diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetHelperDto.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetHelperDto.java deleted file mode 100644 index 535a3521e..000000000 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetHelperDto.java +++ /dev/null @@ -1,96 +0,0 @@ -package de.sovity.edc.ext.wrapper.api.common.model; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import de.sovity.edc.ext.wrapper.api.common.model.utils.CustomDeserializer; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -import java.util.List; - - -@Getter -@Setter -@ToString -@AllArgsConstructor -@Builder(toBuilder = true) -@RequiredArgsConstructor -@JsonIgnoreProperties(ignoreUnknown = true) -public class UiAssetHelperDto { - - @JsonProperty("https://w3id.org/edc/v0.0.1/ns/") - private String ns; - - @JsonProperty("http://purl.org/dc/terms/identifier") - private String identifier; - - @JsonProperty("http://purl.org/dc/terms/title") - @JsonDeserialize(using = CustomDeserializer.class) - private String title; - - @JsonProperty("http://purl.org/dc/terms/language") - private String language; - - @JsonProperty("http://purl.org/dc/terms/description") - private String description; - - @JsonProperty("http://purl.org/dc/terms/creator") - private UiAssetCreator creator; - - @JsonProperty("http://purl.org/dc/terms/publisher") - private UiAssetPublisher publisher; - - @JsonProperty("http://purl.org/dc/terms/license") - private String license; - - @JsonProperty("http://www.w3.org/ns/dcat#version") - private String version; - - @JsonProperty("http://www.w3.org/ns/dcat#keyword") - @JsonDeserialize(using = CustomDeserializer.class) - private List keywords; - - @JsonProperty("http://www.w3.org/ns/dcat#distribution") - private UiAssetDistribution distribution; - - @JsonProperty("http://www.w3.org/ns/dcat#landingPage") - private String landingPage; - - @JsonProperty("https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyMethod") - @JsonDeserialize(using = CustomDeserializer.class) - private Boolean httpDatasourceHintsProxyMethod; - - @JsonProperty("https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyPath") - @JsonDeserialize(using = CustomDeserializer.class) - private Boolean httpDatasourceHintsProxyPath; - - @JsonProperty("https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyQueryParams") - @JsonDeserialize(using = CustomDeserializer.class) - private Boolean httpDatasourceHintsProxyQueryParams; - - @JsonProperty("https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyBody") - @JsonDeserialize(using = CustomDeserializer.class) - private Boolean httpDatasourceHintsProxyBody; - - @JsonProperty("http://w3id.org/mds#dataCategory") - private String dataCategory; - - @JsonProperty("http://w3id.org/mds#dataSubcategory") - private String dataSubcategory; - - @JsonProperty("http://w3id.org/mds#dataModel") - private String dataModel; - - @JsonProperty("http://w3id.org/mds#geoReferenceMethod") - private String geoReferenceMethod; - - @JsonProperty("http://w3id.org/mds#transportMode") - private String transportMode; -} - diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetPublisher.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetPublisher.java deleted file mode 100644 index 56f0bb633..000000000 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetPublisher.java +++ /dev/null @@ -1,29 +0,0 @@ -package de.sovity.edc.ext.wrapper.api.common.model; - -import com.fasterxml.jackson.annotation.JsonProperty; -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; -import lombok.ToString; - - -@Getter -@Setter -@ToString -@AllArgsConstructor -@Builder(toBuilder = true) -@RequiredArgsConstructor -@Schema(description = "Asset Publisher Details") -public class UiAssetPublisher { - - @JsonProperty("@type") - @Schema(description = "Type", requiredMode = Schema.RequiredMode.REQUIRED) - private String type; - - @JsonProperty("http://xmlns.com/foaf/0.1/homepage") - @Schema(description = "Homepage URL", requiredMode = Schema.RequiredMode.REQUIRED) - private String name; -} diff --git a/extensions/wrapper/wrapper-common-mappers/build.gradle.kts b/extensions/wrapper/wrapper-common-mappers/build.gradle.kts index 3932bc968..05b244270 100644 --- a/extensions/wrapper/wrapper-common-mappers/build.gradle.kts +++ b/extensions/wrapper/wrapper-common-mappers/build.gradle.kts @@ -23,7 +23,6 @@ dependencies { implementation("org.apache.commons:commons-lang3:3.13.0") implementation("org.apache.commons:commons-collections4:4.4") - implementation("cz.cvut.kbss.jsonld:jb4jsonld-jackson:0.13.2") testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}") diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java index 6995df11b..e86bd4e8e 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java @@ -1,10 +1,14 @@ package de.sovity.edc.ext.wrapper.api.common.mappers; import com.fasterxml.jackson.databind.ObjectMapper; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.AssetHelperDto; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; -import de.sovity.edc.ext.wrapper.api.common.model.UiAssetHelperDto; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; +import org.eclipse.edc.spi.types.domain.asset.Asset; + +import java.util.HashMap; +import java.util.Map; @RequiredArgsConstructor @@ -14,36 +18,95 @@ public class AssetMapper { */ private final ObjectMapper jsonLdObjectMapper; + @SneakyThrows + public UiAsset buildUiAssetFromAssetJsonLd(String assetJsonLd) { + return buildUiAsset(buildHelperDto(assetJsonLd)); + } - public UiAsset buildUiAsset(UiAssetHelperDto uiAssetHelperDto) { + public UiAsset buildUiAsset(AssetHelperDto assetHelperDto) { return UiAsset.builder() - .name(uiAssetHelperDto.getNs()) - .keywords(uiAssetHelperDto.getKeywords()) - .version(uiAssetHelperDto.getVersion()) - .license(uiAssetHelperDto.getLicense()) - .publisher(uiAssetHelperDto.getPublisher().getName()) - .creator(uiAssetHelperDto.getCreator().getName()) - .description(uiAssetHelperDto.getDescription()) - .language(uiAssetHelperDto.getLanguage()) - .title(uiAssetHelperDto.getTitle()) - .httpDatasourceHintsProxyMethod(uiAssetHelperDto.getHttpDatasourceHintsProxyMethod()) - .httpDatasourceHintsProxyPath(uiAssetHelperDto.getHttpDatasourceHintsProxyPath()) - .httpDatasourceHintsProxyQueryParams(uiAssetHelperDto.getHttpDatasourceHintsProxyQueryParams()) - .httpDatasourceHintsProxyBody(uiAssetHelperDto.getHttpDatasourceHintsProxyBody()) - .dataCategory(uiAssetHelperDto.getDataCategory()) - .dataSubcategory(uiAssetHelperDto.getDataSubcategory()) - .dataModel(uiAssetHelperDto.getDataModel()) - .geoReferenceMethod(uiAssetHelperDto.getGeoReferenceMethod()) - .transportMode(uiAssetHelperDto.getTransportMode()) - .landingPage(uiAssetHelperDto.getLandingPage()) - .distribution(uiAssetHelperDto.getDistribution().getName()) + .name(assetHelperDto.getNs()) + .keywords(assetHelperDto.getKeywords()) + .version(assetHelperDto.getVersion()) + .licenseUrl(assetHelperDto.getLicense()) + .creator(assetHelperDto.getCreator() != null ? assetHelperDto.getCreator().getName() : null) + .publisher(assetHelperDto.getPublisher() != null ? assetHelperDto.getPublisher().getName() : null) + .description(assetHelperDto.getDescription()) + .language(assetHelperDto.getLanguage()) + .title(assetHelperDto.getTitle()) + .httpDatasourceHintsProxyMethod(assetHelperDto.getHttpDatasourceHintsProxyMethod()) + .httpDatasourceHintsProxyPath(assetHelperDto.getHttpDatasourceHintsProxyPath()) + .httpDatasourceHintsProxyQueryParams(assetHelperDto.getHttpDatasourceHintsProxyQueryParams()) + .httpDatasourceHintsProxyBody(assetHelperDto.getHttpDatasourceHintsProxyBody()) + .dataCategory(assetHelperDto.getDataCategory()) + .dataSubcategory(assetHelperDto.getDataSubcategory()) + .dataModel(assetHelperDto.getDataModel()) + .geoReferenceMethod(assetHelperDto.getGeoReferenceMethod()) + .transportMode(assetHelperDto.getTransportMode()) + .landingPageUrl(assetHelperDto.getLandingPage()) + .distribution(assetHelperDto.getDistribution() != null ? assetHelperDto.getDistribution().getName() : null) .build(); } @SneakyThrows - public UiAssetHelperDto buildHelperDto(String assetJsonLd) { + public AssetHelperDto buildHelperDto(String assetJsonLd) { ObjectMapper mapper = new ObjectMapper(); - return mapper.readValue(assetJsonLd, UiAssetHelperDto.class); + return mapper.readValue(assetJsonLd, AssetHelperDto.class); + } + + @SneakyThrows + private UiAsset buildUiAsset(Asset asset) { + var assetJsonLd = jsonLdObjectMapper.writeValueAsString(asset); + var uiAssetHelperDto = buildHelperDto(assetJsonLd); + return buildUiAsset(uiAssetHelperDto); + } + + @SneakyThrows + private Asset buildAssetFromAssetJsonLd(String assetPropertiesJsonLd) { + + UiAsset uiAsset = buildUiAssetFromAssetJsonLd(assetPropertiesJsonLd); + + Asset.Builder assetBuilder = Asset.Builder + .newInstance() + .id(uiAsset.getId()) + .name(uiAsset.getName()) + .description(uiAsset.getDescription()) + .version(uiAsset.getVersion()); + + Map additionalProps = new HashMap<>(); + additionalProps.put("title", uiAsset.getTitle()); + additionalProps.put("language", uiAsset.getLanguage()); + additionalProps.put("creator", uiAsset.getCreator()); + additionalProps.put("publisher", uiAsset.getPublisher()); + additionalProps.put("licenseUrl", uiAsset.getLicenseUrl()); + additionalProps.put("keywords", uiAsset.getKeywords()); + additionalProps.put("distribution", uiAsset.getDistribution()); + additionalProps.put("landingPageUrl", uiAsset.getLandingPageUrl()); + additionalProps.put("httpDatasourceHintsProxyMethod", uiAsset.getHttpDatasourceHintsProxyMethod()); + additionalProps.put("httpDatasourceHintsProxyPath", uiAsset.getHttpDatasourceHintsProxyPath()); + additionalProps.put("httpDatasourceHintsProxyQueryParams", uiAsset.getHttpDatasourceHintsProxyQueryParams()); + additionalProps.put("httpDatasourceHintsProxyBody", uiAsset.getHttpDatasourceHintsProxyBody()); + additionalProps.put("dataCategory", uiAsset.getDataCategory()); + additionalProps.put("dataSubcategory", uiAsset.getDataSubcategory()); + additionalProps.put("dataModel", uiAsset.getDataModel()); + additionalProps.put("geoReferenceMethod", uiAsset.getGeoReferenceMethod()); + additionalProps.put("transportMode", uiAsset.getTransportMode()); + + if(uiAsset.getAdditionalProperties() != null) { + additionalProps.putAll(uiAsset.getAdditionalProperties()); + } + + if(uiAsset.getPrivateProperties() != null) { + assetBuilder.privateProperties(new HashMap<>(uiAsset.getPrivateProperties())); + } + + if(uiAsset.getAdditionalJsonProperties() != null) { + additionalProps.putAll(uiAsset.getAdditionalJsonProperties()); + } + + assetBuilder.properties(additionalProps); + + return assetBuilder.build(); } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetHelperDto.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetHelperDto.java similarity index 81% rename from extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetHelperDto.java rename to extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetHelperDto.java index 392421187..76eb64ef6 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetHelperDto.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetHelperDto.java @@ -21,12 +21,14 @@ @Builder(toBuilder = true) @RequiredArgsConstructor @JsonIgnoreProperties(ignoreUnknown = true) -public class UiAssetHelperDto { +public class AssetHelperDto { @JsonProperty("https://w3id.org/edc/v0.0.1/ns/") + @JsonDeserialize(using = CustomDeserializer.class) private String ns; @JsonProperty("http://purl.org/dc/terms/identifier") + @JsonDeserialize(using = CustomDeserializer.class) private String identifier; @JsonProperty("http://purl.org/dc/terms/title") @@ -34,9 +36,11 @@ public class UiAssetHelperDto { private String title; @JsonProperty("http://purl.org/dc/terms/language") + @JsonDeserialize(using = CustomDeserializer.class) private String language; @JsonProperty("http://purl.org/dc/terms/description") + @JsonDeserialize(using = CustomDeserializer.class) private String description; @JsonProperty("http://purl.org/dc/terms/creator") @@ -46,9 +50,11 @@ public class UiAssetHelperDto { private UiAssetPublisher publisher; @JsonProperty("http://purl.org/dc/terms/license") + @JsonDeserialize(using = CustomDeserializer.class) private String license; @JsonProperty("http://www.w3.org/ns/dcat#version") + @JsonDeserialize(using = CustomDeserializer.class) private String version; @JsonProperty("http://www.w3.org/ns/dcat#keyword") @@ -59,6 +65,7 @@ public class UiAssetHelperDto { private UiAssetDistribution distribution; @JsonProperty("http://www.w3.org/ns/dcat#landingPage") + @JsonDeserialize(using = CustomDeserializer.class) private String landingPage; @JsonProperty("https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyMethod") @@ -78,18 +85,23 @@ public class UiAssetHelperDto { private Boolean httpDatasourceHintsProxyBody; @JsonProperty("http://w3id.org/mds#dataCategory") + @JsonDeserialize(using = CustomDeserializer.class) private String dataCategory; @JsonProperty("http://w3id.org/mds#dataSubcategory") + @JsonDeserialize(using = CustomDeserializer.class) private String dataSubcategory; @JsonProperty("http://w3id.org/mds#dataModel") + @JsonDeserialize(using = CustomDeserializer.class) private String dataModel; @JsonProperty("http://w3id.org/mds#geoReferenceMethod") + @JsonDeserialize(using = CustomDeserializer.class) private String geoReferenceMethod; @JsonProperty("http://w3id.org/mds#transportMode") + @JsonDeserialize(using = CustomDeserializer.class) private String transportMode; } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetCreator.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetCreator.java index a9f185d86..132ce82e3 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetCreator.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetCreator.java @@ -20,10 +20,8 @@ public class UiAssetCreator { @JsonProperty("@type") - @Schema(description = "Type", requiredMode = Schema.RequiredMode.REQUIRED) private String type; @JsonProperty("http://xmlns.com/foaf/0.1/name") - @Schema(description = "Name", requiredMode = Schema.RequiredMode.REQUIRED) private String name; } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetDistribution.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetDistribution.java index 6f4c31fa8..8aa75ba51 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetDistribution.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetDistribution.java @@ -20,10 +20,8 @@ public class UiAssetDistribution { @JsonProperty("@type") - @Schema(description = "Type", requiredMode = Schema.RequiredMode.REQUIRED) private String type; @JsonProperty("http://www.w3.org/ns/dcat#mediaType") - @Schema(description = "Media Type", requiredMode = Schema.RequiredMode.REQUIRED) private String name; } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetPublisher.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetPublisher.java index f8e65edfa..dce806742 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetPublisher.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetPublisher.java @@ -20,10 +20,8 @@ public class UiAssetPublisher { @JsonProperty("@type") - @Schema(description = "Type", requiredMode = Schema.RequiredMode.REQUIRED) private String type; @JsonProperty("http://xmlns.com/foaf/0.1/homepage") - @Schema(description = "Homepage URL", requiredMode = Schema.RequiredMode.REQUIRED) private String name; } diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java index 94a4d7d44..76c5d1653 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java @@ -1,13 +1,13 @@ package de.sovity.edc.ext.wrapper.api.common.mappers; -import com.fasterxml.jackson.databind.ObjectMapper; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.JsonFormatMapper; import lombok.SneakyThrows; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; -import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; + import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; @@ -19,9 +19,9 @@ class AssetMapperTest { @InjectMocks AssetMapper assetMapper; + @InjectMocks + JsonFormatMapper jsonFormatMapper; - - //for sample and then the other edge cases @Test @SneakyThrows void test_buildAssetDto() { @@ -38,27 +38,21 @@ void test_buildAssetDto() { assertThat(uiAsset.getDescription()).isEqualTo("Lorem Ipsum ..."); assertThat(uiAsset.getPublisher()).isEqualTo("https://data-source.my-org/about"); assertThat(uiAsset.getCreator()).isEqualTo("My Organization Name"); - assertThat(uiAsset.getLicense()).isEqualTo("https://data-source.my-org/license"); + assertThat(uiAsset.getLicenseUrl()).isEqualTo("https://data-source.my-org/license"); assertThat(uiAsset.getVersion()).isEqualTo("1.1"); assertThat(uiAsset.getLanguage()).isEqualTo("https://w3id.org/idsa/code/EN"); assertThat(uiAsset.getKeywords()).isEqualTo(List.of("some", "keywords")); assertThat(uiAsset.getHttpDatasourceHintsProxyMethod()).isEqualTo(true); assertThat(uiAsset.getHttpDatasourceHintsProxyPath()).isEqualTo(true); assertThat(uiAsset.getDistribution()).isEqualTo("application/json"); - - // Convert the UiAsset to a JSON string - ObjectMapper objectMapper = new ObjectMapper(); - String resultJson = objectMapper.writer().withDefaultPrettyPrinter().writeValueAsString(uiAsset); - - Files.write(Paths.get("result.json"), resultJson.getBytes()); } + @Test @SneakyThrows void test_KeywordsAsSingleString() { - // Arrange - String jsonContent = new String(Files.readAllBytes(Paths.get(getClass().getResource("/KeywordCase.json").toURI()))); + // Act - var uiAsset = assetMapper.buildUiAsset(assetMapper.buildHelperDto(jsonContent)); + var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(jsonFormatMapper.mapKeywords("{\"keywords\":\"SingleElement\"}")); // Assert assertThat(uiAsset).isNotNull(); @@ -68,36 +62,40 @@ void test_KeywordsAsSingleString() { @Test @SneakyThrows void test_StringsAsList() { - // Arrange - String jsonContent = new String(Files.readAllBytes(Paths.get(getClass().getResource("/StringAsList.json").toURI()))); + // Act - var uiAsset = assetMapper.buildUiAsset(assetMapper.buildHelperDto(jsonContent)); + var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(jsonFormatMapper.mapTitleList( + "{\"title\":" + + "[{\"value\":\"AssetName\",\"language\":\"en\"}," + + "{\"value\":\"AssetNameinFrench\",\"language\":\"fr\"}]}")); // Assert assertThat(uiAsset).isNotNull(); - assertThat(uiAsset.getName()).isEqualTo("urn:artifact:my-asset"); + assertThat(uiAsset.getTitle()).isEqualTo("AssetName"); } @Test @SneakyThrows void test_StringsAsMap() { - // Arrange - String jsonContent = new String(Files.readAllBytes(Paths.get(getClass().getResource("/StringAsMap.json").toURI()))); + // Act - var uiAsset = assetMapper.buildUiAsset(assetMapper.buildHelperDto(jsonContent)); + var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(jsonFormatMapper.mapTitle( + "{\"title\":" + + "{\"@type\":\"SomeType\"," + + "\"@value\":\"AssetName\"}}")); // Assert assertThat(uiAsset).isNotNull(); - assertThat(uiAsset.getName()).isEqualTo("urn:artifact:my-asset"); + assertThat(uiAsset.getTitle()).isEqualTo("AssetName"); } @Test @SneakyThrows void test_badBooleanValue() { - // Arrange - String jsonContent = new String(Files.readAllBytes(Paths.get(getClass().getResource("/BadBooleanValue.json").toURI()))); + // Act - var uiAsset = assetMapper.buildUiAsset(assetMapper.buildHelperDto(jsonContent)); + var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(jsonFormatMapper.mapBooleanHintProxyMethod( + "{\"httpDatasourceHintsProxyMethod\":\"wrongBooleanValue\"}")); // Assert assertThat(uiAsset).isNotNull(); @@ -107,10 +105,9 @@ void test_badBooleanValue() { @Test @SneakyThrows void test_noBooleanValue() { - // Arrange - String jsonContent = new String(Files.readAllBytes(Paths.get(getClass().getResource("/NoBooleanValue.json").toURI()))); + // Act - var uiAsset = assetMapper.buildUiAsset(assetMapper.buildHelperDto(jsonContent)); + var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(jsonFormatMapper.mapBooleanHintProxyMethod("{}")); // Assert assertThat(uiAsset).isNotNull(); diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonFormatMapper.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonFormatMapper.java new file mode 100644 index 000000000..ec7ec67f2 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonFormatMapper.java @@ -0,0 +1,57 @@ +package de.sovity.edc.ext.wrapper.api.common.mappers.utils; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import lombok.SneakyThrows; + +public class JsonFormatMapper { + + private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); + private static final String DCAT_KEYWORD = "http://www.w3.org/ns/dcat#keyword"; + private static final String DC_TERMS_TITLE = "http://purl.org/dc/terms/title"; + private static final String SOVITY_HINTS_PROXY_METHOD = "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyMethod"; + + @SneakyThrows + public String mapKeywords(String oldJsonStr) { + return mapSingleValue(oldJsonStr, "keywords", DCAT_KEYWORD); + } + + @SneakyThrows + public String mapTitle(String oldJsonStr) { + return mapSingleValue(oldJsonStr, "title", DC_TERMS_TITLE); + } + + @SneakyThrows + public String mapBooleanHintProxyMethod(String oldJsonStr) { + return mapSingleValue(oldJsonStr, "httpDatasourceHintsProxyMethod", SOVITY_HINTS_PROXY_METHOD); + } + + @SneakyThrows + public String mapTitleList(String oldJsonStr) { + JsonNode oldJson = OBJECT_MAPPER.readTree(oldJsonStr); + ObjectNode newJson = OBJECT_MAPPER.createObjectNode(); + + if (oldJson.has("title")) { + ArrayNode titleArray = OBJECT_MAPPER.createArrayNode(); + for (JsonNode item : oldJson.get("title")) { + ObjectNode titleObject = OBJECT_MAPPER.createObjectNode(); + titleObject.set("@value", item.get("value")); + titleObject.set("@language", item.get("language")); + titleArray.add(titleObject); + } + newJson.set(DC_TERMS_TITLE, titleArray); + } + + return OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(newJson); + } + + private String mapSingleValue(String jsonStr, String oldKey, String newKey) throws Exception { + JsonNode oldJson = OBJECT_MAPPER.readTree(jsonStr); + ObjectNode newJson = OBJECT_MAPPER.createObjectNode(); + newJson.set(newKey, oldJson.get(oldKey)); + return OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(newJson); + } +} + diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonLdUtils.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonLdUtils.java deleted file mode 100644 index 723583e3e..000000000 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonLdUtils.java +++ /dev/null @@ -1,68 +0,0 @@ -package de.sovity.edc.ext.wrapper.api.common.mappers.utils; - -public class JsonLdUtils { -/* - private static final ObjectMapper objectMapper = new ObjectMapper(); - - public static ValueType getValueType(String jsonLd, String propertyUri) throws Exception { - JsonNode rootNode = objectMapper.readTree(jsonLd); - JsonNode propertyNode = rootNode.get(propertyUri); - - if (propertyNode == null) { - throw new IllegalArgumentException("Property URI not found in provided JSON-LD."); - } - - if (propertyNode.isTextual()) { - return ValueType.STRING; - } - - if (propertyNode.isArray()) { - for (JsonNode node : propertyNode) { - if (!node.isTextual()) { - return ValueType.OTHER; - } - } - return ValueType.ARRAY_OF_STRINGS; - } - - return ValueType.OTHER; - } - - public enum ValueType { - STRING, - ARRAY_OF_STRINGS, - OTHER - } - - public Map inspectPropertyTypes() { - Map propertyTypes = new HashMap<>(); - - for (Field field : UiAssetHelperDto.class.getDeclaredFields()) { - JsonProperty jsonProperty = field.getAnnotation(JsonProperty.class); - if (jsonProperty != null) { - String uri = jsonProperty.value(); - ValueType valueType = determineValueType(field.getType()); - propertyTypes.put(uri, valueType); - } - } - - return propertyTypes; - } - - private ValueType determineValueType(Class type) { - if (type.equals(String.class)) { - return ValueType.STRING; - } else if (type.equals(List.class)) { - return ValueType.ARRAY_OF_STRINGS; - } else { - return ValueType.OTHER; - } - } - - public enum ValueType { - STRING, - ARRAY_OF_STRINGS, - OTHER - }*/ - -} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/resources/BadBooleanValue.json b/extensions/wrapper/wrapper-common-mappers/src/test/resources/BadBooleanValue.json deleted file mode 100644 index 44bf1d0f2..000000000 --- a/extensions/wrapper/wrapper-common-mappers/src/test/resources/BadBooleanValue.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "https://w3id.org/edc/v0.0.1/ns/": "urn:artifact:my-asset", - - "http://purl.org/dc/terms/identifier": "urn:artifact:my-asset", - "http://purl.org/dc/terms/title": "My Asset", - "http://purl.org/dc/terms/language": "https://w3id.org/idsa/code/EN", - "http://purl.org/dc/terms/description": "Lorem Ipsum ...", - "http://purl.org/dc/terms/creator": { - "@type": "http://xmlns.com/foaf/0.1/Organization", - "http://xmlns.com/foaf/0.1/name": "My Organization Name" - }, - "http://purl.org/dc/terms/publisher": { - "@type": "http://xmlns.com/foaf/0.1/Organization", - "http://xmlns.com/foaf/0.1/homepage": "https://data-source.my-org/about" - }, - "http://purl.org/dc/terms/license": "https://data-source.my-org/license", - - "http://www.w3.org/ns/dcat#version": "1.1", - "http://www.w3.org/ns/dcat#keyword": ["some", "keywords"], - "http://www.w3.org/ns/dcat#distribution": { - "@type": "http://www.w3.org/ns/dcat#Distribution", - "http://www.w3.org/ns/dcat#mediaType": "application/json" - }, - "http://www.w3.org/ns/dcat#landingPage": "https://data-source.my-org/docs", - - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyMethod": "idk", - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyPath": "true", - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyQueryParams": "true", - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyBody": "true", - - "http://w3id.org/mds#dataCategory": "Infrastructure and Logistics", - "http://w3id.org/mds#dataSubcategory": "General Information About Planning Of Routes", - "http://w3id.org/mds#dataModel": "my-data-model-001", - "http://w3id.org/mds#geoReferenceMethod": "my-geo-reference-method", - "http://w3id.org/mds#transportMode": "my-geo-reference-method", - - "http://unknown/some-custom-property": "test" -} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/resources/KeywordCase.json b/extensions/wrapper/wrapper-common-mappers/src/test/resources/KeywordCase.json deleted file mode 100644 index f10f6cdc8..000000000 --- a/extensions/wrapper/wrapper-common-mappers/src/test/resources/KeywordCase.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "https://w3id.org/edc/v0.0.1/ns/": "urn:artifact:my-asset", - - "http://purl.org/dc/terms/identifier": "urn:artifact:my-asset", - "http://purl.org/dc/terms/title": "My Asset", - "http://purl.org/dc/terms/language": "https://w3id.org/idsa/code/EN", - "http://purl.org/dc/terms/description": "Lorem Ipsum ...", - "http://purl.org/dc/terms/creator": { - "@type": "http://xmlns.com/foaf/0.1/Organization", - "http://xmlns.com/foaf/0.1/name": "My Organization Name" - }, - "http://purl.org/dc/terms/publisher": { - "@type": "http://xmlns.com/foaf/0.1/Organization", - "http://xmlns.com/foaf/0.1/homepage": "https://data-source.my-org/about" - }, - "http://purl.org/dc/terms/license": "https://data-source.my-org/license", - - "http://www.w3.org/ns/dcat#version": "1.1", - "http://www.w3.org/ns/dcat#keyword": "SingleElement", - "http://www.w3.org/ns/dcat#distribution": { - "@type": "http://www.w3.org/ns/dcat#Distribution", - "http://www.w3.org/ns/dcat#mediaType": "application/json" - }, - "http://www.w3.org/ns/dcat#landingPage": "https://data-source.my-org/docs", - - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyMethod": "true", - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyPath": "true", - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyQueryParams": "true", - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyBody": "true", - - "http://w3id.org/mds#dataCategory": "Infrastructure and Logistics", - "http://w3id.org/mds#dataSubcategory": "General Information About Planning Of Routes", - "http://w3id.org/mds#dataModel": "my-data-model-001", - "http://w3id.org/mds#geoReferenceMethod": "my-geo-reference-method", - "http://w3id.org/mds#transportMode": "my-geo-reference-method", - - "http://unknown/some-custom-property": "test" -} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/resources/NoBooleanValue.json b/extensions/wrapper/wrapper-common-mappers/src/test/resources/NoBooleanValue.json deleted file mode 100644 index da9cae757..000000000 --- a/extensions/wrapper/wrapper-common-mappers/src/test/resources/NoBooleanValue.json +++ /dev/null @@ -1,37 +0,0 @@ -{ - "https://w3id.org/edc/v0.0.1/ns/": "urn:artifact:my-asset", - - "http://purl.org/dc/terms/identifier": "urn:artifact:my-asset", - "http://purl.org/dc/terms/title": "My Asset", - "http://purl.org/dc/terms/language": "https://w3id.org/idsa/code/EN", - "http://purl.org/dc/terms/description": "Lorem Ipsum ...", - "http://purl.org/dc/terms/creator": { - "@type": "http://xmlns.com/foaf/0.1/Organization", - "http://xmlns.com/foaf/0.1/name": "My Organization Name" - }, - "http://purl.org/dc/terms/publisher": { - "@type": "http://xmlns.com/foaf/0.1/Organization", - "http://xmlns.com/foaf/0.1/homepage": "https://data-source.my-org/about" - }, - "http://purl.org/dc/terms/license": "https://data-source.my-org/license", - - "http://www.w3.org/ns/dcat#version": "1.1", - "http://www.w3.org/ns/dcat#keyword": ["some", "keywords"], - "http://www.w3.org/ns/dcat#distribution": { - "@type": "http://www.w3.org/ns/dcat#Distribution", - "http://www.w3.org/ns/dcat#mediaType": "application/json" - }, - "http://www.w3.org/ns/dcat#landingPage": "https://data-source.my-org/docs", - - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyPath": "true", - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyQueryParams": "true", - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyBody": "true", - - "http://w3id.org/mds#dataCategory": "Infrastructure and Logistics", - "http://w3id.org/mds#dataSubcategory": "General Information About Planning Of Routes", - "http://w3id.org/mds#dataModel": "my-data-model-001", - "http://w3id.org/mds#geoReferenceMethod": "my-geo-reference-method", - "http://w3id.org/mds#transportMode": "my-geo-reference-method", - - "http://unknown/some-custom-property": "test" -} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/resources/StringAsList.json b/extensions/wrapper/wrapper-common-mappers/src/test/resources/StringAsList.json deleted file mode 100644 index 000075de2..000000000 --- a/extensions/wrapper/wrapper-common-mappers/src/test/resources/StringAsList.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "https://w3id.org/edc/v0.0.1/ns/": "urn:artifact:my-asset", - - "http://purl.org/dc/terms/identifier": "urn:artifact:my-asset", - "http://purl.org/dc/terms/title": [ - { - "@value": "Asset Name", - "@language": "en" - }, - { - "@value": "Asset Name in French cuz why not", - "@language": "fr" - } - ], - "http://purl.org/dc/terms/language": "https://w3id.org/idsa/code/EN", - "http://purl.org/dc/terms/description": "Lorem Ipsum ...", - "http://purl.org/dc/terms/creator": { - "@type": "http://xmlns.com/foaf/0.1/Organization", - "http://xmlns.com/foaf/0.1/name": "My Organization Name" - }, - "http://purl.org/dc/terms/publisher": { - "@type": "http://xmlns.com/foaf/0.1/Organization", - "http://xmlns.com/foaf/0.1/homepage": "https://data-source.my-org/about" - }, - "http://purl.org/dc/terms/license": "https://data-source.my-org/license", - - "http://www.w3.org/ns/dcat#version": "1.1", - "http://www.w3.org/ns/dcat#keyword": ["some", "keywords"], - "http://www.w3.org/ns/dcat#distribution": { - "@type": "http://www.w3.org/ns/dcat#Distribution", - "http://www.w3.org/ns/dcat#mediaType": "application/json" - }, - "http://www.w3.org/ns/dcat#landingPage": "https://data-source.my-org/docs", - - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyMethod": "true", - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyPath": "true", - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyQueryParams": "true", - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyBody": "true", - - "http://w3id.org/mds#dataCategory": "Infrastructure and Logistics", - "http://w3id.org/mds#dataSubcategory": "General Information About Planning Of Routes", - "http://w3id.org/mds#dataModel": "my-data-model-001", - "http://w3id.org/mds#geoReferenceMethod": "my-geo-reference-method", - "http://w3id.org/mds#transportMode": "my-geo-reference-method", - - "http://unknown/some-custom-property": "test" -} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/resources/StringAsMap.json b/extensions/wrapper/wrapper-common-mappers/src/test/resources/StringAsMap.json deleted file mode 100644 index 149220811..000000000 --- a/extensions/wrapper/wrapper-common-mappers/src/test/resources/StringAsMap.json +++ /dev/null @@ -1,41 +0,0 @@ -{ - "https://w3id.org/edc/v0.0.1/ns/": "urn:artifact:my-asset", - - "http://purl.org/dc/terms/identifier": "urn:artifact:my-asset", - "http://purl.org/dc/terms/title": { - "@type": "https://idk-some-random-spec/special-title", - "@value": "Asset Name" - }, - "http://purl.org/dc/terms/language": "https://w3id.org/idsa/code/EN", - "http://purl.org/dc/terms/description": "Lorem Ipsum ...", - "http://purl.org/dc/terms/creator": { - "@type": "http://xmlns.com/foaf/0.1/Organization", - "http://xmlns.com/foaf/0.1/name": "My Organization Name" - }, - "http://purl.org/dc/terms/publisher": { - "@type": "http://xmlns.com/foaf/0.1/Organization", - "http://xmlns.com/foaf/0.1/homepage": "https://data-source.my-org/about" - }, - "http://purl.org/dc/terms/license": "https://data-source.my-org/license", - - "http://www.w3.org/ns/dcat#version": "1.1", - "http://www.w3.org/ns/dcat#keyword": ["some", "keywords"], - "http://www.w3.org/ns/dcat#distribution": { - "@type": "http://www.w3.org/ns/dcat#Distribution", - "http://www.w3.org/ns/dcat#mediaType": "application/json" - }, - "http://www.w3.org/ns/dcat#landingPage": "https://data-source.my-org/docs", - - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyMethod": "true", - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyPath": "true", - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyQueryParams": "true", - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyBody": "true", - - "http://w3id.org/mds#dataCategory": "Infrastructure and Logistics", - "http://w3id.org/mds#dataSubcategory": "General Information About Planning Of Routes", - "http://w3id.org/mds#dataModel": "my-data-model-001", - "http://w3id.org/mds#geoReferenceMethod": "my-geo-reference-method", - "http://w3id.org/mds#transportMode": "my-geo-reference-method", - - "http://unknown/some-custom-property": "test" -} diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtension.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtension.java index 464c389e4..06843323e 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtension.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtension.java @@ -14,6 +14,8 @@ package de.sovity.edc.ext.wrapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.eclipse.edc.connector.api.management.configuration.ManagementApiConfiguration; import org.eclipse.edc.connector.contract.spi.negotiation.store.ContractNegotiationStore; import org.eclipse.edc.connector.contract.spi.offer.store.ContractDefinitionStore; @@ -33,6 +35,8 @@ import org.eclipse.edc.spi.types.TypeManager; import org.eclipse.edc.web.spi.WebService; +import static org.eclipse.edc.spi.CoreConstants.JSON_LD; + public class WrapperExtension implements ServiceExtension { public static final String EXTENSION_NAME = "WrapperExtension"; @@ -74,7 +78,9 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - var objectMapper = typeManager.getMapper(); + var objectMapper = typeManager.getMapper(JSON_LD); + objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + objectMapper.registerModule(new JavaTimeModule()); var wrapperExtensionContext = WrapperExtensionContextBuilder.buildContext( context, diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java index 954f0019f..9324efaeb 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java @@ -30,6 +30,7 @@ import java.util.Comparator; import java.util.List; +import java.util.Map; @RequiredArgsConstructor public class AssetApiService { @@ -41,11 +42,17 @@ public List getAssets() { var assets = getAllAssets(); return assets.stream().sorted(Comparator.comparing(Asset::getCreatedAt).reversed()).map(asset -> { var entry = new UiAsset(); - entry.setAdditionalProperties(edcPropertyUtils.truncateToMapOfString(asset.getProperties())); - entry.setPrivateProperties(edcPropertyUtils.truncateToMapOfString(asset.getPrivateProperties())); + entry.setId(asset.getId()); entry.setDescription(asset.getDescription()); entry.setName(asset.getName()); entry.setVersion(asset.getVersion()); + entry.setLandingPageUrl((asset.getProperties().get("landingPage") != null) ? + asset.getProperties().get("landingPage").toString() : + null); + entry.setKeywords(List.of((asset.getProperties().get("keywords") != null) ? + asset.getProperties().get("keywords").toString() : + "")); + entry.setPrivateProperties(asset.getPrivateProperties()); return entry; }).toList(); } From 2ef5b4a0e1f3ee1295cd81d81f6f60b09b8720d3 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Wed, 13 Sep 2023 14:09:00 +0200 Subject: [PATCH 05/37] fix: Pipeline (Unused Imports) --- .../sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java | 1 - 1 file changed, 1 deletion(-) diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java index fa831dcdb..d935accd7 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java @@ -15,7 +15,6 @@ package de.sovity.edc.ext.wrapper; import com.fasterxml.jackson.databind.ObjectMapper; -import de.sovity.edc.ext.wrapper.api.common.mappers.AssetMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.OperatorMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.PolicyMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.AtomicConstraintMapper; From ef56352bdb61cfc247ed6c6c962acb3cb3ad0ec1 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Wed, 13 Sep 2023 14:12:11 +0200 Subject: [PATCH 06/37] fix: remove dead code --- .../edc/client/AssetApiServiceTest.java | 4 -- .../sovity/edc/client/utils/AssetUtils.java | 39 ------------------- 2 files changed, 43 deletions(-) delete mode 100644 extensions/wrapper/client/src/test/java/de/sovity/edc/client/utils/AssetUtils.java diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java index aa4f44fec..e58da5c5d 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java @@ -15,7 +15,6 @@ import de.sovity.edc.client.gen.model.AssetCreateRequest; -import de.sovity.edc.client.utils.AssetUtils; import de.sovity.edc.ext.wrapper.utils.EdcPropertyUtils; import lombok.SneakyThrows; import org.eclipse.edc.connector.spi.asset.AssetService; @@ -41,14 +40,11 @@ public class AssetApiServiceTest { public static final String DATA_SINK = "http://my-data-sink/api/stuff"; public static final String DATA_ADDRESS_TYPE = "HttpData"; EdcPropertyUtils edcPropertyUtils; - AssetUtils assetUtils; @BeforeEach void setUp(EdcExtension extension) { TestUtils.setupExtension(extension); edcPropertyUtils = new EdcPropertyUtils(); - assetUtils = new AssetUtils(); - } @Test diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/utils/AssetUtils.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/utils/AssetUtils.java deleted file mode 100644 index 9a99f894a..000000000 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/utils/AssetUtils.java +++ /dev/null @@ -1,39 +0,0 @@ -package de.sovity.edc.client.utils; - -import java.util.Map; - -import static io.restassured.http.ContentType.JSON; -import static jakarta.json.Json.createObjectBuilder; -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.CONTEXT; -import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.ID; -import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; -import static org.eclipse.edc.spi.CoreConstants.EDC_PREFIX; - -import de.sovity.edc.extension.e2e.connector.ConnectorRemote; -import de.sovity.edc.extension.e2e.connector.config.ConnectorRemoteConfig; - -public class AssetUtils { - - private ConnectorRemote connectorRemote; - - public void createAsset(String assetId) { - var requestBody = createObjectBuilder() - .add(CONTEXT, createObjectBuilder().add(EDC_PREFIX, EDC_NAMESPACE)) - .add("asset", createObjectBuilder() - .add(ID, assetId) - .add("name", "name") - .add("description", "description") - .add("properties", createObjectBuilder() - .add("description", "description"))) - .build(); - - connectorRemote.prepareManagementApiCall() - .contentType(JSON) - .body(requestBody) - .when() - .post("/v2/assets") - .then() - .statusCode(200) - .contentType(JSON); - } -} From 1292bb715376219f8bdde34f19e1b870e753ff04 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Wed, 13 Sep 2023 14:44:07 +0200 Subject: [PATCH 07/37] chore: refactor CreateAsset Endpoint --- .../edc/client/AssetApiServiceTest.java | 24 +++---- .../common/model/UiAssetCreateRequest.java | 66 ++++++++++++++++-- .../api/common/mappers/AssetMapper.java | 62 ++++++++--------- .../mappers/utils/EdcPropertyMapperUtils.java | 68 +++++++++++++++++++ .../WrapperExtensionContextBuilder.java | 8 ++- .../edc/ext/wrapper/api/ui/UiResource.java | 5 +- .../api/ui/model/AssetCreateRequest.java | 39 ----------- .../api/ui/pages/asset/AssetApiService.java | 12 +--- .../ui/pages/asset/services/AssetBuilder.java | 38 ----------- 9 files changed, 181 insertions(+), 141 deletions(-) create mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtils.java delete mode 100644 extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetCreateRequest.java delete mode 100644 extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/services/AssetBuilder.java diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java index e58da5c5d..de8c43871 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java @@ -14,7 +14,7 @@ package de.sovity.edc.client; -import de.sovity.edc.client.gen.model.AssetCreateRequest; +import de.sovity.edc.client.gen.model.UiAssetCreateRequest; import de.sovity.edc.ext.wrapper.utils.EdcPropertyUtils; import lombok.SneakyThrows; import org.eclipse.edc.connector.spi.asset.AssetService; @@ -28,6 +28,7 @@ import org.junit.jupiter.api.extension.ExtendWith; import java.text.SimpleDateFormat; +import java.util.List; import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; @@ -92,31 +93,27 @@ void assetPageSorting(AssetService assetService) { void testAssetCreation(AssetService assetService) { // arrange var client = TestUtils.edcClient(); - var properties = Map.of( - Asset.PROPERTY_ID, "asset-1", - "random-prop", "123" - ); - var privateProperties = Map.of("random-private-prop", "456"); var dataAddressProperties = Map.of( EDC_DATA_ADDRESS_TYPE_PROPERTY, DATA_ADDRESS_TYPE, "baseUrl", DATA_SINK ); - var assetRequest = AssetCreateRequest.builder() - .properties(properties) - .privateProperties(privateProperties) + var uiAssetRequest = UiAssetCreateRequest.builder() + .id("asset-1") + .name("AssetName") + .keywords(List.of("keyword1", "keyword2")) .dataAddressProperties(dataAddressProperties) .build(); // act - var response = client.uiApi().createAsset(assetRequest); + var response = client.uiApi().createAsset(uiAssetRequest); // assert - assertThat(response.getId()).isEqualTo(properties.get(Asset.PROPERTY_ID)); + assertThat(response.getId()).isEqualTo("asset-1"); var assets = assetService.query(QuerySpec.max()).getContent().toList(); assertThat(assets).hasSize(1); var asset = assets.get(0); - assertThat(asset.getProperties()).isEqualTo(properties); - assertThat(asset.getPrivateProperties()).isEqualTo(privateProperties); + assertThat(asset.getName()).isEqualTo("AssetName"); + assertThat(asset.getProperties().get("keywords")).isEqualTo(List.of("keyword1", "keyword2")); assertThat(asset.getDataAddress().getProperties()).isEqualTo(dataAddressProperties); } @@ -162,6 +159,5 @@ private static long dateFormatterToLong(String date) { SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); return formatter.parse(date).getTime(); } - } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java index 367edf222..716168d0c 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java @@ -20,6 +20,7 @@ import lombok.NoArgsConstructor; import lombok.Setter; +import java.util.List; import java.util.Map; @Getter @@ -28,12 +29,69 @@ @AllArgsConstructor @Schema(description = "Type-Safe OpenAPI generator friendly Asset Create DTO that supports an opinionated subset of the original EDC Asset Entity.") public class UiAssetCreateRequest { + @Schema(description = "Asset Id", requiredMode = Schema.RequiredMode.REQUIRED) + private String id; + + @Schema(description = "Asset Name", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String name; + + @Schema(description = "Asset Title", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String title; + + @Schema(description = "Asset Language", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String language; + + @Schema(description = "Asset Description", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String description; + + @Schema(description = "Asset Organization Name", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String creator; + + @Schema(description = "Asset Homepage", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String publisher; + + @Schema(description = "License URL", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String licenseUrl; + + @Schema(description = "Version", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String version; + + @Schema(description = "Asset Keywords", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private List keywords; + + @Schema(description = "Asset MediaType", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String distribution; + + @Schema(description = "Landing Page URL", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String landingPageUrl; + + @Schema(description = "Data Category", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String dataCategory; + + @Schema(description = "Data Subcategory", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String dataSubcategory; + + @Schema(description = "Data Model", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String dataModel; + + @Schema(description = "Geo-Reference Method", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String geoReferenceMethod; + + @Schema(description = "Transport Mode", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String transportMode; + @Schema(description = "Data Address", requiredMode = Schema.RequiredMode.REQUIRED) private Map dataAddressProperties; - @Schema(description = "Properties of the Data Address", requiredMode = Schema.RequiredMode.REQUIRED) - private Map properties; + @Schema(description = "Asset additional Properties", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private Map additionalProperties; + + @Schema(description = "Asset Private Properties", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private Map privateProperties; + + @Schema(description = "Asset Json Properties", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private Map additionalJsonProperties; - @Schema(description = "Private Asset Properties", requiredMode = Schema.RequiredMode.REQUIRED) - private Map privateProperties; + @Schema(description = "Contains the entire asset in its original expanded JSON-LD format", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String assetJsonLd; } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java index e86bd4e8e..0bdb82eda 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java @@ -2,7 +2,9 @@ import com.fasterxml.jackson.databind.ObjectMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.AssetHelperDto; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; +import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import org.eclipse.edc.spi.types.domain.asset.Asset; @@ -17,6 +19,7 @@ public class AssetMapper { * This Object Mapper must be able to handle JSON-LD serialization / deserialization. */ private final ObjectMapper jsonLdObjectMapper; + private final EdcPropertyMapperUtils edcPropertyMapperUtils; @SneakyThrows public UiAsset buildUiAssetFromAssetJsonLd(String assetJsonLd) { @@ -55,6 +58,7 @@ public AssetHelperDto buildHelperDto(String assetJsonLd) { return mapper.readValue(assetJsonLd, AssetHelperDto.class); } + @SneakyThrows private UiAsset buildUiAsset(Asset asset) { var assetJsonLd = jsonLdObjectMapper.writeValueAsString(asset); @@ -63,46 +67,42 @@ private UiAsset buildUiAsset(Asset asset) { } @SneakyThrows - private Asset buildAssetFromAssetJsonLd(String assetPropertiesJsonLd) { - - UiAsset uiAsset = buildUiAssetFromAssetJsonLd(assetPropertiesJsonLd); + public Asset buildAssetFromUiAssetCreateRequest(UiAssetCreateRequest uiAssetCreateRequest) { Asset.Builder assetBuilder = Asset.Builder .newInstance() - .id(uiAsset.getId()) - .name(uiAsset.getName()) - .description(uiAsset.getDescription()) - .version(uiAsset.getVersion()); + .id(uiAssetCreateRequest.getId()) + .name(uiAssetCreateRequest.getName()) + .description(uiAssetCreateRequest.getDescription()) + .version(uiAssetCreateRequest.getVersion()) + .dataAddress(edcPropertyMapperUtils.buildDataAddress(uiAssetCreateRequest.getDataAddressProperties())); + Map additionalProps = new HashMap<>(); - additionalProps.put("title", uiAsset.getTitle()); - additionalProps.put("language", uiAsset.getLanguage()); - additionalProps.put("creator", uiAsset.getCreator()); - additionalProps.put("publisher", uiAsset.getPublisher()); - additionalProps.put("licenseUrl", uiAsset.getLicenseUrl()); - additionalProps.put("keywords", uiAsset.getKeywords()); - additionalProps.put("distribution", uiAsset.getDistribution()); - additionalProps.put("landingPageUrl", uiAsset.getLandingPageUrl()); - additionalProps.put("httpDatasourceHintsProxyMethod", uiAsset.getHttpDatasourceHintsProxyMethod()); - additionalProps.put("httpDatasourceHintsProxyPath", uiAsset.getHttpDatasourceHintsProxyPath()); - additionalProps.put("httpDatasourceHintsProxyQueryParams", uiAsset.getHttpDatasourceHintsProxyQueryParams()); - additionalProps.put("httpDatasourceHintsProxyBody", uiAsset.getHttpDatasourceHintsProxyBody()); - additionalProps.put("dataCategory", uiAsset.getDataCategory()); - additionalProps.put("dataSubcategory", uiAsset.getDataSubcategory()); - additionalProps.put("dataModel", uiAsset.getDataModel()); - additionalProps.put("geoReferenceMethod", uiAsset.getGeoReferenceMethod()); - additionalProps.put("transportMode", uiAsset.getTransportMode()); - - if(uiAsset.getAdditionalProperties() != null) { - additionalProps.putAll(uiAsset.getAdditionalProperties()); + additionalProps.put("title", uiAssetCreateRequest.getTitle()); + additionalProps.put("language", uiAssetCreateRequest.getLanguage()); + additionalProps.put("creator", uiAssetCreateRequest.getCreator()); + additionalProps.put("publisher", uiAssetCreateRequest.getPublisher()); + additionalProps.put("licenseUrl", uiAssetCreateRequest.getLicenseUrl()); + additionalProps.put("keywords", uiAssetCreateRequest.getKeywords()); + additionalProps.put("distribution", uiAssetCreateRequest.getDistribution()); + additionalProps.put("landingPageUrl", uiAssetCreateRequest.getLandingPageUrl()); + additionalProps.put("dataCategory", uiAssetCreateRequest.getDataCategory()); + additionalProps.put("dataSubcategory", uiAssetCreateRequest.getDataSubcategory()); + additionalProps.put("dataModel", uiAssetCreateRequest.getDataModel()); + additionalProps.put("geoReferenceMethod", uiAssetCreateRequest.getGeoReferenceMethod()); + additionalProps.put("transportMode", uiAssetCreateRequest.getTransportMode()); + + if(uiAssetCreateRequest.getAdditionalProperties() != null) { + additionalProps.putAll(uiAssetCreateRequest.getAdditionalProperties()); } - if(uiAsset.getPrivateProperties() != null) { - assetBuilder.privateProperties(new HashMap<>(uiAsset.getPrivateProperties())); + if(uiAssetCreateRequest.getPrivateProperties() != null) { + assetBuilder.privateProperties(new HashMap<>(uiAssetCreateRequest.getPrivateProperties())); } - if(uiAsset.getAdditionalJsonProperties() != null) { - additionalProps.putAll(uiAsset.getAdditionalJsonProperties()); + if(uiAssetCreateRequest.getAdditionalJsonProperties() != null) { + additionalProps.putAll(uiAssetCreateRequest.getAdditionalJsonProperties()); } assetBuilder.properties(additionalProps); diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtils.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtils.java new file mode 100644 index 000000000..3096d8db5 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtils.java @@ -0,0 +1,68 @@ +/* + * 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 - init + */ + +package de.sovity.edc.ext.wrapper.api.common.mappers.utils; + +import lombok.RequiredArgsConstructor; +import org.eclipse.edc.spi.types.domain.DataAddress; + +import java.util.HashMap; +import java.util.Map; + +@RequiredArgsConstructor +public class EdcPropertyMapperUtils { + + /** + * Converts a {@code Map} to {@code Map}. + *

+ * Our API forsakes asset properties that are complex objects / JSON and only keeps string + * properties. + * + * @param map all properties + * @return string properties + */ + public Map truncateToMapOfString(Map map) { + Map result = new HashMap<>(); + + for (Map.Entry entry : map.entrySet()) { + Object value = entry.getValue(); + + String valueString; + if (value == null) { + valueString = null; + } else if (value instanceof String str) { + valueString = str; + } else if (value instanceof Double) { + valueString = String.valueOf(value); + } else if (value instanceof Integer) { + valueString = String.valueOf(value); + } else { + continue; + } + + result.put(entry.getKey(), valueString); + } + return result; + } + + @SuppressWarnings({"unchecked", "rawtypes", "java:S1905"}) + public Map toMapOfObject(Map map) { + return new HashMap<>((Map) (Map) map); + } + + public DataAddress buildDataAddress(Map properties) { + return DataAddress.Builder.newInstance() + .properties(toMapOfObject(properties)) + .build(); + } +} diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java index d935accd7..f6628fa70 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java @@ -15,16 +15,17 @@ package de.sovity.edc.ext.wrapper; import com.fasterxml.jackson.databind.ObjectMapper; +import de.sovity.edc.ext.wrapper.api.common.mappers.AssetMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.OperatorMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.PolicyMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.AtomicConstraintMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.ConstraintExtractor; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.LiteralMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.PolicyValidator; import de.sovity.edc.ext.wrapper.api.ee.EnterpriseEditionResourceImpl; import de.sovity.edc.ext.wrapper.api.ui.UiResource; import de.sovity.edc.ext.wrapper.api.ui.pages.asset.AssetApiService; -import de.sovity.edc.ext.wrapper.api.ui.pages.asset.services.AssetBuilder; import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.ContractAgreementPageApiService; import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.ContractAgreementTransferApiService; import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.ContractDefinitionApiService; @@ -134,8 +135,9 @@ public static WrapperExtensionContext buildContext( var contractNegotiationUtils = new ContractNegotiationUtils(contractNegotiationService); var contractAgreementUtils = new ContractAgreementUtils(contractAgreementService); var edcPropertyUtils = new EdcPropertyUtils(); - var assetBuilder = new AssetBuilder(edcPropertyUtils); - var assetApiService = new AssetApiService(assetBuilder, assetService, edcPropertyUtils); + var edcPropertyMapperUtils = new EdcPropertyMapperUtils(); + var assetMapper = new AssetMapper(objectMapper, edcPropertyMapperUtils); + var assetApiService = new AssetApiService(assetService, assetMapper); var transferRequestBuilder = new TransferRequestBuilder( objectMapper, contractAgreementUtils, diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java index e1c6170ac..4b846e7c9 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java @@ -18,7 +18,6 @@ import de.sovity.edc.ext.wrapper.api.common.model.PolicyDefinitionCreateRequest; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import de.sovity.edc.ext.wrapper.api.ui.model.AssetPage; -import de.sovity.edc.ext.wrapper.api.ui.model.AssetCreateRequest; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementPage; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementTransferRequest; import de.sovity.edc.ext.wrapper.api.ui.model.ContractDefinitionRequest; @@ -107,8 +106,8 @@ public AssetPage assetPage() { @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @Operation(description = "Create a new Asset") - public IdResponseDto createAsset(AssetCreateRequest assetCreateRequest) { - return assetApiService.createAsset(assetCreateRequest); + public IdResponseDto createAsset(UiAssetCreateRequest uiAssetCreateRequest) { + return assetApiService.createAsset(uiAssetCreateRequest); } @DELETE diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetCreateRequest.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetCreateRequest.java deleted file mode 100644 index aacbb8121..000000000 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetCreateRequest.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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.model; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.AllArgsConstructor; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -import java.util.Map; - -@Getter -@Setter -@NoArgsConstructor -@AllArgsConstructor -@Schema(description = "Data for creating an Asset") -public class AssetCreateRequest { - @Schema(description = "Data Address", requiredMode = Schema.RequiredMode.REQUIRED) - private Map dataAddressProperties; - - @Schema(description = "Properties of the Data Address", requiredMode = Schema.RequiredMode.REQUIRED) - private Map properties; - - @Schema(description = "Private Asset Properties", requiredMode = Schema.RequiredMode.REQUIRED) - private Map privateProperties; -} diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java index 9324efaeb..a8aeff356 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java @@ -17,11 +17,7 @@ import de.sovity.edc.ext.wrapper.api.common.mappers.AssetMapper; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; -import de.sovity.edc.ext.wrapper.api.ui.model.AssetCreateRequest; -import de.sovity.edc.ext.wrapper.api.ui.model.AssetEntry; import de.sovity.edc.ext.wrapper.api.ui.model.IdResponseDto; -import de.sovity.edc.ext.wrapper.api.ui.pages.asset.services.AssetBuilder; -import de.sovity.edc.ext.wrapper.utils.EdcPropertyUtils; import lombok.RequiredArgsConstructor; import org.eclipse.edc.connector.spi.asset.AssetService; import org.eclipse.edc.spi.query.QuerySpec; @@ -30,13 +26,11 @@ import java.util.Comparator; import java.util.List; -import java.util.Map; @RequiredArgsConstructor public class AssetApiService { - private final AssetBuilder assetBuilder; private final AssetService assetService; - private final EdcPropertyUtils edcPropertyUtils; + private final AssetMapper assetMapper; public List getAssets() { var assets = getAllAssets(); @@ -58,8 +52,8 @@ public List getAssets() { } @NotNull - public IdResponseDto createAsset(AssetCreateRequest request) { - var asset = assetBuilder.buildAsset(request); + public IdResponseDto createAsset(UiAssetCreateRequest request) { + var asset = assetMapper.buildAssetFromUiAssetCreateRequest(request); asset = assetService.create(asset).getContent(); return new IdResponseDto(asset.getId()); } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/services/AssetBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/services/AssetBuilder.java deleted file mode 100644 index e64a28f1e..000000000 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/services/AssetBuilder.java +++ /dev/null @@ -1,38 +0,0 @@ -/* - * 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.wrapper.api.ui.pages.asset.services; - - -import de.sovity.edc.ext.wrapper.api.ui.model.AssetCreateRequest; -import de.sovity.edc.ext.wrapper.utils.EdcPropertyUtils; -import lombok.RequiredArgsConstructor; -import org.eclipse.edc.spi.types.domain.asset.Asset; - -@RequiredArgsConstructor -public class AssetBuilder { - private final EdcPropertyUtils edcPropertyUtils; - - public Asset buildAsset(AssetCreateRequest request) { - var assetProperties = edcPropertyUtils.toMapOfObject(request.getProperties()); - var privateProperties = edcPropertyUtils.toMapOfObject(request.getPrivateProperties()); - - return Asset.Builder.newInstance() - .id(request.getProperties().get(Asset.PROPERTY_ID)) - .properties(assetProperties) - .privateProperties(privateProperties) - .dataAddress(edcPropertyUtils.buildDataAddress(request.getDataAddressProperties())) - .build(); - } -} From 50c6d126c9e1a95573f03d77f75fc78ee79cb564 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Wed, 13 Sep 2023 14:54:38 +0200 Subject: [PATCH 08/37] fix: newLines --- extensions/wrapper/wrapper-common-mappers/build.gradle.kts | 2 -- .../edc/ext/wrapper/api/common/mappers/AssetMapper.java | 4 ---- .../edc/ext/wrapper/api/common/mappers/AssetMapperTest.java | 1 - .../wrapper/api/common/mappers/utils/JsonFormatMapper.java | 1 - 4 files changed, 8 deletions(-) diff --git a/extensions/wrapper/wrapper-common-mappers/build.gradle.kts b/extensions/wrapper/wrapper-common-mappers/build.gradle.kts index 05b244270..32a5ba9fe 100644 --- a/extensions/wrapper/wrapper-common-mappers/build.gradle.kts +++ b/extensions/wrapper/wrapper-common-mappers/build.gradle.kts @@ -18,13 +18,11 @@ dependencies { api("${edcGroup}:core-spi:${edcVersion}") api("${edcGroup}:transform-core:${edcVersion}") - api(project(":extensions:wrapper:wrapper-common-api")) implementation("org.apache.commons:commons-lang3:3.13.0") implementation("org.apache.commons:commons-collections4:4.4") - testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}") testCompileOnly("org.projectlombok:lombok:${lombokVersion}") testImplementation("org.mockito:mockito-core:${mockitoVersion}") diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java index 0bdb82eda..b182c98d1 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java @@ -58,7 +58,6 @@ public AssetHelperDto buildHelperDto(String assetJsonLd) { return mapper.readValue(assetJsonLd, AssetHelperDto.class); } - @SneakyThrows private UiAsset buildUiAsset(Asset asset) { var assetJsonLd = jsonLdObjectMapper.writeValueAsString(asset); @@ -77,7 +76,6 @@ public Asset buildAssetFromUiAssetCreateRequest(UiAssetCreateRequest uiAssetCrea .version(uiAssetCreateRequest.getVersion()) .dataAddress(edcPropertyMapperUtils.buildDataAddress(uiAssetCreateRequest.getDataAddressProperties())); - Map additionalProps = new HashMap<>(); additionalProps.put("title", uiAssetCreateRequest.getTitle()); additionalProps.put("language", uiAssetCreateRequest.getLanguage()); @@ -96,11 +94,9 @@ public Asset buildAssetFromUiAssetCreateRequest(UiAssetCreateRequest uiAssetCrea if(uiAssetCreateRequest.getAdditionalProperties() != null) { additionalProps.putAll(uiAssetCreateRequest.getAdditionalProperties()); } - if(uiAssetCreateRequest.getPrivateProperties() != null) { assetBuilder.privateProperties(new HashMap<>(uiAssetCreateRequest.getPrivateProperties())); } - if(uiAssetCreateRequest.getAdditionalJsonProperties() != null) { additionalProps.putAll(uiAssetCreateRequest.getAdditionalJsonProperties()); } diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java index 76c5d1653..662af9c58 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java @@ -114,4 +114,3 @@ void test_noBooleanValue() { assertThat(uiAsset.getHttpDatasourceHintsProxyMethod()).isEqualTo(null); } } - diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonFormatMapper.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonFormatMapper.java index ec7ec67f2..34dd146a6 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonFormatMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonFormatMapper.java @@ -54,4 +54,3 @@ private String mapSingleValue(String jsonStr, String oldKey, String newKey) thro return OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(newJson); } } - From f616982e8ab32821c2433d405bbe414cda0d79d9 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Wed, 13 Sep 2023 16:03:30 +0200 Subject: [PATCH 09/37] chore: ContractAgreementPageCardBuilder UiAsset Refactoring --- .../edc/client/ContractAgreementPageTest.java | 6 +++--- .../ext/wrapper/api/common/model/UiAsset.java | 4 ++++ .../api/common/mappers/AssetMapper.java | 18 ++++++++++++------ .../api/common/mappers/AssetMapperTest.java | 2 +- .../WrapperExtensionContextBuilder.java | 7 ++++--- .../api/ui/model/ContractAgreementCard.java | 3 +-- .../ContractAgreementPageCardBuilder.java | 13 +++---------- 7 files changed, 28 insertions(+), 25 deletions(-) diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/ContractAgreementPageTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/ContractAgreementPageTest.java index bb1376c89..6bbecf0fe 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/ContractAgreementPageTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/ContractAgreementPageTest.java @@ -93,8 +93,8 @@ void testContractAgreementPage( assertThat(agreement.getCounterPartyAddress()).isEqualTo("http://other-connector"); assertThat(agreement.getCounterPartyId()).isEqualTo("urn:connector:other-connector"); assertThat(agreement.getContractSigningDate()).isEqualTo(todayPlusDays(0)); - assertThat(agreement.getAsset().getProperties()).containsEntry("https://w3id.org/edc/v0.0.1/ns/id", ASSET_ID); - assertThat(agreement.getAsset().getProperties()).containsEntry("some-property", "X"); + assertThat(agreement.getAsset().getId()).isEqualTo(ASSET_ID); + assertThat(agreement.getAsset().getLandingPageUrl()).isEqualTo("X"); assertThat(agreement.getTransferProcesses()).hasSize(1); var transfer = agreement.getTransferProcesses().get(0); @@ -178,7 +178,7 @@ private ContractNegotiation contractDefinition(int contract) { private Asset asset(String assetId) { return Asset.Builder.newInstance() .id(assetId) - .property("some-property", "X") + .property("http://www.w3.org/ns/dcat#landingPage", "X") .createdAt(todayEpochMillis) .dataAddress(dataAddress()) .build(); diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java index eb136d527..6f4e95a6d 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java @@ -27,6 +27,7 @@ @Getter @Setter + @ToString @AllArgsConstructor @Builder(toBuilder = true) @@ -106,6 +107,9 @@ public class UiAsset { @Schema(description = "Asset Json Properties", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private Map additionalJsonProperties; + @Schema(description = "Asset DataAddress Properties", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private Map dataAddressProperties; + @Schema(description = "Contains the entire asset in its original expanded JSON-LD format", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String assetJsonLd; } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java index b182c98d1..283ac86ba 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java @@ -10,6 +10,7 @@ import org.eclipse.edc.spi.types.domain.asset.Asset; import java.util.HashMap; +import java.util.List; import java.util.Map; @@ -23,10 +24,10 @@ public class AssetMapper { @SneakyThrows public UiAsset buildUiAssetFromAssetJsonLd(String assetJsonLd) { - return buildUiAsset(buildHelperDto(assetJsonLd)); + return buildUiAssetFromAssetHelper(buildHelperDto(assetJsonLd)); } - public UiAsset buildUiAsset(AssetHelperDto assetHelperDto) { + public UiAsset buildUiAssetFromAssetHelper(AssetHelperDto assetHelperDto) { return UiAsset.builder() .name(assetHelperDto.getNs()) @@ -59,10 +60,15 @@ public AssetHelperDto buildHelperDto(String assetJsonLd) { } @SneakyThrows - private UiAsset buildUiAsset(Asset asset) { - var assetJsonLd = jsonLdObjectMapper.writeValueAsString(asset); - var uiAssetHelperDto = buildHelperDto(assetJsonLd); - return buildUiAsset(uiAssetHelperDto); + public UiAsset buildUiAssetFromAsset(Asset asset) { + var uiAsset = buildUiAssetFromAssetHelper(buildHelperDto(jsonLdObjectMapper.writeValueAsString(asset.getProperties()))); + + uiAsset.setId(asset.getId()); + uiAsset.setPrivateProperties(asset.getPrivateProperties()); + uiAsset.setDataAddressProperties(edcPropertyMapperUtils.truncateToMapOfString(asset.getDataAddress().getProperties())); + uiAsset.setKeywords(uiAsset.getKeywords() == null ? List.of() : uiAsset.getKeywords()); + + return uiAsset; } @SneakyThrows diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java index 662af9c58..f88ab57ba 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java @@ -29,7 +29,7 @@ void test_buildAssetDto() { String jsonContent = new String(Files.readAllBytes(Paths.get(getClass().getResource("/sample.json").toURI()))); // Act - var uiAsset = assetMapper.buildUiAsset(assetMapper.buildHelperDto(jsonContent)); + var uiAsset = assetMapper.buildUiAssetFromAssetHelper(assetMapper.buildHelperDto(jsonContent)); // Assert assertThat(uiAsset).isNotNull(); diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java index f6628fa70..ee6f1f178 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java @@ -103,10 +103,13 @@ public static WrapperExtensionContext buildContext( objectMapper, constraintExtractor, atomicConstraintMapper); + var edcPropertyMapperUtils = new EdcPropertyMapperUtils(); + var assetMapper = new AssetMapper(objectMapper, edcPropertyMapperUtils); var transferProcessStateService = new TransferProcessStateService(); var contractAgreementPageCardBuilder = new ContractAgreementPageCardBuilder( policyMapper, - transferProcessStateService + transferProcessStateService, + assetMapper ); var contractAgreementDataFetcher = new ContractAgreementDataFetcher( contractAgreementService, @@ -135,8 +138,6 @@ public static WrapperExtensionContext buildContext( var contractNegotiationUtils = new ContractNegotiationUtils(contractNegotiationService); var contractAgreementUtils = new ContractAgreementUtils(contractAgreementService); var edcPropertyUtils = new EdcPropertyUtils(); - var edcPropertyMapperUtils = new EdcPropertyMapperUtils(); - var assetMapper = new AssetMapper(objectMapper, edcPropertyMapperUtils); var assetApiService = new AssetApiService(assetService, assetMapper); var transferRequestBuilder = new TransferRequestBuilder( objectMapper, diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java index 0aa2cb00a..e24a47d7d 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java @@ -14,7 +14,6 @@ package de.sovity.edc.ext.wrapper.api.ui.model; -import de.sovity.edc.ext.wrapper.api.common.model.AssetDto; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyDto; import io.swagger.v3.oas.annotations.media.Schema; @@ -59,7 +58,7 @@ public class ContractAgreementCard { private OffsetDateTime contractEndDate; @Schema(description = "Asset details", requiredMode = Schema.RequiredMode.REQUIRED) - private AssetDto asset; + private UiAsset asset; @Schema(description = "Contract Policy", requiredMode = Schema.RequiredMode.REQUIRED) private UiPolicyDto contractPolicy; diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/ContractAgreementPageCardBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/ContractAgreementPageCardBuilder.java index 941e7ebb3..5dbdaecfe 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/ContractAgreementPageCardBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/ContractAgreementPageCardBuilder.java @@ -14,8 +14,8 @@ package de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services; +import de.sovity.edc.ext.wrapper.api.common.mappers.AssetMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.PolicyMapper; -import de.sovity.edc.ext.wrapper.api.common.model.AssetDto; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementCard; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementDirection; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementTransferProcess; @@ -33,13 +33,13 @@ import static de.sovity.edc.ext.wrapper.utils.EdcDateUtils.utcMillisToOffsetDateTime; import static de.sovity.edc.ext.wrapper.utils.EdcDateUtils.utcSecondsToOffsetDateTime; -import static de.sovity.edc.ext.wrapper.utils.MapUtils.mapValues; @Slf4j @RequiredArgsConstructor public class ContractAgreementPageCardBuilder { private final PolicyMapper policyMapper; private final TransferProcessStateService transferProcessStateService; + private final AssetMapper assetMapper; @NotNull public ContractAgreementCard buildContractAgreementCard( @@ -55,7 +55,7 @@ public ContractAgreementCard buildContractAgreementCard( card.setCounterPartyAddress(negotiation.getCounterPartyAddress()); card.setCounterPartyId(negotiation.getCounterPartyId()); card.setContractSigningDate(utcSecondsToOffsetDateTime(agreement.getContractSigningDate())); - card.setAsset(buildAssetDto(asset)); + card.setAsset(assetMapper.buildUiAssetFromAsset(asset)); card.setContractPolicy(policyMapper.buildPolicyDto(agreement.getPolicy())); card.setTransferProcesses(buildTransferProcesses(transferProcesses)); return card; @@ -84,11 +84,4 @@ private ContractAgreementTransferProcess buildContractAgreementTransfer( transferProcess.setErrorMessage(transferProcessEntity.getErrorDetail()); return transferProcess; } - - @NotNull - private AssetDto buildAssetDto(@NonNull Asset asset) { - var createdAt = utcMillisToOffsetDateTime(asset.getCreatedAt()); - var properties = mapValues(asset.getProperties(), Object::toString); - return new AssetDto(asset.getId(), createdAt, properties); - } } From bd1667ed6b0d8629c95f43df7fba0243da5042f1 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Thu, 14 Sep 2023 13:12:37 +0200 Subject: [PATCH 10/37] chore: Asset e2e Test --- .../api/common/mappers/AssetMapper.java | 2 +- .../connectors/sovity-dev/build.gradle.kts | 1 + .../de/sovity/edc/e2e/ApiWrapperTest.java | 108 ++++++++++++++++++ .../e2e/connector/ConnectorRemote.java | 31 ++++- 4 files changed, 139 insertions(+), 3 deletions(-) create mode 100644 launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/ApiWrapperTest.java diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java index 283ac86ba..7a996b6b0 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java @@ -61,7 +61,7 @@ public AssetHelperDto buildHelperDto(String assetJsonLd) { @SneakyThrows public UiAsset buildUiAssetFromAsset(Asset asset) { - var uiAsset = buildUiAssetFromAssetHelper(buildHelperDto(jsonLdObjectMapper.writeValueAsString(asset.getProperties()))); + var uiAsset = buildUiAssetFromAssetHelper(buildHelperDto(jsonLdObjectMapper.writeValueAsString(asset))); uiAsset.setId(asset.getId()); uiAsset.setPrivateProperties(asset.getPrivateProperties()); diff --git a/launchers/connectors/sovity-dev/build.gradle.kts b/launchers/connectors/sovity-dev/build.gradle.kts index e6122a0c8..e81511065 100644 --- a/launchers/connectors/sovity-dev/build.gradle.kts +++ b/launchers/connectors/sovity-dev/build.gradle.kts @@ -15,6 +15,7 @@ dependencies { testImplementation(project(":extensions:test-backend-controller")) testImplementation(project(":utils:test-connector-remote")) + testImplementation(project(":extensions:wrapper:client")) testImplementation("org.mockito:mockito-core:${mockitoVersion}") testImplementation("org.assertj:assertj-core:${assertj}") testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0") diff --git a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/ApiWrapperTest.java b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/ApiWrapperTest.java new file mode 100644 index 000000000..5a2a09171 --- /dev/null +++ b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/ApiWrapperTest.java @@ -0,0 +1,108 @@ +/* + * 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 - init + */ + +package de.sovity.edc.e2e; + +import de.sovity.edc.client.EdcClient; +import de.sovity.edc.client.gen.model.ContractAgreementTransferRequest; +import de.sovity.edc.client.gen.model.ContractAgreementTransferRequestParams; +import de.sovity.edc.client.gen.model.UiAssetCreateRequest; +import de.sovity.edc.extension.e2e.connector.ConnectorRemote; +import de.sovity.edc.extension.e2e.connector.MockDataAddressRemote; +import de.sovity.edc.extension.e2e.db.TestDatabase; +import de.sovity.edc.extension.e2e.db.TestDatabaseFactory; +import org.eclipse.edc.junit.extensions.EdcExtension; +import org.eclipse.edc.spi.query.QuerySpec; +import org.jetbrains.annotations.NotNull; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import static de.sovity.edc.extension.e2e.connector.DataTransferTestUtil.validateDataTransferred; +import static de.sovity.edc.extension.e2e.connector.config.ConnectorConfigFactory.forTestDatabase; +import static de.sovity.edc.extension.e2e.connector.config.ConnectorRemoteConfigFactory.fromConnectorConfig; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.InstanceOfAssertFactories.MAP; +import static org.eclipse.edc.spi.types.domain.DataAddress.EDC_DATA_ADDRESS_TYPE_PROPERTY; + +class ApiWrapperTest { + + private static final String PROVIDER_PARTICIPANT_ID = "provider"; + private static final String CONSUMER_PARTICIPANT_ID = "consumer"; + + public static final String DATA_SINK = "http://my-data-sink/api/stuff"; + public static final String DATA_ADDRESS_TYPE = "HttpData"; + + @RegisterExtension + static EdcExtension providerEdcContext = new EdcExtension(); + @RegisterExtension + static EdcExtension consumerEdcContext = new EdcExtension(); + + @RegisterExtension + static final TestDatabase PROVIDER_DATABASE = TestDatabaseFactory.getTestDatabase(1); + @RegisterExtension + static final TestDatabase CONSUMER_DATABASE = TestDatabaseFactory.getTestDatabase(2); + + private ConnectorRemote providerConnector; + private ConnectorRemote consumerConnector; + + private EdcClient consumerClient; + private MockDataAddressRemote dataAddress; + + @BeforeEach + void setup() { + var providerConfig = forTestDatabase(PROVIDER_PARTICIPANT_ID, 22000, PROVIDER_DATABASE); + providerEdcContext.setConfiguration(providerConfig.getProperties()); + providerConnector = new ConnectorRemote(fromConnectorConfig(providerConfig)); + + var consumerConfig = forTestDatabase(CONSUMER_PARTICIPANT_ID, 23000, CONSUMER_DATABASE); + consumerEdcContext.setConfiguration(consumerConfig.getProperties()); + consumerConnector = new ConnectorRemote(fromConnectorConfig(consumerConfig)); + + consumerClient = EdcClient.builder() + .managementApiUrl(consumerConfig.getManagementEndpoint().getUri().toString()) + .managementApiKey(consumerConfig.getProperties().get("edc.api.auth.key")) + .build(); + + // We use the provider EDC as data sink / data source (it has the test-backend-controller extension) + dataAddress = new MockDataAddressRemote(providerConnector.getConfig().getDefaultEndpoint()); + } + + @Test + void testAssetCreation() { + // arrange + var assetId = UUID.randomUUID().toString(); + + + Map dataSource = Map.of( + "name", "transfer-test", + "baseUrl", dataAddress.getDataSourceUrl("dummy test data"), + "type", "HttpData", + "proxyQueryParams", "true" + ); + providerConnector.createAsset(assetId, dataSource); + + var assets = consumerClient.uiApi().assetPage(); + + assertThat(assets.getAssets()).hasSize(1); + var asset = assets.getAssets().get(0); + assertThat(asset.getName()).isEqualTo("AssetName"); + assertThat(asset.getKeywords()).isEqualTo(List.of("keyword1", "keyword2")); + } + // TODO test policy conversion + // TODO test asset creation, make this test a full circle in data offering and consumption via the UI API +} diff --git a/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java b/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java index 1d7befd66..0a73fa6de 100644 --- a/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java +++ b/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java @@ -51,6 +51,10 @@ import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_POLICY_ATTRIBUTE; import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; import static org.eclipse.edc.spi.CoreConstants.EDC_PREFIX; +import static org.eclipse.edc.spi.types.domain.asset.Asset.PROPERTY_DESCRIPTION; +import static org.eclipse.edc.spi.types.domain.asset.Asset.PROPERTY_ID; +import static org.eclipse.edc.spi.types.domain.asset.Asset.PROPERTY_NAME; +import static org.eclipse.edc.spi.types.domain.asset.Asset.PROPERTY_VERSION; @SuppressWarnings("java:S5960") @RequiredArgsConstructor @@ -63,7 +67,30 @@ public class ConnectorRemote { private final Duration timeout = Duration.ofSeconds(60); private final JsonLd jsonLd = new TitaniumJsonLd(new ConsoleMonitor()); - public void createAsset(String assetId, Map dataAddressProperties) { + public void createAsset(String assetId, + Map dataAddressProperties) { + /*var requestBody = createObjectBuilder() + .add(CONTEXT, createObjectBuilder().add(EDC_PREFIX, EDC_NAMESPACE)) + .add("asset", createObjectBuilder() + .add(ID, assetId) + .add("properties", createObjectBuilder() + .add(PROPERTY_ID, EDC_NAMESPACE + assetId) + .add(PROPERTY_DESCRIPTION, EDC_NAMESPACE + description) + .add(PROPERTY_NAME, EDC_NAMESPACE + name) + .add(PROPERTY_VERSION, EDC_NAMESPACE + version) + ) + .add("dataAddress", createObjectBuilder(dataAddressProperties))) + .build(); + + prepareManagementApiCall() + .contentType(JSON) + .body(requestBody) + .when() + .post("/v2/assets") + .then() + .statusCode(200) + .contentType(JSON);*/ + var requestBody = createObjectBuilder() .add(CONTEXT, createObjectBuilder().add(EDC_PREFIX, EDC_NAMESPACE)) .add("asset", createObjectBuilder() @@ -348,7 +375,7 @@ public void createDataOffer( .build(); var contractDefinitionId = UUID.randomUUID().toString(); - createAsset(assetId, dataSource); + //createAsset(assetId, dataSource); var noConstraintPolicyId = createPolicy(policy); createContractDefinition( assetId, From d8fa49d511362ed7d54ce2a32bbb8855a3219175 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Thu, 14 Sep 2023 15:03:46 +0200 Subject: [PATCH 11/37] chore: AssetMapper --- .../wrapper-common-mappers/build.gradle.kts | 2 +- .../api/common/mappers/AssetMapper.java | 36 ++++++++++++------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/extensions/wrapper/wrapper-common-mappers/build.gradle.kts b/extensions/wrapper/wrapper-common-mappers/build.gradle.kts index 32a5ba9fe..bac3bc689 100644 --- a/extensions/wrapper/wrapper-common-mappers/build.gradle.kts +++ b/extensions/wrapper/wrapper-common-mappers/build.gradle.kts @@ -19,7 +19,7 @@ dependencies { api("${edcGroup}:transform-core:${edcVersion}") api(project(":extensions:wrapper:wrapper-common-api")) - + api(project(":utils:json-and-jsonld-utils")) implementation("org.apache.commons:commons-lang3:3.13.0") implementation("org.apache.commons:commons-collections4:4.4") diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java index 7a996b6b0..751917c8a 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java @@ -5,9 +5,12 @@ import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; +import de.sovity.edc.utils.JsonUtils; +import jakarta.json.JsonObject; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import org.eclipse.edc.spi.types.domain.asset.Asset; +import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import java.util.HashMap; import java.util.List; @@ -21,6 +24,27 @@ public class AssetMapper { */ private final ObjectMapper jsonLdObjectMapper; private final EdcPropertyMapperUtils edcPropertyMapperUtils; + private final TypeTransformerRegistry typeTransformerRegistry; + + @SneakyThrows + public UiAsset buildUiAssetFromAsset(Asset asset) { + var uiAsset = buildUiAssetFromAssetHelper(buildHelperDto(jsonLdObjectMapper.writeValueAsString(asset))); + + uiAsset.setId(asset.getId()); + uiAsset.setPrivateProperties(asset.getPrivateProperties()); + uiAsset.setDataAddressProperties(edcPropertyMapperUtils.truncateToMapOfString(asset.getDataAddress().getProperties())); + uiAsset.setKeywords(uiAsset.getKeywords() == null ? List.of() : uiAsset.getKeywords()); + + return uiAsset; + } + + public Asset buildAssetFromAssetPropertiesJsonLd(JsonObject json) { + return typeTransformerRegistry.transform(json, Asset.class).getContent(); + } + + private String buildJsonLd(Asset asset) { + return JsonUtils.toJson(typeTransformerRegistry.transform(asset, JsonObject.class).getContent()); + } @SneakyThrows public UiAsset buildUiAssetFromAssetJsonLd(String assetJsonLd) { @@ -59,18 +83,6 @@ public AssetHelperDto buildHelperDto(String assetJsonLd) { return mapper.readValue(assetJsonLd, AssetHelperDto.class); } - @SneakyThrows - public UiAsset buildUiAssetFromAsset(Asset asset) { - var uiAsset = buildUiAssetFromAssetHelper(buildHelperDto(jsonLdObjectMapper.writeValueAsString(asset))); - - uiAsset.setId(asset.getId()); - uiAsset.setPrivateProperties(asset.getPrivateProperties()); - uiAsset.setDataAddressProperties(edcPropertyMapperUtils.truncateToMapOfString(asset.getDataAddress().getProperties())); - uiAsset.setKeywords(uiAsset.getKeywords() == null ? List.of() : uiAsset.getKeywords()); - - return uiAsset; - } - @SneakyThrows public Asset buildAssetFromUiAssetCreateRequest(UiAssetCreateRequest uiAssetCreateRequest) { From b819c8ad48a69f11b7657794f66827ec64cb69a2 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Thu, 14 Sep 2023 17:15:18 +0200 Subject: [PATCH 12/37] ci: try fix test parallelity issues (4) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3506fedd1..eba1cd5c1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,7 +79,7 @@ jobs: - name: "Gradle: Build" uses: gradle/gradle-build-action@a4cf152f482c7ca97ef56ead29bf08bcd953284c with: - arguments: build ${{ env.GRADLE_ARGS }} + arguments: build ${{ env.GRADLE_ARGS }} org.gradle.parallel=false - name: "Gradle: Publish (Main & Release Only)" uses: gradle/gradle-build-action@a4cf152f482c7ca97ef56ead29bf08bcd953284c if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/releases/') }} From c6ec76ae87920d32ba445afe976b65c085bcf224 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Fri, 15 Sep 2023 14:36:24 +0200 Subject: [PATCH 13/37] chore: AssetMapper --- .../edc/client/AssetApiServiceTest.java | 1 - .../api/common/mappers/AssetMapper.java | 4 + .../api/common/mappers/AssetMapperTest.java | 56 ++++++--- .../mappers/utils/JsonFormatMapper.java | 56 --------- .../edc/ext/wrapper/WrapperExtension.java | 8 -- .../WrapperExtensionContextBuilder.java | 10 +- .../edc/ext/wrapper/api/ui/UiResource.java | 8 +- .../ext/wrapper/api/ui/model/AssetEntry.java | 30 ----- .../api/ui/model/ContractAgreementCard.java | 4 +- .../ui/pages/catalog/CatalogApiService.java | 2 +- .../de/sovity/edc/e2e/ApiWrapperTest.java | 108 ------------------ .../de/sovity/edc/e2e/UiApiWrapperTest.java | 30 ++++- .../sovity/edc/utils/jsonld/vocab/Prop.java | 23 ++++ 13 files changed, 102 insertions(+), 238 deletions(-) delete mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonFormatMapper.java delete mode 100644 extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetEntry.java delete mode 100644 launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/ApiWrapperTest.java diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java index de8c43871..6a4d30d8e 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java @@ -71,7 +71,6 @@ void assetPage(AssetService assetStore) { assertThat(asset.getPrivateProperties()).isEqualTo(privateProperties); } - @Test void assetPageSorting(AssetService assetService) { // arrange diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java index 872ce7f8c..a553352f5 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java @@ -6,6 +6,9 @@ import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import de.sovity.edc.utils.JsonUtils; +import de.sovity.edc.utils.jsonld.JsonLdUtils; +import de.sovity.edc.utils.jsonld.vocab.Prop; +import jakarta.json.Json; import jakarta.json.JsonObject; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; @@ -15,6 +18,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; @RequiredArgsConstructor diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java index f88ab57ba..f56575a19 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java @@ -1,17 +1,18 @@ package de.sovity.edc.ext.wrapper.api.common.mappers; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.JsonFormatMapper; +import de.sovity.edc.utils.jsonld.vocab.Prop; import lombok.SneakyThrows; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.junit.jupiter.MockitoExtension; - import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; +import static jakarta.json.Json.createArrayBuilder; +import static jakarta.json.Json.createObjectBuilder; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) @@ -19,8 +20,6 @@ class AssetMapperTest { @InjectMocks AssetMapper assetMapper; - @InjectMocks - JsonFormatMapper jsonFormatMapper; @Test @SneakyThrows @@ -51,8 +50,13 @@ void test_buildAssetDto() { @SneakyThrows void test_KeywordsAsSingleString() { + // Arrange + var requestBody = createObjectBuilder() + .add(Prop.Dcat.KEYWORDS, createArrayBuilder(List.of("SingleElement"))) + .build(); + // Act - var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(jsonFormatMapper.mapKeywords("{\"keywords\":\"SingleElement\"}")); + var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(requestBody.toString()); // Assert assertThat(uiAsset).isNotNull(); @@ -63,11 +67,15 @@ void test_KeywordsAsSingleString() { @SneakyThrows void test_StringsAsList() { + // Arrange + var requestBody = createObjectBuilder() + .add(Prop.DCMI.title, createObjectBuilder() + .add(Prop.VALUE, "AssetName") + .add(Prop.LANGUAGE, "en")) + .build(); + // Act - var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(jsonFormatMapper.mapTitleList( - "{\"title\":" + - "[{\"value\":\"AssetName\",\"language\":\"en\"}," + - "{\"value\":\"AssetNameinFrench\",\"language\":\"fr\"}]}")); + var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(requestBody.toString()); // Assert assertThat(uiAsset).isNotNull(); @@ -78,11 +86,18 @@ void test_StringsAsList() { @SneakyThrows void test_StringsAsMap() { + // Arrange + var requestBody = createObjectBuilder() + .add(Prop.DCMI.title, createArrayBuilder() + .add(createObjectBuilder() + .add(Prop.TYPE, "SomeType") + .add(Prop.VALUE, "AssetName") + ) + ) + .build(); + // Act - var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(jsonFormatMapper.mapTitle( - "{\"title\":" + - "{\"@type\":\"SomeType\"," + - "\"@value\":\"AssetName\"}}")); + var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(requestBody.toString()); // Assert assertThat(uiAsset).isNotNull(); @@ -93,9 +108,13 @@ void test_StringsAsMap() { @SneakyThrows void test_badBooleanValue() { + //Arrange + var requestBody = createObjectBuilder() + .add(Prop.SOVITYSEMANTIC.METHOD, "wrongBooleanValue") + .build(); + // Act - var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(jsonFormatMapper.mapBooleanHintProxyMethod( - "{\"httpDatasourceHintsProxyMethod\":\"wrongBooleanValue\"}")); + var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(requestBody.toString()); // Assert assertThat(uiAsset).isNotNull(); @@ -106,8 +125,13 @@ void test_badBooleanValue() { @SneakyThrows void test_noBooleanValue() { + //Arrange + var requestBody = createObjectBuilder() + .add(Prop.SOVITYSEMANTIC.METHOD, "") + .build(); + // Act - var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(jsonFormatMapper.mapBooleanHintProxyMethod("{}")); + var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(requestBody.toString()); // Assert assertThat(uiAsset).isNotNull(); diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonFormatMapper.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonFormatMapper.java deleted file mode 100644 index 34dd146a6..000000000 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonFormatMapper.java +++ /dev/null @@ -1,56 +0,0 @@ -package de.sovity.edc.ext.wrapper.api.common.mappers.utils; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import lombok.SneakyThrows; - -public class JsonFormatMapper { - - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(); - private static final String DCAT_KEYWORD = "http://www.w3.org/ns/dcat#keyword"; - private static final String DC_TERMS_TITLE = "http://purl.org/dc/terms/title"; - private static final String SOVITY_HINTS_PROXY_METHOD = "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyMethod"; - - @SneakyThrows - public String mapKeywords(String oldJsonStr) { - return mapSingleValue(oldJsonStr, "keywords", DCAT_KEYWORD); - } - - @SneakyThrows - public String mapTitle(String oldJsonStr) { - return mapSingleValue(oldJsonStr, "title", DC_TERMS_TITLE); - } - - @SneakyThrows - public String mapBooleanHintProxyMethod(String oldJsonStr) { - return mapSingleValue(oldJsonStr, "httpDatasourceHintsProxyMethod", SOVITY_HINTS_PROXY_METHOD); - } - - @SneakyThrows - public String mapTitleList(String oldJsonStr) { - JsonNode oldJson = OBJECT_MAPPER.readTree(oldJsonStr); - ObjectNode newJson = OBJECT_MAPPER.createObjectNode(); - - if (oldJson.has("title")) { - ArrayNode titleArray = OBJECT_MAPPER.createArrayNode(); - for (JsonNode item : oldJson.get("title")) { - ObjectNode titleObject = OBJECT_MAPPER.createObjectNode(); - titleObject.set("@value", item.get("value")); - titleObject.set("@language", item.get("language")); - titleArray.add(titleObject); - } - newJson.set(DC_TERMS_TITLE, titleArray); - } - - return OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(newJson); - } - - private String mapSingleValue(String jsonStr, String oldKey, String newKey) throws Exception { - JsonNode oldJson = OBJECT_MAPPER.readTree(jsonStr); - ObjectNode newJson = OBJECT_MAPPER.createObjectNode(); - newJson.set(newKey, oldJson.get(oldKey)); - return OBJECT_MAPPER.writerWithDefaultPrettyPrinter().writeValueAsString(newJson); - } -} diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtension.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtension.java index 91f031d55..1b932fe79 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtension.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtension.java @@ -17,8 +17,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import com.fasterxml.jackson.databind.SerializationFeature; -import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; import org.eclipse.edc.connector.api.management.configuration.ManagementApiConfiguration; import org.eclipse.edc.connector.api.management.configuration.transform.ManagementApiTypeTransformerRegistry; import org.eclipse.edc.connector.contract.spi.negotiation.store.ContractNegotiationStore; @@ -43,8 +41,6 @@ import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.eclipse.edc.web.spi.WebService; -import static org.eclipse.edc.spi.CoreConstants.JSON_LD; - public class WrapperExtension implements ServiceExtension { public static final String EXTENSION_NAME = "WrapperExtension"; @@ -95,13 +91,9 @@ public String name() { @Override public void initialize(ServiceExtensionContext context) { - var objectMapper = typeManager.getMapper(JSON_LD); - objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); - objectMapper.registerModule(new JavaTimeModule()); var objectMapper = typeManager.getMapper(CoreConstants.JSON_LD); fixObjectMapperDateSerialization(objectMapper); - var wrapperExtensionContext = WrapperExtensionContextBuilder.buildContext( assetIndex, assetService, diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java index dbb5c6ce8..a93d589ed 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java @@ -25,7 +25,6 @@ import de.sovity.edc.ext.wrapper.api.common.mappers.utils.PolicyValidator; import de.sovity.edc.ext.wrapper.api.ui.UiResource; import de.sovity.edc.ext.wrapper.api.ui.pages.asset.AssetApiService; -import de.sovity.edc.ext.wrapper.api.ui.pages.asset.AssetBuilder; import de.sovity.edc.ext.wrapper.api.ui.pages.catalog.CatalogApiService; import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.ContractDefinitionApiService; import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.ContractDefinitionBuilder; @@ -114,12 +113,10 @@ public static WrapperExtensionContext buildContext( var constraintExtractor = new ConstraintExtractor(policyValidator, atomicConstraintMapper); var policyMapper = new PolicyMapper( constraintExtractor, - atomicConstraintMapper); - var edcPropertyMapperUtils = new EdcPropertyMapperUtils(); - var assetMapper = new AssetMapper(objectMapper, edcPropertyMapperUtils); atomicConstraintMapper, - typeTransformerRegistry - ); + typeTransformerRegistry); + var edcPropertyMapperUtils = new EdcPropertyMapperUtils(); + var assetMapper = new AssetMapper(objectMapper, edcPropertyMapperUtils, typeTransformerRegistry); var transferProcessStateService = new TransferProcessStateService(); var contractAgreementPageCardBuilder = new ContractAgreementPageCardBuilder( policyMapper, @@ -170,7 +167,6 @@ public static WrapperExtensionContext buildContext( policyMapper); var dataOfferBuilder = new DspDataOfferBuilder(jsonLd); var dspCatalogService = new DspCatalogService(catalogService, dataOfferBuilder); - var assetMapper = new AssetMapper(typeTransformerRegistry); var catalogApiService = new CatalogApiService(assetMapper, policyMapper, dspCatalogService); var contractOfferMapper = new ContractOfferMapper(policyMapper); var contractNegotiationBuilder = new ContractNegotiationBuilder(contractOfferMapper); diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java index b3ebefb85..171faef1e 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/UiResource.java @@ -16,26 +16,24 @@ import de.sovity.edc.ext.wrapper.api.common.model.AssetDto; import de.sovity.edc.ext.wrapper.api.common.model.PolicyDefinitionCreateRequest; -import de.sovity.edc.ext.wrapper.api.ui.model.AssetCreateRequest; -import de.sovity.edc.ext.wrapper.api.ui.model.AssetPage; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import de.sovity.edc.ext.wrapper.api.ui.model.AssetPage; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementPage; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementTransferRequest; import de.sovity.edc.ext.wrapper.api.ui.model.ContractDefinitionPage; import de.sovity.edc.ext.wrapper.api.ui.model.ContractDefinitionRequest; -import de.sovity.edc.ext.wrapper.api.ui.model.UiContractNegotiation; import de.sovity.edc.ext.wrapper.api.ui.model.ContractNegotiationRequest; import de.sovity.edc.ext.wrapper.api.ui.model.IdResponseDto; import de.sovity.edc.ext.wrapper.api.ui.model.PolicyDefinitionPage; import de.sovity.edc.ext.wrapper.api.ui.model.TransferHistoryPage; +import de.sovity.edc.ext.wrapper.api.ui.model.UiContractNegotiation; import de.sovity.edc.ext.wrapper.api.ui.model.UiDataOffer; import de.sovity.edc.ext.wrapper.api.ui.pages.asset.AssetApiService; import de.sovity.edc.ext.wrapper.api.ui.pages.catalog.CatalogApiService; -import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.ContractAgreementPageApiService; -import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.ContractAgreementTransferApiService; import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.ContractDefinitionApiService; import de.sovity.edc.ext.wrapper.api.ui.pages.contract_negotiations.ContractNegotiationApiService; +import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.ContractAgreementPageApiService; +import de.sovity.edc.ext.wrapper.api.ui.pages.contracts.ContractAgreementTransferApiService; import de.sovity.edc.ext.wrapper.api.ui.pages.policy.PolicyDefinitionApiService; import de.sovity.edc.ext.wrapper.api.ui.pages.transferhistory.TransferHistoryPageApiService; import de.sovity.edc.ext.wrapper.api.ui.pages.transferhistory.TransferHistoryPageAssetFetcherService; diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetEntry.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetEntry.java deleted file mode 100644 index ce4b8fa06..000000000 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/AssetEntry.java +++ /dev/null @@ -1,30 +0,0 @@ -/* - * 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.model; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Data; - -import java.util.Map; - -@Data -@Schema(description = "Asset Entry for Asset Page") -public class AssetEntry { - @Schema(description = "Asset Properties", requiredMode = Schema.RequiredMode.REQUIRED) - private Map properties; - - @Schema(description = "Asset Private Properties", requiredMode = Schema.RequiredMode.REQUIRED) - private Map privateProperties; -} diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java index 02ca14d14..4d5a33cc1 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractAgreementCard.java @@ -14,10 +14,8 @@ package de.sovity.edc.ext.wrapper.api.ui.model; -import de.sovity.edc.ext.wrapper.api.common.model.AssetDto; -import de.sovity.edc.ext.wrapper.api.common.model.UiPolicy; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; -import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyDto; +import de.sovity.edc.ext.wrapper.api.common.model.UiPolicy; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiService.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiService.java index 8195cbbbc..e6ac69417 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiService.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiService.java @@ -62,7 +62,7 @@ private UiContractOffer buildContractOffer(DspContractOffer contractOffer) { private UiAsset buildUiAsset(DspDataOffer dataOffer) { var asset = assetMapper.buildAssetFromAssetPropertiesJsonLd(dataOffer.getAssetPropertiesJsonLd()); - return assetMapper.buildUiAsset(asset); + return assetMapper.buildUiAssetFromAsset(asset); } private UiPolicy buildUiPolicy(DspContractOffer contractOffer) { diff --git a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/ApiWrapperTest.java b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/ApiWrapperTest.java deleted file mode 100644 index 5a2a09171..000000000 --- a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/ApiWrapperTest.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * 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 - init - */ - -package de.sovity.edc.e2e; - -import de.sovity.edc.client.EdcClient; -import de.sovity.edc.client.gen.model.ContractAgreementTransferRequest; -import de.sovity.edc.client.gen.model.ContractAgreementTransferRequestParams; -import de.sovity.edc.client.gen.model.UiAssetCreateRequest; -import de.sovity.edc.extension.e2e.connector.ConnectorRemote; -import de.sovity.edc.extension.e2e.connector.MockDataAddressRemote; -import de.sovity.edc.extension.e2e.db.TestDatabase; -import de.sovity.edc.extension.e2e.db.TestDatabaseFactory; -import org.eclipse.edc.junit.extensions.EdcExtension; -import org.eclipse.edc.spi.query.QuerySpec; -import org.jetbrains.annotations.NotNull; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.RegisterExtension; - -import java.util.List; -import java.util.Map; -import java.util.UUID; - -import static de.sovity.edc.extension.e2e.connector.DataTransferTestUtil.validateDataTransferred; -import static de.sovity.edc.extension.e2e.connector.config.ConnectorConfigFactory.forTestDatabase; -import static de.sovity.edc.extension.e2e.connector.config.ConnectorRemoteConfigFactory.fromConnectorConfig; -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.InstanceOfAssertFactories.MAP; -import static org.eclipse.edc.spi.types.domain.DataAddress.EDC_DATA_ADDRESS_TYPE_PROPERTY; - -class ApiWrapperTest { - - private static final String PROVIDER_PARTICIPANT_ID = "provider"; - private static final String CONSUMER_PARTICIPANT_ID = "consumer"; - - public static final String DATA_SINK = "http://my-data-sink/api/stuff"; - public static final String DATA_ADDRESS_TYPE = "HttpData"; - - @RegisterExtension - static EdcExtension providerEdcContext = new EdcExtension(); - @RegisterExtension - static EdcExtension consumerEdcContext = new EdcExtension(); - - @RegisterExtension - static final TestDatabase PROVIDER_DATABASE = TestDatabaseFactory.getTestDatabase(1); - @RegisterExtension - static final TestDatabase CONSUMER_DATABASE = TestDatabaseFactory.getTestDatabase(2); - - private ConnectorRemote providerConnector; - private ConnectorRemote consumerConnector; - - private EdcClient consumerClient; - private MockDataAddressRemote dataAddress; - - @BeforeEach - void setup() { - var providerConfig = forTestDatabase(PROVIDER_PARTICIPANT_ID, 22000, PROVIDER_DATABASE); - providerEdcContext.setConfiguration(providerConfig.getProperties()); - providerConnector = new ConnectorRemote(fromConnectorConfig(providerConfig)); - - var consumerConfig = forTestDatabase(CONSUMER_PARTICIPANT_ID, 23000, CONSUMER_DATABASE); - consumerEdcContext.setConfiguration(consumerConfig.getProperties()); - consumerConnector = new ConnectorRemote(fromConnectorConfig(consumerConfig)); - - consumerClient = EdcClient.builder() - .managementApiUrl(consumerConfig.getManagementEndpoint().getUri().toString()) - .managementApiKey(consumerConfig.getProperties().get("edc.api.auth.key")) - .build(); - - // We use the provider EDC as data sink / data source (it has the test-backend-controller extension) - dataAddress = new MockDataAddressRemote(providerConnector.getConfig().getDefaultEndpoint()); - } - - @Test - void testAssetCreation() { - // arrange - var assetId = UUID.randomUUID().toString(); - - - Map dataSource = Map.of( - "name", "transfer-test", - "baseUrl", dataAddress.getDataSourceUrl("dummy test data"), - "type", "HttpData", - "proxyQueryParams", "true" - ); - providerConnector.createAsset(assetId, dataSource); - - var assets = consumerClient.uiApi().assetPage(); - - assertThat(assets.getAssets()).hasSize(1); - var asset = assets.getAssets().get(0); - assertThat(asset.getName()).isEqualTo("AssetName"); - assertThat(asset.getKeywords()).isEqualTo(List.of("keyword1", "keyword2")); - } - // TODO test policy conversion - // TODO test asset creation, make this test a full circle in data offering and consumption via the UI API -} diff --git a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index ef5f1c5a7..cd8686598 100644 --- a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -31,12 +31,14 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; +import java.util.List; +import java.util.Map; import java.util.UUID; +import static org.assertj.core.api.Assertions.assertThat; import static de.sovity.edc.extension.e2e.connector.DataTransferTestUtil.validateDataTransferred; import static de.sovity.edc.extension.e2e.connector.config.ConnectorConfigFactory.forTestDatabase; import static de.sovity.edc.extension.e2e.connector.config.ConnectorRemoteConfigFactory.fromConnectorConfig; -import static org.assertj.core.api.Assertions.assertThat; class UiApiWrapperTest { @@ -102,15 +104,37 @@ void provide_consume_assetMapping_policyMapping() { // assert assertThat(dataOffer.getEndpoint()).isEqualTo(getProtocolEndpoint(providerConnector)); assertThat(dataOffer.getParticipantId()).isEqualTo(PROVIDER_PARTICIPANT_ID); - assertThat(dataOffer.getAsset().getAssetId()).isEqualTo(assetId); + assertThat(dataOffer.getAsset().getId()).isEqualTo(assetId); validateDataTransferred(dataAddress.getDataSinkSpyUrl(), data); } + @Test + void testAssetCreation() { + // arrange + var assetId = UUID.randomUUID().toString(); + + + Map dataSource = Map.of( + "name", "transfer-test", + "baseUrl", dataAddress.getDataSourceUrl("dummy test data"), + "type", "HttpData", + "proxyQueryParams", "true" + ); + providerConnector.createAsset(assetId, dataSource); + + var assets = consumerClient.uiApi().assetPage(); + + assertThat(assets.getAssets()).hasSize(1); + var asset = assets.getAssets().get(0); + assertThat(asset.getName()).isEqualTo("AssetName"); + assertThat(asset.getKeywords()).isEqualTo(List.of("keyword1", "keyword2")); + } + private UiContractNegotiation negotiate(UiDataOffer dataOffer, UiContractOffer contractOffer) { var negotiationRequest = ContractNegotiationRequest.builder() .counterPartyAddress(dataOffer.getEndpoint()) .counterPartyParticipantId(dataOffer.getParticipantId()) - .assetId(dataOffer.getAsset().getAssetId()) + .assetId(dataOffer.getAsset().getId()) .contractOfferId(contractOffer.getContractOfferId()) .policyJsonLd(contractOffer.getPolicy().getPolicyJsonLd()) .build(); diff --git a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java index 8f9de2574..f3dcc6b39 100644 --- a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java +++ b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java @@ -19,6 +19,8 @@ public class Prop { public final String ID = "@id"; public final String TYPE = "@type"; + public final String VALUE = "@value"; + public final String LANGUAGE = "@language"; @UtilityClass public class Edc { @@ -47,6 +49,7 @@ public class Dcat { public final String DATASET = CTX_WRONG_BUT_USED_BY_CORE_EDC + "dataset"; public final String DISTRIBUTION = CTX_WRONG_BUT_USED_BY_CORE_EDC + "distribution"; public final String VERSION = CTX + "version"; + public final String KEYWORDS = CTX + "keyword"; } /** @@ -57,4 +60,24 @@ public class Odrl { public final String CTX = "http://www.w3.org/ns/odrl/2/"; public final String HAS_POLICY = CTX + "hasPolicy"; } + + /** + * DCMI Metadata Terms Vocabulary, see DCAT 3 Specification + */ + @UtilityClass + public class DCMI { + public final String CTX = "http://purl.org/dc/terms/"; + public final String title = CTX + "title"; + } + + /** + * DCMI Metadata Terms Vocabulary, see DCAT 3 Specification + */ + @UtilityClass + public class SOVITYSEMANTIC { + public final String CTX = "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxy"; + public final String METHOD = CTX + "method/"; + public final String PATH = CTX + "path/"; + + } } From 212e3632436de495e25a40100cc8e503801ce9fa Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Fri, 15 Sep 2023 14:52:06 +0200 Subject: [PATCH 14/37] fix: UiWrapperTest --- .../de/sovity/edc/e2e/UiApiWrapperTest.java | 1 - .../sovity/edc/utils/jsonld/vocab/Prop.java | 1 + utils/test-connector-remote/build.gradle.kts | 1 + .../e2e/connector/ConnectorRemote.java | 27 +++---------------- 4 files changed, 5 insertions(+), 25 deletions(-) diff --git a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index cd8686598..69caf33d3 100644 --- a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -113,7 +113,6 @@ void testAssetCreation() { // arrange var assetId = UUID.randomUUID().toString(); - Map dataSource = Map.of( "name", "transfer-test", "baseUrl", dataAddress.getDataSourceUrl("dummy test data"), diff --git a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java index f3dcc6b39..b8d36aeaf 100644 --- a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java +++ b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java @@ -68,6 +68,7 @@ public class Odrl { public class DCMI { public final String CTX = "http://purl.org/dc/terms/"; public final String title = CTX + "title"; + public final String description = CTX + "description"; } /** diff --git a/utils/test-connector-remote/build.gradle.kts b/utils/test-connector-remote/build.gradle.kts index 38b44059b..53563830f 100644 --- a/utils/test-connector-remote/build.gradle.kts +++ b/utils/test-connector-remote/build.gradle.kts @@ -19,6 +19,7 @@ dependencies { api("${edcGroup}:junit:${edcVersion}") api("org.awaitility:awaitility:${awaitilityVersion}") + api(project(":utils:json-and-jsonld-utils")) implementation("${edcGroup}:sql-core:${edcVersion}") implementation("${edcGroup}:json-ld-spi:${edcVersion}") implementation("${edcGroup}:json-ld:${edcVersion}") diff --git a/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java b/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java index 523b157df..f727e01aa 100644 --- a/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java +++ b/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java @@ -38,6 +38,7 @@ import java.util.UUID; import java.util.concurrent.atomic.AtomicReference; +import de.sovity.edc.utils.jsonld.vocab.Prop; import static io.restassured.RestAssured.given; import static io.restassured.http.ContentType.JSON; import static jakarta.json.Json.createObjectBuilder; @@ -69,34 +70,12 @@ public class ConnectorRemote { public void createAsset(String assetId, Map dataAddressProperties) { - /*var requestBody = createObjectBuilder() - .add(CONTEXT, createObjectBuilder().add(EDC_PREFIX, EDC_NAMESPACE)) - .add("asset", createObjectBuilder() - .add(ID, assetId) - .add("properties", createObjectBuilder() - .add(PROPERTY_ID, EDC_NAMESPACE + assetId) - .add(PROPERTY_DESCRIPTION, EDC_NAMESPACE + description) - .add(PROPERTY_NAME, EDC_NAMESPACE + name) - .add(PROPERTY_VERSION, EDC_NAMESPACE + version) - ) - .add("dataAddress", createObjectBuilder(dataAddressProperties))) - .build(); - - prepareManagementApiCall() - .contentType(JSON) - .body(requestBody) - .when() - .post("/v2/assets") - .then() - .statusCode(200) - .contentType(JSON);*/ - var requestBody = createObjectBuilder() .add(CONTEXT, createObjectBuilder().add(EDC_PREFIX, EDC_NAMESPACE)) .add("asset", createObjectBuilder() .add(ID, assetId) .add("properties", createObjectBuilder() - .add("description", "description"))) + .add(Prop.DCMI.description, "description"))) .add("dataAddress", createObjectBuilder(dataAddressProperties)) .build(); @@ -375,7 +354,7 @@ public void createDataOffer( .build(); var contractDefinitionId = UUID.randomUUID().toString(); - //createAsset(assetId, dataSource); + createAsset(assetId, dataSource); var noConstraintPolicyId = createPolicy(policy); createContractDefinition( assetId, From 6e8238a9a7037808dd82459ec6f2ba7063a6a52d Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Fri, 15 Sep 2023 16:18:24 +0200 Subject: [PATCH 15/37] fix: PR Revision --- .../edc/client/AssetApiServiceTest.java | 6 +- .../edc/client/ContractAgreementPageTest.java | 3 +- .../ext/wrapper/api/common/model/UiAsset.java | 12 +-- .../common/model/UiAssetCreateRequest.java | 7 +- .../model/utils/CustomDeserializer.java | 11 +-- .../api/common/mappers/AssetMapper.java | 89 +----------------- ...> AssetCreatorOrganizationNameJsonLd.java} | 7 +- ...tion.java => AssetDistributionJsonLd.java} | 7 +- .../common/mappers/utils/AssetHelperDto.java | 10 +- ...blisher.java => AssetPublisherJsonLd.java} | 7 +- .../common/mappers/utils/UiAssetBuilder.java | 94 +++++++++++++++++++ .../api/common/mappers/AssetMapperTest.java | 28 +++--- .../utils/EdcPropertyMapperUtilsTest.java} | 9 +- .../WrapperExtensionContextBuilder.java | 6 +- .../api/ui/pages/asset/AssetApiService.java | 17 +--- .../services/TransferRequestBuilder.java | 4 +- .../ext/wrapper/utils/EdcPropertyUtils.java | 71 -------------- .../usecase/services/OfferingServiceTest.java | 4 +- .../sovity/edc/utils/jsonld/vocab/Prop.java | 13 +-- .../e2e/connector/ConnectorRemote.java | 12 +-- 20 files changed, 159 insertions(+), 258 deletions(-) rename extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/{UiAssetCreator.java => AssetCreatorOrganizationNameJsonLd.java} (71%) rename extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/{UiAssetDistribution.java => AssetDistributionJsonLd.java} (70%) rename extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/{UiAssetPublisher.java => AssetPublisherJsonLd.java} (71%) create mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java rename extensions/wrapper/{wrapper/src/test/java/de/sovity/edc/ext/wrapper/utils/EdcPropertyUtilsTest.java => wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtilsTest.java} (83%) delete mode 100644 extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/utils/EdcPropertyUtils.java diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java index 6a4d30d8e..17ede9770 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java @@ -15,7 +15,7 @@ import de.sovity.edc.client.gen.model.UiAssetCreateRequest; -import de.sovity.edc.ext.wrapper.utils.EdcPropertyUtils; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; import lombok.SneakyThrows; import org.eclipse.edc.connector.spi.asset.AssetService; import org.eclipse.edc.junit.annotations.ApiTest; @@ -40,12 +40,12 @@ public class AssetApiServiceTest { public static final String DATA_SINK = "http://my-data-sink/api/stuff"; public static final String DATA_ADDRESS_TYPE = "HttpData"; - EdcPropertyUtils edcPropertyUtils; + EdcPropertyMapperUtils edcPropertyUtils; @BeforeEach void setUp(EdcExtension extension) { TestUtils.setupExtension(extension); - edcPropertyUtils = new EdcPropertyUtils(); + edcPropertyUtils = new EdcPropertyMapperUtils(); } @Test diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/ContractAgreementPageTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/ContractAgreementPageTest.java index 6bbecf0fe..9b199d2f5 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/ContractAgreementPageTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/ContractAgreementPageTest.java @@ -17,6 +17,7 @@ import de.sovity.edc.client.gen.model.ContractAgreementCard; import de.sovity.edc.client.gen.model.TransferProcessState; import de.sovity.edc.client.gen.model.UiPolicyConstraint; +import de.sovity.edc.utils.jsonld.vocab.Prop; import org.eclipse.edc.connector.contract.spi.negotiation.store.ContractNegotiationStore; import org.eclipse.edc.connector.contract.spi.types.agreement.ContractAgreement; import org.eclipse.edc.connector.contract.spi.types.negotiation.ContractNegotiation; @@ -178,7 +179,7 @@ private ContractNegotiation contractDefinition(int contract) { private Asset asset(String assetId) { return Asset.Builder.newInstance() .id(assetId) - .property("http://www.w3.org/ns/dcat#landingPage", "X") + .property(Prop.Dcat.LANDING_PAGE, "X") .createdAt(todayEpochMillis) .dataAddress(dataAddress()) .build(); diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java index 39126afaa..63837f864 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java @@ -38,9 +38,6 @@ public class UiAsset { @Schema(description = "Asset Id", requiredMode = Schema.RequiredMode.REQUIRED) private String id; - @Schema(description = "Asset Name", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - private String name; - @Schema(description = "Asset Title", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String title; @@ -51,10 +48,10 @@ public class UiAsset { private String description; @Schema(description = "Asset Organization Name", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - private String creator; + private String creatorOrganizationName; @Schema(description = "Asset Homepage", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - private String publisher; + private String publisherHomepage; @Schema(description = "License URL", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String licenseUrl; @@ -68,7 +65,7 @@ public class UiAsset { @Schema(description = "Asset MediaType", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String distribution; - @Schema(description = "Landing Page URL", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @Schema(description = "Homepage URL associated with the Asset", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String landingPageUrl; @Schema(description = "HTTP Datasource Hints Proxy Method", requiredMode = Schema.RequiredMode.NOT_REQUIRED) @@ -107,9 +104,6 @@ public class UiAsset { @Schema(description = "Asset Json Properties", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private Map additionalJsonProperties; - @Schema(description = "Asset DataAddress Properties", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - private Map dataAddressProperties; - @Schema(description = "Contains the entire asset in its original expanded JSON-LD format", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String assetJsonLd; } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java index 716168d0c..834bbe250 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java @@ -32,9 +32,6 @@ public class UiAssetCreateRequest { @Schema(description = "Asset Id", requiredMode = Schema.RequiredMode.REQUIRED) private String id; - @Schema(description = "Asset Name", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - private String name; - @Schema(description = "Asset Title", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String title; @@ -45,10 +42,10 @@ public class UiAssetCreateRequest { private String description; @Schema(description = "Asset Organization Name", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - private String creator; + private String creatorOrganizationName; @Schema(description = "Asset Homepage", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - private String publisher; + private String publisherHomepage; @Schema(description = "License URL", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String licenseUrl; diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java index ff67b2b62..faaf12e51 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java @@ -7,23 +7,20 @@ import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.deser.ContextualDeserializer; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; import lombok.SneakyThrows; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; +@NoArgsConstructor +@AllArgsConstructor public class CustomDeserializer extends JsonDeserializer implements ContextualDeserializer { private JavaType type; - public CustomDeserializer() { - } - - public CustomDeserializer(JavaType type) { - this.type = type; - } - @Override public JsonDeserializer createContextual(DeserializationContext deserializationContext, BeanProperty beanProperty) throws JsonMappingException { JavaType type = deserializationContext.getContextualType() != null diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java index a553352f5..f1993072f 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java @@ -1,10 +1,8 @@ package de.sovity.edc.ext.wrapper.api.common.mappers; import com.fasterxml.jackson.databind.ObjectMapper; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.AssetHelperDto; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.UiAssetBuilder; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; -import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import de.sovity.edc.utils.JsonUtils; import de.sovity.edc.utils.jsonld.JsonLdUtils; import de.sovity.edc.utils.jsonld.vocab.Prop; @@ -15,9 +13,7 @@ import org.eclipse.edc.spi.types.domain.asset.Asset; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.Optional; @@ -27,16 +23,16 @@ public class AssetMapper { * This Object Mapper must be able to handle JSON-LD serialization / deserialization. */ private final ObjectMapper jsonLdObjectMapper; - private final EdcPropertyMapperUtils edcPropertyMapperUtils; private final TypeTransformerRegistry typeTransformerRegistry; + private final UiAssetBuilder uiAssetBuilder; + @SneakyThrows public UiAsset buildUiAssetFromAsset(Asset asset) { - var uiAsset = buildUiAssetFromAssetHelper(buildHelperDto(jsonLdObjectMapper.writeValueAsString(asset))); + var uiAsset = uiAssetBuilder.buildUiAssetFromAssetHelper(uiAssetBuilder.buildHelperDto(jsonLdObjectMapper.writeValueAsString(asset))); uiAsset.setId(asset.getId()); uiAsset.setPrivateProperties(asset.getPrivateProperties()); - uiAsset.setDataAddressProperties(edcPropertyMapperUtils.truncateToMapOfString(asset.getDataAddress().getProperties())); uiAsset.setKeywords(uiAsset.getKeywords() == null ? List.of() : uiAsset.getKeywords()); return uiAsset; @@ -50,83 +46,6 @@ private String buildJsonLd(Asset asset) { return JsonUtils.toJson(typeTransformerRegistry.transform(asset, JsonObject.class).getContent()); } - @SneakyThrows - public UiAsset buildUiAssetFromAssetJsonLd(String assetJsonLd) { - return buildUiAssetFromAssetHelper(buildHelperDto(assetJsonLd)); - } - - public UiAsset buildUiAssetFromAssetHelper(AssetHelperDto assetHelperDto) { - - return UiAsset.builder() - .name(assetHelperDto.getNs()) - .keywords(assetHelperDto.getKeywords()) - .version(assetHelperDto.getVersion()) - .licenseUrl(assetHelperDto.getLicense()) - .creator(assetHelperDto.getCreator() != null ? assetHelperDto.getCreator().getName() : null) - .publisher(assetHelperDto.getPublisher() != null ? assetHelperDto.getPublisher().getName() : null) - .description(assetHelperDto.getDescription()) - .language(assetHelperDto.getLanguage()) - .title(assetHelperDto.getTitle()) - .httpDatasourceHintsProxyMethod(assetHelperDto.getHttpDatasourceHintsProxyMethod()) - .httpDatasourceHintsProxyPath(assetHelperDto.getHttpDatasourceHintsProxyPath()) - .httpDatasourceHintsProxyQueryParams(assetHelperDto.getHttpDatasourceHintsProxyQueryParams()) - .httpDatasourceHintsProxyBody(assetHelperDto.getHttpDatasourceHintsProxyBody()) - .dataCategory(assetHelperDto.getDataCategory()) - .dataSubcategory(assetHelperDto.getDataSubcategory()) - .dataModel(assetHelperDto.getDataModel()) - .geoReferenceMethod(assetHelperDto.getGeoReferenceMethod()) - .transportMode(assetHelperDto.getTransportMode()) - .landingPageUrl(assetHelperDto.getLandingPage()) - .distribution(assetHelperDto.getDistribution() != null ? assetHelperDto.getDistribution().getName() : null) - .build(); - } - - @SneakyThrows - public AssetHelperDto buildHelperDto(String assetJsonLd) { - ObjectMapper mapper = new ObjectMapper(); - return mapper.readValue(assetJsonLd, AssetHelperDto.class); - } - - @SneakyThrows - public Asset buildAssetFromUiAssetCreateRequest(UiAssetCreateRequest uiAssetCreateRequest) { - - Asset.Builder assetBuilder = Asset.Builder - .newInstance() - .id(uiAssetCreateRequest.getId()) - .name(uiAssetCreateRequest.getName()) - .description(uiAssetCreateRequest.getDescription()) - .version(uiAssetCreateRequest.getVersion()) - .dataAddress(edcPropertyMapperUtils.buildDataAddress(uiAssetCreateRequest.getDataAddressProperties())); - - Map additionalProps = new HashMap<>(); - additionalProps.put("title", uiAssetCreateRequest.getTitle()); - additionalProps.put("language", uiAssetCreateRequest.getLanguage()); - additionalProps.put("creator", uiAssetCreateRequest.getCreator()); - additionalProps.put("publisher", uiAssetCreateRequest.getPublisher()); - additionalProps.put("licenseUrl", uiAssetCreateRequest.getLicenseUrl()); - additionalProps.put("keywords", uiAssetCreateRequest.getKeywords()); - additionalProps.put("distribution", uiAssetCreateRequest.getDistribution()); - additionalProps.put("landingPageUrl", uiAssetCreateRequest.getLandingPageUrl()); - additionalProps.put("dataCategory", uiAssetCreateRequest.getDataCategory()); - additionalProps.put("dataSubcategory", uiAssetCreateRequest.getDataSubcategory()); - additionalProps.put("dataModel", uiAssetCreateRequest.getDataModel()); - additionalProps.put("geoReferenceMethod", uiAssetCreateRequest.getGeoReferenceMethod()); - additionalProps.put("transportMode", uiAssetCreateRequest.getTransportMode()); - - if(uiAssetCreateRequest.getAdditionalProperties() != null) { - additionalProps.putAll(uiAssetCreateRequest.getAdditionalProperties()); - } - if(uiAssetCreateRequest.getPrivateProperties() != null) { - assetBuilder.privateProperties(new HashMap<>(uiAssetCreateRequest.getPrivateProperties())); - } - if(uiAssetCreateRequest.getAdditionalJsonProperties() != null) { - additionalProps.putAll(uiAssetCreateRequest.getAdditionalJsonProperties()); - } - - assetBuilder.properties(additionalProps); - - return assetBuilder.build(); - } private JsonObject buildJsonLdFromProperties(JsonObject json) { // Try to use the EDC Prop ID, but if it's not available, fall back to the "@id" property var assetId = Optional.ofNullable(JsonLdUtils.string(json, Prop.Edc.ID)) diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetCreator.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetCreatorOrganizationNameJsonLd.java similarity index 71% rename from extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetCreator.java rename to extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetCreatorOrganizationNameJsonLd.java index 132ce82e3..692f70bce 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetCreator.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetCreatorOrganizationNameJsonLd.java @@ -1,7 +1,6 @@ package de.sovity.edc.ext.wrapper.api.common.mappers.utils; import com.fasterxml.jackson.annotation.JsonProperty; -import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -16,11 +15,7 @@ @AllArgsConstructor @Builder(toBuilder = true) @RequiredArgsConstructor -@Schema(description = "Asset Creator Details") -public class UiAssetCreator { - - @JsonProperty("@type") - private String type; +public class AssetCreatorOrganizationNameJsonLd { @JsonProperty("http://xmlns.com/foaf/0.1/name") private String name; diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetDistribution.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetDistributionJsonLd.java similarity index 70% rename from extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetDistribution.java rename to extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetDistributionJsonLd.java index 8aa75ba51..fbfb8d3b3 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetDistribution.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetDistributionJsonLd.java @@ -1,7 +1,6 @@ package de.sovity.edc.ext.wrapper.api.common.mappers.utils; import com.fasterxml.jackson.annotation.JsonProperty; -import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -16,11 +15,7 @@ @AllArgsConstructor @Builder(toBuilder = true) @RequiredArgsConstructor -@Schema(description = "Asset Distribution Details") -public class UiAssetDistribution { - - @JsonProperty("@type") - private String type; +public class AssetDistributionJsonLd { @JsonProperty("http://www.w3.org/ns/dcat#mediaType") private String name; diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetHelperDto.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetHelperDto.java index 76eb64ef6..625e03c13 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetHelperDto.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetHelperDto.java @@ -23,10 +23,6 @@ @JsonIgnoreProperties(ignoreUnknown = true) public class AssetHelperDto { - @JsonProperty("https://w3id.org/edc/v0.0.1/ns/") - @JsonDeserialize(using = CustomDeserializer.class) - private String ns; - @JsonProperty("http://purl.org/dc/terms/identifier") @JsonDeserialize(using = CustomDeserializer.class) private String identifier; @@ -44,10 +40,10 @@ public class AssetHelperDto { private String description; @JsonProperty("http://purl.org/dc/terms/creator") - private UiAssetCreator creator; + private AssetCreatorOrganizationNameJsonLd creator; @JsonProperty("http://purl.org/dc/terms/publisher") - private UiAssetPublisher publisher; + private AssetPublisherJsonLd publisher; @JsonProperty("http://purl.org/dc/terms/license") @JsonDeserialize(using = CustomDeserializer.class) @@ -62,7 +58,7 @@ public class AssetHelperDto { private List keywords; @JsonProperty("http://www.w3.org/ns/dcat#distribution") - private UiAssetDistribution distribution; + private AssetDistributionJsonLd distribution; @JsonProperty("http://www.w3.org/ns/dcat#landingPage") @JsonDeserialize(using = CustomDeserializer.class) diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetPublisher.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPublisherJsonLd.java similarity index 71% rename from extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetPublisher.java rename to extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPublisherJsonLd.java index dce806742..8604fefc4 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetPublisher.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPublisherJsonLd.java @@ -1,7 +1,6 @@ package de.sovity.edc.ext.wrapper.api.common.mappers.utils; import com.fasterxml.jackson.annotation.JsonProperty; -import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -16,11 +15,7 @@ @AllArgsConstructor @Builder(toBuilder = true) @RequiredArgsConstructor -@Schema(description = "Asset Publisher Details") -public class UiAssetPublisher { - - @JsonProperty("@type") - private String type; +public class AssetPublisherJsonLd { @JsonProperty("http://xmlns.com/foaf/0.1/homepage") private String name; diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java new file mode 100644 index 000000000..06a61f951 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java @@ -0,0 +1,94 @@ +package de.sovity.edc.ext.wrapper.api.common.mappers.utils; + +import com.fasterxml.jackson.databind.ObjectMapper; +import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; +import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import org.eclipse.edc.spi.types.domain.asset.Asset; + +import java.util.HashMap; +import java.util.Map; + +@RequiredArgsConstructor +public class UiAssetBuilder { + + private final EdcPropertyMapperUtils edcPropertyMapperUtils; + + @SneakyThrows + public UiAsset buildUiAssetFromAssetJsonLd(String assetJsonLd) { + return buildUiAssetFromAssetHelper(buildHelperDto(assetJsonLd)); + } + + public UiAsset buildUiAssetFromAssetHelper(AssetHelperDto assetHelperDto) { + + return UiAsset.builder() + .keywords(assetHelperDto.getKeywords()) + .version(assetHelperDto.getVersion()) + .licenseUrl(assetHelperDto.getLicense()) + .creatorOrganizationName(assetHelperDto.getCreator() != null ? assetHelperDto.getCreator().getName() : null) + .publisherHomepage(assetHelperDto.getPublisher() != null ? assetHelperDto.getPublisher().getName() : null) + .description(assetHelperDto.getDescription()) + .language(assetHelperDto.getLanguage()) + .title(assetHelperDto.getTitle()) + .httpDatasourceHintsProxyMethod(assetHelperDto.getHttpDatasourceHintsProxyMethod()) + .httpDatasourceHintsProxyPath(assetHelperDto.getHttpDatasourceHintsProxyPath()) + .httpDatasourceHintsProxyQueryParams(assetHelperDto.getHttpDatasourceHintsProxyQueryParams()) + .httpDatasourceHintsProxyBody(assetHelperDto.getHttpDatasourceHintsProxyBody()) + .dataCategory(assetHelperDto.getDataCategory()) + .dataSubcategory(assetHelperDto.getDataSubcategory()) + .dataModel(assetHelperDto.getDataModel()) + .geoReferenceMethod(assetHelperDto.getGeoReferenceMethod()) + .transportMode(assetHelperDto.getTransportMode()) + .landingPageUrl(assetHelperDto.getLandingPage()) + .distribution(assetHelperDto.getDistribution() != null ? assetHelperDto.getDistribution().getName() : null) + .build(); + } + + @SneakyThrows + public AssetHelperDto buildHelperDto(String assetJsonLd) { + ObjectMapper mapper = new ObjectMapper(); + return mapper.readValue(assetJsonLd, AssetHelperDto.class); + } + + @SneakyThrows + public Asset buildAssetFromUiAssetCreateRequest(UiAssetCreateRequest uiAssetCreateRequest) { + + Asset.Builder assetBuilder = Asset.Builder + .newInstance() + .id(uiAssetCreateRequest.getId()) + .name(uiAssetCreateRequest.getTitle()) + .description(uiAssetCreateRequest.getDescription()) + .version(uiAssetCreateRequest.getVersion()) + .dataAddress(edcPropertyMapperUtils.buildDataAddress(uiAssetCreateRequest.getDataAddressProperties())); + + Map additionalProps = new HashMap<>(); + additionalProps.put("TITLE", uiAssetCreateRequest.getTitle()); + additionalProps.put("language", uiAssetCreateRequest.getLanguage()); + additionalProps.put("creatorOrganizationName", uiAssetCreateRequest.getCreatorOrganizationName()); + additionalProps.put("publisherHomepage", uiAssetCreateRequest.getPublisherHomepage()); + additionalProps.put("licenseUrl", uiAssetCreateRequest.getLicenseUrl()); + additionalProps.put("keywords", uiAssetCreateRequest.getKeywords()); + additionalProps.put("distribution", uiAssetCreateRequest.getDistribution()); + additionalProps.put("landingPageUrl", uiAssetCreateRequest.getLandingPageUrl()); + additionalProps.put("dataCategory", uiAssetCreateRequest.getDataCategory()); + additionalProps.put("dataSubcategory", uiAssetCreateRequest.getDataSubcategory()); + additionalProps.put("dataModel", uiAssetCreateRequest.getDataModel()); + additionalProps.put("geoReferenceMethod", uiAssetCreateRequest.getGeoReferenceMethod()); + additionalProps.put("transportMode", uiAssetCreateRequest.getTransportMode()); + + if(uiAssetCreateRequest.getAdditionalProperties() != null) { + additionalProps.putAll(uiAssetCreateRequest.getAdditionalProperties()); + } + if(uiAssetCreateRequest.getPrivateProperties() != null) { + assetBuilder.privateProperties(new HashMap<>(uiAssetCreateRequest.getPrivateProperties())); + } + if(uiAssetCreateRequest.getAdditionalJsonProperties() != null) { + additionalProps.putAll(uiAssetCreateRequest.getAdditionalJsonProperties()); + } + + assetBuilder.properties(additionalProps); + + return assetBuilder.build(); + } +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java index f56575a19..79754c781 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java @@ -1,5 +1,6 @@ package de.sovity.edc.ext.wrapper.api.common.mappers; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.UiAssetBuilder; import de.sovity.edc.utils.jsonld.vocab.Prop; import lombok.SneakyThrows; import org.junit.jupiter.api.Test; @@ -20,6 +21,8 @@ class AssetMapperTest { @InjectMocks AssetMapper assetMapper; + @InjectMocks + UiAssetBuilder assetBuilder; @Test @SneakyThrows @@ -28,15 +31,14 @@ void test_buildAssetDto() { String jsonContent = new String(Files.readAllBytes(Paths.get(getClass().getResource("/sample.json").toURI()))); // Act - var uiAsset = assetMapper.buildUiAssetFromAssetHelper(assetMapper.buildHelperDto(jsonContent)); + var uiAsset = assetBuilder.buildUiAssetFromAssetHelper(assetBuilder.buildHelperDto(jsonContent)); // Assert assertThat(uiAsset).isNotNull(); - assertThat(uiAsset.getName()).isEqualTo("urn:artifact:my-asset"); assertThat(uiAsset.getTitle()).isEqualTo("My Asset"); assertThat(uiAsset.getDescription()).isEqualTo("Lorem Ipsum ..."); - assertThat(uiAsset.getPublisher()).isEqualTo("https://data-source.my-org/about"); - assertThat(uiAsset.getCreator()).isEqualTo("My Organization Name"); + assertThat(uiAsset.getPublisherHomepage()).isEqualTo("https://data-source.my-org/about"); + assertThat(uiAsset.getCreatorOrganizationName()).isEqualTo("My Organization Name"); assertThat(uiAsset.getLicenseUrl()).isEqualTo("https://data-source.my-org/license"); assertThat(uiAsset.getVersion()).isEqualTo("1.1"); assertThat(uiAsset.getLanguage()).isEqualTo("https://w3id.org/idsa/code/EN"); @@ -56,7 +58,7 @@ void test_KeywordsAsSingleString() { .build(); // Act - var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(requestBody.toString()); + var uiAsset = assetBuilder.buildUiAssetFromAssetJsonLd(requestBody.toString()); // Assert assertThat(uiAsset).isNotNull(); @@ -69,13 +71,13 @@ void test_StringsAsList() { // Arrange var requestBody = createObjectBuilder() - .add(Prop.DCMI.title, createObjectBuilder() + .add(Prop.Dcterms.TITLE, createObjectBuilder() .add(Prop.VALUE, "AssetName") .add(Prop.LANGUAGE, "en")) .build(); // Act - var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(requestBody.toString()); + var uiAsset = assetBuilder.buildUiAssetFromAssetJsonLd(requestBody.toString()); // Assert assertThat(uiAsset).isNotNull(); @@ -88,7 +90,7 @@ void test_StringsAsMap() { // Arrange var requestBody = createObjectBuilder() - .add(Prop.DCMI.title, createArrayBuilder() + .add(Prop.Dcterms.TITLE, createArrayBuilder() .add(createObjectBuilder() .add(Prop.TYPE, "SomeType") .add(Prop.VALUE, "AssetName") @@ -97,7 +99,7 @@ void test_StringsAsMap() { .build(); // Act - var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(requestBody.toString()); + var uiAsset = assetBuilder.buildUiAssetFromAssetJsonLd(requestBody.toString()); // Assert assertThat(uiAsset).isNotNull(); @@ -110,11 +112,11 @@ void test_badBooleanValue() { //Arrange var requestBody = createObjectBuilder() - .add(Prop.SOVITYSEMANTIC.METHOD, "wrongBooleanValue") + .add(Prop.SovityDcatExt.METHOD, "wrongBooleanValue") .build(); // Act - var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(requestBody.toString()); + var uiAsset = assetBuilder.buildUiAssetFromAssetJsonLd(requestBody.toString()); // Assert assertThat(uiAsset).isNotNull(); @@ -127,11 +129,11 @@ void test_noBooleanValue() { //Arrange var requestBody = createObjectBuilder() - .add(Prop.SOVITYSEMANTIC.METHOD, "") + .add(Prop.SovityDcatExt.METHOD, "") .build(); // Act - var uiAsset = assetMapper.buildUiAssetFromAssetJsonLd(requestBody.toString()); + var uiAsset = assetBuilder.buildUiAssetFromAssetJsonLd(requestBody.toString()); // Assert assertThat(uiAsset).isNotNull(); diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/utils/EdcPropertyUtilsTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtilsTest.java similarity index 83% rename from extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/utils/EdcPropertyUtilsTest.java rename to extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtilsTest.java index 592dbe30b..a72d91b24 100644 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/utils/EdcPropertyUtilsTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtilsTest.java @@ -12,8 +12,9 @@ * */ -package de.sovity.edc.ext.wrapper.utils; +package de.sovity.edc.ext.wrapper.api.common.mappers.utils; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -22,12 +23,12 @@ import static org.assertj.core.api.Assertions.assertThat; -class EdcPropertyUtilsTest { - EdcPropertyUtils edcPropertyUtils; +class EdcPropertyMapperUtilsTest { + EdcPropertyMapperUtils edcPropertyUtils; @BeforeEach void setup() { - edcPropertyUtils = new EdcPropertyUtils(); + edcPropertyUtils = new EdcPropertyMapperUtils(); } @Test diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java index a93d589ed..4feef9ef5 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java @@ -49,7 +49,6 @@ import de.sovity.edc.ext.wrapper.api.usecase.services.OfferingService; import de.sovity.edc.ext.wrapper.api.usecase.services.PolicyMappingService; import de.sovity.edc.ext.wrapper.api.usecase.services.SupportedPolicyApiService; -import de.sovity.edc.ext.wrapper.utils.EdcPropertyUtils; import de.sovity.edc.utils.catalog.DspCatalogService; import de.sovity.edc.utils.catalog.mapper.DspDataOfferBuilder; import lombok.NoArgsConstructor; @@ -149,13 +148,12 @@ public static WrapperExtensionContext buildContext( transferProcessService); var contractNegotiationUtils = new ContractNegotiationUtils(contractNegotiationService); var contractAgreementUtils = new ContractAgreementUtils(contractAgreementService); - var edcPropertyUtils = new EdcPropertyUtils(); var assetApiService = new AssetApiService(assetService, assetMapper); var transferRequestBuilder = new TransferRequestBuilder( objectMapper, contractAgreementUtils, contractNegotiationUtils, - edcPropertyUtils, + edcPropertyMapperUtils, serviceExtensionContext.getConnectorId() ); var contractAgreementTransferApiService = new ContractAgreementTransferApiService( @@ -199,7 +197,7 @@ public static WrapperExtensionContext buildContext( policyDefinitionStore, contractDefinitionStore, policyMappingService, - edcPropertyUtils); + edcPropertyMapperUtils); var useCaseResource = new UseCaseResource( kpiApiService, supportedPolicyApiService, diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java index a8aeff356..cee7b8f97 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java @@ -15,6 +15,7 @@ package de.sovity.edc.ext.wrapper.api.ui.pages.asset; import de.sovity.edc.ext.wrapper.api.common.mappers.AssetMapper; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.UiAssetBuilder; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import de.sovity.edc.ext.wrapper.api.ui.model.IdResponseDto; @@ -31,29 +32,19 @@ public class AssetApiService { private final AssetService assetService; private final AssetMapper assetMapper; + private final UiAssetBuilder assetBuilder; public List getAssets() { var assets = getAllAssets(); return assets.stream().sorted(Comparator.comparing(Asset::getCreatedAt).reversed()).map(asset -> { - var entry = new UiAsset(); - entry.setId(asset.getId()); - entry.setDescription(asset.getDescription()); - entry.setName(asset.getName()); - entry.setVersion(asset.getVersion()); - entry.setLandingPageUrl((asset.getProperties().get("landingPage") != null) ? - asset.getProperties().get("landingPage").toString() : - null); - entry.setKeywords(List.of((asset.getProperties().get("keywords") != null) ? - asset.getProperties().get("keywords").toString() : - "")); - entry.setPrivateProperties(asset.getPrivateProperties()); + var entry = assetMapper.buildUiAssetFromAsset(asset); return entry; }).toList(); } @NotNull public IdResponseDto createAsset(UiAssetCreateRequest request) { - var asset = assetMapper.buildAssetFromUiAssetCreateRequest(request); + var asset = assetBuilder.buildAssetFromUiAssetCreateRequest(request); asset = assetService.create(asset).getContent(); return new IdResponseDto(asset.getId()); } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/TransferRequestBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/TransferRequestBuilder.java index 53ca11123..0b488336d 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/TransferRequestBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/TransferRequestBuilder.java @@ -15,9 +15,9 @@ package de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services; import com.fasterxml.jackson.databind.ObjectMapper; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementTransferRequest; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementTransferRequestParams; -import de.sovity.edc.ext.wrapper.utils.EdcPropertyUtils; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; import org.eclipse.edc.connector.transfer.spi.types.TransferRequest; @@ -33,7 +33,7 @@ public class TransferRequestBuilder { private final ObjectMapper objectMapper; private final ContractAgreementUtils contractAgreementUtils; private final ContractNegotiationUtils contractNegotiationUtils; - private final EdcPropertyUtils edcPropertyUtils; + private final EdcPropertyMapperUtils edcPropertyUtils; private final String connectorId; public TransferRequest buildTransferRequest( diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/utils/EdcPropertyUtils.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/utils/EdcPropertyUtils.java deleted file mode 100644 index ca1d36370..000000000 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/utils/EdcPropertyUtils.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * 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 - init - */ - -package de.sovity.edc.ext.wrapper.utils; - -import lombok.RequiredArgsConstructor; -import org.eclipse.edc.spi.types.domain.DataAddress; - -import java.util.HashMap; -import java.util.Map; - -@RequiredArgsConstructor -public class EdcPropertyUtils { - - /** - * Converts a {@code Map} to {@code Map}. - *

- * Our API forsakes asset properties that are complex objects / JSON and only keeps string - * properties. - * - * @param map all properties - * @return string properties - */ - public Map truncateToMapOfString(Map map) { - Map result = new HashMap<>(); - - for (Map.Entry entry : map.entrySet()) { - Object value = entry.getValue(); - - String valueString; - if (value == null) { - valueString = null; - } else if (value instanceof String str) { - valueString = str; - } else if (value instanceof Double) { - valueString = String.valueOf(value); - } else if (value instanceof Integer) { - valueString = String.valueOf(value); - } else { - continue; - } - - result.put(entry.getKey(), valueString); - } - return result; - } - - @SuppressWarnings({"unchecked", "rawtypes", "java:S1905"}) - public Map toMapOfObject(Map map) { - if (map == null) { - return new HashMap<>(); - } - return new HashMap<>((Map) (Map) map); - } - - public DataAddress buildDataAddress(Map properties) { - return DataAddress.Builder.newInstance() - .properties(toMapOfObject(properties)) - .build(); - } -} diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingServiceTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingServiceTest.java index 67885b5a0..90fe91948 100644 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingServiceTest.java +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingServiceTest.java @@ -1,12 +1,12 @@ package de.sovity.edc.ext.wrapper.api.usecase.services; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; import de.sovity.edc.ext.wrapper.api.common.model.PermissionDto; import de.sovity.edc.ext.wrapper.api.common.model.PolicyDto; import de.sovity.edc.ext.wrapper.api.usecase.model.AssetEntryDto; import de.sovity.edc.ext.wrapper.api.usecase.model.ContractDefinitionRequestDto; import de.sovity.edc.ext.wrapper.api.usecase.model.CreateOfferingDto; import de.sovity.edc.ext.wrapper.api.usecase.model.PolicyDefinitionRequestDto; -import de.sovity.edc.ext.wrapper.utils.EdcPropertyUtils; import org.eclipse.edc.connector.contract.spi.offer.store.ContractDefinitionStore; import org.eclipse.edc.connector.contract.spi.types.offer.ContractDefinition; import org.eclipse.edc.connector.policy.spi.store.PolicyDefinitionStore; @@ -60,7 +60,7 @@ void setUp() { policyDefinitionStore, contractDefinitionStore, policyMappingService, - new EdcPropertyUtils()); + new EdcPropertyMapperUtils()); this.assetEntryDto = assetDto(); this.asset = asset(); diff --git a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java index b8d36aeaf..d884bfd10 100644 --- a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java +++ b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java @@ -50,6 +50,7 @@ public class Dcat { public final String DISTRIBUTION = CTX_WRONG_BUT_USED_BY_CORE_EDC + "distribution"; public final String VERSION = CTX + "version"; public final String KEYWORDS = CTX + "keyword"; + public final String LANDING_PAGE = CTX + "landingPage"; } /** @@ -62,20 +63,20 @@ public class Odrl { } /** - * DCMI Metadata Terms Vocabulary, see DCAT 3 Specification + * Dcterms Metadata Terms Vocabulary, see DCMI Metadata Terms */ @UtilityClass - public class DCMI { + public class Dcterms { public final String CTX = "http://purl.org/dc/terms/"; - public final String title = CTX + "title"; - public final String description = CTX + "description"; + public final String TITLE = CTX + "TITLE"; + public final String DESCRIPTION = CTX + "DESCRIPTION"; } /** - * DCMI Metadata Terms Vocabulary, see DCAT 3 Specification + * Dcterms Metadata Terms Vocabulary, see DCAT 3 Specification */ @UtilityClass - public class SOVITYSEMANTIC { + public class SovityDcatExt { public final String CTX = "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxy"; public final String METHOD = CTX + "method/"; public final String PATH = CTX + "path/"; diff --git a/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java b/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java index f727e01aa..9cfe46afa 100644 --- a/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java +++ b/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java @@ -16,6 +16,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import de.sovity.edc.extension.e2e.connector.config.ConnectorRemoteConfig; import de.sovity.edc.extension.e2e.connector.config.api.auth.NoneAuthProvider; +import de.sovity.edc.utils.jsonld.vocab.Prop; import io.restassured.http.Header; import io.restassured.specification.RequestSpecification; import jakarta.json.Json; @@ -38,7 +39,6 @@ import java.util.UUID; import java.util.concurrent.atomic.AtomicReference; -import de.sovity.edc.utils.jsonld.vocab.Prop; import static io.restassured.RestAssured.given; import static io.restassured.http.ContentType.JSON; import static jakarta.json.Json.createObjectBuilder; @@ -52,10 +52,6 @@ import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_POLICY_ATTRIBUTE; import static org.eclipse.edc.spi.CoreConstants.EDC_NAMESPACE; import static org.eclipse.edc.spi.CoreConstants.EDC_PREFIX; -import static org.eclipse.edc.spi.types.domain.asset.Asset.PROPERTY_DESCRIPTION; -import static org.eclipse.edc.spi.types.domain.asset.Asset.PROPERTY_ID; -import static org.eclipse.edc.spi.types.domain.asset.Asset.PROPERTY_NAME; -import static org.eclipse.edc.spi.types.domain.asset.Asset.PROPERTY_VERSION; @SuppressWarnings("java:S5960") @RequiredArgsConstructor @@ -75,7 +71,7 @@ public void createAsset(String assetId, .add("asset", createObjectBuilder() .add(ID, assetId) .add("properties", createObjectBuilder() - .add(Prop.DCMI.description, "description"))) + .add(Prop.Dcterms.DESCRIPTION, "description"))) .add("dataAddress", createObjectBuilder(dataAddressProperties)) .build(); @@ -211,7 +207,7 @@ public String negotiateContract( .add("protocol", "dataspace-protocol-http") .add("offer", createObjectBuilder() .add("offerId", offerId) - .add("assetId", assetId) + .add("id", assetId) .add("policy", jsonLd.compact(policy).getContent()) ) .build(); @@ -284,7 +280,7 @@ public String initiateTransfer( .add("dataDestination", destination) .add("protocol", "dataspace-protocol-http") .add("managedResources", false) - .add("assetId", assetId) + .add("id", assetId) .add("contractId", contractAgreementId) .add("connectorAddress", providerProtocolApi.toString()) .add("privateProperties", Json.createObjectBuilder().build()) From a7dedd3222df8447d5b1973662159457f214512c Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Fri, 15 Sep 2023 16:21:53 +0200 Subject: [PATCH 16/37] fix: PR Revision --- .../edc/ext/wrapper/WrapperExtensionContextBuilder.java | 6 ++++-- .../ext/wrapper/api/usecase/services/OfferingService.java | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java index 4feef9ef5..c8c39ed9d 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java @@ -23,6 +23,7 @@ import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.LiteralMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.PolicyValidator; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.UiAssetBuilder; import de.sovity.edc.ext.wrapper.api.ui.UiResource; import de.sovity.edc.ext.wrapper.api.ui.pages.asset.AssetApiService; import de.sovity.edc.ext.wrapper.api.ui.pages.catalog.CatalogApiService; @@ -115,7 +116,8 @@ public static WrapperExtensionContext buildContext( atomicConstraintMapper, typeTransformerRegistry); var edcPropertyMapperUtils = new EdcPropertyMapperUtils(); - var assetMapper = new AssetMapper(objectMapper, edcPropertyMapperUtils, typeTransformerRegistry); + var assetBuilder = new UiAssetBuilder(edcPropertyMapperUtils); + var assetMapper = new AssetMapper(objectMapper, typeTransformerRegistry, assetBuilder); var transferProcessStateService = new TransferProcessStateService(); var contractAgreementPageCardBuilder = new ContractAgreementPageCardBuilder( policyMapper, @@ -148,7 +150,7 @@ public static WrapperExtensionContext buildContext( transferProcessService); var contractNegotiationUtils = new ContractNegotiationUtils(contractNegotiationService); var contractAgreementUtils = new ContractAgreementUtils(contractAgreementService); - var assetApiService = new AssetApiService(assetService, assetMapper); + var assetApiService = new AssetApiService(assetService, assetMapper, assetBuilder); var transferRequestBuilder = new TransferRequestBuilder( objectMapper, contractAgreementUtils, diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingService.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingService.java index ef5149cbd..0354ce64b 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingService.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingService.java @@ -1,10 +1,10 @@ package de.sovity.edc.ext.wrapper.api.usecase.services; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; import de.sovity.edc.ext.wrapper.api.usecase.model.AssetEntryDto; import de.sovity.edc.ext.wrapper.api.usecase.model.ContractDefinitionRequestDto; import de.sovity.edc.ext.wrapper.api.usecase.model.CreateOfferingDto; import de.sovity.edc.ext.wrapper.api.usecase.model.PolicyDefinitionRequestDto; -import de.sovity.edc.ext.wrapper.utils.EdcPropertyUtils; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.eclipse.edc.connector.contract.spi.offer.store.ContractDefinitionStore; @@ -31,7 +31,7 @@ public class OfferingService { private final PolicyDefinitionStore policyDefinitionStore; private final ContractDefinitionStore contractDefinitionStore; private final PolicyMappingService policyMappingService; - private final EdcPropertyUtils edcPropertyUtils; + private final EdcPropertyMapperUtils edcPropertyUtils; /** * Creates the asset, policy and contract definition in the connector. First, transforms the From 77af54a81f5d76084ab7e89d8db04836098ffc3e Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Mon, 18 Sep 2023 11:41:49 +0200 Subject: [PATCH 17/37] fix: PR Revision (Asset Mapper + Asset Mapper Test) --- .../ext/wrapper/api/common/model/UiAsset.java | 4 +- .../api/common/mappers/AssetMapper.java | 43 +++--- .../AssetCreatorOrganizationNameJsonLd.java | 2 + .../utils/AssetDistributionJsonLd.java | 2 +- .../api/common/mappers/utils/AssetJsonLd.java | 33 +++++ ...elperDto.java => AssetPropertyJsonLd.java} | 48 ++++--- .../mappers/utils/AssetPublisherJsonLd.java | 2 + .../common/mappers/utils/UiAssetBuilder.java | 136 +++++++++--------- .../api/common/mappers/AssetMapperTest.java | 100 ++++++++----- .../test/resources/example-asset-jsonld.json | 43 ++++++ .../src/test/resources/sample.json | 38 ----- .../WrapperExtensionContextBuilder.java | 6 +- .../api/ui/pages/asset/AssetApiService.java | 10 +- .../ui/pages/catalog/CatalogApiService.java | 4 +- .../ContractAgreementPageCardBuilder.java | 10 +- .../de/sovity/edc/e2e/UiApiWrapperTest.java | 9 +- .../sovity/edc/utils/jsonld/vocab/Prop.java | 44 +++++- 17 files changed, 316 insertions(+), 218 deletions(-) create mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetJsonLd.java rename extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/{AssetHelperDto.java => AssetPropertyJsonLd.java} (62%) create mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/resources/example-asset-jsonld.json delete mode 100644 extensions/wrapper/wrapper-common-mappers/src/test/resources/sample.json diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java index 63837f864..f22df0aef 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java @@ -36,7 +36,7 @@ public class UiAsset { @Schema(description = "Asset Id", requiredMode = Schema.RequiredMode.REQUIRED) - private String id; + private String assetId; @Schema(description = "Asset Title", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String title; @@ -63,7 +63,7 @@ public class UiAsset { private List keywords; @Schema(description = "Asset MediaType", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - private String distribution; + private String mediaType; @Schema(description = "Homepage URL associated with the Asset", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String landingPageUrl; diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java index f1993072f..c42a0dfe6 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java @@ -1,52 +1,43 @@ package de.sovity.edc.ext.wrapper.api.common.mappers; -import com.fasterxml.jackson.databind.ObjectMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.UiAssetBuilder; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; -import de.sovity.edc.utils.JsonUtils; +import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import de.sovity.edc.utils.jsonld.JsonLdUtils; import de.sovity.edc.utils.jsonld.vocab.Prop; import jakarta.json.Json; import jakarta.json.JsonObject; import lombok.RequiredArgsConstructor; -import lombok.SneakyThrows; import org.eclipse.edc.spi.types.domain.asset.Asset; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; -import java.util.List; import java.util.Optional; @RequiredArgsConstructor public class AssetMapper { - /** - * This Object Mapper must be able to handle JSON-LD serialization / deserialization. - */ - private final ObjectMapper jsonLdObjectMapper; private final TypeTransformerRegistry typeTransformerRegistry; private final UiAssetBuilder uiAssetBuilder; + public UiAsset buildUiAsset(Asset asset) { + var jsonLd = buildAssetJsonLd(asset); + return buildUiAsset(jsonLd); + } - @SneakyThrows - public UiAsset buildUiAssetFromAsset(Asset asset) { - var uiAsset = uiAssetBuilder.buildUiAssetFromAssetHelper(uiAssetBuilder.buildHelperDto(jsonLdObjectMapper.writeValueAsString(asset))); - - uiAsset.setId(asset.getId()); - uiAsset.setPrivateProperties(asset.getPrivateProperties()); - uiAsset.setKeywords(uiAsset.getKeywords() == null ? List.of() : uiAsset.getKeywords()); - - return uiAsset; + public UiAsset buildUiAsset(JsonObject assetJsonLd) { + return uiAssetBuilder.buildUiAsset(assetJsonLd); } - public Asset buildAssetFromAssetPropertiesJsonLd(JsonObject json) { - return typeTransformerRegistry.transform(json, Asset.class).getContent(); + public Asset buildAsset(UiAssetCreateRequest createRequest) { + var assetJsonLd = uiAssetBuilder.buildAssetJsonLd(createRequest); + return buildAsset(assetJsonLd); } - private String buildJsonLd(Asset asset) { - return JsonUtils.toJson(typeTransformerRegistry.transform(asset, JsonObject.class).getContent()); + public Asset buildAssetFromDatasetProperties(JsonObject json) { + return typeTransformerRegistry.transform(buildJsonLdFromDatasetProperties(json), Asset.class).getContent(); } - private JsonObject buildJsonLdFromProperties(JsonObject json) { + private JsonObject buildJsonLdFromDatasetProperties(JsonObject json) { // Try to use the EDC Prop ID, but if it's not available, fall back to the "@id" property var assetId = Optional.ofNullable(JsonLdUtils.string(json, Prop.Edc.ID)) .orElseGet(() -> JsonLdUtils.string(json, Prop.ID)); @@ -57,4 +48,12 @@ private JsonObject buildJsonLdFromProperties(JsonObject json) { .add(Prop.Edc.PROPERTIES, json) .build(); } + + private JsonObject buildAssetJsonLd(Asset asset) { + return typeTransformerRegistry.transform(asset, JsonObject.class).getContent(); + } + + private Asset buildAsset(JsonObject assetJsonLd) { + return typeTransformerRegistry.transform(assetJsonLd, Asset.class).getContent(); + } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetCreatorOrganizationNameJsonLd.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetCreatorOrganizationNameJsonLd.java index 692f70bce..afdfa20d0 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetCreatorOrganizationNameJsonLd.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetCreatorOrganizationNameJsonLd.java @@ -16,6 +16,8 @@ @Builder(toBuilder = true) @RequiredArgsConstructor public class AssetCreatorOrganizationNameJsonLd { + @JsonProperty("@type") + private String type; @JsonProperty("http://xmlns.com/foaf/0.1/name") private String name; diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetDistributionJsonLd.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetDistributionJsonLd.java index fbfb8d3b3..0f7a9e7bc 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetDistributionJsonLd.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetDistributionJsonLd.java @@ -18,5 +18,5 @@ public class AssetDistributionJsonLd { @JsonProperty("http://www.w3.org/ns/dcat#mediaType") - private String name; + private String mediaType; } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetJsonLd.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetJsonLd.java new file mode 100644 index 000000000..ad11a4ae8 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetJsonLd.java @@ -0,0 +1,33 @@ +package de.sovity.edc.ext.wrapper.api.common.mappers.utils; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import de.sovity.edc.ext.wrapper.api.common.model.utils.CustomDeserializer; +import de.sovity.edc.utils.jsonld.vocab.Prop; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.RequiredArgsConstructor; +import lombok.Setter; +import lombok.ToString; + + +@Getter +@Setter +@ToString +@AllArgsConstructor +@Builder(toBuilder = true) +@RequiredArgsConstructor +@JsonIgnoreProperties(ignoreUnknown = true) +public class AssetJsonLd { + + @JsonProperty(Prop.ID) + @JsonDeserialize(using = CustomDeserializer.class) + private String assetId; + + @JsonProperty(Prop.PROPERTIES) + @JsonDeserialize(using = CustomDeserializer.class) + private AssetPropertyJsonLd properties; +} + diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetHelperDto.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPropertyJsonLd.java similarity index 62% rename from extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetHelperDto.java rename to extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPropertyJsonLd.java index 625e03c13..f37273a6a 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetHelperDto.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPropertyJsonLd.java @@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import de.sovity.edc.ext.wrapper.api.common.model.utils.CustomDeserializer; +import de.sovity.edc.utils.jsonld.vocab.Prop; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; @@ -21,82 +22,83 @@ @Builder(toBuilder = true) @RequiredArgsConstructor @JsonIgnoreProperties(ignoreUnknown = true) -public class AssetHelperDto { +public class AssetPropertyJsonLd { - @JsonProperty("http://purl.org/dc/terms/identifier") + @JsonProperty(Prop.Edc.ID) @JsonDeserialize(using = CustomDeserializer.class) - private String identifier; + private String assetId; - @JsonProperty("http://purl.org/dc/terms/title") + @JsonProperty(Prop.Dcterms.TITLE) @JsonDeserialize(using = CustomDeserializer.class) private String title; - @JsonProperty("http://purl.org/dc/terms/language") + @JsonProperty(Prop.Dcterms.LANGUAGE) @JsonDeserialize(using = CustomDeserializer.class) private String language; - @JsonProperty("http://purl.org/dc/terms/description") + @JsonProperty(Prop.Dcterms.DESCRIPTION) @JsonDeserialize(using = CustomDeserializer.class) private String description; - @JsonProperty("http://purl.org/dc/terms/creator") + @JsonProperty(Prop.Dcterms.CREATOR) private AssetCreatorOrganizationNameJsonLd creator; - @JsonProperty("http://purl.org/dc/terms/publisher") + @JsonProperty(Prop.Dcterms.PUBLISHER) private AssetPublisherJsonLd publisher; - @JsonProperty("http://purl.org/dc/terms/license") + @JsonProperty(Prop.Dcterms.LICENSE) @JsonDeserialize(using = CustomDeserializer.class) private String license; - @JsonProperty("http://www.w3.org/ns/dcat#version") + @JsonProperty(Prop.Dcat.VERSION) @JsonDeserialize(using = CustomDeserializer.class) private String version; - @JsonProperty("http://www.w3.org/ns/dcat#keyword") + @JsonProperty(Prop.Dcat.KEYWORDS) @JsonDeserialize(using = CustomDeserializer.class) private List keywords; - @JsonProperty("http://www.w3.org/ns/dcat#distribution") - private AssetDistributionJsonLd distribution; + @JsonProperty(Prop.Dcat.MEDIATYPE) + @JsonDeserialize(using = CustomDeserializer.class) + private String mediaType; - @JsonProperty("http://www.w3.org/ns/dcat#landingPage") + @JsonProperty(Prop.Dcat.LANDING_PAGE) @JsonDeserialize(using = CustomDeserializer.class) private String landingPage; - @JsonProperty("https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyMethod") + @JsonProperty(Prop.SovityDcatExt.METHOD) @JsonDeserialize(using = CustomDeserializer.class) private Boolean httpDatasourceHintsProxyMethod; - @JsonProperty("https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyPath") + @JsonProperty(Prop.SovityDcatExt.PATH) @JsonDeserialize(using = CustomDeserializer.class) private Boolean httpDatasourceHintsProxyPath; - @JsonProperty("https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyQueryParams") + @JsonProperty(Prop.SovityDcatExt.QUERY_PARAMS) @JsonDeserialize(using = CustomDeserializer.class) private Boolean httpDatasourceHintsProxyQueryParams; - @JsonProperty("https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyBody") + @JsonProperty(Prop.SovityDcatExt.BODY) @JsonDeserialize(using = CustomDeserializer.class) private Boolean httpDatasourceHintsProxyBody; - @JsonProperty("http://w3id.org/mds#dataCategory") + @JsonProperty(Prop.Mds.DATA_CATEGORY) @JsonDeserialize(using = CustomDeserializer.class) private String dataCategory; - @JsonProperty("http://w3id.org/mds#dataSubcategory") + @JsonProperty(Prop.Mds.DATA_SUBCATEGORY) @JsonDeserialize(using = CustomDeserializer.class) private String dataSubcategory; - @JsonProperty("http://w3id.org/mds#dataModel") + @JsonProperty(Prop.Mds.DATA_MODEL) @JsonDeserialize(using = CustomDeserializer.class) private String dataModel; - @JsonProperty("http://w3id.org/mds#geoReferenceMethod") + @JsonProperty(Prop.Mds.GEO_REFERENCE_METHOD) @JsonDeserialize(using = CustomDeserializer.class) private String geoReferenceMethod; - @JsonProperty("http://w3id.org/mds#transportMode") + @JsonProperty(Prop.Mds.TRANSPORT_MODE) @JsonDeserialize(using = CustomDeserializer.class) private String transportMode; } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPublisherJsonLd.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPublisherJsonLd.java index 8604fefc4..c4f66f4bc 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPublisherJsonLd.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPublisherJsonLd.java @@ -16,6 +16,8 @@ @Builder(toBuilder = true) @RequiredArgsConstructor public class AssetPublisherJsonLd { + @JsonProperty("@type") + private String type; @JsonProperty("http://xmlns.com/foaf/0.1/homepage") private String name; diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java index 06a61f951..e7c2e4bfa 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java @@ -3,92 +3,94 @@ import com.fasterxml.jackson.databind.ObjectMapper; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; +import de.sovity.edc.utils.JsonUtils; +import de.sovity.edc.utils.jsonld.vocab.Prop; +import jakarta.json.Json; +import jakarta.json.JsonObject; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; -import org.eclipse.edc.spi.types.domain.asset.Asset; - -import java.util.HashMap; -import java.util.Map; @RequiredArgsConstructor public class UiAssetBuilder { + private final ObjectMapper mapper = new ObjectMapper(); - private final EdcPropertyMapperUtils edcPropertyMapperUtils; - - @SneakyThrows - public UiAsset buildUiAssetFromAssetJsonLd(String assetJsonLd) { - return buildUiAssetFromAssetHelper(buildHelperDto(assetJsonLd)); + public UiAsset buildUiAsset(JsonObject assetJsonLd) { + var assetJsonLdObj = parseAssetJsonLd(JsonUtils.toJson(assetJsonLd)); + return buildUiAsset(assetJsonLdObj); } - public UiAsset buildUiAssetFromAssetHelper(AssetHelperDto assetHelperDto) { + private UiAsset buildUiAsset(AssetJsonLd assetJsonLd) { + var assetPropertyJsonLd = assetJsonLd.getProperties(); return UiAsset.builder() - .keywords(assetHelperDto.getKeywords()) - .version(assetHelperDto.getVersion()) - .licenseUrl(assetHelperDto.getLicense()) - .creatorOrganizationName(assetHelperDto.getCreator() != null ? assetHelperDto.getCreator().getName() : null) - .publisherHomepage(assetHelperDto.getPublisher() != null ? assetHelperDto.getPublisher().getName() : null) - .description(assetHelperDto.getDescription()) - .language(assetHelperDto.getLanguage()) - .title(assetHelperDto.getTitle()) - .httpDatasourceHintsProxyMethod(assetHelperDto.getHttpDatasourceHintsProxyMethod()) - .httpDatasourceHintsProxyPath(assetHelperDto.getHttpDatasourceHintsProxyPath()) - .httpDatasourceHintsProxyQueryParams(assetHelperDto.getHttpDatasourceHintsProxyQueryParams()) - .httpDatasourceHintsProxyBody(assetHelperDto.getHttpDatasourceHintsProxyBody()) - .dataCategory(assetHelperDto.getDataCategory()) - .dataSubcategory(assetHelperDto.getDataSubcategory()) - .dataModel(assetHelperDto.getDataModel()) - .geoReferenceMethod(assetHelperDto.getGeoReferenceMethod()) - .transportMode(assetHelperDto.getTransportMode()) - .landingPageUrl(assetHelperDto.getLandingPage()) - .distribution(assetHelperDto.getDistribution() != null ? assetHelperDto.getDistribution().getName() : null) + .assetId(assetPropertyJsonLd.getAssetId()) + .keywords(assetPropertyJsonLd.getKeywords()) + .version(assetPropertyJsonLd.getVersion()) + .licenseUrl(assetPropertyJsonLd.getLicense()) + .creatorOrganizationName(assetPropertyJsonLd.getCreator() != null ? assetPropertyJsonLd.getCreator().getName() : null) + .publisherHomepage(assetPropertyJsonLd.getPublisher() != null ? assetPropertyJsonLd.getPublisher().getName() : null) + .description(assetPropertyJsonLd.getDescription()) + .language(assetPropertyJsonLd.getLanguage()) + .title(assetPropertyJsonLd.getTitle()) + .httpDatasourceHintsProxyMethod(assetPropertyJsonLd.getHttpDatasourceHintsProxyMethod()) + .httpDatasourceHintsProxyPath(assetPropertyJsonLd.getHttpDatasourceHintsProxyPath()) + .httpDatasourceHintsProxyQueryParams(assetPropertyJsonLd.getHttpDatasourceHintsProxyQueryParams()) + .httpDatasourceHintsProxyBody(assetPropertyJsonLd.getHttpDatasourceHintsProxyBody()) + .dataCategory(assetPropertyJsonLd.getDataCategory()) + .dataSubcategory(assetPropertyJsonLd.getDataSubcategory()) + .dataModel(assetPropertyJsonLd.getDataModel()) + .geoReferenceMethod(assetPropertyJsonLd.getGeoReferenceMethod()) + .transportMode(assetPropertyJsonLd.getTransportMode()) + .landingPageUrl(assetPropertyJsonLd.getLandingPage()) + .mediaType(assetPropertyJsonLd.getMediaType()) .build(); } @SneakyThrows - public AssetHelperDto buildHelperDto(String assetJsonLd) { - ObjectMapper mapper = new ObjectMapper(); - return mapper.readValue(assetJsonLd, AssetHelperDto.class); + private AssetJsonLd parseAssetJsonLd(String assetJsonLd) { + var assetPropertiesJsonLd = mapper.readTree(assetJsonLd).get("properties"); + var assetProperties = mapper.readValue(assetPropertiesJsonLd.toString(), AssetPropertyJsonLd.class); + + return AssetJsonLd.builder() + .assetId(String.valueOf(mapper.readTree(assetJsonLd).get("id"))) + .properties(assetProperties) + .build(); } @SneakyThrows - public Asset buildAssetFromUiAssetCreateRequest(UiAssetCreateRequest uiAssetCreateRequest) { + public JsonObject buildAssetJsonLd(UiAssetCreateRequest uiAssetCreateRequest) { - Asset.Builder assetBuilder = Asset.Builder - .newInstance() - .id(uiAssetCreateRequest.getId()) - .name(uiAssetCreateRequest.getTitle()) - .description(uiAssetCreateRequest.getDescription()) - .version(uiAssetCreateRequest.getVersion()) - .dataAddress(edcPropertyMapperUtils.buildDataAddress(uiAssetCreateRequest.getDataAddressProperties())); - - Map additionalProps = new HashMap<>(); - additionalProps.put("TITLE", uiAssetCreateRequest.getTitle()); - additionalProps.put("language", uiAssetCreateRequest.getLanguage()); - additionalProps.put("creatorOrganizationName", uiAssetCreateRequest.getCreatorOrganizationName()); - additionalProps.put("publisherHomepage", uiAssetCreateRequest.getPublisherHomepage()); - additionalProps.put("licenseUrl", uiAssetCreateRequest.getLicenseUrl()); - additionalProps.put("keywords", uiAssetCreateRequest.getKeywords()); - additionalProps.put("distribution", uiAssetCreateRequest.getDistribution()); - additionalProps.put("landingPageUrl", uiAssetCreateRequest.getLandingPageUrl()); - additionalProps.put("dataCategory", uiAssetCreateRequest.getDataCategory()); - additionalProps.put("dataSubcategory", uiAssetCreateRequest.getDataSubcategory()); - additionalProps.put("dataModel", uiAssetCreateRequest.getDataModel()); - additionalProps.put("geoReferenceMethod", uiAssetCreateRequest.getGeoReferenceMethod()); - additionalProps.put("transportMode", uiAssetCreateRequest.getTransportMode()); - - if(uiAssetCreateRequest.getAdditionalProperties() != null) { - additionalProps.putAll(uiAssetCreateRequest.getAdditionalProperties()); - } - if(uiAssetCreateRequest.getPrivateProperties() != null) { - assetBuilder.privateProperties(new HashMap<>(uiAssetCreateRequest.getPrivateProperties())); - } - if(uiAssetCreateRequest.getAdditionalJsonProperties() != null) { - additionalProps.putAll(uiAssetCreateRequest.getAdditionalJsonProperties()); - } + var properties = Json.createObjectBuilder() + .add(Prop.Dcat.KEYWORDS, Json.createArrayBuilder(uiAssetCreateRequest.getKeywords())) + .add(Prop.Dcterms.PUBLISHER, Json.createObjectBuilder() + .add(Prop.TYPE, Prop.Foaf.ORGANIZATION) + .add(Prop.Foaf.HOMEPAGE, uiAssetCreateRequest.getPublisherHomepage())) + .add(Prop.Dcterms.CREATOR, Json.createObjectBuilder() + .add(Prop.TYPE, Prop.Foaf.ORGANIZATION) + .add(Prop.Foaf.NAME, uiAssetCreateRequest.getCreatorOrganizationName())) + .add(Prop.Dcterms.LICENSE, uiAssetCreateRequest.getLicenseUrl()) + .add(Prop.Dcterms.TITLE, uiAssetCreateRequest.getTitle()) + .add(Prop.Dcterms.DESCRIPTION, uiAssetCreateRequest.getDescription()) + .add(Prop.Dcterms.LANGUAGE, uiAssetCreateRequest.getLanguage()) + .add(Prop.Dcat.VERSION, uiAssetCreateRequest.getVersion()) + .add(Prop.Dcat.MEDIATYPE, uiAssetCreateRequest.getDistribution()) + .add(Prop.Dcat.LANDING_PAGE, uiAssetCreateRequest.getLandingPageUrl()) + .add(Prop.Mds.DATA_CATEGORY, uiAssetCreateRequest.getDataCategory()) + .add(Prop.Mds.DATA_SUBCATEGORY, uiAssetCreateRequest.getDataSubcategory()) + .add(Prop.Mds.DATA_MODEL, uiAssetCreateRequest.getDataModel()) + .add(Prop.Mds.GEO_REFERENCE_METHOD, uiAssetCreateRequest.getGeoReferenceMethod()) + .add(Prop.Mds.TRANSPORT_MODE, uiAssetCreateRequest.getTransportMode()) + .build(); - assetBuilder.properties(additionalProps); + var dataAddressProperties = Json.createObjectBuilder() + .add(Prop.Edc.TYPE, uiAssetCreateRequest.getDataAddressProperties().get(Prop.Edc.TYPE)) + .add(Prop.Edc.BASE_URL, uiAssetCreateRequest.getDataAddressProperties().get(Prop.Edc.BASE_URL)) + .build(); - return assetBuilder.build(); + return Json.createObjectBuilder() + .add(Prop.ID, uiAssetCreateRequest.getId()) + .add("properties", properties) + .add("dataAddress", dataAddressProperties) + .build(); } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java index 79754c781..2d4fefefa 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java @@ -1,51 +1,63 @@ package de.sovity.edc.ext.wrapper.api.common.mappers; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.UiAssetBuilder; +import de.sovity.edc.utils.JsonUtils; import de.sovity.edc.utils.jsonld.vocab.Prop; import lombok.SneakyThrows; +import org.eclipse.edc.transform.spi.TypeTransformerRegistry; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.junit.jupiter.MockitoExtension; import java.nio.file.Files; import java.nio.file.Paths; import java.util.List; +import static de.sovity.edc.utils.jsonld.vocab.Prop.PROPERTIES; import static jakarta.json.Json.createArrayBuilder; import static jakarta.json.Json.createObjectBuilder; import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.mock; -@ExtendWith(MockitoExtension.class) class AssetMapperTest { - - @InjectMocks AssetMapper assetMapper; - @InjectMocks - UiAssetBuilder assetBuilder; + + @BeforeEach + void setup() { + var typeTransformerRegistry = mock(TypeTransformerRegistry.class); + var uiAssetBuilder = new UiAssetBuilder(); + assetMapper = new AssetMapper(typeTransformerRegistry, uiAssetBuilder); + } @Test @SneakyThrows void test_buildAssetDto() { // Arrange - String jsonContent = new String(Files.readAllBytes(Paths.get(getClass().getResource("/sample.json").toURI()))); + String assetJsonLd = new String(Files.readAllBytes(Paths.get(getClass().getResource("/example-asset-jsonld.json").toURI()))); // Act - var uiAsset = assetBuilder.buildUiAssetFromAssetHelper(assetBuilder.buildHelperDto(jsonContent)); + var uiAsset = assetMapper.buildUiAsset(JsonUtils.parseJsonObj(assetJsonLd)); // Assert - assertThat(uiAsset).isNotNull(); + assertThat(uiAsset.getAssetId()).isEqualTo("urn:artifact:my-asset"); assertThat(uiAsset.getTitle()).isEqualTo("My Asset"); + assertThat(uiAsset.getLanguage()).isEqualTo("https://w3id.org/idsa/code/EN"); assertThat(uiAsset.getDescription()).isEqualTo("Lorem Ipsum ..."); - assertThat(uiAsset.getPublisherHomepage()).isEqualTo("https://data-source.my-org/about"); 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"); assertThat(uiAsset.getVersion()).isEqualTo("1.1"); - assertThat(uiAsset.getLanguage()).isEqualTo("https://w3id.org/idsa/code/EN"); assertThat(uiAsset.getKeywords()).isEqualTo(List.of("some", "keywords")); - assertThat(uiAsset.getHttpDatasourceHintsProxyMethod()).isEqualTo(true); - assertThat(uiAsset.getHttpDatasourceHintsProxyPath()).isEqualTo(true); - assertThat(uiAsset.getDistribution()).isEqualTo("application/json"); + assertThat(uiAsset.getMediaType()).isEqualTo("application/json"); + assertThat(uiAsset.getLandingPageUrl()).isEqualTo("https://data-source.my-org/docs"); + assertThat(uiAsset.getHttpDatasourceHintsProxyMethod()).isTrue(); + assertThat(uiAsset.getHttpDatasourceHintsProxyPath()).isTrue(); + assertThat(uiAsset.getHttpDatasourceHintsProxyQueryParams()).isTrue(); + assertThat(uiAsset.getHttpDatasourceHintsProxyBody()).isTrue(); + assertThat(uiAsset.getDataCategory()).isEqualTo("Infrastructure and Logistics"); + assertThat(uiAsset.getDataSubcategory()).isEqualTo("General Information About Planning Of Routes"); + assertThat(uiAsset.getDataModel()).isEqualTo("my-data-model-001"); + assertThat(uiAsset.getGeoReferenceMethod()).isEqualTo("my-geo-reference-method"); + assertThat(uiAsset.getTransportMode()).isEqualTo("my-geo-reference-method"); } @Test @@ -53,12 +65,14 @@ void test_buildAssetDto() { void test_KeywordsAsSingleString() { // Arrange - var requestBody = createObjectBuilder() - .add(Prop.Dcat.KEYWORDS, createArrayBuilder(List.of("SingleElement"))) + var assetJsonLd = createObjectBuilder() + .add(Prop.ID, "my-asset-1") + .add(PROPERTIES, createObjectBuilder() + .add(Prop.Dcat.KEYWORDS, "SingleElement") + .build()) .build(); - // Act - var uiAsset = assetBuilder.buildUiAssetFromAssetJsonLd(requestBody.toString()); + var uiAsset = assetMapper.buildUiAsset(assetJsonLd); // Assert assertThat(uiAsset).isNotNull(); @@ -67,17 +81,19 @@ void test_KeywordsAsSingleString() { @Test @SneakyThrows - void test_StringsAsList() { + void test_StringValueWrappedInAtValue() { // Arrange - var requestBody = createObjectBuilder() - .add(Prop.Dcterms.TITLE, createObjectBuilder() - .add(Prop.VALUE, "AssetName") - .add(Prop.LANGUAGE, "en")) + var assetJsonLd = createObjectBuilder() + .add(Prop.ID, "my-asset-1") + .add(PROPERTIES, createObjectBuilder() + .add(Prop.Dcterms.TITLE, createObjectBuilder() + .add(Prop.VALUE, "AssetName") + .add(Prop.Dcterms.LANGUAGE, "en"))) .build(); // Act - var uiAsset = assetBuilder.buildUiAssetFromAssetJsonLd(requestBody.toString()); + var uiAsset = assetMapper.buildUiAsset(assetJsonLd); // Assert assertThat(uiAsset).isNotNull(); @@ -89,7 +105,7 @@ void test_StringsAsList() { void test_StringsAsMap() { // Arrange - var requestBody = createObjectBuilder() + var properties = createObjectBuilder() .add(Prop.Dcterms.TITLE, createArrayBuilder() .add(createObjectBuilder() .add(Prop.TYPE, "SomeType") @@ -97,9 +113,13 @@ void test_StringsAsMap() { ) ) .build(); + var assetJsonLd = createObjectBuilder() + .add(Prop.ID, "my-asset-1") + .add(PROPERTIES, properties) + .build(); // Act - var uiAsset = assetBuilder.buildUiAssetFromAssetJsonLd(requestBody.toString()); + var uiAsset = assetMapper.buildUiAsset(assetJsonLd); // Assert assertThat(uiAsset).isNotNull(); @@ -109,14 +129,16 @@ void test_StringsAsMap() { @Test @SneakyThrows void test_badBooleanValue() { - - //Arrange - var requestBody = createObjectBuilder() - .add(Prop.SovityDcatExt.METHOD, "wrongBooleanValue") + // Arrange + var assetJsonLd = createObjectBuilder() + .add(Prop.ID, "my-asset-1") + .add(PROPERTIES, createObjectBuilder() + .add(Prop.SovityDcatExt.METHOD, "wrongBooleanValue") + .build()) .build(); // Act - var uiAsset = assetBuilder.buildUiAssetFromAssetJsonLd(requestBody.toString()); + var uiAsset = assetMapper.buildUiAsset(assetJsonLd); // Assert assertThat(uiAsset).isNotNull(); @@ -126,14 +148,16 @@ void test_badBooleanValue() { @Test @SneakyThrows void test_noBooleanValue() { - - //Arrange - var requestBody = createObjectBuilder() - .add(Prop.SovityDcatExt.METHOD, "") + // Arrange + var assetJsonLd = createObjectBuilder() + .add(Prop.ID, "my-asset-1") + .add(PROPERTIES, createObjectBuilder() + .add(Prop.SovityDcatExt.METHOD, "") + .build()) .build(); // Act - var uiAsset = assetBuilder.buildUiAssetFromAssetJsonLd(requestBody.toString()); + var uiAsset = assetMapper.buildUiAsset(assetJsonLd); // Assert assertThat(uiAsset).isNotNull(); diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/resources/example-asset-jsonld.json b/extensions/wrapper/wrapper-common-mappers/src/test/resources/example-asset-jsonld.json new file mode 100644 index 000000000..099a95c51 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/test/resources/example-asset-jsonld.json @@ -0,0 +1,43 @@ +{ + "@id": "urn:artifact:my-asset", + "properties": { + "https://w3id.org/edc/v0.0.1/ns/id": "urn:artifact:my-asset", + "http://purl.org/dc/terms/identifier": "urn:artifact:my-asset", + "http://purl.org/dc/terms/title": "My Asset", + "http://purl.org/dc/terms/language": "https://w3id.org/idsa/code/EN", + "http://purl.org/dc/terms/description": "Lorem Ipsum ...", + "http://purl.org/dc/terms/creator": { + "@type": "http://xmlns.com/foaf/0.1/Organization", + "http://xmlns.com/foaf/0.1/name": "My Organization Name" + }, + "http://purl.org/dc/terms/publisher": { + "@type": "http://xmlns.com/foaf/0.1/Organization", + "http://xmlns.com/foaf/0.1/homepage": "https://data-source.my-org/about" + }, + "http://purl.org/dc/terms/license": "https://data-source.my-org/license", + "http://www.w3.org/ns/dcat#version": "1.1", + "http://www.w3.org/ns/dcat#keyword": [ + "some", + "keywords" + ], + "http://www.w3.org/ns/dcat#mediaType": "application/json", + "http://www.w3.org/ns/dcat#landingPage": "https://data-source.my-org/docs", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyMethod": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyPath": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyQueryParams": "true", + "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyBody": "true", + "http://w3id.org/mds#dataCategory": "Infrastructure and Logistics", + "http://w3id.org/mds#dataSubcategory": "General Information About Planning Of Routes", + "http://w3id.org/mds#dataModel": "my-data-model-001", + "http://w3id.org/mds#geoReferenceMethod": "my-geo-reference-method", + "http://w3id.org/mds#transportMode": "my-geo-reference-method", + "http://unknown/some-custom-property": "test" + }, + "privateProperties": { + "idk": "abc" + }, + "dataAddress": { + "https://w3id.org/edc/v0.0.1/ns/type": "HttpData", + "https://w3id.org/edc/v0.0.1/ns/baseUrl": "https://data-source.my-org" + } +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/resources/sample.json b/extensions/wrapper/wrapper-common-mappers/src/test/resources/sample.json deleted file mode 100644 index 74588f668..000000000 --- a/extensions/wrapper/wrapper-common-mappers/src/test/resources/sample.json +++ /dev/null @@ -1,38 +0,0 @@ -{ - "https://w3id.org/edc/v0.0.1/ns/": "urn:artifact:my-asset", - - "http://purl.org/dc/terms/identifier": "urn:artifact:my-asset", - "http://purl.org/dc/terms/title": "My Asset", - "http://purl.org/dc/terms/language": "https://w3id.org/idsa/code/EN", - "http://purl.org/dc/terms/description": "Lorem Ipsum ...", - "http://purl.org/dc/terms/creator": { - "@type": "http://xmlns.com/foaf/0.1/Organization", - "http://xmlns.com/foaf/0.1/name": "My Organization Name" - }, - "http://purl.org/dc/terms/publisher": { - "@type": "http://xmlns.com/foaf/0.1/Organization", - "http://xmlns.com/foaf/0.1/homepage": "https://data-source.my-org/about" - }, - "http://purl.org/dc/terms/license": "https://data-source.my-org/license", - - "http://www.w3.org/ns/dcat#version": "1.1", - "http://www.w3.org/ns/dcat#keyword": ["some", "keywords"], - "http://www.w3.org/ns/dcat#distribution": { - "@type": "http://www.w3.org/ns/dcat#Distribution", - "http://www.w3.org/ns/dcat#mediaType": "application/json" - }, - "http://www.w3.org/ns/dcat#landingPage": "https://data-source.my-org/docs", - - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyMethod": "true", - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyPath": "true", - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyQueryParams": "true", - "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxyBody": "true", - - "http://w3id.org/mds#dataCategory": "Infrastructure and Logistics", - "http://w3id.org/mds#dataSubcategory": "General Information About Planning Of Routes", - "http://w3id.org/mds#dataModel": "my-data-model-001", - "http://w3id.org/mds#geoReferenceMethod": "my-geo-reference-method", - "http://w3id.org/mds#transportMode": "my-geo-reference-method", - - "http://unknown/some-custom-property": "test" -} diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java index c8c39ed9d..651073b8f 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java @@ -116,8 +116,8 @@ public static WrapperExtensionContext buildContext( atomicConstraintMapper, typeTransformerRegistry); var edcPropertyMapperUtils = new EdcPropertyMapperUtils(); - var assetBuilder = new UiAssetBuilder(edcPropertyMapperUtils); - var assetMapper = new AssetMapper(objectMapper, typeTransformerRegistry, assetBuilder); + var assetBuilder = new UiAssetBuilder(); + var assetMapper = new AssetMapper(typeTransformerRegistry, assetBuilder); var transferProcessStateService = new TransferProcessStateService(); var contractAgreementPageCardBuilder = new ContractAgreementPageCardBuilder( policyMapper, @@ -150,7 +150,7 @@ public static WrapperExtensionContext buildContext( transferProcessService); var contractNegotiationUtils = new ContractNegotiationUtils(contractNegotiationService); var contractAgreementUtils = new ContractAgreementUtils(contractAgreementService); - var assetApiService = new AssetApiService(assetService, assetMapper, assetBuilder); + var assetApiService = new AssetApiService(assetService, assetMapper); var transferRequestBuilder = new TransferRequestBuilder( objectMapper, contractAgreementUtils, diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java index cee7b8f97..78b4a17b3 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java @@ -15,7 +15,6 @@ package de.sovity.edc.ext.wrapper.api.ui.pages.asset; import de.sovity.edc.ext.wrapper.api.common.mappers.AssetMapper; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.UiAssetBuilder; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import de.sovity.edc.ext.wrapper.api.ui.model.IdResponseDto; @@ -32,19 +31,16 @@ public class AssetApiService { private final AssetService assetService; private final AssetMapper assetMapper; - private final UiAssetBuilder assetBuilder; public List getAssets() { var assets = getAllAssets(); - return assets.stream().sorted(Comparator.comparing(Asset::getCreatedAt).reversed()).map(asset -> { - var entry = assetMapper.buildUiAssetFromAsset(asset); - return entry; - }).toList(); + return assets.stream().sorted(Comparator.comparing(Asset::getCreatedAt).reversed()) + .map(assetMapper::buildUiAsset).toList(); } @NotNull public IdResponseDto createAsset(UiAssetCreateRequest request) { - var asset = assetBuilder.buildAssetFromUiAssetCreateRequest(request); + var asset = assetMapper.buildAsset(request); asset = assetService.create(asset).getContent(); return new IdResponseDto(asset.getId()); } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiService.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiService.java index e6ac69417..6bfa417fe 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiService.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/catalog/CatalogApiService.java @@ -61,8 +61,8 @@ private UiContractOffer buildContractOffer(DspContractOffer contractOffer) { } private UiAsset buildUiAsset(DspDataOffer dataOffer) { - var asset = assetMapper.buildAssetFromAssetPropertiesJsonLd(dataOffer.getAssetPropertiesJsonLd()); - return assetMapper.buildUiAssetFromAsset(asset); + var asset = assetMapper.buildAssetFromDatasetProperties(dataOffer.getAssetPropertiesJsonLd()); + return assetMapper.buildUiAsset(asset); } private UiPolicy buildUiPolicy(DspContractOffer contractOffer) { diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/ContractAgreementPageCardBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/ContractAgreementPageCardBuilder.java index 09b0c5cdc..f75c568fc 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/ContractAgreementPageCardBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/ContractAgreementPageCardBuilder.java @@ -16,7 +16,6 @@ import de.sovity.edc.ext.wrapper.api.common.mappers.AssetMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.PolicyMapper; -import de.sovity.edc.ext.wrapper.api.common.model.AssetDto; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementCard; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementDirection; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementTransferProcess; @@ -36,13 +35,6 @@ import static de.sovity.edc.ext.wrapper.utils.EdcDateUtils.utcMillisToOffsetDateTime; import static de.sovity.edc.ext.wrapper.utils.EdcDateUtils.utcSecondsToOffsetDateTime; -import java.util.Comparator; -import java.util.List; - -import static de.sovity.edc.ext.wrapper.utils.EdcDateUtils.utcMillisToOffsetDateTime; -import static de.sovity.edc.ext.wrapper.utils.EdcDateUtils.utcSecondsToOffsetDateTime; -import static de.sovity.edc.ext.wrapper.utils.MapUtils.mapValues; - @Slf4j @RequiredArgsConstructor public class ContractAgreementPageCardBuilder { @@ -64,7 +56,7 @@ public ContractAgreementCard buildContractAgreementCard( card.setCounterPartyAddress(negotiation.getCounterPartyAddress()); card.setCounterPartyId(negotiation.getCounterPartyId()); card.setContractSigningDate(utcSecondsToOffsetDateTime(agreement.getContractSigningDate())); - card.setAsset(assetMapper.buildUiAssetFromAsset(asset)); + card.setAsset(assetMapper.buildUiAsset(asset)); card.setContractPolicy(policyMapper.buildUiPolicy(agreement.getPolicy())); card.setTransferProcesses(buildTransferProcesses(transferProcesses)); return card; diff --git a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index 69caf33d3..275a1d6e8 100644 --- a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -18,6 +18,7 @@ import de.sovity.edc.client.gen.model.ContractAgreementTransferRequestParams; import de.sovity.edc.client.gen.model.ContractNegotiationRequest; import de.sovity.edc.client.gen.model.ContractNegotiationState.SimplifiedStateEnum; +import de.sovity.edc.client.gen.model.UiAssetCreateRequest; import de.sovity.edc.client.gen.model.UiContractNegotiation; import de.sovity.edc.client.gen.model.UiContractOffer; import de.sovity.edc.client.gen.model.UiDataOffer; @@ -89,7 +90,13 @@ void provide_consume_assetMapping_policyMapping() { // TODO test all asset properties including additionalProperties var data = "expected data 123"; var assetId = UUID.randomUUID().toString(); - providerConnector.createDataOffer(assetId, dataAddress.getDataSourceUrl(data)); + //providerConnector.createDataOffer(assetId, dataAddress.getDataSourceUrl(data)); + + var providerClient = consumerClient; //TODO use providerClient + + var assetCreateRequest = UiAssetCreateRequest.builder() + .build(); + providerClient.uiApi().createAsset(assetCreateRequest); var dataOffers = consumerClient.uiApi().catalogPageDataOffers(getProtocolEndpoint(providerConnector)); assertThat(dataOffers).hasSize(1); diff --git a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java index d884bfd10..2208db9c1 100644 --- a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java +++ b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java @@ -21,6 +21,7 @@ public class Prop { public final String TYPE = "@type"; public final String VALUE = "@value"; public final String LANGUAGE = "@language"; + public final String PROPERTIES = "properties"; @UtilityClass public class Edc { @@ -29,6 +30,8 @@ public class Edc { public final String ID = CTX + "id"; public final String PARTICIPANT_ID = CTX + "participantId"; public final String PROPERTIES = CTX + "properties"; + public final String TYPE = CTX + "type"; + public final String BASE_URL = CTX + "baseUrl"; } /** @@ -51,6 +54,7 @@ public class Dcat { public final String VERSION = CTX + "version"; public final String KEYWORDS = CTX + "keyword"; public final String LANDING_PAGE = CTX + "landingPage"; + public final String MEDIATYPE = CTX + "mediaType"; } /** @@ -68,8 +72,13 @@ public class Odrl { @UtilityClass public class Dcterms { public final String CTX = "http://purl.org/dc/terms/"; - public final String TITLE = CTX + "TITLE"; - public final String DESCRIPTION = CTX + "DESCRIPTION"; + public final String IDENTIFIER = CTX + "identifier"; + public final String TITLE = CTX + "title"; + public final String DESCRIPTION = CTX + "description"; + public final String LANGUAGE = CTX + "language"; + public final String CREATOR = CTX + "creator"; + public final String PUBLISHER = CTX + "publisher"; + public final String LICENSE = CTX + "license"; } /** @@ -77,9 +86,34 @@ public class Dcterms { */ @UtilityClass public class SovityDcatExt { - public final String CTX = "https://semantic.sovity.io/dcat-ext#httpDatasourceHintsProxy"; - public final String METHOD = CTX + "method/"; - public final String PATH = CTX + "path/"; + public final String CTX = "https://semantic.sovity.io/dcat-ext#"; + public final String METHOD = CTX + "httpDatasourceHintsProxyMethod"; + public final String PATH = CTX + "httpDatasourceHintsProxyPath"; + public final String QUERY_PARAMS = CTX + "httpDatasourceHintsProxyQueryParams"; + public final String BODY = CTX + "httpDatasourceHintsProxyBody"; + } + /** + * FOAF Vocabulary + */ + @UtilityClass + public class Foaf { + public final String CTX = "http://xmlns.com/foaf/0.1/"; + public final String ORGANIZATION = CTX + "Organization"; + public final String NAME = CTX + "name"; + public final String HOMEPAGE = CTX + "homepage"; + } + + /** + * MDS Vocabulary + */ + @UtilityClass + public class Mds { + public final String CTX = "http://w3id.org/mds#"; + public final String DATA_CATEGORY = CTX + "dataCategory"; + public final String DATA_SUBCATEGORY = CTX + "dataSubcategory"; + public final String DATA_MODEL = CTX + "dataModel"; + public final String GEO_REFERENCE_METHOD = CTX + "geoReferenceMethod"; + public final String TRANSPORT_MODE = CTX + "transportMode"; } } From 43189c0257eefab8ab985e7d5cb6cd3828c640fd Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Mon, 18 Sep 2023 14:02:22 +0200 Subject: [PATCH 18/37] fix: PR Revision (Asset Mapper + Asset Mapper Test) --- .../edc/client/AssetApiServiceTest.java | 11 ++- .../edc/client/ContractAgreementPageTest.java | 2 +- .../wrapper-common-mappers/build.gradle.kts | 1 + .../api/common/mappers/AssetMapper.java | 13 +++- .../mappers/utils/JsonBuilderUtils.java | 38 ++++++++++ .../common/mappers/utils/UiAssetBuilder.java | 69 +++++++++++-------- .../api/ui/pages/asset/AssetApiService.java | 1 + .../de/sovity/edc/e2e/UiApiWrapperTest.java | 28 ++------ 8 files changed, 103 insertions(+), 60 deletions(-) create mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonBuilderUtils.java diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java index 17ede9770..70a0802a8 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java @@ -16,6 +16,7 @@ import de.sovity.edc.client.gen.model.UiAssetCreateRequest; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; +import de.sovity.edc.utils.jsonld.vocab.Prop; import lombok.SneakyThrows; import org.eclipse.edc.connector.spi.asset.AssetService; import org.eclipse.edc.junit.annotations.ApiTest; @@ -66,7 +67,7 @@ void assetPage(AssetService assetStore) { var assets = result.getAssets(); assertThat(assets).hasSize(1); var asset = assets.get(0); - assertThat(asset.getId()).isEqualTo(properties.get(Asset.PROPERTY_ID)); + assertThat(asset.getAssetId()).isEqualTo(properties.get(Asset.PROPERTY_ID)); assertThat(asset.getLandingPageUrl()).isEqualTo(properties.get("landingPage")); assertThat(asset.getPrivateProperties()).isEqualTo(privateProperties); } @@ -84,7 +85,7 @@ void assetPageSorting(AssetService assetService) { // assert assertThat(result.getAssets()) - .extracting(asset -> asset.getId()) + .extracting(asset -> asset.getAssetId()) .containsExactly("asset-3", "asset-2", "asset-1"); } @@ -93,13 +94,11 @@ void testAssetCreation(AssetService assetService) { // arrange var client = TestUtils.edcClient(); var dataAddressProperties = Map.of( - EDC_DATA_ADDRESS_TYPE_PROPERTY, DATA_ADDRESS_TYPE, - "baseUrl", DATA_SINK + Prop.Edc.TYPE, DATA_ADDRESS_TYPE, + Prop.Edc.BASE_URL, DATA_SINK ); var uiAssetRequest = UiAssetCreateRequest.builder() .id("asset-1") - .name("AssetName") - .keywords(List.of("keyword1", "keyword2")) .dataAddressProperties(dataAddressProperties) .build(); diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/ContractAgreementPageTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/ContractAgreementPageTest.java index 9b199d2f5..6dac1f493 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/ContractAgreementPageTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/ContractAgreementPageTest.java @@ -94,7 +94,7 @@ void testContractAgreementPage( assertThat(agreement.getCounterPartyAddress()).isEqualTo("http://other-connector"); assertThat(agreement.getCounterPartyId()).isEqualTo("urn:connector:other-connector"); assertThat(agreement.getContractSigningDate()).isEqualTo(todayPlusDays(0)); - assertThat(agreement.getAsset().getId()).isEqualTo(ASSET_ID); + assertThat(agreement.getAsset().getAssetId()).isEqualTo(ASSET_ID); assertThat(agreement.getAsset().getLandingPageUrl()).isEqualTo("X"); assertThat(agreement.getTransferProcesses()).hasSize(1); diff --git a/extensions/wrapper/wrapper-common-mappers/build.gradle.kts b/extensions/wrapper/wrapper-common-mappers/build.gradle.kts index 48f4332a3..706433936 100644 --- a/extensions/wrapper/wrapper-common-mappers/build.gradle.kts +++ b/extensions/wrapper/wrapper-common-mappers/build.gradle.kts @@ -22,6 +22,7 @@ dependencies { api(project(":utils:json-and-jsonld-utils")) implementation("org.apache.commons:commons-lang3:3.13.0") implementation("org.apache.commons:commons-collections4:4.4") + implementation("com.google.code.gson:gson:2.7") testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}") testCompileOnly("org.projectlombok:lombok:${lombokVersion}") diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java index c42a0dfe6..0babf1fb6 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java @@ -11,6 +11,7 @@ import org.eclipse.edc.spi.types.domain.asset.Asset; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; +import java.util.Map; import java.util.Optional; @@ -30,7 +31,8 @@ public UiAsset buildUiAsset(JsonObject assetJsonLd) { public Asset buildAsset(UiAssetCreateRequest createRequest) { var assetJsonLd = uiAssetBuilder.buildAssetJsonLd(createRequest); - return buildAsset(assetJsonLd); + var asset = buildAsset(assetJsonLd); + return asset.toBuilder().build(); } public Asset buildAssetFromDatasetProperties(JsonObject json) { @@ -44,7 +46,6 @@ private JsonObject buildJsonLdFromDatasetProperties(JsonObject json) { return Json.createObjectBuilder() .add(Prop.ID, assetId) - .add(Prop.TYPE, Prop.Edc.TYPE_ASSET) .add(Prop.Edc.PROPERTIES, json) .build(); } @@ -54,6 +55,14 @@ private JsonObject buildAssetJsonLd(Asset asset) { } private Asset buildAsset(JsonObject assetJsonLd) { + + //test + var testAsset = Asset.Builder.newInstance() + .id("asset-1") + .properties(Map.of()) + .build(); + var assetstring = typeTransformerRegistry.transform(testAsset, JsonObject.class).getContent().toString(); + return typeTransformerRegistry.transform(assetJsonLd, Asset.class).getContent(); } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonBuilderUtils.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonBuilderUtils.java new file mode 100644 index 000000000..35b8a0e80 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonBuilderUtils.java @@ -0,0 +1,38 @@ +package de.sovity.edc.ext.wrapper.api.common.mappers.utils; + +import jakarta.json.Json; +import jakarta.json.JsonObject; +import jakarta.json.JsonObjectBuilder; +import jakarta.json.JsonValue; +import lombok.RequiredArgsConstructor; + +import java.util.List; +import java.util.Map; + +@RequiredArgsConstructor +public class JsonBuilderUtils { + + protected static JsonObjectBuilder addNonNull(JsonObjectBuilder builder, String key, Object value) { + if (value != null) { + builder.add(key, (String) value); + } + return builder; + } + + protected static JsonObjectBuilder addNonNullArray(JsonObjectBuilder builder, String key, List values) { + if (values != null && !values.isEmpty()) { + builder.add(key, Json.createArrayBuilder(values)); + } + return builder; + } + + protected static JsonObject mapToJson(Map map) { + JsonObjectBuilder builder = Json.createObjectBuilder(); + + for (Map.Entry entry : map.entrySet()) { + builder.add(entry.getKey(), Json.createValue((String) entry.getValue())); + } + + return builder.build(); + } +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java index e7c2e4bfa..b3671b079 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java @@ -1,14 +1,19 @@ package de.sovity.edc.ext.wrapper.api.common.mappers.utils; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.ObjectMapper; +import com.google.gson.Gson; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import de.sovity.edc.utils.JsonUtils; import de.sovity.edc.utils.jsonld.vocab.Prop; import jakarta.json.Json; import jakarta.json.JsonObject; +import jakarta.json.JsonObjectBuilder; import lombok.RequiredArgsConstructor; import lombok.SneakyThrows; +import org.jetbrains.annotations.Nullable; @RequiredArgsConstructor public class UiAssetBuilder { @@ -58,39 +63,47 @@ private AssetJsonLd parseAssetJsonLd(String assetJsonLd) { } @SneakyThrows + @Nullable public JsonObject buildAssetJsonLd(UiAssetCreateRequest uiAssetCreateRequest) { - var properties = Json.createObjectBuilder() - .add(Prop.Dcat.KEYWORDS, Json.createArrayBuilder(uiAssetCreateRequest.getKeywords())) - .add(Prop.Dcterms.PUBLISHER, Json.createObjectBuilder() - .add(Prop.TYPE, Prop.Foaf.ORGANIZATION) - .add(Prop.Foaf.HOMEPAGE, uiAssetCreateRequest.getPublisherHomepage())) - .add(Prop.Dcterms.CREATOR, Json.createObjectBuilder() - .add(Prop.TYPE, Prop.Foaf.ORGANIZATION) - .add(Prop.Foaf.NAME, uiAssetCreateRequest.getCreatorOrganizationName())) - .add(Prop.Dcterms.LICENSE, uiAssetCreateRequest.getLicenseUrl()) - .add(Prop.Dcterms.TITLE, uiAssetCreateRequest.getTitle()) - .add(Prop.Dcterms.DESCRIPTION, uiAssetCreateRequest.getDescription()) - .add(Prop.Dcterms.LANGUAGE, uiAssetCreateRequest.getLanguage()) - .add(Prop.Dcat.VERSION, uiAssetCreateRequest.getVersion()) - .add(Prop.Dcat.MEDIATYPE, uiAssetCreateRequest.getDistribution()) - .add(Prop.Dcat.LANDING_PAGE, uiAssetCreateRequest.getLandingPageUrl()) - .add(Prop.Mds.DATA_CATEGORY, uiAssetCreateRequest.getDataCategory()) - .add(Prop.Mds.DATA_SUBCATEGORY, uiAssetCreateRequest.getDataSubcategory()) - .add(Prop.Mds.DATA_MODEL, uiAssetCreateRequest.getDataModel()) - .add(Prop.Mds.GEO_REFERENCE_METHOD, uiAssetCreateRequest.getGeoReferenceMethod()) - .add(Prop.Mds.TRANSPORT_MODE, uiAssetCreateRequest.getTransportMode()) - .build(); + var propertiesBuilder = Json.createObjectBuilder(); - var dataAddressProperties = Json.createObjectBuilder() - .add(Prop.Edc.TYPE, uiAssetCreateRequest.getDataAddressProperties().get(Prop.Edc.TYPE)) - .add(Prop.Edc.BASE_URL, uiAssetCreateRequest.getDataAddressProperties().get(Prop.Edc.BASE_URL)) - .build(); + JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Edc.ID, uiAssetCreateRequest.getId()); + JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Dcterms.LICENSE, uiAssetCreateRequest.getLicenseUrl()); + JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Dcterms.TITLE, uiAssetCreateRequest.getTitle()); + JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Dcterms.DESCRIPTION, uiAssetCreateRequest.getDescription()); + JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Dcterms.LANGUAGE, uiAssetCreateRequest.getLanguage()); + JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Dcat.VERSION, uiAssetCreateRequest.getVersion()); + JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Dcat.MEDIATYPE, uiAssetCreateRequest.getDistribution()); + JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Dcat.LANDING_PAGE, uiAssetCreateRequest.getLandingPageUrl()); + JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Mds.DATA_CATEGORY, uiAssetCreateRequest.getDataCategory()); + JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Mds.DATA_SUBCATEGORY, uiAssetCreateRequest.getDataSubcategory()); + JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Mds.DATA_MODEL, uiAssetCreateRequest.getDataModel()); + JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Mds.GEO_REFERENCE_METHOD, uiAssetCreateRequest.getGeoReferenceMethod()); + JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Mds.TRANSPORT_MODE, uiAssetCreateRequest.getTransportMode()); + JsonBuilderUtils.addNonNullArray(propertiesBuilder, Prop.Dcat.KEYWORDS, uiAssetCreateRequest.getKeywords()); + + if (uiAssetCreateRequest.getPublisherHomepage() != null) { + propertiesBuilder.add(Prop.Dcterms.PUBLISHER, Json.createObjectBuilder() + .add(Prop.TYPE, Prop.Foaf.ORGANIZATION) + .add(Prop.Foaf.HOMEPAGE, uiAssetCreateRequest.getPublisherHomepage())); + } + if (uiAssetCreateRequest.getCreatorOrganizationName() != null) { + propertiesBuilder.add(Prop.Dcterms.CREATOR, Json.createObjectBuilder() + .add(Prop.TYPE, Prop.Foaf.ORGANIZATION) + .add(Prop.Foaf.NAME, uiAssetCreateRequest.getCreatorOrganizationName())); + + } - return Json.createObjectBuilder() + var assetJsonLd = Json.createObjectBuilder() .add(Prop.ID, uiAssetCreateRequest.getId()) - .add("properties", properties) - .add("dataAddress", dataAddressProperties) + .add(Prop.TYPE, Prop.Edc.TYPE_ASSET) + .add(Prop.Edc.PROPERTIES, propertiesBuilder.build()) .build(); + + var assetJsonLdString = assetJsonLd.toString(); + + + return assetJsonLd; } } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java index 78b4a17b3..c1212db42 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java @@ -18,6 +18,7 @@ import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import de.sovity.edc.ext.wrapper.api.ui.model.IdResponseDto; +import lombok.Builder; import lombok.RequiredArgsConstructor; import org.eclipse.edc.connector.spi.asset.AssetService; import org.eclipse.edc.spi.query.QuerySpec; diff --git a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index 275a1d6e8..4abb14d36 100644 --- a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -95,6 +95,9 @@ void provide_consume_assetMapping_policyMapping() { var providerClient = consumerClient; //TODO use providerClient var assetCreateRequest = UiAssetCreateRequest.builder() + .id("asset-1") + .title("AssetName") + .keywords(List.of("keyword1", "keyword2")) .build(); providerClient.uiApi().createAsset(assetCreateRequest); @@ -111,36 +114,15 @@ void provide_consume_assetMapping_policyMapping() { // assert assertThat(dataOffer.getEndpoint()).isEqualTo(getProtocolEndpoint(providerConnector)); assertThat(dataOffer.getParticipantId()).isEqualTo(PROVIDER_PARTICIPANT_ID); - assertThat(dataOffer.getAsset().getId()).isEqualTo(assetId); + assertThat(dataOffer.getAsset().getAssetId()).isEqualTo(assetId); validateDataTransferred(dataAddress.getDataSinkSpyUrl(), data); } - @Test - void testAssetCreation() { - // arrange - var assetId = UUID.randomUUID().toString(); - - Map dataSource = Map.of( - "name", "transfer-test", - "baseUrl", dataAddress.getDataSourceUrl("dummy test data"), - "type", "HttpData", - "proxyQueryParams", "true" - ); - providerConnector.createAsset(assetId, dataSource); - - var assets = consumerClient.uiApi().assetPage(); - - assertThat(assets.getAssets()).hasSize(1); - var asset = assets.getAssets().get(0); - assertThat(asset.getName()).isEqualTo("AssetName"); - assertThat(asset.getKeywords()).isEqualTo(List.of("keyword1", "keyword2")); - } - private UiContractNegotiation negotiate(UiDataOffer dataOffer, UiContractOffer contractOffer) { var negotiationRequest = ContractNegotiationRequest.builder() .counterPartyAddress(dataOffer.getEndpoint()) .counterPartyParticipantId(dataOffer.getParticipantId()) - .assetId(dataOffer.getAsset().getId()) + .assetId(dataOffer.getAsset().getAssetId()) .contractOfferId(contractOffer.getContractOfferId()) .policyJsonLd(contractOffer.getPolicy().getPolicyJsonLd()) .build(); From 83190bc7bec3d31fcb0d7c455ace96bd1cc3ee88 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Mon, 18 Sep 2023 14:29:07 +0200 Subject: [PATCH 19/37] test: fix AssetApiServiceTest#testAssetCreation --- .../edc/client/AssetApiServiceTest.java | 15 ++-- .../api/common/mappers/AssetMapper.java | 3 +- .../mappers/utils/JsonBuilderUtils.java | 3 +- .../common/mappers/utils/UiAssetBuilder.java | 72 +++++++++++-------- .../api/common/mappers/AssetMapperTest.java | 3 +- .../WrapperExtensionContextBuilder.java | 2 +- .../sovity/edc/utils/jsonld/vocab/Prop.java | 2 + 7 files changed, 57 insertions(+), 43 deletions(-) diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java index 70a0802a8..2af6f96bc 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java @@ -14,6 +14,7 @@ package de.sovity.edc.client; +import de.sovity.edc.client.gen.model.UiAsset; import de.sovity.edc.client.gen.model.UiAssetCreateRequest; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; import de.sovity.edc.utils.jsonld.vocab.Prop; @@ -33,14 +34,12 @@ import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; -import static org.eclipse.edc.spi.types.domain.DataAddress.EDC_DATA_ADDRESS_TYPE_PROPERTY; @ApiTest @ExtendWith(EdcExtension.class) public class AssetApiServiceTest { public static final String DATA_SINK = "http://my-data-sink/api/stuff"; - public static final String DATA_ADDRESS_TYPE = "HttpData"; EdcPropertyMapperUtils edcPropertyUtils; @BeforeEach @@ -85,7 +84,7 @@ void assetPageSorting(AssetService assetService) { // assert assertThat(result.getAssets()) - .extracting(asset -> asset.getAssetId()) + .extracting(UiAsset::getAssetId) .containsExactly("asset-3", "asset-2", "asset-1"); } @@ -94,11 +93,13 @@ void testAssetCreation(AssetService assetService) { // arrange var client = TestUtils.edcClient(); var dataAddressProperties = Map.of( - Prop.Edc.TYPE, DATA_ADDRESS_TYPE, + Prop.Edc.TYPE, "HttpData", Prop.Edc.BASE_URL, DATA_SINK ); var uiAssetRequest = UiAssetCreateRequest.builder() .id("asset-1") + .title("AssetName") + .keywords(List.of("keyword1", "keyword2")) .dataAddressProperties(dataAddressProperties) .build(); @@ -110,8 +111,8 @@ void testAssetCreation(AssetService assetService) { var assets = assetService.query(QuerySpec.max()).getContent().toList(); assertThat(assets).hasSize(1); var asset = assets.get(0); - assertThat(asset.getName()).isEqualTo("AssetName"); - assertThat(asset.getProperties().get("keywords")).isEqualTo(List.of("keyword1", "keyword2")); + assertThat(asset.getProperties()).containsEntry(Prop.Dcterms.TITLE, "AssetName"); + assertThat(asset.getProperties()).containsEntry(Prop.Dcat.KEYWORDS, List.of("keyword1", "keyword2")); assertThat(asset.getDataAddress().getProperties()).isEqualTo(dataAddressProperties); } @@ -138,7 +139,7 @@ private void createAsset( ) { DataAddress dataAddress = DataAddress.Builder.newInstance() - .type(DATA_ADDRESS_TYPE) + .type("HttpData") .property("baseUrl", DATA_SINK) .build(); diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java index 0babf1fb6..a9f52e6e3 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java @@ -31,8 +31,7 @@ public UiAsset buildUiAsset(JsonObject assetJsonLd) { public Asset buildAsset(UiAssetCreateRequest createRequest) { var assetJsonLd = uiAssetBuilder.buildAssetJsonLd(createRequest); - var asset = buildAsset(assetJsonLd); - return asset.toBuilder().build(); + return buildAsset(assetJsonLd); } public Asset buildAssetFromDatasetProperties(JsonObject json) { diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonBuilderUtils.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonBuilderUtils.java index 35b8a0e80..50d9effa8 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonBuilderUtils.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonBuilderUtils.java @@ -5,6 +5,7 @@ import jakarta.json.JsonObjectBuilder; import jakarta.json.JsonValue; import lombok.RequiredArgsConstructor; +import org.apache.commons.collections4.CollectionUtils; import java.util.List; import java.util.Map; @@ -20,7 +21,7 @@ protected static JsonObjectBuilder addNonNull(JsonObjectBuilder builder, String } protected static JsonObjectBuilder addNonNullArray(JsonObjectBuilder builder, String key, List values) { - if (values != null && !values.isEmpty()) { + if (CollectionUtils.isNotEmpty(values)) { builder.add(key, Json.createArrayBuilder(values)); } return builder; diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java index b3671b079..fa2a17569 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java @@ -1,9 +1,6 @@ package de.sovity.edc.ext.wrapper.api.common.mappers.utils; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.databind.ObjectMapper; -import com.google.gson.Gson; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import de.sovity.edc.utils.JsonUtils; @@ -15,9 +12,13 @@ import lombok.SneakyThrows; import org.jetbrains.annotations.Nullable; +import static de.sovity.edc.ext.wrapper.api.common.mappers.utils.JsonBuilderUtils.addNonNull; +import static de.sovity.edc.ext.wrapper.api.common.mappers.utils.JsonBuilderUtils.addNonNullArray; + @RequiredArgsConstructor public class UiAssetBuilder { private final ObjectMapper mapper = new ObjectMapper(); + private final EdcPropertyMapperUtils edcPropertyMapperUtils; public UiAsset buildUiAsset(JsonObject assetJsonLd) { var assetJsonLdObj = parseAssetJsonLd(JsonUtils.toJson(assetJsonLd)); @@ -65,45 +66,54 @@ private AssetJsonLd parseAssetJsonLd(String assetJsonLd) { @SneakyThrows @Nullable public JsonObject buildAssetJsonLd(UiAssetCreateRequest uiAssetCreateRequest) { + var properties = getAssetProperties(uiAssetCreateRequest); + var dataAddress = getDataAddress(uiAssetCreateRequest); - var propertiesBuilder = Json.createObjectBuilder(); - - JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Edc.ID, uiAssetCreateRequest.getId()); - JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Dcterms.LICENSE, uiAssetCreateRequest.getLicenseUrl()); - JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Dcterms.TITLE, uiAssetCreateRequest.getTitle()); - JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Dcterms.DESCRIPTION, uiAssetCreateRequest.getDescription()); - JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Dcterms.LANGUAGE, uiAssetCreateRequest.getLanguage()); - JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Dcat.VERSION, uiAssetCreateRequest.getVersion()); - JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Dcat.MEDIATYPE, uiAssetCreateRequest.getDistribution()); - JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Dcat.LANDING_PAGE, uiAssetCreateRequest.getLandingPageUrl()); - JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Mds.DATA_CATEGORY, uiAssetCreateRequest.getDataCategory()); - JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Mds.DATA_SUBCATEGORY, uiAssetCreateRequest.getDataSubcategory()); - JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Mds.DATA_MODEL, uiAssetCreateRequest.getDataModel()); - JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Mds.GEO_REFERENCE_METHOD, uiAssetCreateRequest.getGeoReferenceMethod()); - JsonBuilderUtils.addNonNull(propertiesBuilder, Prop.Mds.TRANSPORT_MODE, uiAssetCreateRequest.getTransportMode()); - JsonBuilderUtils.addNonNullArray(propertiesBuilder, Prop.Dcat.KEYWORDS, uiAssetCreateRequest.getKeywords()); + return Json.createObjectBuilder() + .add(Prop.ID, uiAssetCreateRequest.getId()) + .add(Prop.TYPE, Prop.Edc.TYPE_ASSET) + .add(Prop.Edc.PROPERTIES, Json.createArrayBuilder().add(properties)) + .add(Prop.Edc.DATA_ADDRESS, Json.createArrayBuilder().add(dataAddress)) + .build(); + } + + private JsonObjectBuilder getAssetProperties(UiAssetCreateRequest uiAssetCreateRequest) { + var properties = Json.createObjectBuilder(); + + addNonNull(properties, Prop.Edc.ID, uiAssetCreateRequest.getId()); + addNonNull(properties, Prop.Dcterms.LICENSE, uiAssetCreateRequest.getLicenseUrl()); + addNonNull(properties, Prop.Dcterms.TITLE, uiAssetCreateRequest.getTitle()); + addNonNull(properties, Prop.Dcterms.DESCRIPTION, uiAssetCreateRequest.getDescription()); + addNonNull(properties, Prop.Dcterms.LANGUAGE, uiAssetCreateRequest.getLanguage()); + addNonNull(properties, Prop.Dcat.VERSION, uiAssetCreateRequest.getVersion()); + addNonNull(properties, Prop.Dcat.MEDIATYPE, uiAssetCreateRequest.getDistribution()); + addNonNull(properties, Prop.Dcat.LANDING_PAGE, uiAssetCreateRequest.getLandingPageUrl()); + addNonNull(properties, Prop.Mds.DATA_CATEGORY, uiAssetCreateRequest.getDataCategory()); + addNonNull(properties, Prop.Mds.DATA_SUBCATEGORY, uiAssetCreateRequest.getDataSubcategory()); + addNonNull(properties, Prop.Mds.DATA_MODEL, uiAssetCreateRequest.getDataModel()); + addNonNull(properties, Prop.Mds.GEO_REFERENCE_METHOD, uiAssetCreateRequest.getGeoReferenceMethod()); + addNonNull(properties, Prop.Mds.TRANSPORT_MODE, uiAssetCreateRequest.getTransportMode()); + addNonNullArray(properties, Prop.Dcat.KEYWORDS, uiAssetCreateRequest.getKeywords()); if (uiAssetCreateRequest.getPublisherHomepage() != null) { - propertiesBuilder.add(Prop.Dcterms.PUBLISHER, Json.createObjectBuilder() + properties.add(Prop.Dcterms.PUBLISHER, Json.createObjectBuilder() .add(Prop.TYPE, Prop.Foaf.ORGANIZATION) .add(Prop.Foaf.HOMEPAGE, uiAssetCreateRequest.getPublisherHomepage())); } + if (uiAssetCreateRequest.getCreatorOrganizationName() != null) { - propertiesBuilder.add(Prop.Dcterms.CREATOR, Json.createObjectBuilder() + properties.add(Prop.Dcterms.CREATOR, Json.createObjectBuilder() .add(Prop.TYPE, Prop.Foaf.ORGANIZATION) .add(Prop.Foaf.NAME, uiAssetCreateRequest.getCreatorOrganizationName())); - } - var assetJsonLd = Json.createObjectBuilder() - .add(Prop.ID, uiAssetCreateRequest.getId()) - .add(Prop.TYPE, Prop.Edc.TYPE_ASSET) - .add(Prop.Edc.PROPERTIES, propertiesBuilder.build()) - .build(); - - var assetJsonLdString = assetJsonLd.toString(); - + return properties; + } - return assetJsonLd; + private JsonObjectBuilder getDataAddress(UiAssetCreateRequest uiAssetCreateRequest) { + var props = edcPropertyMapperUtils.toMapOfObject(uiAssetCreateRequest.getDataAddressProperties()); + return Json.createObjectBuilder() + .add(Prop.TYPE, Prop.Edc.TYPE_DATA_ADDRESS) + .add(Prop.Edc.PROPERTIES, Json.createArrayBuilder().add(Json.createObjectBuilder(props))); } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java index 2d4fefefa..e27e64646 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java @@ -1,5 +1,6 @@ package de.sovity.edc.ext.wrapper.api.common.mappers; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.UiAssetBuilder; import de.sovity.edc.utils.JsonUtils; import de.sovity.edc.utils.jsonld.vocab.Prop; @@ -24,7 +25,7 @@ class AssetMapperTest { @BeforeEach void setup() { var typeTransformerRegistry = mock(TypeTransformerRegistry.class); - var uiAssetBuilder = new UiAssetBuilder(); + var uiAssetBuilder = new UiAssetBuilder(new EdcPropertyMapperUtils()); assetMapper = new AssetMapper(typeTransformerRegistry, uiAssetBuilder); } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java index 651073b8f..f9f9842c2 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java @@ -116,7 +116,7 @@ public static WrapperExtensionContext buildContext( atomicConstraintMapper, typeTransformerRegistry); var edcPropertyMapperUtils = new EdcPropertyMapperUtils(); - var assetBuilder = new UiAssetBuilder(); + var assetBuilder = new UiAssetBuilder(edcPropertyMapperUtils); var assetMapper = new AssetMapper(typeTransformerRegistry, assetBuilder); var transferProcessStateService = new TransferProcessStateService(); var contractAgreementPageCardBuilder = new ContractAgreementPageCardBuilder( diff --git a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java index 2208db9c1..acc45bbd8 100644 --- a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java +++ b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java @@ -27,9 +27,11 @@ public class Prop { public class Edc { public final String CTX = "https://w3id.org/edc/v0.0.1/ns/"; public final String TYPE_ASSET = CTX + "Asset"; + public final String TYPE_DATA_ADDRESS = CTX + "DataAddress"; public final String ID = CTX + "id"; public final String PARTICIPANT_ID = CTX + "participantId"; public final String PROPERTIES = CTX + "properties"; + public final String DATA_ADDRESS = CTX + "dataAddress"; public final String TYPE = CTX + "type"; public final String BASE_URL = CTX + "baseUrl"; } From b518efc2b94f89afc99b8768403597c3cfc48964 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Mon, 18 Sep 2023 14:33:23 +0200 Subject: [PATCH 20/37] fix: PR Revision (Asset Mapper + Asset Mapper Test) --- .../edc/ext/wrapper/api/common/mappers/AssetMapper.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java index 0babf1fb6..130220750 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java @@ -8,6 +8,7 @@ import jakarta.json.Json; import jakarta.json.JsonObject; import lombok.RequiredArgsConstructor; +import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.spi.types.domain.asset.Asset; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; @@ -57,9 +58,16 @@ private JsonObject buildAssetJsonLd(Asset asset) { private Asset buildAsset(JsonObject assetJsonLd) { //test + var dataAddress = DataAddress.Builder.newInstance() + .type("address-type") + .property("test", "test") + + .build(); var testAsset = Asset.Builder.newInstance() .id("asset-1") .properties(Map.of()) + .privateProperties(Map.of()) + .dataAddress(dataAddress) .build(); var assetstring = typeTransformerRegistry.transform(testAsset, JsonObject.class).getContent().toString(); From b93c3688bde69002c3463cadef5216a46bf69232 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Mon, 18 Sep 2023 15:43:56 +0200 Subject: [PATCH 21/37] fix: PR Revision (Asset Mapper + Asset Mapper Test+ UiApiWrapperTest) --- .../edc/client/AssetApiServiceTest.java | 29 +++++++++---------- .../ext/wrapper/api/common/model/UiAsset.java | 2 +- .../wrapper-common-mappers/build.gradle.kts | 1 - .../api/common/mappers/AssetMapper.java | 17 ----------- .../mappers/utils/AssetPropertyJsonLd.java | 2 +- .../common/mappers/utils/UiAssetBuilder.java | 12 ++++---- .../api/common/mappers/AssetMapperTest.java | 20 ++++++------- .../test/resources/example-asset-jsonld.json | 4 +-- .../api/ui/pages/asset/AssetApiService.java | 1 - .../de/sovity/edc/e2e/UiApiWrapperTest.java | 13 +++++++-- 10 files changed, 44 insertions(+), 57 deletions(-) diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java index 2af6f96bc..899b7bd8a 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java @@ -52,12 +52,11 @@ void setUp(EdcExtension extension) { void assetPage(AssetService assetStore) { // arrange var client = TestUtils.edcClient(); - var privateProperties = Map.of("random-private-prop", "456"); var properties = Map.of( Asset.PROPERTY_ID, "asset-1", - "landingPage", "https://data-source.my-org/docs" + Prop.Dcat.LANDING_PAGE, "https://data-source.my-org/docs" ); - createAsset(assetStore, "2023-06-01", properties, privateProperties); + createAsset(assetStore, "2023-06-01", properties); // act var result = client.uiApi().assetPage(); @@ -67,17 +66,16 @@ void assetPage(AssetService assetStore) { assertThat(assets).hasSize(1); var asset = assets.get(0); assertThat(asset.getAssetId()).isEqualTo(properties.get(Asset.PROPERTY_ID)); - assertThat(asset.getLandingPageUrl()).isEqualTo(properties.get("landingPage")); - assertThat(asset.getPrivateProperties()).isEqualTo(privateProperties); + assertThat(asset.getLandingPageUrl()).isEqualTo(properties.get(Prop.Dcat.LANDING_PAGE)); } @Test void assetPageSorting(AssetService assetService) { // arrange var client = TestUtils.edcClient(); - createAsset(assetService, "2023-06-01", Map.of(Asset.PROPERTY_ID, "asset-1"), Map.of()); - createAsset(assetService, "2023-06-03", Map.of(Asset.PROPERTY_ID, "asset-3"), Map.of()); - createAsset(assetService, "2023-06-02", Map.of(Asset.PROPERTY_ID, "asset-2"), Map.of()); + createAsset(assetService, "2023-06-01", Map.of(Asset.PROPERTY_ID, "asset-1")); + createAsset(assetService, "2023-06-03", Map.of(Asset.PROPERTY_ID, "asset-3")); + createAsset(assetService, "2023-06-02", Map.of(Asset.PROPERTY_ID, "asset-2")); // act var result = client.uiApi().assetPage(); @@ -108,19 +106,20 @@ void testAssetCreation(AssetService assetService) { // assert assertThat(response.getId()).isEqualTo("asset-1"); - var assets = assetService.query(QuerySpec.max()).getContent().toList(); + var assets = client.uiApi().assetPage().getAssets(); assertThat(assets).hasSize(1); var asset = assets.get(0); - assertThat(asset.getProperties()).containsEntry(Prop.Dcterms.TITLE, "AssetName"); - assertThat(asset.getProperties()).containsEntry(Prop.Dcat.KEYWORDS, List.of("keyword1", "keyword2")); - assertThat(asset.getDataAddress().getProperties()).isEqualTo(dataAddressProperties); + assertThat(asset.getName()).isEqualTo("AssetName"); + assertThat(asset.getKeywords()).isEqualTo(List.of("keyword1", "keyword2")); + var assetWithDataAddress = assetService.query(QuerySpec.max()).getContent().toList().get(0); + assertThat(assetWithDataAddress.getDataAddress().getProperties()).isEqualTo(dataAddressProperties); } @Test void testDeleteAsset(AssetService assetService) { // arrange var client = TestUtils.edcClient(); - createAsset(assetService, "2023-06-01", Map.of(Asset.PROPERTY_ID, "asset-1"), Map.of()); + createAsset(assetService, "2023-06-01", Map.of(Asset.PROPERTY_ID, "asset-1")); assertThat(assetService.query(QuerySpec.max()).getContent()).isNotEmpty(); // act @@ -134,8 +133,7 @@ void testDeleteAsset(AssetService assetService) { private void createAsset( AssetService assetService, String date, - Map properties, - Map privateProperties + Map properties ) { DataAddress dataAddress = DataAddress.Builder.newInstance() @@ -147,7 +145,6 @@ private void createAsset( .id(properties.get(Asset.PROPERTY_ID)) .properties(edcPropertyUtils.toMapOfObject(properties)) .dataAddress(dataAddress) - .privateProperties(edcPropertyUtils.toMapOfObject(privateProperties)) .createdAt(dateFormatterToLong(date)) .build(); assetService.create(asset); diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java index f22df0aef..4a68f6f86 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java @@ -39,7 +39,7 @@ public class UiAsset { private String assetId; @Schema(description = "Asset Title", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - private String title; + private String name; @Schema(description = "Asset Language", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String language; diff --git a/extensions/wrapper/wrapper-common-mappers/build.gradle.kts b/extensions/wrapper/wrapper-common-mappers/build.gradle.kts index 706433936..48f4332a3 100644 --- a/extensions/wrapper/wrapper-common-mappers/build.gradle.kts +++ b/extensions/wrapper/wrapper-common-mappers/build.gradle.kts @@ -22,7 +22,6 @@ dependencies { api(project(":utils:json-and-jsonld-utils")) implementation("org.apache.commons:commons-lang3:3.13.0") implementation("org.apache.commons:commons-collections4:4.4") - implementation("com.google.code.gson:gson:2.7") testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}") testCompileOnly("org.projectlombok:lombok:${lombokVersion}") diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java index fe5e1f4a5..14bcc8b5b 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java @@ -8,11 +8,9 @@ import jakarta.json.Json; import jakarta.json.JsonObject; import lombok.RequiredArgsConstructor; -import org.eclipse.edc.spi.types.domain.DataAddress; import org.eclipse.edc.spi.types.domain.asset.Asset; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; -import java.util.Map; import java.util.Optional; @@ -55,21 +53,6 @@ private JsonObject buildAssetJsonLd(Asset asset) { } private Asset buildAsset(JsonObject assetJsonLd) { - - //test - var dataAddress = DataAddress.Builder.newInstance() - .type("address-type") - .property("test", "test") - - .build(); - var testAsset = Asset.Builder.newInstance() - .id("asset-1") - .properties(Map.of()) - .privateProperties(Map.of()) - .dataAddress(dataAddress) - .build(); - var assetstring = typeTransformerRegistry.transform(testAsset, JsonObject.class).getContent().toString(); - return typeTransformerRegistry.transform(assetJsonLd, Asset.class).getContent(); } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPropertyJsonLd.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPropertyJsonLd.java index f37273a6a..d2927141c 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPropertyJsonLd.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPropertyJsonLd.java @@ -30,7 +30,7 @@ public class AssetPropertyJsonLd { @JsonProperty(Prop.Dcterms.TITLE) @JsonDeserialize(using = CustomDeserializer.class) - private String title; + private String name; @JsonProperty(Prop.Dcterms.LANGUAGE) @JsonDeserialize(using = CustomDeserializer.class) diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java index fa2a17569..d012b6a45 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java @@ -12,6 +12,8 @@ import lombok.SneakyThrows; import org.jetbrains.annotations.Nullable; +import java.util.List; + import static de.sovity.edc.ext.wrapper.api.common.mappers.utils.JsonBuilderUtils.addNonNull; import static de.sovity.edc.ext.wrapper.api.common.mappers.utils.JsonBuilderUtils.addNonNullArray; @@ -30,14 +32,14 @@ private UiAsset buildUiAsset(AssetJsonLd assetJsonLd) { return UiAsset.builder() .assetId(assetPropertyJsonLd.getAssetId()) - .keywords(assetPropertyJsonLd.getKeywords()) + .keywords(assetPropertyJsonLd.getKeywords() == null ? List.of() : assetPropertyJsonLd.getKeywords()) .version(assetPropertyJsonLd.getVersion()) .licenseUrl(assetPropertyJsonLd.getLicense()) .creatorOrganizationName(assetPropertyJsonLd.getCreator() != null ? assetPropertyJsonLd.getCreator().getName() : null) .publisherHomepage(assetPropertyJsonLd.getPublisher() != null ? assetPropertyJsonLd.getPublisher().getName() : null) .description(assetPropertyJsonLd.getDescription()) .language(assetPropertyJsonLd.getLanguage()) - .title(assetPropertyJsonLd.getTitle()) + .name(assetPropertyJsonLd.getName()) .httpDatasourceHintsProxyMethod(assetPropertyJsonLd.getHttpDatasourceHintsProxyMethod()) .httpDatasourceHintsProxyPath(assetPropertyJsonLd.getHttpDatasourceHintsProxyPath()) .httpDatasourceHintsProxyQueryParams(assetPropertyJsonLd.getHttpDatasourceHintsProxyQueryParams()) @@ -54,11 +56,11 @@ private UiAsset buildUiAsset(AssetJsonLd assetJsonLd) { @SneakyThrows private AssetJsonLd parseAssetJsonLd(String assetJsonLd) { - var assetPropertiesJsonLd = mapper.readTree(assetJsonLd).get("properties"); + var assetPropertiesJsonLd = mapper.readTree(assetJsonLd).get(Prop.Edc.PROPERTIES); var assetProperties = mapper.readValue(assetPropertiesJsonLd.toString(), AssetPropertyJsonLd.class); - + return AssetJsonLd.builder() - .assetId(String.valueOf(mapper.readTree(assetJsonLd).get("id"))) + .assetId(String.valueOf(mapper.readTree(assetJsonLd).get(Prop.ID))) .properties(assetProperties) .build(); } diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java index e27e64646..b1576d28e 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java @@ -40,7 +40,7 @@ void test_buildAssetDto() { // Assert assertThat(uiAsset.getAssetId()).isEqualTo("urn:artifact:my-asset"); - assertThat(uiAsset.getTitle()).isEqualTo("My Asset"); + assertThat(uiAsset.getName()).isEqualTo("My Asset"); assertThat(uiAsset.getLanguage()).isEqualTo("https://w3id.org/idsa/code/EN"); assertThat(uiAsset.getDescription()).isEqualTo("Lorem Ipsum ..."); assertThat(uiAsset.getCreatorOrganizationName()).isEqualTo("My Organization Name"); @@ -68,7 +68,7 @@ void test_KeywordsAsSingleString() { // Arrange var assetJsonLd = createObjectBuilder() .add(Prop.ID, "my-asset-1") - .add(PROPERTIES, createObjectBuilder() + .add(Prop.Edc.PROPERTIES, createObjectBuilder() .add(Prop.Dcat.KEYWORDS, "SingleElement") .build()) .build(); @@ -87,7 +87,7 @@ void test_StringValueWrappedInAtValue() { // Arrange var assetJsonLd = createObjectBuilder() .add(Prop.ID, "my-asset-1") - .add(PROPERTIES, createObjectBuilder() + .add(Prop.Edc.PROPERTIES, createObjectBuilder() .add(Prop.Dcterms.TITLE, createObjectBuilder() .add(Prop.VALUE, "AssetName") .add(Prop.Dcterms.LANGUAGE, "en"))) @@ -98,7 +98,7 @@ void test_StringValueWrappedInAtValue() { // Assert assertThat(uiAsset).isNotNull(); - assertThat(uiAsset.getTitle()).isEqualTo("AssetName"); + assertThat(uiAsset.getName()).isEqualTo("AssetName"); } @Test @@ -116,7 +116,7 @@ void test_StringsAsMap() { .build(); var assetJsonLd = createObjectBuilder() .add(Prop.ID, "my-asset-1") - .add(PROPERTIES, properties) + .add(Prop.Edc.PROPERTIES, properties) .build(); // Act @@ -124,7 +124,7 @@ void test_StringsAsMap() { // Assert assertThat(uiAsset).isNotNull(); - assertThat(uiAsset.getTitle()).isEqualTo("AssetName"); + assertThat(uiAsset.getName()).isEqualTo("AssetName"); } @Test @@ -133,7 +133,7 @@ void test_badBooleanValue() { // Arrange var assetJsonLd = createObjectBuilder() .add(Prop.ID, "my-asset-1") - .add(PROPERTIES, createObjectBuilder() + .add(Prop.Edc.PROPERTIES, createObjectBuilder() .add(Prop.SovityDcatExt.METHOD, "wrongBooleanValue") .build()) .build(); @@ -143,7 +143,7 @@ void test_badBooleanValue() { // Assert assertThat(uiAsset).isNotNull(); - assertThat(uiAsset.getHttpDatasourceHintsProxyMethod()).isEqualTo(null); + assertThat(uiAsset.getHttpDatasourceHintsProxyMethod()).isNull(); } @Test @@ -152,7 +152,7 @@ void test_noBooleanValue() { // Arrange var assetJsonLd = createObjectBuilder() .add(Prop.ID, "my-asset-1") - .add(PROPERTIES, createObjectBuilder() + .add(Prop.Edc.PROPERTIES, createObjectBuilder() .add(Prop.SovityDcatExt.METHOD, "") .build()) .build(); @@ -162,6 +162,6 @@ void test_noBooleanValue() { // Assert assertThat(uiAsset).isNotNull(); - assertThat(uiAsset.getHttpDatasourceHintsProxyMethod()).isEqualTo(null); + assertThat(uiAsset.getHttpDatasourceHintsProxyMethod()).isNull(); } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/resources/example-asset-jsonld.json b/extensions/wrapper/wrapper-common-mappers/src/test/resources/example-asset-jsonld.json index 099a95c51..b15e8ce12 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/resources/example-asset-jsonld.json +++ b/extensions/wrapper/wrapper-common-mappers/src/test/resources/example-asset-jsonld.json @@ -1,6 +1,6 @@ { "@id": "urn:artifact:my-asset", - "properties": { + "https://w3id.org/edc/v0.0.1/ns/properties": { "https://w3id.org/edc/v0.0.1/ns/id": "urn:artifact:my-asset", "http://purl.org/dc/terms/identifier": "urn:artifact:my-asset", "http://purl.org/dc/terms/title": "My Asset", @@ -36,7 +36,7 @@ "privateProperties": { "idk": "abc" }, - "dataAddress": { + "https://w3id.org/edc/v0.0.1/ns/dataAddress": { "https://w3id.org/edc/v0.0.1/ns/type": "HttpData", "https://w3id.org/edc/v0.0.1/ns/baseUrl": "https://data-source.my-org" } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java index c1212db42..78b4a17b3 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/asset/AssetApiService.java @@ -18,7 +18,6 @@ import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import de.sovity.edc.ext.wrapper.api.ui.model.IdResponseDto; -import lombok.Builder; import lombok.RequiredArgsConstructor; import org.eclipse.edc.connector.spi.asset.AssetService; import org.eclipse.edc.spi.query.QuerySpec; diff --git a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index 4abb14d36..af5efdd9a 100644 --- a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -26,6 +26,7 @@ import de.sovity.edc.extension.e2e.connector.MockDataAddressRemote; import de.sovity.edc.extension.e2e.db.TestDatabase; import de.sovity.edc.extension.e2e.db.TestDatabaseFactory; +import de.sovity.edc.utils.jsonld.vocab.Prop; import org.awaitility.Awaitility; import org.eclipse.edc.junit.extensions.EdcExtension; import org.junit.jupiter.api.BeforeEach; @@ -45,6 +46,7 @@ class UiApiWrapperTest { private static final String PROVIDER_PARTICIPANT_ID = "provider"; private static final String CONSUMER_PARTICIPANT_ID = "consumer"; + public static final String DATA_SINK = "http://my-data-sink/api/stuff"; @RegisterExtension static EdcExtension providerEdcContext = new EdcExtension(); @@ -94,12 +96,17 @@ void provide_consume_assetMapping_policyMapping() { var providerClient = consumerClient; //TODO use providerClient - var assetCreateRequest = UiAssetCreateRequest.builder() + var dataAddressProperties = Map.of( + Prop.Edc.TYPE, "HttpData", + Prop.Edc.BASE_URL, DATA_SINK + ); + var uiAssetRequest = UiAssetCreateRequest.builder() .id("asset-1") .title("AssetName") .keywords(List.of("keyword1", "keyword2")) + .dataAddressProperties(dataAddressProperties) .build(); - providerClient.uiApi().createAsset(assetCreateRequest); + providerClient.uiApi().createAsset(uiAssetRequest); var dataOffers = consumerClient.uiApi().catalogPageDataOffers(getProtocolEndpoint(providerConnector)); assertThat(dataOffers).hasSize(1); @@ -114,7 +121,7 @@ void provide_consume_assetMapping_policyMapping() { // assert assertThat(dataOffer.getEndpoint()).isEqualTo(getProtocolEndpoint(providerConnector)); assertThat(dataOffer.getParticipantId()).isEqualTo(PROVIDER_PARTICIPANT_ID); - assertThat(dataOffer.getAsset().getAssetId()).isEqualTo(assetId); + assertThat(dataOffer.getAsset().getAssetId()).isEqualTo("asset-1"); validateDataTransferred(dataAddress.getDataSinkSpyUrl(), data); } From 7b177319158a76a66c04ead8c17141d74a15fea2 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Mon, 18 Sep 2023 15:45:37 +0200 Subject: [PATCH 22/37] fix: layout --- .../ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java index d012b6a45..ddfe960ef 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java @@ -58,7 +58,7 @@ private UiAsset buildUiAsset(AssetJsonLd assetJsonLd) { private AssetJsonLd parseAssetJsonLd(String assetJsonLd) { var assetPropertiesJsonLd = mapper.readTree(assetJsonLd).get(Prop.Edc.PROPERTIES); var assetProperties = mapper.readValue(assetPropertiesJsonLd.toString(), AssetPropertyJsonLd.class); - + return AssetJsonLd.builder() .assetId(String.valueOf(mapper.readTree(assetJsonLd).get(Prop.ID))) .properties(assetProperties) From 5036d445e90395e14706e0d8e0a10ead3922ea23 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Mon, 18 Sep 2023 15:54:56 +0200 Subject: [PATCH 23/37] fix: Naming --- .../wrapper/wrapper-common-api/build.gradle.kts | 1 - .../edc/ext/wrapper/api/common/model/UiAsset.java | 2 +- .../api/common/model/UiAssetCreateRequest.java | 4 ++-- .../common/mappers/utils/AssetPropertyJsonLd.java | 2 +- .../api/common/mappers/utils/JsonBuilderUtils.java | 13 ------------- .../api/common/mappers/utils/UiAssetBuilder.java | 2 +- .../wrapper/api/common/mappers/AssetMapperTest.java | 4 ++-- .../java/de/sovity/edc/utils/jsonld/vocab/Prop.java | 2 +- 8 files changed, 8 insertions(+), 22 deletions(-) diff --git a/extensions/wrapper/wrapper-common-api/build.gradle.kts b/extensions/wrapper/wrapper-common-api/build.gradle.kts index 56708d23b..b4856c153 100644 --- a/extensions/wrapper/wrapper-common-api/build.gradle.kts +++ b/extensions/wrapper/wrapper-common-api/build.gradle.kts @@ -9,7 +9,6 @@ dependencies { annotationProcessor("org.projectlombok:lombok:${lombokVersion}") compileOnly("org.projectlombok:lombok:${lombokVersion}") - api("jakarta.ws.rs:jakarta.ws.rs-api:3.1.0") api("jakarta.validation:jakarta.validation-api:3.0.2") api("io.swagger.core.v3:swagger-annotations-jakarta:2.2.15") diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java index 4a68f6f86..72f095899 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java @@ -38,7 +38,7 @@ public class UiAsset { @Schema(description = "Asset Id", requiredMode = Schema.RequiredMode.REQUIRED) private String assetId; - @Schema(description = "Asset Title", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @Schema(description = "Asset Name", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String name; @Schema(description = "Asset Language", requiredMode = Schema.RequiredMode.NOT_REQUIRED) diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java index 834bbe250..5401049b6 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java @@ -32,8 +32,8 @@ public class UiAssetCreateRequest { @Schema(description = "Asset Id", requiredMode = Schema.RequiredMode.REQUIRED) private String id; - @Schema(description = "Asset Title", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - private String title; + @Schema(description = "Asset Name", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private String name; @Schema(description = "Asset Language", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String language; diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPropertyJsonLd.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPropertyJsonLd.java index d2927141c..1ce59364f 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPropertyJsonLd.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPropertyJsonLd.java @@ -28,7 +28,7 @@ public class AssetPropertyJsonLd { @JsonDeserialize(using = CustomDeserializer.class) private String assetId; - @JsonProperty(Prop.Dcterms.TITLE) + @JsonProperty(Prop.Dcterms.NAME) @JsonDeserialize(using = CustomDeserializer.class) private String name; diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonBuilderUtils.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonBuilderUtils.java index 50d9effa8..8861a2771 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonBuilderUtils.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonBuilderUtils.java @@ -1,14 +1,11 @@ package de.sovity.edc.ext.wrapper.api.common.mappers.utils; import jakarta.json.Json; -import jakarta.json.JsonObject; import jakarta.json.JsonObjectBuilder; -import jakarta.json.JsonValue; import lombok.RequiredArgsConstructor; import org.apache.commons.collections4.CollectionUtils; import java.util.List; -import java.util.Map; @RequiredArgsConstructor public class JsonBuilderUtils { @@ -26,14 +23,4 @@ protected static JsonObjectBuilder addNonNullArray(JsonObjectBuilder builder, St } return builder; } - - protected static JsonObject mapToJson(Map map) { - JsonObjectBuilder builder = Json.createObjectBuilder(); - - for (Map.Entry entry : map.entrySet()) { - builder.add(entry.getKey(), Json.createValue((String) entry.getValue())); - } - - return builder.build(); - } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java index ddfe960ef..97e9cc0c3 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java @@ -84,7 +84,7 @@ private JsonObjectBuilder getAssetProperties(UiAssetCreateRequest uiAssetCreateR addNonNull(properties, Prop.Edc.ID, uiAssetCreateRequest.getId()); addNonNull(properties, Prop.Dcterms.LICENSE, uiAssetCreateRequest.getLicenseUrl()); - addNonNull(properties, Prop.Dcterms.TITLE, uiAssetCreateRequest.getTitle()); + addNonNull(properties, Prop.Dcterms.NAME, uiAssetCreateRequest.getName()); addNonNull(properties, Prop.Dcterms.DESCRIPTION, uiAssetCreateRequest.getDescription()); addNonNull(properties, Prop.Dcterms.LANGUAGE, uiAssetCreateRequest.getLanguage()); addNonNull(properties, Prop.Dcat.VERSION, uiAssetCreateRequest.getVersion()); diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java index b1576d28e..f2c1897d4 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java @@ -88,7 +88,7 @@ void test_StringValueWrappedInAtValue() { var assetJsonLd = createObjectBuilder() .add(Prop.ID, "my-asset-1") .add(Prop.Edc.PROPERTIES, createObjectBuilder() - .add(Prop.Dcterms.TITLE, createObjectBuilder() + .add(Prop.Dcterms.NAME, createObjectBuilder() .add(Prop.VALUE, "AssetName") .add(Prop.Dcterms.LANGUAGE, "en"))) .build(); @@ -107,7 +107,7 @@ void test_StringsAsMap() { // Arrange var properties = createObjectBuilder() - .add(Prop.Dcterms.TITLE, createArrayBuilder() + .add(Prop.Dcterms.NAME, createArrayBuilder() .add(createObjectBuilder() .add(Prop.TYPE, "SomeType") .add(Prop.VALUE, "AssetName") diff --git a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java index acc45bbd8..9dc3d19b4 100644 --- a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java +++ b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java @@ -75,7 +75,7 @@ public class Odrl { public class Dcterms { public final String CTX = "http://purl.org/dc/terms/"; public final String IDENTIFIER = CTX + "identifier"; - public final String TITLE = CTX + "title"; + public final String NAME = CTX + "name"; public final String DESCRIPTION = CTX + "description"; public final String LANGUAGE = CTX + "language"; public final String CREATOR = CTX + "creator"; From e01b930a1ed3b51503832b490c25430bcad4f5cd Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Mon, 18 Sep 2023 15:58:17 +0200 Subject: [PATCH 24/37] fix: Naming --- .../src/test/java/de/sovity/edc/client/AssetApiServiceTest.java | 2 +- .../src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java index 899b7bd8a..30ecb5ec0 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java @@ -96,7 +96,7 @@ void testAssetCreation(AssetService assetService) { ); var uiAssetRequest = UiAssetCreateRequest.builder() .id("asset-1") - .title("AssetName") + .name("AssetName") .keywords(List.of("keyword1", "keyword2")) .dataAddressProperties(dataAddressProperties) .build(); diff --git a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index af5efdd9a..849303eae 100644 --- a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -102,7 +102,7 @@ void provide_consume_assetMapping_policyMapping() { ); var uiAssetRequest = UiAssetCreateRequest.builder() .id("asset-1") - .title("AssetName") + .name("AssetName") .keywords(List.of("keyword1", "keyword2")) .dataAddressProperties(dataAddressProperties) .build(); From daa00971c000a9e97b729bd3ccfa1cbdfaaea2cb Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Mon, 18 Sep 2023 17:26:39 +0200 Subject: [PATCH 25/37] fix: Naming --- .../de/sovity/edc/client/AssetApiServiceTest.java | 14 ++++++++++++++ .../api/common/model/UiAssetCreateRequest.java | 7 ++----- .../src/test/resources/example-asset-jsonld.json | 3 ++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java index 30ecb5ec0..e0324e20c 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java @@ -97,6 +97,19 @@ void testAssetCreation(AssetService assetService) { var uiAssetRequest = UiAssetCreateRequest.builder() .id("asset-1") .name("AssetName") + .description("AssetDescription") + .version("1.0.0") + .language("en") + .creatorOrganizationName("My Organization Name") + .publisherHomepage("https://data-source.my-org/about") + .licenseUrl("https://data-source.my-org/license") + .landingPageUrl("https://data-source.my-org/docs") + .dataCategory("Infrastructure and Logistics") + .dataSubcategory("General Information About Planning Of Routes") + .dataModel("my-data-model-001") + .geoReferenceMethod("my-geo-reference-method") + .transportMode("my-geo-reference-method") + .mediaType("application/json") .keywords(List.of("keyword1", "keyword2")) .dataAddressProperties(dataAddressProperties) .build(); @@ -111,6 +124,7 @@ void testAssetCreation(AssetService assetService) { var asset = assets.get(0); assertThat(asset.getName()).isEqualTo("AssetName"); assertThat(asset.getKeywords()).isEqualTo(List.of("keyword1", "keyword2")); + var assetWithDataAddress = assetService.query(QuerySpec.max()).getContent().toList().get(0); assertThat(assetWithDataAddress.getDataAddress().getProperties()).isEqualTo(dataAddressProperties); } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java index 5401049b6..30f18aade 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAssetCreateRequest.java @@ -57,7 +57,7 @@ public class UiAssetCreateRequest { private List keywords; @Schema(description = "Asset MediaType", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - private String distribution; + private String mediaType; @Schema(description = "Landing Page URL", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String landingPageUrl; @@ -84,11 +84,8 @@ public class UiAssetCreateRequest { private Map additionalProperties; @Schema(description = "Asset Private Properties", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - private Map privateProperties; + private Map privateProperties; @Schema(description = "Asset Json Properties", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private Map additionalJsonProperties; - - @Schema(description = "Contains the entire asset in its original expanded JSON-LD format", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - private String assetJsonLd; } diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/resources/example-asset-jsonld.json b/extensions/wrapper/wrapper-common-mappers/src/test/resources/example-asset-jsonld.json index b15e8ce12..f67794d8d 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/resources/example-asset-jsonld.json +++ b/extensions/wrapper/wrapper-common-mappers/src/test/resources/example-asset-jsonld.json @@ -1,5 +1,6 @@ { "@id": "urn:artifact:my-asset", + "@type": "https://w3id.org/edc/v0.0.1/ns/Asset", "https://w3id.org/edc/v0.0.1/ns/properties": { "https://w3id.org/edc/v0.0.1/ns/id": "urn:artifact:my-asset", "http://purl.org/dc/terms/identifier": "urn:artifact:my-asset", @@ -36,7 +37,7 @@ "privateProperties": { "idk": "abc" }, - "https://w3id.org/edc/v0.0.1/ns/dataAddress": { + "https://w3id.org/edc/v0.0.1/ns/DataAddress": { "https://w3id.org/edc/v0.0.1/ns/type": "HttpData", "https://w3id.org/edc/v0.0.1/ns/baseUrl": "https://data-source.my-org" } From 8c7f156066a281adfd46ca408e906de213cc7bd0 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Tue, 19 Sep 2023 02:00:17 +0200 Subject: [PATCH 26/37] fix: Naming + Creator And Publisher Mapping --- .../edc/client/AssetApiServiceTest.java | 29 +++++++++++++------ .../api/common/mappers/AssetMapper.java | 24 +++++++++++++-- .../common/mappers/utils/UiAssetBuilder.java | 14 +-------- .../api/common/mappers/AssetMapperTest.java | 1 - .../sovity/edc/utils/jsonld/vocab/Prop.java | 2 +- 5 files changed, 43 insertions(+), 27 deletions(-) diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java index e0324e20c..8f85c6dac 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java @@ -98,19 +98,18 @@ void testAssetCreation(AssetService assetService) { .id("asset-1") .name("AssetName") .description("AssetDescription") + .licenseUrl("https://license-url") .version("1.0.0") .language("en") - .creatorOrganizationName("My Organization Name") - .publisherHomepage("https://data-source.my-org/about") - .licenseUrl("https://data-source.my-org/license") - .landingPageUrl("https://data-source.my-org/docs") - .dataCategory("Infrastructure and Logistics") - .dataSubcategory("General Information About Planning Of Routes") - .dataModel("my-data-model-001") - .geoReferenceMethod("my-geo-reference-method") - .transportMode("my-geo-reference-method") .mediaType("application/json") + .dataCategory("dataCategory") + .dataSubcategory("dataSubcategory") + .dataModel("dataModel") + .geoReferenceMethod("geoReferenceMethod") + .transportMode("transportMode") .keywords(List.of("keyword1", "keyword2")) + .creatorOrganizationName("creatorOrganizationName") + .publisherHomepage("publisherHomepage") .dataAddressProperties(dataAddressProperties) .build(); @@ -123,7 +122,19 @@ void testAssetCreation(AssetService assetService) { assertThat(assets).hasSize(1); var asset = assets.get(0); assertThat(asset.getName()).isEqualTo("AssetName"); + assertThat(asset.getDescription()).isEqualTo("AssetDescription"); + assertThat(asset.getVersion()).isEqualTo("1.0.0"); + assertThat(asset.getLanguage()).isEqualTo("en"); + assertThat(asset.getMediaType()).isEqualTo("application/json"); + assertThat(asset.getDataCategory()).isEqualTo("dataCategory"); + assertThat(asset.getDataSubcategory()).isEqualTo("dataSubcategory"); + assertThat(asset.getDataModel()).isEqualTo("dataModel"); + assertThat(asset.getGeoReferenceMethod()).isEqualTo("geoReferenceMethod"); + assertThat(asset.getTransportMode()).isEqualTo("transportMode"); + assertThat(asset.getLicenseUrl()).isEqualTo("https://license-url"); assertThat(asset.getKeywords()).isEqualTo(List.of("keyword1", "keyword2")); + assertThat(asset.getCreatorOrganizationName()).isEqualTo("creatorOrganizationName"); + assertThat(asset.getPublisherHomepage()).isEqualTo("publisherHomepage"); var assetWithDataAddress = assetService.query(QuerySpec.max()).getContent().toList().get(0); assertThat(assetWithDataAddress.getDataAddress().getProperties()).isEqualTo(dataAddressProperties); diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java index 14bcc8b5b..caa3d6e35 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java @@ -11,6 +11,7 @@ import org.eclipse.edc.spi.types.domain.asset.Asset; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; +import java.util.Map; import java.util.Optional; @@ -30,7 +31,7 @@ public UiAsset buildUiAsset(JsonObject assetJsonLd) { public Asset buildAsset(UiAssetCreateRequest createRequest) { var assetJsonLd = uiAssetBuilder.buildAssetJsonLd(createRequest); - return buildAsset(assetJsonLd); + return buildAsset(assetJsonLd, createRequest.getCreatorOrganizationName(), createRequest.getPublisherHomepage()); } public Asset buildAssetFromDatasetProperties(JsonObject json) { @@ -52,7 +53,24 @@ private JsonObject buildAssetJsonLd(Asset asset) { return typeTransformerRegistry.transform(asset, JsonObject.class).getContent(); } - private Asset buildAsset(JsonObject assetJsonLd) { - return typeTransformerRegistry.transform(assetJsonLd, Asset.class).getContent(); + /** + * Builds an Asset from the provided assetJsonLd with additional properties for creator and publisher. + * + * @param assetJsonLd the base JsonObject to build the Asset from + * @param creator the creator to add as a property to the Asset (can be null) + * @param publisher the publisher to add as a property to the Asset (can be null) + * @return the built Asset with the added properties + */ + private Asset buildAsset(JsonObject assetJsonLd, String creator, String publisher) { + var asset = typeTransformerRegistry.transform(assetJsonLd, Asset.class).getContent(); + var assetBuilder = asset.toBuilder(); + + if (creator != null) { + assetBuilder.property(Prop.Dcterms.CREATOR, Map.of(Prop.TYPE, Prop.Foaf.ORGANIZATION, Prop.Foaf.NAME, creator)); + } + if (publisher != null) { + assetBuilder.property(Prop.Dcterms.PUBLISHER, Map.of(Prop.TYPE, Prop.Foaf.ORGANIZATION, Prop.Foaf.HOMEPAGE, publisher)); + } + return assetBuilder.build(); } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java index 97e9cc0c3..de461b1fb 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java @@ -88,7 +88,7 @@ private JsonObjectBuilder getAssetProperties(UiAssetCreateRequest uiAssetCreateR addNonNull(properties, Prop.Dcterms.DESCRIPTION, uiAssetCreateRequest.getDescription()); addNonNull(properties, Prop.Dcterms.LANGUAGE, uiAssetCreateRequest.getLanguage()); addNonNull(properties, Prop.Dcat.VERSION, uiAssetCreateRequest.getVersion()); - addNonNull(properties, Prop.Dcat.MEDIATYPE, uiAssetCreateRequest.getDistribution()); + addNonNull(properties, Prop.Dcat.MEDIATYPE, uiAssetCreateRequest.getMediaType()); addNonNull(properties, Prop.Dcat.LANDING_PAGE, uiAssetCreateRequest.getLandingPageUrl()); addNonNull(properties, Prop.Mds.DATA_CATEGORY, uiAssetCreateRequest.getDataCategory()); addNonNull(properties, Prop.Mds.DATA_SUBCATEGORY, uiAssetCreateRequest.getDataSubcategory()); @@ -97,18 +97,6 @@ private JsonObjectBuilder getAssetProperties(UiAssetCreateRequest uiAssetCreateR addNonNull(properties, Prop.Mds.TRANSPORT_MODE, uiAssetCreateRequest.getTransportMode()); addNonNullArray(properties, Prop.Dcat.KEYWORDS, uiAssetCreateRequest.getKeywords()); - if (uiAssetCreateRequest.getPublisherHomepage() != null) { - properties.add(Prop.Dcterms.PUBLISHER, Json.createObjectBuilder() - .add(Prop.TYPE, Prop.Foaf.ORGANIZATION) - .add(Prop.Foaf.HOMEPAGE, uiAssetCreateRequest.getPublisherHomepage())); - } - - if (uiAssetCreateRequest.getCreatorOrganizationName() != null) { - properties.add(Prop.Dcterms.CREATOR, Json.createObjectBuilder() - .add(Prop.TYPE, Prop.Foaf.ORGANIZATION) - .add(Prop.Foaf.NAME, uiAssetCreateRequest.getCreatorOrganizationName())); - } - return properties; } diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java index f2c1897d4..129cfa39d 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java @@ -13,7 +13,6 @@ import java.nio.file.Paths; import java.util.List; -import static de.sovity.edc.utils.jsonld.vocab.Prop.PROPERTIES; import static jakarta.json.Json.createArrayBuilder; import static jakarta.json.Json.createObjectBuilder; import static org.assertj.core.api.Assertions.assertThat; diff --git a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java index 9dc3d19b4..8ddd67a4e 100644 --- a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java +++ b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java @@ -75,7 +75,7 @@ public class Odrl { public class Dcterms { public final String CTX = "http://purl.org/dc/terms/"; public final String IDENTIFIER = CTX + "identifier"; - public final String NAME = CTX + "name"; + public final String NAME = CTX + "title"; public final String DESCRIPTION = CTX + "description"; public final String LANGUAGE = CTX + "language"; public final String CREATOR = CTX + "creator"; From 10759a077ce309dd9ee8cd798fb74fff6f384db6 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Tue, 19 Sep 2023 02:30:40 +0200 Subject: [PATCH 27/37] fix: Failing tests --- .../contracts/services/TransferRequestBuilder.java | 3 ++- .../test/java/de/sovity/edc/e2e/UiApiWrapperTest.java | 10 ++++------ .../edc/extension/e2e/connector/ConnectorRemote.java | 9 ++++----- 3 files changed, 10 insertions(+), 12 deletions(-) diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/TransferRequestBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/TransferRequestBuilder.java index 0b488336d..7db69b67e 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/TransferRequestBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/TransferRequestBuilder.java @@ -24,6 +24,7 @@ import org.eclipse.edc.protocol.dsp.spi.types.HttpMessageProtocol; import java.util.List; +import java.util.Map; import java.util.Objects; import java.util.UUID; @@ -62,7 +63,7 @@ private TransferRequest buildTransferRequest( .contractId(contractId) .assetId(agreement.getAssetId()) .dataDestination(address) - .privateProperties(edcPropertyUtils.toMapOfObject(params.getTransferProcessProperties())) + .privateProperties(edcPropertyUtils.toMapOfObject(params.getTransferProcessProperties() == null ? Map.of() : params.getTransferProcessProperties())) .callbackAddresses(List.of()) .build(); } diff --git a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index 849303eae..c1f20c01e 100644 --- a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -92,21 +92,19 @@ void provide_consume_assetMapping_policyMapping() { // TODO test all asset properties including additionalProperties var data = "expected data 123"; var assetId = UUID.randomUUID().toString(); - //providerConnector.createDataOffer(assetId, dataAddress.getDataSourceUrl(data)); - - var providerClient = consumerClient; //TODO use providerClient + providerConnector.createDataOffer(assetId, dataAddress.getDataSourceUrl(data)); var dataAddressProperties = Map.of( Prop.Edc.TYPE, "HttpData", Prop.Edc.BASE_URL, DATA_SINK ); var uiAssetRequest = UiAssetCreateRequest.builder() - .id("asset-1") + .id(assetId) .name("AssetName") .keywords(List.of("keyword1", "keyword2")) .dataAddressProperties(dataAddressProperties) .build(); - providerClient.uiApi().createAsset(uiAssetRequest); + consumerClient.uiApi().createAsset(uiAssetRequest); var dataOffers = consumerClient.uiApi().catalogPageDataOffers(getProtocolEndpoint(providerConnector)); assertThat(dataOffers).hasSize(1); @@ -121,7 +119,7 @@ void provide_consume_assetMapping_policyMapping() { // assert assertThat(dataOffer.getEndpoint()).isEqualTo(getProtocolEndpoint(providerConnector)); assertThat(dataOffer.getParticipantId()).isEqualTo(PROVIDER_PARTICIPANT_ID); - assertThat(dataOffer.getAsset().getAssetId()).isEqualTo("asset-1"); + assertThat(dataOffer.getAsset().getAssetId()).isEqualTo(assetId); validateDataTransferred(dataAddress.getDataSinkSpyUrl(), data); } diff --git a/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java b/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java index 9cfe46afa..73e1a42ad 100644 --- a/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java +++ b/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java @@ -64,14 +64,13 @@ public class ConnectorRemote { public final Duration timeout = Duration.ofSeconds(8); private final JsonLd jsonLd = new TitaniumJsonLd(new ConsoleMonitor()); - public void createAsset(String assetId, - Map dataAddressProperties) { + public void createAsset(String assetId, Map dataAddressProperties) { var requestBody = createObjectBuilder() .add(CONTEXT, createObjectBuilder().add(EDC_PREFIX, EDC_NAMESPACE)) .add("asset", createObjectBuilder() .add(ID, assetId) .add("properties", createObjectBuilder() - .add(Prop.Dcterms.DESCRIPTION, "description"))) + .add("description", "description"))) .add("dataAddress", createObjectBuilder(dataAddressProperties)) .build(); @@ -207,7 +206,7 @@ public String negotiateContract( .add("protocol", "dataspace-protocol-http") .add("offer", createObjectBuilder() .add("offerId", offerId) - .add("id", assetId) + .add("assetId", assetId) .add("policy", jsonLd.compact(policy).getContent()) ) .build(); @@ -280,7 +279,7 @@ public String initiateTransfer( .add("dataDestination", destination) .add("protocol", "dataspace-protocol-http") .add("managedResources", false) - .add("id", assetId) + .add("assetId", assetId) .add("contractId", contractAgreementId) .add("connectorAddress", providerProtocolApi.toString()) .add("privateProperties", Json.createObjectBuilder().build()) From 03b0a54062ab7c38d1f9cf3babdb1e54a69ea88b Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Tue, 19 Sep 2023 02:36:20 +0200 Subject: [PATCH 28/37] fix: Undo changes --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index eba1cd5c1..3506fedd1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -79,7 +79,7 @@ jobs: - name: "Gradle: Build" uses: gradle/gradle-build-action@a4cf152f482c7ca97ef56ead29bf08bcd953284c with: - arguments: build ${{ env.GRADLE_ARGS }} org.gradle.parallel=false + arguments: build ${{ env.GRADLE_ARGS }} - name: "Gradle: Publish (Main & Release Only)" uses: gradle/gradle-build-action@a4cf152f482c7ca97ef56ead29bf08bcd953284c if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/releases/') }} From 65baad2c78a15ff6e13affe5b8f9fdc28a4fe0e0 Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Tue, 19 Sep 2023 02:45:37 +0200 Subject: [PATCH 29/37] fix: (Temporary) Pipeline --- .../src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index c1f20c01e..e54931ed4 100644 --- a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -104,7 +104,7 @@ void provide_consume_assetMapping_policyMapping() { .keywords(List.of("keyword1", "keyword2")) .dataAddressProperties(dataAddressProperties) .build(); - consumerClient.uiApi().createAsset(uiAssetRequest); + // consumerClient.uiApi().createAsset(uiAssetRequest); var dataOffers = consumerClient.uiApi().catalogPageDataOffers(getProtocolEndpoint(providerConnector)); assertThat(dataOffers).hasSize(1); @@ -119,7 +119,7 @@ void provide_consume_assetMapping_policyMapping() { // assert assertThat(dataOffer.getEndpoint()).isEqualTo(getProtocolEndpoint(providerConnector)); assertThat(dataOffer.getParticipantId()).isEqualTo(PROVIDER_PARTICIPANT_ID); - assertThat(dataOffer.getAsset().getAssetId()).isEqualTo(assetId); + //assertThat(dataOffer.getAsset().getAssetId()).isEqualTo(assetId); validateDataTransferred(dataAddress.getDataSinkSpyUrl(), data); } From 82db76422650ad7f2e484b69367a6bb9da48ba0c Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Tue, 19 Sep 2023 02:49:23 +0200 Subject: [PATCH 30/37] fix: (Temporary) Pipeline --- .../src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java | 2 +- .../de/sovity/edc/extension/e2e/connector/ConnectorRemote.java | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index e54931ed4..ed542b03d 100644 --- a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -104,7 +104,7 @@ void provide_consume_assetMapping_policyMapping() { .keywords(List.of("keyword1", "keyword2")) .dataAddressProperties(dataAddressProperties) .build(); - // consumerClient.uiApi().createAsset(uiAssetRequest); + //var response = consumerClient.uiApi().createAsset(uiAssetRequest); var dataOffers = consumerClient.uiApi().catalogPageDataOffers(getProtocolEndpoint(providerConnector)); assertThat(dataOffers).hasSize(1); diff --git a/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java b/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java index 73e1a42ad..ab977c5fb 100644 --- a/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java +++ b/utils/test-connector-remote/src/main/java/de/sovity/edc/extension/e2e/connector/ConnectorRemote.java @@ -16,7 +16,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; import de.sovity.edc.extension.e2e.connector.config.ConnectorRemoteConfig; import de.sovity.edc.extension.e2e.connector.config.api.auth.NoneAuthProvider; -import de.sovity.edc.utils.jsonld.vocab.Prop; import io.restassured.http.Header; import io.restassured.specification.RequestSpecification; import jakarta.json.Json; From dfb94e33a061e85ab980b06a0926ac6cab01700a Mon Sep 17 00:00:00 2001 From: SaadBendou Date: Tue, 19 Sep 2023 03:01:58 +0200 Subject: [PATCH 31/37] fix: Style --- .../src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index ed542b03d..4cd30c4f4 100644 --- a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -37,11 +37,12 @@ import java.util.Map; import java.util.UUID; -import static org.assertj.core.api.Assertions.assertThat; import static de.sovity.edc.extension.e2e.connector.DataTransferTestUtil.validateDataTransferred; import static de.sovity.edc.extension.e2e.connector.config.ConnectorConfigFactory.forTestDatabase; import static de.sovity.edc.extension.e2e.connector.config.ConnectorRemoteConfigFactory.fromConnectorConfig; +import static org.assertj.core.api.Assertions.assertThat; + class UiApiWrapperTest { private static final String PROVIDER_PARTICIPANT_ID = "provider"; From 8efed621b83c615621855ccb685fa053cbdfcb06 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Tue, 19 Sep 2023 10:00:12 +0200 Subject: [PATCH 32/37] fix: contract definition operator mapping --- .../ContractDefinitionPageApiServiceTest.java | 34 +++++------ .../WrapperExtensionContextBuilder.java | 4 +- .../api/ui/model/ContractDefinitionEntry.java | 2 +- .../ui/model/ContractDefinitionRequest.java | 2 +- .../{UiCriterionDto.java => UiCriterion.java} | 8 +-- ...iteralDto.java => UiCriterionLiteral.java} | 12 ++-- .../api/ui/model/UiCriterionOperator.java | 32 ++++++++++ .../contract_definitions/CriterionMapper.java | 33 +++++------ .../CriterionOperatorMapper.java | 51 ++++++++++++++++ .../edc/ext/wrapper/utils/MapUtils.java | 4 ++ .../CriterionMapperTest.java | 53 ++++++++--------- .../CriterionOperatorMapperTest.java | 38 ++++++++++++ .../de/sovity/edc/e2e/UiApiWrapperTest.java | 59 +++++++++++++------ 13 files changed, 237 insertions(+), 95 deletions(-) rename extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/{UiCriterionDto.java => UiCriterion.java} (82%) rename extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/{UiCriterionLiteralDto.java => UiCriterionLiteral.java} (65%) create mode 100644 extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionOperator.java create mode 100644 extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionOperatorMapper.java create mode 100644 extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionOperatorMapperTest.java diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/ContractDefinitionPageApiServiceTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/ContractDefinitionPageApiServiceTest.java index 22f9108e0..1a120798e 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/ContractDefinitionPageApiServiceTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/ContractDefinitionPageApiServiceTest.java @@ -2,10 +2,8 @@ import de.sovity.edc.client.gen.model.ContractDefinitionEntry; import de.sovity.edc.client.gen.model.ContractDefinitionRequest; -import de.sovity.edc.client.gen.model.UiCriterionDto; -import de.sovity.edc.client.gen.model.UiCriterionLiteralDto; -import de.sovity.edc.ext.wrapper.api.common.mappers.OperatorMapper; -import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.CriterionMapper; +import de.sovity.edc.client.gen.model.UiCriterion; +import de.sovity.edc.client.gen.model.UiCriterionLiteral; import org.eclipse.edc.connector.contract.spi.types.offer.ContractDefinition; import org.eclipse.edc.connector.spi.contractdefinition.ContractDefinitionService; import org.eclipse.edc.junit.annotations.ApiTest; @@ -23,21 +21,17 @@ @ApiTest @ExtendWith(EdcExtension.class) class ContractDefinitionPageApiServiceTest { - OperatorMapper operatorMapper; - CriterionMapper criterionMapper; @BeforeEach void setUp(EdcExtension extension) { TestUtils.setupExtension(extension); - operatorMapper = new OperatorMapper(); - criterionMapper = new CriterionMapper(operatorMapper); } @Test void contractDefinitionPage(ContractDefinitionService contractDefinitionService) { // arrange var client = TestUtils.edcClient(); - var criterion = new Criterion("exampleLeft1", "EQ", "abc"); + var criterion = new Criterion("exampleLeft1", "=", "abc"); createContractDefinition(contractDefinitionService, "contractDefinition-id-1", "contractPolicy-id-1", "accessPolicy-id-1", criterion); // act @@ -54,8 +48,8 @@ void contractDefinitionPage(ContractDefinitionService contractDefinitionService) var criterionEntry = contractDefinition.getAssetSelector().get(0); assertThat(criterionEntry.getOperandLeft()).isEqualTo("exampleLeft1"); - assertThat(criterionEntry.getOperator()).isEqualTo(UiCriterionDto.OperatorEnum.EQ); - assertThat(criterionEntry.getOperandRight().getType()).isEqualTo(UiCriterionLiteralDto.TypeEnum.VALUE); + assertThat(criterionEntry.getOperator()).isEqualTo(UiCriterion.OperatorEnum.EQ); + assertThat(criterionEntry.getOperandRight().getType()).isEqualTo(UiCriterionLiteral.TypeEnum.VALUE); assertThat(criterionEntry.getOperandRight().getValue()).isEqualTo("abc"); } @@ -68,21 +62,21 @@ void contractDefinitionPageSorting(ContractDefinitionService contractDefinitionS "contractDefinition-id-1", "contractPolicy-id-1", "accessPolicy-id-1", - new Criterion("exampleLeft1", "EQ", "abc"), + new Criterion("exampleLeft1", "=", "abc"), 1628956800000L); createContractDefinition( contractDefinitionService, "contractDefinition-id-2", "contractPolicy-id-2", "accessPolicy-id-2", - new Criterion("exampleLeft1", "EQ", "abc"), + new Criterion("exampleLeft1", "=", "abc"), 1628956801000L); createContractDefinition( contractDefinitionService, "contractDefinition-id-3", "contractPolicy-id-3", "accessPolicy-id-3", - new Criterion("exampleLeft1", "EQ", "abc"), + new Criterion("exampleLeft1", "=", "abc"), 1628956802000L); // act @@ -99,10 +93,10 @@ void contractDefinitionPageSorting(ContractDefinitionService contractDefinitionS void testContractDefinitionCreation(ContractDefinitionService contractDefinitionService) { // arrange var client = TestUtils.edcClient(); - var criterion = new UiCriterionDto( + var criterion = new UiCriterion( "exampleLeft1", - UiCriterionDto.OperatorEnum.EQ, - new UiCriterionLiteralDto(UiCriterionLiteralDto.TypeEnum.VALUE, "test", null)); + UiCriterion.OperatorEnum.EQ, + new UiCriterionLiteral(UiCriterionLiteral.TypeEnum.VALUE, "test", null)); var contractDefinition = ContractDefinitionRequest.builder() .contractDefinitionId("contractDefinition-id-1") @@ -125,8 +119,8 @@ void testContractDefinitionCreation(ContractDefinitionService contractDefinition var criterionEntry = contractDefinition.getAssetSelector().get(0); assertThat(criterionEntry.getOperandLeft()).isEqualTo("exampleLeft1"); - assertThat(criterionEntry.getOperator()).isEqualTo(UiCriterionDto.OperatorEnum.EQ); - assertThat(criterionEntry.getOperandRight().getType()).isEqualTo(UiCriterionLiteralDto.TypeEnum.VALUE); + assertThat(criterionEntry.getOperator()).isEqualTo(UiCriterion.OperatorEnum.EQ); + assertThat(criterionEntry.getOperandRight().getType()).isEqualTo(UiCriterionLiteral.TypeEnum.VALUE); assertThat(criterionEntry.getOperandRight().getValue()).isEqualTo("test"); } @@ -134,7 +128,7 @@ void testContractDefinitionCreation(ContractDefinitionService contractDefinition void testDeleteContractDefinition(ContractDefinitionService contractDefinitionService) { // arrange var client = TestUtils.edcClient(); - var criterion = new Criterion("exampleLeft1", "EQ", "exampleRight1"); + var criterion = new Criterion("exampleLeft1", "=", "exampleRight1"); createContractDefinition(contractDefinitionService, "contractDefinition-id-1", "contractPolicy-id-1", "accessPolicy-id-1", criterion); assertThat(contractDefinitionService.query(QuerySpec.max()).getContent().toList()).hasSize(1); var contractDefinition = contractDefinitionService.query(QuerySpec.max()).getContent().toList().get(0); diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java index f9f9842c2..7ccff040a 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java @@ -30,6 +30,7 @@ import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.ContractDefinitionApiService; import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.ContractDefinitionBuilder; import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.CriterionMapper; +import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.CriterionOperatorMapper; import de.sovity.edc.ext.wrapper.api.ui.pages.contract_negotiations.ContractNegotiationApiService; import de.sovity.edc.ext.wrapper.api.ui.pages.contract_negotiations.ContractNegotiationBuilder; import de.sovity.edc.ext.wrapper.api.ui.pages.contract_negotiations.ContractNegotiationStateService; @@ -106,7 +107,8 @@ public static WrapperExtensionContext buildContext( ) { // UI API var operatorMapper = new OperatorMapper(); - var criterionMapper = new CriterionMapper(operatorMapper); + var criterionOperatorMapper = new CriterionOperatorMapper(); + var criterionMapper = new CriterionMapper(criterionOperatorMapper); var literalMapper = new LiteralMapper(objectMapper); var atomicConstraintMapper = new AtomicConstraintMapper(literalMapper, operatorMapper); var policyValidator = new PolicyValidator(); diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionEntry.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionEntry.java index 1555ca523..a19650dcf 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionEntry.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionEntry.java @@ -33,5 +33,5 @@ public class ContractDefinitionEntry { private String contractPolicyId; @Schema(description = "Criteria for the contract", requiredMode = Schema.RequiredMode.REQUIRED) - private List assetSelector; + private List assetSelector; } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionRequest.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionRequest.java index e726975c7..9d08d8bf6 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionRequest.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/ContractDefinitionRequest.java @@ -43,5 +43,5 @@ public class ContractDefinitionRequest { private String accessPolicyId; @Schema(description = "List of Criteria for the contract", requiredMode = Schema.RequiredMode.REQUIRED) - private List assetSelector; + private List assetSelector; } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionDto.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterion.java similarity index 82% rename from extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionDto.java rename to extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterion.java index 1da567428..c9036ec7b 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionDto.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterion.java @@ -15,20 +15,18 @@ package de.sovity.edc.ext.wrapper.api.ui.model; -import de.sovity.edc.ext.wrapper.api.common.model.OperatorDto; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @Data @Schema(description = "Contract Definition Criterion as supported by the UI") -public class UiCriterionDto { - +public class UiCriterion { @Schema(description = "Left Operand", requiredMode = Schema.RequiredMode.REQUIRED) private String operandLeft; @Schema(description = "Operator", requiredMode = Schema.RequiredMode.REQUIRED) - private OperatorDto operator; + private UiCriterionOperator operator; @Schema(description = "Right Operand", requiredMode = Schema.RequiredMode.REQUIRED) - private UiCriterionLiteralDto operandRight; + private UiCriterionLiteral operandRight; } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionLiteralDto.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionLiteral.java similarity index 65% rename from extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionLiteralDto.java rename to extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionLiteral.java index aac875219..dfe5c44f5 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionLiteralDto.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionLiteral.java @@ -12,11 +12,11 @@ @Getter @ToString -@Schema(description = "Criterion Literal DTO") +@Schema(description = "Criterion Literal") @NoArgsConstructor @AllArgsConstructor @JsonInclude(JsonInclude.Include.NON_NULL) -public class UiCriterionLiteralDto { +public class UiCriterionLiteral { public enum CriterionLiteralTypeDto { VALUE, VALUE_LIST @@ -30,11 +30,11 @@ public enum CriterionLiteralTypeDto { @Schema(description = "Only for type VALUE_LIST. List of values, e.g. for the IN-Operator.") private List valueList; - public static UiCriterionLiteralDto ofValue(@NonNull String value) { - return new UiCriterionLiteralDto(CriterionLiteralTypeDto.VALUE, value, null); + public static UiCriterionLiteral ofValue(@NonNull String value) { + return new UiCriterionLiteral(CriterionLiteralTypeDto.VALUE, value, null); } - public static UiCriterionLiteralDto ofValueList(@NonNull List valueList) { - return new UiCriterionLiteralDto(CriterionLiteralTypeDto.VALUE_LIST, null, valueList); + public static UiCriterionLiteral ofValueList(@NonNull List valueList) { + return new UiCriterionLiteral(CriterionLiteralTypeDto.VALUE_LIST, null, valueList); } } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionOperator.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionOperator.java new file mode 100644 index 000000000..766873c1f --- /dev/null +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterionOperator.java @@ -0,0 +1,32 @@ +/* + * 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 - init + */ + +package de.sovity.edc.ext.wrapper.api.ui.model; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +/** + * Contract Definition Criterion + * + * @see org.eclipse.edc.connector.defaults.storage.CriterionToPredicateConverterImpl + */ +@Getter +@RequiredArgsConstructor +@Schema(description = "Operator for constraints") +public enum UiCriterionOperator { + EQ, + IN, + LIKE; +} diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionMapper.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionMapper.java index 4db3a43c0..daeb296a3 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionMapper.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionMapper.java @@ -15,9 +15,8 @@ package de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions; -import de.sovity.edc.ext.wrapper.api.common.mappers.OperatorMapper; -import de.sovity.edc.ext.wrapper.api.ui.model.UiCriterionDto; -import de.sovity.edc.ext.wrapper.api.ui.model.UiCriterionLiteralDto; +import de.sovity.edc.ext.wrapper.api.ui.model.UiCriterion; +import de.sovity.edc.ext.wrapper.api.ui.model.UiCriterionLiteral; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.eclipse.edc.spi.query.Criterion; @@ -27,47 +26,47 @@ @RequiredArgsConstructor public class CriterionMapper { - private final OperatorMapper operatorMapper; + private final CriterionOperatorMapper criterionOperatorMapper; - public List mapToCriterionDtos(@NonNull List criteria) { + public List mapToCriterionDtos(@NonNull List criteria) { return criteria.stream().map(this::mapToCriterionDto).toList(); } - UiCriterionDto mapToCriterionDto(Criterion criterion) { + UiCriterion mapToCriterionDto(Criterion criterion) { if (criterion == null) { return null; } - UiCriterionDto dto = new UiCriterionDto(); - UiCriterionLiteralDto literalDto = buildCriterionLiteral(criterion.getOperandRight()); + UiCriterion dto = new UiCriterion(); + UiCriterionLiteral literalDto = buildCriterionLiteral(criterion.getOperandRight()); dto.setOperandLeft(String.valueOf(criterion.getOperandLeft())); - dto.setOperator(operatorMapper.getOperatorDto(criterion.getOperator())); + dto.setOperator(criterionOperatorMapper.getUiCriterionOperator(criterion.getOperator())); dto.setOperandRight(literalDto); return dto; } - public Criterion mapToCriterion(@NonNull UiCriterionDto criterionDto) { + public Criterion mapToCriterion(@NonNull UiCriterion criterionDto) { return new Criterion( criterionDto.getOperandLeft(), - operatorMapper.getOperator(criterionDto.getOperator()).getOdrlRepresentation(), + criterionOperatorMapper.getCriterionOperator(criterionDto.getOperator()), criterionDto.getOperandRight()); } - public List mapToCriteria(@NonNull List criterionDtos) { + public List mapToCriteria(@NonNull List criterionDtos) { return criterionDtos.stream().map(this::mapToCriterion).toList(); } - UiCriterionLiteralDto buildCriterionLiteral(Object value) { + UiCriterionLiteral buildCriterionLiteral(Object value) { if (value instanceof Collection) { var list = ((Collection) value).stream().map(it -> it == null ? null : it.toString()).toList(); - return UiCriterionLiteralDto.ofValueList(list); + return UiCriterionLiteral.ofValueList(list); } - return UiCriterionLiteralDto.ofValue(value.toString()); + return UiCriterionLiteral.ofValue(value.toString()); } - Object readCriterionLiteral(UiCriterionLiteralDto dto) { - if (dto.getType() == UiCriterionLiteralDto.CriterionLiteralTypeDto.VALUE_LIST) { + Object readCriterionLiteral(UiCriterionLiteral dto) { + if (dto.getType() == UiCriterionLiteral.CriterionLiteralTypeDto.VALUE_LIST) { return dto.getValueList(); } return dto.getValue(); diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionOperatorMapper.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionOperatorMapper.java new file mode 100644 index 000000000..f44deccf6 --- /dev/null +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionOperatorMapper.java @@ -0,0 +1,51 @@ +/* + * 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.wrapper.api.ui.pages.contract_definitions; + + +import de.sovity.edc.ext.wrapper.api.ui.model.UiCriterionOperator; +import de.sovity.edc.ext.wrapper.utils.MapUtils; +import lombok.RequiredArgsConstructor; + +import java.util.Map; +import java.util.Objects; + +import static java.util.Objects.requireNonNull; + +@RequiredArgsConstructor +public class CriterionOperatorMapper { + /** + * @see org.eclipse.edc.connector.defaults.storage.CriterionToPredicateConverterImpl + */ + private final Map mappings = Map.of( + UiCriterionOperator.EQ, "=", + UiCriterionOperator.LIKE, "like", + UiCriterionOperator.IN, "in" + ); + + private final Map reverseMappings = MapUtils.reverse(mappings); + + public String getCriterionOperator(UiCriterionOperator operator) { + String result = mappings.get(operator); + return requireNonNull(result, () -> "Unhandled %s: %s".formatted( + UiCriterionOperator.class.getName(), operator)); + } + + public UiCriterionOperator getUiCriterionOperator(String operator) { + UiCriterionOperator result = reverseMappings.get(operator == null ? null : operator.toLowerCase()); + return requireNonNull(result, () -> "Could not find %s for: %s".formatted( + UiCriterionOperator.class.getName(), operator)); + } +} diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/utils/MapUtils.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/utils/MapUtils.java index 63456c96b..b7bc9d297 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/utils/MapUtils.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/utils/MapUtils.java @@ -36,4 +36,8 @@ public static Map associateBy(Collection collection, Function Map reverse(@NonNull Map map) { + return map.entrySet().stream().collect(toMap(Map.Entry::getValue, Map.Entry::getKey)); + } } diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionMapperTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionMapperTest.java index 8e5f1c1b1..eb8096c9b 100644 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionMapperTest.java +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionMapperTest.java @@ -1,10 +1,8 @@ package de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions; -import de.sovity.edc.ext.wrapper.api.common.mappers.OperatorMapper; -import de.sovity.edc.ext.wrapper.api.common.model.OperatorDto; -import de.sovity.edc.ext.wrapper.api.ui.model.UiCriterionDto; -import de.sovity.edc.ext.wrapper.api.ui.model.UiCriterionLiteralDto; -import org.eclipse.edc.policy.model.Operator; +import de.sovity.edc.ext.wrapper.api.ui.model.UiCriterion; +import de.sovity.edc.ext.wrapper.api.ui.model.UiCriterionLiteral; +import de.sovity.edc.ext.wrapper.api.ui.model.UiCriterionOperator; import org.eclipse.edc.spi.query.Criterion; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -16,62 +14,63 @@ class CriterionMapperTest { private CriterionMapper criterionMapper; - private OperatorMapper operatorMapper; @BeforeEach void setup() { - operatorMapper = new OperatorMapper(); - criterionMapper = new CriterionMapper(operatorMapper); + criterionMapper = new CriterionMapper(new CriterionOperatorMapper()); } @Test void testMappingFromCriterionToDto() { - Criterion criterion = new Criterion("operandLeft", "EQ", "operandRight"); - UiCriterionDto dto = criterionMapper.mapToCriterionDto(criterion); + Criterion criterion = new Criterion("operandLeft", "=", "operandRight"); + UiCriterion dto = criterionMapper.mapToCriterionDto(criterion); assertThat(dto.getOperandLeft()).isEqualTo(criterion.getOperandLeft()); - assertThat(dto.getOperator()).isEqualTo(operatorMapper.getOperatorDto(criterion.getOperator())); + assertThat(dto.getOperator()).isEqualTo(UiCriterionOperator.EQ); assertThat(dto.getOperandRight().getValue()).isEqualTo(criterion.getOperandRight()); } @Test void testMappingFromDtoToCriterion() { - UiCriterionDto dto = new UiCriterionDto(); + UiCriterion dto = new UiCriterion(); dto.setOperandLeft("operandLeft"); - dto.setOperator(OperatorDto.EQ); - dto.setOperandRight(UiCriterionLiteralDto.ofValue("operandRight")); + dto.setOperator(UiCriterionOperator.EQ); + dto.setOperandRight(UiCriterionLiteral.ofValue("operandRight")); Criterion criterion = criterionMapper.mapToCriterion(dto); assertThat(criterion.getOperandLeft()).isEqualTo(dto.getOperandLeft()); - assertThat(criterion.getOperator()).isEqualTo(Operator.EQ.getOdrlRepresentation()); + assertThat(criterion.getOperator()).isEqualTo("="); assertThat(criterion.getOperandRight()).isEqualTo(dto.getOperandRight()); } @Test - void testBuildCriterionLiteral() { + void testLiteralMapping_String() { String value = "testValue"; - UiCriterionLiteralDto dtowithValue = criterionMapper.buildCriterionLiteral(value); + UiCriterionLiteral literal = criterionMapper.buildCriterionLiteral(value); - List valueList = Arrays.asList("value1", "value2", null); - UiCriterionLiteralDto dtowithList = criterionMapper.buildCriterionLiteral(valueList); + assertThat(literal.getType()).isEqualTo(UiCriterionLiteral.CriterionLiteralTypeDto.VALUE); + assertThat(literal.getValue()).isEqualTo(value); + assertThat(literal.getValueList()).isNull(); + } - assertThat(dtowithValue.getType()).isEqualTo(UiCriterionLiteralDto.CriterionLiteralTypeDto.VALUE); - assertThat(dtowithValue.getValue()).isEqualTo(value); - assertThat(dtowithValue.getValueList()).isNull(); + @Test + void testLiteralMapping_StringList() { + List valueList = Arrays.asList("value1", "value2", null); + UiCriterionLiteral literal = criterionMapper.buildCriterionLiteral(valueList); - assertThat(dtowithList.getType()).isEqualTo(UiCriterionLiteralDto.CriterionLiteralTypeDto.VALUE_LIST); - assertThat(dtowithList.getValueList()).containsExactly("value1", "value2", null); - assertThat(dtowithList.getValue()).isNull(); + assertThat(literal.getType()).isEqualTo(UiCriterionLiteral.CriterionLiteralTypeDto.VALUE_LIST); + assertThat(literal.getValueList()).containsExactly("value1", "value2", null); + assertThat(literal.getValue()).isNull(); } @Test void testReadCriterionLiteral() { String value = "testValue"; - UiCriterionLiteralDto dtowithValue = UiCriterionLiteralDto.ofValue(value); + UiCriterionLiteral dtowithValue = UiCriterionLiteral.ofValue(value); List valueList = Arrays.asList("value1", "value2"); - UiCriterionLiteralDto dtowithList = UiCriterionLiteralDto.ofValueList(valueList); + UiCriterionLiteral dtowithList = UiCriterionLiteral.ofValueList(valueList); assertThat(criterionMapper.readCriterionLiteral(dtowithValue)).isEqualTo(value); assertThat(criterionMapper.readCriterionLiteral(dtowithList)).isEqualTo(valueList); diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionOperatorMapperTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionOperatorMapperTest.java new file mode 100644 index 000000000..d2915f2c9 --- /dev/null +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionOperatorMapperTest.java @@ -0,0 +1,38 @@ +package de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions; + +import de.sovity.edc.ext.wrapper.api.ui.model.UiCriterionOperator; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; + +import static org.assertj.core.api.Assertions.assertThat; + +class CriterionOperatorMapperTest { + private CriterionOperatorMapper criterionOperatorMapper; + + @BeforeEach + void setup() { + criterionOperatorMapper = new CriterionOperatorMapper(); + } + + @Test + void testCaseInsensitivity() { + assertThat(criterionOperatorMapper.getUiCriterionOperator("lIKe")).isEqualTo(UiCriterionOperator.LIKE); + } + + @Test + void testMappings() { + assertThat(criterionOperatorMapper.getUiCriterionOperator("=")).isEqualTo(UiCriterionOperator.EQ); + assertThat(criterionOperatorMapper.getUiCriterionOperator("like")).isEqualTo(UiCriterionOperator.LIKE); + assertThat(criterionOperatorMapper.getUiCriterionOperator("in")).isEqualTo(UiCriterionOperator.IN); + assertThat(criterionOperatorMapper.getCriterionOperator(UiCriterionOperator.EQ)).isEqualTo("="); + assertThat(criterionOperatorMapper.getCriterionOperator(UiCriterionOperator.LIKE)).isEqualTo("like"); + assertThat(criterionOperatorMapper.getCriterionOperator(UiCriterionOperator.IN)).isEqualTo("in"); + + // Ensures the mapping isn't forgotten in the future + Arrays.stream(UiCriterionOperator.values()).forEach(criterionOperatorMapper::getCriterionOperator); + } + +} + diff --git a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index 849303eae..af725bc2b 100644 --- a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -16,12 +16,17 @@ import de.sovity.edc.client.EdcClient; import de.sovity.edc.client.gen.model.ContractAgreementTransferRequest; import de.sovity.edc.client.gen.model.ContractAgreementTransferRequestParams; +import de.sovity.edc.client.gen.model.ContractDefinitionRequest; import de.sovity.edc.client.gen.model.ContractNegotiationRequest; import de.sovity.edc.client.gen.model.ContractNegotiationState.SimplifiedStateEnum; +import de.sovity.edc.client.gen.model.PolicyDefinitionCreateRequest; import de.sovity.edc.client.gen.model.UiAssetCreateRequest; import de.sovity.edc.client.gen.model.UiContractNegotiation; import de.sovity.edc.client.gen.model.UiContractOffer; +import de.sovity.edc.client.gen.model.UiCriterionDto; +import de.sovity.edc.client.gen.model.UiCriterionLiteralDto; import de.sovity.edc.client.gen.model.UiDataOffer; +import de.sovity.edc.client.gen.model.UiPolicyCreateRequest; import de.sovity.edc.extension.e2e.connector.ConnectorRemote; import de.sovity.edc.extension.e2e.connector.MockDataAddressRemote; import de.sovity.edc.extension.e2e.db.TestDatabase; @@ -35,12 +40,11 @@ import java.util.List; import java.util.Map; -import java.util.UUID; -import static org.assertj.core.api.Assertions.assertThat; import static de.sovity.edc.extension.e2e.connector.DataTransferTestUtil.validateDataTransferred; import static de.sovity.edc.extension.e2e.connector.config.ConnectorConfigFactory.forTestDatabase; import static de.sovity.edc.extension.e2e.connector.config.ConnectorRemoteConfigFactory.fromConnectorConfig; +import static org.assertj.core.api.Assertions.assertThat; class UiApiWrapperTest { @@ -61,6 +65,7 @@ class UiApiWrapperTest { private ConnectorRemote providerConnector; private ConnectorRemote consumerConnector; + private EdcClient providerClient; private EdcClient consumerClient; private MockDataAddressRemote dataAddress; @@ -70,6 +75,11 @@ void setup() { providerEdcContext.setConfiguration(providerConfig.getProperties()); providerConnector = new ConnectorRemote(fromConnectorConfig(providerConfig)); + providerClient = EdcClient.builder() + .managementApiUrl(providerConfig.getManagementEndpoint().getUri().toString()) + .managementApiKey(providerConfig.getProperties().get("edc.api.auth.key")) + .build(); + var consumerConfig = forTestDatabase(CONSUMER_PARTICIPANT_ID, 23000, CONSUMER_DATABASE); consumerEdcContext.setConfiguration(consumerConfig.getProperties()); consumerConnector = new ConnectorRemote(fromConnectorConfig(consumerConfig)); @@ -87,26 +97,39 @@ void setup() { @Test void provide_consume_assetMapping_policyMapping() { // arrange - // TODO use UI API for creation of the data offer - // TODO use a policy with a constraint - // TODO test all asset properties including additionalProperties var data = "expected data 123"; - var assetId = UUID.randomUUID().toString(); - //providerConnector.createDataOffer(assetId, dataAddress.getDataSourceUrl(data)); - var providerClient = consumerClient; //TODO use providerClient + var policyId = providerClient.uiApi().createPolicyDefinition(PolicyDefinitionCreateRequest.builder() + .policyDefinitionId("policy-1") + .policy(UiPolicyCreateRequest.builder() + .constraints(List.of()) + .build()) + .build()).getId(); - var dataAddressProperties = Map.of( - Prop.Edc.TYPE, "HttpData", - Prop.Edc.BASE_URL, DATA_SINK - ); - var uiAssetRequest = UiAssetCreateRequest.builder() + // TODO test all asset properties including additionalProperties + var assetId = providerClient.uiApi().createAsset(UiAssetCreateRequest.builder() .id("asset-1") .name("AssetName") .keywords(List.of("keyword1", "keyword2")) - .dataAddressProperties(dataAddressProperties) - .build(); - providerClient.uiApi().createAsset(uiAssetRequest); + .dataAddressProperties(Map.of( + Prop.Edc.TYPE, "HttpData", + Prop.Edc.BASE_URL, dataAddress.getDataSourceUrl(data) + )) + .build()).getId(); + + providerClient.uiApi().createContractDefinition(ContractDefinitionRequest.builder() + .contractDefinitionId("cd-1") + .accessPolicyId(policyId) + .contractPolicyId(policyId) + .assetSelector(List.of(UiCriterionDto.builder() + .operandLeft(Prop.Edc.ID) + .operator(UiCriterionDto.OperatorEnum.EQ) + .operandRight(UiCriterionLiteralDto.builder() + .type(UiCriterionLiteralDto.TypeEnum.VALUE) + .value(assetId) + .build()) + .build())) + .build()); var dataOffers = consumerClient.uiApi().catalogPageDataOffers(getProtocolEndpoint(providerConnector)); assertThat(dataOffers).hasSize(1); @@ -121,7 +144,9 @@ void provide_consume_assetMapping_policyMapping() { // assert assertThat(dataOffer.getEndpoint()).isEqualTo(getProtocolEndpoint(providerConnector)); assertThat(dataOffer.getParticipantId()).isEqualTo(PROVIDER_PARTICIPANT_ID); - assertThat(dataOffer.getAsset().getAssetId()).isEqualTo("asset-1"); + assertThat(dataOffer.getAsset().getAssetId()).isEqualTo(assetId); + assertThat(dataOffer.getAsset().getKeywords()).isEqualTo(List.of("keyword1", "keyword2")); + assertThat(dataOffer.getAsset().getName()).isEqualTo("AssetName"); validateDataTransferred(dataAddress.getDataSinkSpyUrl(), data); } From fb7c92eebb9a1b66b44a2de404d50e5caa28c7cf Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Tue, 19 Sep 2023 10:23:01 +0200 Subject: [PATCH 33/37] fix: contract definition literal mapping --- .../WrapperExtensionContextBuilder.java | 4 +- .../ext/wrapper/api/ui/model/UiCriterion.java | 4 ++ .../ContractDefinitionApiService.java | 20 ++++--- .../ContractDefinitionBuilder.java | 2 +- .../CriterionLiteralMapper.java | 50 +++++++++++++++++ .../contract_definitions/CriterionMapper.java | 53 ++++++------------ .../CriterionLiteralMapperTest.java | 54 ++++++++++++++++++ .../CriterionMapperTest.java | 56 ++++--------------- .../de/sovity/edc/e2e/UiApiWrapperTest.java | 14 ++--- 9 files changed, 156 insertions(+), 101 deletions(-) create mode 100644 extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionLiteralMapper.java create mode 100644 extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionLiteralMapperTest.java diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java index 7ccff040a..12745360a 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java @@ -29,6 +29,7 @@ import de.sovity.edc.ext.wrapper.api.ui.pages.catalog.CatalogApiService; import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.ContractDefinitionApiService; import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.ContractDefinitionBuilder; +import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.CriterionLiteralMapper; import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.CriterionMapper; import de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions.CriterionOperatorMapper; import de.sovity.edc.ext.wrapper.api.ui.pages.contract_negotiations.ContractNegotiationApiService; @@ -108,7 +109,8 @@ public static WrapperExtensionContext buildContext( // UI API var operatorMapper = new OperatorMapper(); var criterionOperatorMapper = new CriterionOperatorMapper(); - var criterionMapper = new CriterionMapper(criterionOperatorMapper); + var criterionLiteralMapper = new CriterionLiteralMapper(); + var criterionMapper = new CriterionMapper(criterionOperatorMapper, criterionLiteralMapper); var literalMapper = new LiteralMapper(objectMapper); var atomicConstraintMapper = new AtomicConstraintMapper(literalMapper, operatorMapper); var policyValidator = new PolicyValidator(); diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterion.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterion.java index c9036ec7b..465e4a300 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterion.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/model/UiCriterion.java @@ -16,9 +16,13 @@ import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NoArgsConstructor; @Data +@NoArgsConstructor +@AllArgsConstructor @Schema(description = "Contract Definition Criterion as supported by the UI") public class UiCriterion { @Schema(description = "Left Operand", requiredMode = Schema.RequiredMode.REQUIRED) diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/ContractDefinitionApiService.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/ContractDefinitionApiService.java index 2f2ec3af2..47a9d0be2 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/ContractDefinitionApiService.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/ContractDefinitionApiService.java @@ -37,14 +37,18 @@ public List getContractDefinitions() { var definitions = getAllContractDefinitions(); return definitions.stream() .sorted(Comparator.comparing(ContractDefinition::getCreatedAt).reversed()) - .map(definition -> { - var entry = new ContractDefinitionEntry(); - entry.setContractDefinitionId(definition.getId()); - entry.setAccessPolicyId(definition.getAccessPolicyId()); - entry.setContractPolicyId(definition.getContractPolicyId()); - entry.setAssetSelector(criterionMapper.mapToCriterionDtos(definition.getAssetsSelector())); - return entry; - }).toList(); + .map(this::buildContractDefinitionEntry) + .toList(); + } + + @NotNull + private ContractDefinitionEntry buildContractDefinitionEntry(ContractDefinition definition) { + var entry = new ContractDefinitionEntry(); + entry.setContractDefinitionId(definition.getId()); + entry.setAccessPolicyId(definition.getAccessPolicyId()); + entry.setContractPolicyId(definition.getContractPolicyId()); + entry.setAssetSelector(criterionMapper.buildUiCriteria(definition.getAssetsSelector())); + return entry; } @NotNull diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/ContractDefinitionBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/ContractDefinitionBuilder.java index 0962dfbff..b948eed0d 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/ContractDefinitionBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/ContractDefinitionBuilder.java @@ -34,7 +34,7 @@ public ContractDefinition buildContractDefinition(ContractDefinitionRequest requ .id(contractDefinitionId) .contractPolicyId(contractPolicyId) .accessPolicyId(accessPolicyId) - .assetsSelector(criterionMapper.mapToCriteria(assetsSelector)) + .assetsSelector(criterionMapper.buildCriteria(assetsSelector)) .build(); } } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionLiteralMapper.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionLiteralMapper.java new file mode 100644 index 000000000..d8b10088e --- /dev/null +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionLiteralMapper.java @@ -0,0 +1,50 @@ +/* + * 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.wrapper.api.ui.pages.contract_definitions; + + +import de.sovity.edc.ext.wrapper.api.ui.model.UiCriterionLiteral; +import lombok.RequiredArgsConstructor; + +import java.util.Collection; +import java.util.List; + +@RequiredArgsConstructor +public class CriterionLiteralMapper { + + public UiCriterionLiteral buildUiCriterionLiteral(Object value) { + if (value instanceof Collection) { + var list = getValueList((Collection) value); + return UiCriterionLiteral.ofValueList(list); + } + + return UiCriterionLiteral.ofValue(value.toString()); + } + + public Object getValue(UiCriterionLiteral dto) { + return switch (dto.getType()) { + case VALUE -> dto.getValue(); + case VALUE_LIST -> dto.getValueList(); + default -> throw new IllegalStateException("Unhandled %s: %s".formatted( + UiCriterionLiteral.CriterionLiteralTypeDto.class.getName(), + dto.getType() + )); + }; + } + + private List getValueList(Collection valueList) { + return valueList.stream().map(it -> it == null ? null : it.toString()).toList(); + } +} diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionMapper.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionMapper.java index 7d7152b96..79191ebfd 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionMapper.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionMapper.java @@ -16,60 +16,39 @@ import de.sovity.edc.ext.wrapper.api.ui.model.UiCriterion; -import de.sovity.edc.ext.wrapper.api.ui.model.UiCriterionLiteral; import lombok.NonNull; import lombok.RequiredArgsConstructor; import org.eclipse.edc.spi.query.Criterion; -import java.util.Collection; import java.util.List; +import java.util.Objects; @RequiredArgsConstructor public class CriterionMapper { private final CriterionOperatorMapper criterionOperatorMapper; + private final CriterionLiteralMapper criterionLiteralMapper; - public List mapToCriterionDtos(@NonNull List criteria) { - return criteria.stream().map(this::mapToCriterionDto).toList(); + public List buildUiCriteria(@NonNull List criteria) { + return criteria.stream().filter(Objects::nonNull).map(this::buildUiCriterion).toList(); } - UiCriterion mapToCriterionDto(Criterion criterion) { - if (criterion == null) { - return null; - } - UiCriterion dto = new UiCriterion(); - UiCriterionLiteral literalDto = buildCriterionLiteral(criterion.getOperandRight()); - dto.setOperandLeft(String.valueOf(criterion.getOperandLeft())); - dto.setOperator(criterionOperatorMapper.getUiCriterionOperator(criterion.getOperator())); - dto.setOperandRight(literalDto); - return dto; - } + public UiCriterion buildUiCriterion(Criterion criterion) { + var operandLeft = String.valueOf(criterion.getOperandLeft()); + var operator = criterionOperatorMapper.getUiCriterionOperator(criterion.getOperator()); + var operandRight = criterionLiteralMapper.buildUiCriterionLiteral(criterion.getOperandRight()); - public Criterion mapToCriterion(@NonNull UiCriterion criterionDto) { - return new Criterion( - criterionDto.getOperandLeft(), - criterionOperatorMapper.getCriterionOperator(criterionDto.getOperator()), - criterionDto.getOperandRight()); + return new UiCriterion(operandLeft, operator, operandRight); } - public List mapToCriteria(@NonNull List criterionDtos) { - return criterionDtos.stream().map(this::mapToCriterion).toList(); + public List buildCriteria(@NonNull List criteria) { + return criteria.stream().filter(Objects::nonNull).map(this::buildCriterion).toList(); } + public Criterion buildCriterion(@NonNull UiCriterion criterionDto) { + var operandLeft = criterionDto.getOperandLeft(); + var operator = criterionOperatorMapper.getCriterionOperator(criterionDto.getOperator()); + var operandRight = criterionLiteralMapper.getValue(criterionDto.getOperandRight()); - @SuppressWarnings("unchecked") - UiCriterionLiteral buildCriterionLiteral(Object value) { - if (value instanceof Collection) { - var list = ((Collection) value).stream().map(it -> it == null ? null : it.toString()).toList(); - return UiCriterionLiteral.ofValueList(list); - } - - return UiCriterionLiteral.ofValue(value.toString()); - } - - Object readCriterionLiteral(UiCriterionLiteral dto) { - if (dto.getType() == UiCriterionLiteral.CriterionLiteralTypeDto.VALUE_LIST) { - return dto.getValueList(); - } - return dto.getValue(); + return new Criterion(operandLeft, operator, operandRight); } } diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionLiteralMapperTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionLiteralMapperTest.java new file mode 100644 index 000000000..e9ea4773e --- /dev/null +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionLiteralMapperTest.java @@ -0,0 +1,54 @@ +package de.sovity.edc.ext.wrapper.api.ui.pages.contract_definitions; + +import de.sovity.edc.ext.wrapper.api.ui.model.UiCriterionLiteral; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import java.util.Arrays; +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +class CriterionLiteralMapperTest { + private CriterionLiteralMapper criterionLiteralMapper; + + @BeforeEach + void setup() { + criterionLiteralMapper = new CriterionLiteralMapper(); + } + + @Test + void testBuildUiCriterionLiteral_String() { + String value = "testValue"; + UiCriterionLiteral literal = criterionLiteralMapper.buildUiCriterionLiteral(value); + + assertThat(literal.getType()).isEqualTo(UiCriterionLiteral.CriterionLiteralTypeDto.VALUE); + assertThat(literal.getValue()).isEqualTo(value); + assertThat(literal.getValueList()).isNull(); + } + + @Test + void testBuildUiCriterionLiteral_StringList() { + List valueList = Arrays.asList("value1", "value2", null); + UiCriterionLiteral literal = criterionLiteralMapper.buildUiCriterionLiteral(valueList); + + assertThat(literal.getType()).isEqualTo(UiCriterionLiteral.CriterionLiteralTypeDto.VALUE_LIST); + assertThat(literal.getValueList()).containsExactly("value1", "value2", null); + assertThat(literal.getValue()).isNull(); + } + + @Test + void testGetValue_String() { + String value = "testValue"; + UiCriterionLiteral literal = UiCriterionLiteral.ofValue(value); + assertThat(criterionLiteralMapper.getValue(literal)).isEqualTo(value); + } + + @Test + void testGetValue_StringList() { + List valueList = Arrays.asList("value1", "value2"); + UiCriterionLiteral literal = UiCriterionLiteral.ofValueList(valueList); + assertThat(criterionLiteralMapper.getValue(literal)).isEqualTo(valueList); + } +} + diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionMapperTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionMapperTest.java index eb8096c9b..367408088 100644 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionMapperTest.java +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/ui/pages/contract_definitions/CriterionMapperTest.java @@ -7,9 +7,6 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import java.util.Arrays; -import java.util.List; - import static org.assertj.core.api.Assertions.assertThat; class CriterionMapperTest { @@ -17,64 +14,31 @@ class CriterionMapperTest { @BeforeEach void setup() { - criterionMapper = new CriterionMapper(new CriterionOperatorMapper()); + criterionMapper = new CriterionMapper(new CriterionOperatorMapper(), new CriterionLiteralMapper()); } @Test void testMappingFromCriterionToDto() { - Criterion criterion = new Criterion("operandLeft", "=", "operandRight"); - UiCriterion dto = criterionMapper.mapToCriterionDto(criterion); + Criterion criterion = new Criterion("left", "=", "right"); + UiCriterion dto = criterionMapper.buildUiCriterion(criterion); - assertThat(dto.getOperandLeft()).isEqualTo(criterion.getOperandLeft()); + assertThat(dto.getOperandLeft()).isEqualTo("left"); assertThat(dto.getOperator()).isEqualTo(UiCriterionOperator.EQ); - assertThat(dto.getOperandRight().getValue()).isEqualTo(criterion.getOperandRight()); + assertThat(dto.getOperandRight().getValue()).isEqualTo("right"); } @Test void testMappingFromDtoToCriterion() { UiCriterion dto = new UiCriterion(); - dto.setOperandLeft("operandLeft"); + dto.setOperandLeft("left"); dto.setOperator(UiCriterionOperator.EQ); - dto.setOperandRight(UiCriterionLiteral.ofValue("operandRight")); + dto.setOperandRight(UiCriterionLiteral.ofValue("right")); - Criterion criterion = criterionMapper.mapToCriterion(dto); + Criterion criterion = criterionMapper.buildCriterion(dto); - assertThat(criterion.getOperandLeft()).isEqualTo(dto.getOperandLeft()); + assertThat(criterion.getOperandLeft()).isEqualTo("left"); assertThat(criterion.getOperator()).isEqualTo("="); - assertThat(criterion.getOperandRight()).isEqualTo(dto.getOperandRight()); - } - - @Test - void testLiteralMapping_String() { - String value = "testValue"; - UiCriterionLiteral literal = criterionMapper.buildCriterionLiteral(value); - - assertThat(literal.getType()).isEqualTo(UiCriterionLiteral.CriterionLiteralTypeDto.VALUE); - assertThat(literal.getValue()).isEqualTo(value); - assertThat(literal.getValueList()).isNull(); - } - - @Test - void testLiteralMapping_StringList() { - List valueList = Arrays.asList("value1", "value2", null); - UiCriterionLiteral literal = criterionMapper.buildCriterionLiteral(valueList); - - assertThat(literal.getType()).isEqualTo(UiCriterionLiteral.CriterionLiteralTypeDto.VALUE_LIST); - assertThat(literal.getValueList()).containsExactly("value1", "value2", null); - assertThat(literal.getValue()).isNull(); - } - - @Test - void testReadCriterionLiteral() { - String value = "testValue"; - UiCriterionLiteral dtowithValue = UiCriterionLiteral.ofValue(value); - - List valueList = Arrays.asList("value1", "value2"); - UiCriterionLiteral dtowithList = UiCriterionLiteral.ofValueList(valueList); - - assertThat(criterionMapper.readCriterionLiteral(dtowithValue)).isEqualTo(value); - assertThat(criterionMapper.readCriterionLiteral(dtowithList)).isEqualTo(valueList); - + assertThat(criterion.getOperandRight()).isEqualTo("right"); } } diff --git a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index af725bc2b..7d2ffdc84 100644 --- a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -23,8 +23,8 @@ import de.sovity.edc.client.gen.model.UiAssetCreateRequest; import de.sovity.edc.client.gen.model.UiContractNegotiation; import de.sovity.edc.client.gen.model.UiContractOffer; -import de.sovity.edc.client.gen.model.UiCriterionDto; -import de.sovity.edc.client.gen.model.UiCriterionLiteralDto; +import de.sovity.edc.client.gen.model.UiCriterion; +import de.sovity.edc.client.gen.model.UiCriterionLiteral; import de.sovity.edc.client.gen.model.UiDataOffer; import de.sovity.edc.client.gen.model.UiPolicyCreateRequest; import de.sovity.edc.extension.e2e.connector.ConnectorRemote; @@ -50,7 +50,6 @@ class UiApiWrapperTest { private static final String PROVIDER_PARTICIPANT_ID = "provider"; private static final String CONSUMER_PARTICIPANT_ID = "consumer"; - public static final String DATA_SINK = "http://my-data-sink/api/stuff"; @RegisterExtension static EdcExtension providerEdcContext = new EdcExtension(); @@ -106,7 +105,6 @@ void provide_consume_assetMapping_policyMapping() { .build()) .build()).getId(); - // TODO test all asset properties including additionalProperties var assetId = providerClient.uiApi().createAsset(UiAssetCreateRequest.builder() .id("asset-1") .name("AssetName") @@ -121,11 +119,11 @@ void provide_consume_assetMapping_policyMapping() { .contractDefinitionId("cd-1") .accessPolicyId(policyId) .contractPolicyId(policyId) - .assetSelector(List.of(UiCriterionDto.builder() + .assetSelector(List.of(UiCriterion.builder() .operandLeft(Prop.Edc.ID) - .operator(UiCriterionDto.OperatorEnum.EQ) - .operandRight(UiCriterionLiteralDto.builder() - .type(UiCriterionLiteralDto.TypeEnum.VALUE) + .operator(UiCriterion.OperatorEnum.EQ) + .operandRight(UiCriterionLiteral.builder() + .type(UiCriterionLiteral.TypeEnum.VALUE) .value(assetId) .build()) .build())) From 5e51ebcf33328ef9487feb1e5e34698f24e71433 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Tue, 19 Sep 2023 10:48:32 +0200 Subject: [PATCH 34/37] fix: asset json-ld handling --- extensions/wrapper/client/build.gradle.kts | 2 +- .../edc/client/AssetApiServiceTest.java | 71 +++++++++- .../java/de/sovity/edc/client/TestUtils.java | 1 - .../ext/wrapper/api/common/model/UiAsset.java | 13 +- .../wrapper-common-mappers/build.gradle.kts | 1 + .../api/common/mappers/AssetMapper.java | 61 ++++---- .../api/common/mappers/PolicyMapper.java | 7 +- .../utils/AssetDistributionJsonLd.java | 22 --- .../api/common/mappers/utils/AssetJsonLd.java | 33 ----- .../mappers/utils/AssetPropertyJsonLd.java | 105 -------------- .../mappers/utils/AssetPublisherJsonLd.java | 24 ---- .../mappers/utils/FailedMappingException.java | 13 ++ .../mappers/utils/JsonBuilderUtils.java | 9 +- .../common/mappers/utils/UiAssetBuilder.java | 109 --------------- .../common/mappers/utils/UiAssetMapper.java | 130 ++++++++++++++++++ .../api/common/mappers/AssetMapperTest.java | 16 ++- .../WrapperExtensionContextBuilder.java | 6 +- .../java/de/sovity/edc/utils/JsonUtils.java | 4 + .../sovity/edc/utils/jsonld/JsonLdUtils.java | 82 ++++++++++- .../sovity/edc/utils/jsonld/vocab/Prop.java | 17 ++- 20 files changed, 366 insertions(+), 360 deletions(-) delete mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetDistributionJsonLd.java delete mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetJsonLd.java delete mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPropertyJsonLd.java delete mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPublisherJsonLd.java create mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/FailedMappingException.java delete mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java create mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetMapper.java diff --git a/extensions/wrapper/client/build.gradle.kts b/extensions/wrapper/client/build.gradle.kts index da7569e62..ed8781609 100644 --- a/extensions/wrapper/client/build.gradle.kts +++ b/extensions/wrapper/client/build.gradle.kts @@ -63,7 +63,7 @@ dependencies { testImplementation("${jettyGroup}:jetty-util:${jettyVersion}") testImplementation("${jettyGroup}:jetty-webapp:${jettyVersion}") - testImplementation("${edcGroup}:json-ld-spi:${edcVersion}") + testImplementation("${edcGroup}:json-ld:${edcVersion}") testImplementation("${edcGroup}:dsp-http-spi:${edcVersion}") testImplementation("${edcGroup}:dsp-api-configuration:${edcVersion}") testImplementation(project(":extensions:wrapper:wrapper")) diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java index 8f85c6dac..a2db9a5fb 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java @@ -17,6 +17,7 @@ import de.sovity.edc.client.gen.model.UiAsset; import de.sovity.edc.client.gen.model.UiAssetCreateRequest; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.FailedMappingException; import de.sovity.edc.utils.jsonld.vocab.Prop; import lombok.SneakyThrows; import org.eclipse.edc.connector.spi.asset.AssetService; @@ -92,7 +93,11 @@ void testAssetCreation(AssetService assetService) { var client = TestUtils.edcClient(); var dataAddressProperties = Map.of( Prop.Edc.TYPE, "HttpData", - Prop.Edc.BASE_URL, DATA_SINK + Prop.Edc.BASE_URL, DATA_SINK, + Prop.Edc.PROXY_METHOD, "true", + Prop.Edc.PROXY_PATH, "true", + Prop.Edc.PROXY_QUERY_PARAMS, "true", + Prop.Edc.PROXY_BODY, "true" ); var uiAssetRequest = UiAssetCreateRequest.builder() .id("asset-1") @@ -118,9 +123,11 @@ void testAssetCreation(AssetService assetService) { // assert assertThat(response.getId()).isEqualTo("asset-1"); + var assets = client.uiApi().assetPage().getAssets(); assertThat(assets).hasSize(1); var asset = assets.get(0); + assertThat(asset.getAssetId()).isEqualTo("asset-1"); assertThat(asset.getName()).isEqualTo("AssetName"); assertThat(asset.getDescription()).isEqualTo("AssetDescription"); assertThat(asset.getVersion()).isEqualTo("1.0.0"); @@ -135,11 +142,68 @@ void testAssetCreation(AssetService assetService) { assertThat(asset.getKeywords()).isEqualTo(List.of("keyword1", "keyword2")); assertThat(asset.getCreatorOrganizationName()).isEqualTo("creatorOrganizationName"); assertThat(asset.getPublisherHomepage()).isEqualTo("publisherHomepage"); + assertThat(asset.getHttpDatasourceHintsProxyMethod()).isTrue(); + assertThat(asset.getHttpDatasourceHintsProxyPath()).isTrue(); + assertThat(asset.getHttpDatasourceHintsProxyQueryParams()).isTrue(); + assertThat(asset.getHttpDatasourceHintsProxyBody()).isTrue(); - var assetWithDataAddress = assetService.query(QuerySpec.max()).getContent().toList().get(0); + var assetWithDataAddress = assetService.query(QuerySpec.max()).orElseThrow(FailedMappingException::ofFailure).toList().get(0); assertThat(assetWithDataAddress.getDataAddress().getProperties()).isEqualTo(dataAddressProperties); } + @Test + void testAssetCreation_noProxying() { + // arrange + var client = TestUtils.edcClient(); + var dataAddressProperties = Map.of( + Prop.Edc.TYPE, "HttpData", + Prop.Edc.BASE_URL, DATA_SINK + ); + var uiAssetRequest = UiAssetCreateRequest.builder() + .id("asset-1") + .dataAddressProperties(dataAddressProperties) + .build(); + + // act + var response = client.uiApi().createAsset(uiAssetRequest); + + // assert + assertThat(response.getId()).isEqualTo("asset-1"); + var assets = client.uiApi().assetPage().getAssets(); + assertThat(assets).hasSize(1); + var asset = assets.get(0); + assertThat(asset.getHttpDatasourceHintsProxyMethod()).isFalse(); + assertThat(asset.getHttpDatasourceHintsProxyPath()).isFalse(); + assertThat(asset.getHttpDatasourceHintsProxyQueryParams()).isFalse(); + assertThat(asset.getHttpDatasourceHintsProxyBody()).isFalse(); + } + + @Test + void testAssetCreation_differentDataAddressType() { + // arrange + var client = TestUtils.edcClient(); + var dataAddressProperties = Map.of( + Prop.Edc.TYPE, "Unknown" + ); + var uiAssetRequest = UiAssetCreateRequest.builder() + .id("asset-1") + .dataAddressProperties(dataAddressProperties) + .build(); + + // act + var response = client.uiApi().createAsset(uiAssetRequest); + + // assert + assertThat(response.getId()).isEqualTo("asset-1"); + var assets = client.uiApi().assetPage().getAssets(); + assertThat(assets).hasSize(1); + var asset = assets.get(0); + assertThat(asset.getHttpDatasourceHintsProxyMethod()).isNull(); + assertThat(asset.getHttpDatasourceHintsProxyPath()).isNull(); + assertThat(asset.getHttpDatasourceHintsProxyQueryParams()).isNull(); + assertThat(asset.getHttpDatasourceHintsProxyBody()).isNull(); + } + @Test void testDeleteAsset(AssetService assetService) { // arrange @@ -160,10 +224,9 @@ private void createAsset( String date, Map properties ) { - DataAddress dataAddress = DataAddress.Builder.newInstance() .type("HttpData") - .property("baseUrl", DATA_SINK) + .property(Prop.Edc.BASE_URL, DATA_SINK) .build(); var asset = Asset.Builder.newInstance() diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/TestUtils.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/TestUtils.java index 0662c0f0a..0e10d23f1 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/TestUtils.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/TestUtils.java @@ -57,7 +57,6 @@ public static Map createConfiguration( public static void setupExtension(EdcExtension extension) { extension.registerServiceMock(ProtocolWebhook.class, mock(ProtocolWebhook.class)); - extension.registerServiceMock(JsonLd.class, mock(JsonLd.class)); extension.setConfiguration(createConfiguration(Map.of())); } diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java index 72f095899..0b3979285 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java @@ -95,15 +95,18 @@ public class UiAsset { @Schema(description = "Transport Mode", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String transportMode; - @Schema(description = "Asset additional Properties", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @Schema(description = "Unhandled Asset Properties (that were strings)", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private Map additionalProperties; - @Schema(description = "Asset Private Properties", requiredMode = Schema.RequiredMode.NOT_REQUIRED) - private Map privateProperties; - - @Schema(description = "Asset Json Properties", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @Schema(description = "Unhandled Asset Properties (that were not strings but other JSON values)", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private Map additionalJsonProperties; + @Schema(description = "Private Asset Properties (that were strings)", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private Map privateProperties; + + @Schema(description = "Private Asset Properties (that were not strings but other JSON values)", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + private Map privateJsonProperties; + @Schema(description = "Contains the entire asset in its original expanded JSON-LD format", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String assetJsonLd; } diff --git a/extensions/wrapper/wrapper-common-mappers/build.gradle.kts b/extensions/wrapper/wrapper-common-mappers/build.gradle.kts index 48f4332a3..8f6de4f2f 100644 --- a/extensions/wrapper/wrapper-common-mappers/build.gradle.kts +++ b/extensions/wrapper/wrapper-common-mappers/build.gradle.kts @@ -25,6 +25,7 @@ dependencies { testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}") testCompileOnly("org.projectlombok:lombok:${lombokVersion}") + testImplementation("${edcGroup}:json-ld:${edcVersion}") testImplementation("org.mockito:mockito-core:${mockitoVersion}") testImplementation("org.mockito:mockito-inline:${mockitoVersion}") testImplementation("org.mockito:mockito-junit-jupiter:${mockitoVersion}") diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java index caa3d6e35..c1727e2e3 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapper.java @@ -1,6 +1,7 @@ package de.sovity.edc.ext.wrapper.api.common.mappers; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.UiAssetBuilder; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.FailedMappingException; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.UiAssetMapper; import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; import de.sovity.edc.utils.jsonld.JsonLdUtils; @@ -8,37 +9,52 @@ import jakarta.json.Json; import jakarta.json.JsonObject; import lombok.RequiredArgsConstructor; +import org.eclipse.edc.jsonld.spi.JsonLd; import org.eclipse.edc.spi.types.domain.asset.Asset; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; -import java.util.Map; import java.util.Optional; @RequiredArgsConstructor public class AssetMapper { private final TypeTransformerRegistry typeTransformerRegistry; - private final UiAssetBuilder uiAssetBuilder; + private final UiAssetMapper uiAssetMapper; + private final JsonLd jsonLd; public UiAsset buildUiAsset(Asset asset) { - var jsonLd = buildAssetJsonLd(asset); - return buildUiAsset(jsonLd); + var assetJsonLd = buildAssetJsonLd(asset); + return buildUiAsset(assetJsonLd); } public UiAsset buildUiAsset(JsonObject assetJsonLd) { - return uiAssetBuilder.buildUiAsset(assetJsonLd); + return uiAssetMapper.buildUiAsset(assetJsonLd); } public Asset buildAsset(UiAssetCreateRequest createRequest) { - var assetJsonLd = uiAssetBuilder.buildAssetJsonLd(createRequest); - return buildAsset(assetJsonLd, createRequest.getCreatorOrganizationName(), createRequest.getPublisherHomepage()); + var assetJsonLd = uiAssetMapper.buildAssetJsonLd(createRequest); + return buildAsset(assetJsonLd); } public Asset buildAssetFromDatasetProperties(JsonObject json) { - return typeTransformerRegistry.transform(buildJsonLdFromDatasetProperties(json), Asset.class).getContent(); + return buildAsset(buildAssetJsonLdFromDatasetProperties(json)); } - private JsonObject buildJsonLdFromDatasetProperties(JsonObject json) { + public Asset buildAsset(JsonObject assetJsonLd) { + var expanded = jsonLd.expand(assetJsonLd) + .orElseThrow(FailedMappingException::ofFailure); + return typeTransformerRegistry.transform(expanded, Asset.class) + .orElseThrow(FailedMappingException::ofFailure); + } + + private JsonObject buildAssetJsonLd(Asset asset) { + var assetJsonLd = typeTransformerRegistry.transform(asset, JsonObject.class) + .orElseThrow(FailedMappingException::ofFailure); + return jsonLd.expand(assetJsonLd) + .orElseThrow(FailedMappingException::ofFailure); + } + + private JsonObject buildAssetJsonLdFromDatasetProperties(JsonObject json) { // Try to use the EDC Prop ID, but if it's not available, fall back to the "@id" property var assetId = Optional.ofNullable(JsonLdUtils.string(json, Prop.Edc.ID)) .orElseGet(() -> JsonLdUtils.string(json, Prop.ID)); @@ -48,29 +64,4 @@ private JsonObject buildJsonLdFromDatasetProperties(JsonObject json) { .add(Prop.Edc.PROPERTIES, json) .build(); } - - private JsonObject buildAssetJsonLd(Asset asset) { - return typeTransformerRegistry.transform(asset, JsonObject.class).getContent(); - } - - /** - * Builds an Asset from the provided assetJsonLd with additional properties for creator and publisher. - * - * @param assetJsonLd the base JsonObject to build the Asset from - * @param creator the creator to add as a property to the Asset (can be null) - * @param publisher the publisher to add as a property to the Asset (can be null) - * @return the built Asset with the added properties - */ - private Asset buildAsset(JsonObject assetJsonLd, String creator, String publisher) { - var asset = typeTransformerRegistry.transform(assetJsonLd, Asset.class).getContent(); - var assetBuilder = asset.toBuilder(); - - if (creator != null) { - assetBuilder.property(Prop.Dcterms.CREATOR, Map.of(Prop.TYPE, Prop.Foaf.ORGANIZATION, Prop.Foaf.NAME, creator)); - } - if (publisher != null) { - assetBuilder.property(Prop.Dcterms.PUBLISHER, Map.of(Prop.TYPE, Prop.Foaf.ORGANIZATION, Prop.Foaf.HOMEPAGE, publisher)); - } - return assetBuilder.build(); - } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java index 778bf9f46..be9a8bbd4 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/PolicyMapper.java @@ -2,6 +2,7 @@ import de.sovity.edc.ext.wrapper.api.common.mappers.utils.AtomicConstraintMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.ConstraintExtractor; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.FailedMappingException; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.MappingErrors; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.PolicyValidator; import de.sovity.edc.ext.wrapper.api.common.model.UiPolicyCreateRequest; @@ -80,7 +81,8 @@ public Policy buildPolicy(UiPolicyCreateRequest policyCreateDto) { * @return {@link Policy} */ public Policy buildPolicy(JsonObject policyJsonLd) { - return typeTransformerRegistry.transform(policyJsonLd, Policy.class).getContent(); + return typeTransformerRegistry.transform(policyJsonLd, Policy.class) + .orElseThrow(FailedMappingException::ofFailure); } /** @@ -104,6 +106,7 @@ public Policy buildPolicy(String policyJsonLd) { * @return policy JSON-LD */ public JsonObject buildPolicyJsonLd(Policy policy) { - return typeTransformerRegistry.transform(policy, JsonObject.class).getContent(); + return typeTransformerRegistry.transform(policy, JsonObject.class) + .orElseThrow(FailedMappingException::ofFailure); } } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetDistributionJsonLd.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetDistributionJsonLd.java deleted file mode 100644 index 0f7a9e7bc..000000000 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetDistributionJsonLd.java +++ /dev/null @@ -1,22 +0,0 @@ -package de.sovity.edc.ext.wrapper.api.common.mappers.utils; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; -import lombok.ToString; - - -@Getter -@Setter -@ToString -@AllArgsConstructor -@Builder(toBuilder = true) -@RequiredArgsConstructor -public class AssetDistributionJsonLd { - - @JsonProperty("http://www.w3.org/ns/dcat#mediaType") - private String mediaType; -} diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetJsonLd.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetJsonLd.java deleted file mode 100644 index ad11a4ae8..000000000 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetJsonLd.java +++ /dev/null @@ -1,33 +0,0 @@ -package de.sovity.edc.ext.wrapper.api.common.mappers.utils; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import de.sovity.edc.ext.wrapper.api.common.model.utils.CustomDeserializer; -import de.sovity.edc.utils.jsonld.vocab.Prop; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; -import lombok.ToString; - - -@Getter -@Setter -@ToString -@AllArgsConstructor -@Builder(toBuilder = true) -@RequiredArgsConstructor -@JsonIgnoreProperties(ignoreUnknown = true) -public class AssetJsonLd { - - @JsonProperty(Prop.ID) - @JsonDeserialize(using = CustomDeserializer.class) - private String assetId; - - @JsonProperty(Prop.PROPERTIES) - @JsonDeserialize(using = CustomDeserializer.class) - private AssetPropertyJsonLd properties; -} - diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPropertyJsonLd.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPropertyJsonLd.java deleted file mode 100644 index 1ce59364f..000000000 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPropertyJsonLd.java +++ /dev/null @@ -1,105 +0,0 @@ -package de.sovity.edc.ext.wrapper.api.common.mappers.utils; - -import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import com.fasterxml.jackson.annotation.JsonProperty; -import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import de.sovity.edc.ext.wrapper.api.common.model.utils.CustomDeserializer; -import de.sovity.edc.utils.jsonld.vocab.Prop; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; -import lombok.ToString; - -import java.util.List; - - -@Getter -@Setter -@ToString -@AllArgsConstructor -@Builder(toBuilder = true) -@RequiredArgsConstructor -@JsonIgnoreProperties(ignoreUnknown = true) -public class AssetPropertyJsonLd { - - @JsonProperty(Prop.Edc.ID) - @JsonDeserialize(using = CustomDeserializer.class) - private String assetId; - - @JsonProperty(Prop.Dcterms.NAME) - @JsonDeserialize(using = CustomDeserializer.class) - private String name; - - @JsonProperty(Prop.Dcterms.LANGUAGE) - @JsonDeserialize(using = CustomDeserializer.class) - private String language; - - @JsonProperty(Prop.Dcterms.DESCRIPTION) - @JsonDeserialize(using = CustomDeserializer.class) - private String description; - - @JsonProperty(Prop.Dcterms.CREATOR) - private AssetCreatorOrganizationNameJsonLd creator; - - @JsonProperty(Prop.Dcterms.PUBLISHER) - private AssetPublisherJsonLd publisher; - - @JsonProperty(Prop.Dcterms.LICENSE) - @JsonDeserialize(using = CustomDeserializer.class) - private String license; - - @JsonProperty(Prop.Dcat.VERSION) - @JsonDeserialize(using = CustomDeserializer.class) - private String version; - - @JsonProperty(Prop.Dcat.KEYWORDS) - @JsonDeserialize(using = CustomDeserializer.class) - private List keywords; - - @JsonProperty(Prop.Dcat.MEDIATYPE) - @JsonDeserialize(using = CustomDeserializer.class) - private String mediaType; - - @JsonProperty(Prop.Dcat.LANDING_PAGE) - @JsonDeserialize(using = CustomDeserializer.class) - private String landingPage; - - @JsonProperty(Prop.SovityDcatExt.METHOD) - @JsonDeserialize(using = CustomDeserializer.class) - private Boolean httpDatasourceHintsProxyMethod; - - @JsonProperty(Prop.SovityDcatExt.PATH) - @JsonDeserialize(using = CustomDeserializer.class) - private Boolean httpDatasourceHintsProxyPath; - - @JsonProperty(Prop.SovityDcatExt.QUERY_PARAMS) - @JsonDeserialize(using = CustomDeserializer.class) - private Boolean httpDatasourceHintsProxyQueryParams; - - @JsonProperty(Prop.SovityDcatExt.BODY) - @JsonDeserialize(using = CustomDeserializer.class) - private Boolean httpDatasourceHintsProxyBody; - - @JsonProperty(Prop.Mds.DATA_CATEGORY) - @JsonDeserialize(using = CustomDeserializer.class) - private String dataCategory; - - @JsonProperty(Prop.Mds.DATA_SUBCATEGORY) - @JsonDeserialize(using = CustomDeserializer.class) - private String dataSubcategory; - - @JsonProperty(Prop.Mds.DATA_MODEL) - @JsonDeserialize(using = CustomDeserializer.class) - private String dataModel; - - @JsonProperty(Prop.Mds.GEO_REFERENCE_METHOD) - @JsonDeserialize(using = CustomDeserializer.class) - private String geoReferenceMethod; - - @JsonProperty(Prop.Mds.TRANSPORT_MODE) - @JsonDeserialize(using = CustomDeserializer.class) - private String transportMode; -} - diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPublisherJsonLd.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPublisherJsonLd.java deleted file mode 100644 index c4f66f4bc..000000000 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetPublisherJsonLd.java +++ /dev/null @@ -1,24 +0,0 @@ -package de.sovity.edc.ext.wrapper.api.common.mappers.utils; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; -import lombok.ToString; - - -@Getter -@Setter -@ToString -@AllArgsConstructor -@Builder(toBuilder = true) -@RequiredArgsConstructor -public class AssetPublisherJsonLd { - @JsonProperty("@type") - private String type; - - @JsonProperty("http://xmlns.com/foaf/0.1/homepage") - private String name; -} diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/FailedMappingException.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/FailedMappingException.java new file mode 100644 index 000000000..d9b5ea056 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/FailedMappingException.java @@ -0,0 +1,13 @@ +package de.sovity.edc.ext.wrapper.api.common.mappers.utils; + +import org.eclipse.edc.spi.result.Failure; + +public class FailedMappingException extends RuntimeException { + public FailedMappingException(String message) { + super(message); + } + + public static FailedMappingException ofFailure(Failure failure) { + return new FailedMappingException(failure.getFailureDetail()); + } +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonBuilderUtils.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonBuilderUtils.java index 8861a2771..8e8d7e975 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonBuilderUtils.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/JsonBuilderUtils.java @@ -2,17 +2,18 @@ import jakarta.json.Json; import jakarta.json.JsonObjectBuilder; -import lombok.RequiredArgsConstructor; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; import org.apache.commons.collections4.CollectionUtils; import java.util.List; -@RequiredArgsConstructor +@NoArgsConstructor(access = AccessLevel.PRIVATE) public class JsonBuilderUtils { - protected static JsonObjectBuilder addNonNull(JsonObjectBuilder builder, String key, Object value) { + protected static JsonObjectBuilder addNonNull(JsonObjectBuilder builder, String key, String value) { if (value != null) { - builder.add(key, (String) value); + builder.add(key, value); } return builder; } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java deleted file mode 100644 index de461b1fb..000000000 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetBuilder.java +++ /dev/null @@ -1,109 +0,0 @@ -package de.sovity.edc.ext.wrapper.api.common.mappers.utils; - -import com.fasterxml.jackson.databind.ObjectMapper; -import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; -import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; -import de.sovity.edc.utils.JsonUtils; -import de.sovity.edc.utils.jsonld.vocab.Prop; -import jakarta.json.Json; -import jakarta.json.JsonObject; -import jakarta.json.JsonObjectBuilder; -import lombok.RequiredArgsConstructor; -import lombok.SneakyThrows; -import org.jetbrains.annotations.Nullable; - -import java.util.List; - -import static de.sovity.edc.ext.wrapper.api.common.mappers.utils.JsonBuilderUtils.addNonNull; -import static de.sovity.edc.ext.wrapper.api.common.mappers.utils.JsonBuilderUtils.addNonNullArray; - -@RequiredArgsConstructor -public class UiAssetBuilder { - private final ObjectMapper mapper = new ObjectMapper(); - private final EdcPropertyMapperUtils edcPropertyMapperUtils; - - public UiAsset buildUiAsset(JsonObject assetJsonLd) { - var assetJsonLdObj = parseAssetJsonLd(JsonUtils.toJson(assetJsonLd)); - return buildUiAsset(assetJsonLdObj); - } - - private UiAsset buildUiAsset(AssetJsonLd assetJsonLd) { - var assetPropertyJsonLd = assetJsonLd.getProperties(); - - return UiAsset.builder() - .assetId(assetPropertyJsonLd.getAssetId()) - .keywords(assetPropertyJsonLd.getKeywords() == null ? List.of() : assetPropertyJsonLd.getKeywords()) - .version(assetPropertyJsonLd.getVersion()) - .licenseUrl(assetPropertyJsonLd.getLicense()) - .creatorOrganizationName(assetPropertyJsonLd.getCreator() != null ? assetPropertyJsonLd.getCreator().getName() : null) - .publisherHomepage(assetPropertyJsonLd.getPublisher() != null ? assetPropertyJsonLd.getPublisher().getName() : null) - .description(assetPropertyJsonLd.getDescription()) - .language(assetPropertyJsonLd.getLanguage()) - .name(assetPropertyJsonLd.getName()) - .httpDatasourceHintsProxyMethod(assetPropertyJsonLd.getHttpDatasourceHintsProxyMethod()) - .httpDatasourceHintsProxyPath(assetPropertyJsonLd.getHttpDatasourceHintsProxyPath()) - .httpDatasourceHintsProxyQueryParams(assetPropertyJsonLd.getHttpDatasourceHintsProxyQueryParams()) - .httpDatasourceHintsProxyBody(assetPropertyJsonLd.getHttpDatasourceHintsProxyBody()) - .dataCategory(assetPropertyJsonLd.getDataCategory()) - .dataSubcategory(assetPropertyJsonLd.getDataSubcategory()) - .dataModel(assetPropertyJsonLd.getDataModel()) - .geoReferenceMethod(assetPropertyJsonLd.getGeoReferenceMethod()) - .transportMode(assetPropertyJsonLd.getTransportMode()) - .landingPageUrl(assetPropertyJsonLd.getLandingPage()) - .mediaType(assetPropertyJsonLd.getMediaType()) - .build(); - } - - @SneakyThrows - private AssetJsonLd parseAssetJsonLd(String assetJsonLd) { - var assetPropertiesJsonLd = mapper.readTree(assetJsonLd).get(Prop.Edc.PROPERTIES); - var assetProperties = mapper.readValue(assetPropertiesJsonLd.toString(), AssetPropertyJsonLd.class); - - return AssetJsonLd.builder() - .assetId(String.valueOf(mapper.readTree(assetJsonLd).get(Prop.ID))) - .properties(assetProperties) - .build(); - } - - @SneakyThrows - @Nullable - public JsonObject buildAssetJsonLd(UiAssetCreateRequest uiAssetCreateRequest) { - var properties = getAssetProperties(uiAssetCreateRequest); - var dataAddress = getDataAddress(uiAssetCreateRequest); - - return Json.createObjectBuilder() - .add(Prop.ID, uiAssetCreateRequest.getId()) - .add(Prop.TYPE, Prop.Edc.TYPE_ASSET) - .add(Prop.Edc.PROPERTIES, Json.createArrayBuilder().add(properties)) - .add(Prop.Edc.DATA_ADDRESS, Json.createArrayBuilder().add(dataAddress)) - .build(); - } - - private JsonObjectBuilder getAssetProperties(UiAssetCreateRequest uiAssetCreateRequest) { - var properties = Json.createObjectBuilder(); - - addNonNull(properties, Prop.Edc.ID, uiAssetCreateRequest.getId()); - addNonNull(properties, Prop.Dcterms.LICENSE, uiAssetCreateRequest.getLicenseUrl()); - addNonNull(properties, Prop.Dcterms.NAME, uiAssetCreateRequest.getName()); - addNonNull(properties, Prop.Dcterms.DESCRIPTION, uiAssetCreateRequest.getDescription()); - addNonNull(properties, Prop.Dcterms.LANGUAGE, uiAssetCreateRequest.getLanguage()); - addNonNull(properties, Prop.Dcat.VERSION, uiAssetCreateRequest.getVersion()); - addNonNull(properties, Prop.Dcat.MEDIATYPE, uiAssetCreateRequest.getMediaType()); - addNonNull(properties, Prop.Dcat.LANDING_PAGE, uiAssetCreateRequest.getLandingPageUrl()); - addNonNull(properties, Prop.Mds.DATA_CATEGORY, uiAssetCreateRequest.getDataCategory()); - addNonNull(properties, Prop.Mds.DATA_SUBCATEGORY, uiAssetCreateRequest.getDataSubcategory()); - addNonNull(properties, Prop.Mds.DATA_MODEL, uiAssetCreateRequest.getDataModel()); - addNonNull(properties, Prop.Mds.GEO_REFERENCE_METHOD, uiAssetCreateRequest.getGeoReferenceMethod()); - addNonNull(properties, Prop.Mds.TRANSPORT_MODE, uiAssetCreateRequest.getTransportMode()); - addNonNullArray(properties, Prop.Dcat.KEYWORDS, uiAssetCreateRequest.getKeywords()); - - return properties; - } - - private JsonObjectBuilder getDataAddress(UiAssetCreateRequest uiAssetCreateRequest) { - var props = edcPropertyMapperUtils.toMapOfObject(uiAssetCreateRequest.getDataAddressProperties()); - return Json.createObjectBuilder() - .add(Prop.TYPE, Prop.Edc.TYPE_DATA_ADDRESS) - .add(Prop.Edc.PROPERTIES, Json.createArrayBuilder().add(Json.createObjectBuilder(props))); - } -} diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetMapper.java new file mode 100644 index 000000000..f12760252 --- /dev/null +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetMapper.java @@ -0,0 +1,130 @@ +package de.sovity.edc.ext.wrapper.api.common.mappers.utils; + +import de.sovity.edc.ext.wrapper.api.common.model.UiAsset; +import de.sovity.edc.ext.wrapper.api.common.model.UiAssetCreateRequest; +import de.sovity.edc.utils.JsonUtils; +import de.sovity.edc.utils.jsonld.JsonLdUtils; +import de.sovity.edc.utils.jsonld.vocab.Prop; +import de.sovity.edc.utils.jsonld.vocab.Prop.SovityDcatExt.HttpDatasourceHints; +import jakarta.json.Json; +import jakarta.json.JsonObject; +import jakarta.json.JsonObjectBuilder; +import lombok.RequiredArgsConstructor; +import lombok.SneakyThrows; +import org.eclipse.edc.jsonld.spi.JsonLd; +import org.jetbrains.annotations.Nullable; + +import java.util.Map; + +import static de.sovity.edc.ext.wrapper.api.common.mappers.utils.JsonBuilderUtils.addNonNull; +import static de.sovity.edc.ext.wrapper.api.common.mappers.utils.JsonBuilderUtils.addNonNullArray; + +@RequiredArgsConstructor +public class UiAssetMapper { + private final EdcPropertyMapperUtils edcPropertyMapperUtils; + private final JsonLd jsonLd; + + public UiAsset buildUiAsset(JsonObject assetJsonLd) { + var properties = JsonLdUtils.object(assetJsonLd, Prop.Edc.PROPERTIES); + + var uiAsset = new UiAsset(); + uiAsset.setAssetJsonLd(buildCompactAssetJsonLd(assetJsonLd)); + + uiAsset.setAssetId(JsonLdUtils.string(assetJsonLd, Prop.ID)); + uiAsset.setLicenseUrl(JsonLdUtils.string(properties, Prop.Dcterms.LICENSE)); + uiAsset.setName(JsonLdUtils.string(properties, Prop.Dcterms.NAME)); + uiAsset.setDescription(JsonLdUtils.string(properties, Prop.Dcterms.DESCRIPTION)); + uiAsset.setLanguage(JsonLdUtils.string(properties, Prop.Dcterms.LANGUAGE)); + uiAsset.setVersion(JsonLdUtils.string(properties, Prop.Dcat.VERSION)); + uiAsset.setMediaType(JsonLdUtils.string(properties, Prop.Dcat.MEDIATYPE)); + uiAsset.setLandingPageUrl(JsonLdUtils.string(properties, Prop.Dcat.LANDING_PAGE)); + uiAsset.setDataCategory(JsonLdUtils.string(properties, Prop.Mds.DATA_CATEGORY)); + uiAsset.setDataSubcategory(JsonLdUtils.string(properties, Prop.Mds.DATA_SUBCATEGORY)); + uiAsset.setDataModel(JsonLdUtils.string(properties, Prop.Mds.DATA_MODEL)); + uiAsset.setGeoReferenceMethod(JsonLdUtils.string(properties, Prop.Mds.GEO_REFERENCE_METHOD)); + uiAsset.setTransportMode(JsonLdUtils.string(properties, Prop.Mds.TRANSPORT_MODE)); + uiAsset.setKeywords(JsonLdUtils.stringList(properties, Prop.Dcat.KEYWORDS)); + + uiAsset.setHttpDatasourceHintsProxyMethod(JsonLdUtils.bool(properties, HttpDatasourceHints.METHOD)); + uiAsset.setHttpDatasourceHintsProxyPath(JsonLdUtils.bool(properties, HttpDatasourceHints.PATH)); + uiAsset.setHttpDatasourceHintsProxyQueryParams(JsonLdUtils.bool(properties, HttpDatasourceHints.QUERY_PARAMS)); + uiAsset.setHttpDatasourceHintsProxyBody(JsonLdUtils.bool(properties, HttpDatasourceHints.BODY)); + + var publisher = JsonLdUtils.object(properties, Prop.Dcterms.PUBLISHER); + uiAsset.setPublisherHomepage(JsonLdUtils.string(publisher, Prop.Foaf.HOMEPAGE)); + + var creator = JsonLdUtils.object(properties, Prop.Dcterms.CREATOR); + uiAsset.setCreatorOrganizationName(JsonLdUtils.string(creator, Prop.Foaf.NAME)); + + return uiAsset; + } + + private String buildCompactAssetJsonLd(JsonObject assetJsonLd) { + var compacted = jsonLd.compact(assetJsonLd).orElseThrow(FailedMappingException::ofFailure); + return JsonUtils.toJson(compacted); + } + + @SneakyThrows + @Nullable + public JsonObject buildAssetJsonLd(UiAssetCreateRequest uiAssetCreateRequest) { + var properties = getAssetProperties(uiAssetCreateRequest); + var dataAddress = getDataAddress(uiAssetCreateRequest); + + return Json.createObjectBuilder() + .add(Prop.ID, uiAssetCreateRequest.getId()) + .add(Prop.TYPE, Prop.Edc.TYPE_ASSET) + .add(Prop.Edc.PROPERTIES, properties) + .add(Prop.Edc.DATA_ADDRESS, dataAddress) + .build(); + } + + private JsonObjectBuilder getAssetProperties(UiAssetCreateRequest uiAssetCreateRequest) { + var properties = Json.createObjectBuilder(); + + addNonNull(properties, Prop.Edc.ID, uiAssetCreateRequest.getId()); + addNonNull(properties, Prop.Dcterms.LICENSE, uiAssetCreateRequest.getLicenseUrl()); + addNonNull(properties, Prop.Dcterms.NAME, uiAssetCreateRequest.getName()); + addNonNull(properties, Prop.Dcterms.DESCRIPTION, uiAssetCreateRequest.getDescription()); + addNonNull(properties, Prop.Dcterms.LANGUAGE, uiAssetCreateRequest.getLanguage()); + addNonNull(properties, Prop.Dcat.VERSION, uiAssetCreateRequest.getVersion()); + addNonNull(properties, Prop.Dcat.MEDIATYPE, uiAssetCreateRequest.getMediaType()); + addNonNull(properties, Prop.Dcat.LANDING_PAGE, uiAssetCreateRequest.getLandingPageUrl()); + addNonNull(properties, Prop.Mds.DATA_CATEGORY, uiAssetCreateRequest.getDataCategory()); + addNonNull(properties, Prop.Mds.DATA_SUBCATEGORY, uiAssetCreateRequest.getDataSubcategory()); + addNonNull(properties, Prop.Mds.DATA_MODEL, uiAssetCreateRequest.getDataModel()); + addNonNull(properties, Prop.Mds.GEO_REFERENCE_METHOD, uiAssetCreateRequest.getGeoReferenceMethod()); + addNonNull(properties, Prop.Mds.TRANSPORT_MODE, uiAssetCreateRequest.getTransportMode()); + addNonNullArray(properties, Prop.Dcat.KEYWORDS, uiAssetCreateRequest.getKeywords()); + + if (uiAssetCreateRequest.getPublisherHomepage() != null) { + properties.add(Prop.Dcterms.PUBLISHER, Json.createObjectBuilder() + .add(Prop.Foaf.HOMEPAGE, uiAssetCreateRequest.getPublisherHomepage())); + } + + if (uiAssetCreateRequest.getCreatorOrganizationName() != null) { + properties.add(Prop.Dcterms.CREATOR, Json.createObjectBuilder() + .add(Prop.Foaf.NAME, uiAssetCreateRequest.getCreatorOrganizationName())); + } + + var dataAddress = uiAssetCreateRequest.getDataAddressProperties(); + if (dataAddress.get(Prop.Edc.TYPE).equals("HttpData")) { + addNonNull(properties, HttpDatasourceHints.BODY, trueIfTrue(dataAddress, Prop.Edc.PROXY_BODY)); + addNonNull(properties, HttpDatasourceHints.PATH, trueIfTrue(dataAddress, Prop.Edc.PROXY_PATH)); + addNonNull(properties, HttpDatasourceHints.QUERY_PARAMS, trueIfTrue(dataAddress, Prop.Edc.PROXY_QUERY_PARAMS)); + addNonNull(properties, HttpDatasourceHints.METHOD, trueIfTrue(dataAddress, Prop.Edc.PROXY_METHOD)); + } + + return properties; + } + + private String trueIfTrue(Map dataAddressProperties, String key) { + return "true".equals(dataAddressProperties.get(key)) ? "true" : "false"; + } + + private JsonObjectBuilder getDataAddress(UiAssetCreateRequest uiAssetCreateRequest) { + var props = edcPropertyMapperUtils.toMapOfObject(uiAssetCreateRequest.getDataAddressProperties()); + return Json.createObjectBuilder() + .add(Prop.TYPE, Prop.Edc.TYPE_DATA_ADDRESS) + .add(Prop.Edc.PROPERTIES, Json.createObjectBuilder(props)); + } +} diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java index 129cfa39d..f4cd357eb 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java @@ -1,10 +1,12 @@ package de.sovity.edc.ext.wrapper.api.common.mappers; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.UiAssetBuilder; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.UiAssetMapper; import de.sovity.edc.utils.JsonUtils; import de.sovity.edc.utils.jsonld.vocab.Prop; import lombok.SneakyThrows; +import org.eclipse.edc.jsonld.TitaniumJsonLd; +import org.eclipse.edc.spi.monitor.Monitor; import org.eclipse.edc.transform.spi.TypeTransformerRegistry; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -23,9 +25,10 @@ class AssetMapperTest { @BeforeEach void setup() { + var jsonLd = new TitaniumJsonLd(mock(Monitor.class)); var typeTransformerRegistry = mock(TypeTransformerRegistry.class); - var uiAssetBuilder = new UiAssetBuilder(new EdcPropertyMapperUtils()); - assetMapper = new AssetMapper(typeTransformerRegistry, uiAssetBuilder); + var uiAssetBuilder = new UiAssetMapper(new EdcPropertyMapperUtils(), jsonLd); + assetMapper = new AssetMapper(typeTransformerRegistry, uiAssetBuilder, jsonLd); } @Test @@ -58,6 +61,7 @@ void test_buildAssetDto() { assertThat(uiAsset.getDataModel()).isEqualTo("my-data-model-001"); assertThat(uiAsset.getGeoReferenceMethod()).isEqualTo("my-geo-reference-method"); assertThat(uiAsset.getTransportMode()).isEqualTo("my-geo-reference-method"); + assertThat(uiAsset.getAssetJsonLd()).contains("\"%s\"".formatted(Prop.Edc.ID)); } @Test @@ -89,7 +93,7 @@ void test_StringValueWrappedInAtValue() { .add(Prop.Edc.PROPERTIES, createObjectBuilder() .add(Prop.Dcterms.NAME, createObjectBuilder() .add(Prop.VALUE, "AssetName") - .add(Prop.Dcterms.LANGUAGE, "en"))) + .add(Prop.LANGUAGE, "en"))) .build(); // Act @@ -133,7 +137,7 @@ void test_badBooleanValue() { var assetJsonLd = createObjectBuilder() .add(Prop.ID, "my-asset-1") .add(Prop.Edc.PROPERTIES, createObjectBuilder() - .add(Prop.SovityDcatExt.METHOD, "wrongBooleanValue") + .add(Prop.SovityDcatExt.HttpDatasourceHints.METHOD, "wrongBooleanValue") .build()) .build(); @@ -152,7 +156,7 @@ void test_noBooleanValue() { var assetJsonLd = createObjectBuilder() .add(Prop.ID, "my-asset-1") .add(Prop.Edc.PROPERTIES, createObjectBuilder() - .add(Prop.SovityDcatExt.METHOD, "") + .add(Prop.SovityDcatExt.HttpDatasourceHints.METHOD, "") .build()) .build(); diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java index 12745360a..b4e7960dc 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java @@ -23,7 +23,7 @@ import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.LiteralMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.PolicyValidator; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.UiAssetBuilder; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.UiAssetMapper; import de.sovity.edc.ext.wrapper.api.ui.UiResource; import de.sovity.edc.ext.wrapper.api.ui.pages.asset.AssetApiService; import de.sovity.edc.ext.wrapper.api.ui.pages.catalog.CatalogApiService; @@ -120,8 +120,8 @@ public static WrapperExtensionContext buildContext( atomicConstraintMapper, typeTransformerRegistry); var edcPropertyMapperUtils = new EdcPropertyMapperUtils(); - var assetBuilder = new UiAssetBuilder(edcPropertyMapperUtils); - var assetMapper = new AssetMapper(typeTransformerRegistry, assetBuilder); + var assetBuilder = new UiAssetMapper(edcPropertyMapperUtils, jsonLd); + var assetMapper = new AssetMapper(typeTransformerRegistry, assetBuilder, jsonLd); var transferProcessStateService = new TransferProcessStateService(); var contractAgreementPageCardBuilder = new ContractAgreementPageCardBuilder( policyMapper, diff --git a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/JsonUtils.java b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/JsonUtils.java index 26a8258e5..3c011ce2d 100644 --- a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/JsonUtils.java +++ b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/JsonUtils.java @@ -32,6 +32,10 @@ public static JsonObject parseJsonObj(String string) { } public static String toJson(JsonValue json) { + if (json == null) { + return "null"; + } + var sw = new StringWriter(); try (var writer = Json.createWriter(sw)) { writer.write(json); diff --git a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/JsonLdUtils.java b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/JsonLdUtils.java index 0ff22fab9..7b6169c94 100644 --- a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/JsonLdUtils.java +++ b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/JsonLdUtils.java @@ -13,6 +13,7 @@ package de.sovity.edc.utils.jsonld; +import de.sovity.edc.utils.JsonUtils; import jakarta.json.JsonNumber; import jakarta.json.JsonObject; import jakarta.json.JsonString; @@ -48,13 +49,37 @@ public static String string(JsonValue json) { } return switch (value.getValueType()) { - case ARRAY -> throw new IllegalStateException("unexpected array" + value); - case OBJECT -> throw new IllegalStateException("unexpected object" + value); case STRING -> ((JsonString) value).getString(); case NUMBER -> ((JsonNumber) value).bigDecimalValue().toString(); case FALSE -> "false"; case TRUE -> "true"; case NULL -> null; + // We do this over throwing errors because we want to be able to handle invalid json-ld + case ARRAY, OBJECT -> JsonUtils.toJson(value); + }; + } + + /** + * Get a boolean property + * + * @param json json-ld + * @return boolean value or null + */ + public static Boolean bool(JsonValue json) { + var value = value(json); + if (value == null) { + return null; + } + + return switch (value.getValueType()) { + case STRING -> switch (((JsonString) value).getString().toLowerCase()) { + case "true" -> Boolean.TRUE; + case "false" -> Boolean.FALSE; + default -> null; + }; + case FALSE -> Boolean.FALSE; + case TRUE -> Boolean.TRUE; + case NUMBER, NULL, ARRAY, OBJECT -> null; }; } @@ -128,6 +153,27 @@ public static String string(JsonObject object, String key) { return string(field); } + /** + * Get an object property. Defaults to an empty object for ease of use if not found. + * + * @param object json-ld + * @param key key + * @return string or null + */ + public static JsonObject object(JsonObject object, String key) { + JsonValue field = object.get(key); + if (field == null) { + return JsonValue.EMPTY_JSON_OBJECT; + } + + var unwrapped = value(field); + if (unwrapped == null || unwrapped.getValueType() != JsonValue.ValueType.OBJECT) { + return JsonValue.EMPTY_JSON_OBJECT; + } + + return (JsonObject) unwrapped; + } + /** * Get a list property while unwrapping values and only keeping objects. * @@ -142,4 +188,36 @@ public static List listOfObjects(JsonObject object, String key) { } return listOfObjects(field); } + + /** + * Get a list of strings. defaults to empty list + * + * @param object json-ld + * @param key key + * @return string list or empty list + */ + public static List stringList(JsonObject object, String key) { + JsonValue field = object.get(key); + if (field == null) { + return List.of(); + } + return list(field).stream() + .map(JsonLdUtils::string) + .toList(); + } + + /** + * Get a boolean property. defaults to null + * + * @param object json-ld + * @param key key + * @return boolean or null + */ + public static Boolean bool(JsonObject object, String key) { + JsonValue field = object.get(key); + if (field == null) { + return null; + } + return bool(field); + } } diff --git a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java index 8ddd67a4e..c254c02de 100644 --- a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java +++ b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java @@ -20,6 +20,7 @@ public class Prop { public final String ID = "@id"; public final String TYPE = "@type"; public final String VALUE = "@value"; + public final String CONTEXT = "@context"; public final String LANGUAGE = "@language"; public final String PROPERTIES = "properties"; @@ -34,6 +35,10 @@ public class Edc { public final String DATA_ADDRESS = CTX + "dataAddress"; public final String TYPE = CTX + "type"; public final String BASE_URL = CTX + "baseUrl"; + public final String PROXY_METHOD = CTX + "proxyMethod"; + public final String PROXY_PATH = CTX + "proxyPath"; + public final String PROXY_QUERY_PARAMS = CTX + "proxyQueryParams"; + public final String PROXY_BODY = CTX + "proxyBody"; } /** @@ -89,10 +94,14 @@ public class Dcterms { @UtilityClass public class SovityDcatExt { public final String CTX = "https://semantic.sovity.io/dcat-ext#"; - public final String METHOD = CTX + "httpDatasourceHintsProxyMethod"; - public final String PATH = CTX + "httpDatasourceHintsProxyPath"; - public final String QUERY_PARAMS = CTX + "httpDatasourceHintsProxyQueryParams"; - public final String BODY = CTX + "httpDatasourceHintsProxyBody"; + + @UtilityClass + public class HttpDatasourceHints { + public final String METHOD = CTX + "httpDatasourceHintsProxyMethod"; + public final String PATH = CTX + "httpDatasourceHintsProxyPath"; + public final String QUERY_PARAMS = CTX + "httpDatasourceHintsProxyQueryParams"; + public final String BODY = CTX + "httpDatasourceHintsProxyBody"; + } } /** From a72cd04c6af747a84d8902686f1348d56e5730b4 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Tue, 19 Sep 2023 12:44:29 +0200 Subject: [PATCH 35/37] docs: fix wording --- .../de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java index 0b3979285..1b2194583 100644 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java +++ b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/UiAsset.java @@ -107,6 +107,6 @@ public class UiAsset { @Schema(description = "Private Asset Properties (that were not strings but other JSON values)", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private Map privateJsonProperties; - @Schema(description = "Contains the entire asset in its original expanded JSON-LD format", requiredMode = Schema.RequiredMode.NOT_REQUIRED) + @Schema(description = "Contains the entire asset in the JSON-LD format", requiredMode = Schema.RequiredMode.NOT_REQUIRED) private String assetJsonLd; } From c92359f4c9f9f56db82eedd135b921986221acfd Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Tue, 19 Sep 2023 12:59:59 +0200 Subject: [PATCH 36/37] chore: improve code quality --- .../edc/client/AssetApiServiceTest.java | 6 +- .../model/utils/CustomDeserializer.java | 100 ------------------ .../AssetCreatorOrganizationNameJsonLd.java | 24 ----- ...MapperUtils.java => EdcPropertyUtils.java} | 9 +- .../common/mappers/utils/UiAssetMapper.java | 4 +- .../api/common/mappers/AssetMapperTest.java | 4 +- ...ilsTest.java => EdcPropertyUtilsTest.java} | 7 +- .../WrapperExtensionContextBuilder.java | 10 +- .../services/TransferRequestBuilder.java | 7 +- .../api/usecase/services/OfferingService.java | 4 +- .../usecase/services/OfferingServiceTest.java | 4 +- .../edc/ext/wrapper/utils/MapUtilsTest.java | 40 +++++++ .../de/sovity/edc/e2e/UiApiWrapperTest.java | 31 ++++++ .../sovity/edc/utils/jsonld/vocab/Prop.java | 1 + 14 files changed, 102 insertions(+), 149 deletions(-) delete mode 100644 extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java delete mode 100644 extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetCreatorOrganizationNameJsonLd.java rename extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/{EdcPropertyMapperUtils.java => EdcPropertyUtils.java} (92%) rename extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/{EdcPropertyMapperUtilsTest.java => EdcPropertyUtilsTest.java} (86%) create mode 100644 extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/utils/MapUtilsTest.java diff --git a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java index a2db9a5fb..d568ea527 100644 --- a/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java +++ b/extensions/wrapper/client/src/test/java/de/sovity/edc/client/AssetApiServiceTest.java @@ -16,7 +16,7 @@ import de.sovity.edc.client.gen.model.UiAsset; import de.sovity.edc.client.gen.model.UiAssetCreateRequest; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyUtils; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.FailedMappingException; import de.sovity.edc.utils.jsonld.vocab.Prop; import lombok.SneakyThrows; @@ -41,12 +41,12 @@ public class AssetApiServiceTest { public static final String DATA_SINK = "http://my-data-sink/api/stuff"; - EdcPropertyMapperUtils edcPropertyUtils; + EdcPropertyUtils edcPropertyUtils; @BeforeEach void setUp(EdcExtension extension) { TestUtils.setupExtension(extension); - edcPropertyUtils = new EdcPropertyMapperUtils(); + edcPropertyUtils = new EdcPropertyUtils(); } @Test diff --git a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java b/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java deleted file mode 100644 index faaf12e51..000000000 --- a/extensions/wrapper/wrapper-common-api/src/main/java/de/sovity/edc/ext/wrapper/api/common/model/utils/CustomDeserializer.java +++ /dev/null @@ -1,100 +0,0 @@ -package de.sovity.edc.ext.wrapper.api.common.model.utils; - -import com.fasterxml.jackson.core.JsonParser; -import com.fasterxml.jackson.databind.BeanProperty; -import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JavaType; -import com.fasterxml.jackson.databind.JsonDeserializer; -import com.fasterxml.jackson.databind.JsonMappingException; -import com.fasterxml.jackson.databind.deser.ContextualDeserializer; -import lombok.AllArgsConstructor; -import lombok.NoArgsConstructor; -import lombok.SneakyThrows; - -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.List; - -@NoArgsConstructor -@AllArgsConstructor -public class CustomDeserializer extends JsonDeserializer implements ContextualDeserializer { - - private JavaType type; - - @Override - public JsonDeserializer createContextual(DeserializationContext deserializationContext, BeanProperty beanProperty) throws JsonMappingException { - JavaType type = deserializationContext.getContextualType() != null - ? deserializationContext.getContextualType() - : beanProperty.getMember().getType(); - return new CustomDeserializer(type); - } - - @SneakyThrows - @Override - public Object deserialize(JsonParser p, DeserializationContext deserializationContext) { - if (type.isTypeOrSubTypeOf(String.class)) { - return parseString(p); - } else if (type.isTypeOrSubTypeOf(Boolean.class)) { - return parseBoolean(p); - } else if (type.isTypeOrSubTypeOf(List.class)) { - return parseList(p); - } - return p.readValueAs(Object.class); - } - - @SneakyThrows - private String parseString(JsonParser p) { - if (p.isExpectedStartArrayToken()) { - return getFirstValueFromList(p.readValueAs(List.class)); - } else if (p.isExpectedStartObjectToken()) { - return extractValueFromMap(p.readValueAs(LinkedHashMap.class)); - } - return p.getText(); - } - - @SneakyThrows - private Boolean parseBoolean(JsonParser p) { - String valueAsString = p.isExpectedStartArrayToken() ? getFirstValueFromList(p.readValueAs(List.class)) : p.getText(); - if ("true".equalsIgnoreCase(valueAsString)) { - return true; - } else if ("false".equalsIgnoreCase(valueAsString)) { - return false; - } - return null; - } - - @SneakyThrows - private List parseList(JsonParser p) { - if (p.isExpectedStartArrayToken()) { - return p.readValueAs(List.class); - } - return Collections.singletonList(p.getText()); - } - - private String getFirstValueFromList(List list) { - if (list.isEmpty()) { - return null; - } - Object firstItem = list.get(0); - if (firstItem instanceof List) { - return getFirstValueFromList((List) firstItem); - } else if (firstItem instanceof LinkedHashMap) { - return extractValueFromMap((LinkedHashMap) firstItem); - } - return firstItem.toString(); - } - - @SneakyThrows - private String extractValueFromMap(LinkedHashMap map) { - Object valueObject = map.get("@value"); - - if (valueObject instanceof List) { - return getFirstValueFromList((List) valueObject); - - } else if (valueObject instanceof LinkedHashMap) { - return extractValueFromMap((LinkedHashMap) valueObject); - } - - return valueObject.toString(); - } -} diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetCreatorOrganizationNameJsonLd.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetCreatorOrganizationNameJsonLd.java deleted file mode 100644 index afdfa20d0..000000000 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/AssetCreatorOrganizationNameJsonLd.java +++ /dev/null @@ -1,24 +0,0 @@ -package de.sovity.edc.ext.wrapper.api.common.mappers.utils; - -import com.fasterxml.jackson.annotation.JsonProperty; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Getter; -import lombok.RequiredArgsConstructor; -import lombok.Setter; -import lombok.ToString; - - -@Getter -@Setter -@ToString -@AllArgsConstructor -@Builder(toBuilder = true) -@RequiredArgsConstructor -public class AssetCreatorOrganizationNameJsonLd { - @JsonProperty("@type") - private String type; - - @JsonProperty("http://xmlns.com/foaf/0.1/name") - private String name; -} diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtils.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyUtils.java similarity index 92% rename from extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtils.java rename to extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyUtils.java index 3096d8db5..5af531863 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtils.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyUtils.java @@ -20,7 +20,7 @@ import java.util.Map; @RequiredArgsConstructor -public class EdcPropertyMapperUtils { +public class EdcPropertyUtils { /** * Converts a {@code Map} to {@code Map}. @@ -34,6 +34,10 @@ public class EdcPropertyMapperUtils { public Map truncateToMapOfString(Map map) { Map result = new HashMap<>(); + if (map == null) { + return result; + } + for (Map.Entry entry : map.entrySet()) { Object value = entry.getValue(); @@ -57,6 +61,9 @@ public Map truncateToMapOfString(Map map) { @SuppressWarnings({"unchecked", "rawtypes", "java:S1905"}) public Map toMapOfObject(Map map) { + if (map == null) { + return Map.of(); + } return new HashMap<>((Map) (Map) map); } diff --git a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetMapper.java b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetMapper.java index f12760252..4ed2139b8 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetMapper.java +++ b/extensions/wrapper/wrapper-common-mappers/src/main/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/UiAssetMapper.java @@ -21,7 +21,7 @@ @RequiredArgsConstructor public class UiAssetMapper { - private final EdcPropertyMapperUtils edcPropertyMapperUtils; + private final EdcPropertyUtils edcPropertyUtils; private final JsonLd jsonLd; public UiAsset buildUiAsset(JsonObject assetJsonLd) { @@ -122,7 +122,7 @@ private String trueIfTrue(Map dataAddressProperties, String key) } private JsonObjectBuilder getDataAddress(UiAssetCreateRequest uiAssetCreateRequest) { - var props = edcPropertyMapperUtils.toMapOfObject(uiAssetCreateRequest.getDataAddressProperties()); + var props = edcPropertyUtils.toMapOfObject(uiAssetCreateRequest.getDataAddressProperties()); return Json.createObjectBuilder() .add(Prop.TYPE, Prop.Edc.TYPE_DATA_ADDRESS) .add(Prop.Edc.PROPERTIES, Json.createObjectBuilder(props)); diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java index f4cd357eb..a3e97226f 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/AssetMapperTest.java @@ -1,6 +1,6 @@ package de.sovity.edc.ext.wrapper.api.common.mappers; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyUtils; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.UiAssetMapper; import de.sovity.edc.utils.JsonUtils; import de.sovity.edc.utils.jsonld.vocab.Prop; @@ -27,7 +27,7 @@ class AssetMapperTest { void setup() { var jsonLd = new TitaniumJsonLd(mock(Monitor.class)); var typeTransformerRegistry = mock(TypeTransformerRegistry.class); - var uiAssetBuilder = new UiAssetMapper(new EdcPropertyMapperUtils(), jsonLd); + var uiAssetBuilder = new UiAssetMapper(new EdcPropertyUtils(), jsonLd); assetMapper = new AssetMapper(typeTransformerRegistry, uiAssetBuilder, jsonLd); } diff --git a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtilsTest.java b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyUtilsTest.java similarity index 86% rename from extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtilsTest.java rename to extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyUtilsTest.java index a72d91b24..d95246d45 100644 --- a/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyMapperUtilsTest.java +++ b/extensions/wrapper/wrapper-common-mappers/src/test/java/de/sovity/edc/ext/wrapper/api/common/mappers/utils/EdcPropertyUtilsTest.java @@ -14,7 +14,6 @@ package de.sovity.edc.ext.wrapper.api.common.mappers.utils; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -23,12 +22,12 @@ import static org.assertj.core.api.Assertions.assertThat; -class EdcPropertyMapperUtilsTest { - EdcPropertyMapperUtils edcPropertyUtils; +class EdcPropertyUtilsTest { + EdcPropertyUtils edcPropertyUtils; @BeforeEach void setup() { - edcPropertyUtils = new EdcPropertyMapperUtils(); + edcPropertyUtils = new EdcPropertyUtils(); } @Test diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java index b4e7960dc..d58598873 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/WrapperExtensionContextBuilder.java @@ -20,7 +20,7 @@ import de.sovity.edc.ext.wrapper.api.common.mappers.PolicyMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.AtomicConstraintMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.ConstraintExtractor; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyUtils; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.LiteralMapper; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.PolicyValidator; import de.sovity.edc.ext.wrapper.api.common.mappers.utils.UiAssetMapper; @@ -119,8 +119,8 @@ public static WrapperExtensionContext buildContext( constraintExtractor, atomicConstraintMapper, typeTransformerRegistry); - var edcPropertyMapperUtils = new EdcPropertyMapperUtils(); - var assetBuilder = new UiAssetMapper(edcPropertyMapperUtils, jsonLd); + var edcPropertyUtils = new EdcPropertyUtils(); + var assetBuilder = new UiAssetMapper(edcPropertyUtils, jsonLd); var assetMapper = new AssetMapper(typeTransformerRegistry, assetBuilder, jsonLd); var transferProcessStateService = new TransferProcessStateService(); var contractAgreementPageCardBuilder = new ContractAgreementPageCardBuilder( @@ -159,7 +159,7 @@ public static WrapperExtensionContext buildContext( objectMapper, contractAgreementUtils, contractNegotiationUtils, - edcPropertyMapperUtils, + edcPropertyUtils, serviceExtensionContext.getConnectorId() ); var contractAgreementTransferApiService = new ContractAgreementTransferApiService( @@ -203,7 +203,7 @@ public static WrapperExtensionContext buildContext( policyDefinitionStore, contractDefinitionStore, policyMappingService, - edcPropertyMapperUtils); + edcPropertyUtils); var useCaseResource = new UseCaseResource( kpiApiService, supportedPolicyApiService, diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/TransferRequestBuilder.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/TransferRequestBuilder.java index 7db69b67e..ea093aa91 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/TransferRequestBuilder.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/ui/pages/contracts/services/TransferRequestBuilder.java @@ -15,7 +15,7 @@ package de.sovity.edc.ext.wrapper.api.ui.pages.contracts.services; import com.fasterxml.jackson.databind.ObjectMapper; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyUtils; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementTransferRequest; import de.sovity.edc.ext.wrapper.api.ui.model.ContractAgreementTransferRequestParams; import lombok.RequiredArgsConstructor; @@ -24,7 +24,6 @@ import org.eclipse.edc.protocol.dsp.spi.types.HttpMessageProtocol; import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.UUID; @@ -34,7 +33,7 @@ public class TransferRequestBuilder { private final ObjectMapper objectMapper; private final ContractAgreementUtils contractAgreementUtils; private final ContractNegotiationUtils contractNegotiationUtils; - private final EdcPropertyMapperUtils edcPropertyUtils; + private final EdcPropertyUtils edcPropertyUtils; private final String connectorId; public TransferRequest buildTransferRequest( @@ -63,7 +62,7 @@ private TransferRequest buildTransferRequest( .contractId(contractId) .assetId(agreement.getAssetId()) .dataDestination(address) - .privateProperties(edcPropertyUtils.toMapOfObject(params.getTransferProcessProperties() == null ? Map.of() : params.getTransferProcessProperties())) + .privateProperties(edcPropertyUtils.toMapOfObject(params.getTransferProcessProperties())) .callbackAddresses(List.of()) .build(); } diff --git a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingService.java b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingService.java index 0354ce64b..ad2f96c22 100644 --- a/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingService.java +++ b/extensions/wrapper/wrapper/src/main/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingService.java @@ -1,6 +1,6 @@ package de.sovity.edc.ext.wrapper.api.usecase.services; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyUtils; import de.sovity.edc.ext.wrapper.api.usecase.model.AssetEntryDto; import de.sovity.edc.ext.wrapper.api.usecase.model.ContractDefinitionRequestDto; import de.sovity.edc.ext.wrapper.api.usecase.model.CreateOfferingDto; @@ -31,7 +31,7 @@ public class OfferingService { private final PolicyDefinitionStore policyDefinitionStore; private final ContractDefinitionStore contractDefinitionStore; private final PolicyMappingService policyMappingService; - private final EdcPropertyMapperUtils edcPropertyUtils; + private final EdcPropertyUtils edcPropertyUtils; /** * Creates the asset, policy and contract definition in the connector. First, transforms the diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingServiceTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingServiceTest.java index 90fe91948..8bd1dbbfc 100644 --- a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingServiceTest.java +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/api/usecase/services/OfferingServiceTest.java @@ -1,6 +1,6 @@ package de.sovity.edc.ext.wrapper.api.usecase.services; -import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyMapperUtils; +import de.sovity.edc.ext.wrapper.api.common.mappers.utils.EdcPropertyUtils; import de.sovity.edc.ext.wrapper.api.common.model.PermissionDto; import de.sovity.edc.ext.wrapper.api.common.model.PolicyDto; import de.sovity.edc.ext.wrapper.api.usecase.model.AssetEntryDto; @@ -60,7 +60,7 @@ void setUp() { policyDefinitionStore, contractDefinitionStore, policyMappingService, - new EdcPropertyMapperUtils()); + new EdcPropertyUtils()); this.assetEntryDto = assetDto(); this.asset = asset(); diff --git a/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/utils/MapUtilsTest.java b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/utils/MapUtilsTest.java new file mode 100644 index 000000000..cf8b53fd8 --- /dev/null +++ b/extensions/wrapper/wrapper/src/test/java/de/sovity/edc/ext/wrapper/utils/MapUtilsTest.java @@ -0,0 +1,40 @@ +/* + * 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.utils; + +import org.junit.jupiter.api.Test; + +import java.util.List; +import java.util.Map; + +import static org.assertj.core.api.Assertions.assertThat; + +class MapUtilsTest { + + @Test + void mapValues() { + assertThat(MapUtils.mapValues(Map.of(1, "a"), String::toUpperCase)).isEqualTo(Map.of(1, "A")); + } + + @Test + void associateBy() { + assertThat(MapUtils.associateBy(List.of("a"), String::toUpperCase)).isEqualTo(Map.of("A", "a")); + } + + @Test + void reverse() { + assertThat(MapUtils.reverse(Map.of("a", 1))).isEqualTo(Map.of(1, "a")); + } +} diff --git a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java index 7d2ffdc84..77d603022 100644 --- a/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java +++ b/launchers/connectors/sovity-dev/src/test/java/de/sovity/edc/e2e/UiApiWrapperTest.java @@ -108,12 +108,26 @@ void provide_consume_assetMapping_policyMapping() { var assetId = providerClient.uiApi().createAsset(UiAssetCreateRequest.builder() .id("asset-1") .name("AssetName") + .description("AssetDescription") + .licenseUrl("https://license-url") + .version("1.0.0") + .language("en") + .mediaType("application/json") + .dataCategory("dataCategory") + .dataSubcategory("dataSubcategory") + .dataModel("dataModel") + .geoReferenceMethod("geoReferenceMethod") + .transportMode("transportMode") .keywords(List.of("keyword1", "keyword2")) + .creatorOrganizationName("creatorOrganizationName") + .publisherHomepage("publisherHomepage") .dataAddressProperties(Map.of( Prop.Edc.TYPE, "HttpData", + Prop.Edc.METHOD, "GET", Prop.Edc.BASE_URL, dataAddress.getDataSourceUrl(data) )) .build()).getId(); + assertThat(assetId).isEqualTo("asset-1"); providerClient.uiApi().createContractDefinition(ContractDefinitionRequest.builder() .contractDefinitionId("cd-1") @@ -145,6 +159,23 @@ void provide_consume_assetMapping_policyMapping() { assertThat(dataOffer.getAsset().getAssetId()).isEqualTo(assetId); assertThat(dataOffer.getAsset().getKeywords()).isEqualTo(List.of("keyword1", "keyword2")); assertThat(dataOffer.getAsset().getName()).isEqualTo("AssetName"); + assertThat(dataOffer.getAsset().getDescription()).isEqualTo("AssetDescription"); + assertThat(dataOffer.getAsset().getVersion()).isEqualTo("1.0.0"); + assertThat(dataOffer.getAsset().getLanguage()).isEqualTo("en"); + assertThat(dataOffer.getAsset().getMediaType()).isEqualTo("application/json"); + assertThat(dataOffer.getAsset().getDataCategory()).isEqualTo("dataCategory"); + assertThat(dataOffer.getAsset().getDataSubcategory()).isEqualTo("dataSubcategory"); + assertThat(dataOffer.getAsset().getDataModel()).isEqualTo("dataModel"); + assertThat(dataOffer.getAsset().getGeoReferenceMethod()).isEqualTo("geoReferenceMethod"); + assertThat(dataOffer.getAsset().getTransportMode()).isEqualTo("transportMode"); + assertThat(dataOffer.getAsset().getLicenseUrl()).isEqualTo("https://license-url"); + assertThat(dataOffer.getAsset().getKeywords()).isEqualTo(List.of("keyword1", "keyword2")); + assertThat(dataOffer.getAsset().getCreatorOrganizationName()).isEqualTo("creatorOrganizationName"); + assertThat(dataOffer.getAsset().getPublisherHomepage()).isEqualTo("publisherHomepage"); + assertThat(dataOffer.getAsset().getHttpDatasourceHintsProxyMethod()).isFalse(); + assertThat(dataOffer.getAsset().getHttpDatasourceHintsProxyPath()).isFalse(); + assertThat(dataOffer.getAsset().getHttpDatasourceHintsProxyQueryParams()).isFalse(); + assertThat(dataOffer.getAsset().getHttpDatasourceHintsProxyBody()).isFalse(); validateDataTransferred(dataAddress.getDataSinkSpyUrl(), data); } diff --git a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java index c254c02de..948528107 100644 --- a/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java +++ b/utils/json-and-jsonld-utils/src/main/java/de/sovity/edc/utils/jsonld/vocab/Prop.java @@ -35,6 +35,7 @@ public class Edc { public final String DATA_ADDRESS = CTX + "dataAddress"; public final String TYPE = CTX + "type"; public final String BASE_URL = CTX + "baseUrl"; + public final String METHOD = CTX + "method"; public final String PROXY_METHOD = CTX + "proxyMethod"; public final String PROXY_PATH = CTX + "proxyPath"; public final String PROXY_QUERY_PARAMS = CTX + "proxyQueryParams"; From 541e8651b38493d65d74e6b9f9c6e06b73516de0 Mon Sep 17 00:00:00 2001 From: Richard Treier Date: Tue, 19 Sep 2023 13:10:08 +0200 Subject: [PATCH 37/37] chore: update CHANGELOG.md --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1e4042584..6a78037f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,7 +19,8 @@ All notable changes to this project will be documented in this file. ### Minor Changes - UI API Wrapper Model: - - Opinionated Policy Model and Mappers for EDC UI and Broker Server Extension + - UiPolicy + PolicyMapper for EDC UI and Broker Server + - UiAsset + AssetMapper for EDC UI and Broker Server - UI API Wrapper Endpoints: - Asset Page - Create Asset