Search in sources :

Example 6 with Submodel

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

the class ElementValueMapperTest method testEntityToValueMapping.

@Test
public void testEntityToValueMapping() throws ValueFormatException {
    EntityValue expected = 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 input = new DefaultEntity.Builder().statement(new DefaultProperty.Builder().category("Test").idShort(expected.getStatements().keySet().iterator().next()).valueType(Datatype.String.getName()).value("foo").build()).entityType(expected.getEntityType()).globalAssetId(new DefaultReference.Builder().keys(expected.getGlobalAssetId()).build()).build();
    ElementValue actual = ElementValueMapper.toValue(input);
    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) RelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.RelationshipElementValue) ReferenceElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue) ElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ElementValue) AnnotatedRelationshipElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.AnnotatedRelationshipElementValue) DefaultProperty(io.adminshell.aas.v3.model.impl.DefaultProperty) Test(org.junit.Test)

Example 7 with Submodel

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

the class ElementValueMapperTest method testReferenceElementSetValueMapping.

@Test
public void testReferenceElementSetValueMapping() {
    SubmodelElement actual = new DefaultReferenceElement.Builder().value(new DefaultReference.Builder().build()).build();
    ReferenceElementValue value = ReferenceElementValue.builder().key(KeyType.IRI, KeyElements.SUBMODEL, "http://example.org/submodel/1").key(KeyType.ID_SHORT, KeyElements.PROPERTY, "property1").build();
    SubmodelElement expected = new DefaultReferenceElement.Builder().value(new DefaultReference.Builder().keys(value.getKeys()).build()).build();
    ElementValueMapper.setValue(actual, value);
    Assert.assertEquals(expected, actual);
}
Also used : ReferenceElementValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.ReferenceElementValue) SubmodelElement(io.adminshell.aas.v3.model.SubmodelElement) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) Test(org.junit.Test)

Example 8 with Submodel

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

the class PutSubmodelRequestHandler method process.

@Override
public PutSubmodelResponse process(PutSubmodelRequest request) {
    PutSubmodelResponse response = new PutSubmodelResponse();
    try {
        // check if resource does exist
        Submodel submodel = (Submodel) persistence.get(request.getSubmodel().getIdentification(), new QueryModifier.Builder().extend(Extend.WithoutBLOBValue).level(Level.Core).build());
        submodel = (Submodel) persistence.put(request.getSubmodel());
        response.setPayload(submodel);
        response.setStatusCode(StatusCode.Success);
        Reference reference = AasUtils.toReference(submodel);
        readValueFromAssetConnectionAndUpdatePersistence(reference, submodel.getSubmodelElements());
        publishElementUpdateEventMessage(reference, submodel);
    } catch (ResourceNotFoundException ex) {
        response.setStatusCode(StatusCode.ClientErrorResourceNotFound);
    } catch (Exception ex) {
        response.setStatusCode(StatusCode.ServerInternalError);
    }
    return response;
}
Also used : Submodel(io.adminshell.aas.v3.model.Submodel) PutSubmodelResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.PutSubmodelResponse) Reference(io.adminshell.aas.v3.model.Reference) QueryModifier(de.fraunhofer.iosb.ilt.faaast.service.model.api.modifier.QueryModifier) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException) ResourceNotFoundException(de.fraunhofer.iosb.ilt.faaast.service.exception.ResourceNotFoundException)

Example 9 with Submodel

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

the class OpcUaEndpoint method writeValue.

/**
 * Writes the Value of the given SubmodelElement into the service.
 *
 * @param element The desired SubmodelElement including the new value
 * @param submodel The corresponding submodel
 * @param refElement The reference to the SubmodelElement
 * @return True if the write succeeded, false otherwise
 */
