Commit a11db080 authored by Alexandre Delanoë's avatar Alexandre Delanoë

[DBFLOW] parsing + insertion + insertion duplicatas + delete corpus.

parent cc6f3763
...@@ -31,40 +31,57 @@ authors ...@@ -31,40 +31,57 @@ authors
module Gargantext.Database.Flow module Gargantext.Database.Flow
where where
import System.FilePath (FilePath)
import GHC.Base ((>>)) import GHC.Base ((>>))
import Data.Maybe (Maybe(..)) import Data.Maybe (Maybe(..))
import Gargantext.Core.Types (NodePoly(..)) import Gargantext.Core.Types (NodePoly(..))
import Gargantext.Prelude import Gargantext.Prelude
import Gargantext.Database.Bashql (runCmd') import Gargantext.Database.Bashql (runCmd', del)
import Gargantext.Database.Node (Cmd(..), getRoot, mkRoot) import Gargantext.Database.Node (Cmd(..), getRoot, mkRoot, mkCorpus, defaultCorpus)
import Gargantext.Database.User (getUser, UserLight(..)) import Gargantext.Database.User (getUser, UserLight(..))
import Gargantext.Database.Node.Document.Import (insertDocuments) import Gargantext.Database.Node.Document.Import (insertDocuments)
import Gargantext.Text.Parsers (parseDocs, FileFormat(WOS))
--flow :: IO () --flow :: FilePath -> IO ()
flow = do flow fp = do
masterUser <- runCmd' (getUser "gargantua") masterUser <- runCmd' (getUser "gargantua")
let masterUserId = case masterUser of let masterUserId = case masterUser of
Nothing -> panic "Error: User does not exist (yet)" -- mk NodeUser gargantua_id "Node Gargantua" Nothing -> panic "Error: User does not exist (yet)" -- mk NodeUser gargantua_id "Node Gargantua"
Just user -> userLight_id user Just user -> userLight_id user
root <- map _node_id <$> runCmd' (getRoot masterUserId) rootId' <- map _node_id <$> runCmd' (getRoot masterUserId)
root' <- case root of rootId'' <- case rootId' of
[] -> runCmd' (mkRoot masterUserId) [] -> runCmd' (mkRoot masterUserId)
un -> case length un >= 2 of un -> case length un >= 2 of
True -> panic "Error: more than 1 userNode / user" True -> panic "Error: more than 1 userNode / user"
False -> pure root False -> pure rootId'
let rootId = maybe (panic "error rootId") identity (head rootId'')
printDebug "Root ID : " rootId
corpusId' <- runCmd' $ mkCorpus (Just "Corpus WOS") Nothing rootId masterUserId
let corpusId = maybe (panic "error corpusId") identity (head corpusId')
printDebug "Corpus ID : " corpusId
docs <- parseDocs WOS fp
ids <- runCmd' $ insertDocuments masterUserId corpusId docs
printDebug "Docs IDs : " ids
printDebug "User Node : " root' idsRepeat <- runCmd' $ insertDocuments masterUserId corpusId docs
printDebug "Docs IDs : " idsRepeat
pure () runCmd' (del [corpusId])
{-
{-
--folderId <- mk Folder parentId (Name "Data") (Descr "All corpora DATA here") --folderId <- mk Folder parentId (Name "Data") (Descr "All corpora DATA here")
folderId <- mk Folder rootId "Data" folderId <- mk Folder rootId "Data"
corpusId <- mk Corpus folderId (Name "WOS") (Descr "WOS database description") corpusId <- mk Corpus folderId (Name "WOS") (Descr "WOS database description")
-}
{-
docs <- parseDocuments WOS "doc/.." docs <- parseDocuments WOS "doc/.."
ids <- add (Documents corpusId) docs ids <- add (Documents corpusId) docs
......
...@@ -373,6 +373,9 @@ node2row (Node id tn ud pid nm dt hp) = ((pgInt4 <$> id) ...@@ -373,6 +373,9 @@ node2row (Node id tn ud pid nm dt hp) = ((pgInt4 <$> id)
,(pgStrictJSONB hp) ,(pgStrictJSONB hp)
) )
------------------------------------------------------------------------ ------------------------------------------------------------------------
insertNodesR' :: [NodeWrite'] -> Cmd [Int]
insertNodesR' ns = mkCmd $ \c -> insertNodesR ns c
insertNodes :: [NodeWrite'] -> Connection -> IO Int64 insertNodes :: [NodeWrite'] -> Connection -> IO Int64
insertNodes ns conn = runInsertMany conn nodeTable' (map node2row ns) insertNodes ns conn = runInsertMany conn nodeTable' (map node2row ns)
...@@ -486,3 +489,8 @@ mkRoot :: UserId -> Cmd [Int] ...@@ -486,3 +489,8 @@ mkRoot :: UserId -> Cmd [Int]
mkRoot uId = case uId > 0 of mkRoot uId = case uId > 0 of
False -> panic "UserId <= 0" False -> panic "UserId <= 0"
True -> mk'' NodeUser Nothing uId ("User Node : " <> (pack . show) uId) True -> mk'' NodeUser Nothing uId ("User Node : " <> (pack . show) uId)
mkCorpus :: Maybe Name -> Maybe HyperdataCorpus -> ParentId -> UserId -> Cmd [Int]
mkCorpus n h p u = insertNodesR' [nodeCorpusW n h p u]
...@@ -77,6 +77,7 @@ import qualified Data.Digest.Pure.SHA as SHA (sha256, showDigest) ...@@ -77,6 +77,7 @@ import qualified Data.Digest.Pure.SHA as SHA (sha256, showDigest)
import qualified Data.ByteString.Lazy.Char8 as DC (pack) import qualified Data.ByteString.Lazy.Char8 as DC (pack)
import Gargantext.Database.Config (nodeTypeId) import Gargantext.Database.Config (nodeTypeId)
import Gargantext.Database.Node (mkCmd, Cmd(..))
import Gargantext.Database.Types.Node import Gargantext.Database.Types.Node
-- TODO : the import of Document constructor below does not work -- TODO : the import of Document constructor below does not work
-- import Gargantext.Database.Types.Node (Document) -- import Gargantext.Database.Types.Node (Document)
...@@ -103,8 +104,8 @@ import GHC.Generics (Generic) ...@@ -103,8 +104,8 @@ import GHC.Generics (Generic)
-- | Insert Document main function -- | Insert Document main function
-- UserId : user who is inserting the documents -- UserId : user who is inserting the documents
-- ParentId : folder ID which is parent of the inserted documents -- ParentId : folder ID which is parent of the inserted documents
insertDocuments :: Connection -> UserId -> ParentId -> [HyperdataDocument] -> IO [ReturnId] insertDocuments :: UserId -> ParentId -> [HyperdataDocument] -> Cmd [ReturnId]
insertDocuments conn uId pId hs = query conn queryInsert (Only $ Values fields inputData) insertDocuments uId pId hs = mkCmd $ \c -> query c queryInsert (Only $ Values fields inputData)
where where
fields = map (\t-> QualifiedIdentifier Nothing t) inputSqlTypes fields = map (\t-> QualifiedIdentifier Nothing t) inputSqlTypes
inputData = prepare uId pId hs inputData = prepare uId pId hs
......
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