diff --git a/assetconnection/common/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/assetconnection/common/format/JsonFormat.java b/assetconnection/common/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/assetconnection/common/format/JsonFormat.java index f9846002c..ba8f859c8 100644 --- a/assetconnection/common/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/assetconnection/common/format/JsonFormat.java +++ b/assetconnection/common/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/assetconnection/common/format/JsonFormat.java @@ -27,6 +27,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.dataformat.SerializationException; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.JsonApiDeserializer; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.JsonApiSerializer; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.UnsupportedModifierException; import de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue; import de.fraunhofer.iosb.ilt.faaast.service.model.value.Datatype; import de.fraunhofer.iosb.ilt.faaast.service.typing.ElementValueTypeInfo; @@ -123,7 +124,7 @@ public String write(DataElementValue value) throws AssetConnectionException { try { return serializer.write(value); } - catch (SerializationException e) { + catch (SerializationException | UnsupportedModifierException e) { throw new AssetConnectionException("serializing value to JSON failed", e); } } diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/ApiSerializer.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/ApiSerializer.java index 37f222b8e..b1a3597ec 100644 --- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/ApiSerializer.java +++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/ApiSerializer.java @@ -15,6 +15,7 @@ package de.fraunhofer.iosb.ilt.faaast.service.dataformat; import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.UnsupportedModifierException; import java.io.File; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -43,8 +44,9 @@ public interface ApiSerializer { * @param modifier output modifier defining how to serialize * @return string serialization of obj * @throws SerializationException if serialization fails + * @throws UnsupportedModifierException if the modifier is not supported for this element */ - public String write(Object obj, OutputModifier modifier) throws SerializationException; + public String write(Object obj, OutputModifier modifier) throws SerializationException, UnsupportedModifierException; /** @@ -54,8 +56,9 @@ public interface ApiSerializer { * @param obj object to serialize * @return string serialization of obj * @throws SerializationException if serialization fails + * @throws UnsupportedModifierException if the modifier is not supported for this element */ - public default String write(Object obj) throws SerializationException { + public default String write(Object obj) throws SerializationException, UnsupportedModifierException { return write(obj, OutputModifier.DEFAULT); } @@ -68,8 +71,9 @@ public default String write(Object obj) throws SerializationException { * @param modifier output modifier defining how to serialize * @throws IOException if writing to the stream fails * @throws SerializationException if serialization fails + * @throws UnsupportedModifierException if the modifier is not supported for this element */ - public default void write(OutputStream out, Object obj, OutputModifier modifier) throws IOException, SerializationException { + public default void write(OutputStream out, Object obj, OutputModifier modifier) throws IOException, SerializationException, UnsupportedModifierException { write(out, DEFAULT_CHARSET, obj, modifier); } @@ -82,8 +86,9 @@ public default void write(OutputStream out, Object obj, OutputModifier modifier) * @param obj object to serialize * @throws IOException if writing to the stream fails * @throws SerializationException if serialization fails + * @throws UnsupportedModifierException if the modifier is not supported for this element */ - public default void write(OutputStream out, Object obj) throws IOException, SerializationException { + public default void write(OutputStream out, Object obj) throws IOException, SerializationException, UnsupportedModifierException { write(out, obj, OutputModifier.DEFAULT); } @@ -97,8 +102,9 @@ public default void write(OutputStream out, Object obj) throws IOException, Seri * @param modifier output modifier defining how to serialize * @throws IOException if writing to the stream fails * @throws SerializationException if serialization fails + * @throws UnsupportedModifierException if the modifier is not supported for this element */ - public default void write(OutputStream out, Charset charset, Object obj, OutputModifier modifier) throws IOException, SerializationException { + public default void write(OutputStream out, Charset charset, Object obj, OutputModifier modifier) throws IOException, SerializationException, UnsupportedModifierException { try (OutputStreamWriter writer = new OutputStreamWriter(out, charset)) { writer.write(write(obj, modifier)); } @@ -114,8 +120,9 @@ public default void write(OutputStream out, Charset charset, Object obj, OutputM * @param obj object to serialize * @throws IOException if writing to the stream fails * @throws SerializationException if serialization fails + * @throws UnsupportedModifierException if the modifier is not supported for this element */ - public default void write(OutputStream out, Charset charset, Object obj) throws IOException, SerializationException { + public default void write(OutputStream out, Charset charset, Object obj) throws IOException, SerializationException, UnsupportedModifierException { write(out, charset, obj, OutputModifier.DEFAULT); } @@ -130,8 +137,9 @@ public default void write(OutputStream out, Charset charset, Object obj) throws * @throws FileNotFoundException if file is not found * @throws IOException if writing to the stream fails * @throws SerializationException if serialization fails + * @throws UnsupportedModifierException if the modifier is not supported for this element */ - public default void write(File file, Charset charset, Object obj, OutputModifier modifier) throws IOException, SerializationException { + public default void write(File file, Charset charset, Object obj, OutputModifier modifier) throws IOException, SerializationException, UnsupportedModifierException { try (OutputStream out = new FileOutputStream(file)) { write(out, charset, obj, modifier); } @@ -148,8 +156,9 @@ public default void write(File file, Charset charset, Object obj, OutputModifier * @throws FileNotFoundException if file is not found * @throws IOException if writing to the stream fails * @throws SerializationException if serialization fails + * @throws UnsupportedModifierException if the modifier is not supported for this element */ - public default void write(File file, Charset charset, Object obj) throws IOException, SerializationException { + public default void write(File file, Charset charset, Object obj) throws IOException, SerializationException, UnsupportedModifierException { write(file, charset, obj, OutputModifier.DEFAULT); } @@ -163,8 +172,9 @@ public default void write(File file, Charset charset, Object obj) throws IOExcep * @throws FileNotFoundException if file is not found * @throws IOException if writing to the stream fails * @throws SerializationException if serialization fails + * @throws UnsupportedModifierException if the modifier is not supported for this element */ - public default void write(File file, Object obj, OutputModifier modifier) throws IOException, SerializationException { + public default void write(File file, Object obj, OutputModifier modifier) throws IOException, SerializationException, UnsupportedModifierException { write(file, DEFAULT_CHARSET, obj, modifier); } @@ -178,8 +188,9 @@ public default void write(File file, Object obj, OutputModifier modifier) throws * @throws FileNotFoundException if file is not found * @throws IOException if writing to the stream fails * @throws SerializationException if serialization fails + * @throws UnsupportedModifierException if the modifier is not supported for this element */ - public default void write(File file, Object obj) throws IOException, SerializationException { + public default void write(File file, Object obj) throws IOException, SerializationException, UnsupportedModifierException { write(file, obj, OutputModifier.DEFAULT); } diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/environment/serializer/JsonEnvironmentSerializer.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/environment/serializer/JsonEnvironmentSerializer.java index da8b82a6a..ae9236289 100644 --- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/environment/serializer/JsonEnvironmentSerializer.java +++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/environment/serializer/JsonEnvironmentSerializer.java @@ -20,9 +20,12 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.serialization.DataFormat; import java.nio.charset.Charset; import java.util.Collection; +import java.util.Objects; import org.eclipse.digitaltwin.aas4j.v3.dataformat.aasx.InMemoryFile; import org.eclipse.digitaltwin.aas4j.v3.dataformat.json.JsonSerializer; import org.eclipse.digitaltwin.aas4j.v3.model.Environment; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** @@ -31,6 +34,7 @@ @SupportedDataformat(DataFormat.JSON) public class JsonEnvironmentSerializer implements EnvironmentSerializer { + private static final Logger LOGGER = LoggerFactory.getLogger(JsonEnvironmentSerializer.class); private final JsonSerializer serializer; public JsonEnvironmentSerializer() { @@ -40,8 +44,8 @@ public JsonEnvironmentSerializer() { @Override public byte[] write(Charset charset, Environment environment, Collection files) throws SerializationException { - if (files != null && !files.isEmpty()) { - throw new UnsupportedOperationException("serializing file content is not supported for data format JSON"); + if (Objects.nonNull(files) && !files.isEmpty()) { + LOGGER.debug("embedded files are ignored when serializing to JSON"); } try { return serializer.write(environment).getBytes(charset); diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/environment/serializer/JsonLDEnvironmentSerializer.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/environment/serializer/JsonLDEnvironmentSerializer.java index a0998da0b..e914b2bb0 100644 --- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/environment/serializer/JsonLDEnvironmentSerializer.java +++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/environment/serializer/JsonLDEnvironmentSerializer.java @@ -30,6 +30,7 @@ @SupportedDataformat(DataFormat.JSONLD) public class JsonLDEnvironmentSerializer implements EnvironmentSerializer { + // private static final Logger LOGGER = LoggerFactory.getLogger(JsonLDEnvironmentSerializer.class); // private final Serializer serializer; public JsonLDEnvironmentSerializer() { @@ -40,8 +41,8 @@ public JsonLDEnvironmentSerializer() { @Override public byte[] write(Charset charset, Environment environment, Collection files) throws SerializationException { throw new UnsupportedOperationException("Current version of AAS4j library does not support RDF/JSON-LD de-/serialization"); - // if (files != null && !files.isEmpty()) { - // throw new UnsupportedOperationException("serializing file content is not supported for data format RDF"); + // if (Objects.nonNull(files) && !files.isEmpty()) { + // LOGGER.debug("embedded files are ignored when serializing to JSON-LD"); // } // try { // return serializer.write(environment, Lang.JSONLD).getBytes(charset); diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/environment/serializer/RdfEnvironmentSerializer.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/environment/serializer/RdfEnvironmentSerializer.java index 4aa08361e..c6be38971 100644 --- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/environment/serializer/RdfEnvironmentSerializer.java +++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/environment/serializer/RdfEnvironmentSerializer.java @@ -36,6 +36,7 @@ @SupportedDataformat(DataFormat.RDF) public class RdfEnvironmentSerializer implements EnvironmentSerializer { + // private static final Logger LOGGER = LoggerFactory.getLogger(RdfEnvironmentSerializer.class); public static final Lang DEFAULT_RDF_LANGUAGE = Lang.TTL; // private final Serializer serializer; @@ -56,8 +57,8 @@ public RdfEnvironmentSerializer() { */ public byte[] write(Charset charset, Environment environment, Collection files, Lang rdfLanguage) throws SerializationException { throw new UnsupportedOperationException("Current version of AAS4j library does not support RDF/JSON-LD de-/serialization"); - // if (files != null && !files.isEmpty()) { - // throw new UnsupportedOperationException("serializing file content is not supported for data format RDF"); + // if (Objects.nonNull(files) && !files.isEmpty()) { + // LOGGER.debug("embedded files are ignored when serializing to RDF"); // } // try { // return serializer.write(environment, rdfLanguage).getBytes(charset); diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/environment/serializer/XmlEnvironmentSerializer.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/environment/serializer/XmlEnvironmentSerializer.java index a25589fe0..2114a9fb9 100644 --- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/environment/serializer/XmlEnvironmentSerializer.java +++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/environment/serializer/XmlEnvironmentSerializer.java @@ -20,9 +20,12 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.serialization.DataFormat; import java.nio.charset.Charset; import java.util.Collection; +import java.util.Objects; import org.eclipse.digitaltwin.aas4j.v3.dataformat.aasx.InMemoryFile; import org.eclipse.digitaltwin.aas4j.v3.dataformat.xml.XmlSerializer; import org.eclipse.digitaltwin.aas4j.v3.model.Environment; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** @@ -31,6 +34,7 @@ @SupportedDataformat(DataFormat.XML) public class XmlEnvironmentSerializer implements EnvironmentSerializer { + private static final Logger LOGGER = LoggerFactory.getLogger(XmlEnvironmentSerializer.class); private final XmlSerializer serializer; public XmlEnvironmentSerializer() { @@ -40,8 +44,8 @@ public XmlEnvironmentSerializer() { @Override public byte[] write(Charset charset, Environment environment, Collection files) throws SerializationException { - if (files != null && !files.isEmpty()) { - throw new UnsupportedOperationException("serializing file content is not supported for data format XML"); + if (Objects.nonNull(files) && !files.isEmpty()) { + LOGGER.debug("embedded files are ignored when serializing to XML"); } try { return serializer.write(environment).getBytes(charset); diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/request/handler/aasrepository/GetAllAssetAdministrationShellsByAssetIdReferenceRequestHandler.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/request/handler/aasrepository/GetAllAssetAdministrationShellsByAssetIdReferenceRequestHandler.java new file mode 100644 index 000000000..ebd4b24a7 --- /dev/null +++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/request/handler/aasrepository/GetAllAssetAdministrationShellsByAssetIdReferenceRequestHandler.java @@ -0,0 +1,72 @@ +/* + * 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.service.request.handler.aasrepository; + +import de.fraunhofer.iosb.ilt.faaast.service.exception.MessageBusException; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.aasrepository.GetAllAssetAdministrationShellsByAssetIdReferenceRequest; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.response.aasrepository.GetAllAssetAdministrationShellsByAssetIdReferenceResponse; +import de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.access.ElementReadEventMessage; +import de.fraunhofer.iosb.ilt.faaast.service.persistence.AssetAdministrationShellSearchCriteria; +import de.fraunhofer.iosb.ilt.faaast.service.request.handler.AbstractRequestHandler; +import de.fraunhofer.iosb.ilt.faaast.service.request.handler.RequestExecutionContext; +import de.fraunhofer.iosb.ilt.faaast.service.util.LambdaExceptionHelper; +import de.fraunhofer.iosb.ilt.faaast.service.util.ReferenceBuilder; +import java.util.List; +import java.util.stream.Collectors; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; + + +/** + * Class to handle a + * {@link de.fraunhofer.iosb.ilt.faaast.service.model.api.request.aasrepository.GetAllAssetAdministrationShellsByAssetIdRequest} + * in the service and to send the corresponding response + * {@link de.fraunhofer.iosb.ilt.faaast.service.model.api.response.aasrepository.GetAllAssetAdministrationShellsByAssetIdResponse}. + * Is responsible for communication with the persistence and sends the corresponding events to the message bus. + */ +public class GetAllAssetAdministrationShellsByAssetIdReferenceRequestHandler + extends AbstractRequestHandler { + + public GetAllAssetAdministrationShellsByAssetIdReferenceRequestHandler(RequestExecutionContext context) { + super(context); + } + + + @Override + public GetAllAssetAdministrationShellsByAssetIdReferenceResponse process(GetAllAssetAdministrationShellsByAssetIdReferenceRequest request) throws MessageBusException { + Page page = context.getPersistence().findAssetAdministrationShells( + AssetAdministrationShellSearchCriteria.builder() + .assetIds(parseSpecificAssetIds(request.getAssetIds())) + .build(), + request.getOutputModifier(), + request.getPagingInfo()); + if (!request.isInternal()) { + page.getContent().forEach(LambdaExceptionHelper.rethrowConsumer( + x -> context.getMessageBus().publish(ElementReadEventMessage.builder() + .element(x) + .value(x) + .build()))); + } + List result = page.getContent().stream() + .map(ReferenceBuilder::forAas) + .collect(Collectors.toList()); + return GetAllAssetAdministrationShellsByAssetIdReferenceResponse.builder() + .payload(Page.of(result, page.getMetadata())) + .success() + .build(); + } + +} diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/request/handler/aasrepository/GetAllAssetAdministrationShellsByIdShortReferenceRequestHandler.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/request/handler/aasrepository/GetAllAssetAdministrationShellsByIdShortReferenceRequestHandler.java new file mode 100644 index 000000000..d8507d411 --- /dev/null +++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/request/handler/aasrepository/GetAllAssetAdministrationShellsByIdShortReferenceRequestHandler.java @@ -0,0 +1,73 @@ +/* + * 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.service.request.handler.aasrepository; + +import de.fraunhofer.iosb.ilt.faaast.service.exception.MessageBusException; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.aasrepository.GetAllAssetAdministrationShellsByIdShortReferenceRequest; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.response.aasrepository.GetAllAssetAdministrationShellsByIdShortReferenceResponse; +import de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.access.ElementReadEventMessage; +import de.fraunhofer.iosb.ilt.faaast.service.persistence.AssetAdministrationShellSearchCriteria; +import de.fraunhofer.iosb.ilt.faaast.service.request.handler.AbstractRequestHandler; +import de.fraunhofer.iosb.ilt.faaast.service.request.handler.RequestExecutionContext; +import de.fraunhofer.iosb.ilt.faaast.service.util.LambdaExceptionHelper; +import de.fraunhofer.iosb.ilt.faaast.service.util.ReferenceBuilder; +import java.util.List; +import java.util.Objects; +import java.util.stream.Collectors; +import org.eclipse.digitaltwin.aas4j.v3.model.AssetAdministrationShell; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; + + +/** + * Class to handle a + * {@link de.fraunhofer.iosb.ilt.faaast.service.model.api.request.aasrepository.GetAllAssetAdministrationShellsByIdShortRequest} + * in the service and to send the corresponding response + * {@link de.fraunhofer.iosb.ilt.faaast.service.model.api.response.aasrepository.GetAllAssetAdministrationShellsByIdShortResponse}. + * Is responsible for communication with the persistence and sends the corresponding events to the message bus. + */ +public class GetAllAssetAdministrationShellsByIdShortReferenceRequestHandler + extends AbstractRequestHandler { + + public GetAllAssetAdministrationShellsByIdShortReferenceRequestHandler(RequestExecutionContext context) { + super(context); + } + + + @Override + public GetAllAssetAdministrationShellsByIdShortReferenceResponse process(GetAllAssetAdministrationShellsByIdShortReferenceRequest request) throws MessageBusException { + Page page = context.getPersistence().findAssetAdministrationShells( + AssetAdministrationShellSearchCriteria.builder() + .idShort(request.getIdShort()) + .build(), + request.getOutputModifier(), + request.getPagingInfo()); + if (!request.isInternal() && Objects.nonNull(page.getContent())) { + page.getContent().forEach(LambdaExceptionHelper.rethrowConsumer( + x -> context.getMessageBus().publish(ElementReadEventMessage.builder() + .element(x) + .value(x) + .build()))); + } + List result = page.getContent().stream() + .map(ReferenceBuilder::forAas) + .collect(Collectors.toList()); + return GetAllAssetAdministrationShellsByIdShortReferenceResponse.builder() + .payload(Page.of(result, page.getMetadata())) + .success() + .build(); + } + +} diff --git a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/util/ElementValueHelper.java b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/util/ElementValueHelper.java index ecefc33b7..cd9a5e9e3 100644 --- a/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/util/ElementValueHelper.java +++ b/core/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/util/ElementValueHelper.java @@ -29,6 +29,7 @@ import java.util.stream.Collectors; import java.util.stream.Stream; import org.eclipse.digitaltwin.aas4j.v3.model.AnnotatedRelationshipElement; +import org.eclipse.digitaltwin.aas4j.v3.model.BasicEventElement; import org.eclipse.digitaltwin.aas4j.v3.model.DataElement; import org.eclipse.digitaltwin.aas4j.v3.model.Entity; import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable; @@ -120,12 +121,13 @@ public static boolean isValueOnlySupported(Class type) { */ public static boolean isSerializableAsValue(Class type) { return DataElement.class.isAssignableFrom(type) - || SubmodelElementCollection.class.isAssignableFrom(type) - || SubmodelElementList.class.isAssignableFrom(type) + || AnnotatedRelationshipElement.class.isAssignableFrom(type) + || BasicEventElement.class.isAssignableFrom(type) + || Entity.class.isAssignableFrom(type) || ReferenceElement.class.isAssignableFrom(type) || RelationshipElement.class.isAssignableFrom(type) - || AnnotatedRelationshipElement.class.isAssignableFrom(type) - || Entity.class.isAssignableFrom(type); + || SubmodelElementCollection.class.isAssignableFrom(type) + || SubmodelElementList.class.isAssignableFrom(type); } diff --git a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonApiDeserializer.java b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonApiDeserializer.java index 4d9ef24b2..6d008b66d 100644 --- a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonApiDeserializer.java +++ b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonApiDeserializer.java @@ -35,6 +35,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.dataformat.ApiDeserializer; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.deserializer.AnnotatedRelationshipElementValueDeserializer; +import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.deserializer.BasicEventElementValueDeserializer; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.deserializer.ContextAwareElementValueDeserializer; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.deserializer.ElementValueDeserializer; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.deserializer.EntityValueDeserializer; @@ -52,10 +53,12 @@ import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.AbstractRequestWithModifierMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.AbstractSubmodelInterfaceRequestMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.InvokeOperationRequestMixin; +import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.MessageMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.PageMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.value.PropertyValueMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.value.ReferenceElementValueMixin; import de.fraunhofer.iosb.ilt.faaast.service.model.SubmodelElementIdentifier; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.Message; import de.fraunhofer.iosb.ilt.faaast.service.model.api.StatusCode; import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; @@ -67,6 +70,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.api.response.submodel.GetSubmodelElementByPathResponse; import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ValueMappingException; import de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue; +import de.fraunhofer.iosb.ilt.faaast.service.model.value.BasicEventElementValue; import de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue; import de.fraunhofer.iosb.ilt.faaast.service.model.value.EntityValue; import de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue; @@ -481,6 +485,7 @@ protected void modifyMapper(JsonMapper mapper) { mapper.addMixIn(AbstractSubmodelInterfaceRequest.class, AbstractSubmodelInterfaceRequestMixin.class); mapper.addMixIn(ReferenceElementValue.class, ReferenceElementValueMixin.class); mapper.addMixIn(Page.class, PageMixin.class); + mapper.addMixIn(Message.class, MessageMixin.class); mapper.addMixIn(InvokeOperationRequest.class, InvokeOperationRequestMixin.class); SimpleModule module = new SimpleModule() { @Override @@ -524,6 +529,7 @@ public com.fasterxml.jackson.databind.JsonDeserializer modifyCollectionDeseri module.addDeserializer(TypedValue.class, new TypedValueDeserializer()); module.addDeserializer(PropertyValue.class, new PropertyValueDeserializer()); module.addDeserializer(AnnotatedRelationshipElementValue.class, new AnnotatedRelationshipElementValueDeserializer()); + module.addDeserializer(BasicEventElementValue.class, new BasicEventElementValueDeserializer()); module.addDeserializer(SubmodelElementCollectionValue.class, new SubmodelElementCollectionValueDeserializer()); module.addDeserializer(SubmodelElementListValue.class, new SubmodelElementListValueDeserializer()); module.addDeserializer(MultiLanguagePropertyValue.class, new MultiLanguagePropertyValueDeserializer()); diff --git a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonApiSerializer.java b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonApiSerializer.java index f6df29159..886587c72 100644 --- a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonApiSerializer.java +++ b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonApiSerializer.java @@ -23,6 +23,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.AbstractRequestWithModifierMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.AbstractSubmodelInterfaceRequestMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.InvokeOperationRequestMixin; +import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.MessageMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.PageMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.ResultMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.ServiceSpecificationProfileMixin; @@ -31,6 +32,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.serializer.ModifierAwareSerializer; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.serializer.PagingMetadataSerializer; import de.fraunhofer.iosb.ilt.faaast.service.model.ServiceSpecificationProfile; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.Message; import de.fraunhofer.iosb.ilt.faaast.service.model.api.Result; import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; @@ -38,6 +40,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.AbstractRequestWithModifier; import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.AbstractSubmodelInterfaceRequest; import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.submodel.InvokeOperationRequest; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.UnsupportedModifierException; import de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue; import de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue; import de.fraunhofer.iosb.ilt.faaast.service.util.CollectionHelper; @@ -79,6 +82,7 @@ protected void modifyMapper(JsonMapper mapper) { mapper.addMixIn(AbstractSubmodelInterfaceRequest.class, AbstractSubmodelInterfaceRequestMixin.class); mapper.addMixIn(ReferenceElementValue.class, ReferenceElementValueMixin.class); mapper.addMixIn(Page.class, PageMixin.class); + mapper.addMixIn(Message.class, MessageMixin.class); mapper.addMixIn(InvokeOperationRequest.class, InvokeOperationRequestMixin.class); mapper.addMixIn(Result.class, ResultMixin.class); mapper.addMixIn(ServiceSpecificationProfile.class, ServiceSpecificationProfileMixin.class); @@ -86,7 +90,7 @@ protected void modifyMapper(JsonMapper mapper) { @Override - public String write(Object obj, OutputModifier modifier) throws SerializationException { + public String write(Object obj, OutputModifier modifier) throws SerializationException, UnsupportedModifierException { Ensure.requireNonNull(modifier, "modifier must be non-null"); switch (modifier.getContent()) { case VALUE: @@ -103,7 +107,7 @@ public String write(Object obj, OutputModifier modifier) throws SerializationExc } - private String serializeNormal(Object obj, OutputModifier modifier) throws SerializationException { + private String serializeNormal(Object obj, OutputModifier modifier) throws SerializationException, UnsupportedModifierException { if (obj != null && ElementValue.class.isAssignableFrom(obj.getClass())) { return valueOnlySerializer.write(obj, modifier.getLevel(), modifier.getExtent()); } diff --git a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonEventDeserializer.java b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonEventDeserializer.java index 5c239e128..372a20ebc 100644 --- a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonEventDeserializer.java +++ b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonEventDeserializer.java @@ -18,6 +18,7 @@ import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.databind.module.SimpleModule; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException; +import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.deserializer.BasicEventElementValueDeserializer; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.deserializer.EntityValueDeserializer; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.deserializer.EnumDeserializer; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.deserializer.MultiLanguagePropertyValueDeserializer; @@ -31,6 +32,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.value.ReferenceElementValueMixin; import de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.EventMessage; import de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue; +import de.fraunhofer.iosb.ilt.faaast.service.model.value.BasicEventElementValue; import de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue; import de.fraunhofer.iosb.ilt.faaast.service.model.value.EntityValue; import de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue; @@ -65,6 +67,7 @@ protected void modifyMapper(JsonMapper mapper) { module.addDeserializer(TypedValue.class, new TypedValueDeserializer()); module.addDeserializer(PropertyValue.class, new PropertyValueDeserializer()); module.addDeserializer(AnnotatedRelationshipElementValue.class, new AnnotatedRelationshipElementValueDeserializer()); + module.addDeserializer(BasicEventElementValue.class, new BasicEventElementValueDeserializer()); module.addDeserializer(SubmodelElementCollectionValue.class, new SubmodelElementCollectionValueDeserializer()); module.addDeserializer(MultiLanguagePropertyValue.class, new MultiLanguagePropertyValueDeserializer()); module.addDeserializer(EntityValue.class, new EntityValueDeserializer()); diff --git a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonEventSerializer.java b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonEventSerializer.java index f29552f4a..ad18373aa 100644 --- a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonEventSerializer.java +++ b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonEventSerializer.java @@ -25,6 +25,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.event.EventMessageMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.value.ReferenceElementValueMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.serializer.AnnotatedRelationshipElementValueSerializer; +import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.serializer.BasicEventElementValueSerializer; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.serializer.BlobValueSerializer; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.serializer.EnumSerializer; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.serializer.FileValueSerializer; @@ -33,6 +34,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.serializer.event.TypedValueSerializer; import de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.EventMessage; import de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue; +import de.fraunhofer.iosb.ilt.faaast.service.model.value.BasicEventElementValue; import de.fraunhofer.iosb.ilt.faaast.service.model.value.BlobValue; import de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue; import de.fraunhofer.iosb.ilt.faaast.service.model.value.FileValue; @@ -74,6 +76,7 @@ public JsonSerializer modifySerializer(SerializationConfig config, BeanDescri }); module.addSerializer(BlobValue.class, new BlobValueSerializer()); module.addSerializer(FileValue.class, new FileValueSerializer()); + module.addSerializer(BasicEventElementValue.class, new BasicEventElementValueSerializer()); module.addSerializer(MultiLanguagePropertyValue.class, new MultiLanguagePropertyValueSerializer()); module.addSerializer(AnnotatedRelationshipElementValue.class, new AnnotatedRelationshipElementValueSerializer()); module.addSerializer(TypedValue.class, new TypedValueSerializer()); diff --git a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonFieldNames.java b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonFieldNames.java index 7b9e4ac99..48cb0e3b2 100644 --- a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonFieldNames.java +++ b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/JsonFieldNames.java @@ -24,6 +24,8 @@ public class JsonFieldNames { public static final String ANNOTATED_RELATIONSHIP_ELEMENT_VALUE_FIRST = "first"; public static final String ANNOTATED_RELATIONSHIP_ELEMENT_VALUE_SECOND = "second"; + public static final String BASIC_EVENT_ELEMENT_OBSERVED = "observed"; + public static final String BLOB_VALUE_CONTENT_TYPE = "contentType"; public static final String BLOB_VALUE_VALUE = "value"; diff --git a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/MetadataJsonSerializer.java b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/MetadataJsonSerializer.java index 72e05916e..611ca4114 100644 --- a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/MetadataJsonSerializer.java +++ b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/MetadataJsonSerializer.java @@ -19,6 +19,7 @@ import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.databind.module.SimpleModule; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.SerializationException; +import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.MessageMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.PageMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.metadata.AnnotatedRelationshipElementMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.metadata.AssetAdministrationShellMixin; @@ -34,6 +35,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.metadata.SubmodelElementListMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.metadata.SubmodelMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.serializer.PagingMetadataSerializer; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.Message; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.PagingMetadata; import de.fraunhofer.iosb.ilt.faaast.service.util.CollectionHelper; @@ -86,6 +88,7 @@ protected void modifyMapper(JsonMapper mapper) { mapper.addMixIn(Blob.class, BlobMixin.class); mapper.addMixIn(File.class, FileMixin.class); mapper.addMixIn(Page.class, PageMixin.class); + mapper.addMixIn(Message.class, MessageMixin.class); SimpleModule module = new SimpleModule(); module.addSerializer(PagingMetadata.class, new PagingMetadataSerializer()); mapper.registerModule(module); diff --git a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/PathJsonSerializer.java b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/PathJsonSerializer.java index 61f664b70..e36f6635e 100644 --- a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/PathJsonSerializer.java +++ b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/PathJsonSerializer.java @@ -20,6 +20,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.IdShortPath; import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Level; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.UnsupportedModifierException; import java.util.List; import java.util.Objects; import java.util.stream.Collectors; @@ -49,8 +50,9 @@ public JsonMapper getMapper() { * @param obj the object to serialize * @return the string serialization of the object * @throws SerializationException if serialization fails + * @throws UnsupportedModifierException if the modifier is not supported for this element */ - public String write(IdShortPath parent, Object obj) throws SerializationException { + public String write(IdShortPath parent, Object obj) throws SerializationException, UnsupportedModifierException { return write(parent, obj, Level.DEFAULT); } @@ -64,8 +66,9 @@ public String write(IdShortPath parent, Object obj) throws SerializationExceptio * @param level level of serialization * @return JSON array of all idShort paths subject to serialization according to specification. * @throws SerializationException if serialization fails + * @throws UnsupportedModifierException if the modifier is not supported for this element */ - public String write(IdShortPath parent, Object obj, Level level) throws SerializationException { + public String write(IdShortPath parent, Object obj, Level level) throws SerializationException, UnsupportedModifierException { if (Objects.nonNull(obj) && Page.class.isAssignableFrom(obj.getClass())) { Page page = (Page) obj; return new JsonApiSerializer().write(Page.of( diff --git a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/ValueOnlyJsonSerializer.java b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/ValueOnlyJsonSerializer.java index 915d8c5e3..0b4549bd1 100644 --- a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/ValueOnlyJsonSerializer.java +++ b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/ValueOnlyJsonSerializer.java @@ -28,6 +28,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.dataformat.SerializationException; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.AbstractRequestWithModifierMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.AbstractSubmodelInterfaceRequestMixin; +import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.MessageMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.PageMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.ResponseMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.ResultMixin; @@ -41,6 +42,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.value.SubmodelElementListValueMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins.value.TypedValueMixin; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.serializer.AnnotatedRelationshipElementValueSerializer; +import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.serializer.BasicEventElementValueSerializer; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.serializer.BlobValueSerializer; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.serializer.EntityValueSerializer; import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.serializer.EnumSerializer; @@ -53,6 +55,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.api.Message; import de.fraunhofer.iosb.ilt.faaast.service.model.api.Response; import de.fraunhofer.iosb.ilt.faaast.service.model.api.Result; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Content; import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Extent; import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Level; import de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult; @@ -62,7 +65,9 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.AbstractSubmodelInterfaceRequest; import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.submodel.InvokeOperationRequest; import de.fraunhofer.iosb.ilt.faaast.service.model.api.response.submodel.GetOperationAsyncResultResponse; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.UnsupportedContentModifierException; import de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue; +import de.fraunhofer.iosb.ilt.faaast.service.model.value.BasicEventElementValue; import de.fraunhofer.iosb.ilt.faaast.service.model.value.BlobValue; import de.fraunhofer.iosb.ilt.faaast.service.model.value.EntityValue; import de.fraunhofer.iosb.ilt.faaast.service.model.value.FileValue; @@ -119,8 +124,9 @@ public JsonMapper getMapper() { * @param obj the object to serialize * @return the serialized object * @throws SerializationException if serialization fails + * @throws UnsupportedContentModifierException if obj does not support valueOnly serialization */ - public String write(Object obj) throws SerializationException { + public String write(Object obj) throws SerializationException, UnsupportedContentModifierException { return write(obj, Level.DEFAULT, Extent.DEFAULT); } @@ -133,8 +139,9 @@ public String write(Object obj) throws SerializationException { * @param level the level to use for serialization * @return the serialized object * @throws SerializationException if serialization fails + * @throws UnsupportedContentModifierException if obj does not support valueOnly serialization */ - public String write(Object obj, Level level) throws SerializationException { + public String write(Object obj, Level level) throws SerializationException, UnsupportedContentModifierException { return write(obj, level, Extent.DEFAULT); } @@ -147,8 +154,9 @@ public String write(Object obj, Level level) throws SerializationException { * @param extent the extent to use for serialization * @return the serialized object * @throws SerializationException if serialization fails + * @throws UnsupportedContentModifierException if obj does not support valueOnly serialization */ - public String write(Object obj, Extent extent) throws SerializationException { + public String write(Object obj, Extent extent) throws SerializationException, UnsupportedContentModifierException { return write(obj, Level.DEFAULT, extent); } @@ -161,15 +169,13 @@ public String write(Object obj, Extent extent) throws SerializationException { * @param extend the extent to use for serialization * @return the serialized object * @throws SerializationException if serialization fails + * @throws UnsupportedContentModifierException if obj does not support valueOnly serialization */ - public String write(Object obj, Level level, Extent extend) throws SerializationException { + public String write(Object obj, Level level, Extent extend) throws SerializationException, UnsupportedContentModifierException { if (Objects.nonNull(obj) && !ElementValueHelper.isValueOnlySupported(obj) && !isExplicitelyAcceptedType(obj.getClass())) { - throw new SerializationException( - String.format( - "Provided element is not supported by value-only serialization (type: %s). Supported types are: all subtypes of DataElement, SubmodelElementCollection, ReferenceElement, RelationshipElement, AnnotatedRelationshipElement, and Entity as well as all subtypes of ElementValue", - obj.getClass())); + throw new UnsupportedContentModifierException(Content.VALUE, obj.getClass()); } try { return wrapper.getMapper().writer() @@ -209,6 +215,7 @@ protected JsonMapper modifyMapper(JsonMapper mapper) { mapper.addMixIn(AbstractDateTimeValue.class, AbstractDateTimeValueMixIn.class); mapper.addMixIn(ReferenceElementValue.class, ReferenceElementValueMixin.class); mapper.addMixIn(Page.class, PageMixin.class); + mapper.addMixIn(Message.class, MessageMixin.class); mapper.addMixIn(AbstractRequestWithModifier.class, AbstractRequestWithModifierMixin.class); mapper.addMixIn(AbstractSubmodelInterfaceRequest.class, AbstractSubmodelInterfaceRequestMixin.class); mapper.addMixIn(InvokeOperationRequest.class, InvokeOperationRequestValueMixin.class); @@ -221,6 +228,7 @@ protected JsonMapper modifyMapper(JsonMapper mapper) { module.addSerializer(MultiLanguagePropertyValue.class, new MultiLanguagePropertyValueSerializer()); module.addSerializer(FileValue.class, new FileValueSerializer()); module.addSerializer(BlobValue.class, new BlobValueSerializer()); + module.addSerializer(BasicEventElementValue.class, new BasicEventElementValueSerializer()); module.addSerializer(AnnotatedRelationshipElementValue.class, new AnnotatedRelationshipElementValueSerializer()); module.addSerializer(EntityValue.class, new EntityValueSerializer()); module.addSerializer(SubmodelElement.class, new SubmodelElementValueSerializer()); diff --git a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/deserializer/BasicEventElementValueDeserializer.java b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/deserializer/BasicEventElementValueDeserializer.java new file mode 100644 index 000000000..ca3dc460c --- /dev/null +++ b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/deserializer/BasicEventElementValueDeserializer.java @@ -0,0 +1,50 @@ +/* + * 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.service.dataformat.json.deserializer; + +import com.fasterxml.jackson.core.JacksonException; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonNode; +import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.JsonFieldNames; +import de.fraunhofer.iosb.ilt.faaast.service.model.value.BasicEventElementValue; +import java.io.IOException; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; + + +/** + * Deserializer for {@link de.fraunhofer.iosb.ilt.faaast.service.model.value.BasicEventElementValue}. + */ +public class BasicEventElementValueDeserializer extends ContextAwareElementValueDeserializer { + + public BasicEventElementValueDeserializer() { + this(null); + } + + + public BasicEventElementValueDeserializer(Class type) { + super(type); + } + + + @Override + public BasicEventElementValue deserializeValue(JsonNode node, DeserializationContext context) throws IOException, JacksonException { + BasicEventElementValue.Builder builder = new BasicEventElementValue.Builder(); + if (node.has(JsonFieldNames.BASIC_EVENT_ELEMENT_OBSERVED)) { + builder.observed(context.readTreeAsValue(node.get(JsonFieldNames.BASIC_EVENT_ELEMENT_OBSERVED), Reference.class)); + } + return builder.build(); + } + +} diff --git a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/mixins/MessageMixin.java b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/mixins/MessageMixin.java new file mode 100644 index 000000000..707398f58 --- /dev/null +++ b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/mixins/MessageMixin.java @@ -0,0 +1,28 @@ +/* + * 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.service.dataformat.json.mixins; + +import com.fasterxml.jackson.annotation.JsonInclude; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.Message; + + +/** + * Mixing for {@link Message}. + */ +public interface MessageMixin { + + @JsonInclude(JsonInclude.Include.NON_EMPTY) + public String getCode(); +} diff --git a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/mixins/ResultMixin.java b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/mixins/ResultMixin.java index 900920a74..1049d13fa 100644 --- a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/mixins/ResultMixin.java +++ b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/mixins/ResultMixin.java @@ -14,10 +14,8 @@ */ package de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.mixins; -import com.fasterxml.jackson.annotation.JsonUnwrapped; -import de.fraunhofer.iosb.ilt.faaast.service.model.api.Message; +import com.fasterxml.jackson.annotation.JsonInclude; import de.fraunhofer.iosb.ilt.faaast.service.model.api.Result; -import java.util.List; /** @@ -25,6 +23,6 @@ */ public interface ResultMixin { - @JsonUnwrapped - public List getMessages(); + @JsonInclude(JsonInclude.Include.NON_NULL) + public String getCode(); } diff --git a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/serializer/BasicEventElementValueSerializer.java b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/serializer/BasicEventElementValueSerializer.java new file mode 100644 index 000000000..df033d112 --- /dev/null +++ b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/serializer/BasicEventElementValueSerializer.java @@ -0,0 +1,53 @@ +/* + * 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.service.dataformat.json.serializer; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; +import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.JsonFieldNames; +import de.fraunhofer.iosb.ilt.faaast.service.model.value.BasicEventElementValue; +import java.io.IOException; +import java.util.Objects; + + +/** + * Serializer for {@link de.fraunhofer.iosb.ilt.faaast.service.model.value.BasicEventElementValue}. + */ +public class BasicEventElementValueSerializer extends StdSerializer { + + public BasicEventElementValueSerializer() { + this(null); + } + + + public BasicEventElementValueSerializer(Class type) { + super(type); + } + + + @Override + public void serialize(BasicEventElementValue value, JsonGenerator generator, SerializerProvider provider) throws IOException, JsonProcessingException { + if (Objects.nonNull(value)) { + generator.writeStartObject(); + if (Objects.nonNull(value.getObserved())) { + provider.defaultSerializeField(JsonFieldNames.BASIC_EVENT_ELEMENT_OBSERVED, value.getObserved(), generator); + } + generator.writeEndObject(); + } + } + +} diff --git a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/serializer/PagingMetadataSerializer.java b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/serializer/PagingMetadataSerializer.java index e7f8a24d0..a6eeee3a2 100644 --- a/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/serializer/PagingMetadataSerializer.java +++ b/dataformat/json/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/dataformat/json/serializer/PagingMetadataSerializer.java @@ -21,6 +21,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.util.EncodingHelper; import de.fraunhofer.iosb.ilt.faaast.service.util.FaaastConstants; import java.io.IOException; +import java.util.Objects; /** @@ -41,7 +42,9 @@ public PagingMetadataSerializer(Class t) { @Override public void serialize(PagingMetadata value, JsonGenerator generator, SerializerProvider provider) throws IOException { generator.writeStartObject(); - generator.writeStringField(FaaastConstants.CURSOR, EncodingHelper.base64UrlEncode(value.getCursor())); + if (Objects.nonNull(value.getCursor())) { + generator.writeStringField(FaaastConstants.CURSOR, EncodingHelper.base64UrlEncode(value.getCursor())); + } generator.writeEndObject(); } } diff --git a/dataformat/json/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/serialization/json/JsonSerializerTest.java b/dataformat/json/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/serialization/json/JsonSerializerTest.java index ffcd3b585..2c417a761 100644 --- a/dataformat/json/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/serialization/json/JsonSerializerTest.java +++ b/dataformat/json/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/serialization/json/JsonSerializerTest.java @@ -22,6 +22,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.PagingMetadata; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.UnsupportedModifierException; import de.fraunhofer.iosb.ilt.faaast.service.serialization.json.fixture.ValueOnlyExamples; import java.io.File; import java.io.IOException; @@ -100,7 +101,7 @@ public void testReferableListSerialization() throws Exception { @Test - public void testSubmodelElementListValueOnly() throws SerializationException, JSONException { + public void testSubmodelElementListValueOnly() throws SerializationException, JSONException, UnsupportedModifierException { Map data = Map.of(ValueOnlyExamples.PROPERTY_STRING, ValueOnlyExamples.PROPERTY_STRING_FILE, ValueOnlyExamples.RANGE_INT, ValueOnlyExamples.RANGE_INT_FILE); String expected = data.entrySet().stream() @@ -122,13 +123,13 @@ public void testSubmodelElementListValueOnly() throws SerializationException, JS @Test - public void testEnumsWithCustomNaming() throws SerializationException { + public void testEnumsWithCustomNaming() throws SerializationException, UnsupportedModifierException { Assert.assertEquals("\"SuccessCreated\"", serializer.write(StatusCode.SUCCESS_CREATED)); } @Test - public void testEnumsWithoutCustomNaming() throws SerializationException { + public void testEnumsWithoutCustomNaming() throws SerializationException, UnsupportedModifierException { Assert.assertEquals("\"UTF-8\"", serializer.write(StandardCharsets.UTF_8)); } @@ -161,7 +162,7 @@ private void assertEquals(String expected, String actual) throws JSONException { @Test - public void testPageWithoutCursor() throws SerializationException, JSONException { + public void testPageWithoutCursor() throws SerializationException, JSONException, UnsupportedModifierException { Page page = Page. builder() .metadata(PagingMetadata.builder() .build()) @@ -180,7 +181,6 @@ public void testPageWithoutCursor() throws SerializationException, JSONException + " \"idShort\" : \"idShort\"\n" + " } ],\n" + " \"paging_metadata\" : {\n" - + " \"cursor\" : null\n" + " }\n" + "}"; JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE); @@ -188,7 +188,7 @@ public void testPageWithoutCursor() throws SerializationException, JSONException @Test - public void testPageWithCursor() throws SerializationException, JSONException { + public void testPageWithCursor() throws SerializationException, JSONException, UnsupportedModifierException { Page page = Page. builder() .metadata(PagingMetadata.builder() .cursor("foo") diff --git a/dataformat/json/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/serialization/json/PathJsonSerializerTest.java b/dataformat/json/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/serialization/json/PathJsonSerializerTest.java index b2bc843e3..80de4fc91 100644 --- a/dataformat/json/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/serialization/json/PathJsonSerializerTest.java +++ b/dataformat/json/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/serialization/json/PathJsonSerializerTest.java @@ -20,6 +20,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.PathJsonSerializer; import de.fraunhofer.iosb.ilt.faaast.service.model.IdShortPath; import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Level; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.UnsupportedModifierException; import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ValueMappingException; import de.fraunhofer.iosb.ilt.faaast.service.serialization.json.util.Path; import java.io.IOException; @@ -57,7 +58,7 @@ public class PathJsonSerializerTest { private static final String ID_PROPERTY_3 = "property3"; @Test - public void testProperty() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testProperty() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedModifierException { Object input = new DefaultProperty.Builder() .idShort(ID_PROPERTY_1) .build(); @@ -69,7 +70,7 @@ public void testProperty() throws SerializationException, JSONException, IOExcep @Test - public void testCollection() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testCollection() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedModifierException { Object input = new DefaultSubmodelElementCollection.Builder() .idShort(ID_COLLECTION_1) .value(new DefaultProperty.Builder() @@ -105,7 +106,7 @@ public void testCollection() throws SerializationException, JSONException, IOExc @Test - public void testCollectionWithParent() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testCollectionWithParent() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedModifierException { Object input = new DefaultSubmodelElementCollection.Builder() .idShort(ID_COLLECTION_1) .value(new DefaultProperty.Builder() @@ -149,7 +150,7 @@ public void testCollectionWithParent() throws SerializationException, JSONExcept @Test - public void testListProperty() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testListProperty() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedModifierException { Object input = new DefaultSubmodelElementList.Builder() .idShort(ID_COLLECTION_1) .value(new DefaultProperty.Builder() @@ -170,7 +171,7 @@ public void testListProperty() throws SerializationException, JSONException, IOE @Test - public void testListComplex() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testListComplex() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedModifierException { Object input = new DefaultSubmodel.Builder() .idShort("Submodel") .submodelElements(new DefaultProperty.Builder() @@ -300,7 +301,7 @@ public void testListComplex() throws SerializationException, JSONException, IOEx @Test - public void testSubmodelEmpty() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testSubmodelEmpty() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedModifierException { Object input = new DefaultSubmodel.Builder() .idShort(ID_SUBMODEL_1) .build(); @@ -311,7 +312,7 @@ public void testSubmodelEmpty() throws SerializationException, JSONException, IO @Test - public void testSubmodel() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testSubmodel() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedModifierException { Object input = new DefaultSubmodel.Builder() .idShort(ID_SUBMODEL_1) .submodelElements(new DefaultProperty.Builder() @@ -340,7 +341,7 @@ public void testSubmodel() throws SerializationException, JSONException, IOExcep @Test - public void testComplex() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testComplex() throws SerializationException, JSONException, IOException, ValueMappingException, JsonProcessingException, UnsupportedModifierException { Object input = new DefaultSubmodel.Builder() .idShort("TestSubmodel3") .id("https://acplt.org/Test_Submodel") @@ -426,21 +427,23 @@ public void testComplex() throws SerializationException, JSONException, IOExcept } - private void assertEquals(IdShortPath parent, Object obj, Path path, Level level) throws SerializationException, JsonProcessingException, JSONException { + private void assertEquals(IdShortPath parent, Object obj, Path path, Level level) + throws SerializationException, JsonProcessingException, JSONException, UnsupportedModifierException { String actual = serializer.write(parent, obj, level); String expected = new ObjectMapper().writeValueAsString(path.getPaths()); JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE); } - private void assertEquals(IdShortPath parent, Object obj, List expectedPaths, Level level) throws SerializationException, JsonProcessingException, JSONException { + private void assertEquals(IdShortPath parent, Object obj, List expectedPaths, Level level) + throws SerializationException, JsonProcessingException, JSONException, UnsupportedModifierException { String actual = serializer.write(parent, obj, level); String expected = new ObjectMapper().writeValueAsString(expectedPaths); JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE); } - private void assertEquals(IdShortPath parent, Object obj, Path path) throws SerializationException, JsonProcessingException, JSONException { + private void assertEquals(IdShortPath parent, Object obj, Path path) throws SerializationException, JsonProcessingException, JSONException, UnsupportedModifierException { assertEquals(parent, obj, path.asCorePath(), Level.CORE); assertEquals(parent, obj, path, Level.DEEP); } diff --git a/dataformat/json/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/serialization/json/ValueOnlyJsonSerializerTest.java b/dataformat/json/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/serialization/json/ValueOnlyJsonSerializerTest.java index d08c2837e..07a1be59e 100644 --- a/dataformat/json/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/serialization/json/ValueOnlyJsonSerializerTest.java +++ b/dataformat/json/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/serialization/json/ValueOnlyJsonSerializerTest.java @@ -18,6 +18,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.ValueOnlyJsonSerializer; import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Extent; import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Level; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.UnsupportedContentModifierException; import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ValueMappingException; import de.fraunhofer.iosb.ilt.faaast.service.model.value.mapper.ElementValueMapper; import de.fraunhofer.iosb.ilt.faaast.service.serialization.json.fixture.ValueOnlyExamples; @@ -43,14 +44,20 @@ public class ValueOnlyJsonSerializerTest { ValueOnlyJsonSerializer serializer = new ValueOnlyJsonSerializer(); @Test - public void testAnnotatedRelationshipElement() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testAnnotatedRelationshipElement() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedContentModifierException { assertEquals(ValueOnlyExamples.ANNOTATED_RELATIONSHIP_ELEMENT_FILE, ValueOnlyExamples.ANNOTATED_RELATIONSHIP_ELEMENT); assertValue(ValueOnlyExamples.ANNOTATED_RELATIONSHIP_ELEMENT_FILE, ValueOnlyExamples.ANNOTATED_RELATIONSHIP_ELEMENT); } @Test - public void testBlob() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testBasicEventElement() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedContentModifierException { + assertEquals(ValueOnlyExamples.BASIC_EVENT_ELEMENT_FILE, ValueOnlyExamples.BASIC_EVENT_ELEMENT); + } + + + @Test + public void testBlob() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedContentModifierException { assertEquals(ValueOnlyExamples.BLOB_FILE_WITH_BLOB, ValueOnlyExamples.BLOB, Extent.WITH_BLOB_VALUE); assertEquals(ValueOnlyExamples.BLOB_FILE_WITHOUT_BLOB, ValueOnlyExamples.BLOB, Extent.WITHOUT_BLOB_VALUE); assertValue(ValueOnlyExamples.BLOB_FILE_WITH_BLOB, ValueOnlyExamples.BLOB, Extent.WITH_BLOB_VALUE); @@ -59,14 +66,14 @@ public void testBlob() throws SerializationException, JSONException, IOException @Test - public void testSubmodelElementCollection() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testSubmodelElementCollection() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedContentModifierException { assertEquals(ValueOnlyExamples.SUBMODEL_ELEMENT_COLLECTION_FILE, ValueOnlyExamples.SUBMODEL_ELEMENT_COLLECTION); assertValue(ValueOnlyExamples.SUBMODEL_ELEMENT_COLLECTION_FILE, ValueOnlyExamples.SUBMODEL_ELEMENT_COLLECTION); } @Test - public void testSubmodelElementList() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testSubmodelElementList() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedContentModifierException { assertEquals(ValueOnlyExamples.SUBMODEL_ELEMENT_LIST_SIMPLE_FILE, ValueOnlyExamples.SUBMODEL_ELEMENT_LIST_SIMPLE); assertValue(ValueOnlyExamples.SUBMODEL_ELEMENT_LIST_SIMPLE_FILE, ValueOnlyExamples.SUBMODEL_ELEMENT_LIST_SIMPLE); assertEquals(ValueOnlyExamples.SUBMODEL_ELEMENT_LIST_FILE, ValueOnlyExamples.SUBMODEL_ELEMENT_LIST); @@ -75,60 +82,60 @@ public void testSubmodelElementList() throws SerializationException, JSONExcepti @Test - public void testEntity() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testEntity() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedContentModifierException { assertEquals(ValueOnlyExamples.ENTITY_FILE, ValueOnlyExamples.ENTITY); assertValue(ValueOnlyExamples.ENTITY_FILE, ValueOnlyExamples.ENTITY); } @Test - public void testFile() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testFile() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedContentModifierException { assertEquals(ValueOnlyExamples.FILE_FILE, ValueOnlyExamples.FILE); assertValue(ValueOnlyExamples.FILE_FILE, ValueOnlyExamples.FILE); } @Test - public void testInvokeOperationRequest() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testInvokeOperationRequest() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedContentModifierException { assertEquals(ValueOnlyExamples.INVOKE_OPERATION_REQUEST_FILE, ValueOnlyExamples.INVOKE_OPERATION_SYNC_REQUEST); } @Test - public void testGetOperationAsyncResultResponse() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testGetOperationAsyncResultResponse() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedContentModifierException { assertEquals(ValueOnlyExamples.GET_OPERATION_ASYNC_RESULT_RESPONSE_FILE, ValueOnlyExamples.GET_OPERATION_ASYNC_RESULT_RESPONSE); } @Test - public void testMultiLanguageProperty() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testMultiLanguageProperty() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedContentModifierException { assertEquals(ValueOnlyExamples.MULTI_LANGUAGE_PROPERTY_FILE, ValueOnlyExamples.MULTI_LANGUAGE_PROPERTY); assertValue(ValueOnlyExamples.MULTI_LANGUAGE_PROPERTY_FILE, ValueOnlyExamples.MULTI_LANGUAGE_PROPERTY); } @Test(expected = SerializationException.class) - public void testNonValue() throws SerializationException, JSONException, IOException { + public void testNonValue() throws SerializationException, JSONException, IOException, UnsupportedContentModifierException { serializer.write(new DefaultProperty.Builder().build()); } @Test - public void testProperty() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testProperty() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedContentModifierException { assertEquals(ValueOnlyExamples.PROPERTY_STRING_FILE, ValueOnlyExamples.PROPERTY_STRING); assertValue(ValueOnlyExamples.PROPERTY_STRING_FILE, ValueOnlyExamples.PROPERTY_STRING); } @Test - public void testPropertyGDay() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testPropertyGDay() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedContentModifierException { assertEquals(ValueOnlyExamples.PROPERTY_GDAY_FILE, ValueOnlyExamples.PROPERTY_GDAY); assertValue(ValueOnlyExamples.PROPERTY_GDAY_FILE, ValueOnlyExamples.PROPERTY_GDAY); } @Test - public void testList() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testList() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedContentModifierException { Map data = Map.of(ValueOnlyExamples.PROPERTY_STRING, ValueOnlyExamples.PROPERTY_STRING_FILE, ValueOnlyExamples.RANGE_INT, ValueOnlyExamples.RANGE_INT_FILE); String expected = data.entrySet().stream() @@ -151,7 +158,7 @@ public void testList() throws SerializationException, JSONException, IOException @Test - public void testArray() throws SerializationException, JSONException, IOException { + public void testArray() throws SerializationException, JSONException, IOException, UnsupportedContentModifierException { Object[] array = new Object[] { ValueOnlyExamples.PROPERTY_STRING, ValueOnlyExamples.RANGE_INT @@ -165,7 +172,7 @@ public void testArray() throws SerializationException, JSONException, IOExceptio @Test - public void testMap() throws SerializationException, JSONException, IOException { + public void testMap() throws SerializationException, JSONException, IOException, UnsupportedContentModifierException { Map map = Map.of("first", ValueOnlyExamples.PROPERTY_STRING, "second", ValueOnlyExamples.RANGE_INT); String expected = String.format("{ \"first\": %s,\"second\":%s}", @@ -177,14 +184,14 @@ public void testMap() throws SerializationException, JSONException, IOException @Test - public void testRange() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testRange() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedContentModifierException { assertEquals(ValueOnlyExamples.RANGE_DOUBLE_FILE, ValueOnlyExamples.RANGE_DOUBLE); assertValue(ValueOnlyExamples.RANGE_DOUBLE_FILE, ValueOnlyExamples.RANGE_DOUBLE); } @Test - public void testReferenceElement() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testReferenceElement() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedContentModifierException { assertEquals(ValueOnlyExamples.REFERENCE_ELEMENT_GLOBAL_FILE, ValueOnlyExamples.REFERENCE_ELEMENT_GLOBAL); assertEquals(ValueOnlyExamples.REFERENCE_ELEMENT_MODEL_FILE, ValueOnlyExamples.REFERENCE_ELEMENT_MODEL); assertValue(ValueOnlyExamples.REFERENCE_ELEMENT_GLOBAL_FILE, ValueOnlyExamples.REFERENCE_ELEMENT_GLOBAL); @@ -193,56 +200,60 @@ public void testReferenceElement() throws SerializationException, JSONException, @Test - public void testRelationshipElement() throws SerializationException, JSONException, IOException, ValueMappingException { + public void testRelationshipElement() throws SerializationException, JSONException, IOException, ValueMappingException, UnsupportedContentModifierException { assertEquals(ValueOnlyExamples.RELATIONSHIP_ELEMENT_FILE, ValueOnlyExamples.RELATIONSHIP_ELEMENT); assertValue(ValueOnlyExamples.RELATIONSHIP_ELEMENT_FILE, ValueOnlyExamples.RELATIONSHIP_ELEMENT); } @Test - public void testSubmodel() throws SerializationException, JSONException, IOException { + public void testSubmodel() throws SerializationException, JSONException, IOException, UnsupportedContentModifierException { assertEquals(ValueOnlyExamples.SUBMODEL_FILE, ValueOnlyExamples.SUBMODEL); } - private void assertEquals(File expectedFile, Object value) throws JSONException, IOException, SerializationException { + private void assertEquals(File expectedFile, Object value) throws JSONException, IOException, SerializationException, UnsupportedContentModifierException { assertEquals(expectedFile, value, Level.DEFAULT, Extent.DEFAULT); } - private void assertEquals(String expected, Object value) throws JSONException, IOException, SerializationException { + private void assertEquals(String expected, Object value) throws JSONException, IOException, SerializationException, UnsupportedContentModifierException { assertEquals(expected, value, Level.DEFAULT, Extent.DEFAULT); } - private void assertEquals(File expectedFile, Object value, Level level, Extent extend) throws JSONException, IOException, SerializationException { + private void assertEquals(File expectedFile, Object value, Level level, Extent extend) + throws JSONException, IOException, SerializationException, UnsupportedContentModifierException { assertEquals(Files.readString(expectedFile.toPath()), value, level, extend); } - private void assertEquals(File expectedFile, Object value, Extent extend) throws JSONException, IOException, SerializationException { + private void assertEquals(File expectedFile, Object value, Extent extend) throws JSONException, IOException, SerializationException, UnsupportedContentModifierException { assertEquals(Files.readString(expectedFile.toPath()), value, Level.DEFAULT, extend); } - private void assertEquals(String expected, Object value, Level level, Extent extend) throws JSONException, IOException, SerializationException { + private void assertEquals(String expected, Object value, Level level, Extent extend) + throws JSONException, IOException, SerializationException, UnsupportedContentModifierException { String actual = serializer.write(value, level, extend); JSONAssert.assertEquals(expected, actual, JSONCompareMode.NON_EXTENSIBLE); } - private void assertValue(File expectedFile, SubmodelElement submodelElement) throws JSONException, IOException, SerializationException, ValueMappingException { + private void assertValue(File expectedFile, SubmodelElement submodelElement) + throws JSONException, IOException, SerializationException, ValueMappingException, UnsupportedContentModifierException { assertValue(expectedFile, submodelElement, Level.DEFAULT, Extent.DEFAULT); } - private void assertValue(File expectedFile, SubmodelElement submodelElement, Extent extend) throws JSONException, IOException, SerializationException, ValueMappingException { + private void assertValue(File expectedFile, SubmodelElement submodelElement, Extent extend) + throws JSONException, IOException, SerializationException, ValueMappingException, UnsupportedContentModifierException { assertValue(expectedFile, submodelElement, Level.DEFAULT, extend); } private void assertValue(File expectedFile, SubmodelElement submodelElement, Level level, Extent extend) - throws JSONException, IOException, SerializationException, ValueMappingException { + throws JSONException, IOException, SerializationException, ValueMappingException, UnsupportedContentModifierException { assertEquals(ValueHelper.extractValueJson(expectedFile, submodelElement), ElementValueMapper.toValue(submodelElement), level, extend); } diff --git a/dataformat/json/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/serialization/json/fixture/ValueOnlyExamples.java b/dataformat/json/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/serialization/json/fixture/ValueOnlyExamples.java index a61714676..1bc7de966 100644 --- a/dataformat/json/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/serialization/json/fixture/ValueOnlyExamples.java +++ b/dataformat/json/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/serialization/json/fixture/ValueOnlyExamples.java @@ -21,6 +21,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.api.operation.OperationResult; import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.submodel.InvokeOperationSyncRequest; import de.fraunhofer.iosb.ilt.faaast.service.model.api.response.submodel.GetOperationAsyncResultResponse; +import de.fraunhofer.iosb.ilt.faaast.service.util.ReferenceBuilder; import java.io.File; import java.sql.Date; import java.time.LocalDateTime; @@ -29,8 +30,10 @@ import javax.xml.datatype.DatatypeFactory; import org.eclipse.digitaltwin.aas4j.v3.model.AasSubmodelElements; import org.eclipse.digitaltwin.aas4j.v3.model.AnnotatedRelationshipElement; +import org.eclipse.digitaltwin.aas4j.v3.model.BasicEventElement; import org.eclipse.digitaltwin.aas4j.v3.model.Blob; import org.eclipse.digitaltwin.aas4j.v3.model.DataTypeDefXsd; +import org.eclipse.digitaltwin.aas4j.v3.model.Direction; import org.eclipse.digitaltwin.aas4j.v3.model.Entity; import org.eclipse.digitaltwin.aas4j.v3.model.EntityType; import org.eclipse.digitaltwin.aas4j.v3.model.KeyTypes; @@ -45,6 +48,7 @@ import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementCollection; import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultAnnotatedRelationshipElement; +import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultBasicEventElement; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultBlob; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultEntity; import org.eclipse.digitaltwin.aas4j.v3.model.impl.DefaultFile; @@ -67,29 +71,29 @@ public class ValueOnlyExamples { private static final String RESOURCE_PATH = "src/test/resources/valueonly"; - public static final File SUBMODEL_FILE = new File(RESOURCE_PATH + "/submodel.json"); - public static final File SUBMODEL_ELEMENT_COLLECTION_FILE = new File(RESOURCE_PATH + "/submodel-element-collection.json"); - public static final File SUBMODEL_ELEMENT_LIST_FILE = new File(RESOURCE_PATH + "/submodel-element-list.json"); - public static final File SUBMODEL_ELEMENT_LIST_SIMPLE_FILE = new File(RESOURCE_PATH + "/submodel-element-list-simple.json"); - public static final File ENTITY_FILE = new File(RESOURCE_PATH + "/entity.json"); - public static final File ANNOTATED_RELATIONSHIP_ELEMENT_FILE = new File(RESOURCE_PATH + "/annotated-relationship-element.json"); - public static final File RELATIONSHIP_ELEMENT_FILE = new File(RESOURCE_PATH + "/relationship-element.json"); + public static final File BASIC_EVENT_ELEMENT_FILE = new File(RESOURCE_PATH + "/basic-event-element.json"); public static final File BLOB_FILE_WITHOUT_BLOB = new File(RESOURCE_PATH + "/blob-withoutblob.json"); public static final File BLOB_FILE_WITH_BLOB = new File(RESOURCE_PATH + "/blob-withblob.json"); + public static final File ENTITY_FILE = new File(RESOURCE_PATH + "/entity.json"); public static final File FILE_FILE = new File(RESOURCE_PATH + "/file.json"); - public static final File REFERENCE_ELEMENT_MODEL_FILE = new File(RESOURCE_PATH + "/reference-element-model.json"); - public static final File REFERENCE_ELEMENT_GLOBAL_FILE = new File(RESOURCE_PATH + "/reference-element-global.json"); - public static final File RANGE_INT_FILE = new File(RESOURCE_PATH + "/range-int.json"); - public static final File RANGE_DOUBLE_FILE = new File(RESOURCE_PATH + "/range-double.json"); + public static final File GET_OPERATION_ASYNC_RESULT_RESPONSE_FILE = new File(RESOURCE_PATH + "/get-operation-async-result-response.json"); + public static final File INVOKE_OPERATION_REQUEST_FILE = new File(RESOURCE_PATH + "/invoke-operation-request.json"); public static final File MULTI_LANGUAGE_PROPERTY_FILE = new File(RESOURCE_PATH + "/multilanguage-property.json"); - public static final File PROPERTY_INT_FILE = new File(RESOURCE_PATH + "/property-int.json"); + public static final File PROPERTY_DATETIME_FILE = new File(RESOURCE_PATH + "/property-datetime.json"); public static final File PROPERTY_DOUBLE_FILE = new File(RESOURCE_PATH + "/property-double.json"); - public static final File PROPERTY_STRING_FILE = new File(RESOURCE_PATH + "/property-string.json"); public static final File PROPERTY_GDAY_FILE = new File(RESOURCE_PATH + "/property-gday.json"); - public static final File PROPERTY_DATETIME_FILE = new File(RESOURCE_PATH + "/property-datetime.json"); - public static final File INVOKE_OPERATION_REQUEST_FILE = new File(RESOURCE_PATH + "/invoke-operation-request.json"); - public static final File GET_OPERATION_ASYNC_RESULT_RESPONSE_FILE = new File(RESOURCE_PATH + "/get-operation-async-result-response.json"); + public static final File PROPERTY_INT_FILE = new File(RESOURCE_PATH + "/property-int.json"); + public static final File PROPERTY_STRING_FILE = new File(RESOURCE_PATH + "/property-string.json"); + public static final File RANGE_DOUBLE_FILE = new File(RESOURCE_PATH + "/range-double.json"); + public static final File RANGE_INT_FILE = new File(RESOURCE_PATH + "/range-int.json"); + public static final File REFERENCE_ELEMENT_GLOBAL_FILE = new File(RESOURCE_PATH + "/reference-element-global.json"); + public static final File REFERENCE_ELEMENT_MODEL_FILE = new File(RESOURCE_PATH + "/reference-element-model.json"); + public static final File RELATIONSHIP_ELEMENT_FILE = new File(RESOURCE_PATH + "/relationship-element.json"); + public static final File SUBMODEL_ELEMENT_COLLECTION_FILE = new File(RESOURCE_PATH + "/submodel-element-collection.json"); + public static final File SUBMODEL_ELEMENT_LIST_FILE = new File(RESOURCE_PATH + "/submodel-element-list.json"); + public static final File SUBMODEL_ELEMENT_LIST_SIMPLE_FILE = new File(RESOURCE_PATH + "/submodel-element-list-simple.json"); + public static final File SUBMODEL_FILE = new File(RESOURCE_PATH + "/submodel.json"); public static final Blob BLOB = new DefaultBlob.Builder() .idShort("blob1") @@ -97,6 +101,51 @@ public class ValueOnlyExamples { .value("example-data".getBytes()) .build(); + public static final BasicEventElement BASIC_EVENT_ELEMENT = new DefaultBasicEventElement.Builder() + .idShort("basicEventElement1") + .direction(Direction.INPUT) + .observed(ReferenceBuilder.forSubmodel("http://example.org/submodel/1", "http://example.org/element/1")) + .build(); + + public static final Operation CONTEXT_OPERATION_INVOKE = new DefaultOperation.Builder() + .inputVariables(new DefaultOperationVariable.Builder() + .value(new DefaultProperty.Builder() + .idShort("inString") + .valueType(DataTypeDefXsd.STRING) + .build()) + .build()) + .inputVariables(new DefaultOperationVariable.Builder() + .value(new DefaultProperty.Builder() + .idShort("inInt") + .valueType(DataTypeDefXsd.INT) + .build()) + .build()) + .inputVariables(new DefaultOperationVariable.Builder() + .value(new DefaultProperty.Builder() + .idShort("inDouble") + .valueType(DataTypeDefXsd.DOUBLE) + .build()) + .build()) + .inoutputVariables(new DefaultOperationVariable.Builder() + .value(new DefaultProperty.Builder() + .idShort("inoutString") + .valueType(DataTypeDefXsd.STRING) + .build()) + .build()) + .inoutputVariables(new DefaultOperationVariable.Builder() + .value(new DefaultProperty.Builder() + .idShort("inoutInt") + .valueType(DataTypeDefXsd.INT) + .build()) + .build()) + .inoutputVariables(new DefaultOperationVariable.Builder() + .value(new DefaultProperty.Builder() + .idShort("inoutDouble") + .valueType(DataTypeDefXsd.DOUBLE) + .build()) + .build()) + .build(); + public static final Entity ENTITY = new DefaultEntity.Builder() .idShort("entity1") .entityType(EntityType.SELF_MANAGED_ENTITY) @@ -114,6 +163,110 @@ public class ValueOnlyExamples { .value("SafetyInstructions.pdf") .build(); + public static final GetOperationAsyncResultResponse GET_OPERATION_ASYNC_RESULT_RESPONSE = GetOperationAsyncResultResponse.builder() + .success() + .payload(new OperationResult.Builder() + .executionState(ExecutionState.COMPLETED) + .inoutputArgument(new DefaultOperationVariable.Builder() + .value(new DefaultProperty.Builder() + .idShort("inoutString") + .valueType(DataTypeDefXsd.STRING) + .value("bar") + .build()) + .build()) + .inoutputArgument(new DefaultOperationVariable.Builder() + .value(new DefaultProperty.Builder() + .idShort("inoutInt") + .valueType(DataTypeDefXsd.INT) + .value("-42") + .build()) + .build()) + .inoutputArgument(new DefaultOperationVariable.Builder() + .value(new DefaultProperty.Builder() + .idShort("inoutDouble") + .valueType(DataTypeDefXsd.DOUBLE) + .value("17.42") + .build()) + .build()) + .outputArgument(new DefaultOperationVariable.Builder() + .value(new DefaultProperty.Builder() + .idShort("outString") + .valueType(DataTypeDefXsd.STRING) + .value("foo-bar") + .build()) + .build()) + .outputArgument(new DefaultOperationVariable.Builder() + .value(new DefaultProperty.Builder() + .idShort("outInt") + .valueType(DataTypeDefXsd.INT) + .value("-24") + .build()) + .build()) + .outputArgument(new DefaultOperationVariable.Builder() + .value(new DefaultProperty.Builder() + .idShort("outDouble") + .valueType(DataTypeDefXsd.DOUBLE) + .value("24.24") + .build()) + .build()) + .build()) + .result(Result.builder() + .message(Message.builder() + .messageType(MessageType.INFO) + .text("some message text") + .timestamp(Date.from(LocalDateTime.parse("2024-01-01T00:00:00").atOffset(ZoneOffset.UTC).toInstant())) + .build()) + .build()) + .build(); + + public static final InvokeOperationSyncRequest INVOKE_OPERATION_SYNC_REQUEST = InvokeOperationSyncRequest.builder() + .submodelId("http://example.org/submodels/1") + .path("my.test.operation") + .timeout(DatatypeFactory.newDefaultInstance().newDuration("P1Y2M3DT1H2M3S")) + .inputArgument(new DefaultOperationVariable.Builder() + .value(new DefaultProperty.Builder() + .idShort("inString") + .valueType(DataTypeDefXsd.STRING) + .value("foo") + .build()) + .build()) + .inputArgument(new DefaultOperationVariable.Builder() + .value(new DefaultProperty.Builder() + .idShort("inInt") + .valueType(DataTypeDefXsd.INT) + .value("42") + .build()) + .build()) + .inputArgument(new DefaultOperationVariable.Builder() + .value(new DefaultProperty.Builder() + .idShort("inDouble") + .valueType(DataTypeDefXsd.DOUBLE) + .value("42.17") + .build()) + .build()) + .inoutputArgument(new DefaultOperationVariable.Builder() + .value(new DefaultProperty.Builder() + .idShort("inoutString") + .valueType(DataTypeDefXsd.STRING) + .value("bar") + .build()) + .build()) + .inoutputArgument(new DefaultOperationVariable.Builder() + .value(new DefaultProperty.Builder() + .idShort("inoutInt") + .valueType(DataTypeDefXsd.INT) + .value("-42") + .build()) + .build()) + .inoutputArgument(new DefaultOperationVariable.Builder() + .value(new DefaultProperty.Builder() + .idShort("inoutDouble") + .valueType(DataTypeDefXsd.DOUBLE) + .value("17.42") + .build()) + .build()) + .build(); + public static final MultiLanguageProperty MULTI_LANGUAGE_PROPERTY = new DefaultMultiLanguageProperty.Builder() .idShort("multiLanguageProp1") .value(new DefaultLangStringTextType.Builder() @@ -125,7 +278,12 @@ public class ValueOnlyExamples { .text("bar") .build()) .build(); - + public static final Property PROPERTY_DATETIME = new DefaultProperty.Builder() + .category("category") + .idShort("propDateTime") + .valueType(DataTypeDefXsd.DATE_TIME) + .value(OffsetDateTime.of(2022, 7, 31, 17, 8, 51, 0, ZoneOffset.UTC).toString()) + .build(); public static final Property PROPERTY_DOUBLE = new DefaultProperty.Builder() .category("category") .idShort("propDouble") @@ -133,11 +291,11 @@ public class ValueOnlyExamples { .value("42.17") .build(); - public static final Property PROPERTY_DATETIME = new DefaultProperty.Builder() + public static final Property PROPERTY_GDAY = new DefaultProperty.Builder() .category("category") - .idShort("propDateTime") - .valueType(DataTypeDefXsd.DATE_TIME) - .value(OffsetDateTime.of(2022, 7, 31, 17, 8, 51, 0, ZoneOffset.UTC).toString()) + .idShort("propGDay") + .value("---15") + .valueType(DataTypeDefXsd.GDAY) .build(); public static final Property PROPERTY_INT = new DefaultProperty.Builder() @@ -153,13 +311,6 @@ public class ValueOnlyExamples { .value("foo") .build(); - public static final Property PROPERTY_GDAY = new DefaultProperty.Builder() - .category("category") - .idShort("propGDay") - .value("---15") - .valueType(DataTypeDefXsd.GDAY) - .build(); - public static final Range RANGE_DOUBLE = new DefaultRange.Builder() .idShort("rangeDouble") .valueType(DataTypeDefXsd.DOUBLE) @@ -167,13 +318,62 @@ public class ValueOnlyExamples { .max("5.0") .build(); + public static final Range RANGE_INT = new DefaultRange.Builder() + .idShort("rangeInt") + .valueType(DataTypeDefXsd.INT) + .min("17") + .max("42") + .build(); + + public static final ReferenceElement REFERENCE_ELEMENT_GLOBAL = new DefaultReferenceElement.Builder() + .idShort("referenceGlobal") + .value(new DefaultReference.Builder() + .type(ReferenceTypes.EXTERNAL_REFERENCE) + .keys(new DefaultKey.Builder() + .type(KeyTypes.GLOBAL_REFERENCE) + .value("http://customer.com/demo/aas/1/1/1234859590") + .build()) + .build()) + .build(); + + public static final ReferenceElement REFERENCE_ELEMENT_MODEL = new DefaultReferenceElement.Builder() + .idShort("referenceModel") + .value(new DefaultReference.Builder() + .type(ReferenceTypes.MODEL_REFERENCE) + .keys(new DefaultKey.Builder() + .type(KeyTypes.SUBMODEL) + .value("http://customer.com/demo/aas/1/1/1234859590") + .build()) + .keys(new DefaultKey.Builder() + .type(KeyTypes.PROPERTY) + .value("MaxRotationSpeed") + .build()) + .build()) + .build(); + + public static final RelationshipElement RELATIONSHIP_ELEMENT = new DefaultRelationshipElement.Builder() + .idShort("relationship1") + .first(REFERENCE_ELEMENT_GLOBAL.getValue()) + .second(REFERENCE_ELEMENT_MODEL.getValue()) + .build(); + public static final SubmodelElementCollection SUBMODEL_ELEMENT_COLLECTION = new DefaultSubmodelElementCollection.Builder() .idShort("collection1") .value(PROPERTY_STRING) .value(RANGE_DOUBLE) .value(ENTITY) .build(); - + public static final Submodel SUBMODEL = new DefaultSubmodel.Builder() + .category("category") + .idShort("submodel1") + .id("http://example.org/test") + .submodelElements(PROPERTY_STRING) + .submodelElements(RANGE_DOUBLE) + .submodelElements(SUBMODEL_ELEMENT_COLLECTION) + .submodelElements(new DefaultOperation.Builder() + .idShort("operation1") + .build()) + .build(); public static final SubmodelElementList SUBMODEL_ELEMENT_LIST = new DefaultSubmodelElementList.Builder() .idShort("listOfLists") .typeValueListElement(AasSubmodelElements.SUBMODEL_ELEMENT_LIST) @@ -265,39 +465,6 @@ public class ValueOnlyExamples { .build()) .build(); - public static final Range RANGE_INT = new DefaultRange.Builder() - .idShort("rangeInt") - .valueType(DataTypeDefXsd.INT) - .min("17") - .max("42") - .build(); - - public static final ReferenceElement REFERENCE_ELEMENT_GLOBAL = new DefaultReferenceElement.Builder() - .idShort("referenceGlobal") - .value(new DefaultReference.Builder() - .type(ReferenceTypes.EXTERNAL_REFERENCE) - .keys(new DefaultKey.Builder() - .type(KeyTypes.GLOBAL_REFERENCE) - .value("http://customer.com/demo/aas/1/1/1234859590") - .build()) - .build()) - .build(); - - public static final ReferenceElement REFERENCE_ELEMENT_MODEL = new DefaultReferenceElement.Builder() - .idShort("referenceModel") - .value(new DefaultReference.Builder() - .type(ReferenceTypes.MODEL_REFERENCE) - .keys(new DefaultKey.Builder() - .type(KeyTypes.SUBMODEL) - .value("http://customer.com/demo/aas/1/1/1234859590") - .build()) - .keys(new DefaultKey.Builder() - .type(KeyTypes.PROPERTY) - .value("MaxRotationSpeed") - .build()) - .build()) - .build(); - public static final AnnotatedRelationshipElement ANNOTATED_RELATIONSHIP_ELEMENT = new DefaultAnnotatedRelationshipElement.Builder() .idShort("annotatedRelationship1") .first(REFERENCE_ELEMENT_GLOBAL.getValue()) @@ -308,167 +475,6 @@ public class ValueOnlyExamples { .build()) .build(); - public static final RelationshipElement RELATIONSHIP_ELEMENT = new DefaultRelationshipElement.Builder() - .idShort("relationship1") - .first(REFERENCE_ELEMENT_GLOBAL.getValue()) - .second(REFERENCE_ELEMENT_MODEL.getValue()) - .build(); - - public static final Submodel SUBMODEL = new DefaultSubmodel.Builder() - .category("category") - .idShort("submodel1") - .id("http://example.org/test") - .submodelElements(PROPERTY_STRING) - .submodelElements(RANGE_DOUBLE) - .submodelElements(SUBMODEL_ELEMENT_COLLECTION) - .submodelElements(new DefaultOperation.Builder() - .idShort("operation1") - .build()) - .build(); - - public static final Operation CONTEXT_OPERATION_INVOKE = new DefaultOperation.Builder() - .inputVariables(new DefaultOperationVariable.Builder() - .value(new DefaultProperty.Builder() - .idShort("inString") - .valueType(DataTypeDefXsd.STRING) - .build()) - .build()) - .inputVariables(new DefaultOperationVariable.Builder() - .value(new DefaultProperty.Builder() - .idShort("inInt") - .valueType(DataTypeDefXsd.INT) - .build()) - .build()) - .inputVariables(new DefaultOperationVariable.Builder() - .value(new DefaultProperty.Builder() - .idShort("inDouble") - .valueType(DataTypeDefXsd.DOUBLE) - .build()) - .build()) - .inoutputVariables(new DefaultOperationVariable.Builder() - .value(new DefaultProperty.Builder() - .idShort("inoutString") - .valueType(DataTypeDefXsd.STRING) - .build()) - .build()) - .inoutputVariables(new DefaultOperationVariable.Builder() - .value(new DefaultProperty.Builder() - .idShort("inoutInt") - .valueType(DataTypeDefXsd.INT) - .build()) - .build()) - .inoutputVariables(new DefaultOperationVariable.Builder() - .value(new DefaultProperty.Builder() - .idShort("inoutDouble") - .valueType(DataTypeDefXsd.DOUBLE) - .build()) - .build()) - .build(); - - public static final GetOperationAsyncResultResponse GET_OPERATION_ASYNC_RESULT_RESPONSE = GetOperationAsyncResultResponse.builder() - .success() - .payload(new OperationResult.Builder() - .executionState(ExecutionState.COMPLETED) - .inoutputArgument(new DefaultOperationVariable.Builder() - .value(new DefaultProperty.Builder() - .idShort("inoutString") - .valueType(DataTypeDefXsd.STRING) - .value("bar") - .build()) - .build()) - .inoutputArgument(new DefaultOperationVariable.Builder() - .value(new DefaultProperty.Builder() - .idShort("inoutInt") - .valueType(DataTypeDefXsd.INT) - .value("-42") - .build()) - .build()) - .inoutputArgument(new DefaultOperationVariable.Builder() - .value(new DefaultProperty.Builder() - .idShort("inoutDouble") - .valueType(DataTypeDefXsd.DOUBLE) - .value("17.42") - .build()) - .build()) - .outputArgument(new DefaultOperationVariable.Builder() - .value(new DefaultProperty.Builder() - .idShort("outString") - .valueType(DataTypeDefXsd.STRING) - .value("foo-bar") - .build()) - .build()) - .outputArgument(new DefaultOperationVariable.Builder() - .value(new DefaultProperty.Builder() - .idShort("outInt") - .valueType(DataTypeDefXsd.INT) - .value("-24") - .build()) - .build()) - .outputArgument(new DefaultOperationVariable.Builder() - .value(new DefaultProperty.Builder() - .idShort("outDouble") - .valueType(DataTypeDefXsd.DOUBLE) - .value("24.24") - .build()) - .build()) - .build()) - .result(Result.builder() - .message(Message.builder() - .messageType(MessageType.INFO) - .text("some message text") - .timestamp(Date.from(LocalDateTime.parse("2024-01-01T00:00:00").atOffset(ZoneOffset.UTC).toInstant())) - .build()) - .build()) - .build(); - - public static final InvokeOperationSyncRequest INVOKE_OPERATION_SYNC_REQUEST = InvokeOperationSyncRequest.builder() - .submodelId("http://example.org/submodels/1") - .path("my.test.operation") - .timeout(DatatypeFactory.newDefaultInstance().newDuration("P1Y2M3DT1H2M3S")) - .inputArgument(new DefaultOperationVariable.Builder() - .value(new DefaultProperty.Builder() - .idShort("inString") - .valueType(DataTypeDefXsd.STRING) - .value("foo") - .build()) - .build()) - .inputArgument(new DefaultOperationVariable.Builder() - .value(new DefaultProperty.Builder() - .idShort("inInt") - .valueType(DataTypeDefXsd.INT) - .value("42") - .build()) - .build()) - .inputArgument(new DefaultOperationVariable.Builder() - .value(new DefaultProperty.Builder() - .idShort("inDouble") - .valueType(DataTypeDefXsd.DOUBLE) - .value("42.17") - .build()) - .build()) - .inoutputArgument(new DefaultOperationVariable.Builder() - .value(new DefaultProperty.Builder() - .idShort("inoutString") - .valueType(DataTypeDefXsd.STRING) - .value("bar") - .build()) - .build()) - .inoutputArgument(new DefaultOperationVariable.Builder() - .value(new DefaultProperty.Builder() - .idShort("inoutInt") - .valueType(DataTypeDefXsd.INT) - .value("-42") - .build()) - .build()) - .inoutputArgument(new DefaultOperationVariable.Builder() - .value(new DefaultProperty.Builder() - .idShort("inoutDouble") - .valueType(DataTypeDefXsd.DOUBLE) - .value("17.42") - .build()) - .build()) - .build(); - private ValueOnlyExamples() { } diff --git a/dataformat/json/src/test/resources/valueonly/basic-event-element.json b/dataformat/json/src/test/resources/valueonly/basic-event-element.json new file mode 100644 index 000000000..c762f725b --- /dev/null +++ b/dataformat/json/src/test/resources/valueonly/basic-event-element.json @@ -0,0 +1,17 @@ +{ + "basicEventElement1": { + "observed": { + "type": "ModelReference", + "keys": [ + { + "type": "Submodel", + "value": "http://example.org/submodel/1" + }, + { + "type": "SubmodelElement", + "value": "http://example.org/element/1" + } + ] + } + } +} \ No newline at end of file diff --git a/dataformat/json/src/test/resources/valueonly/get-operation-async-result-response.json b/dataformat/json/src/test/resources/valueonly/get-operation-async-result-response.json index 354663540..cbb7907b2 100644 --- a/dataformat/json/src/test/resources/valueonly/get-operation-async-result-response.json +++ b/dataformat/json/src/test/resources/valueonly/get-operation-async-result-response.json @@ -3,7 +3,6 @@ { "messageType": "Info", "text": "some message text", - "code": "", "timestamp": "2024-01-01T00:00:00.000+00:00" } ], diff --git a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/RequestHandler.java b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/RequestHandler.java index 1bbd569f5..4fdc0a51f 100644 --- a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/RequestHandler.java +++ b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/RequestHandler.java @@ -216,7 +216,7 @@ private void handlePreflightedCORSRequest(String url, HttpServletRequest request private void executeAndSend(HttpServletResponse response, de.fraunhofer.iosb.ilt.faaast.service.model.api.Request apiRequest) - throws SerializationException { + throws SerializationException, InvalidRequestException { if (apiRequest == null) { HttpHelper.send(response, StatusCode.CLIENT_ERROR_BAD_REQUEST); return; diff --git a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/request/mapper/AbstractRequestMapperWithOutputModifierAndPaging.java b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/request/mapper/AbstractRequestMapperWithOutputModifierAndPaging.java index 1fcaa13bc..87e990c16 100644 --- a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/request/mapper/AbstractRequestMapperWithOutputModifierAndPaging.java +++ b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/request/mapper/AbstractRequestMapperWithOutputModifierAndPaging.java @@ -56,15 +56,10 @@ protected AbstractRequestMapperWithOutputModifierAndPaging(ServiceContext servic @Override public T doParse(HttpRequest httpRequest, Map urlParameters, OutputModifier outputModifier) throws InvalidRequestException { - try { - PagingInfo pagingInfo = PagingHelper.parsePagingInfo(httpRequest.getQueryParameters()); - T result = doParse(httpRequest, urlParameters, outputModifier, pagingInfo); - result.setPagingInfo(pagingInfo); - return result; - } - catch (IllegalArgumentException e) { - throw new InvalidRequestException("invalid output modifier", e); - } + PagingInfo pagingInfo = PagingHelper.parsePagingInfo(httpRequest.getQueryParameters()); + T result = doParse(httpRequest, urlParameters, outputModifier, pagingInfo); + result.setPagingInfo(pagingInfo); + return result; } } diff --git a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/request/mapper/aasrepository/GetAllAssetAdministrationShellsByAssetIdReferenceRequestMapper.java b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/request/mapper/aasrepository/GetAllAssetAdministrationShellsByAssetIdReferenceRequestMapper.java new file mode 100644 index 000000000..990bc2df8 --- /dev/null +++ b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/request/mapper/aasrepository/GetAllAssetAdministrationShellsByAssetIdReferenceRequestMapper.java @@ -0,0 +1,76 @@ +/* + * 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.service.endpoint.http.request.mapper.aasrepository; + +import de.fraunhofer.iosb.ilt.faaast.service.ServiceContext; +import de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException; +import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.model.HttpMethod; +import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.model.HttpRequest; +import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.request.mapper.AbstractRequestMapperWithOutputModifierAndPaging; +import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.request.mapper.QueryParameters; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Content; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.PagingInfo; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.aasrepository.GetAllAssetAdministrationShellsByAssetIdReferenceRequest; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.response.aasrepository.GetAllAssetAdministrationShellsByAssetIdReferenceResponse; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.InvalidRequestException; +import de.fraunhofer.iosb.ilt.faaast.service.util.EncodingHelper; +import java.util.Map; +import org.eclipse.digitaltwin.aas4j.v3.model.SpecificAssetId; + + +/** + * class to map HTTP-GET-Request path: shells/$reference?assetIds={}. + */ +public class GetAllAssetAdministrationShellsByAssetIdReferenceRequestMapper + extends + AbstractRequestMapperWithOutputModifierAndPaging { + + private static final String PATTERN = "shells/\\$reference"; + + public GetAllAssetAdministrationShellsByAssetIdReferenceRequestMapper(ServiceContext serviceContext) { + super(serviceContext, HttpMethod.GET, PATTERN, Content.METADATA, Content.NORMAL, Content.PATH, Content.VALUE); + } + + + @Override + public boolean matchesUrl(HttpRequest httpRequest) { + return super.matchesUrl(httpRequest) && httpRequest.hasQueryParameter(QueryParameters.ASSET_IDS); + } + + + @Override + public GetAllAssetAdministrationShellsByAssetIdReferenceRequest doParse(HttpRequest httpRequest, Map urlParameters, OutputModifier outputModifier, + PagingInfo pagingInfo) + throws InvalidRequestException { + try { + return GetAllAssetAdministrationShellsByAssetIdReferenceRequest.builder() + .assetIds(deserializer.readList(EncodingHelper.base64UrlDecode(httpRequest.getQueryParameter(QueryParameters.ASSET_IDS)), + SpecificAssetId.class)) + .build(); + } + catch (IllegalArgumentException e) { + throw new InvalidRequestException(String.format( + "invalid query parameter - value not valid base64 (name: %s, value: %s)", + QueryParameters.ASSET_IDS, + httpRequest.getQueryParameter(QueryParameters.ASSET_IDS)), + e); + } + catch (DeserializationException e) { + throw new InvalidRequestException( + String.format("error deserializing %s (value: %s)", QueryParameters.ASSET_IDS, httpRequest.getQueryParameter(QueryParameters.ASSET_IDS)), e); + } + } +} diff --git a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/request/mapper/aasrepository/GetAllAssetAdministrationShellsByAssetIdRequestMapper.java b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/request/mapper/aasrepository/GetAllAssetAdministrationShellsByAssetIdRequestMapper.java index 955da2808..0c5a12917 100644 --- a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/request/mapper/aasrepository/GetAllAssetAdministrationShellsByAssetIdRequestMapper.java +++ b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/request/mapper/aasrepository/GetAllAssetAdministrationShellsByAssetIdRequestMapper.java @@ -20,6 +20,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.model.HttpRequest; import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.request.mapper.AbstractRequestMapperWithOutputModifierAndPaging; import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.request.mapper.QueryParameters; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Content; import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.PagingInfo; import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.aasrepository.GetAllAssetAdministrationShellsByAssetIdRequest; @@ -36,10 +37,10 @@ public class GetAllAssetAdministrationShellsByAssetIdRequestMapper extends AbstractRequestMapperWithOutputModifierAndPaging { - private static final String PATTERN = "shells"; + private static final String PATTERN = "shells$"; public GetAllAssetAdministrationShellsByAssetIdRequestMapper(ServiceContext serviceContext) { - super(serviceContext, HttpMethod.GET, PATTERN); + super(serviceContext, HttpMethod.GET, PATTERN, Content.REFERENCE); } diff --git a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/request/mapper/aasrepository/GetAllAssetAdministrationShellsByIdShortReferenceRequestMapper.java b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/request/mapper/aasrepository/GetAllAssetAdministrationShellsByIdShortReferenceRequestMapper.java new file mode 100644 index 000000000..af070f0f3 --- /dev/null +++ b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/request/mapper/aasrepository/GetAllAssetAdministrationShellsByIdShortReferenceRequestMapper.java @@ -0,0 +1,57 @@ +/* + * 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.service.endpoint.http.request.mapper.aasrepository; + +import de.fraunhofer.iosb.ilt.faaast.service.ServiceContext; +import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.model.HttpMethod; +import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.model.HttpRequest; +import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.request.mapper.AbstractRequestMapperWithOutputModifierAndPaging; +import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.request.mapper.QueryParameters; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Content; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.PagingInfo; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.aasrepository.GetAllAssetAdministrationShellsByIdShortReferenceRequest; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.response.aasrepository.GetAllAssetAdministrationShellsByIdShortReferenceResponse; +import java.util.Map; + + +/** + * class to map HTTP-Request path: shells/$reference?idShort={}. + */ +public class GetAllAssetAdministrationShellsByIdShortReferenceRequestMapper + extends + AbstractRequestMapperWithOutputModifierAndPaging { + + private static final String PATTERN = "shells/\\$reference"; + + public GetAllAssetAdministrationShellsByIdShortReferenceRequestMapper(ServiceContext serviceContext) { + super(serviceContext, HttpMethod.GET, PATTERN, Content.METADATA, Content.NORMAL, Content.PATH, Content.VALUE); + } + + + @Override + public boolean matchesUrl(HttpRequest httpRequest) { + return super.matchesUrl(httpRequest) && httpRequest.hasQueryParameter(QueryParameters.ID_SHORT); + } + + + @Override + public GetAllAssetAdministrationShellsByIdShortReferenceRequest doParse(HttpRequest httpRequest, Map urlParameters, OutputModifier outputModifier, + PagingInfo pagingInfo) { + return GetAllAssetAdministrationShellsByIdShortReferenceRequest.builder() + .idShort(httpRequest.getQueryParameters().get(QueryParameters.ID_SHORT)) + .build(); + } +} diff --git a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/request/mapper/aasrepository/GetAllAssetAdministrationShellsByIdShortRequestMapper.java b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/request/mapper/aasrepository/GetAllAssetAdministrationShellsByIdShortRequestMapper.java index b5c2642b9..1da12e9e5 100644 --- a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/request/mapper/aasrepository/GetAllAssetAdministrationShellsByIdShortRequestMapper.java +++ b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/request/mapper/aasrepository/GetAllAssetAdministrationShellsByIdShortRequestMapper.java @@ -19,6 +19,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.model.HttpRequest; import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.request.mapper.AbstractRequestMapperWithOutputModifierAndPaging; import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.request.mapper.QueryParameters; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Content; import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.PagingInfo; import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.aasrepository.GetAllAssetAdministrationShellsByIdShortRequest; @@ -32,10 +33,10 @@ public class GetAllAssetAdministrationShellsByIdShortRequestMapper extends AbstractRequestMapperWithOutputModifierAndPaging { - private static final String PATTERN = "shells"; + private static final String PATTERN = "shells$"; public GetAllAssetAdministrationShellsByIdShortRequestMapper(ServiceContext serviceContext) { - super(serviceContext, HttpMethod.GET, PATTERN); + super(serviceContext, HttpMethod.GET, PATTERN, Content.REFERENCE); } diff --git a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/ResponseMappingManager.java b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/ResponseMappingManager.java index 9ac7e0b3b..25804d46f 100644 --- a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/ResponseMappingManager.java +++ b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/ResponseMappingManager.java @@ -20,6 +20,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.response.mapper.AbstractResponseMapper; import de.fraunhofer.iosb.ilt.faaast.service.model.api.Request; import de.fraunhofer.iosb.ilt.faaast.service.model.api.Response; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.InvalidRequestException; import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure; import de.fraunhofer.iosb.ilt.faaast.service.util.MostSpecificClassComparator; import jakarta.servlet.http.HttpServletResponse; @@ -44,10 +45,10 @@ public ResponseMappingManager(ServiceContext serviceContext) { * @param apiResponse the API response to process * @param httpResponse the HTTP response to write to * @throws IllegalArgumentException is apiRequest is null - * * @throws IllegalArgumentException is apiResponse is null - * * @throws IllegalArgumentException is httpResponse is null + * @throws IllegalArgumentException is apiResponse is null + * @throws IllegalArgumentException is httpResponse is null */ - public void map(Request apiRequest, Response apiResponse, HttpServletResponse httpResponse) { + public void map(Request apiRequest, Response apiResponse, HttpServletResponse httpResponse) throws InvalidRequestException { Ensure.requireNonNull(apiRequest, "apiRequest must be non-null"); Ensure.requireNonNull(apiResponse, "apiResponse must be non-null"); Ensure.requireNonNull(httpResponse, "httpResponse must be non-null"); diff --git a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/mapper/AbstractResponseMapper.java b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/mapper/AbstractResponseMapper.java index 8b25eed3b..6e7fde096 100644 --- a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/mapper/AbstractResponseMapper.java +++ b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/mapper/AbstractResponseMapper.java @@ -17,6 +17,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.ServiceContext; import de.fraunhofer.iosb.ilt.faaast.service.model.api.Request; import de.fraunhofer.iosb.ilt.faaast.service.model.api.Response; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.InvalidRequestException; import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure; import jakarta.servlet.http.HttpServletResponse; import java.util.Objects; @@ -42,8 +43,9 @@ protected AbstractResponseMapper(ServiceContext serviceContext) { * @param apiRequest the API request received * @param apiResponse the API response that shall be sent as a response to the apiRequest * @param httpResponse the HTTP response object to write to + * @throws InvalidRequestException if the request is invalid */ - public abstract void map(U apiRequest, T apiResponse, HttpServletResponse httpResponse); + public abstract void map(U apiRequest, T apiResponse, HttpServletResponse httpResponse) throws InvalidRequestException; @Override diff --git a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/mapper/GetOperationAsyncStatusResponseMapper.java b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/mapper/GetOperationAsyncStatusResponseMapper.java index 0877ad0e6..900a32690 100644 --- a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/mapper/GetOperationAsyncStatusResponseMapper.java +++ b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/mapper/GetOperationAsyncStatusResponseMapper.java @@ -23,6 +23,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.api.StatusCode; import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.submodel.GetOperationAsyncStatusRequest; import de.fraunhofer.iosb.ilt.faaast.service.model.api.response.submodel.GetOperationAsyncStatusResponse; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.InvalidRequestException; import de.fraunhofer.iosb.ilt.faaast.service.util.EncodingHelper; import jakarta.servlet.http.HttpServletResponse; import java.util.Map; @@ -43,7 +44,7 @@ public GetOperationAsyncStatusResponseMapper(ServiceContext serviceContext) { @Override - public void map(GetOperationAsyncStatusRequest apiRequest, GetOperationAsyncStatusResponse apiResponse, HttpServletResponse httpResponse) { + public void map(GetOperationAsyncStatusRequest apiRequest, GetOperationAsyncStatusResponse apiResponse, HttpServletResponse httpResponse) throws InvalidRequestException { try { switch (apiResponse.getPayload().getExecutionState()) { case INITIATED: diff --git a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/mapper/ResponseWithFileMapper.java b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/mapper/ResponseWithFileMapper.java index ce159b772..720dd108c 100644 --- a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/mapper/ResponseWithFileMapper.java +++ b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/mapper/ResponseWithFileMapper.java @@ -22,6 +22,9 @@ import de.fraunhofer.iosb.ilt.faaast.service.util.FileHelper; import jakarta.servlet.http.HttpServletResponse; import java.util.Map; +import java.util.Objects; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** @@ -31,6 +34,8 @@ public class ResponseWithFileMapper extends AbstractResponseMapper> { private static final String HEADER_CONTENT_DISPOSITION = "Content-Disposition"; + private static final MediaType DEFAULT_CONTENT_TYPE = MediaType.OCTET_STREAM; + private static final Logger LOGGER = LoggerFactory.getLogger(ResponseWithFileMapper.class); public ResponseWithFileMapper(ServiceContext serviceContext) { super(serviceContext); @@ -39,11 +44,25 @@ public ResponseWithFileMapper(ServiceContext serviceContext) { @Override public void map(Request apiRequest, AbstractResponseWithFile apiResponse, HttpServletResponse httpResponse) { + MediaType contentType = DEFAULT_CONTENT_TYPE; + if (Objects.isNull(apiResponse.getPayload().getContentType())) { + LOGGER.debug("encountered missing content-type, using default content-type instead (default: {})", DEFAULT_CONTENT_TYPE.toString()); + } + else { + try { + contentType = MediaType.parse(apiResponse.getPayload().getContentType()); + } + catch (IllegalArgumentException e) { + LOGGER.warn("encountered unparseable content-type, using default content-type instead (found: {}, default: {})", + apiResponse.getPayload().getContentType(), + DEFAULT_CONTENT_TYPE.toString()); + } + } HttpHelper.sendContent( httpResponse, apiResponse.getStatusCode(), apiResponse.getPayload().getContent(), - MediaType.parse(apiResponse.getPayload().getContentType()), + contentType, Map.of(HEADER_CONTENT_DISPOSITION, String.format( "attachment; filename=\"%s\"", FileHelper.getFilenameFromPath(apiResponse.getPayload().getPath())))); diff --git a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/mapper/ResponseWithPayloadResponseMapper.java b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/mapper/ResponseWithPayloadResponseMapper.java index bc2be1f27..6612b1510 100644 --- a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/mapper/ResponseWithPayloadResponseMapper.java +++ b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/response/mapper/ResponseWithPayloadResponseMapper.java @@ -25,6 +25,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.OutputModifier; import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.AbstractRequestWithModifier; import de.fraunhofer.iosb.ilt.faaast.service.model.api.response.AbstractResponseWithPayload; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.InvalidRequestException; import jakarta.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -46,7 +47,7 @@ public ResponseWithPayloadResponseMapper(ServiceContext serviceContext) { @Override - public void map(U apiRequest, T apiResponse, HttpServletResponse httpResponse) { + public void map(U apiRequest, T apiResponse, HttpServletResponse httpResponse) throws InvalidRequestException { try { HttpHelper.sendJson(httpResponse, apiResponse.getStatusCode(), diff --git a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/util/HttpHelper.java b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/util/HttpHelper.java index ee0ebc6ba..ec0953521 100644 --- a/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/util/HttpHelper.java +++ b/endpoint/http/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/util/HttpHelper.java @@ -20,6 +20,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.api.MessageType; import de.fraunhofer.iosb.ilt.faaast.service.model.api.Result; import de.fraunhofer.iosb.ilt.faaast.service.model.api.StatusCode; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.UnsupportedModifierException; import de.fraunhofer.iosb.ilt.faaast.service.util.Ensure; import jakarta.servlet.http.HttpServletResponse; import java.io.IOException; @@ -150,6 +151,9 @@ public static void send(HttpServletResponse response, StatusCode statusCode, Res LOGGER.warn("error serializing response", e); sendContent(response, StatusCode.SERVER_INTERNAL_ERROR, null, null); } + catch (UnsupportedModifierException e) { + sendException(response, e); + } } @@ -222,17 +226,35 @@ public static void sendContent(HttpServletResponse response, StatusCode statusCo response.setContentLengthLong(content.length); } catch (IOException e) { - send(response, - StatusCode.SERVER_INTERNAL_ERROR, - Result.builder() - .message(MessageType.EXCEPTION, e.getMessage()) - .build()); + sendException(response, e); } } } } + /** + * Sends a HTTP response with given statusCode, payload and contentType. + * + * @param response HTTP response object + * @param exception exception occured + * @throws IllegalArgumentException if response is null + * @throws IllegalArgumentException if statusCode is null + */ + public static void sendException(HttpServletResponse response, Exception exception) { + try { + send(response, + StatusCode.SERVER_INTERNAL_ERROR, + Result.builder() + .message(MessageType.EXCEPTION, exception.getMessage()) + .build()); + } + catch (Exception e) { + response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500); + } + } + + /** * Sends an empty HTTP response with given statusCode and headers. * diff --git a/endpoint/http/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/serialization/HttpJsonSerializerTest.java b/endpoint/http/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/serialization/HttpJsonSerializerTest.java index 25acceead..a31beffcf 100644 --- a/endpoint/http/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/serialization/HttpJsonSerializerTest.java +++ b/endpoint/http/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/endpoint/http/serialization/HttpJsonSerializerTest.java @@ -18,6 +18,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.api.Message; import de.fraunhofer.iosb.ilt.faaast.service.model.api.MessageType; import de.fraunhofer.iosb.ilt.faaast.service.model.api.Result; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.UnsupportedModifierException; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.TimeZone; @@ -34,13 +35,13 @@ public class HttpJsonSerializerTest { private final HttpJsonApiSerializer serializer = new HttpJsonApiSerializer(); @Test - public void testEnumsWithCustomNaming() throws SerializationException { + public void testEnumsWithCustomNaming() throws SerializationException, UnsupportedModifierException { Assert.assertEquals("\"Error\"", serializer.write(MessageType.ERROR)); } @Test - public void testResult() throws SerializationException, ParseException, JSONException { + public void testResult() throws SerializationException, ParseException, JSONException, UnsupportedModifierException { SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); Result result = Result.builder() diff --git a/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/api/request/aasrepository/GetAllAssetAdministrationShellsByAssetIdReferenceRequest.java b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/api/request/aasrepository/GetAllAssetAdministrationShellsByAssetIdReferenceRequest.java new file mode 100644 index 000000000..ee3992505 --- /dev/null +++ b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/api/request/aasrepository/GetAllAssetAdministrationShellsByAssetIdReferenceRequest.java @@ -0,0 +1,107 @@ +/* + * 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.service.model.api.request.aasrepository; + +import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Content; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.AbstractRequestWithModifier; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.AbstractRequestWithModifierAndPaging; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.OutputModifierConstraints; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.response.aasrepository.GetAllAssetAdministrationShellsByAssetIdReferenceResponse; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.SpecificAssetId; + + +/** + * Request class for GetAllAssetAdministrationShellsByAssetId requests with content modifier Reference. + */ +public class GetAllAssetAdministrationShellsByAssetIdReferenceRequest extends AbstractRequestWithModifierAndPaging { + + private List assetIds; + + public GetAllAssetAdministrationShellsByAssetIdReferenceRequest() { + super(new OutputModifierConstraints.Builder() + .supportedContentModifiers(Content.REFERENCE) + .supportsExtent(false) + .supportsLevel(false) + .build()); + this.assetIds = new ArrayList<>(); + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + GetAllAssetAdministrationShellsByAssetIdReferenceRequest that = (GetAllAssetAdministrationShellsByAssetIdReferenceRequest) o; + return super.equals(that) + && Objects.equals(assetIds, that.assetIds); + } + + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), assetIds); + } + + + public List getAssetIds() { + return assetIds; + } + + + public void setAssetIds(List assetIds) { + this.assetIds = assetIds; + } + + + public static Builder builder() { + return new Builder(); + } + + public abstract static class AbstractBuilder> + extends AbstractRequestWithModifier.AbstractBuilder { + + public B assetId(SpecificAssetId value) { + getBuildingInstance().getAssetIds().add(value); + return getSelf(); + } + + + public B assetIds(List value) { + getBuildingInstance().setAssetIds(value); + return getSelf(); + } + } + + public static class Builder extends AbstractBuilder { + + @Override + protected Builder getSelf() { + return this; + } + + + @Override + protected GetAllAssetAdministrationShellsByAssetIdReferenceRequest newBuildingInstance() { + return new GetAllAssetAdministrationShellsByAssetIdReferenceRequest(); + } + } +} diff --git a/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/api/request/aasrepository/GetAllAssetAdministrationShellsByIdShortReferenceRequest.java b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/api/request/aasrepository/GetAllAssetAdministrationShellsByIdShortReferenceRequest.java new file mode 100644 index 000000000..69a381d89 --- /dev/null +++ b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/api/request/aasrepository/GetAllAssetAdministrationShellsByIdShortReferenceRequest.java @@ -0,0 +1,97 @@ +/* + * 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.service.model.api.request.aasrepository; + +import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Content; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.AbstractRequestWithModifier; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.AbstractRequestWithModifierAndPaging; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.OutputModifierConstraints; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.response.aasrepository.GetAllAssetAdministrationShellsByIdShortReferenceResponse; +import java.util.Objects; + + +/** + * Request class for GetAllAssetAdministrationShellsByIdShort requests with content modifier Reference. + */ +public class GetAllAssetAdministrationShellsByIdShortReferenceRequest extends AbstractRequestWithModifierAndPaging { + + private String idShort; + + public GetAllAssetAdministrationShellsByIdShortReferenceRequest() { + super(new OutputModifierConstraints.Builder() + .supportedContentModifiers(Content.REFERENCE) + .supportsExtent(false) + .supportsLevel(false) + .build()); + } + + + public String getIdShort() { + return idShort; + } + + + public void setIdShort(String idShort) { + this.idShort = idShort; + } + + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + GetAllAssetAdministrationShellsByIdShortReferenceRequest that = (GetAllAssetAdministrationShellsByIdShortReferenceRequest) o; + return super.equals(that) + && Objects.equals(idShort, that.idShort); + } + + + @Override + public int hashCode() { + return Objects.hash(super.hashCode(), idShort); + } + + + public static Builder builder() { + return new Builder(); + } + + public abstract static class AbstractBuilder> + extends AbstractRequestWithModifier.AbstractBuilder { + + public B idShort(String value) { + getBuildingInstance().setIdShort(value); + return getSelf(); + } + } + + public static class Builder extends AbstractBuilder { + + @Override + protected Builder getSelf() { + return this; + } + + + @Override + protected GetAllAssetAdministrationShellsByIdShortReferenceRequest newBuildingInstance() { + return new GetAllAssetAdministrationShellsByIdShortReferenceRequest(); + } + } +} diff --git a/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/api/response/aasrepository/GetAllAssetAdministrationShellsByAssetIdReferenceResponse.java b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/api/response/aasrepository/GetAllAssetAdministrationShellsByAssetIdReferenceResponse.java new file mode 100644 index 000000000..fd3f94fd2 --- /dev/null +++ b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/api/response/aasrepository/GetAllAssetAdministrationShellsByAssetIdReferenceResponse.java @@ -0,0 +1,43 @@ +/* + * 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.service.model.api.response.aasrepository; + +import de.fraunhofer.iosb.ilt.faaast.service.model.api.response.AbstractPagedResponse; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; + + +/** + * Response class for GetAllAssetAdministrationShellsByAssetId requests with content modifier Reference. + */ +public class GetAllAssetAdministrationShellsByAssetIdReferenceResponse extends AbstractPagedResponse { + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends AbstractBuilder { + + @Override + protected Builder getSelf() { + return this; + } + + + @Override + protected GetAllAssetAdministrationShellsByAssetIdReferenceResponse newBuildingInstance() { + return new GetAllAssetAdministrationShellsByAssetIdReferenceResponse(); + } + } +} diff --git a/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/api/response/aasrepository/GetAllAssetAdministrationShellsByIdShortReferenceResponse.java b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/api/response/aasrepository/GetAllAssetAdministrationShellsByIdShortReferenceResponse.java new file mode 100644 index 000000000..7219116d4 --- /dev/null +++ b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/api/response/aasrepository/GetAllAssetAdministrationShellsByIdShortReferenceResponse.java @@ -0,0 +1,43 @@ +/* + * 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.service.model.api.response.aasrepository; + +import de.fraunhofer.iosb.ilt.faaast.service.model.api.response.AbstractPagedResponse; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; + + +/** + * Response class for GetAllAssetAdministrationShellsByIdShort requests with content modifier Reference. + */ +public class GetAllAssetAdministrationShellsByIdShortReferenceResponse extends AbstractPagedResponse { + + public static Builder builder() { + return new Builder(); + } + + public static class Builder extends AbstractBuilder { + + @Override + protected Builder getSelf() { + return this; + } + + + @Override + protected GetAllAssetAdministrationShellsByIdShortReferenceResponse newBuildingInstance() { + return new GetAllAssetAdministrationShellsByIdShortReferenceResponse(); + } + } +} diff --git a/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/exception/UnsupportedContentModifierException.java b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/exception/UnsupportedContentModifierException.java index dc3248e3d..92f4802bb 100644 --- a/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/exception/UnsupportedContentModifierException.java +++ b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/exception/UnsupportedContentModifierException.java @@ -40,6 +40,11 @@ public UnsupportedContentModifierException(Content contentModifier, Collection type) { + super(String.format("content modifier not supported for type (modifier: %s, type: %s)", contentModifier, type.getSimpleName())); + } + + public UnsupportedContentModifierException(String contentModifier, Collection supportedContentModifiers) { super(String.format("unsupported content modifier '%s' (supported content modifiers: %s)", contentModifier, diff --git a/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/value/BasicEventElementValue.java b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/value/BasicEventElementValue.java new file mode 100644 index 000000000..0679a4bd1 --- /dev/null +++ b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/value/BasicEventElementValue.java @@ -0,0 +1,83 @@ +/* + * 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.service.model.value; + +import java.util.Objects; +import org.eclipse.digitaltwin.aas4j.v3.model.Reference; +import org.eclipse.digitaltwin.aas4j.v3.model.builder.ExtendableBuilder; + + +/** + * Value class for BasicEventElement. + */ +public class BasicEventElementValue extends DataElementValue { + + private Reference observed; + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + BasicEventElementValue that = (BasicEventElementValue) o; + return Objects.equals(observed, that.observed); + } + + + public Reference getObserved() { + return observed; + } + + + public void setObserved(Reference observed) { + this.observed = observed; + } + + + @Override + public int hashCode() { + return Objects.hash(observed); + } + + + public static Builder builder() { + return new Builder(); + } + + public abstract static class AbstractBuilder> extends ExtendableBuilder { + + public B observed(Reference value) { + getBuildingInstance().setObserved(value); + return getSelf(); + } + } + + public static class Builder extends AbstractBuilder { + + @Override + protected Builder getSelf() { + return this; + } + + + @Override + protected BasicEventElementValue newBuildingInstance() { + return new BasicEventElementValue(); + } + } +} diff --git a/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/value/mapper/BasicEventElementValueMapper.java b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/value/mapper/BasicEventElementValueMapper.java new file mode 100644 index 000000000..fa8cb9935 --- /dev/null +++ b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/value/mapper/BasicEventElementValueMapper.java @@ -0,0 +1,45 @@ +/* + * 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.service.model.value.mapper; + +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ValueMappingException; +import de.fraunhofer.iosb.ilt.faaast.service.model.value.BasicEventElementValue; +import org.eclipse.digitaltwin.aas4j.v3.model.BasicEventElement; + + +/** + * Converts between {@link org.eclipse.digitaltwin.aas4j.v3.model.BasicEventElement} and + * {@link de.fraunhofer.iosb.ilt.faaast.service.model.value.BasicEventElementValue}. + */ +public class BasicEventElementValueMapper implements DataValueMapper { + + @Override + public BasicEventElementValue toValue(BasicEventElement submodelElement) { + if (submodelElement == null) { + return null; + } + BasicEventElementValue elementValue = new BasicEventElementValue(); + elementValue.setObserved(submodelElement.getObserved()); + return elementValue; + } + + + @Override + public BasicEventElement setValue(BasicEventElement submodelElement, BasicEventElementValue value) throws ValueMappingException { + DataValueMapper.super.setValue(submodelElement, value); + submodelElement.setObserved(value.getObserved()); + return submodelElement; + } +} diff --git a/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/value/mapper/EntityValueMapper.java b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/value/mapper/EntityValueMapper.java index f4995ff05..a03eff869 100644 --- a/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/value/mapper/EntityValueMapper.java +++ b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/value/mapper/EntityValueMapper.java @@ -16,10 +16,12 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ValueMappingException; import de.fraunhofer.iosb.ilt.faaast.service.model.value.EntityValue; +import de.fraunhofer.iosb.ilt.faaast.service.util.ElementValueHelper; import de.fraunhofer.iosb.ilt.faaast.service.util.LambdaExceptionHelper; import java.util.Objects; import java.util.stream.Collectors; import org.eclipse.digitaltwin.aas4j.v3.model.Entity; +import org.eclipse.digitaltwin.aas4j.v3.model.Referable; import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElement; @@ -36,11 +38,14 @@ public EntityValue toValue(Entity submodelElement) throws ValueMappingException } EntityValue value = EntityValue.builder().build(); value.setEntityType(submodelElement.getEntityType()); - if (submodelElement.getStatements() != null && submodelElement.getStatements().stream().noneMatch(Objects::isNull)) { + + if (Objects.nonNull(submodelElement.getStatements())) { value.setStatements(submodelElement.getStatements().stream() + .filter(Objects::nonNull) + .filter(ElementValueHelper::isValueOnlySupported) .collect(Collectors.toMap( - x -> x != null ? x.getIdShort() : null, - LambdaExceptionHelper.rethrowFunction(x -> x != null ? ElementValueMapper.toValue(x) : null)))); + Referable::getIdShort, + LambdaExceptionHelper.rethrowFunction(ElementValueMapper::toValue)))); } value.setGlobalAssetId(submodelElement.getGlobalAssetId()); value.setSpecificAssetIds(submodelElement.getSpecificAssetIds()); diff --git a/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/value/mapper/SubmodelElementCollectionValueMapper.java b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/value/mapper/SubmodelElementCollectionValueMapper.java index 154af2e8c..8c4522e28 100644 --- a/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/value/mapper/SubmodelElementCollectionValueMapper.java +++ b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/value/mapper/SubmodelElementCollectionValueMapper.java @@ -16,6 +16,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ValueMappingException; import de.fraunhofer.iosb.ilt.faaast.service.model.value.SubmodelElementCollectionValue; +import de.fraunhofer.iosb.ilt.faaast.service.util.ElementValueHelper; import de.fraunhofer.iosb.ilt.faaast.service.util.LambdaExceptionHelper; import java.util.Objects; import java.util.stream.Collectors; @@ -36,13 +37,13 @@ public SubmodelElementCollectionValue toValue(SubmodelElementCollection submodel return null; } SubmodelElementCollectionValue value = SubmodelElementCollectionValue.builder().build(); - if (submodelElement.getValue() != null && submodelElement.getValue().stream().noneMatch(Objects::isNull)) { - value.setValues(submodelElement.getValue().stream().collect(Collectors.toMap( - Referable::getIdShort, - LambdaExceptionHelper.rethrowFunction(ElementValueMapper::toValue)))); - } - else { - value.setValues(null); + if (Objects.nonNull(submodelElement.getValue())) { + value.setValues(submodelElement.getValue().stream() + .filter(Objects::nonNull) + .filter(ElementValueHelper::isValueOnlySupported) + .collect(Collectors.toMap( + Referable::getIdShort, + LambdaExceptionHelper.rethrowFunction(ElementValueMapper::toValue)))); } return value; } diff --git a/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/value/mapper/SubmodelElementListValueMapper.java b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/value/mapper/SubmodelElementListValueMapper.java index daf1f6f73..50500875c 100644 --- a/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/value/mapper/SubmodelElementListValueMapper.java +++ b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/model/value/mapper/SubmodelElementListValueMapper.java @@ -17,6 +17,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ValueMappingException; import de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue; import de.fraunhofer.iosb.ilt.faaast.service.model.value.SubmodelElementListValue; +import de.fraunhofer.iosb.ilt.faaast.service.util.ElementValueHelper; import de.fraunhofer.iosb.ilt.faaast.service.util.LambdaExceptionHelper; import java.util.Objects; import java.util.stream.Collectors; @@ -35,15 +36,14 @@ public SubmodelElementListValue toValue(SubmodelElementList submodelElement) thr return null; } SubmodelElementListValue value = SubmodelElementListValue.builder().build(); - if (submodelElement.getValue() != null && submodelElement.getValue().stream().noneMatch(Objects::isNull)) { + if (Objects.nonNull(submodelElement.getValue())) { value.setValues(submodelElement.getValue().stream() + .filter(Objects::nonNull) + .filter(ElementValueHelper::isValueOnlySupported) .map(LambdaExceptionHelper.rethrowFunction(ElementValueMapper::toValue)) .map(ElementValue.class::cast) .collect(Collectors.toList())); } - else { - value.setValues(null); - } return value; } diff --git a/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/util/ElementValueHelper.java b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/util/ElementValueHelper.java new file mode 100644 index 000000000..cd9a5e9e3 --- /dev/null +++ b/model/src/main/java/de/fraunhofer/iosb/ilt/faaast/service/util/ElementValueHelper.java @@ -0,0 +1,164 @@ +/* + * 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.service.util; + +import com.google.common.reflect.TypeToken; +import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ValueMappingException; +import de.fraunhofer.iosb.ilt.faaast.service.model.value.DataElementValue; +import de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue; +import de.fraunhofer.iosb.ilt.faaast.service.model.value.mapper.ElementValueMapper; +import java.lang.reflect.Type; +import java.util.Collection; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import org.eclipse.digitaltwin.aas4j.v3.model.AnnotatedRelationshipElement; +import org.eclipse.digitaltwin.aas4j.v3.model.BasicEventElement; +import org.eclipse.digitaltwin.aas4j.v3.model.DataElement; +import org.eclipse.digitaltwin.aas4j.v3.model.Entity; +import org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable; +import org.eclipse.digitaltwin.aas4j.v3.model.ReferenceElement; +import org.eclipse.digitaltwin.aas4j.v3.model.RelationshipElement; +import org.eclipse.digitaltwin.aas4j.v3.model.Submodel; +import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementCollection; +import org.eclipse.digitaltwin.aas4j.v3.model.SubmodelElementList; + + +/** + * Helper class for {@link de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue}. + */ +public class ElementValueHelper { + + private static final Type COLLECTION_GENERIC_TOKEN; + private static final Type MAP_GENERIC_TOKEN; + + static { + try { + COLLECTION_GENERIC_TOKEN = TypeToken.of(Collection.class.getMethod("iterator").getGenericReturnType()).resolveType(Iterator.class.getTypeParameters()[0]).getType(); + MAP_GENERIC_TOKEN = Map.class.getMethod("get", Object.class).getGenericReturnType(); + } + catch (NoSuchMethodException e) { + throw new IllegalStateException("static initialization of ElementValueHelper failed", e); + } + } + + private ElementValueHelper() {} + + + /** + * Checks if an object can be converted to an element value. + * + * @param obj which should be checked + * @return true if the object can be converted to an element value, false otherwise + */ + public static boolean isValueOnlySupported(Object obj) { + if (obj == null) { + return true; + } + Class type = obj.getClass(); + if (type.isArray()) { + return Stream.of((Object[]) obj).allMatch(ElementValueHelper::isValueOnlySupported); + } + if (Collection.class.isAssignableFrom(type)) { + return ((Collection) obj).stream().allMatch(ElementValueHelper::isValueOnlySupported); + } + if (Map.class.isAssignableFrom(type)) { + return ((Map) obj).values().stream().allMatch(ElementValueHelper::isValueOnlySupported); + } + if (Page.class.isAssignableFrom(type)) { + return ((Page) obj).getContent().stream().allMatch(ElementValueHelper::isValueOnlySupported); + } + return isValueOnlySupported(type); + } + + + /** + * Checks if an object of a specific class can be converted to an element value. + * + * @param type which should be checked + * @return true if an object of the type can be converted to an element value, false otherwise + */ + public static boolean isValueOnlySupported(Class type) { + if (isSerializableAsValue(type) + || Submodel.class.isAssignableFrom(type) + || ElementValue.class.isAssignableFrom(type)) { + return true; + } + if (type.isArray()) { + return isValueOnlySupported(TypeToken.of(type).getComponentType()); + } + if (Collection.class.isAssignableFrom(type)) { + return isValueOnlySupported(TypeToken.of(type).resolveType(COLLECTION_GENERIC_TOKEN).getRawType()); + } + if (Map.class.isAssignableFrom(type)) { + return isValueOnlySupported(TypeToken.of(type).resolveType(MAP_GENERIC_TOKEN).getRawType()); + } + return false; + } + + + /** + * Checks if an object of a specific class can be converted to an element value. + * + * @param type which should be checked + * @return true if an object of the type can be converted to an element value, false otherwise + */ + public static boolean isSerializableAsValue(Class type) { + return DataElement.class.isAssignableFrom(type) + || AnnotatedRelationshipElement.class.isAssignableFrom(type) + || BasicEventElement.class.isAssignableFrom(type) + || Entity.class.isAssignableFrom(type) + || ReferenceElement.class.isAssignableFrom(type) + || RelationshipElement.class.isAssignableFrom(type) + || SubmodelElementCollection.class.isAssignableFrom(type) + || SubmodelElementList.class.isAssignableFrom(type); + } + + + /** + * Checks if given value is a valid {@link DataElementValue}. + * + * @param value the value to check + * @return true if value is valid value of type {@link DataElementValue}, false otherwise + */ + public static boolean isValidDataElementValue(Object value) { + return value == null || DataElementValue.class.isAssignableFrom(value.getClass()); + } + + + /** + * Converts a list of {@link org.eclipse.digitaltwin.aas4j.v3.model.OperationVariable} to a map of + * {@link de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue} with their idShort as keys. + * + * @param variables list of operation variables + * @return the corresponding map of element values and their idShorts + * @throws de.fraunhofer.iosb.ilt.faaast.service.model.exception.ValueMappingException if mapping of element values + * fails + */ + public static Map toValueMap(List variables) throws ValueMappingException { + return variables.stream() + .filter(Objects::nonNull) + .map(OperationVariable::getValue) + .filter(Objects::nonNull) + .collect(Collectors.toMap( + x -> x.getIdShort(), + LambdaExceptionHelper.rethrowFunction( + x -> ElementValueMapper.toValue(x)))); + } +} diff --git a/model/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/model/elementvaluemapper/SubmodelElementCollcetionValueTest.java b/model/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/model/elementvaluemapper/SubmodelElementCollcetionValueTest.java index e4488604b..dc966148a 100644 --- a/model/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/model/elementvaluemapper/SubmodelElementCollcetionValueTest.java +++ b/model/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/model/elementvaluemapper/SubmodelElementCollcetionValueTest.java @@ -59,7 +59,6 @@ public void testToValueMapping() throws ValueMappingException { @Test public void testToValueMappingWithNull() throws ValueMappingException { SubmodelElementCollectionValue expected = SubmodelElementCollectionValue.builder() - .values(null) .build(); SubmodelElement input = new DefaultSubmodelElementCollection.Builder() .value((List) null) diff --git a/model/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/model/elementvaluemapper/SubmodelElementListValueTest.java b/model/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/model/elementvaluemapper/SubmodelElementListValueTest.java index be5b02944..d464d689e 100644 --- a/model/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/model/elementvaluemapper/SubmodelElementListValueTest.java +++ b/model/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/model/elementvaluemapper/SubmodelElementListValueTest.java @@ -59,7 +59,6 @@ public void testToValueMapping() throws ValueMappingException { @Test public void testToValueMappingWithNull() throws ValueMappingException { SubmodelElementListValue expected = SubmodelElementListValue.builder() - .values(null) .build(); SubmodelElement input = new DefaultSubmodelElementList.Builder() .value((List) null) diff --git a/test/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/test/AssetConnectionIT.java b/test/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/test/AssetConnectionIT.java index a6e5b7651..5d6f918fc 100644 --- a/test/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/test/AssetConnectionIT.java +++ b/test/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/test/AssetConnectionIT.java @@ -36,6 +36,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.api.StatusCode; import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Content; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.UnsupportedModifierException; import de.fraunhofer.iosb.ilt.faaast.service.persistence.memory.PersistenceInMemoryConfig; import de.fraunhofer.iosb.ilt.faaast.service.test.util.ApiPaths; import de.fraunhofer.iosb.ilt.faaast.service.test.util.HttpHelper; @@ -217,7 +218,8 @@ private static ServiceConfig withAssetConnection(ServiceConfig config, String no private void assertServiceAvailabilityHttp(int port) - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { List expected = environment.getAssetAdministrationShells(); assertExecutePage( HttpMethod.GET, @@ -255,7 +257,8 @@ private void assertTargetValue(int port, int expectedValue) private Page assertExecutePage(HttpMethod method, String url, StatusCode statusCode, Object input, List expected, Class type) - throws IOException, InterruptedException, URISyntaxException, SerializationException, DeserializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, InterruptedException, URISyntaxException, SerializationException, DeserializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { HttpResponse response = HttpHelper.execute(httpClient, method, url, input); assertEquals(toHttpStatusCode(statusCode), response.statusCode()); Page actual = HttpHelper.readResponsePage(response, type); diff --git a/test/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/test/HttpEndpointIT.java b/test/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/test/HttpEndpointIT.java index 914023a6e..b189d63b3 100644 --- a/test/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/test/HttpEndpointIT.java +++ b/test/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/test/HttpEndpointIT.java @@ -63,6 +63,8 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.submodel.InvokeOperationRequest; import de.fraunhofer.iosb.ilt.faaast.service.model.api.request.submodel.InvokeOperationSyncRequest; import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ResourceNotFoundException; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.UnsupportedContentModifierException; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.UnsupportedModifierException; import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ValueFormatException; import de.fraunhofer.iosb.ilt.faaast.service.model.exception.ValueMappingException; import de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.EventMessage; @@ -290,7 +292,8 @@ public AssetOperationProviderConfig getConfig() { @Test public void testAASBasicDiscoveryCreate() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { AssetAdministrationShell aas = environment.getAssetAdministrationShells().get(0); SpecificAssetId newIdentifier = new DefaultSpecificAssetId.Builder() .name("foo") @@ -315,7 +318,8 @@ public void testAASBasicDiscoveryCreate() @Test public void testAASBasicDiscoveryDelete() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { AssetAdministrationShell aas = environment.getAssetAdministrationShells().get(0); aas.getAssetInformation().getSpecificAssetIds().clear(); aas.getAssetInformation().setGlobalAssetId(null); @@ -335,7 +339,8 @@ public void testAASBasicDiscoveryDelete() @Test public void testAASBasicDiscoveryGetAssetAdministrationShells() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { List expected = environment.getAssetAdministrationShells().stream() .map(x -> x.getId()) .collect(Collectors.toList()); @@ -351,7 +356,8 @@ public void testAASBasicDiscoveryGetAssetAdministrationShells() @Test public void testAASBasicDiscoveryGetAssetAdministrationShellsByGlobalAssetId() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { String assetIdValue = "https://acplt.org/Test_Asset"; List expected = environment.getAssetAdministrationShells().stream() .filter(x -> x.getAssetInformation().getGlobalAssetId().equalsIgnoreCase(assetIdValue)) @@ -369,7 +375,8 @@ public void testAASBasicDiscoveryGetAssetAdministrationShellsByGlobalAssetId() @Test public void testAASBasicDiscoveryGetAssetLinks() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { AssetAdministrationShell aas = environment.getAssetAdministrationShells().get(0); List expected = new ArrayList<>(aas.getAssetInformation().getSpecificAssetIds()); expected.add(new DefaultSpecificAssetId.Builder() @@ -503,7 +510,7 @@ public void testAASRepositoryGetAssetAdministrationShellByIdContentReference() @Test public void testAASRepositoryGetAssetAdministrationShellByIdUsingSubmodelIdReturnsResourceNotFound() throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, MessageBusException, NoSuchAlgorithmException, - KeyManagementException { + KeyManagementException, UnsupportedModifierException { String submodelId = environment.getSubmodels().get(1).getId(); assertExecuteSingle(HttpMethod.GET, apiPaths.aasRepository().assetAdministrationShell(submodelId), @@ -527,7 +534,8 @@ public void testAASRepositoryGetAssetAdministrationShellByIdNotExists() @Test public void testAASRepositoryGetAssetAdministrationShells() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { List expected = environment.getAssetAdministrationShells(); assertExecutePage( HttpMethod.GET, @@ -541,7 +549,8 @@ public void testAASRepositoryGetAssetAdministrationShells() @Test public void testAASRepositoryGetAssetAdministrationShellsContentReference() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { List expected = environment.getAssetAdministrationShells().stream() .map(ReferenceBuilder::forAas) .collect(Collectors.toList()); @@ -557,7 +566,8 @@ public void testAASRepositoryGetAssetAdministrationShellsContentReference() @Test public void testAASRepositoryGetAssetAdministrationShellsWithPaging() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { // 4 elements in total are available, query data with increasing page size 1, 2, 3. String cursor = null; List allExpectedShells = environment.getAssetAdministrationShells(); @@ -796,7 +806,7 @@ private void assertSerialization(List aass, boolean in @Test public void testAssetAdministrationShellInterfaceCreateSubmodelRef() throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, MessageBusException, NoSuchAlgorithmException, - KeyManagementException { + KeyManagementException, UnsupportedModifierException { String name = "test"; Reference newReference = new DefaultReference.Builder() .keys(new DefaultKey.Builder() @@ -836,7 +846,7 @@ public void testAssetAdministrationShellInterfaceCreateSubmodelRef() @Test public void testAssetAdministrationShellInterfaceDeleteSubmodelRef() throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, MessageBusException, NoSuchAlgorithmException, - KeyManagementException { + KeyManagementException, UnsupportedModifierException { AssetAdministrationShell aas = environment.getAssetAdministrationShells().get(1); Reference submodelToDelete = aas.getSubmodels().get(0); aas.getSubmodels().remove(submodelToDelete); @@ -912,7 +922,8 @@ public void testAssetAdministrationShellInterfaceGetAssetAdministrationShellNotE @Test public void testAssetAdministrationShellInterfaceGetAssetInformation() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { AssetAdministrationShell aas = environment.getAssetAdministrationShells().get(1); AssetInformation expected = aas.getAssetInformation(); // TODO does this trigger any message bus event? @@ -928,7 +939,8 @@ public void testAssetAdministrationShellInterfaceGetAssetInformation() @Test public void testAssetAdministrationShellInterfaceGetSubmodelRefs() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { AssetAdministrationShell aas = environment.getAssetAdministrationShells().get(1); List expected = aas.getSubmodels(); assertExecutePage( @@ -964,7 +976,7 @@ public void testAssetAdministrationShellInterfaceUpdateAssetAdministrationShell( @Test public void testAssetAdministrationShellInterfaceUpdateAssetInformation() throws InterruptedException, MessageBusException, IOException, URISyntaxException, SerializationException, DeserializationException, NoSuchAlgorithmException, - KeyManagementException { + KeyManagementException, UnsupportedModifierException { AssetAdministrationShell aas = environment.getAssetAdministrationShells().get(1); AssetInformation expected = aas.getAssetInformation(); expected.getSpecificAssetIds().add(new DefaultSpecificAssetId.Builder() @@ -1087,7 +1099,8 @@ public void testConceptDescriptionRepositoryGetConceptDescriptionNotExists() @Test public void testConceptDescriptionRepositoryGetConceptDescriptions() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { List expected = environment.getConceptDescriptions(); assertExecutePage( HttpMethod.GET, @@ -1407,7 +1420,8 @@ public void testSubmodelInterfaceGetSubmodelElementContentReference() @Test public void testSubmodelInterfaceGetSubmodelElements() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { Submodel submodel = environment.getSubmodels().get(0); List expected = submodel.getSubmodelElements(); assertExecutePage( @@ -1422,7 +1436,8 @@ public void testSubmodelInterfaceGetSubmodelElements() @Test public void testSubmodelInterfaceGetSubmodelElementsContentReference() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { Submodel submodel = environment.getSubmodels().get(0); List expected = submodel .getSubmodelElements() @@ -1441,7 +1456,7 @@ public void testSubmodelInterfaceGetSubmodelElementsContentReference() @Test public void testSubmodelInterfaceGetSubmodelContentValue() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, MessageBusException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, MessageBusException, UnsupportedModifierException { Submodel submodel = environment.getSubmodels().get(3); String expected = new JsonApiSerializer().write(submodel, new OutputModifier.Builder() .content(Content.VALUE) @@ -1477,7 +1492,8 @@ public void testSubmodelInterfaceFileAttachmentWithRelativePath() @Test public void testAASThumbnail() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { AssetAdministrationShell aas = environment.getAssetAdministrationShells().get(1); AssetInformation expected = aas.getAssetInformation(); String imageName = "file:///image.png"; @@ -1525,7 +1541,7 @@ public void testAASThumbnail() @Test public void testSubmodelInterfaceGetSubmodelContentMetadata() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, MessageBusException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, MessageBusException, UnsupportedModifierException { Submodel submodel = DeepCopyHelper.deepCopy(environment.getSubmodels().get(3)); String expected = new JsonApiSerializer().write(submodel, new OutputModifier.Builder() .content(Content.METADATA) @@ -1641,7 +1657,7 @@ public void testSubmodelInterfaceGetSubmodelLevelDeep() @Test public void testSubmodelInterfaceInvokeOperationAsync() throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, MessageBusException, NoSuchAlgorithmException, - KeyManagementException { + KeyManagementException, UnsupportedModifierException { int inputValue = 4; Reference reference = operationSquareIdentifier.toReference(); CountDownLatch condition = new CountDownLatch(1); @@ -1792,7 +1808,7 @@ private static T getOperationSqaureInvokeRequ @Test public void testSubmodelInterfaceInvokeOperationAsyncValueOnly() throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, MessageBusException, NoSuchAlgorithmException, - KeyManagementException, JSONException { + KeyManagementException, JSONException, UnsupportedContentModifierException, UnsupportedModifierException { int inputValue = 4; Reference reference = operationSquareIdentifier.toReference(); @@ -1987,7 +2003,7 @@ public void testSubmodelInterfaceInvokeOperationSyncWithExceptionInOperation() @Test public void testSubmodelInterfaceInvokeOperationAsyncWithTimeout() throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, MessageBusException, NoSuchAlgorithmException, - KeyManagementException, ValueMappingException { + KeyManagementException, ValueMappingException, UnsupportedModifierException { Reference reference = operationSquareIdentifier.toReference(); mockOperation(reference, (input, inoutput) -> { try { @@ -2054,7 +2070,7 @@ public void testSubmodelInterfaceInvokeOperationAsyncWithTimeout() @Test public void testSubmodelInterfaceInvokeOperationAsyncWithExceptionInOperation() throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, MessageBusException, NoSuchAlgorithmException, - KeyManagementException, ValueMappingException { + KeyManagementException, ValueMappingException, UnsupportedModifierException { Reference reference = operationSquareIdentifier.toReference(); mockOperation(reference, (input, inoutput) -> { throw new UnsupportedOperationException("not implemented"); @@ -2356,7 +2372,7 @@ public void testSubmodelInterfaceGetSubmodelElementInAasContext() @Test public void testSubmodelInterfaceGetSubmodelElementsInAasContext() throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, ResourceNotFoundException, NoSuchAlgorithmException, - KeyManagementException { + KeyManagementException, UnsupportedModifierException { AssetAdministrationShell aas = environment.getAssetAdministrationShells().get(1); Submodel submodel = EnvironmentHelper.resolve(aas.getSubmodels().get(0), environment, Submodel.class); List expected = submodel.getSubmodelElements(); @@ -2372,7 +2388,8 @@ public void testSubmodelInterfaceGetSubmodelElementsInAasContext() @Test public void testSubmodelInterfaceGetSubmodelContentValueInAasContext() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, MessageBusException, ResourceNotFoundException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, MessageBusException, ResourceNotFoundException, + UnsupportedModifierException { AssetAdministrationShell aas = environment.getAssetAdministrationShells().get(1); Submodel submodel = EnvironmentHelper.resolve(aas.getSubmodels().get(0), environment, Submodel.class); String expected = new JsonApiSerializer().write(submodel, new OutputModifier.Builder() @@ -2677,7 +2694,8 @@ public void testSubmodelRepositoryGetSubmodelNotExists() @Test public void testSubmodelRepositoryGetSubmodels() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { List expected = environment.getSubmodels(); ExtendHelper.withoutBlobValue(expected); assertExecutePage( @@ -2692,7 +2710,8 @@ public void testSubmodelRepositoryGetSubmodels() @Test public void testSubmodelRepositoryGetSubmodelsContentReference() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { List expected = environment.getSubmodels().stream() .map(ReferenceBuilder::forSubmodel) .collect(Collectors.toList()); @@ -2708,7 +2727,8 @@ public void testSubmodelRepositoryGetSubmodelsContentReference() @Test public void testSubmodelRepositoryGetSubmodelsByIdShort() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { Submodel expected = environment.getSubmodels().get(1); assertExecutePage( HttpMethod.GET, @@ -2722,7 +2742,8 @@ public void testSubmodelRepositoryGetSubmodelsByIdShort() @Test public void testSubmodelRepositoryGetSubmodelsBySemanticId() - throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, DeserializationException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { Submodel expected = environment.getSubmodels().get(1); assertExecutePage(HttpMethod.GET, String.format("%s?semanticId=%s", @@ -2766,13 +2787,15 @@ public void testMethodNotAllowed() throws Exception { private void assertExecute(HttpMethod method, String url, StatusCode statusCode) - throws IOException, InterruptedException, URISyntaxException, SerializationException, DeserializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, InterruptedException, URISyntaxException, SerializationException, DeserializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { assertExecuteSingle(method, url, statusCode, null, null, null); } private void assertExecuteMultiple(HttpMethod method, String url, StatusCode statusCode, Object input, Object expected, Class type) - throws IOException, InterruptedException, URISyntaxException, SerializationException, DeserializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, InterruptedException, URISyntaxException, SerializationException, DeserializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { HttpResponse response = HttpHelper.execute(httpClient, method, url, input); Assert.assertEquals(toHttpStatusCode(statusCode), response.statusCode()); if (expected != null) { @@ -2783,7 +2806,8 @@ private void assertExecuteMultiple(HttpMethod method, String url, StatusCode sta private Page assertExecutePage(HttpMethod method, String url, StatusCode statusCode, Object input, List expected, Class type) - throws IOException, InterruptedException, URISyntaxException, SerializationException, DeserializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, InterruptedException, URISyntaxException, SerializationException, DeserializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { HttpResponse response = HttpHelper.execute(httpClient, method, url, input); Assert.assertEquals(toHttpStatusCode(statusCode), response.statusCode()); Page actual = HttpHelper.readResponsePage(response, type); @@ -2795,7 +2819,8 @@ private Page assertExecutePage(HttpMethod method, String url, StatusCode private HttpResponse assertExecuteSingle(HttpMethod method, String url, StatusCode statusCode, Object input, Object expected, Class type) - throws IOException, InterruptedException, URISyntaxException, SerializationException, DeserializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, InterruptedException, URISyntaxException, SerializationException, DeserializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { HttpResponse response = HttpHelper.execute(httpClient, method, url, input); Assert.assertEquals(toHttpStatusCode(statusCode), response.statusCode()); if (expected != null) { diff --git a/test/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/test/util/ApiPaths.java b/test/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/test/util/ApiPaths.java index 58efb4e01..ff84ef441 100644 --- a/test/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/test/util/ApiPaths.java +++ b/test/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/test/util/ApiPaths.java @@ -21,6 +21,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Content; import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Extent; import de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.Level; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.UnsupportedModifierException; import de.fraunhofer.iosb.ilt.faaast.service.util.EncodingHelper; import de.fraunhofer.iosb.ilt.faaast.service.util.StringHelper; import java.net.URLEncoder; @@ -256,7 +257,7 @@ public String assetAdministrationShells(String cursor, long limit) { } - public String assetAdministrationShells(Map assetIds) throws SerializationException { + public String assetAdministrationShells(Map assetIds) throws SerializationException, UnsupportedModifierException { return String.format("%s?assetIds=%s", assetAdministrationShells(), EncodingHelper.base64UrlEncode(new HttpJsonApiSerializer().write( @@ -269,7 +270,7 @@ public String assetAdministrationShells(Map assetIds) throws Ser } - public String assetAdministrationShells(Map assetIds, String cursor, long limit) throws SerializationException { + public String assetAdministrationShells(Map assetIds, String cursor, long limit) throws SerializationException, UnsupportedModifierException { return paging(assetAdministrationShells(assetIds), cursor, limit); } diff --git a/test/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/test/util/HttpHelper.java b/test/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/test/util/HttpHelper.java index 416a92eb7..8dea11444 100644 --- a/test/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/test/util/HttpHelper.java +++ b/test/src/test/java/de/fraunhofer/iosb/ilt/faaast/service/test/util/HttpHelper.java @@ -23,6 +23,7 @@ import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.model.HttpMethod; import de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.util.HttpConstants; import de.fraunhofer.iosb.ilt.faaast.service.model.api.paging.Page; +import de.fraunhofer.iosb.ilt.faaast.service.model.exception.UnsupportedModifierException; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; @@ -61,13 +62,15 @@ public static T getWithSingleResult(HttpClient client, String url, Class public static T postWithSingleResult(HttpClient client, String url, T payload, Class type) - throws IOException, URISyntaxException, InterruptedException, SerializationException, DeserializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, URISyntaxException, InterruptedException, SerializationException, DeserializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { return (T) readResponse(post(client, url, payload), type); } public static T putWithSingleResult(HttpClient client, String url, T payload, Class type) - throws IOException, InterruptedException, URISyntaxException, DeserializationException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, InterruptedException, URISyntaxException, DeserializationException, SerializationException, NoSuchAlgorithmException, KeyManagementException, + UnsupportedModifierException { return (T) readResponse(put(client, url, payload), type); } @@ -79,7 +82,7 @@ public static T deleteWithSingleResult(HttpClient client, String url, Class< public static HttpResponse execute(HttpClient client, HttpMethod method, String url, Object payload) - throws IOException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, UnsupportedModifierException { switch (method) { case GET: return get(client, url); @@ -96,13 +99,13 @@ public static HttpResponse execute(HttpClient client, HttpMethod method, public static HttpResponse execute(HttpClient client, HttpMethod method, String url) - throws IOException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, UnsupportedModifierException { return execute(client, method, url, null); } public static HttpResponse put(HttpClient client, String url, Object payload) - throws IOException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, UnsupportedModifierException { return client .send(HttpRequest.newBuilder() .uri(new URI(url)) @@ -114,7 +117,7 @@ public static HttpResponse put(HttpClient client, String url, Object pay public static HttpResponse post(HttpClient client, String url, Object payload) - throws IOException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException { + throws IOException, InterruptedException, URISyntaxException, SerializationException, NoSuchAlgorithmException, KeyManagementException, UnsupportedModifierException { return client .send(HttpRequest.newBuilder() .uri(new URI(url))