From 546ba7e2d08da7cfab90a8fe8b551260a7c0dcb1 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Wed, 16 Oct 2024 17:34:57 +0200 Subject: [PATCH 1/3] add description endpoint --- pom.xml | 2 +- .../service/DescriptionController.java | 44 +++++++++++++++++++ .../config/DescriptorMapperConfig.java | 3 ++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/DescriptionController.java diff --git a/pom.xml b/pom.xml index 74055c1..d84028f 100644 --- a/pom.xml +++ b/pom.xml @@ -63,7 +63,7 @@ 3.26.3 10.18.2 - 1.1.0 + 1.2.0-SNAPSHOT 2.3.232 6.6.1.Final 2.18.0 diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/DescriptionController.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/DescriptionController.java new file mode 100644 index 0000000..2d0659e --- /dev/null +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/DescriptionController.java @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://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. + */ +package de.fraunhofer.iosb.ilt.faaast.registry.service; + +import de.fraunhofer.iosb.ilt.faaast.service.model.ServiceDescription; +import de.fraunhofer.iosb.ilt.faaast.service.model.ServiceSpecificationProfile; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + + +/** + * REST controller for the description. + */ +@RestController +@RequestMapping("/api/v3.0/description") +public class DescriptionController { + + /** + * Returns a description object containing the capabilities and supported features of the server. + * + * @return The description object. + */ + @GetMapping + public ServiceDescription getDescription() { + return ServiceDescription.builder() + .profile(ServiceSpecificationProfile.AAS_REGISTRY_FULL) + .profile(ServiceSpecificationProfile.SUBMODEL_REGISTRY_FULL) + .build(); + } + +} diff --git a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java index 1dcf203..a2c0d4a 100644 --- a/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java +++ b/service/src/main/java/de/fraunhofer/iosb/ilt/faaast/registry/service/config/DescriptorMapperConfig.java @@ -20,6 +20,8 @@ import com.fasterxml.jackson.databind.module.SimpleModule; import com.fasterxml.jackson.databind.util.StdDateFormat; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.PageMixin; +import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.ServiceSpecificationProfileMixin; +import de.fraunhofer.iosb.ilt.faaast.service.model.ServiceSpecificationProfile; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.internal.deserialization.EnumDeserializer; import org.eclipse.digitaltwin.aas4j.v3.dataformat.core.internal.serialization.EnumSerializer; @@ -127,6 +129,7 @@ public Jackson2ObjectMapperBuilder jackson2ObjectMapperBuilder() { .mixIn(Extension.class, ExtensionMixin.class) .mixIn(Key.class, KeyMixin.class) .mixIn(Reference.class, ReferenceMixin.class) + .mixIn(ServiceSpecificationProfile.class, ServiceSpecificationProfileMixin.class) .featuresToDisable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS) .featuresToEnable(SerializationFeature.WRITE_DATES_WITH_ZONE_ID) .dateFormat(new StdDateFormat().withColonInTimeZone(true)); From 2d4fedb674811bfc6e7a7b2c7679604cbe738e54 Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Wed, 16 Oct 2024 17:52:59 +0200 Subject: [PATCH 2/3] add description integration test --- .../service/DescriptionControllerIT.java | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 service/src/test/java/de/fraunhofer/iosb/ilt/faaast/registry/service/DescriptionControllerIT.java diff --git a/service/src/test/java/de/fraunhofer/iosb/ilt/faaast/registry/service/DescriptionControllerIT.java b/service/src/test/java/de/fraunhofer/iosb/ilt/faaast/registry/service/DescriptionControllerIT.java new file mode 100644 index 0000000..4ea4c66 --- /dev/null +++ b/service/src/test/java/de/fraunhofer/iosb/ilt/faaast/registry/service/DescriptionControllerIT.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2021 Fraunhofer IOSB, eine rechtlich nicht selbstaendige + * Einrichtung der Fraunhofer-Gesellschaft zur Foerderung der angewandten + * Forschung e.V. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://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. + */ +package de.fraunhofer.iosb.ilt.faaast.registry.service; + +import de.fraunhofer.iosb.ilt.faaast.service.model.ServiceDescription; +import de.fraunhofer.iosb.ilt.faaast.service.model.ServiceSpecificationProfile; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.boot.test.web.server.LocalServerPort; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit4.SpringRunner; + + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = App.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@TestPropertySource(locations = "classpath:application-integrationtest.properties") +public class DescriptionControllerIT { + + @LocalServerPort + private int port; + + @Autowired + private TestRestTemplate restTemplate; + + @Test + public void testDescription() { + ResponseEntity response = restTemplate.exchange(createURLWithPort(""), HttpMethod.GET, null, ServiceDescription.class); + Assert.assertNotNull(response); + Assert.assertEquals(HttpStatus.OK, response.getStatusCode()); + Assert.assertNotNull(response.getBody()); + ServiceDescription expected = ServiceDescription.builder() + .profile(ServiceSpecificationProfile.AAS_REGISTRY_FULL) + .profile(ServiceSpecificationProfile.SUBMODEL_REGISTRY_FULL) + .build(); + Assert.assertEquals(expected, response.getBody()); + } + + + private String createURLWithPort(String uri) { + return "http://localhost:" + port + "/api/v3.0/description" + uri; + } +} From db1b714436be19cee3b24505099deb6e53d1397e Mon Sep 17 00:00:00 2001 From: Tino Bischoff Date: Thu, 17 Oct 2024 09:32:43 +0200 Subject: [PATCH 3/3] update documentation and ChangeLog --- docs/source/api/api.md | 3 +++ docs/source/changelog/changelog.md | 1 + 2 files changed, 4 insertions(+) diff --git a/docs/source/api/api.md b/docs/source/api/api.md index fbfff9d..6234cbe 100644 --- a/docs/source/api/api.md +++ b/docs/source/api/api.md @@ -16,6 +16,9 @@ Please be aware, that HTTPS is used. - api/v3.0/submodel-descriptors ![GET](https://img.shields.io/badge/GET-blue) ![POST](https://img.shields.io/badge/POST-brightgreen) - api/v3.0/submodel-descriptors/{submodelIdentifier} ![GET](https://img.shields.io/badge/GET-blue) ![PUT](https://img.shields.io/badge/PUT-orange) ![DELETE](https://img.shields.io/badge/DELETE-red) +- Description Interface + - api/v3.0/description ![GET](https://img.shields.io/badge/GET-blue) + ## Example In the default configuration, the base URL for the API is e.g.: diff --git a/docs/source/changelog/changelog.md b/docs/source/changelog/changelog.md index f98a1dc..e973390 100644 --- a/docs/source/changelog/changelog.md +++ b/docs/source/changelog/changelog.md @@ -5,6 +5,7 @@ **New Features & Major Changes** - HTTP - Added option to turn off SSL + - Added description endpoint **Internal changes & bugfixes** - General