use of de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceMethodManagerListener method onCall.
/**
* Callback method when a method was called
*
* @param serviceContext the current service context
* @param objectId the ID of the node whose method is being called
* @param object the object node whose method is being called, if available
* @param methodId the ID of the method being called
* @param method the method node being called, if available
* @param inputArguments input argument values
* @param inputArgumentResults argument errors. If errors in the values are
* encountered.
* @param inputArgumentDiagnosticInfos diagnostic info, in case of errors.
* @param outputs output values. The array is pre-created, just fill in the
* values.
* @return true if you handle the call, which prevents any other handler
* being called.
* @throws StatusException if there are errors in the method handling. For
* example, if you set inputArgumentResults, you should throw a
* StatusException with StatusCodes.Bad_InvalidArgument
*/
@Override
public boolean onCall(ServiceContext serviceContext, NodeId objectId, UaNode object, NodeId methodId, UaMethod method, Variant[] inputArguments, StatusCode[] inputArgumentResults, DiagnosticInfo[] inputArgumentDiagnosticInfos, Variant[] outputs) throws StatusException {
boolean retval = false;
// Handle method calls
// Note that the outputs array is already allocated
logger.info("onCall: method " + methodId.toString() + ": called. InputArguments: " + Arrays.toString(inputArguments));
try {
if (endpoint == null) {
logger.warn("onCall: no Endpoint available");
} else {
SubmodelElementData data = nodeManager.getAasData(objectId);
Operation aasOper = (Operation) data.getSubmodelElement();
if (aasOper != null) {
List<OperationVariable> inputVariables = aasOper.getInputVariables();
ValueConverter.setOperationValues(inputVariables, inputArguments);
List<OperationVariable> outputVariables = endpoint.callOperation(aasOper, inputVariables, data.getSubmodel(), data.getReference());
ValueConverter.setOutputArguments(outputVariables, outputs);
retval = true;
} else {
logger.info("onCall: Property for " + objectId.toString() + " not found");
}
}
} catch (StatusException se) {
logger.error("onCall StatusException", se);
throw se;
} catch (Throwable ex) {
logger.error("onCall Exception", ex);
throw new StatusException(ex.getMessage(), StatusCodes.Bad_UnexpectedError);
}
return retval;
}
use of de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData 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
* @throws ServiceException If the operation fails
* @throws AddressSpaceException If the operation fails
* @throws ServiceResultException If the operation fails
*/
private void addAasBlob(UaNode node, Blob aasBlob, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
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));
logger.debug("addAasBlob: NodeId " + blobNode.getValueNode().getNodeId() + "; Blob: " + 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 (Throwable ex) {
logger.error("addAasBlob Exception", ex);
throw ex;
}
}
use of de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAasOperation.
/**
* Adds an AAS Operation to the given node.
*
* @param node The desired UA node
* @param aasOperation The corresponding AAS operation 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 operation should be added ordered
* (true) or unordered (false)
*/
private void addAasOperation(UaNode node, Operation aasOperation, Submodel submodel, Reference parentRef, boolean ordered) {
try {
String name = aasOperation.getIdShort();
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASOperationType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = getDefaultNodeId();
AASOperationType oper = createInstance(AASOperationType.class, nid, browseName, LocalizedText.english(name));
addSubmodelElementBaseData(oper, aasOperation);
Reference operRef = AasUtils.toReference(parentRef, aasOperation);
// for operations we put the corresponding operation object into the map
submodelElementAasMap.put(nid, new SubmodelElementData(aasOperation, submodel, SubmodelElementData.Type.OPERATION, operRef));
logger.debug("addAasOperation: NodeId " + nid + "; Property: " + aasOperation);
// add method
NodeId myMethodId = new NodeId(getNamespaceIndex(), nid.getValue().toString() + "." + name);
PlainMethod method = new PlainMethod(this, myMethodId, name, Locale.ENGLISH);
Argument[] inputs = new Argument[aasOperation.getInputVariables().size()];
for (int i = 0; i < aasOperation.getInputVariables().size(); i++) {
OperationVariable v = aasOperation.getInputVariables().get(i);
inputs[i] = new Argument();
setOperationArgument(inputs[i], v);
}
method.setInputArguments(inputs);
Argument[] outputs = new Argument[1];
for (int i = 0; i < aasOperation.getOutputVariables().size(); i++) {
OperationVariable v = aasOperation.getOutputVariables().get(i);
outputs[i] = new Argument();
setOperationArgument(outputs[i], v);
}
method.setOutputArguments(outputs);
MethodManagerUaNode m = (MethodManagerUaNode) this.getMethodManager();
m.addCallListener(aasMethodManagerListener);
method.setDescription(new LocalizedText("", ""));
oper.addComponent(method);
if (ordered) {
node.addReference(oper, Identifiers.HasOrderedComponent, false);
} else {
node.addComponent(oper);
}
referableMap.put(operRef, new ObjectData(aasOperation, oper, submodel));
} catch (Throwable ex) {
logger.error("addAasOperation Exception", ex);
}
}
use of de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData 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
* @throws ServiceException If the operation fails
* @throws AddressSpaceException If the operation fails
* @throws ServiceResultException If the operation fails
*/
private void addAasRelationshipElement(UaNode node, RelationshipElement aasRelElem, Submodel submodel, Reference parentRef, boolean ordered) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
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 (Throwable ex) {
logger.error("addAasRelationshipElement Exception", ex);
throw ex;
}
}
use of de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.SubmodelElementData in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method setRangeValueAndType.
/**
* Adds the min and max properties to the UA range object and sets the values
*
* @param aasRange The AAS range object
* @param range The corresponding UA range object
* @param submodel The corresponding submodel
* @param rangeRef The AAS reference to the Range
*/
private void setRangeValueAndType(Range aasRange, AASRangeType range, Submodel submodel, Reference rangeRef) {
try {
String minValue = aasRange.getMin();
String maxValue = aasRange.getMax();
NodeId myPropertyIdMin = new NodeId(getNamespaceIndex(), range.getNodeId().getValue().toString() + "." + AASRangeType.MIN);
NodeId myPropertyIdMax = new NodeId(getNamespaceIndex(), range.getNodeId().getValue().toString() + "." + AASRangeType.MAX);
String valueType = aasRange.getValueType();
QualifiedName browseNameMin = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASRangeType.getNamespaceUri(), AASRangeType.MIN).toQualifiedName(getNamespaceTable());
LocalizedText displayNameMin = LocalizedText.english(AASRangeType.MIN);
QualifiedName browseNameMax = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASRangeType.getNamespaceUri(), AASRangeType.MAX).toQualifiedName(getNamespaceTable());
LocalizedText displayNameMax = LocalizedText.english(AASRangeType.MAX);
submodelElementAasMap.put(myPropertyIdMin, new SubmodelElementData(aasRange, submodel, SubmodelElementData.Type.RANGE_MIN, rangeRef));
submodelElementAasMap.put(myPropertyIdMax, new SubmodelElementData(aasRange, submodel, SubmodelElementData.Type.RANGE_MAX, rangeRef));
submodelElementOpcUAMap.put(rangeRef, range);
TypedValue minTypedValue = TypedValueFactory.create(valueType, minValue);
TypedValue maxTypedValue = TypedValueFactory.create(valueType, maxValue);
AASValueTypeDataType valueDataType;
if (minTypedValue != null) {
valueDataType = ValueConverter.datatypeToValueType(minTypedValue.getDataType());
} else {
valueDataType = ValueConverter.stringToValueType(valueType);
}
range.setValueType(valueDataType);
switch(valueDataType) {
//
case Boolean:
if (minValue != null) {
PlainProperty<Boolean> myBoolProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
myBoolProperty.setDataTypeId(Identifiers.Boolean);
if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
myBoolProperty.setValue(minTypedValue.getValue());
}
myBoolProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myBoolProperty);
}
if (maxValue != null) {
PlainProperty<Boolean> myBoolProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
myBoolProperty.setDataTypeId(Identifiers.Boolean);
if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
myBoolProperty.setValue(maxTypedValue.getValue());
}
myBoolProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myBoolProperty);
}
break;
// break;
case Int32:
if (minValue != null) {
PlainProperty<Integer> myIntProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
myIntProperty.setDataTypeId(Identifiers.Int32);
if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
myIntProperty.setValue(minTypedValue.getValue());
}
myIntProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myIntProperty);
}
if (maxValue != null) {
PlainProperty<Integer> myIntProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
myIntProperty.setDataTypeId(Identifiers.Int32);
if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
myIntProperty.setValue(maxTypedValue.getValue());
}
myIntProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myIntProperty);
}
break;
case Int64:
if (minValue != null) {
PlainProperty<Long> myLongProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
myLongProperty.setDataTypeId(Identifiers.Int64);
if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
Object obj = minTypedValue.getValue();
if (!(obj instanceof Long)) {
obj = Long.parseLong(obj.toString());
}
myLongProperty.setValue(obj);
}
myLongProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myLongProperty);
}
if (maxValue != null) {
PlainProperty<Long> myLongProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
myLongProperty.setDataTypeId(Identifiers.Int64);
if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
Object obj = maxTypedValue.getValue();
if (!(obj instanceof Long)) {
obj = Long.parseLong(obj.toString());
}
myLongProperty.setValue(obj);
}
myLongProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myLongProperty);
}
break;
case Int16:
if (minValue != null) {
PlainProperty<Short> myInt16Property = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
myInt16Property.setDataTypeId(Identifiers.Int16);
if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
myInt16Property.setValue(minTypedValue.getValue());
}
myInt16Property.setDescription(new LocalizedText("", ""));
range.addProperty(myInt16Property);
}
if (maxValue != null) {
PlainProperty<Short> myInt16Property = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
myInt16Property.setDataTypeId(Identifiers.Int16);
if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
myInt16Property.setValue(maxTypedValue.getValue());
}
myInt16Property.setDescription(new LocalizedText("", ""));
range.addProperty(myInt16Property);
}
break;
case SByte:
if (minValue != null) {
PlainProperty<Byte> mySByteProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
mySByteProperty.setDataTypeId(Identifiers.SByte);
if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
mySByteProperty.setValue(minTypedValue.getValue());
}
mySByteProperty.setDescription(new LocalizedText("", ""));
range.addProperty(mySByteProperty);
}
if (maxValue != null) {
PlainProperty<Byte> mySByteProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
mySByteProperty.setDataTypeId(Identifiers.SByte);
if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
mySByteProperty.setValue(maxTypedValue.getValue());
}
mySByteProperty.setDescription(new LocalizedText("", ""));
range.addProperty(mySByteProperty);
}
break;
//
case Double:
if (minValue != null) {
PlainProperty<Double> myDoubleProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
myDoubleProperty.setDataTypeId(Identifiers.Double);
if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
myDoubleProperty.setValue(minTypedValue.getValue());
}
myDoubleProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myDoubleProperty);
}
if (maxValue != null) {
PlainProperty<Double> myDoubleProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
myDoubleProperty.setDataTypeId(Identifiers.Double);
if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
myDoubleProperty.setValue(maxTypedValue.getValue());
}
myDoubleProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myDoubleProperty);
}
break;
case Float:
if (minValue != null) {
PlainProperty<Float> myFloatProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
myFloatProperty.setDataTypeId(Identifiers.Float);
if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
myFloatProperty.setValue(minTypedValue.getValue());
}
myFloatProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myFloatProperty);
}
if (maxValue != null) {
PlainProperty<Float> myFloatProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
myFloatProperty.setDataTypeId(Identifiers.Float);
if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
myFloatProperty.setValue(maxTypedValue.getValue());
}
myFloatProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myFloatProperty);
}
break;
//
case String:
if (minValue != null) {
PlainProperty<String> myStringProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
myStringProperty.setDataTypeId(Identifiers.String);
if ((minTypedValue != null) && (minTypedValue.getValue() != null)) {
myStringProperty.setValue(minTypedValue.getValue());
}
myStringProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myStringProperty);
}
if (maxValue != null) {
PlainProperty<String> myStringProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
myStringProperty.setDataTypeId(Identifiers.String);
if ((maxTypedValue != null) && (maxTypedValue.getValue() != null)) {
myStringProperty.setValue(maxTypedValue.getValue());
}
myStringProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myStringProperty);
}
break;
// break;
default:
logger.warn("setRangeValueAndType: Range " + range.getBrowseName().getName() + ": Unknown type: " + valueType + "; use string as default");
if (minValue != null) {
PlainProperty<String> myStringProperty = new PlainProperty<>(this, myPropertyIdMin, browseNameMin, displayNameMin);
myStringProperty.setDataTypeId(Identifiers.String);
myStringProperty.setValue(minValue);
myStringProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myStringProperty);
}
if (maxValue != null) {
PlainProperty<String> myStringProperty = new PlainProperty<>(this, myPropertyIdMax, browseNameMax, displayNameMax);
myStringProperty.setDataTypeId(Identifiers.String);
myStringProperty.setValue(maxValue);
myStringProperty.setDescription(new LocalizedText("", ""));
range.addProperty(myStringProperty);
}
break;
}
} catch (Throwable ex) {
logger.error("setRangeValueAndType Exception", ex);
}
}
Aggregations