Search in sources :

Example 6 with LocalizedText

use of com.prosysopc.ua.stack.builtintypes.LocalizedText in project FAAAST-Service by FraunhoferIOSB.

the class ValueConverter method getLocalizedTextFromLangStringSet.

/**
 * Gets a LocalizedText array from an AAS LangString Set.
 *
 * @param value The desired AAS Lang String
 * @return The corresponding LocalizedText array
 */
public static LocalizedText[] getLocalizedTextFromLangStringSet(List<LangString> value) {
    LocalizedText[] retval = null;
    try {
        ArrayList<LocalizedText> arr = new ArrayList<>();
        value.forEach(ls -> {
            arr.add(new LocalizedText(ls.getValue(), ls.getLanguage()));
        });
        retval = arr.toArray(LocalizedText[]::new);
    } catch (Throwable ex) {
        logger.error("getLocalizedTextFromLangStringSet Exception", ex);
        throw ex;
    }
    return retval;
}
Also used : ArrayList(java.util.ArrayList) LocalizedText(com.prosysopc.ua.stack.builtintypes.LocalizedText)

Example 7 with LocalizedText

use of com.prosysopc.ua.stack.builtintypes.LocalizedText in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpointTest method testWriteMultiLanguagePropertyValue.

/**
 * Test method for writing a property. Writes the property in the OPC UA
 * Server and checks the new value in the server.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws InterruptedException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
@Test
public void testWriteMultiLanguagePropertyValue() throws SecureIdentityException, IOException, ServiceException, StatusException, InterruptedException, ServiceResultException {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("testWriteMultiLanguagePropertyValue: client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    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_MULTI_LAN_PROP_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_VALUE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testWriteMultiLanguagePropertyValue Browse Result Null", bpres);
    Assert.assertTrue("testWriteMultiLanguagePropertyValue Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testWriteMultiLanguagePropertyValue Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testWriteMultiLanguagePropertyValue ValueType Null", targets);
    Assert.assertTrue("testWriteMultiLanguagePropertyValue ValueType empty", targets.length > 0);
    NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    List<LocalizedText> oldValue = new ArrayList<>();
    oldValue.add(new LocalizedText("Example value of a MultiLanguageProperty element", "en-us"));
    oldValue.add(new LocalizedText("Beispielswert für ein MulitLanguageProperty-Element", "de"));
    // The DataElementValueMapper changes the order of the elements in some cases
    List<LocalizedText> newValue = new ArrayList<>();
    newValue.add(new LocalizedText("Beispielswert2 fuer ein anderes MulitLanguageProperty-Element", "de"));
    newValue.add(new LocalizedText("Example value of a MultiLanguageProperty element", "en-us"));
    TestUtils.writeNewValueArray(client, writeNode, oldValue.toArray(LocalizedText[]::new), newValue.toArray(LocalizedText[]::new));
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) LocalizedText(com.prosysopc.ua.stack.builtintypes.LocalizedText) UaClient(com.prosysopc.ua.client.UaClient) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) Test(org.junit.Test)

Example 8 with LocalizedText

use of com.prosysopc.ua.stack.builtintypes.LocalizedText in project FAAAST-Service by FraunhoferIOSB.

the class OpcUaEndpointFullTest method testWriteSubmodelElementCollectionValue3.

/**
 * Test method for writing a Value of a SubmodelElementCollection. Writes the property in the OPC UA
 * Server and checks the new value in the server.
 *
 * @throws SecureIdentityException If the operation fails
 * @throws IOException If the operation fails
 * @throws ServiceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws InterruptedException If the operation fails
 * @throws ServiceResultException If the operation fails
 */
