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;
}
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();
}
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();
}
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());
}
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;
}
}
Aggregations