Skip to content

Commit

Permalink
chore: AssetMapper
Browse files Browse the repository at this point in the history
  • Loading branch information
SaadEGI committed Sep 15, 2023
1 parent 3187376 commit c6ec76a
Show file tree
Hide file tree
Showing 13 changed files with 102 additions and 238 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ void assetPage(AssetService assetStore) {
assertThat(asset.getPrivateProperties()).isEqualTo(privateProperties);
}


@Test
void assetPageSorting(AssetService assetService) {
// arrange
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -15,6 +18,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;


@RequiredArgsConstructor
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
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)
class AssetMapperTest {

@InjectMocks
AssetMapper assetMapper;
@InjectMocks
JsonFormatMapper jsonFormatMapper;

@Test
@SneakyThrows
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand All @@ -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();
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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";
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit c6ec76a

Please sign in to comment.