Skip to content

Commit

Permalink
prepare for review
Browse files Browse the repository at this point in the history
  • Loading branch information
richardtreier committed Jun 25, 2024
1 parent 57a88d2 commit 7018ff3
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import org.junit.jupiter.api.extension.AfterAllCallback;
import org.junit.jupiter.api.extension.BeforeAllCallback;

import java.util.function.Consumer;
import javax.sql.DataSource;
import java.util.function.Consumer;

public interface TestDatabase extends BeforeAllCallback, AfterAllCallback {
String getJdbcUrl();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@
@Schema(description = "Data Offer Data Source Model. Supports certain Data Address types but also leaves a backdoor for custom Data Address Properties.")
public class UiDataSource {
@Schema(
description = "Data Address Type. " +
"Supported types are HTTP_DATA and CUSTOM.",
description = "Data Address Type.",
defaultValue = "CUSTOM",
requiredMode = Schema.RequiredMode.REQUIRED
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private JsonObject getAssetProperties(
addMobilityTheme(properties, request);

addCustomJsonLd(properties, request);
addDataSourceHints(dataAddressJsonLd, properties);
addDataSourceHints(properties, dataAddressJsonLd);
return properties.build();
}

Expand All @@ -151,7 +151,7 @@ private void addCustomJsonLd(JsonObjectBuilder properties, UiAssetCreateRequest
jsonLd.forEach((key, value) -> addNonNullJsonValue(properties, key, value));
}

private void addDataSourceHints(JsonObject dataAddressJsonLd, JsonObjectBuilder properties) {
private void addDataSourceHints(JsonObjectBuilder properties, JsonObject dataAddressJsonLd) {
var dataSourceHints = dataSourceMapper.buildAssetPropsFromDataAddress(dataAddressJsonLd);
properties.addAll(Json.createObjectBuilder(dataSourceHints));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
import com.ibm.icu.impl.Pair;
import de.sovity.edc.ext.wrapper.api.common.mappers.asset.utils.EdcPropertyUtils;
import de.sovity.edc.ext.wrapper.api.common.mappers.dataaddress.http.HttpDataSourceMapper;
import de.sovity.edc.ext.wrapper.api.common.model.DataSourceType;
import de.sovity.edc.ext.wrapper.api.common.model.UiDataSource;
import de.sovity.edc.ext.wrapper.api.common.model.UiDataSourceHttpData;
import de.sovity.edc.ext.wrapper.api.common.model.UiDataSourceOnRequest;
import de.sovity.edc.utils.jsonld.JsonLdUtils;
import de.sovity.edc.utils.jsonld.vocab.Prop;
import jakarta.json.Json;
import jakarta.json.JsonObject;
import jakarta.json.JsonObjectBuilder;
import jakarta.json.JsonValue;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;

import java.util.Map;
import java.util.function.Function;
import java.util.function.Supplier;

import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toMap;


Expand All @@ -43,19 +43,15 @@ public JsonObject buildDataSourceJsonLd(@NonNull UiDataSource dataSource) {
}

public JsonObject buildAssetPropsFromDataAddress(JsonObject dataAddressJsonLd) {
var assetProps = Json.createObjectBuilder();

// We purposefully do not match the DataSource type but the final Data Address properties
// to work with "custom data addresses" to the best of our ability.
var dataAddress = getDataAddressProperties(dataAddressJsonLd);
// We purposefully do not match the DataSource type but the properties to support the data address type "CUSTOM"
var dataAddress = parseDataAddressJsonLd(dataAddressJsonLd);
var type = dataAddress.getOrDefault(Prop.Edc.TYPE, "");


if (type.equals(Prop.Edc.DATA_ADDRESS_TYPE_HTTP_DATA)) {
assetProps.addAll(httpDataSourceMapper.enhanceAssetWithDataSourceHints(dataAddress));
return httpDataSourceMapper.enhanceAssetWithDataSourceHints(dataAddress);
}

return assetProps.build();
return JsonValue.EMPTY_JSON_OBJECT;
}

private <T> T matchDataSource(
Expand All @@ -65,7 +61,10 @@ private <T> T matchDataSource(
@NonNull Supplier<T> customMapper
) {
var type = dataSource.getType();
requireNonNull(type, "Data Source Type must not be null");
if (type == null) {
type = DataSourceType.CUSTOM;
}

return switch (type) {
case HTTP_DATA -> httpDataMapper.apply(dataSource.getHttpData());
case ON_REQUEST -> onRequestMapper.apply(dataSource.getOnRequest());
Expand All @@ -81,12 +80,11 @@ private JsonObject buildDataAddressJsonLd(Map<String, String> properties) {
.build();
}

private Map<String, String> getDataAddressProperties(JsonObject dataAddressJsonLd) {
private Map<String, String> parseDataAddressJsonLd(JsonObject dataAddressJsonLd) {
return dataAddressJsonLd.entrySet().stream()
.map(entry -> {
var value = JsonLdUtils.string(entry.getValue());
return Pair.of(entry.getKey(), value == null ? "" : value);
})
.collect(toMap(it -> it.first, it -> it.second));
.collect(toMap(Map.Entry::getKey, it -> {
var value = JsonLdUtils.string(it.getValue());
return value == null ? "" : value;
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import de.sovity.edc.ext.wrapper.api.common.model.UiDataSourceOnRequest;
import de.sovity.edc.utils.jsonld.vocab.Prop;
import jakarta.json.Json;
import jakarta.json.JsonObject;
import jakarta.json.JsonObjectBuilder;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -84,7 +85,7 @@ public Map<String, String> buildOnRequestDataAddress(@NonNull UiDataSourceOnRequ
* @param dataAddress data address
* @return json object to be merged with asset properties
*/
public JsonObjectBuilder enhanceAssetWithDataSourceHints(Map<String, String> dataAddress) {
public JsonObject enhanceAssetWithDataSourceHints(Map<String, String> dataAddress) {
var json = Json.createObjectBuilder();

// Parameterization Hints
Expand Down Expand Up @@ -113,6 +114,6 @@ public JsonObjectBuilder enhanceAssetWithDataSourceHints(Map<String, String> dat
}
});

return json;
return json.build();
}
}
2 changes: 1 addition & 1 deletion launchers/common/base-mds/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
}

dependencies {
// implementation(libs.loggingHouse.client)
implementation(libs.loggingHouse.client)
}

group = libs.versions.sovityEdcGroup.get()

0 comments on commit 7018ff3

Please sign in to comment.