]> Git — Sourcephile - gargantext.git/blob - bin/gargantext-init/Main.hs
merging and ajusting theshold in similarity graph export
[gargantext.git] / bin / gargantext-init / Main.hs
1 {-|
2 Module : Main.hs
3 Description : Gargantext Import Corpus
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 Import a corpus binary.
11
12 -}
13
14 {-# LANGUAGE Strict #-}
15
16 module Main where
17
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
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)
36
37 secret :: Text
38 secret = "Database secret to change"
39
40 main :: IO ()
41 main = do
42 [iniPath] <- getArgs
43
44 let createUsers :: Cmd GargError Int64
45 createUsers = insertUsersDemo
46
47 let
48 mkRoots :: Cmd GargError [(UserId, RootId)]
49 mkRoots = mapM getOrMkRoot $ map UserName ["gargantua", "user1", "user2", "user3"]
50 -- TODO create all users roots
51
52 let
53 initMaster :: Cmd GargError (UserId, RootId, CorpusId, ListId)
54 initMaster = do
55 (masterUserId, masterRootId, masterCorpusId) <- getOrMk_RootWithCorpus (UserName userMaster) (Left corpusMasterName) (Nothing :: Maybe HyperdataCorpus)
56 masterListId <- getOrMkList masterCorpusId masterUserId
57 _triggers <- initLastTriggers masterListId
58 pure (masterUserId, masterRootId, masterCorpusId, masterListId)
59
60 withDevEnv iniPath $ \env -> do
61 _ <- runCmdDev env (initFirstTriggers secret :: Cmd GargError [Int64])
62 _ <- runCmdDev env createUsers
63 x <- runCmdDev env initMaster
64 _ <- runCmdDev env mkRoots
65 putStrLn $ show x
66 pure ()