]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/API/Admin/EnvTypes.hs
[Node write upload] Add params
[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.Database.Prelude (HasConnectionPool(..), HasConfig(..))
26 import Gargantext.Prelude
27 import Gargantext.Prelude.Config (GargConfig(..))
28 import Gargantext.Prelude.Mail.Types (MailConfig)
29
30 import qualified Gargantext.Utils.Jobs.Monad as Jobs
31
32 data GargJob
33 = TableNgramsJob
34 | ForgotPasswordJob
35 | UpdateNgramsListJobJSON
36 | UpdateNgramsListJobCSV
37 | AddContactJob
38 | AddFileJob
39 | DocumentFromWriteNodeJob
40 | UpdateNodeJob
41 | UploadFrameCalcJob
42 | UploadDocumentJob
43 | NewNodeJob
44 | AddCorpusQueryJob
45 | AddCorpusFormJob
46 | AddCorpusFileJob
47 | AddAnnuaireFormJob
48 | RecomputeGraphJob
49 deriving (Show, Eq, Ord, Enum, Bounded)
50
51 data Env = Env
52 { _env_settings :: !Settings
53 , _env_logger :: !LoggerSet
54 , _env_pool :: !(Pool Connection)
55 , _env_nodeStory :: !NodeStoryEnv
56 , _env_manager :: !Manager
57 , _env_self_url :: !BaseUrl
58 , _env_scrapers :: !ScrapersEnv
59 , _env_jobs :: !(Jobs.JobEnv GargJob (Dual [JobLog]) JobLog)
60 , _env_config :: !GargConfig
61 , _env_mail :: !MailConfig
62 }
63 deriving (Generic)
64
65 makeLenses ''Env
66
67 instance HasConfig Env where
68 hasConfig = env_config
69
70 instance HasConnectionPool Env where
71 connPool = env_pool
72
73 instance HasNodeStoryEnv Env where
74 hasNodeStory = env_nodeStory
75
76 instance HasNodeStoryVar Env where
77 hasNodeStoryVar = hasNodeStory . nse_getter
78
79 instance HasNodeStorySaver Env where
80 hasNodeStorySaver = hasNodeStory . nse_saver
81
82 instance HasNodeStoryImmediateSaver Env where
83 hasNodeStoryImmediateSaver = hasNodeStory . nse_saver_immediate
84
85 instance HasNodeArchiveStoryImmediateSaver Env where
86 hasNodeArchiveStoryImmediateSaver = hasNodeStory . nse_archive_saver_immediate
87
88 instance HasSettings Env where
89 settings = env_settings
90
91 instance HasMail Env where
92 mailSettings = env_mail
93
94 instance Servant.Job.Core.HasEnv Env (Job JobLog JobLog) where
95 _env = env_scrapers . Servant.Job.Core._env
96
97 instance HasJobEnv Env JobLog JobLog where
98 job_env = env_scrapers
99
100 instance Jobs.MonadJob (ReaderT Env (ExceptT GargError IO)) GargJob (Dual [JobLog]) JobLog where
101 getJobEnv = asks (view env_jobs)
102
103 data MockEnv = MockEnv
104 { _menv_firewall :: !FireWall
105 }
106 deriving (Generic)
107
108 makeLenses ''MockEnv
109
110
111
112 data DevEnv = DevEnv
113 { _dev_env_settings :: !Settings
114 , _dev_env_config :: !GargConfig
115 , _dev_env_pool :: !(Pool Connection)
116 , _dev_env_nodeStory :: !NodeStoryEnv
117 , _dev_env_mail :: !MailConfig
118 }
119
120 makeLenses ''DevEnv
121
122 instance HasConfig DevEnv where
123 hasConfig = dev_env_config
124
125 instance HasConnectionPool DevEnv where
126 connPool = dev_env_pool
127
128 instance HasSettings DevEnv where
129 settings = dev_env_settings
130
131
132 instance HasNodeStoryEnv DevEnv where
133 hasNodeStory = dev_env_nodeStory
134
135 instance HasNodeStoryVar DevEnv where
136 hasNodeStoryVar = hasNodeStory . nse_getter
137
138 instance HasNodeStorySaver DevEnv where
139 hasNodeStorySaver = hasNodeStory . nse_saver
140
141 instance HasNodeStoryImmediateSaver DevEnv where
142 hasNodeStoryImmediateSaver = hasNodeStory . nse_saver_immediate
143
144 instance HasNodeArchiveStoryImmediateSaver DevEnv where
145 hasNodeArchiveStoryImmediateSaver = hasNodeStory . nse_archive_saver_immediate
146
147 instance HasMail DevEnv where
148 mailSettings = dev_env_mail