Search in sources :

Example 1 with Submodel

use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.

the class RequestHandlerManagerTest method testDeleteSubmodelElementByPathRequest.

@Test
public void testDeleteSubmodelElementByPathRequest() throws ResourceNotFoundException {
    Submodel submodel = environment.getSubmodels().get(0);
    Reference reference = ReferenceHelper.toReference(ReferenceHelper.toKeys(SUBMODEL_ELEMENT_REF), submodel.getIdentification(), Submodel.class);
    when(persistence.get(reference, new QueryModifier())).thenReturn(environment.getSubmodels().get(0).getSubmodelElements().get(0));
    DeleteSubmodelElementByPathRequest request = new DeleteSubmodelElementByPathRequest.Builder().id(submodel.getIdentification()).path(ReferenceHelper.toKeys(SUBMODEL_ELEMENT_REF)).build();
    DeleteSubmodelElementByPathResponse response = manager.execute(request);
    DeleteSubmodelElementByPathResponse expected = new DeleteSubmodelElementByPathResponse.Builder().statusCode(StatusCode.Success).build();
    Assert.assertEquals(expected, response);
    verify(persistence).remove(reference);
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) AtomicReference(java.util.concurrent.atomic.AtomicReference) QueryModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier) DeleteSubmodelElementByPathResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.DeleteSubmodelElementByPathResponse) DeleteSubmodelElementByPathRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.DeleteSubmodelElementByPathRequest) Test(org.junit.Test)

Example 2 with Submodel

use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.

the class ReferenceHelper method completeReferenceWithProperKeyElements.

/**
 * Browse the keys of a reference and try to find the referenced element in the
 * asset administration shell environment to set the right {@link io.adminshell.aas.v3.model.KeyElements}
 * of the key.
 * All key types must be null or SUBMODEL_ELEMENT.
 *
 * @param reference with keys which should be completed
 * @param env the asset administration shell environment which contains the referenced elements
 * @throws ResourceNotFoundException if an element referenced by a key could not be found
 */
public static void completeReferenceWithProperKeyElements(Reference reference, AssetAdministrationShellEnvironment env) throws ResourceNotFoundException {
    if (reference == null) {
        return;
    }
    List<Key> keys = reference.getKeys();
    if (keys.stream().allMatch(x -> x.getType() != null && x.getType() != KeyElements.SUBMODEL_ELEMENT)) {
        return;
    }
    final Referable[] parent = { null };
    for (Key k : keys) {
        if (env.getAssetAdministrationShells().stream().anyMatch(x -> x.getIdentification().getIdentifier().equalsIgnoreCase(k.getValue()) || x.getIdShort().equalsIgnoreCase(k.getValue()))) {
            k.setType(KeyElements.ASSET_ADMINISTRATION_SHELL);
            continue;
        }
        env.getSubmodels().forEach(x -> {
            if (x.getIdentification().getIdentifier().equalsIgnoreCase(k.getValue()) || x.getIdShort().equalsIgnoreCase(k.getValue())) {
                k.setType(KeyElements.SUBMODEL);
                parent[0] = x;
            }
        });
        if (k.getType() != null && k.getType() != KeyElements.SUBMODEL_ELEMENT) {
            continue;
        }
        if (env.getConceptDescriptions().stream().anyMatch(x -> x.getIdentification().getIdentifier().equalsIgnoreCase(k.getValue()) || x.getIdShort().equalsIgnoreCase(k.getValue()))) {
            k.setType(KeyElements.CONCEPT_DESCRIPTION);
            continue;
        }
        if (env.getAssets().stream().anyMatch(x -> x.getIdentification().getIdentifier().equalsIgnoreCase(k.getValue()) || x.getIdShort().equalsIgnoreCase(k.getValue()))) {
            k.setType(KeyElements.ASSET);
            continue;
        }
        if (parent[0] != null && Submodel.class.isAssignableFrom(parent[0].getClass())) {
            Submodel submodel = (Submodel) parent[0];
            submodel.getSubmodelElements().forEach(y -> {
                if (y.getIdShort().equalsIgnoreCase(k.getValue())) {
                    k.setType(AasUtils.referableToKeyType(y));
                    parent[0] = y;
                }
            });
        } else if (SubmodelElementCollection.class.isAssignableFrom(parent[0].getClass())) {
            ((SubmodelElementCollection) parent[0]).getValues().forEach(x -> {
                if (x.getIdShort().equalsIgnoreCase(k.getValue())) {
                    k.setType(AasUtils.referableToKeyType(x));
                    parent[0] = x;
                }
            });
        } else if (Operation.class.isAssignableFrom(parent[0].getClass())) {
            Operation operation = (Operation) parent[0];
            Stream.concat(Stream.concat(operation.getInoutputVariables().stream(), operation.getInputVariables().stream()), operation.getOutputVariables().stream()).forEach(x -> {
                if (x.getValue().getIdShort().equalsIgnoreCase(k.getValue())) {
                    k.setType(AasUtils.referableToKeyType(x.getValue()));
                    parent[0] = x.getValue();
                }
            });
        }
        if (k.getType() == null) {
            throw new ResourceNotFoundException("Resource with ID " + k.getValue() + " was not found!");
        }
    }
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) KeyElements(io.adminshell.aas.v3.model.KeyElements) Operation(io.adminshell.aas.v3.model.Operation) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) Reference(io.adminshell.aas.v3.model.Reference) AssetAdministrationShellEnvironment(io.adminshell.aas.v3.model.AssetAdministrationShellEnvironment) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) Collectors(java.util.stream.Collectors) AasUtils(io.adminshell.aas.v3.dataformat.core.util.AasUtils) Identifier(io.adminshell.aas.v3.model.Identifier) ArrayList(java.util.ArrayList) ReflectionHelper(io.adminshell.aas.v3.dataformat.core.ReflectionHelper) Key(io.adminshell.aas.v3.model.Key) List(java.util.List) Stream(java.util.stream.Stream) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) Referable(io.adminshell.aas.v3.model.Referable) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) KeyType(io.adminshell.aas.v3.model.KeyType) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) Submodel(io.adminshell.aas.v3.model.Submodel) Referable(io.adminshell.aas.v3.model.Referable) SubmodelElementCollection(io.adminshell.aas.v3.model.SubmodelElementCollection) Operation(io.adminshell.aas.v3.model.Operation) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) Key(io.adminshell.aas.v3.model.Key) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey)

