Commit 98708c2e authored by Alfredo Di Napoli's avatar Alfredo Di Napoli

Support exporting of tree hierarchies (with proviso)

Exporting a corpus works, as it also exports its children, but for
example the docs and terms nodes do not have any associated content.
This is because those are stored in separate DB tables, and we need
to find a way to export those as well.
parent c248eaf1
...@@ -34,7 +34,7 @@ import Gargantext.Core (lookupDBid) ...@@ -34,7 +34,7 @@ import Gargantext.Core (lookupDBid)
import Gargantext.Database.Admin.Types.Node import Gargantext.Database.Admin.Types.Node
import Gargantext.Database.Prelude (IsDBCmd) import Gargantext.Database.Prelude (IsDBCmd)
import Gargantext.Database.Query.Table.Node.Error (HasNodeError, nodeError, NodeError (..)) import Gargantext.Database.Query.Table.Node.Error (HasNodeError, nodeError, NodeError (..))
import Gargantext.Database.Query.Table.Node (insertNodeWithHyperdata, getNodes) import Gargantext.Database.Query.Table.Node (insertNodeWithHyperdata, getNodes, getUserRootPrivateNode)
import Gargantext.Database.Schema.Node (NodePoly(..)) import Gargantext.Database.Schema.Node (NodePoly(..))
import Gargantext.Orphans () import Gargantext.Orphans ()
import Prelude import Prelude
...@@ -66,8 +66,11 @@ remoteImportHandler loggedInUser c = do ...@@ -66,8 +66,11 @@ remoteImportHandler loggedInUser c = do
case deserialiseOrFail @ExpectedPayload (B.toLazyByteString $ mconcat chunks) of case deserialiseOrFail @ExpectedPayload (B.toLazyByteString $ mconcat chunks) of
Left err -> throwError $ _BackendInternalError # InternalUnexpectedError (toException $ userError $ "Deserialization error: " ++ show err) Left err -> throwError $ _BackendInternalError # InternalUnexpectedError (toException $ userError $ "Deserialization error: " ++ show err)
Right (TreeN x xs) -> do Right (TreeN x xs) -> do
-- NOTE(adn) By default, we append the imported node(s) to the user's
-- private folder.
privateFolderId <- _node_id <$> getUserRootPrivateNode (_auth_user_id loggedInUser)
-- Attempts to insert nodes a we go along. -- Attempts to insert nodes a we go along.
rootNode <- insertNode Nothing x rootNode <- insertNode (Just privateFolderId) x
foldlM (insertTrees (Just rootNode)) [rootNode] xs foldlM (insertTrees (Just rootNode)) [rootNode] xs
where where
...@@ -113,7 +116,7 @@ checkNodeTypeAllowed n ...@@ -113,7 +116,7 @@ checkNodeTypeAllowed n
-- | At the moment we support only export corpus nodes and their children (i.e. "Docs", "Terms", "Graph"). -- | At the moment we support only export corpus nodes and their children (i.e. "Docs", "Terms", "Graph").
exportableNodeTypes :: [NodeType] exportableNodeTypes :: [NodeType]
exportableNodeTypes = [ NodeCorpus, NodeCorpusV3, NodeTexts, NodeGraph, NodeList ] exportableNodeTypes = [ NodeCorpus, NodeCorpusV3, NodeTexts, NodeGraph, NodeList, NodePhylo ]
streamEncoder :: (MonadIO m, Serialise a) => a -> ConduitT () Named.RemoteBinaryData m () streamEncoder :: (MonadIO m, Serialise a) => a -> ConduitT () Named.RemoteBinaryData m ()
streamEncoder = CL.sourceList . map Named.RemoteBinaryData . BL.toChunks . serialise streamEncoder = CL.sourceList . map Named.RemoteBinaryData . BL.toChunks . serialise
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment