diff --git a/edc-controlplane/edc-controlplane-base/build.gradle.kts b/edc-controlplane/edc-controlplane-base/build.gradle.kts index 451885b69..09ed0b6b7 100644 --- a/edc-controlplane/edc-controlplane-base/build.gradle.kts +++ b/edc-controlplane/edc-controlplane-base/build.gradle.kts @@ -77,5 +77,7 @@ dependencies { // cloud provisioner extensions runtimeOnly(project(":edc-extensions:backport:azblob-provisioner")) + // fix dataset + runtimeOnly(project(":edc-extensions:dataset-bugfix")) } diff --git a/edc-extensions/dataset-bugfix/build.gradle.kts b/edc-extensions/dataset-bugfix/build.gradle.kts new file mode 100644 index 000000000..794ccea9c --- /dev/null +++ b/edc-extensions/dataset-bugfix/build.gradle.kts @@ -0,0 +1,28 @@ +/******************************************************************************** + * Copyright (c) 2024 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 + ********************************************************************************/ + +plugins { + `java-library` +} + +dependencies { + api(libs.edc.spi.core) + api(libs.edc.spi.jsonld) + api(libs.edc.spi.web) +} diff --git a/edc-extensions/dataset-bugfix/src/main/java/org/eclipse/tractusx/edc/dataset/fix/DatasetFixExtension.java b/edc-extensions/dataset-bugfix/src/main/java/org/eclipse/tractusx/edc/dataset/fix/DatasetFixExtension.java new file mode 100644 index 000000000..fc2da6d26 --- /dev/null +++ b/edc-extensions/dataset-bugfix/src/main/java/org/eclipse/tractusx/edc/dataset/fix/DatasetFixExtension.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2024 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 + */ + +package org.eclipse.tractusx.edc.dataset.fix; + +import jakarta.json.JsonObject; +import jakarta.ws.rs.NotFoundException; +import jakarta.ws.rs.container.ContainerRequestContext; +import jakarta.ws.rs.container.ContainerResponseContext; +import jakarta.ws.rs.container.ContainerResponseFilter; +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.web.spi.WebService; +import org.eclipse.edc.web.spi.configuration.ApiContext; + +import static jakarta.ws.rs.HttpMethod.GET; +import static org.eclipse.edc.jsonld.spi.JsonLdKeywords.TYPE; +import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.DCAT_DATASET_TYPE; +import static org.eclipse.edc.jsonld.spi.PropertyAndTypeNames.ODRL_POLICY_ATTRIBUTE; + +public class DatasetFixExtension implements ServiceExtension { + + @Inject + private WebService webService; + + @Override + public void initialize(ServiceExtensionContext context) { + webService.registerResource(ApiContext.PROTOCOL, new DatasetFilter()); + } + + private static class DatasetFilter implements ContainerResponseFilter { + + private static final String GET_DATASETS_PATH = "catalog/datasets/"; + + @Override + public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) { + if (requestContext.getUriInfo().getPath().contains(GET_DATASETS_PATH) && requestContext.getMethod().equals(GET)) { + if (responseContext.getEntity() instanceof JsonObject jsonObject) { + if (jsonObject.getString(TYPE).equals(DCAT_DATASET_TYPE) && + jsonObject.containsKey(ODRL_POLICY_ATTRIBUTE) && + jsonObject.getJsonArray(ODRL_POLICY_ATTRIBUTE).isEmpty() + ) { + throw new NotFoundException(); + } + } + } + } + } +} diff --git a/edc-extensions/dataset-bugfix/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension b/edc-extensions/dataset-bugfix/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension new file mode 100644 index 000000000..b26160fa7 --- /dev/null +++ b/edc-extensions/dataset-bugfix/src/main/resources/META-INF/services/org.eclipse.edc.spi.system.ServiceExtension @@ -0,0 +1,20 @@ +################################################################################# +# Copyright (c) 2024 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.dataset.fix.DatasetFixExtension diff --git a/edc-tests/edc-controlplane/catalog-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/CatalogTest.java b/edc-tests/edc-controlplane/catalog-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/CatalogTest.java index 6f0a04221..1eab87a9e 100644 --- a/edc-tests/edc-controlplane/catalog-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/CatalogTest.java +++ b/edc-tests/edc-controlplane/catalog-tests/src/test/java/org/eclipse/tractusx/edc/tests/catalog/CatalogTest.java @@ -30,6 +30,7 @@ import org.junit.jupiter.api.extension.RegisterExtension; import java.util.Map; +import java.util.UUID; import static java.util.stream.IntStream.range; import static org.assertj.core.api.Assertions.assertThat; @@ -81,7 +82,6 @@ void requestCatalog_fulfillsPolicy_shouldReturnOffer() { .allSatisfy(co -> { assertThat(getDatasetAssetId(co.asJsonObject())).isEqualTo("test-asset"); }); - } @Test @@ -203,7 +203,19 @@ void requestCatalog_of1000Assets_shouldContainAll() { var o2 = CONSUMER.getCatalogDatasets(PROVIDER, createQuery(500, 0)); var o3 = CONSUMER.getCatalogDatasets(PROVIDER, createQuery(500, 500)); assertThat(o2).doesNotContainAnyElementsOf(o3); + } + @Test + void getDataset_shouldReturn404_whenDatasetHasNoPolicies() { + var assetId = UUID.randomUUID().toString(); + PROVIDER.createAsset(assetId); + + PROVIDER.getProtocolEndpoint().baseRequest() + .header("Authorization", "{ \"client_id\": \"CONSUMER\", \"BusinessPartnerNumber\": \"BPN-CONSUMER\" }") + .get("/catalog/datasets/" + assetId) + .then() + .log().ifValidationFails() + .statusCode(404); } } diff --git a/settings.gradle.kts b/settings.gradle.kts index c3bd8a359..1c279b1e6 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -38,6 +38,7 @@ include(":edc-extensions:bpn-validation:bpn-validation-api") include(":edc-extensions:bpn-validation:bpn-validation-spi") include(":edc-extensions:bpn-validation:bpn-validation-core") include(":edc-extensions:bpn-validation:business-partner-store-sql") +include(":edc-extensions:dataset-bugfix") include(":edc-extensions:migrations:postgresql-migration-lib") include(":edc-extensions:migrations:control-plane-migration") include(":edc-extensions:migrations:data-plane-migration")