3 Description : Gargantext Import Corpus
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Import a corpus binary.
14 {-# LANGUAGE Strict #-}
18 import Data.Text (Text)
19 import Data.Either (Either(..))
20 import Data.Maybe (Maybe(..))
21 import Gargantext.API.Admin.Settings (withDevEnv, runCmdDev)
22 import Gargantext.API.Prelude (GargError)
23 import Gargantext.API.Node () -- instances only
24 import Gargantext.Core.Types.Individu (User(..))
25 import Gargantext.Database.Action.Flow (getOrMkRoot, getOrMk_RootWithCorpus)
26 import Gargantext.Database.Query.Table.Node (getOrMkList)
27 import Gargantext.Database.Query.Table.User (insertUsersDemo)
28 import Gargantext.Database.Admin.Config (userMaster, corpusMasterName)
29 import Gargantext.Database.Admin.Types.Node
30 import Gargantext.Database.Admin.Trigger.Init (initFirstTriggers, initLastTriggers)
31 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataCorpus)
32 import Gargantext.Database.Admin.Types.Node (CorpusId, RootId, ListId)
33 import Gargantext.Database.Prelude (Cmd, )
34 import Gargantext.Prelude
35 import System.Environment (getArgs)
37 -- TODO put this in gargantext.ini
39 secret = "Database secret to change"
45 let createUsers :: Cmd GargError Int64
46 createUsers = insertUsersDemo
49 mkRoots :: Cmd GargError [(UserId, RootId)]
50 mkRoots = mapM getOrMkRoot $ map UserName ["gargantua", "user1", "user2", "user3"]
51 -- TODO create all users roots
54 initMaster :: Cmd GargError (UserId, RootId, CorpusId, ListId)
56 (masterUserId, masterRootId, masterCorpusId)
57 <- getOrMk_RootWithCorpus (UserName userMaster)
58 (Left corpusMasterName)
59 (Nothing :: Maybe HyperdataCorpus)
60 masterListId <- getOrMkList masterCorpusId masterUserId
61 _triggers <- initLastTriggers masterListId
62 pure (masterUserId, masterRootId, masterCorpusId, masterListId)
64 withDevEnv iniPath $ \env -> do
65 _ <- runCmdDev env (initFirstTriggers secret :: Cmd GargError [Int64])
66 _ <- runCmdDev env createUsers
67 x <- runCmdDev env initMaster
68 _ <- runCmdDev env mkRoots