Search in sources :

Example 1 with AASFileType

use of opc.i4aas.AASFileType 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;
    }
}
Also used : AASFileType(opc.i4aas.AASFileType) Reference(io.adminshell.aas.v3.model.Reference) DefaultReference(io.adminshell.aas.v3.model.impl.DefaultReference) UaQualifiedName(com.prosysopc.ua.UaQualifiedName) QualifiedName(com.prosysopc.ua.stack.builtintypes.QualifiedName) ObjectData(de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData) ByteString(com.prosysopc.ua.stack.builtintypes.ByteString) LangString(io.adminshell.aas.v3.model.LangString) LocalizedText(com.prosysopc.ua.stack.builtintypes.LocalizedText) NodeId(com.prosysopc.ua.stack.builtintypes.NodeId) FileTypeNode(com.prosysopc.ua.types.opcua.server.FileTypeNode) File(io.adminshell.aas.v3.model.File)

Aggregations

UaQualifiedName (com.prosysopc.ua.UaQualifiedName)1 ByteString (com.prosysopc.ua.stack.builtintypes.ByteString)1 LocalizedText (com.prosysopc.ua.stack.builtintypes.LocalizedText)1 NodeId (com.prosysopc.ua.stack.builtintypes.NodeId)1 QualifiedName (com.prosysopc.ua.stack.builtintypes.QualifiedName)1 FileTypeNode (com.prosysopc.ua.types.opcua.server.FileTypeNode)1 ObjectData (de.fraunhofer.iosb.ilt.faaast.service.endpoint.opcua.data.ObjectData)1 File (io.adminshell.aas.v3.model.File)1 LangString (io.adminshell.aas.v3.model.LangString)1 Reference (io.adminshell.aas.v3.model.Reference)1 DefaultReference (io.adminshell.aas.v3.model.impl.DefaultReference)1 AASFileType (opc.i4aas.AASFileType)1