Search in sources :

Example 1 with DeserializationException

use of de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException in project FAAAST-Service by FraunhoferIOSB.

the class IntegrationTestHttpEndpoint method testGETShellsWithAssetIds.

@Test
public void testGETShellsWithAssetIds() throws IOException, DeserializationException {
    String assetIdValue = "https://acplt.org/Test_Asset";
    List<AssetAdministrationShell> expected = environment.getAssetAdministrationShells().stream().filter(x -> x.getAssetInformation().getGlobalAssetId().getKeys().stream().anyMatch(y -> y.getValue().equalsIgnoreCase(assetIdValue))).collect(Collectors.toList());
    String assetIdsParameter = "[{\"key\": \"globalAssetId\",\"value\":\"" + assetIdValue + "\"}]";
    HttpResponse response = getListCall(HTTP_SHELLS + "?assetIds=" + Base64.getUrlEncoder().encodeToString(assetIdsParameter.getBytes(StandardCharsets.UTF_8)));
    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    List<AssetAdministrationShell> actual = retrieveResourceFromResponseList(response, AssetAdministrationShell.class);
    Assert.assertEquals(expected, actual);
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) ElementReadEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.access.ElementReadEventMessage) AASFull(de.fraunhofer.iosb.ilt.faaast.service.model.AASFull) AssetAdministrationShellEnvironment(io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment) HttpStatus(org.apache.http.HttpStatus) Service(de.fraunhofer.iosb.ilt.faaast.service.Service) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) ServiceConfig(de.fraunhofer.iosb.ilt.faaast.service.config.ServiceConfig) AssetInformation(io.adminshell.aas.v3.model.AssetInformation) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) ArrayList(java.util.ArrayList) MessageBusInternalConfig(de.fraunhofer.iosb.ilt.faaast.service.messagebus.internal.MessageBusInternalConfig) DeserializationException(de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException) SubscriptionInfo(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionInfo) AssetKind(io.adminshell.aas.v3.model.AssetKind) After(org.junit.After) KeyType(io.adminshell.aas.v3.model.KeyType) LangString(io.adminshell.aas.v3.model.LangString) DefaultAssetAdministrationShell(io.adminshell.aas.v3.model.impl.DefaultAssetAdministrationShell) Util(de.fraunhofer.iosb.ilt.faaast.service.starter.integrationtests.Util) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) ElementDeleteEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage) Before(org.junit.Before) MessageBus(de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus) DefaultSubmodel(io.adminshell.aas.v3.model.impl.DefaultSubmodel) IdentifierType(io.adminshell.aas.v3.model.IdentifierType) Reference(io.adminshell.aas.v3.model.Reference) HttpEndpointConfig(de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.HttpEndpointConfig) IOException(java.io.IOException) Test(org.junit.Test) SubscriptionId(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionId) ElementCreateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage) SerializationException(de.fraunhofer.iosb.ilt.faaast.service.dataformat.SerializationException) JsonSerializer(de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.JsonSerializer) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Base64(java.util.Base64) List(java.util.List) PersistenceInMemoryConfig(de.fraunhofer.iosb.ilt.faaast.service.persistence.memory.PersistenceInMemoryConfig) CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) HttpResponse(org.apache.http.HttpResponse) ElementUpdateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementUpdateEventMessage) AssetAdministrationShell(io.adminshell.aas.v3.model.AssetAdministrationShell) Assert(org.junit.Assert) Submodel(io.adminshell.aas.v3.model.Submodel) DefaultAssetAdministrationShell(io.adminshell.aas.v3.model.impl.DefaultAssetAdministrationShell) AssetAdministrationShell(io.adminshell.aas.v3.model.AssetAdministrationShell) HttpResponse(org.apache.http.HttpResponse) LangString(io.adminshell.aas.v3.model.LangString) Test(org.junit.Test)

Example 2 with DeserializationException

use of de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException in project FAAAST-Service by FraunhoferIOSB.

the class IntegrationTestHttpEndpoint method testGETShellsWithIdShort.

