Skip to content

Commit

Permalink
Handle OrConstraint (#595)
Browse files Browse the repository at this point in the history
  • Loading branch information
ndr-brt authored Dec 15, 2022
1 parent 6e8f1b4 commit f5215dc
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 35 deletions.
8 changes: 4 additions & 4 deletions edc-extensions/custom-jsonld/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,19 +97,19 @@
<dependencies>
<!-- SPI -->
<dependency>
<groupId>org.eclipse.dataspaceconnector</groupId>
<groupId>org.eclipse.edc</groupId>
<artifactId>core-spi</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.dataspaceconnector</groupId>
<groupId>org.eclipse.edc</groupId>
<artifactId>ids-jsonld-serdes</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.dataspaceconnector</groupId>
<groupId>org.eclipse.edc</groupId>
<artifactId>ids-spi</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.dataspaceconnector</groupId>
<groupId>org.eclipse.edc</groupId>
<artifactId>ids-core</artifactId>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@

import de.fraunhofer.iais.eis.*;
import de.fraunhofer.iais.eis.util.TypedLiteral;
import org.eclipse.dataspaceconnector.ids.core.serialization.IdsConstraintImpl;
import org.eclipse.dataspaceconnector.ids.jsonld.JsonLd;
import org.eclipse.dataspaceconnector.ids.jsonld.JsonLdSerializer;
import org.eclipse.dataspaceconnector.ids.spi.domain.IdsConstants;
import org.eclipse.dataspaceconnector.ids.spi.service.ConnectorService;
import org.eclipse.dataspaceconnector.runtime.metamodel.annotation.Inject;
import org.eclipse.dataspaceconnector.spi.system.ServiceExtension;
import org.eclipse.dataspaceconnector.spi.system.ServiceExtensionContext;
import org.eclipse.dataspaceconnector.spi.types.TypeManager;
import org.eclipse.edc.protocol.ids.jsonld.JsonLd;
import org.eclipse.edc.protocol.ids.jsonld.JsonLdSerializer;
import org.eclipse.edc.protocol.ids.serialization.IdsConstraintImpl;
import org.eclipse.edc.protocol.ids.spi.domain.IdsConstants;
import org.eclipse.edc.protocol.ids.spi.service.ConnectorService;
import org.eclipse.edc.runtime.metamodel.annotation.Inject;
import org.eclipse.edc.spi.system.ServiceExtension;
import org.eclipse.edc.spi.system.ServiceExtensionContext;
import org.eclipse.edc.spi.types.TypeManager;

/**
* This extension is a temporary fix for a serialization bug:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# Copyright (c) 2022 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
# Copyright (c) 2021,2022 Contributors to the Eclipse Foundation
#
# See the NOTICE file(s) distributed with this work for additional
# information regarding copyright ownership.
#
# 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
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

org.eclipse.tractusx.edc.jsonld.CustomJsonLdExtension
Original file line number Diff line number Diff line change
Expand Up @@ -146,26 +146,17 @@ public ContractNegotiation getNegotiation(String id) throws IOException {
return mapNegotiation(negotiation);
}

public List<ContractNegotiation> getNegotiations() throws IOException {
final List<ManagementApiNegotiation> negotiations =
get(NEGOTIATIONS_PATH + "/", new TypeToken<List<ManagementApiNegotiation>>() {});
return negotiations.stream().map(this::mapNegotiation).collect(Collectors.toList());
}

public void createAsset(Asset asset) throws IOException {
final ManagementApiDataAddress dataAddress = new ManagementApiDataAddress();
final ManagementApiAssetCreate assetCreate = new ManagementApiAssetCreate();
dataAddress.properties =
Map.of(
ManagementApiDataAddress.TYPE,
"HttpData",
"baseUrl",
"https://jsonplaceholder.typicode.com/todos/1");

assetCreate.asset = mapAsset(asset);
assetCreate.dataAddress = dataAddress;

post(ASSET_PATH, assetCreate);
}

public void createAsset(AssetWithDataAddress assetWithDataAddress) throws IOException {
final ManagementApiAssetCreate assetCreate = new ManagementApiAssetCreate();
assetCreate.asset = mapAsset(assetWithDataAddress.getAsset());
assetCreate.dataAddress = mapDataAddress(assetWithDataAddress.getDataAddress());
assetCreate.dataAddress = mapDataAddress(asset.getDataAddress());

post(ASSET_PATH, assetCreate);
}
Expand Down Expand Up @@ -280,7 +271,33 @@ private TransferProcess mapTransferProcess(ManagementApiTransferProcess transfer

private ManagementApiDataAddress mapDataAddress(@NonNull DataAddress dataAddress) {
final ManagementApiDataAddress apiObject = new ManagementApiDataAddress();
apiObject.setProperties(dataAddress.getProperties());

if (dataAddress instanceof HttpProxySourceDataAddress) {
final HttpProxySourceDataAddress a = (HttpProxySourceDataAddress) dataAddress;
apiObject.setProperties(Map.of("type", "HttpData", "baseUrl", a.getBaseUrl()));
} else if (dataAddress instanceof HttpProxySinkDataAddress) {
apiObject.setProperties(Map.of("type", "HttpProxy"));
} else if (dataAddress instanceof S3DataAddress) {
final S3DataAddress a = (S3DataAddress) dataAddress;
apiObject.setProperties(
Map.of(
"type",
"AmazonS3",
"bucketName",
a.getBucketName(),
"region",
a.getRegion(),
"keyName",
a.getKeyName()));
} else if (dataAddress instanceof NullDataAddress) {
// set something that passes validation
apiObject.setProperties(Map.of("type", "HttpData", "baseUrl", "http://localhost"));
} else {
throw new UnsupportedOperationException(
String.format(
"Cannot map data address of type %s to EDC domain", dataAddress.getClass()));
}

return apiObject;
}

Expand Down
10 changes: 5 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1066,16 +1066,16 @@
</dependency>
<dependency>
<groupId>org.eclipse.edc</groupId>
<artifactId>monitor-jdk-logger</artifactId>
<artifactId>ids-jsonld-serdes</artifactId>
<version>${org.eclipse.edc.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.dataspaceconnector</groupId>
<artifactId>ids-jsonld-serdes</artifactId>
<version>${org.eclipse.dataspaceconnector.version}</version>
<groupId>org.eclipse.edc</groupId>
<artifactId>monitor-jdk-logger</artifactId>
<version>${org.eclipse.edc.version}</version>
</dependency>
<dependency>
<groupId>org.eclipse.dataspaceconnector</groupId>
<groupId>org.eclipse.edc</groupId>
<artifactId>jersey</artifactId>
<version>${org.eclipse.edc.version}</version>
</dependency>
Expand Down

0 comments on commit f5215dc

Please sign in to comment.