use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAssetInformation.
/**
* Adds an AssetInformation object to the given Node.
*
* @param aasNode The AAS node where the AssetInformation should be added
* @param assetInformation The desired AssetInformation object
* @throws StatusException If the operation fails
*/
private void addAssetInformation(AASAssetAdministrationShellType aasNode, AssetInformation assetInformation) throws StatusException {
if (aasNode == null) {
throw new IllegalArgumentException("aasNode = null");
} else if (assetInformation == null) {
throw new IllegalArgumentException("assetInformation = null");
}
try {
boolean created = false;
AASAssetInformationType assetInfoNode;
assetInfoNode = aasNode.getAssetInformationNode();
if (assetInfoNode == null) {
String displayName = "AssetInformation";
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASSubmodelType.getNamespaceUri(), displayName).toQualifiedName(getNamespaceTable());
NodeId nid = createNodeId(aasNode, browseName);
assetInfoNode = createInstance(AASAssetInformationType.class, nid, browseName, LocalizedText.english(displayName));
created = true;
}
if (assetInfoNode != null) {
// AssetKind
AssetKind assetKind = assetInformation.getAssetKind();
assetInfoNode.setAssetKind(ValueConverter.convertAssetKind(assetKind));
// BillOfMaterials
List<Reference> assetBills = assetInformation.getBillOfMaterials();
if ((assetBills != null) && (!assetBills.isEmpty())) {
AASReferenceList assetBillsNode = assetInfoNode.getBillOfMaterialNode();
addBillOfMaterials(assetBillsNode, assetBills);
}
// DefaultThumbnail
File thumbnail = assetInformation.getDefaultThumbnail();
if (thumbnail != null) {
addAasFile(assetInfoNode, thumbnail, null, null, false, AASAssetInformationType.DEFAULT_THUMBNAIL);
}
// GlobalAssetId
Reference globalAssetId = assetInformation.getGlobalAssetId();
if (globalAssetId != null) {
addAasReferenceAasNS(assetInfoNode, globalAssetId, AASAssetInformationType.GLOBAL_ASSET_ID);
}
// SpecificAssetIds
List<IdentifierKeyValuePair> specificAssetIds = assetInformation.getSpecificAssetIds();
if ((specificAssetIds != null) && (!specificAssetIds.isEmpty())) {
addSpecificAssetIds(assetInfoNode, specificAssetIds, "SpecificAssetIds");
}
if (created) {
aasNode.addComponent(assetInfoNode);
}
}
} catch (Exception ex) {
LOG.error("addAssetInformation 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 submodelNode 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(AASSubmodelType submodelNode, 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 = submodelNode.getDataSpecificationNode();
if (listNode == null) {
addAasReferenceList(submodelNode, refList, AASSubmodelType.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 addQualifier.
/**
* Creates and adds a Qualifier to the given Node.
*
* @param node The UA node in which the Qualifier should be created
* @param qualifier The desired Qualifier
* @param name The name of the qualifier
*/
private void addQualifier(UaNode node, Qualifier qualifier, String name) throws StatusException {
if (node == null) {
throw new IllegalArgumentException(NODE_NULL);
} else if (qualifier == null) {
throw new IllegalArgumentException("qualifier = null");
}
try {
LOG.info("addQualifier {}; to Node: {}", name, node);
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASQualifierType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = createNodeId(node, browseName);
AASQualifierType qualifierNode = createInstance(AASQualifierType.class, nid, browseName, LocalizedText.english(name));
// Type
qualifierNode.setType(qualifier.getType());
// ValueType
qualifierNode.setValueType(ValueConverter.stringToValueType(qualifier.getValueType()));
// Value
if (qualifier.getValue() != null) {
if (qualifierNode.getValueNode() == null) {
addQualifierValueNode(qualifierNode);
}
qualifierNode.setValue(qualifier.getValue());
}
// ValueId
if (qualifier.getValueId() != null) {
addAasReferenceAasNS(qualifierNode, qualifier.getValueId(), AASQualifierType.VALUE_ID);
}
if (VALUES_READ_ONLY) {
if (qualifierNode.getValueNode() != null) {
qualifierNode.getValueNode().setAccessLevel(AccessLevelType.CurrentRead);
}
if (qualifierNode.getValueTypeNode() != null) {
qualifierNode.getValueTypeNode().setAccessLevel(AccessLevelType.CurrentRead);
}
if (qualifierNode.getTypeNode() != null) {
qualifierNode.getTypeNode().setAccessLevel(AccessLevelType.CurrentRead);
}
}
node.addComponent(qualifierNode);
} catch (Exception ex) {
LOG.error("addQualifier Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAssetAdministrationShell.
/**
* Adds the given AssetAdministrationShell.
*
* @throws StatusException If the operation fails
*/
private void addAssetAdministrationShell(AssetAdministrationShell aas) throws StatusException {
try {
TypeDefinitionBasedNodeBuilderConfiguration.Builder conf = TypeDefinitionBasedNodeBuilderConfiguration.builder();
Reference derivedFrom = aas.getDerivedFrom();
if (derivedFrom != null) {
UaBrowsePath bp = UaBrowsePath.from(opc.i4aas.ObjectTypeIds.AASAssetAdministrationShellType, UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASAssetAdministrationShellType.getNamespaceUri(), AASAssetAdministrationShellType.DERIVED_FROM));
conf.addOptional(bp);
}
this.setNodeBuilderConfiguration(conf.build());
QualifiedName browseName = UaQualifiedName.from(NAMESPACE_URI, aas.getIdShort()).toQualifiedName(getNamespaceTable());
String displayName = "AAS:" + aas.getIdShort();
NodeId nid = new NodeId(getNamespaceIndex(), aas.getIdShort());
if (findNode(nid) != null) {
// The NodeId already exists
nid = getDefaultNodeId();
}
AASAssetAdministrationShellType aasShell = createInstance(AASAssetAdministrationShellTypeNode.class, nid, browseName, LocalizedText.english(displayName));
addIdentifiable(aasShell, aas.getIdentification(), aas.getAdministration(), aas.getCategory());
// DataSpecifications
addEmbeddedDataSpecifications(aasShell, aas.getEmbeddedDataSpecifications());
// AssetInformation
AssetInformation assetInformation = aas.getAssetInformation();
if (assetInformation != null) {
addAssetInformation(aasShell, assetInformation);
}
// submodel references
List<Reference> submodelRefs = aas.getSubmodels();
if ((submodelRefs != null) && (!submodelRefs.isEmpty())) {
addSubmodelReferences(aasShell, submodelRefs);
}
// add AAS to Environment
addNodeAndReference(aasEnvironmentNode, aasShell, Identifiers.Organizes);
referableMap.put(AasUtils.toReference(aas), new ObjectData(aas, aasShell));
} catch (Exception ex) {
LOG.error("addAssetAdministrationShell Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.StatusException 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;
}
}
Aggregations