@Test
public void testGETShellsWithIdShort() throws IOException, DeserializationException {
    List<AssetAdministrationShell> expected = environment.getAssetAdministrationShells().stream().filter(x -> x.getIdShort().equalsIgnoreCase(environment.getAssetAdministrationShells().get(0).getIdShort())).collect(Collectors.toList());
    HttpResponse response = getListCall(HTTP_SHELLS + "?idShort=" + environment.getAssetAdministrationShells().get(0).getIdShort());
    Assert.assertEquals(HttpStatus.SC_OK, response.getStatusLine().getStatusCode());
    List<AssetAdministrationShell> actual = retrieveResourceFromResponseList(response, AssetAdministrationShell.class);
    Assert.assertEquals(expected, actual);
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) ElementReadEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.access.ElementReadEventMessage) AASFull(de.fraunhofer.iosb.ilt.faaast.service.model.AASFull) AssetAdministrationShellEnvironment(io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment) HttpStatus(org.apache.http.HttpStatus) Service(de.fraunhofer.iosb.ilt.faaast.service.Service) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) ServiceConfig(de.fraunhofer.iosb.ilt.faaast.service.config.ServiceConfig) AssetInformation(io.adminshell.aas.v3.model.AssetInformation) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) ArrayList(java.util.ArrayList) MessageBusInternalConfig(de.fraunhofer.iosb.ilt.faaast.service.messagebus.internal.MessageBusInternalConfig) DeserializationException(de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException) SubscriptionInfo(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionInfo) AssetKind(io.adminshell.aas.v3.model.AssetKind) After(org.junit.After) KeyType(io.adminshell.aas.v3.model.KeyType) LangString(io.adminshell.aas.v3.model.LangString) DefaultAssetAdministrationShell(io.adminshell.aas.v3.model.impl.DefaultAssetAdministrationShell) Util(de.fraunhofer.iosb.ilt.faaast.service.starter.integrationtests.Util) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) ElementDeleteEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementDeleteEventMessage) Before(org.junit.Before) MessageBus(de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus) DefaultSubmodel(io.adminshell.aas.v3.model.impl.DefaultSubmodel) IdentifierType(io.adminshell.aas.v3.model.IdentifierType) Reference(io.adminshell.aas.v3.model.Reference) HttpEndpointConfig(de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.HttpEndpointConfig) IOException(java.io.IOException) Test(org.junit.Test) SubscriptionId(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionId) ElementCreateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementCreateEventMessage) SerializationException(de.fraunhofer.iosb.ilt.faaast.service.dataformat.SerializationException) JsonSerializer(de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.JsonSerializer) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Base64(java.util.Base64) List(java.util.List) PersistenceInMemoryConfig(de.fraunhofer.iosb.ilt.faaast.service.persistence.memory.PersistenceInMemoryConfig) CoreConfig(de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) HttpResponse(org.apache.http.HttpResponse) ElementUpdateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementUpdateEventMessage) AssetAdministrationShell(io.adminshell.aas.v3.model.AssetAdministrationShell) Assert(org.junit.Assert) Submodel(io.adminshell.aas.v3.model.Submodel) DefaultAssetAdministrationShell(io.adminshell.aas.v3.model.impl.DefaultAssetAdministrationShell) AssetAdministrationShell(io.adminshell.aas.v3.model.AssetAdministrationShell) HttpResponse(org.apache.http.HttpResponse) Test(org.junit.Test)

Example 3 with DeserializationException

use of de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException in project FAAAST-Service by FraunhoferIOSB.

the class JsonDeserializerTest method compareValueList.

private void compareValueList(Map<SubmodelElement, File> input) throws DeserializationException, IOException {
    List<Object> expected = input.keySet().stream().map(x -> ElementValueMapper.toValue(x)).collect(Collectors.toList());
    TypeInfo typeInfo = TypeExtractor.extractTypeInfo(input.keySet());
    List<ElementValue> actual = deserializer.readValueList(filesAsJsonArray(input), typeInfo);
    Assert.assertEquals(expected, actual);
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) TypeExtractor(de.fraunhofer.iosb.ilt.faaast.service.typing.TypeExtractor) ElementValueMapper(de.fraunhofer.iosb.ilt.faaast.service.model.value.mapper.ElementValueMapper) Datatype(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.Datatype) IOException(java.io.IOException) Test(org.junit.Test) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Level(java.util.logging.Level) List(java.util.List) DeserializationException(de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException) RangeValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.RangeValue) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) PropertyValues(de.fraunhofer.iosb.ilt.faaast.service.serialization.json.fixture.PropertyValues) Map(java.util.Map) JsonDeserializer(de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.JsonDeserializer) TypeInfo(de.fraunhofer.iosb.ilt.faaast.service.typing.TypeInfo) PropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue) Assert(org.junit.Assert) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) TypeInfo(de.fraunhofer.iosb.ilt.faaast.service.typing.TypeInfo)

Example 4 with DeserializationException

use of de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException in project FAAAST-Service by FraunhoferIOSB.

the class SetSubmodelElementValueByPathRequestMapper method parse.

