]> Git — Sourcephile - gargantext.git/blob - bin/gargantext-init/Main.hs
[API] Facto and mkdir Admin
[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 NoImplicitPrelude #-}
15 {-# LANGUAGE OverloadedStrings #-}
16 {-# LANGUAGE FlexibleContexts #-}
17 {-# LANGUAGE RankNTypes #-}
18 {-# LANGUAGE Strict #-}
19
20 module Main where
21
22 import Data.Either (Either(..))
23 import Data.Maybe (Maybe(..))
24 import Gargantext.API.Node () -- instances
25 import Gargantext.API.Admin.Settings (withDevEnv, runCmdDev)
26 import Gargantext.API.Admin.Types (GargError)
27 import Gargantext.Core.Types.Individu (UserId, User(..))
28 import Gargantext.Database.Action.Flow (getOrMkRoot, getOrMk_RootWithCorpus)
29 import Gargantext.Database.Admin.Config (userMaster, corpusMasterName)
30 import Gargantext.Database.Admin.Trigger.Init (initTriggers)
31 import Gargantext.Database.Admin.Types.Node (CorpusId, RootId, HyperdataCorpus, ListId)
32 import Gargantext.Database.Admin.Utils (Cmd, )
33 import Gargantext.Database.Action.Query.Node (getOrMkList)
34 import Gargantext.Database.Action.Query.User (insertUsersDemo)
35 import Gargantext.Prelude
36 import System.Environment (getArgs)
37
38 main :: IO ()
39 main = do
40 [iniPath] <- getArgs
41
42 let createUsers :: Cmd GargError Int64
43 createUsers = insertUsersDemo
44
45 let
46 mkRoots :: Cmd GargError [(UserId, RootId)]
47 mkRoots = mapM getOrMkRoot $ map UserName ["gargantua", "user1", "user2"]
48 -- TODO create all users roots
49
50 let
51 initMaster :: Cmd GargError (UserId, RootId, CorpusId, ListId)
52 initMaster = do
53 (masterUserId, masterRootId, masterCorpusId) <- getOrMk_RootWithCorpus (UserName userMaster) (Left corpusMasterName) (Nothing :: Maybe HyperdataCorpus)
54 masterListId <- getOrMkList masterCorpusId masterUserId
55 _triggers <- initTriggers masterListId
56 pure (masterUserId, masterRootId, masterCorpusId, masterListId)
57
58 withDevEnv iniPath $ \env -> do
59 _ <- runCmdDev env createUsers
60 _ <- runCmdDev env mkRoots
61 x <- runCmdDev env initMaster
62 putStrLn $ show x
63 pure ()