use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAasRelationshipElement.
/**
* Adds an AAS Relationship Element to the given node.
*
* @param node The desired UA node
* @param aasRelElem The corresponding AAS Relationship Element
* @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 addAasRelationshipElement(UaNode node, RelationshipElement aasRelElem, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException {
try {
if ((node != null) && (aasRelElem != null)) {
Reference relElemRef = AasUtils.toReference(parentRef, aasRelElem);
String name = aasRelElem.getIdShort();
AASRelationshipElementType relElemNode;
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASRelationshipElementType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = getDefaultNodeId();
if (aasRelElem instanceof AnnotatedRelationshipElement) {
relElemNode = createAnnotatedRelationshipElement((AnnotatedRelationshipElement) aasRelElem, submodel, relElemRef, nid);
} else {
relElemNode = createInstance(AASRelationshipElementType.class, nid, browseName, LocalizedText.english(name));
}
if (relElemNode != null) {
addSubmodelElementBaseData(relElemNode, aasRelElem);
setAasReferenceData(aasRelElem.getFirst(), relElemNode.getFirstNode(), false);
setAasReferenceData(aasRelElem.getSecond(), relElemNode.getSecondNode(), false);
submodelElementAasMap.put(relElemNode.getFirstNode().getKeysNode().getNodeId(), new SubmodelElementData(aasRelElem, submodel, SubmodelElementData.Type.RELATIONSHIP_ELEMENT_FIRST, relElemRef));
submodelElementAasMap.put(relElemNode.getSecondNode().getKeysNode().getNodeId(), new SubmodelElementData(aasRelElem, submodel, SubmodelElementData.Type.RELATIONSHIP_ELEMENT_SECOND, relElemRef));
submodelElementOpcUAMap.put(relElemRef, relElemNode);
if (ordered) {
node.addReference(relElemNode, Identifiers.HasOrderedComponent, false);
} else {
node.addComponent(relElemNode);
}
referableMap.put(relElemRef, new ObjectData(aasRelElem, relElemNode, submodel));
}
}
} catch (Exception ex) {
LOG.error("addAasRelationshipElement Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method setPropertyValue.
/**
* Sets the value of a property.
*
* @param property The desired Property
* @param value The new value.
* @throws StatusException If the operation fails.
*/
@SuppressWarnings("java:S125")
private void setPropertyValue(AASPropertyType property, PropertyValue value) throws StatusException {
if (property == null) {
throw new IllegalArgumentException("property is null");
} else if (value == null) {
throw new IllegalArgumentException(VALUE_NULL);
}
LOG.debug("setPropertyValue: {} to {}", property.getBrowseName().getName(), value.getValue());
try {
// special treatment for some not directly supported types
TypedValue<?> tv = value.getValue();
Object obj = tv.getValue();
if ((tv instanceof DecimalValue) || (tv instanceof IntegerValue)) {
obj = Long.parseLong(obj.toString());
}
property.setValue(obj);
// switch (property.getValueType()) {
// case ByteString:
// // TO DO integrate Property value
// property.setValue(value.getValue());
// break;
//
// case Boolean:
// // TO DO integrate Property value
// property.setValue(value.getValue());
// break;
//
// case DateTime:
// // TO DO integrate Property value
// property.setValue(value.getValue());
// break;
//
// case Int32:
// // TO DO integrate Property value
// property.setValue(value.getValue());
// break;
//
// case UInt32:
// // TO DO integrate Property value
// property.setValue(value.getValue());
// break;
//
// case Int64:
// // TO DO integrate Property value
// property.setValue(value.getValue());
// break;
//
// case UInt64:
// // TO DO integrate Property value
// property.setValue(value.getValue());
// break;
//
// case Int16:
// // TO DO integrate Property value
// property.setValue(value.getValue());
// break;
//
// case UInt16:
// // TO DO integrate Property value
// property.setValue(value.getValue());
// break;
//
// case Byte:
// // TO DO integrate Property value
// property.setValue(value.getValue());
// break;
//
// case SByte:
// // TO DO integrate Property value
// property.setValue(value.getValue());
// break;
//
// case Double:
// // TO DO integrate Property value
// property.setValue(value.getValue());
// break;
//
// case Float:
// // TO DO integrate Property value
// property.setValue(value.getValue());
// break;
//
// case LocalizedText:
// // TO DO integrate Property value
// property.setValue(value.getValue());
// break;
//
// case String:
// // TO DO integrate Property value
// property.setValue(value.getValue());
// break;
//
// case UtcTime:
// // TO DO integrate Property value
// property.setValue(value.getValue());
// break;
//
// default:
// logger.warn("setPropertyValue: Property " + property.getBrowseName().getName() + ": Unknown type: " + property.getValueType());
// break;
// }
} catch (Exception ex) {
LOG.error("setPropertyValue Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAasCapability.
/**
* Adds an AAS Capability to the given node.
*
* @param node The desired UA node
* @param aasCapability The corresponding AAS Capability 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 capability should be added ordered
* (true) or unordered (false)
* @throws StatusException If the operation fails
*/
private void addAasCapability(UaNode node, Capability aasCapability, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException {
try {
if ((node != null) && (aasCapability != null)) {
String name = aasCapability.getIdShort();
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASCapabilityType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = getDefaultNodeId();
AASCapabilityType capabilityNode = createInstance(AASCapabilityType.class, nid, browseName, LocalizedText.english(name));
addSubmodelElementBaseData(capabilityNode, aasCapability);
if (ordered) {
node.addReference(capabilityNode, Identifiers.HasOrderedComponent, false);
} else {
node.addComponent(capabilityNode);
}
Reference capabilityRef = AasUtils.toReference(parentRef, aasCapability);
referableMap.put(capabilityRef, new ObjectData(aasCapability, capabilityNode, submodel));
}
} catch (Exception ex) {
LOG.error("addAasCapability Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.StatusException in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method setRelationshipValue.
/**
* Sets the values for the given RelationshipElement.
*
* @param aasElement The desired RelationshipElement.
* @param value The new value.
* @throws StatusException If the operation fails
*/
private void setRelationshipValue(AASRelationshipElementType aasElement, RelationshipElementValue value) throws StatusException {
if (aasElement == null) {
throw new IllegalArgumentException("aasElement is null");
} else if (value == null) {
throw new IllegalArgumentException(VALUE_NULL);
}
try {
Reference ref = new DefaultReference.Builder().keys(value.getFirst()).build();
setAasReferenceData(ref, aasElement.getFirstNode(), false);
ref = new DefaultReference.Builder().keys(value.getSecond()).build();
setAasReferenceData(ref, aasElement.getSecondNode(), false);
if ((aasElement instanceof AASAnnotatedRelationshipElementType) && (value instanceof AnnotatedRelationshipElementValue)) {
AASAnnotatedRelationshipElementType annotatedElement = (AASAnnotatedRelationshipElementType) aasElement;
AnnotatedRelationshipElementValue annotatedValue = (AnnotatedRelationshipElementValue) value;
UaNode[] annotationNodes = annotatedElement.getAnnotationNode().getComponents();
Map<String, DataElementValue> valueMap = annotatedValue.getAnnotations();
if (annotationNodes.length != valueMap.size()) {
LOG.warn("Size of Value ({}) doesn't match the number of AnnotationNodes ({})", valueMap.size(), annotationNodes.length);
throw new IllegalArgumentException("Size of Value doesn't match the number of AnnotationNodes");
}
// The Key of the Map is the IDShort of the DataElement (in our case the BrowseName)
for (UaNode annotationNode : annotationNodes) {
if (valueMap.containsKey(annotationNode.getBrowseName().getName())) {
setDataElementValue(annotationNode, valueMap.get(annotationNode.getBrowseName().getName()));
}
}
} else {
LOG.info("setRelationshipValue: No AnnotatedRelationshipElement {}", aasElement.getBrowseName().getName());
}
} catch (Exception ex) {
LOG.error("setAnnotatedRelationshipValue 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 assetNode The desired node where the DataSpecifications should be added
* @param list The list of the desired Data Specifications
* @throws StatusException If the operation fails
*/
private void addEmbeddedDataSpecifications(AASAssetType assetNode, 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 = assetNode.getDataSpecificationNode();
if (listNode == null) {
addAasReferenceList(assetNode, refList, AASAssetType.DATA_SPECIFICATION);
} else {
addEmbeddedDataSpecificationsReferences(listNode, refList);
}
}
} catch (Exception ex) {
LOG.error(ADD_EMBED_DS_EXC, ex);
throw ex;
}
}
Aggregations