use of com.prosysopc.ua.StatusException 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.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method setRangeValue.
/**
* Sets the value for the given Range.
*
* @param range The desired Range.
* @param value The new value
* @throws StatusException If the operation fails
*/
private void setRangeValue(AASRangeType range, RangeValue<?> value) throws StatusException {
if (range == null) {
throw new IllegalArgumentException("range is null");
} else if (value == null) {
throw new IllegalArgumentException(VALUE_NULL);
}
try {
// special treatment for some not directly supported types
TypedValue<?> tvmin = value.getMin();
Object objmin = tvmin.getValue();
if ((tvmin instanceof DecimalValue) || (tvmin instanceof IntegerValue)) {
objmin = Long.parseLong(objmin.toString());
}
TypedValue<?> tvmax = value.getMax();
Object objmax = tvmax.getValue();
if ((tvmax instanceof DecimalValue) || (tvmax instanceof IntegerValue)) {
objmax = Long.parseLong(objmax.toString());
}
range.setMin(objmin);
range.setMax(objmax);
} catch (Exception ex) {
LOG.error("setRangeValue Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addSubmodelElementBaseData.
/**
* Adds base data to the given submodel element.
*
* @param node The desired submodel element UA node
* @param element The corresponding AAS submodel element
* @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 addSubmodelElementBaseData(AASSubmodelElementType node, SubmodelElement element) throws StatusException {
try {
if ((node != null) && (element != null)) {
// Category
String category = element.getCategory();
if (category == null) {
category = "";
}
node.setCategory(category);
node.setModelingKind(ValueConverter.convertModelingKind(element.getKind()));
// DataSpecifications
addEmbeddedDataSpecifications(node, element.getEmbeddedDataSpecifications());
// SemanticId
if (element.getSemanticId() != null) {
addSemanticId(node, element.getSemanticId());
}
// Qualifiers
List<Constraint> qualifiers = element.getQualifiers();
if ((qualifiers != null) && (!qualifiers.isEmpty())) {
if (node.getQualifierNode() == null) {
addQualifierNode(node);
}
addQualifiers(node.getQualifierNode(), qualifiers);
}
// Description
addDescriptions(node, element.getDescriptions());
if (VALUES_READ_ONLY) {
node.getCategoryNode().setAccessLevel(AccessLevelType.CurrentRead);
node.getModelingKindNode().setAccessLevel(AccessLevelType.CurrentRead);
}
}
} catch (Exception ex) {
LOG.error("addSubmodelElementBaseData Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method createAasNodes.
/**
* Creates the AAS nodes in the address space.
*
* @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 createAasNodes() throws StatusException, ServiceResultException, ServiceException, AddressSpaceException {
try {
if (aasEnvironment != null) {
// add AASEnvironmentType
addAasEnvironmentNode();
// ConceptDescriptions.
addConceptDescriptions(aasEnvironment.getConceptDescriptions());
// Assets
List<Asset> assets = aasEnvironment.getAssets();
if ((assets != null) && (!assets.isEmpty())) {
for (Asset asset : assets) {
addAsset(aasEnvironmentNode, asset);
}
}
// Submodels
List<Submodel> submodels = aasEnvironment.getSubmodels();
if ((submodels != null) && (!submodels.isEmpty())) {
for (Submodel submodel : submodels) {
addSubmodel(aasEnvironmentNode, submodel);
}
}
addAssetAdministrationShells();
}
} catch (Exception ex) {
LOG.error("createAasNodes Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.StatusException 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;
}
}
Aggregations