use of opc.i4aas.AASSubmodelType in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method elementCreated.
/**
* Handles an elementCreated event.
*
* @param element Reference to the created element.
* @param value The element that was added.
* @throws StatusException If the operation fails
* @throws ServiceResultException If the operation fails
* @throws ServiceException If the operation fails
* @throws AddressSpaceException If the operation fails
*/
private void elementCreated(Reference element, Referable value) throws StatusException, ServiceResultException, ServiceException, AddressSpaceException {
if (element == null) {
throw new IllegalArgumentException("element is null");
} else if (value == null) {
throw new IllegalArgumentException("value is null");
}
try {
logger.debug("elementCreated called. Reference " + AasUtils.asString(element));
// The element is the parent object where the value is added
ObjectData parent = null;
if (referableMap.containsKey(element)) {
parent = referableMap.get(element);
} else {
logger.info("elementCreated: element not found in referableMap: " + AasUtils.asString(element));
}
if (value instanceof ConceptDescription) {
addConceptDescriptions(List.of((ConceptDescription) value));
} else if (value instanceof Asset) {
addAsset(aasEnvironmentNode, (Asset) value);
} else if (value instanceof Submodel) {
addSubmodel(aasEnvironmentNode, (Submodel) value);
} else if (value instanceof AssetAdministrationShell) {
addAssetAdministrationShell((AssetAdministrationShell) value);
} else if (parent != null) {
if (value instanceof EmbeddedDataSpecification) {
if (parent.getNode() instanceof AASAssetAdministrationShellType) {
addEmbeddedDataSpecifications((AASAssetAdministrationShellType) parent.getNode(), List.of((EmbeddedDataSpecification) value));
} else if (parent.getNode() instanceof AASSubmodelType) {
addEmbeddedDataSpecifications((AASSubmodelType) parent.getNode(), List.of((EmbeddedDataSpecification) value));
} else if (parent.getNode() instanceof AASSubmodelElementType) {
addEmbeddedDataSpecifications((AASSubmodelElementType) parent.getNode(), List.of((EmbeddedDataSpecification) value));
} else if (parent.getNode() instanceof AASAssetType) {
addEmbeddedDataSpecifications((AASAssetType) parent.getNode(), List.of((EmbeddedDataSpecification) value));
} else {
logger.warn("elementCreated: EmbeddedDataSpecification parent class not found");
}
} else if (value instanceof Constraint) {
if (parent.getNode() instanceof AASSubmodelType) {
addQualifiers(((AASSubmodelType) parent.getNode()).getQualifierNode(), List.of((Constraint) value));
} else if (parent.getNode() instanceof AASSubmodelElementType) {
addQualifiers(((AASSubmodelElementType) parent.getNode()).getQualifierNode(), List.of((Constraint) value));
} else {
logger.warn("elementCreated: Constraint parent class not found");
}
} else if (value instanceof SubmodelElement) {
if (parent.getNode() instanceof AASSubmodelType) {
logger.info("elementCreated: call addSubmodelElements");
addSubmodelElements(parent.getNode(), List.of((SubmodelElement) value), (Submodel) parent.getReferable(), element);
} else if (parent.getNode() instanceof AASSubmodelElementType) {
logger.info("elementCreated: call addSubmodelElements");
addSubmodelElements(parent.getNode(), List.of((SubmodelElement) value), parent.getSubmodel(), element);
} else {
logger.warn("elementCreated: SubmodelElement parent class not found: " + parent.getNode().getNodeId().toString() + "; " + parent.getNode());
}
}
} else {
logger.warn("elementCreated: element not found: " + AasUtils.asString(element));
}
} catch (Throwable ex) {
logger.error("elementCreated Exception", ex);
throw ex;
}
}
use of opc.i4aas.AASSubmodelType 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();
}
logger.trace("addSubmodel: create Submodel " + submodel.getIdShort() + "; NodeId: " + nid.toString());
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 {
logger.warn("addSubmodel: IdShort is empty!");
}
} catch (Throwable ex) {
logger.error("addSubmodel Exception", ex);
throw ex;
}
}
Aggregations