Search in sources :

Example 1 with LangString

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

the class AasServiceNodeManager method addDescriptions.

/**
 * Adds the descriptions to the given argument.
 *
 * @param arg The desired UA argument
 * @param descriptions The list of AAS descriptions
 */
private void addDescriptions(Argument arg, List<LangString> descriptions) {
    try {
        if ((arg != null) && (descriptions != null)) {
            if (!descriptions.isEmpty()) {
                LangString desc = descriptions.get(0);
                arg.setDescription(new LocalizedText(desc.getValue(), desc.getLanguage()));
            }
        }
    } catch (Throwable ex) {
        logger.error("addDescriptions Exception", ex);
    }
}
Also used : LangString(io.adminshell.aas.v3.model.LangString) LocalizedText(com.prosysopc.ua.stack.builtintypes.LocalizedText)

Example 2 with LangString

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

the class AasServiceNodeManager method addDescriptions.

/**
 * Adds the list of Descriptions to the given node.
 *
 * @param node The desired UA node in which the Descriptions should be created
 * @param descriptions The list of AAS descriptions
 */
private void addDescriptions(UaNode node, List<LangString> descriptions) {
    try {
        if ((node != null) && (descriptions != null)) {
            if (!descriptions.isEmpty()) {
                LangString desc = descriptions.get(0);
                node.setDescription(new LocalizedText(desc.getValue(), desc.getLanguage()));
            }
        }
    } catch (Throwable ex) {
        logger.error("addDescriptions Exception", ex);
        throw ex;
    }
}
Also used : LangString(io.adminshell.aas.v3.model.LangString) LocalizedText(com.prosysopc.ua.stack.builtintypes.LocalizedText)

Example 3 with LangString

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

the class AasServiceNodeManager method addAasMultiLanguageProperty.

/**
 * Adds an AAS Multi Language Property to the given node.
 *
 * @param node The desired UA node
 * @param aasMultiLang The AAS Multi Language Property to add
 * @param submodel The corresponding Submodel as parent object of the data element
 * @param parentRef The AAS reference to the parent object
 * @param ordered Specifies whether the multi language property should be
 *            added ordered (true) or unordered (false)
 * @throws StatusException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws AddressSpaceException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
private void addAasMultiLanguageProperty(UaNode node, MultiLanguageProperty aasMultiLang, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
    try {
        if ((node != null) && (aasMultiLang != null)) {
            String name = aasMultiLang.getIdShort();
            QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASMultiLanguagePropertyType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
            NodeId nid = getDefaultNodeId();
            AASMultiLanguagePropertyType multiLangNode = createInstance(AASMultiLanguagePropertyType.class, nid, browseName, LocalizedText.english(name));
            addSubmodelElementBaseData(multiLangNode, aasMultiLang);
            List<LangString> values = aasMultiLang.getValues();
            if (values != null) {
                if (multiLangNode.getValueNode() == null) {
                    addMultiLanguageValueNode(multiLangNode, values.size());
                }
                multiLangNode.getValueNode().setValue(ValueConverter.getLocalizedTextFromLangStringSet(values));
            }
            if (aasMultiLang.getValueId() != null) {
                addAasReferenceAasNS(multiLangNode, aasMultiLang.getValueId(), AASMultiLanguagePropertyType.VALUE_ID);
            }
            Reference multiLangRef = AasUtils.toReference(parentRef, aasMultiLang);
            submodelElementAasMap.put(multiLangNode.getValueNode().getNodeId(), new SubmodelElementData(aasMultiLang, submodel, SubmodelElementData.Type.MULTI_LANGUAGE_VALUE, multiLangRef));
            submodelElementOpcUAMap.put(multiLangRef, multiLangNode);
            if (ordered) {
                node.addReference(multiLangNode, Identifiers.HasOrderedComponent, false);
            } else {
                node.addComponent(multiLangNode);
            }
            referableMap.put(multiLangRef, new ObjectData(aasMultiLang, multiLangNode, submodel));
        }
    } catch (Throwable ex) {
        logger.error("addAasMultiLanguageProperty Exception", ex);
        throw ex;
    }
}
Also used : AASMultiLanguagePropertyType(opc.i4aas.AASMultiLanguagePropertyType) LangString(io.adminshell.aas.v3.model.LangString) Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) UaQualifiedName(com.prosysopc.ua.UaQualifiedName) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) ObjectData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString) SubmodelElementData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)

Example 4 with LangString

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

the class MultiLanguagePropertyValueSerializer method serialize.

@Override
public void serialize(MultiLanguagePropertyValue value, JsonGenerator generator, SerializerProvider provider) throws IOException {
    if (value != null) {
        generator.writeStartObject();
        for (LangString langString : value.getLangStringSet()) {
            generator.writeStringField(langString.getLanguage(), langString.getValue());
        }
        generator.writeEndObject();
    }
}
Also used : LangString(io.adminshell.aas.v3.model.LangString)

Example 5 with LangString

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

the class OpcUaEndpoint2Test method testUpdateSubmodel.

/**
 * Test method for updating a complete submodel (Operational Data).
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws Exception If the operation fails
 */
