Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add custom Json and JsonLd fields #820

Merged
merged 13 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions UPDATES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@

# Updates checklist

## Problem

A list of the element that may break when updating the EDC version.

In `de.sovity.edc.ext.wrapper.api.ui.pages.asset.AssetBuilder.fromEditMetadataRequest`

When re-creating the asset, we can't re-use the `Asset.toBuilder()` as it doesn't allow us to remove properties.

We must therefore re-build the asset using the same content as that `.toBuilder()`.

If the Eclipse EDC ads a field in this builder, we will miss it and any write to the JsonLd via the web API
will remove that hypothetical new field.

## Workaround

On the EDC version update, check that `org.eclipse.edc.spi.types.domain.asset.Asset.toBuilder` doesn't set more
fields than what we set. If a new field was added, add it to this function too.
ununhexium marked this conversation as resolved.
Show resolved Hide resolved
135 changes: 51 additions & 84 deletions docs/sovity-edc-api-wrapper.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -558,34 +558,23 @@ components:
type: string
description: Data Address
description: Data Address
additionalProperties:
type: object
additionalProperties:
type: string
description: Custom Asset Properties (that are strings)
description: Custom Asset Properties (that are strings)
additionalJsonProperties:
type: object
additionalProperties:
type: string
description: Custom Asset Properties (that are not strings but other JSON
values)
description: Custom Asset Properties (that are not strings but other JSON
values)
privateProperties:
type: object
additionalProperties:
type: string
description: Private Asset Properties (that are strings)
description: Private Asset Properties (that are strings)
privateJsonProperties:
type: object
additionalProperties:
type: string
description: Private Asset Properties (that are not strings but other
JSON values)
description: Private Asset Properties (that are not strings but other JSON
values)
customJsonAsString:
type: string
description: Contains serialized custom properties in the JSON format.
customJsonLdAsString:
type: string
description: "Contains serialized custom properties in the JSON LD format.\
\ Contrary to the customJsonAsString field, this string must represent\
\ a JSON LD object and will be affected by JSON LD compaction and expansion.\
\ Due to a technical limitation, the properties can't be booleans."
privateCustomJsonAsString:
type: string
description: Same as customJsonAsString but the data will be stored in the
private properties.
privateCustomJsonLdAsString:
type: string
description: Same as customJsonLdAsString but the data will be stored in
the private properties. The same limitations apply.
description: Type-Safe OpenAPI generator friendly Asset Create DTO that supports
an opinionated subset of the original EDC Asset Entity.
IdResponseDto:
Expand Down Expand Up @@ -839,34 +828,23 @@ components:
type: string
description: Temporal coverage end date (inclusive)
format: date
additionalProperties:
type: object
additionalProperties:
type: string
description: Custom Asset Properties (that are strings)
description: Custom Asset Properties (that are strings)
additionalJsonProperties:
type: object
additionalProperties:
type: string
description: Custom Asset Properties (that are not strings but other JSON
values)
description: Custom Asset Properties (that are not strings but other JSON
values)
privateProperties:
type: object
additionalProperties:
type: string
description: Private Asset Properties (that are strings)
description: Private Asset Properties (that are strings)
privateJsonProperties:
type: object
additionalProperties:
type: string
description: Private Asset Properties (that are not strings but other
JSON values)
description: Private Asset Properties (that are not strings but other JSON
values)
customJsonAsString:
type: string
description: Contains serialized custom properties in the JSON format.
customJsonLdAsString:
type: string
description: "Contains serialized custom properties in the JSON LD format.\
\ Contrary to the customJsonAsString field, this string must represent\
\ a JSON LD object and will be affected by JSON LD compaction and expansion.\
\ Due to a technical limitation, the properties can't be booleans."
privateCustomJsonAsString:
type: string
description: Same as customJsonAsString but the data will be stored in the
private properties.
privateCustomJsonLdAsString:
type: string
description: Same as customJsonLdAsString but the data will be stored in
the private properties. The same limitations apply.
description: Data for editing an asset.
AssetPage:
required:
Expand Down Expand Up @@ -1010,37 +988,26 @@ components:
type: string
description: Temporal coverage end date (inclusive)
format: date
additionalProperties:
type: object
additionalProperties:
type: string
description: Unhandled Asset Properties (that were strings)
description: Unhandled Asset Properties (that were strings)
additionalJsonProperties:
type: object
additionalProperties:
type: string
description: Unhandled Asset Properties (that were not strings but other
JSON values)
description: Unhandled Asset Properties (that were not strings but other
JSON values)
privateProperties:
type: object
additionalProperties:
type: string
description: Private Asset Properties (that were strings)
description: Private Asset Properties (that were strings)
privateJsonProperties:
type: object
additionalProperties:
type: string
description: Private Asset Properties (that were not strings but other
JSON values)
description: Private Asset Properties (that were not strings but other JSON
values)
assetJsonLd:
type: string
description: Contains the entire asset in the JSON-LD format
customJsonAsString:
type: string
description: Contains serialized custom properties in the JSON format.
customJsonLdAsString:
type: string
description: "Contains serialized custom properties in the JSON LD format.\
\ Contrary to the customJsonAsString field, this string must represent\
\ a JSON LD object and will be affected by JSON LD compaction and expansion.\
\ Due to a technical limitation, the properties can't be booleans."
privateCustomJsonAsString:
type: string
description: Same as customJsonAsString but the data will be stored in the
private properties.
privateCustomJsonLdAsString:
type: string
description: Same as customJsonLdAsString but the data will be stored in
the private properties. The same limitations apply.
description: Type-Safe Asset Metadata as needed by our UI
UiContractOffer:
required:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,26 @@ public class UiAsset {
@Schema(description = "Temporal coverage end date (inclusive)", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private LocalDate temporalCoverageToInclusive;

@Schema(description = "Unhandled Asset Properties (that were strings)", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private Map<String, String> additionalProperties;

@Schema(description = "Unhandled Asset Properties (that were not strings but other JSON values)", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private Map<String, String> additionalJsonProperties;

@Schema(description = "Private Asset Properties (that were strings)", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private Map<String, String> privateProperties;

@Schema(description = "Private Asset Properties (that were not strings but other JSON values)", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private Map<String, String> privateJsonProperties;

@Schema(description = "Contains the entire asset in the JSON-LD format", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String assetJsonLd;

@Schema(description = "Contains serialized custom properties in the JSON format.",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String customJsonAsString;

@Schema(description = "Contains serialized custom properties in the JSON LD format. " +
"Contrary to the customJsonAsString field, this string must represent a JSON LD object " +
"and will be affected by JSON LD compaction and expansion. " +
"Due to a technical limitation, the properties can't be booleans.",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String customJsonLdAsString;

@Schema(description = "Same as customJsonAsString but the data will be stored in the private properties.",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String privateCustomJsonAsString;

@Schema(description = "Same as customJsonLdAsString but the data will be stored in the private properties. " +
"The same limitations apply.",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String privateCustomJsonLdAsString;
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,23 @@ public class UiAssetCreateRequest {
@Schema(description = "Data Address", requiredMode = Schema.RequiredMode.REQUIRED)
private Map<String, String> dataAddressProperties;

@Schema(description = "Custom Asset Properties (that are strings)", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private Map<String, String> additionalProperties;

@Schema(description = "Custom Asset Properties (that are not strings but other JSON values)", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private Map<String, String> additionalJsonProperties;

@Schema(description = "Private Asset Properties (that are strings)", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private Map<String, String> privateProperties;

@Schema(description = "Private Asset Properties (that are not strings but other JSON values)", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private Map<String, String> privateJsonProperties;
@Schema(description = "Contains serialized custom properties in the JSON format.",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String customJsonAsString;

@Schema(description = "Contains serialized custom properties in the JSON LD format. " +
"Contrary to the customJsonAsString field, this string must represent a JSON LD object " +
"and will be affected by JSON LD compaction and expansion. " +
"Due to a technical limitation, the properties can't be booleans.",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String customJsonLdAsString;

@Schema(description = "Same as customJsonAsString but the data will be stored in the private properties.",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String privateCustomJsonAsString;

@Schema(description = "Same as customJsonLdAsString but the data will be stored in the private properties. " +
"The same limitations apply.",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String privateCustomJsonLdAsString;
}
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,23 @@ public class UiAssetEditMetadataRequest {
@Schema(description = "Temporal coverage end date (inclusive)", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private LocalDate temporalCoverageToInclusive;

@Schema(description = "Custom Asset Properties (that are strings)", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private Map<String, String> additionalProperties;

@Schema(description = "Custom Asset Properties (that are not strings but other JSON values)", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private Map<String, String> additionalJsonProperties;

@Schema(description = "Private Asset Properties (that are strings)", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private Map<String, String> privateProperties;

@Schema(description = "Private Asset Properties (that are not strings but other JSON values)", requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private Map<String, String> privateJsonProperties;
@Schema(description = "Contains serialized custom properties in the JSON format.",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String customJsonAsString;

@Schema(description = "Contains serialized custom properties in the JSON LD format. " +
"Contrary to the customJsonAsString field, this string must represent a JSON LD object " +
"and will be affected by JSON LD compaction and expansion. " +
"Due to a technical limitation, the properties can't be booleans.",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String customJsonLdAsString;

@Schema(description = "Same as customJsonAsString but the data will be stored in the private properties.",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String privateCustomJsonAsString;

@Schema(description = "Same as customJsonLdAsString but the data will be stored in the private properties. " +
"The same limitations apply.",
requiredMode = Schema.RequiredMode.NOT_REQUIRED)
private String privateCustomJsonLdAsString;
}
8 changes: 5 additions & 3 deletions extensions/wrapper/wrapper-common-mappers/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
val lombokVersion: String by project

val assertj: String by project
val edcGroup: String by project
val edcVersion: String by project
val assertj: String by project
val jsonUnit: String by project
val mockitoVersion: String by project

plugins {
Expand All @@ -27,11 +28,12 @@ dependencies {
testAnnotationProcessor("org.projectlombok:lombok:${lombokVersion}")
testCompileOnly("org.projectlombok:lombok:${lombokVersion}")
testImplementation("${edcGroup}:json-ld:${edcVersion}")
testImplementation("net.javacrumbs.json-unit:json-unit-assertj:${jsonUnit}")
testImplementation("org.assertj:assertj-core:${assertj}")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
testImplementation("org.mockito:mockito-core:${mockitoVersion}")
testImplementation("org.mockito:mockito-inline:${mockitoVersion}")
testImplementation("org.mockito:mockito-junit-jupiter:${mockitoVersion}")
testImplementation("org.assertj:assertj-core:${assertj}")
testImplementation("org.junit.jupiter:junit-jupiter-api:5.10.0")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.10.0")
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,13 @@ protected static JsonObjectBuilder addNonNullJsonValue(JsonObjectBuilder builder
builder.add(key, value);
return builder;
}

protected static JsonObjectBuilder addNonNullJsonValue(JsonObjectBuilder builder, String key, JsonValue value) {
if (value == null || value.getValueType() == JsonValue.ValueType.NULL) {
return builder;
}

builder.add(key, value);
return builder;
}
}
Loading
Loading