public boolean writeValue(SubmodelElement element, Submodel submodel, Reference refElement) {
    boolean retval = false;
    if (element == null) {
        throw new IllegalArgumentException("element == null");
    } else if (submodel == null) {
        throw new IllegalArgumentException("submodel == null");
    }
    try {
        SetSubmodelElementValueByPathRequest request = new SetSubmodelElementValueByPathRequest();
        List<Key> path = new ArrayList<>();
        path.addAll(refElement.getKeys());
        request.setId(submodel.getIdentification());
        request.setPath(path);
        request.setValueParser(new OpcUaElementValueParser());
        if (element instanceof MultiLanguageProperty) {
            MultiLanguageProperty mlp = (MultiLanguageProperty) element;
            if ((mlp.getValues() != null) && (mlp.getValues().size() > 1)) {
                for (int i = 0; i < mlp.getValues().size(); i++) {
                    logger.info("writeValue: MLP " + i + ": " + mlp.getValues().get(i).getValue());
                }
            }
        }
        request.setRawValue(ElementValueMapper.toValue(element));
        if (request.getRawValue() instanceof MultiLanguagePropertyValue) {
            MultiLanguagePropertyValue mlpv = (MultiLanguagePropertyValue) request.getRawValue();
            if ((mlpv.getLangStringSet() != null) && (mlpv.getLangStringSet().size() > 1)) {
                for (int i = 0; i < mlpv.getLangStringSet().size(); i++) {
                    logger.info("writeValue: MLPV " + i + ": " + mlpv.getLangStringSet().toArray()[i]);
                }
            }
        }
        Response response = service.execute(request);
        logger.info("writeValue: Submodel " + submodel.getIdentification().getIdentifier() + "; Element " + element.getIdShort() + "; Status: " + response.getStatusCode());
        if (isSuccess(response.getStatusCode())) {
            retval = true;
        }
    } catch (Exception ex) {
        logger.error("writeValue error", ex);
    }
    return retval;
}
Also used : SetSubmodelElementValueByPathRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.SetSubmodelElementValueByPathRequest) InvokeOperationSyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse) Response(de.fraunhofer.iosb.ilt.faaast.service.model.api.Response) MultiLanguageProperty(io.adminshell.aas.v3.model.MultiLanguageProperty) ArrayList(java.util.ArrayList) Key(io.adminshell.aas.v3.model.Key) Endpoint(de.fraunhofer.iosb.ilt.faaast.service.endpoint.Endpoint) StatusException(com.prosysopc.ua.StatusException) MultiLanguagePropertyValue(de.fraunhofer.iosb.ilt.faaast.service.model.value.MultiLanguagePropertyValue)

Example 10 with Submodel

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

the class OpcUaEndpoint method callOperation.

/**
 * Calls the desired operation in the service.
 *
 * @param operation The desired operation
 * @param inputVariables The input arguments
 * @param submodel The corresponding submodel
 * @param refElement The reference to the SubmodelElement
 * @return The OutputArguments The output arguments returned from the operation call
 * @throws StatusException If the operation fails
 */
public List<OperationVariable> callOperation(Operation operation, List<OperationVariable> inputVariables, Submodel submodel, Reference refElement) throws StatusException {
    List<OperationVariable> outputArguments;
    try {
        InvokeOperationSyncRequest request = new InvokeOperationSyncRequest();
        List<Key> path = new ArrayList<>();
        path.addAll(refElement.getKeys());
        request.setId(submodel.getIdentification());
        request.setPath(path);
        request.setInputArguments(inputVariables);
        request.setContent(Content.Normal);
        requestCounter++;
        request.setRequestId(Integer.toString(requestCounter));
        // execute method
        InvokeOperationSyncResponse response = (InvokeOperationSyncResponse) service.execute(request);
        if (isSuccess(response.getStatusCode())) {
            logger.info("callOperation: Operation " + operation.getIdShort() + " executed successfully");
        } else if (response.getStatusCode() == StatusCode.ClientMethodNotAllowed) {
            logger.warn("callOperation: Operation " + operation.getIdShort() + " error executing operation: " + response.getStatusCode());
            throw new StatusException(StatusCodes.Bad_NotExecutable);
        } else {
            logger.warn("callOperation: Operation " + operation.getIdShort() + " error executing operation: " + response.getStatusCode());
            throw new StatusException(StatusCodes.Bad_UnexpectedError);
        }
        outputArguments = response.getPayload().getOutputArguments();
    } catch (Exception ex) {
        logger.error("callOperation error", ex);
        throw ex;
    }
    return outputArguments;
}
Also used : StatusException(com.prosysopc.ua.StatusException) OperationVariable(io.adminshell.aas.v3.model.OperationVariable) InvokeOperationSyncRequest(de.fraunhofer.iosb.ilt.faaast.service.model.request.InvokeOperationSyncRequest) ArrayList(java.util.ArrayList) InvokeOperationSyncResponse(de.fraunhofer.iosb.ilt.faaast.service.model.api.response.InvokeOperationSyncResponse) Key(io.adminshell.aas.v3.model.Key) StatusException(com.prosysopc.ua.StatusException)

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