@Test
public void testUpdateSubmodel() throws SecureIdentityException, IOException, ServiceException, Exception {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("testUpdateSubmodel: client connected");
    int aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    // make sure one of the old elements exists, the new element exists not yet
    List<RelativePath> relPath = new ArrayList<>();
    List<RelativePathElement> browsePath = new ArrayList<>();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.SUBMODEL_OPER_DATA_NODE_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.TEST_RANGE_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.RANGE_MAX_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    browsePath.clear();
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.AAS_ENVIRONMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.SUBMODEL_OPER_DATA_NODE_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_REL_ELEMENT_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, AASRelationshipElementType.SECOND)));
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.KEYS_VALUE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testUpdateSubmodel Browse Result Null", bpres);
    Assert.assertTrue("testUpdateSubmodel Browse 1 Result: size doesn't match", bpres.length == 2);
    Assert.assertTrue("testUpdateSubmodel Browse 1 Result 1 Good", bpres[0].getStatusCode().isGood());
    Assert.assertTrue("testUpdateSubmodel Browse 1 Result 2 Bad", bpres[1].getStatusCode().isBad());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testUpdateSubmodel RangeMax Null", targets);
    Assert.assertTrue("testUpdateSubmodel RangeMax empty", targets.length > 0);
    // update submodel
    // Send update event to MessageBus
    ElementUpdateEventMessage msg = new ElementUpdateEventMessage();
    msg.setElement(new DefaultReference.Builder().key(new DefaultKey.Builder().idType(KeyType.IRI).type(KeyElements.SUBMODEL).value(AASSimple.SUBMODEL_OPERATIONAL_DATA_ID).build()).build());
    msg.setValue(new DefaultSubmodel.Builder().idShort(TestDefines.SUBMODEL_OPER_DATA_NODE_NAME).identification(new DefaultIdentifier.Builder().idType(IdentifierType.IRI).identifier("https://acplt.org/NewOperationalData").build()).administration(new DefaultAdministrativeInformation.Builder().version("1.1").revision("5").build()).kind(ModelingKind.INSTANCE).submodelElement(new DefaultRelationshipElement.Builder().idShort("ExampleRelationshipElement").category("Parameter").description(new LangString("Example RelationshipElement object", "en-us")).description(new LangString("Beispiel RelationshipElement Element", "de")).semanticId(new DefaultReference.Builder().key(new DefaultKey.Builder().type(KeyElements.GLOBAL_REFERENCE).value("http://acplt.org/RelationshipElements/ExampleRelationshipElement").idType(KeyType.IRI).build()).build()).first(new DefaultReference.Builder().key(new DefaultKey.Builder().type(KeyElements.SUBMODEL).value("https://acplt.org/Test_Submodel").idType(KeyType.IRI).build()).key(new DefaultKey.Builder().type(KeyElements.SUBMODEL_ELEMENT_COLLECTION).value("ExampleSubmodelCollectionOrdered").idType(KeyType.ID_SHORT).build()).key(new DefaultKey.Builder().type(KeyElements.PROPERTY).value("ExampleProperty").idType(KeyType.ID_SHORT).build()).build()).second(new DefaultReference.Builder().key(new DefaultKey.Builder().type(KeyElements.SUBMODEL).value("http://acplt.org/Submodels/Assets/TestAsset/BillOfMaterial").idType(KeyType.IRI).build()).key(new DefaultKey.Builder().type(KeyElements.ENTITY).value("ExampleEntity").idType(KeyType.ID_SHORT).build()).key(new DefaultKey.Builder().type(KeyElements.PROPERTY).value("ExampleProperty2").idType(KeyType.ID_SHORT).build()).build()).build()).build());
    service.getMessageBus().publish(msg);
    Thread.sleep(DEFAULT_TIMEOUT);
    // check that the old element is not there anymore, but the new element
    bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testUpdateSubmodel Browse Result old Null", bpres);
    Assert.assertTrue("testUpdateSubmodel Browse 2 Result: size doesn't match", bpres.length == 2);
    Assert.assertTrue("testUpdateSubmodel Browse 2 Result 1 Bad", bpres[0].getStatusCode().isBad());
    Assert.assertTrue("testUpdateSubmodel Browse 2 Result 2 Good", bpres[1].getStatusCode().isGood());
    // read a value of the new SubmodelElement
    targets = bpres[1].getTargets();
    Assert.assertNotNull("testUpdateSubmodel RelationshipElement Null", targets);
    Assert.assertTrue("testUpdateSubmodel RelationshipElement empty", targets.length > 0);
    List<AASKeyDataType> smeValue = new ArrayList<>();
    smeValue.add(new AASKeyDataType(AASKeyElementsDataType.Submodel, "http://acplt.org/Submodels/Assets/TestAsset/BillOfMaterial", AASKeyTypeDataType.IRI));
    smeValue.add(new AASKeyDataType(AASKeyElementsDataType.Entity, "ExampleEntity", AASKeyTypeDataType.IdShort));
    smeValue.add(new AASKeyDataType(AASKeyElementsDataType.Property, "ExampleProperty2", AASKeyTypeDataType.IdShort));
    DataValue value = client.readValue(client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId()));
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertArrayEquals("new SubmodelElement value not equal", smeValue.toArray(AASKeyDataType[]::new), (AASKeyDataType[]) value.getValue().getValue());
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : DataValue(com.prosysopc.ua.stack.builtintypes.DataValue) ArrayList(java.util.ArrayList) DefaultRelationshipElement(io.adminshell.aas.v3.model.impl.DefaultRelationshipElement) DefaultSubmodel(io.adminshell.aas.v3.model.impl.DefaultSubmodel) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) DefaultIdentifier(io.adminshell.aas.v3.model.impl.DefaultIdentifier) ElementUpdateEventMessage(de.fraunhofer.iosb.ilt.faaast.service.model.messagebus.event.change.ElementUpdateEventMessage) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) LangString(io.adminshell.aas.v3.model.LangString) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) AASKeyDataType(opc.i4aas.AASKeyDataType) UaClient(com.prosysopc.ua.client.UaClient) DefaultKey(io.adminshell.aas.v3.model.impl.DefaultKey) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) Test(org.junit.Test)

Aggregations

LangString (io.adminshell.aas.v3.model.LangString)6 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)3 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)3 UaClient (com.prosysopc.ua.client.UaClient)2 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)2 LocalizedText (com.prosysopc.ua.stack.builtintypes.LocalizedText)2 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)2 RelativePath (com.prosysopc.ua.stack.core.RelativePath)2 RelativePathElement (com.prosysopc.ua.stack.core.RelativePathElement)2 DefaultIdentifier (io.adminshell.aas.v3.model.impl.DefaultIdentifier)2 DefaultKey (io.adminshell.aas.v3.model.impl.DefaultKey)2 DefaultRelationshipElement (io.adminshell.aas.v3.model.impl.DefaultRelationshipElement)2 DefaultSubmodel (io.adminshell.aas.v3.model.impl.DefaultSubmodel)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)1 DataValue (com.prosysopc.ua.stack.builtintypes.DataValue)1 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)1 BrowsePathTarget (com.prosysopc.ua.stack.core.BrowsePathTarget)1 ObjectData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData)1