]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Core/Ext/IMTUser.hs
[NgramsGroup] refact parameters
[gargantext.git] / src / Gargantext / Core / Ext / IMTUser.hs
1 {-|
2 Module : Gargantext.Core.Ext.IMTUser
3 Description : Interface to get IMT users
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 We can not import the IMT Client API code since it is copyrighted.
11 Here is writtent a common interface.
12
13 -}
14
15
16 module Gargantext.Core.Ext.IMTUser (deserialiseImtUsersFromFile)
17 where
18
19 import Codec.Serialise
20 import Data.Maybe (catMaybes)
21 import Data.Text (Text)
22 import GHC.Generics (Generic)
23 import Gargantext.Database.Admin.Types.Hyperdata.Contact
24 import Gargantext.Prelude
25 import System.IO (FilePath)
26 import qualified Data.ByteString.Lazy as BSL
27
28 ------------------------------------------------------------------------
29
30 instance Serialise IMTUser
31
32 deserialiseImtUsersFromFile :: FilePath -> IO [HyperdataContact]
33 deserialiseImtUsersFromFile filepath = map imtUser2gargContact <$> deserialiseFromFile' filepath
34
35 deserialiseFromFile' :: FilePath -> IO [IMTUser]
36 deserialiseFromFile' filepath = deserialise <$> BSL.readFile filepath
37
38 data IMTUser = IMTUser
39 { id :: Text
40 , entite :: Maybe Text
41 , mail :: Maybe Text
42 , nom :: Maybe Text
43 , prenom :: Maybe Text
44 , fonction :: Maybe Text
45 , tel :: Maybe Text
46 , fax :: Maybe Text
47 , service :: Maybe Text
48 , groupe :: Maybe Text
49 , bureau :: Maybe Text
50 , url :: Maybe Text
51 , pservice :: Maybe Text
52 , pfonction :: Maybe Text
53 , afonction :: Maybe Text
54 , grprech :: Maybe Text
55 , lieu :: Maybe Text
56 , aprecision :: Maybe Text
57 , atel :: Maybe Text
58 , sexe :: Maybe Text
59 , statut :: Maybe Text
60 , idutilentite :: Maybe Text
61 , entite2 :: Maybe Text
62 , service2 :: Maybe Text
63 , groupe2 :: Maybe Text
64 , actif :: Maybe Text
65 , idutilsiecoles :: Maybe Text
66 , date_modification :: Maybe Text
67 } deriving (Eq, Show, Generic)
68
69 imtUser2gargContact :: IMTUser -> HyperdataContact
70 imtUser2gargContact (IMTUser id' entite' mail' nom' prenom' fonction' tel' _fax'
71 service' _groupe' bureau' url' _pservice' _pfonction' _afonction'
72 _grprech' lieu' _aprecision' _atel' _sexe' _statut' _idutilentite'
73 _entite2' _service2' _group2' _actif' _idutilsiecoles' date_modification')
74 = HyperdataContact (Just "IMT Annuaire") (Just qui) [ou] ((<>) <$> (fmap (\p -> p <> " ") prenom') <*> nom') entite' date_modification' Nothing Nothing
75 where
76 qui = ContactWho (Just id') prenom' nom' (catMaybes [service']) []
77 ou = ContactWhere (toList entite') (toList service') fonction' bureau' (Just "France") lieu' contact Nothing Nothing
78 contact = Just $ ContactTouch mail' tel' url'
79 -- meta = ContactMetaData (Just "IMT annuaire") date_modification'
80 toList Nothing = []
81 toList (Just x) = [x]
82
83
84