use of com.prosysopc.ua.stack.builtintypes.QualifiedName 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.stack.builtintypes.QualifiedName 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.stack.builtintypes.QualifiedName in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAasReferenceElement.
/**
* Adds an AAS reference element to the given node.
*
* @param node The desired UA node
* @param aasRefElem The AAS reference element 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 reference element should be added
* ordered (true) or unordered (false)
* @throws StatusException If the operation fails
*/
private void addAasReferenceElement(UaNode node, ReferenceElement aasRefElem, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException {
try {
if ((node != null) && (aasRefElem != null)) {
String name = aasRefElem.getIdShort();
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASReferenceElementType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = getDefaultNodeId();
AASReferenceElementType refElemNode = createInstance(AASReferenceElementType.class, nid, browseName, LocalizedText.english(name));
addSubmodelElementBaseData(refElemNode, aasRefElem);
if (aasRefElem.getValue() != null) {
setAasReferenceData(aasRefElem.getValue(), refElemNode.getValueNode(), false);
}
Reference refElemRef = AasUtils.toReference(parentRef, aasRefElem);
submodelElementAasMap.put(refElemNode.getValueNode().getKeysNode().getNodeId(), new SubmodelElementData(aasRefElem, submodel, SubmodelElementData.Type.REFERENCE_ELEMENT_VALUE, refElemRef));
submodelElementOpcUAMap.put(refElemRef, refElemNode);
if (ordered) {
node.addReference(refElemNode, Identifiers.HasOrderedComponent, false);
} else {
node.addComponent(refElemNode);
}
referableMap.put(refElemRef, new ObjectData(aasRefElem, refElemNode, submodel));
}
} catch (Exception ex) {
LOG.error("addAasReferenceElement Exception", ex);
throw ex;
}
}
use of com.prosysopc.ua.stack.builtintypes.QualifiedName in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method setPropertyValueAndType.
/**
* Adds the OPC UA property itself to the given Property object and sets the value.
*
* @param aasProperty The AAS property
* @param submodel The corresponding Submodel as parent object of the data element
* @param prop The UA Property object
* @param propRef The AAS reference to the property
*/
@SuppressWarnings("java:S125")
private void setPropertyValueAndType(Property aasProperty, Submodel submodel, AASPropertyType prop, Reference propRef) {
try {
NodeId myPropertyId = new NodeId(getNamespaceIndex(), prop.getNodeId().getValue().toString() + "." + AASPropertyType.VALUE);
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASPropertyType.getNamespaceUri(), AASPropertyType.VALUE).toQualifiedName(getNamespaceTable());
LocalizedText displayName = LocalizedText.english(AASPropertyType.VALUE);
submodelElementAasMap.put(myPropertyId, new SubmodelElementData(aasProperty, submodel, SubmodelElementData.Type.PROPERTY_VALUE, propRef));
LOG.debug("setPropertyValueAndType: NodeId {}; Property: {}", myPropertyId, aasProperty);
if (submodel != null) {
submodelElementOpcUAMap.put(propRef, prop);
}
AASValueTypeDataType valueDataType;
PropertyValue typedValue = PropertyValue.of(aasProperty.getValueType(), aasProperty.getValue());
if ((typedValue != null) && (typedValue.getValue() != null)) {
valueDataType = ValueConverter.datatypeToValueType(typedValue.getValue().getDataType());
} else {
valueDataType = ValueConverter.stringToValueType(aasProperty.getValueType());
}
prop.setValueType(valueDataType);
switch(valueDataType) {
//
case Boolean:
PlainProperty<Boolean> myBoolProperty = new PlainProperty<>(this, myPropertyId, browseName, displayName);
myBoolProperty.setDataTypeId(Identifiers.Boolean);
if ((typedValue != null) && (typedValue.getValue() != null) && (typedValue.getValue().getValue() != null)) {
myBoolProperty.setValue(typedValue.getValue().getValue());
}
prop.addProperty(myBoolProperty);
break;
//
case Int32:
PlainProperty<Integer> myIntProperty = new PlainProperty<>(this, myPropertyId, browseName, displayName);
myIntProperty.setDataTypeId(Identifiers.Int32);
if ((typedValue != null) && (typedValue.getValue() != null) && (typedValue.getValue().getValue() != null)) {
myIntProperty.setValue(typedValue.getValue().getValue());
}
prop.addProperty(myIntProperty);
break;
//
case Int64:
PlainProperty<Long> myLongProperty = new PlainProperty<>(this, myPropertyId, browseName, displayName);
myLongProperty.setDataTypeId(Identifiers.Int64);
if ((typedValue != null) && (typedValue.getValue() != null) && (typedValue.getValue().getValue() != null)) {
Object obj = typedValue.getValue().getValue();
if (!(obj instanceof Long)) {
obj = Long.parseLong(obj.toString());
}
myLongProperty.setValue(obj);
}
prop.addProperty(myLongProperty);
break;
//
case Int16:
PlainProperty<Short> myInt16Property = new PlainProperty<>(this, myPropertyId, browseName, displayName);
myInt16Property.setDataTypeId(Identifiers.Int16);
if ((typedValue != null) && (typedValue.getValue() != null) && (typedValue.getValue().getValue() != null)) {
myInt16Property.setValue(typedValue.getValue().getValue());
}
prop.addProperty(myInt16Property);
break;
//
case SByte:
PlainProperty<Byte> mySByteProperty = new PlainProperty<>(this, myPropertyId, browseName, displayName);
mySByteProperty.setDataTypeId(Identifiers.SByte);
if ((typedValue != null) && (typedValue.getValue() != null) && (typedValue.getValue().getValue() != null)) {
mySByteProperty.setValue(typedValue.getValue().getValue());
}
prop.addProperty(mySByteProperty);
break;
case Double:
PlainProperty<Double> myDoubleProperty = new PlainProperty<>(this, myPropertyId, browseName, displayName);
myDoubleProperty.setDataTypeId(Identifiers.Double);
if ((typedValue != null) && (typedValue.getValue() != null) && (typedValue.getValue().getValue() != null)) {
myDoubleProperty.setValue(typedValue.getValue().getValue());
}
prop.addProperty(myDoubleProperty);
break;
case Float:
PlainProperty<Float> myFloatProperty = new PlainProperty<>(this, myPropertyId, browseName, displayName);
myFloatProperty.setDataTypeId(Identifiers.Float);
if ((typedValue != null) && (typedValue.getValue() != null) && (typedValue.getValue().getValue() != null)) {
myFloatProperty.setValue(typedValue.getValue().getValue());
}
prop.addProperty(myFloatProperty);
break;
//
case String:
PlainProperty<String> myStringProperty = new PlainProperty<>(this, myPropertyId, browseName, displayName);
myStringProperty.setDataTypeId(Identifiers.String);
if ((typedValue != null) && (typedValue.getValue() != null) && (typedValue.getValue().getValue() != null)) {
myStringProperty.setValue(typedValue.getValue().getValue());
}
prop.addProperty(myStringProperty);
break;
//
default:
LOG.warn("setValueAndType: Property {}: Unknown type: {}; use string as default", prop.getBrowseName().getName(), aasProperty.getValueType());
PlainProperty<String> myDefaultProperty = new PlainProperty<>(this, myPropertyId, browseName, displayName);
myDefaultProperty.setDataTypeId(Identifiers.String);
myDefaultProperty.setValue(aasProperty.getValue());
prop.addProperty(myDefaultProperty);
break;
}
if ((prop.getValueNode() != null) && (prop.getValueNode().getDescription() == null)) {
prop.getValueNode().setDescription(new LocalizedText("", ""));
}
} catch (Exception ex) {
LOG.error("setPropertyValueAndType Exception", ex);
}
}
Aggregations