@Test
public void testWriteSubmodelElementCollectionValue3() throws SecureIdentityException, IOException, ServiceException, StatusException, InterruptedException, ServiceResultException {
    UaClient client = new UaClient(ENDPOINT_URL);
    client.setSecurityMode(SecurityMode.NONE);
    TestUtils.initialize(client);
    client.connect();
    System.out.println("client connected");
    aasns = client.getAddressSpace().getNamespaceTable().getIndex(VariableIds.AASAssetAdministrationShellType_AssetInformation_AssetKind.getNamespaceUri());
    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.FULL_SUBMODEL_7_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_SM_ELEM_COLL_O_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.TEST_MULTI_LAN_PROP_NAME)));
    browsePath.add(new RelativePathElement(Identifiers.HasProperty, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_VALUE_NAME)));
    relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
    BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(Identifiers.ObjectsFolder, relPath.toArray(RelativePath[]::new));
    Assert.assertNotNull("testWriteMultiLanguagePropertyValue Browse Result Null", bpres);
    Assert.assertTrue("testWriteMultiLanguagePropertyValue Browse Result: size doesn't match", bpres.length == 1);
    Assert.assertTrue("testWriteMultiLanguagePropertyValue Browse Result Good", bpres[0].getStatusCode().isGood());
    BrowsePathTarget[] targets = bpres[0].getTargets();
    Assert.assertNotNull("testWriteMultiLanguagePropertyValue ValueType Null", targets);
    Assert.assertTrue("testWriteMultiLanguagePropertyValue ValueType empty", targets.length > 0);
    NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
    // The DataElementValueMapper changes the order of the elements in some cases
    List<LocalizedText> newValue = new ArrayList<>();
    newValue.add(new LocalizedText("english test element", "en-us"));
    newValue.add(new LocalizedText("deutsches Test-Element", "de"));
    TestUtils.writeNewValueArray(client, writeNode, new ArrayList<>().toArray(LocalizedText[]::new), newValue.toArray(LocalizedText[]::new));
    System.out.println("disconnect client");
    client.disconnect();
}
Also used : RelativePath(com.prosysopc.ua.stack.core.RelativePath) BrowsePathResult(com.prosysopc.ua.stack.core.BrowsePathResult) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ArrayList(java.util.ArrayList) LocalizedText(com.prosysopc.ua.stack.builtintypes.LocalizedText) UaClient(com.prosysopc.ua.client.UaClient) RelativePathElement(com.prosysopc.ua.stack.core.RelativePathElement) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) BrowsePathTarget(com.prosysopc.ua.stack.core.BrowsePathTarget) Test(org.junit.Test)

Example 9 with LocalizedText

use of com.prosysopc.ua.stack.builtintypes.LocalizedText in project FAAAST-Service by FraunhoferIOSB.

the class TestUtils method writeNewValueArray.

/**
 * Writes the new value (array) into the given node and checks whether the value was written correctly.
 *
 * @param client The OPC UA Client.
 * @param writeNode The node which should be written.
 * @param oldValue The old value.
 * @param newValue The new value.
 * @throws ServiceException If the operation fails
 * @throws StatusException If the operation fails
 * @throws InterruptedException If the operation fails
 */
public static void writeNewValueArray(UaClient client, NodeId writeNode, LocalizedText[] oldValue, LocalizedText[] newValue) throws ServiceException, StatusException, InterruptedException {
    DataValue value = client.readValue(writeNode);
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertArrayEquals("intial value not equal", oldValue, (LocalizedText[]) value.getValue().getValue());
    client.writeValue(writeNode, newValue);
    // wait until the write is finished completely
    Thread.sleep(WRITE_TIMEOUT);
    // read new value
    value = client.readValue(writeNode);
    Assert.assertEquals(StatusCode.GOOD, value.getStatusCode());
    Assert.assertArrayEquals("new value not equal", newValue, (LocalizedText[]) value.getValue().getValue());
}
Also used : DataValue(com.prosysopc.ua.stack.builtintypes.DataValue) LocalizedText(com.prosysopc.ua.stack.builtintypes.LocalizedText)

Example 10 with LocalizedText

use of com.prosysopc.ua.stack.builtintypes.LocalizedText in project FAAAST-Service by FraunhoferIOSB.

the class AasServiceNodeManager method addAasFile.

