use of com.prosysopc.ua.nodes.UaNode in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAasReference.
/**
* Adds an AAS Reference to the given node with the given namespace.
*
* @param node The node in which the object is created
* @param ref The desired AAS reference object to add
* @param name The desired name
* @param namespaceUri The desired namespace URI tu use
* @param readOnly True if the value should be read-only
* @return The created node
* @throws StatusException If the operation fails
*/
private UaNode addAasReference(UaNode node, Reference ref, String name, String namespaceUri, boolean readOnly) throws StatusException {
UaNode retval = null;
try {
if (ref != null) {
QualifiedName browseName = UaQualifiedName.from(namespaceUri, name).toQualifiedName(getNamespaceTable());
NodeId nid = getDefaultNodeId();
AASReferenceType nodeRef = createInstance(AASReferenceType.class, nid, browseName, LocalizedText.english(name));
LOG.debug("addAasReference: add Node {} to Node {}", nid, node.getNodeId());
setAasReferenceData(ref, nodeRef, readOnly);
node.addComponent(nodeRef);
retval = nodeRef;
}
} catch (Exception ex) {
LOG.error("addAasReference Exception", ex);
throw ex;
}
return retval;
}
use of com.prosysopc.ua.nodes.UaNode in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addSubmodelReferences.
/**
* Adds the given submodel references to the given node.
*
* @param node The desired UA node in which the objects should be created
* @param submodelRefs The desired submodel references
* @throws StatusException If the operation fails
*/
private void addSubmodelReferences(AASAssetAdministrationShellType node, List<Reference> submodelRefs) throws StatusException {
if (node == null) {
throw new IllegalArgumentException(NODE_NULL);
} else if (submodelRefs == null) {
throw new IllegalArgumentException("sumodelRefs = null");
}
try {
String name = "Submodel";
AASReferenceList referenceListNode = node.getSubmodelNode();
LOG.info("addSubmodelReferences: add {} Submodels to Node: {}", submodelRefs.size(), node);
boolean added = false;
if (referenceListNode == null) {
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASReferenceList.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = createNodeId(node, browseName);
referenceListNode = createInstance(AASReferenceList.class, nid, browseName, LocalizedText.english(name));
LOG.info("addSubmodelReferences: add Node {} to Node {}", referenceListNode.getNodeId(), node.getNodeId());
added = true;
}
int counter = 1;
for (Reference ref : submodelRefs) {
UaNode submodelNode = null;
String submodelName = getSubmodelName(ref);
if (submodelName.isEmpty()) {
submodelName = name + counter++;
}
if (submodelOpcUAMap.containsKey(ref)) {
submodelNode = submodelOpcUAMap.get(ref);
}
UaNode refNode = addAasReferenceAasNS(referenceListNode, ref, submodelName);
if (refNode != null) {
// add hasAddIn reference to the submodel
if (submodelNode != null) {
refNode.addReference(submodelNode, Identifiers.HasAddIn, false);
} else {
LOG.warn("addSubmodelReferences: Submodel {} not found in submodelRefMap", ref);
}
}
}
if (added) {
node.addComponent(referenceListNode);
}
} catch (Exception ex) {
LOG.error("addSubmodelReferences Exception", ex);
throw ex;
}
}
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_NULL);
}
try {
// EntityType
entity.setEntityType(ValueConverter.getAasEntityType(value.getEntityType()));
// GlobalAssetId
if ((value.getGlobalAssetId() != null) && (!value.getGlobalAssetId().isEmpty())) {
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()) {
LOG.warn("Size of Value ({}) doesn't match the number of StatementNodes ({})", valueMap.size(), statementNodes.length);
throw new IllegalArgumentException("Size of Value doesn't match the number of StatementNodes");
}
for (UaNode statementNode1 : statementNodes) {
if ((statementNode1 instanceof AASSubmodelElementType) && value.getStatements().containsKey(statementNode1.getBrowseName().getName())) {
setSubmodelElementValue((AASSubmodelElementType) statementNode1, value.getStatements().get(statementNode1.getBrowseName().getName()));
}
}
}
} catch (Exception ex) {
LOG.error("setEntityValue Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.nodes.UaNode in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addConceptDescriptions.
/**
* Adds the given list of AAS Concept Descriptions.
*
* @param descriptions The desired list of AAS Concept Descriptions
* @throws StatusException If the operation fails
*/
private void addConceptDescriptions(List<ConceptDescription> descriptions) throws StatusException {
try {
// create folder DictionaryEntries
final UaNode dictionariesFolder = getServer().getNodeManagerRoot().getNodeOrExternal(Identifiers.Dictionaries);
// Folder for my objects
final NodeId dictionarieEntriesFolderId = new NodeId(getNamespaceIndex(), "Dictionaries.DictionaryEntries");
FolderTypeNode dictEntriesFolder = createInstance(FolderTypeNode.class, "DictionaryEntries", dictionarieEntriesFolderId);
this.addNodeAndReference(dictionariesFolder, dictEntriesFolder, Identifiers.Organizes);
for (ConceptDescription c : descriptions) {
String name = c.getIdShort();
NodeId nid = createNodeId(dictionariesFolder, name);
DictionaryEntryType dictNode;
switch(c.getIdentification().getIdType()) {
case IRDI:
AASIrdiConceptDescriptionType irdiNode = createInstance(AASIrdiConceptDescriptionType.class, name, nid);
addIdentifiable(irdiNode, c.getIdentification(), c.getAdministration(), name);
addConceptDescriptionReference(irdiNode, getReference(c));
dictEntriesFolder.addComponent(irdiNode);
dictionaryMap.put(getReference(c), irdiNode);
dictNode = irdiNode;
break;
case IRI:
AASIriConceptDescriptionType iriNode = createInstance(AASIriConceptDescriptionType.class, name, nid);
addIdentifiable(iriNode, c.getIdentification(), c.getAdministration(), name);
addConceptDescriptionReference(iriNode, getReference(c));
dictEntriesFolder.addComponent(iriNode);
dictionaryMap.put(getReference(c), iriNode);
dictNode = iriNode;
break;
default:
AASCustomConceptDescriptionType customNode = createInstance(AASCustomConceptDescriptionType.class, name, nid);
addIdentifiable(customNode, c.getIdentification(), c.getAdministration(), name);
addConceptDescriptionReference(customNode, getReference(c));
dictEntriesFolder.addComponent(customNode);
dictionaryMap.put(getReference(c), customNode);
dictNode = customNode;
break;
}
referableMap.put(AasUtils.toReference(c), new ObjectData(c, dictNode));
}
} catch (Exception ex) {
LOG.error("addConceptDescriptions Exception", ex);
throw ex;
}
}
Aggregations