@Override
public Request parse(HttpRequest httpRequest) {
    final List<Key> path = ElementPathHelper.toKeys(EncodingHelper.urlDecode(httpRequest.getPathElements().get(4)));
    final Identifier identifier = IdentifierHelper.parseIdentifier(EncodingHelper.base64Decode(httpRequest.getPathElements().get(1)));
    return SetSubmodelElementValueByPathRequest.builder().id(identifier).path(path).value(httpRequest.getBody()).valueParser(new ElementValueParser<Object>() {

        @Override
        public <U extends ElementValue> U parse(Object raw, Class<U> type) throws DeserializationException {
            if (ElementValue.class.isAssignableFrom(type)) {
                return deserializer.readValue(raw.toString(), serviceContext.getTypeInfo(ReferenceHelper.toReference(path, identifier, Submodel.class)));
            } else if (SubmodelElement.class.isAssignableFrom(type)) {
                SubmodelElement submodelElement = (SubmodelElement) deserializer.read(raw.toString(), type);
                return ElementValueMapper.toValue(submodelElement);
            }
            throw new DeserializationException(String.format("error deserializing payload - invalid type '%s' (must be either instance of ElementValue or SubmodelElement", type.getSimpleName()));
        }
    }).build();
}
Also used : ElementValueParser(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValueParser) Identifier(io.adminshell.aas.v3.model.Identifier) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) Key(io.adminshell.aas.v3.model.Key) DeserializationException(de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException)

Example 5 with DeserializationException

use of de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException in project FAAAST-Service by FraunhoferIOSB.

the class JsonDeserializerTest method compareValueMap.

private void compareValueMap(Map<SubmodelElement, File> input) throws DeserializationException, IOException {
    Map<Object, ElementValue> expected = input.keySet().stream().collect(Collectors.toMap(x -> x.getIdShort(), x -> ElementValueMapper.toValue(x)));
    TypeInfo typeInfo = TypeExtractor.extractTypeInfo(input.keySet().stream().collect(Collectors.toMap(x -> x.getIdShort(), x -> x)));
    Map<Object, ElementValue> actual = deserializer.readValueMap(filesAsJsonObject(input), typeInfo);
    Assert.assertEquals(expected, actual);
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) TypeExtractor(de.fraunhofer.iosb.ilt.faaast.service.typing.TypeExtractor) ElementValueMapper(de.fraunhofer.iosb.ilt.faaast.service.model.value.mapper.ElementValueMapper) Datatype(de.fraunhofer.iosb.ilt.faaast.service.model.value.primitive.Datatype) IOException(java.io.IOException) Test(org.junit.Test) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Level(java.util.logging.Level) List(java.util.List) DeserializationException(de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException) RangeValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.RangeValue) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) PropertyValues(de.fraunhofer.iosb.ilt.faaast.service.serialization.json.fixture.PropertyValues) Map(java.util.Map) JsonDeserializer(de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.JsonDeserializer) TypeInfo(de.fraunhofer.iosb.ilt.faaast.service.typing.TypeInfo) PropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.PropertyValue) Assert(org.junit.Assert) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) TypeInfo(de.fraunhofer.iosb.ilt.faaast.service.typing.TypeInfo)

Aggregations

DeserializationException (de.fraunhofer.iosb.ilt.faaast.service.dataformat.DeserializationException)6 SubmodelElement (io.adminshell.aas.v3.model.SubmodelElement)6 IOException (java.io.IOException)5 List (java.util.List)5 Collectors (java.util.stream.Collectors)5 Assert (org.junit.Assert)5 Test (org.junit.Test)5 ElementValue (de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue)3 Service (de.fraunhofer.iosb.ilt.faaast.service.Service)2 CoreConfig (de.fraunhofer.iosb.ilt.faaast.service.config.CoreConfig)2 ServiceConfig (de.fraunhofer.iosb.ilt.faaast.service.config.ServiceConfig)2 SerializationException (de.fraunhofer.iosb.ilt.faaast.service.dataformat.SerializationException)2 JsonDeserializer (de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.JsonDeserializer)2 JsonSerializer (de.fraunhofer.iosb.ilt.faaast.service.dataformat.json.JsonSerializer)2 HttpEndpointConfig (de.fraunhofer.iosb.ilt.faaast.service.endpoint.http.HttpEndpointConfig)2 MessageBus (de.fraunhofer.iosb.ilt.faaast.service.messagebus.MessageBus)2 MessageBusInternalConfig (de.fraunhofer.iosb.ilt.faaast.service.messagebus.internal.MessageBusInternalConfig)2 AASFull (de.fraunhofer.iosb.ilt.faaast.service.model.AASFull)2 SubscriptionId (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionId)2 SubscriptionInfo (de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.SubscriptionInfo)2