]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Admin/EnvTypes.hs
[NLP] implement NLP server selection in INI file
[gargantext.git] / src / Gargantext / API / Admin / EnvTypes.hs
1 -- |
2
3 {-# LANGUAGE TemplateHaskell #-}
4
5 module Gargantext.API.Admin.EnvTypes where
6
7 import Control.Lens
8 import Control.Monad.Except
9 import Control.Monad.Reader
10 import Data.Monoid
11 import Data.Pool (Pool)
12 import Database.PostgreSQL.Simple (Connection)
13 import GHC.Generics (Generic)
14 import Network.HTTP.Client (Manager)
15 import Servant.Client (BaseUrl)
16 import Servant.Job.Async (HasJobEnv(..), Job)
17 import System.Log.FastLogger
18 import qualified Servant.Job.Core
19
20 import Gargantext.API.Admin.Types
21 import Gargantext.API.Admin.Orchestrator.Types
22 import Gargantext.API.Prelude (GargError)
23 import Gargantext.Core.NodeStory
24 import Gargantext.Core.Mail.Types (HasMail, mailSettings)
25 import Gargantext.Core.NLP (NLPServerMap, HasNLPServer(..))
26 import Gargantext.Database.Prelude (HasConnectionPool(..), HasConfig(..))
27 import Gargantext.Prelude
28 import Gargantext.Prelude.Config (GargConfig(..))
29 import Gargantext.Prelude.Mail.Types (MailConfig)
30
31 import qualified Gargantext.Utils.Jobs.Monad as Jobs
32
33 data GargJob
34 = TableNgramsJob
35 | ForgotPasswordJob
36 | UpdateNgramsListJobJSON
37 | UpdateNgramsListJobCSV
38 | AddContactJob
39 | AddFileJob
40 | DocumentFromWriteNodeJob
41 | UpdateNodeJob
42 | UploadFrameCalcJob
43 | UploadDocumentJob
44 | NewNodeJob
45 | AddCorpusQueryJob
46 | AddCorpusFormJob
47 | AddCorpusFileJob
48 | AddAnnuaireFormJob
49 | RecomputeGraphJob
50 deriving (Show, Eq, Ord, Enum, Bounded)
51
52 data Env = Env
53 { _env_settings :: !Settings
54 , _env_logger :: !LoggerSet
55 , _env_pool :: !(Pool Connection)
56 , _env_nodeStory :: !NodeStoryEnv
57 , _env_manager :: !Manager
58 , _env_self_url :: !BaseUrl
59 , _env_scrapers :: !ScrapersEnv
60 , _env_jobs :: !(Jobs.JobEnv GargJob (Dual [JobLog]) JobLog)
61 , _env_config :: !GargConfig
62 , _env_mail :: !MailConfig
63 , _env_nlp :: !NLPServerMap
64 }
65 deriving (Generic)
66
67 makeLenses ''Env
68
69 instance HasConfig Env where
70 hasConfig = env_config
71
72 instance HasConnectionPool Env where
73 connPool = env_pool
74
75 instance HasNodeStoryEnv Env where
76 hasNodeStory = env_nodeStory
77
78 instance HasNodeStoryVar Env where
79 hasNodeStoryVar = hasNodeStory . nse_getter
80
81 instance HasNodeStorySaver Env where
82 hasNodeStorySaver = hasNodeStory . nse_saver
83
84 instance HasNodeStoryImmediateSaver Env where
85 hasNodeStoryImmediateSaver = hasNodeStory . nse_saver_immediate
86
87 instance HasNodeArchiveStoryImmediateSaver Env where
88 hasNodeArchiveStoryImmediateSaver = hasNodeStory . nse_archive_saver_immediate
89
90 instance HasSettings Env where
91 settings = env_settings
92
93 instance HasMail Env where
94 mailSettings = env_mail
95
96 instance HasNLPServer Env where
97 nlpServer = env_nlp
98
99 instance Servant.Job.Core.HasEnv Env (Job JobLog JobLog) where
100 _env = env_scrapers . Servant.Job.Core._env
101
102 instance HasJobEnv Env JobLog JobLog where
103 job_env = env_scrapers
104
105 instance Jobs.MonadJob (ReaderT Env (ExceptT GargError IO)) GargJob (Dual [JobLog]) JobLog where
106 getJobEnv = asks (view env_jobs)
107
108 data MockEnv = MockEnv
109 { _menv_firewall :: !FireWall
110 }
111 deriving (Generic)
112
113 makeLenses ''MockEnv
114
115
116
117 data DevEnv = DevEnv
118 { _dev_env_settings :: !Settings
119 , _dev_env_config :: !GargConfig
120 , _dev_env_pool :: !(Pool Connection)
121 , _dev_env_nodeStory :: !NodeStoryEnv
122 , _dev_env_mail :: !MailConfig
123 , _dev_env_nlp :: !NLPServerMap
124 }
125
126 makeLenses ''DevEnv
127
128 instance HasConfig DevEnv where
129 hasConfig = dev_env_config
130
131 instance HasConnectionPool DevEnv where
132 connPool = dev_env_pool
133
134 instance HasSettings DevEnv where
135 settings = dev_env_settings
136
137
138 instance HasNodeStoryEnv DevEnv where
139 hasNodeStory = dev_env_nodeStory
140
141 instance HasNodeStoryVar DevEnv where
142 hasNodeStoryVar = hasNodeStory . nse_getter
143
144 instance HasNodeStorySaver DevEnv where
145 hasNodeStorySaver = hasNodeStory . nse_saver
146
147 instance HasNodeStoryImmediateSaver DevEnv where
148 hasNodeStoryImmediateSaver = hasNodeStory . nse_saver_immediate
149
150 instance HasNodeArchiveStoryImmediateSaver DevEnv where
151 hasNodeArchiveStoryImmediateSaver = hasNodeStory . nse_archive_saver_immediate
152
153 instance HasMail DevEnv where
154 mailSettings = dev_env_mail
155
156 instance HasNLPServer DevEnv where
157 nlpServer = dev_env_nlp