protected DocumentModel doCreateLeafNode(DocumentModel parent, SourceNode node)
      throws IOException {
    if (!shouldImportDocument(node)) {
      return null;
    }
    Stopwatch stopwatch = SimonManager.getStopwatch("org.nuxeo.ecm.platform.importer.create_leaf");
    Split split = stopwatch.start();
    DocumentModel leaf = null;
    try {
      leaf = getFactory().createLeafNode(session, parent, node);
    } catch (IOException e) {
      String errMsg =
          "Unable to create leaf document for "
              + node.getSourcePath()
              + ":"
              + e
              + (e.getCause() != null ? e.getCause() : "");
      fslog(errMsg, true);
      log.error(errMsg);
      // Process leaf node creation error and check if the global
      // import task should continue
      boolean shouldImportTaskContinue =
          getFactory().processLeafNodeCreationError(session, parent, node);
      if (!shouldImportTaskContinue) {
        throw new NuxeoException(e);
      }
    } finally {
      split.stop();
    }
    BlobHolder bh = node.getBlobHolder();
    if (leaf != null && bh != null) {
      Blob blob = bh.getBlob();
      if (blob != null) {
        long fileSize = blob.getLength();
        String fileName = blob.getFilename();
        if (fileSize > 0) {
          long kbSize = fileSize / 1024;
          String parentPath = (parent == null) ? "null" : parent.getPathAsString();
          fslog(
              "Created doc "
                  + leaf.getName()
                  + " at "
                  + parentPath
                  + " with file "
                  + fileName
                  + " of size "
                  + kbSize
                  + "KB",
              true);
        }
        uploadedKO += fileSize;
      }

      // save session if needed
      commit();
    }
    return leaf;
  }
  protected DocumentModel doCreateFolderishNode(DocumentModel parent, SourceNode node) {
    if (!shouldImportDocument(node)) {
      return null;
    }
    Stopwatch stopwatch =
        SimonManager.getStopwatch("org.nuxeo.ecm.platform.importer.create_folder");
    Split split = stopwatch.start();
    DocumentModel folder = null;
    try {
      folder = getFactory().createFolderishNode(session, parent, node);
    } catch (IOException e) {
      String errorMsg =
          "Unable to create folderish document for "
              + node.getSourcePath()
              + ":"
              + e
              + (e.getCause() != null ? e.getCause() : "");
      fslog(errorMsg, true);
      log.error(errorMsg);
      // Process folderish node creation error and check if the global
      // import task should continue
      boolean shouldImportTaskContinue =
          getFactory().processFolderishNodeCreationError(session, parent, node);
      if (!shouldImportTaskContinue) {
        throw new NuxeoException(e);
      }
    } finally {
      split.stop();
    }
    if (folder != null) {
      String parentPath = (parent == null) ? "null" : parent.getPathAsString();
      fslog("Created Folder " + folder.getName() + " at " + parentPath, true);

      // save session if needed
      commit();
    }
    return folder;
  }
  protected void commit(boolean force) {
    uploadedFiles++;
    if (uploadedFiles % 10 == 0) {
      GenericMultiThreadedImporter.addCreatedDoc(taskId, uploadedFiles);
    }

    if (uploadedFiles % batchSize == 0 || force) {
      Stopwatch stopwatch =
          SimonManager.getStopwatch("org.nuxeo.ecm.platform.importer.session_save");
      Split split = stopwatch.start();
      fslog("Committing Core Session after " + uploadedFiles + " files", true);
      session.save();
      TransactionHelper.commitOrRollbackTransaction();
      TransactionHelper.startTransaction(transactionTimeout);
      split.stop();
    }
  }