private DocRef importExplorerDoc(final ImportExportActionHandler importExportActionHandler,
                                     final Path nodeFile,
                                     final DocRef docRef,
                                     final Set<String> tags,
                                     final String path,
                                     final Map<String, byte[]> dataMap,
                                     final ImportState importState,
                                     final Map<DocRef, ImportState> confirmMap,
                                     final ImportSettings importSettings) {

        // This shows where the thing is in the Explorer Tree
        // Uses the importSettings.getRootDocRef() to work out where to put things
        final DocRef importRootDocRef = importSettings.getRootDocRef();
        final String importPath = resolvePath(path, importRootDocRef);

        String destPath = importPath;
        String destName = docRef.getName();

        // See if we have an existing node for this item.
        final Optional<ExplorerNode> existingNode = explorerNodeService.getNode(docRef);
        final boolean docExists = existingNode.isPresent();
        boolean moving = false;

        if (docExists) {
            // This is a pre-existing item so make sure we are allowed to update it.
            if (!securityContext.hasDocumentPermission(docRef,
                                                       DocumentPermission.EDIT)) {
                throw new PermissionException(securityContext.getUserRef(),
                        "You do not have permission to update '" + docRef + "'");
            }

            importState.setState(State.UPDATE);
            final List<ExplorerNode> parents = explorerNodeService.getPath(docRef);
            final String currentPath = getParentPath(parents);
            if (!importSettings.isUseImportNames()) {
                destName = existingNode.get().getName();
            }
            if (!importSettings.isUseImportFolders()) {
                destPath = currentPath;
            }
            if (!destPath.equals(currentPath)) {
                moving = true;
            }
        } else {
            importState.setState(State.NEW);
        }
        importState.setDestPath(createPath(destPath, destName));

        // If we are creating a new node or moving an existing one then create the destination folders and check
        // permissions.
        DocRef folderRef = null;
        ExplorerNode parentNode = null;
        if (importState.getState() == State.NEW || moving) {
            // Create parent folders for the new node.
            final ExplorerNode parent = explorerNodeService.getRoot();
            parentNode = getOrCreateParentFolder(parent,
                                                 importPath,
                                                 ImportSettings.ok(importSettings, importState));

            // Check permissions on the parent folder.
            folderRef = new DocRef(parentNode.getType(), parentNode.getUuid(), parentNode.getName());
            if (!securityContext.hasDocumentCreatePermission(folderRef, docRef.getType())) {
                throw new PermissionException(securityContext.getUserRef(),
                        "You do not have permission to create '" + docRef + "' in '" + folderRef);
            }
        }

        try {
            // Import the item via the appropriate handler.
            if (importExportActionHandler != null && (
                    ImportMode.CREATE_CONFIRMATION.equals(importSettings.getImportMode()) ||
                    ImportMode.IGNORE_CONFIRMATION.equals(importSettings.getImportMode()) ||
                    importState.isAction())) {

                final DocRef imported = importExportActionHandler.importDocument(
                        docRef,
                        dataMap,
                        importState,
                        importSettings);

                if (imported == null) {
                    throw new RuntimeException("Import failed - no DocRef returned");
                }

                // Add explorer node afterwards on successful import as they won't be controlled by
                // doc service.
                if (ImportSettings.ok(importSettings, importState)) {
                    final ExplorerNode explorerNode = ExplorerNode
                            .builder()
                            .docRef(docRef)
                            .build();

                    // Create, rename and/or move explorer node.
                    if (existingNode.isEmpty()) {
                        explorerNodeService.createNode(
                                imported,
                                folderRef,
                                PermissionInheritance.DESTINATION);
                        explorerService.rebuildTree();
                    } else {
                        if (importSettings.isUseImportNames()) {
                            explorerService.rename(explorerNode, docRef.getName());
                        }
                        if (moving) {
                            explorerService.move(
                                    Collections.singletonList(explorerNode),
                                    parentNode,
                                    PermissionInheritance.DESTINATION);
                        }
                    }

                    importExportDocumentEventLog.importDocument(
                            docRef.getType(),
                            imported.getUuid(),
                            docRef.getName(),
                            null);
                }
            } else {
                // We can't import this item so remove it from the map.
                confirmMap.remove(docRef);
            }
        } catch (final RuntimeException e) {
            importState.addMessage(Severity.ERROR, e.getMessage());
            LOGGER.error("Error importing file {}", nodeFile.toAbsolutePath(), e);
            importExportDocumentEventLog.importDocument(docRef.getType(),
                    docRef.getUuid(),
                    docRef.getName(),
                    e);
            throw e;
        }

        return docRef;
    }
Imports something that appears in the Explorer Tree.
@param importExportActionHandler Handler for the type of DocRef
@param nodeFile Path to the import file on disk
@param docRef DocRef created from the .node data on disk
@param tags List of tags extracted from .node data on disk
@param path Path to the item in the Explorer Tree, from the .node data
            on disk
@param dataMap Map of disk file extension to disk file contents
@param importState State of the import for docRef
@param confirmMap Accessed to remove docRef from the map if the docRef
                  cannot be imported.
@param importSettings Key settings for the import; notably the RootDocRef.
@return The DocRef of the imported document.
stroom-importexport/stroom-importexport-impl/src/main/java/stroom/importexport/impl/ImportExportSerializerImpl.java