use of com.prosysopc.ua.types.opcua.server.FileTypeNode in project FAAAST-Service by FraunhoferIOSB.
the class AasServiceNodeManager method addAasFile.
/**
* Adds an AAS file to the given node.
*
* @param node The desired UA node
* @param aasFile The AAS file object
* @param submodel The corresponding Submodel as parent object of the data element
* @param parentRef The AAS reference to the parent node
* @param ordered Specifies whether the file should be added ordered (true) or unordered (false)
* @param nodeName The desired Name of the node. If this value is not set,
* the IdShort of the file is used.
* @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 addAasFile(UaNode node, File aasFile, Submodel submodel, Reference parentRef, boolean ordered, String nodeName) throws StatusException, ServiceException, AddressSpaceException, ServiceResultException {
try {
if ((node != null) && (aasFile != null)) {
String name = aasFile.getIdShort();
if ((nodeName != null) && (!nodeName.isEmpty())) {
name = nodeName;
}
QualifiedName browseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASFileType.getNamespaceUri(), name).toQualifiedName(getNamespaceTable());
NodeId nid = getDefaultNodeId();
AASFileType fileNode = createInstance(AASFileType.class, nid, browseName, LocalizedText.english(name));
addSubmodelElementBaseData(fileNode, aasFile);
// MimeType
if (!aasFile.getMimeType().isEmpty()) {
fileNode.setMimeType(aasFile.getMimeType());
}
// Value
if (aasFile.getValue() != null) {
if (fileNode.getValueNode() == null) {
addFileValueNode(fileNode);
}
fileNode.setValue(aasFile.getValue());
if (!aasFile.getValue().isEmpty()) {
java.io.File f = new java.io.File(aasFile.getValue());
if (!f.exists()) {
logger.warn("addAasFile: File '" + f.getAbsolutePath() + "' does not exist!");
} else {
// File Object: include only when the file exists
QualifiedName fileBrowseName = UaQualifiedName.from(opc.i4aas.ObjectTypeIds.AASFileType.getNamespaceUri(), AASFileType.FILE).toQualifiedName(getNamespaceTable());
NodeId fileId = new NodeId(getNamespaceIndex(), fileNode.getNodeId().getValue().toString() + "." + AASFileType.FILE);
FileTypeNode fileType = createInstance(FileTypeNode.class, fileId, fileBrowseName, LocalizedText.english(AASFileType.FILE));
fileType.setFile(new java.io.File(aasFile.getValue()));
fileType.setWritable(false);
fileType.setUserWritable(false);
if (fileType.getNodeVersion() != null) {
fileType.getNodeVersion().setDescription(new LocalizedText("", ""));
}
fileNode.addReference(fileType, Identifiers.HasAddIn, false);
}
}
}
if (ordered) {
node.addReference(fileNode, Identifiers.HasOrderedComponent, false);
} else {
node.addComponent(fileNode);
}
if (parentRef != null) {
Reference fileRef = AasUtils.toReference(parentRef, aasFile);
referableMap.put(fileRef, new ObjectData(aasFile, fileNode, submodel));
}
}
} catch (Throwable ex) {
logger.error("addAasFile Exception", ex);
throw ex;
}
}
Aggregations