use of opc.i4aas.AASKeyDataType in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method setAasReferenceData.
/**
* Sets the data in the given Reference node.
*
* @param ref The desired UA reference object
* @param refNode The AAS Reference object with the source data
* @param readOnly True if the value should be read-only
* @throws StatusException If the operation fails
*/
private void setAasReferenceData(Reference ref, AASReferenceType refNode, boolean readOnly) throws StatusException {
if (refNode == null) {
throw new IllegalArgumentException("refNode is null");
} else if (ref == null) {
throw new IllegalArgumentException("ref is null");
}
try {
List<AASKeyDataType> keyList = new ArrayList<>();
ref.getKeys().stream().map(k -> {
AASKeyDataType keyValue = new AASKeyDataType();
keyValue.setIdType(ValueConverter.getAasKeyType(k.getIdType()));
keyValue.setType(ValueConverter.getAasKeyElementsDataType(k.getType()));
keyValue.setValue(k.getValue());
return keyValue;
}).forEachOrdered(keyValue -> {
keyList.add(keyValue);
});
refNode.getKeysNode().setArrayDimensions(new UnsignedInteger[] { UnsignedInteger.valueOf(keyList.size()) });
if (readOnly) {
refNode.getKeysNode().setAccessLevel(AccessLevelType.CurrentRead);
}
refNode.setKeys(keyList.toArray(AASKeyDataType[]::new));
} catch (Throwable ex) {
logger.error("setAasReferenceData Exception", ex);
throw ex;
}
}
use of opc.i4aas.AASKeyDataType in project FAAAST-Service by FraunhoferIOSB.
the class ValueConverter method getReferenceFromKeys.
/**
* Creates a reference from the given List of Keys.
*
* @param value The desired list of Keys.
* @return The created reference.
*/
public static Reference getReferenceFromKeys(AASKeyDataType[] value) {
if (value == null) {
throw new IllegalArgumentException("value is null");
}
Reference retval = null;
try {
List<Key> keys = new ArrayList<>();
for (AASKeyDataType key : value) {
keys.add(new DefaultKey.Builder().type(getKeyElements(key.getType())).idType(getKeyType(key.getIdType())).value(key.getValue()).build());
}
retval = new DefaultReference.Builder().keys(keys).build();
} catch (Throwable ex) {
logger.error("getReferenceFromKeys Exception", ex);
throw ex;
}
return retval;
}
use of opc.i4aas.AASKeyDataType in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaEndpointTest method testWriteReferenceElementValue.
/**
* 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 testWriteReferenceElementValue() 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.SUBMODEL_OPER_DATA_NODE_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.TEST_REF_ELEM_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.PROPERTY_VALUE_NAME)));
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("testWriteReferenceElementValue Browse Result Null", bpres);
Assert.assertTrue("testWriteReferenceElementValue Browse Result: size doesn't match", bpres.length == 1);
Assert.assertTrue("testWriteReferenceElementValue Browse Result Good", bpres[0].getStatusCode().isGood());
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("testWriteReferenceElementValue ValueType Null", targets);
Assert.assertTrue("testWriteReferenceElementValue ValueType empty", targets.length > 0);
NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
List<AASKeyDataType> oldValue = new ArrayList<>();
oldValue.add(new AASKeyDataType(AASKeyElementsDataType.Submodel, TestDefines.SUBMODEL_TECH_DATA_NAME, AASKeyTypeDataType.IRI));
oldValue.add(new AASKeyDataType(AASKeyElementsDataType.Property, TestDefines.MAX_ROTATION_SPEED_NAME, AASKeyTypeDataType.IdShort));
// The DataElementValueMapper changes the order of the elements
List<AASKeyDataType> newValue = new ArrayList<>();
newValue.add(new AASKeyDataType(AASKeyElementsDataType.Submodel, TestDefines.SUBMODEL_TECH_DATA_NAME, AASKeyTypeDataType.IRI));
newValue.add(new AASKeyDataType(AASKeyElementsDataType.Property, "Another property", AASKeyTypeDataType.IdShort));
TestUtils.writeNewValueArray(client, writeNode, oldValue.toArray(AASKeyDataType[]::new), newValue.toArray(AASKeyDataType[]::new));
System.out.println("testWriteReferenceElementValue: disconnect client");
client.disconnect();
}
use of opc.i4aas.AASKeyDataType in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaEndpointFullTest method testWriteRelationshipElementValue.
/**
* Test method for writing a RelationshipElement. 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 testWriteRelationshipElementValue() 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_4_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("testWriteRelationshipElementValue Browse Result Null", bpres);
Assert.assertTrue("testWriteRelationshipElementValue Browse Result: size doesn't match", bpres.length == 1);
Assert.assertTrue("testWriteRelationshipElementValue Browse Result Good", bpres[0].getStatusCode().isGood());
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("testWriteRelationshipElementValue ValueType Null", targets);
Assert.assertTrue("testWriteRelationshipElementValue ValueType empty", targets.length > 0);
NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
List<AASKeyDataType> oldValue = new ArrayList<>();
oldValue.add(new AASKeyDataType(AASKeyElementsDataType.Submodel, "https://acplt.org/Test_Submodel_Mandatory", AASKeyTypeDataType.IRI));
oldValue.add(new AASKeyDataType(AASKeyElementsDataType.SubmodelElementCollection, "ExampleSubmodelCollectionOrdered", AASKeyTypeDataType.IdShort));
oldValue.add(new AASKeyDataType(AASKeyElementsDataType.MultiLanguageProperty, "ExampleMultiLanguageProperty", AASKeyTypeDataType.IdShort));
// The DataElementValueMapper changes the order of the elements
List<AASKeyDataType> newValue = new ArrayList<>();
newValue.add(new AASKeyDataType(AASKeyElementsDataType.Submodel, "https://acplt.org/Test_Submodel_Mandatory", AASKeyTypeDataType.IRI));
newValue.add(new AASKeyDataType(AASKeyElementsDataType.SubmodelElementCollection, "ExampleSubmodelCollectionOrdered", AASKeyTypeDataType.IdShort));
newValue.add(new AASKeyDataType(AASKeyElementsDataType.Range, "ExampleRange", AASKeyTypeDataType.IdShort));
TestUtils.writeNewValueArray(client, writeNode, oldValue.toArray(AASKeyDataType[]::new), newValue.toArray(AASKeyDataType[]::new));
System.out.println("disconnect client");
client.disconnect();
}
use of opc.i4aas.AASKeyDataType in project FAAAST-Service by FraunhoferIOSB.
the class OpcUaEndpointFullTest method testWriteEntityGlobalAssetId.
/**
* Test method for writing a GlobalAssetId of an Entity. 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 testWriteEntityGlobalAssetId() 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("testWriteEntityGlobalAssetId: 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_2_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.FULL_ENTITY2_NAME)));
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, AASEntityType.GLOBAL_ASSET_ID)));
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("testWriteEntityGlobalAssetId Browse Result Null", bpres);
Assert.assertTrue("testWriteEntityGlobalAssetId Browse Result: size doesn't match", bpres.length == 1);
Assert.assertTrue("testWriteEntityGlobalAssetId Browse Result Good", bpres[0].getStatusCode().isGood());
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("testWriteEntityGlobalAssetId ValueType Null", targets);
Assert.assertTrue("testWriteEntityGlobalAssetId ValueType empty", targets.length > 0);
NodeId writeNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
List<AASKeyDataType> oldValue = new ArrayList<>();
oldValue.add(new AASKeyDataType(AASKeyElementsDataType.Asset, "https://acplt.org/Test_Asset2", AASKeyTypeDataType.IRI));
List<AASKeyDataType> newValue = new ArrayList<>();
newValue.add(new AASKeyDataType(AASKeyElementsDataType.Asset, "https://acplt2.org/Test_Asset3", AASKeyTypeDataType.IRI));
TestUtils.writeNewValueArray(client, writeNode, oldValue.toArray(AASKeyDataType[]::new), newValue.toArray(AASKeyDataType[]::new));
System.out.println("disconnect client");
client.disconnect();
}
Aggregations