use of com.prosysopc.ua.nodes.UaNode in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method setRelationshipValue.
/**
* Sets the values for the given RelationshipElement.
*
* @param aasElement The desired RelationshipElement.
* @param value The new value.
* @throws StatusException If the operation fails
*/
private void setRelationshipValue(AASRelationshipElementType aasElement, RelationshipElementValue value) throws StatusException {
if (aasElement == null) {
throw new IllegalArgumentException("aasElement is null");
} else if (value == null) {
throw new IllegalArgumentException("value is null");
}
try {
Reference ref = new DefaultReference.Builder().keys(value.getFirst()).build();
setAasReferenceData(ref, aasElement.getFirstNode(), false);
ref = new DefaultReference.Builder().keys(value.getSecond()).build();
setAasReferenceData(ref, aasElement.getSecondNode(), false);
if ((aasElement instanceof AASAnnotatedRelationshipElementType) && (value instanceof AnnotatedRelationshipElementValue)) {
AASAnnotatedRelationshipElementType annotatedElement = (AASAnnotatedRelationshipElementType) aasElement;
AnnotatedRelationshipElementValue annotatedValue = (AnnotatedRelationshipElementValue) value;
UaNode[] annotationNodes = annotatedElement.getAnnotationNode().getComponents();
Map<String, DataElementValue> valueMap = annotatedValue.getAnnotations();
if (annotationNodes.length != valueMap.size()) {
logger.warn("Size of Value (" + valueMap.size() + ") doesn't match the number of AnnotationNodes (" + annotationNodes.length + ")");
throw new IllegalArgumentException("Size of Value doesn't match the number of AnnotationNodes");
}
// The Key of the Map is the IDShort of the DataElement (in our case the BrowseName)
for (UaNode annotationNode : annotationNodes) {
if (valueMap.containsKey(annotationNode.getBrowseName().getName())) {
setDataElementValue(annotationNode, valueMap.get(annotationNode.getBrowseName().getName()));
}
}
} else {
logger.info("setRelationshipValue: No AnnotatedRelationshipElement " + aasElement.getBrowseName().getName());
}
} catch (Throwable ex) {
logger.error("setAnnotatedRelationshipValue Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.nodes.UaNode in project FAAAST-Service by FraunhoferIOSB.
the class TestUtils method checkQualifierNode.
/**
* Searches for the Qualifier Node in the given Node.
*
* @param client The OPC UA client
* @param node The desired node
* @param aasns The namespace index of the AAS namespace
* @param qualifierList The list of qualifiers
* @throws ServiceException If the operation fails
* @throws ServiceResultException If the operation fails
* @throws AddressSpaceException If the operation fails
* @throws StatusException If the operation fails
*/
public static void checkQualifierNode(UaClient client, NodeId node, int aasns, List<Qualifier> qualifierList) throws ServiceException, ServiceResultException, AddressSpaceException, StatusException {
List<RelativePath> relPath = new ArrayList<>();
List<RelativePathElement> browsePath = new ArrayList<>();
browsePath.add(new RelativePathElement(Identifiers.HierarchicalReferences, false, true, new QualifiedName(aasns, TestDefines.QUALIFIER_NAME)));
relPath.add(new RelativePath(browsePath.toArray(RelativePathElement[]::new)));
BrowsePathResult[] bpres = client.getAddressSpace().translateBrowsePathsToNodeIds(node, relPath.toArray(RelativePath[]::new));
Assert.assertNotNull("checkQualifierNode Browse Result Null", bpres);
Assert.assertTrue("checkQualifierNode Browse Result: size doesn't match", bpres.length == 1);
BrowsePathTarget[] targets = bpres[0].getTargets();
Assert.assertNotNull("checkQualifierNode Node Targets Null", targets);
Assert.assertTrue("checkQualifierNode Node targets empty", targets.length > 0);
// Currently we only check that the NodeId is not null and we have the correct type
NodeId qualNode = client.getAddressSpace().getNamespaceTable().toNodeId(targets[0].getTargetId());
Assert.assertFalse("checkQualifierNode Node not found", NodeId.isNull(qualNode));
checkType(client, qualNode, new NodeId(aasns, TestDefines.AAS_QUALIFIER_LIST_ID));
List<AASQualifierType> nodeList = new ArrayList<>();
List<ReferenceDescription> refs = client.getAddressSpace().browse(qualNode);
for (ReferenceDescription ref : refs) {
NodeId nid = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getNodeId());
checkType(client, nid, new NodeId(aasns, TestDefines.AAS_QUALIFIER_TYPE_ID));
UaNode qnode = client.getAddressSpace().getNode(nid);
if (qnode instanceof AASQualifierType) {
nodeList.add((AASQualifierType) qnode);
}
}
checkQualifierList(qualifierList, nodeList);
// Assert.assertArrayEquals(qualifierList.toArray(), nodeList.toArray());
}
use of com.prosysopc.ua.nodes.UaNode in project FAAAST-Service by FraunhoferIOSB.
the class TestUtils method checkType.
/**
* Checks if the given Node is of the desired type.
*
* @param client The OPC UA Client
* @param node The desired Node
* @param typeNode The expected type.
* @throws ServiceException If the operation fails
* @throws AddressSpaceException If the operation fails
* @throws ServiceResultException If the operation fails
*/
public static void checkType(UaClient client, NodeId node, NodeId typeNode) throws ServiceException, AddressSpaceException, ServiceResultException {
UaNode uanode = client.getAddressSpace().getNode(node);
Assert.assertNotNull("checkType UaNode Null", uanode);
UaReference ref = uanode.getReference(Identifiers.HasTypeDefinition, false);
Assert.assertNotNull("checkType Reference Null", ref);
NodeId refId = client.getAddressSpace().getNamespaceTable().toNodeId(ref.getTargetId());
Assert.assertEquals("type not equal", typeNode, refId);
}
use of com.prosysopc.ua.nodes.UaNode in project FAAAST-Service by FraunhoferIOSB.
the class TestUtils method checkBrowseName.
/**
* Checks the Browse Name of the given Node.
*
* @param client The OPC UA Client
* @param nodeId The NodeId of the desired Node.
* @param desiredName The desired Browse Name.
* @throws ServiceException If the operation fails
* @throws AddressSpaceException If the operation fails
*/
public static void checkBrowseName(UaClient client, NodeId nodeId, String desiredName) throws ServiceException, AddressSpaceException {
UaNode node = client.getAddressSpace().getNode(nodeId);
Assert.assertNotNull("Node is null: " + desiredName, node);
checkBrowseName(node, desiredName);
}
use of com.prosysopc.ua.nodes.UaNode in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method setEntityValue.
/**
* Sets the values for the given Entity.
*
* @param entity The desired Entity.
* @param value The new value.
* @throws StatusException If the operation fails
*/
private void setEntityValue(AASEntityType entity, EntityValue value) throws StatusException {
if (entity == null) {
throw new IllegalArgumentException("entity is null");
} else if (value == null) {
throw new IllegalArgumentException("value is null");
}
try {
// EntityType
entity.setEntityType(ValueConverter.getAasEntityType(value.getEntityType()));
// GlobalAssetId
if ((value.getGlobalAssetId() != null) && (value.getGlobalAssetId().size() > 0)) {
DefaultReference ref = new DefaultReference.Builder().keys(value.getGlobalAssetId()).build();
setAasReferenceData(ref, entity.getGlobalAssetIdNode());
}
// Statements
Map<String, ElementValue> valueMap = value.getStatements();
AASSubmodelElementList statementNode = entity.getStatementNode();
if (statementNode != null) {
UaNode[] statementNodes = statementNode.getComponents();
if (statementNodes.length != valueMap.size()) {
logger.warn("Size of Value (" + valueMap.size() + ") doesn't match the number of StatementNodes (" + statementNodes.length + ")");
throw new IllegalArgumentException("Size of Value doesn't match the number of StatementNodes");
}
for (UaNode statementNode1 : statementNodes) {
if (statementNode1 instanceof AASSubmodelElementType) {
if (value.getStatements().containsKey(statementNode1.getBrowseName().getName())) {
setSubmodelElementValue((AASSubmodelElementType) statementNode1, value.getStatements().get(statementNode1.getBrowseName().getName()));
}
}
}
}
} catch (Throwable ex) {
logger.error("setEntityValue Exception", ex);
throw ex;
}
}
Aggregations