Example 3 with Submodel

use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.

the class PostSubmodelRequestHandler method process.

@Override
public PostSubmodelResponse process(PostSubmodelRequest request) {
    PostSubmodelResponse response = new PostSubmodelResponse();
    try {
        Submodel submodel = (Submodel) persistence.put(request.getSubmodel());
        response.setPayload(submodel);
        response.setStatusCode(StatusCode.SuccessCreated);
        Reference reference = AasUtils.toReference(submodel);
        readValueFromAssetConnectionAndUpdatePersistence(reference, submodel.getSubmodelElements());
        publishElementCreateEventMessage(reference, submodel);
    } catch (Exception ex) {
        response.setStatusCode(StatusCode.ServerInternalError);
    }
    return response;
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) PostSubmodelResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PostSubmodelResponse) Reference(io.adminshell.aas.v3.model.Reference)

Example 4 with Submodel

use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.

the class ElementValueMapperTest method testEntitySetValueMapping.

@Test
public void testEntitySetValueMapping() throws ValueFormatException {
    SubmodelElement actual = new DefaultEntity.Builder().statement(new DefaultProperty.Builder().idShort("property").build()).build();
    EntityValue value = EntityValue.builder().statement("property", PropertyValue.of(Datatype.String, "foo")).entityType(EntityType.SELF_MANAGED_ENTITY).globalAssetId(List.of(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value("http://example.org/submodel/1").build(), new DefaultKey.Builder().idType(KeyType.ID_SHORT).type(KeyElements.PROPERTY).value("property1").build())).build();
    SubmodelElement expected = new DefaultEntity.Builder().statement(new DefaultProperty.Builder().idShort(value.getStatements().keySet().iterator().next()).valueType(Datatype.String.getName()).value("foo").build()).entityType(value.getEntityType()).globalAssetId(new DefaultReference.Builder().keys(value.getGlobalAssetId()).build()).build();
    ElementValueMapper.setValue(actual, value);
    Assert.assertEquals(expected, actual);
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) EntityValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.EntityValue) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) Test(org.junit.Test)

Example 5 with Submodel

use of io.adminshell.aas.v3.model.Submodel in project FAAAST-Service by FraunhoferIOSB.

the class ElementValueMapperTest method testRelationshipElementSetValueMapping.

@Test
public void testRelationshipElementSetValueMapping() {
    SubmodelElement actual = new DefaultRelationshipElement.Builder().build();
    RelationshipElementValue value = RelationshipElementValue.builder().first(List.of(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value("http://example.org/submodel/1").build(), new DefaultKey.Builder().idType(KeyType.ID_SHORT).type(KeyElements.PROPERTY).value("property1").build())).second(List.of(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value("http://example.org/submodel/2").build(), new DefaultKey.Builder().idType(KeyType.ID_SHORT).type(KeyElements.PROPERTY).value("property2").build())).build();
    SubmodelElement expected = new DefaultRelationshipElement.Builder().first(new DefaultReference.Builder().keys(value.getFirst()).build()).second(new DefaultReference.Builder().keys(value.getSecond()).build()).build();
    ElementValueMapper.setValue(actual, value);
    Assert.assertEquals(expected, actual);
}
Also used : SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) RelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.RelationshipElementValue) AnnotatedRelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue) DefaultRelationshipElement(io.adminshell.aas.v3.model.impl.DefaultRelationshipElement) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)38 Submodel (io.adminshell.aas.v3.model.Submodel)36 Reference (io.adminshell.aas.v3.model.Reference)34 LangString (io.adminshell.aas.v3.model.LangString)30 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)30 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)22 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)21 SubmodelElement (io.adminshell.aas.v3.model.SubmodelElement)21 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)19 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)17 ObjectData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData)15 DefaultSubmodel (io.adminshell.aas.v3.model.impl.DefaultSubmodel)14 DefaultKey (io.adminshell.aas.v3.model.impl.DefaultKey)13 ArrayList (java.util.ArrayList)13 ResourceNotFoundException (de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)12 DefaultIdentifier (io.adminshell.aas.v3.model.impl.DefaultIdentifier)12 QueryModifier (de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier)11 Identifier (io.adminshell.aas.v3.model.Identifier)10 SubmodelElementCollection (io.adminshell.aas.v3.model.SubmodelElementCollection)8 List (java.util.List)8