]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Ext/IMTUser.hs
[FIX] removing template haskell
[gargantext.git] / src / Gargantext / Ext / IMTUser.hs
1 {-|
2 Module : Gargantext.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 {-# LANGUAGE NoImplicitPrelude #-}
16 {-# LANGUAGE OverloadedStrings #-}
17 {-# LANGUAGE DeriveGeneric #-}
18
19 module Gargantext.Ext.IMTUser (deserialiseImtUsersFromFile)
20 where
21
22 import Codec.Serialise
23 import Data.Maybe (Maybe, catMaybes)
24 import Data.Text (Text)
25 import GHC.Generics (Generic)
26 import Gargantext.Database.Query.Table.Node.Contact -- (HyperdataContact, ContactWho, ContactWhere, ContactTouch, ContactMetaData)
27 import Gargantext.Prelude
28 import System.IO (FilePath)
29 import qualified Data.ByteString.Lazy as BSL
30
31 ------------------------------------------------------------------------
32
33 instance Serialise IMTUser
34
35 deserialiseImtUsersFromFile :: FilePath -> IO [HyperdataContact]
36 deserialiseImtUsersFromFile filepath = map imtUser2gargContact <$> deserialiseFromFile' filepath
37
38 deserialiseFromFile' :: FilePath -> IO [IMTUser]
39 deserialiseFromFile' filepath = deserialise <$> BSL.readFile filepath
40
41 data IMTUser = IMTUser
42 { id :: Text
43 , entite :: Maybe Text
44 , mail :: Maybe Text
45 , nom :: Maybe Text
46 , prenom :: Maybe Text
47 , fonction :: Maybe Text
48 , tel :: Maybe Text
49 , fax :: Maybe Text
50 , service :: Maybe Text
51 , groupe :: Maybe Text
52 , bureau :: Maybe Text
53 , url :: Maybe Text
54 , pservice :: Maybe Text
55 , pfonction :: Maybe Text
56 , afonction :: Maybe Text
57 , grprech :: Maybe Text
58 , lieu :: Maybe Text
59 , aprecision :: Maybe Text
60 , atel :: Maybe Text
61 , sexe :: Maybe Text
62 , statut :: Maybe Text
63 , idutilentite :: Maybe Text
64 , entite2 :: Maybe Text
65 , service2 :: Maybe Text
66 , groupe2 :: Maybe Text
67 , actif :: Maybe Text
68 , idutilsiecoles :: Maybe Text
69 , date_modification :: Maybe Text
70 } deriving (Eq, Show, Generic)
71
72 imtUser2gargContact :: IMTUser -> HyperdataContact
73 imtUser2gargContact (IMTUser id' entite' mail' nom' prenom' fonction' tel' _fax'
74 service' _groupe' bureau' url' _pservice' _pfonction' _afonction'
75 _grprech' lieu' _aprecision' _atel' _sexe' _statut' _idutilentite'
76 _entite2' _service2' _group2' _actif' _idutilsiecoles' date_modification')
77 = HyperdataContact (Just "IMT Annuaire") (Just qui) [ou] ((<>) <$> (fmap (\p -> p <> " ") prenom') <*> nom') entite' date_modification' Nothing Nothing
78 where
79 qui = ContactWho (Just id') prenom' nom' (catMaybes [service']) []
80 ou = ContactWhere (toList entite') (toList service') fonction' bureau' (Just "France") lieu' contact Nothing Nothing
81 contact = Just $ ContactTouch mail' tel' url'
82 -- meta = ContactMetaData (Just "IMT annuaire") date_modification'
83 toList Nothing = []
84 toList (Just x) = [x]
85
86
87