/**
 * Adds an AAS file to the given node.
 *
 * @param node The desired UA node
 * @param aasFile The AAS file object
 * @param submodel The corresponding Submodel as parent object of the data element
 * @param parentRef The AAS reference to the parent node
 * @param ordered Specifies whether the file should be added ordered (true) or unordered (false)
 * @param nodeName The desired Name of the node. If this value is not set,
 *            the IdShort of the file is used.
 * @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 addAasFile(UaNode node, File aasFile, Submodel submodel, Reference parentRef, boolean ordered, String nodeName) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
    try {
        if ((node != null) && (aasFile != null)) {
            String name = aasFile.getIdShort();
            if ((nodeName != null) && (!nodeName.isEmpty())) {
                name = nodeName;
            }
            QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASFileType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
            NodeId nid = getDefaultNodeId();
            AASFileType fileNode = createInstance(AASFileType.class, nid, browseName, LocalizedText.english(name));
            addSubmodelElementBaseData(fileNode, aasFile);
            // MimeType
            if (!aasFile.getMimeType().isEmpty()) {
                fileNode.setMimeType(aasFile.getMimeType());
            }
            // Value
            if (aasFile.getValue() != null) {
                if (fileNode.getValueNode() == null) {
                    addFileValueNode(fileNode);
                }
                fileNode.setValue(aasFile.getValue());
                if (!aasFile.getValue().isEmpty()) {
                    java.io.File f = new java.io.File(aasFile.getValue());
                    if (!f.exists()) {
                        logger.warn("addAasFile: File '" + f.getAbsolutePath() + "' does not exist!");
                    } else {
                        // File Object: include only when the file exists
                        QualifiedName fileBrowseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASFileType.getNamespaceUri(), AASFileType.FILE).toQualifiedName(getNamespaceTable());
                        NodeId fileId = new NodeId(getNamespaceIndex(), fileNode.getNodeId().getValue().toString() + "." + AASFileType.FILE);
                        FileTypeNode fileType = createInstance(FileTypeNode.class, fileId, fileBrowseName, LocalizedText.english(AASFileType.FILE));
                        fileType.setFile(new java.io.File(aasFile.getValue()));
                        fileType.setWritable(false);
                        fileType.setUserWritable(false);
                        if (fileType.getNodeVersion() != null) {
                            fileType.getNodeVersion().setDescription(new LocalizedText("", ""));
                        }
                        fileNode.addReference(fileType, Identifiers.HasAddIn, false);
                    }
                }
            }
            if (ordered) {
                node.addReference(fileNode, Identifiers.HasOrderedComponent, false);
            } else {
                node.addComponent(fileNode);
            }
            if (parentRef != null) {
                Reference fileRef = AasUtils.toReference(parentRef, aasFile);
                referableMap.put(fileRef, new ObjectData(aasFile, fileNode, submodel));
            }
        }
    } catch (Throwable ex) {
        logger.error("addAasFile Exception", ex);
        throw ex;
    }
}
Also used : AASFileType(opc.i4aas.AASFileType) 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) 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) LocalizedText(com.prosysopc.ua.stack.builtintypes.LocalizedText) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) FileTypeNode(com.prosysopc.ua.types.opcua.server.FileTypeNode) File(io.adminshell.aas.v3.model.File)

Aggregations

LocalizedText (com.prosysopc.ua.stack.builtintypes.LocalizedText)20 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)12 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)9 LangString (io.adminshell.aas.v3.model.LangString)9 PlainProperty (com.prosysopc.ua.server.nodes.PlainProperty)8 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)7 UaQualifiedName (com.prosysopc.ua.UaQualifiedName)5 ObjectData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData)3 SubmodelElementData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData)3 Reference (io.adminshell.aas.v3.model.Reference)3 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)3 ArrayList (java.util.ArrayList)3 ApplicationIdentity (com.prosysopc.ua.ApplicationIdentity)2 UaClient (com.prosysopc.ua.client.UaClient)2 UaObject (com.prosysopc.ua.nodes.UaObject)2 UnsignedInteger (com.prosysopc.ua.stack.builtintypes.UnsignedInteger)2 ApplicationDescription (com.prosysopc.ua.stack.core.ApplicationDescription)2 BrowsePathResult (com.prosysopc.ua.stack.core.BrowsePathResult)2 BrowsePathTarget (com.prosysopc.ua.stack.core.BrowsePathTarget)2 RelativePath (com.prosysopc.ua.stack.core.RelativePath)2