use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method subscribeMessageBus.
/**
* Subscribes to Events on the MessageBus (e.g. ValueChangeEvents).
*
* @throws MessageBusException if subscribing fails
*/
private void subscribeMessageBus() throws MessageBusException {
try {
if (messageBus != null) {
LOG.debug("subscribeMessageBus: subscribe ValueChangeEvents");
SubscriptionInfo info = SubscriptionInfo.create(ValueChangeEventMessage.class, t -> {
try {
valueChanged(t.getElement(), t.getNewValue(), t.getOldValue());
} catch (StatusException e) {
LOG.error("valueChanged Exception", e);
}
});
SubscriptionId rv = messageBus.subscribe(info);
subscriptions.add(rv);
info = SubscriptionInfo.create(ElementCreateEventMessage.class, x -> {
try {
elementCreated(x.getElement(), x.getValue());
} catch (Exception e) {
LOG.error("elementCreated Exception", e);
}
});
rv = messageBus.subscribe(info);
subscriptions.add(rv);
info = SubscriptionInfo.create(ElementDeleteEventMessage.class, x -> {
try {
elementDeleted(x.getElement());
} catch (Exception e) {
LOG.error("elementDeleted Exception", e);
}
});
rv = messageBus.subscribe(info);
subscriptions.add(rv);
info = SubscriptionInfo.create(ElementUpdateEventMessage.class, x -> {
try {
elementUpdated(x.getElement(), x.getValue());
} catch (Exception e) {
LOG.error("elementUpdated Exception", e);
}
});
rv = messageBus.subscribe(info);
subscriptions.add(rv);
} else {
LOG.warn("MessageBus not available!");
}
} catch (Exception ex) {
LOG.error("subscribeMessageBus Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addEmbeddedDataSpecifications.
/**
* Adds the references to the given Embedded Data Specifications.
*
* @param aasNode The desired object where the DataSpecifications should be added
* @param list The list of the desired Data Specifications
* @throws StatusException If the operation fails
*/
private void addEmbeddedDataSpecifications(AASAssetAdministrationShellType aasNode, List<EmbeddedDataSpecification> list) throws StatusException {
try {
if ((list != null) && (!list.isEmpty())) {
List<Reference> refList = new ArrayList<>();
for (EmbeddedDataSpecification eds : list) {
refList.add(eds.getDataSpecification());
}
AASReferenceList listNode = aasNode.getDataSpecificationNode();
if (listNode == null) {
addAasReferenceList(aasNode, refList, AASAssetAdministrationShellType.DATA_SPECIFICATION);
} else {
addEmbeddedDataSpecificationsReferences(listNode, refList);
}
}
} catch (Exception ex) {
LOG.error(ADD_EMBED_DS_EXC, ex);
throw ex;
}
}
use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method setIdentifierKeyValuePairData.
/**
* Sets the data for the given IdentifierKeyValuePair Node from the corresponding AAS object.
*
* @param identifierPairNode The desired IdentifierKeyValuePair Node
* @param aasIdentifierPair The corresponding AAS IdentifierKeyValuePair
* @param readOnly True if the value should be read-only
* @throws StatusException If the operation fails
*/
private void setIdentifierKeyValuePairData(AASIdentifierKeyValuePairType identifierPairNode, IdentifierKeyValuePair aasIdentifierPair, boolean readOnly) throws StatusException {
try {
// ExternalSubjectId
Reference externalSubjectId = aasIdentifierPair.getExternalSubjectId();
if (externalSubjectId != null) {
AASReferenceType extSubjectNode = identifierPairNode.getExternalSubjectIdNode();
if (extSubjectNode == null) {
addAasReferenceAasNS(identifierPairNode, externalSubjectId, AASIdentifierKeyValuePairType.EXTERNAL_SUBJECT_ID);
} else {
setAasReferenceData(externalSubjectId, extSubjectNode);
}
}
// Key
identifierPairNode.setKey(aasIdentifierPair.getKey());
// Value
identifierPairNode.setValue(aasIdentifierPair.getValue());
if (readOnly) {
identifierPairNode.getKeyNode().setAccessLevel(AccessLevelType.CurrentRead);
identifierPairNode.getValueNode().setAccessLevel(AccessLevelType.CurrentRead);
}
} catch (Exception ex) {
LOG.error("setIdentifierKeyValuePairData Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAasRange.
/**
* Adds an AAS range object to the given node.
*
* @param node The desired UA node
* @param aasRange The corresponding AAS range object to add
* @param submodel The corresponding Submodel as parent object of the data element
* @param parentRef The reference to the parent object
* @param ordered Specifies whether the range should be added ordered (true)
* or unordered (false)
* @throws StatusException If the operation fails
*/
private void addAasRange(UaNode node, Range aasRange, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException {
try {
if ((node != null) && (aasRange != null)) {
String name = aasRange.getIdShort();
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASRangeType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = getDefaultNodeId();
AASRangeType rangeNode = createInstance(AASRangeType.class, nid, browseName, LocalizedText.english(name));
addSubmodelElementBaseData(rangeNode, aasRange);
Reference rangeRef = AasUtils.toReference(parentRef, aasRange);
setRangeValueAndType(aasRange, rangeNode, submodel, rangeRef);
if (ordered) {
node.addReference(rangeNode, Identifiers.HasOrderedComponent, false);
} else {
node.addComponent(rangeNode);
}
referableMap.put(rangeRef, new ObjectData(aasRange, rangeNode, submodel));
}
} catch (Exception ex) {
LOG.error("addAasRange Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method init.
/**
* Initializes the Node Manager.
*
* @throws StatusException If the operation fails
* @throws UaNodeFactoryException Error creating nodes
*/
@Override
protected void init() throws StatusException, UaNodeFactoryException {
try {
super.init();
createAddressSpace();
} catch (ServiceResultException ex) {
throw new StatusException(ex);
} catch (ServiceException ex) {
throw new StatusException(ex.getServiceResult(), ex);
} catch (AddressSpaceException | MessageBusException ex) {
throw new StatusException(ex.getMessage(), ex);
}
}
Aggregations