use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAasEntity.
/**
* Adds an AAS entity to the given node.
*
* @param node The desired UA node
* @param aasEntity The AAS entity to add
* @param submodel The corresponding Submodel
* @param parentRef The AAS reference to the parent object
* @param ordered Specifies whether the entity should be added ordered
* (true) or unordered (false)
* @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 addAasEntity(UaNode node, Entity aasEntity, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
try {
if ((node != null) && (aasEntity != null)) {
String name = aasEntity.getIdShort();
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASEntityType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = getDefaultNodeId();
AASEntityType entityNode = createInstance(AASEntityType.class, nid, browseName, LocalizedText.english(name));
addSubmodelElementBaseData(entityNode, aasEntity);
Reference entityRef = AasUtils.toReference(parentRef, aasEntity);
// EntityType
entityNode.setEntityType(ValueConverter.getAasEntityType(aasEntity.getEntityType()));
submodelElementAasMap.put(entityNode.getEntityTypeNode().getNodeId(), new SubmodelElementData(aasEntity, submodel, SubmodelElementData.Type.ENTITY_TYPE, entityRef));
// GlobalAssetId
if (aasEntity.getGlobalAssetId() != null) {
if (entityNode.getGlobalAssetIdNode() == null) {
addAasReferenceAasNS(entityNode, aasEntity.getGlobalAssetId(), AASEntityType.GLOBAL_ASSET_ID, false);
} else {
setAasReferenceData(aasEntity.getGlobalAssetId(), entityNode.getGlobalAssetIdNode(), false);
}
submodelElementAasMap.put(entityNode.getGlobalAssetIdNode().getKeysNode().getNodeId(), new SubmodelElementData(aasEntity, submodel, SubmodelElementData.Type.ENTITY_GLOBAL_ASSET_ID, entityRef));
}
// SpecificAssetIds
IdentifierKeyValuePair specificAssetId = aasEntity.getSpecificAssetId();
if (specificAssetId != null) {
if (entityNode.getSpecificAssetIdNode() == null) {
addIdentifierKeyValuePair(entityNode, specificAssetId, AASEntityType.SPECIFIC_ASSET_ID);
} else {
setIdentifierKeyValuePairData(entityNode.getSpecificAssetIdNode(), specificAssetId);
}
}
// Statements
addSubmodelElements(entityNode.getStatementNode(), aasEntity.getStatements(), submodel, entityRef);
submodelElementOpcUAMap.put(entityRef, entityNode);
if (ordered) {
node.addReference(entityNode, Identifiers.HasOrderedComponent, false);
} else {
node.addComponent(entityNode);
}
referableMap.put(entityRef, new ObjectData(aasEntity, entityNode, submodel));
}
} catch (Exception ex) {
LOG.error("addAasEntity Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addSubmodel.
/**
* Adds a submodel to a given Node
*
* @param node The desired Node where the submodel should be added
* @param submodel The desired AAS submodel
*/
private void addSubmodel(UaNode node, Submodel submodel) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
if (submodel == null) {
throw new IllegalArgumentException("submodel is null");
}
try {
String shortId = submodel.getIdShort();
if (!shortId.isEmpty()) {
String displayName = "Submodel:" + shortId;
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASSubmodelType.getNamespaceUri(), shortId).toQualifiedName(getNamespaceTable());
NodeId nid = createNodeId(node, browseName);
if (findNode(nid) != null) {
// The NodeId already exists
nid = getDefaultNodeId();
}
LOG.trace("addSubmodel: create Submodel {}; NodeId: {}", submodel.getIdShort(), nid);
AASSubmodelType smNode = createInstance(AASSubmodelType.class, nid, browseName, LocalizedText.english(displayName));
// ModelingKind
smNode.setModelingKind(ValueConverter.convertModelingKind(submodel.getKind()));
addIdentifiable(smNode, submodel.getIdentification(), submodel.getAdministration(), submodel.getCategory());
// DataSpecifications
addEmbeddedDataSpecifications(smNode, submodel.getEmbeddedDataSpecifications());
// Qualifiers
List<Constraint> qualifiers = submodel.getQualifiers();
if ((qualifiers != null) && (!qualifiers.isEmpty())) {
if (smNode.getQualifierNode() == null) {
addQualifierNode(smNode);
}
addQualifiers(smNode.getQualifierNode(), qualifiers);
}
// SemanticId
if (submodel.getSemanticId() != null) {
addSemanticId(smNode, submodel.getSemanticId());
}
// Description
addDescriptions(smNode, submodel.getDescriptions());
Reference refSubmodel = AasUtils.toReference(submodel);
// SubmodelElements
addSubmodelElements(smNode, submodel.getSubmodelElements(), submodel, refSubmodel);
if (VALUES_READ_ONLY) {
smNode.getModelingKindNode().setAccessLevel(AccessLevelType.CurrentRead);
}
submodelOpcUAMap.put(AasUtils.toReference(submodel), smNode);
node.addComponent(smNode);
referableMap.put(AasUtils.toReference(submodel), new ObjectData(submodel, smNode));
} else {
LOG.warn("addSubmodel: IdShort is empty!");
}
} catch (Exception ex) {
LOG.error("addSubmodel Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAasBlob.
/**
* Adds an AAS Blob to the given UA node.
*
* @param node The desired UA node
* @param aasBlob The AAS blob to add
* @param submodel The corresponding Submodel as parent object of the data element
* @param parentRef Tne reference to the parent object
* @param ordered Specifies whether the blob should be added ordered (true)
* or unordered (false)
* @throws StatusException If the operation fails
*/
private void addAasBlob(UaNode node, Blob aasBlob, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException {
try {
if ((node != null) && (aasBlob != null)) {
String name = aasBlob.getIdShort();
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASBlobType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = getDefaultNodeId();
AASBlobType blobNode = createInstance(AASBlobType.class, nid, browseName, LocalizedText.english(name));
addSubmodelElementBaseData(blobNode, aasBlob);
// MimeType
blobNode.setMimeType(aasBlob.getMimeType());
Reference blobRef = AasUtils.toReference(parentRef, aasBlob);
// Value
if (aasBlob.getValue() != null) {
if (blobNode.getValueNode() == null) {
addBlobValueNode(blobNode);
}
submodelElementAasMap.put(blobNode.getValueNode().getNodeId(), new SubmodelElementData(aasBlob, submodel, SubmodelElementData.Type.BLOB_VALUE, blobRef));
LOG.debug("addAasBlob: NodeId {}; Blob: {}", blobNode.getValueNode().getNodeId(), aasBlob);
submodelElementOpcUAMap.put(blobRef, blobNode);
blobNode.setValue(ByteString.valueOf(aasBlob.getValue()));
}
if (ordered) {
node.addReference(blobNode, Identifiers.HasOrderedComponent, false);
} else {
node.addComponent(blobNode);
}
referableMap.put(blobRef, new ObjectData(aasBlob, blobNode, submodel));
}
} catch (Exception ex) {
LOG.error("addAasBlob Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAasEvent.
/**
* Adds an AAS Event to the given node.
*
* @param node The desired UA node
* @param aasEvent The AAS Event to add
* @param submodel The corresponding Submodel as parent object of the data element
* @param parentRef The AAS reference to the parent object
* @param ordered Specifies whether the entity should be added ordered
* (true) or unordered (false)
* @throws StatusException If the operation fails
*/
private void addAasEvent(UaNode node, Event aasEvent, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException {
try {
if ((node != null) && (aasEvent != null)) {
String name = aasEvent.getIdShort();
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASEventType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = getDefaultNodeId();
AASEventType eventNode = createInstance(AASEventType.class, nid, browseName, LocalizedText.english(name));
addSubmodelElementBaseData(eventNode, aasEvent);
if (aasEvent instanceof BasicEvent) {
setBasicEventData(eventNode, (BasicEvent) aasEvent);
}
Reference eventRef = AasUtils.toReference(parentRef, aasEvent);
if (ordered) {
node.addReference(eventNode, Identifiers.HasOrderedComponent, false);
} else {
node.addComponent(eventNode);
}
referableMap.put(eventRef, new ObjectData(aasEvent, eventNode, submodel));
}
} catch (Exception ex) {
LOG.error("addAasEvent Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addIdentifierKeyValuePair.
/**
* Adds an IdentifierKeyValuePair to the given Node.
*
* @param node The UA node in which the IdentifierKeyValuePair should be created
* @param identifierPair The desired IdentifierKeyValuePair
* @param name The desired name of the IdentifierKeyValuePair node
* @param readOnly True if the value should be read-only
* @throws StatusException If the operation fails
*/
private void addIdentifierKeyValuePair(UaNode node, IdentifierKeyValuePair identifierPair, String name, boolean readOnly) throws StatusException {
if (node == null) {
throw new IllegalArgumentException(NODE_NULL);
} else if (identifierPair == null) {
throw new IllegalArgumentException("identifierPair = null");
}
try {
LOG.info("addIdentifierKeyValuePair {}; to Node: {}", name, node);
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASIdentifierKeyValuePairType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = createNodeId(node, browseName);
AASIdentifierKeyValuePairType identifierPairNode = createInstance(AASIdentifierKeyValuePairType.class, nid, browseName, LocalizedText.english(name));
setIdentifierKeyValuePairData(identifierPairNode, identifierPair, readOnly);
node.addComponent(identifierPairNode);
} catch (Exception ex) {
LOG.error("addIdentifierKeyValuePair Exception", ex);
throw ex;
}
}
Aggregations