]> Git — Sourcephile - gargantext.git/blob - bin/gargantext-init/Main.hs
New similarity measure for inter-temporal matching added named WeightedLogSim Adapted...
[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 Gargantext.API.Dev (withDevEnv, runCmdDev)
21 import Gargantext.API.Prelude (GargError)
22 import Gargantext.API.Node () -- instances only
23 import Gargantext.Core.Types.Individu (User(..))
24 import Gargantext.Database.Action.Flow (getOrMkRoot, getOrMk_RootWithCorpus)
25 import Gargantext.Database.Query.Table.Node (getOrMkList)
26 import Gargantext.Database.Query.Table.User (insertUsersDemo)
27 import Gargantext.Database.Admin.Config (userMaster, corpusMasterName)
28 import Gargantext.Database.Admin.Types.Node
29 import Gargantext.Database.Admin.Trigger.Init (initFirstTriggers, initLastTriggers)
30 import Gargantext.Database.Admin.Types.Hyperdata (HyperdataCorpus)
31 import Gargantext.Database.Prelude (Cmd, )
32 import Gargantext.Prelude
33 import System.Environment (getArgs)
34
35 -- TODO put this in gargantext.ini
36 secret :: Text
37 secret = "Database secret to change"
38
39 main :: IO ()
40 main = do
41 [iniPath] <- getArgs
42
43 let createUsers :: Cmd GargError Int64
44 createUsers = insertUsersDemo
45
46 let
47 mkRoots :: Cmd GargError [(UserId, RootId)]
48 mkRoots = mapM getOrMkRoot $ map UserName ["gargantua", "user1", "user2", "user3"]
49 -- TODO create all users roots
50
51 let
52 initMaster :: Cmd GargError (UserId, RootId, CorpusId, ListId)
53 initMaster = do
54 (masterUserId, masterRootId, masterCorpusId)
55 <- getOrMk_RootWithCorpus (UserName userMaster)
56 (Left corpusMasterName)
57 (Nothing :: Maybe HyperdataCorpus)
58 masterListId <- getOrMkList masterCorpusId masterUserId
59 _triggers <- initLastTriggers masterListId
60 pure (masterUserId, masterRootId, masterCorpusId, masterListId)
61
62 withDevEnv iniPath $ \env -> do
63 _ <- runCmdDev env (initFirstTriggers secret :: Cmd GargError [Int64])
64 _ <- runCmdDev env createUsers
65 x <- runCmdDev env initMaster
66 _ <- runCmdDev env mkRoots
67 putStrLn $ show x
68 pure ()