]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Ext/IMTUser.hs
[DEMO] adapting Contact Type.
[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
23 import System.IO (FilePath)
24 import Codec.Serialise
25 import Data.Maybe (Maybe, catMaybes)
26 import Data.Text (Text)
27 import GHC.Generics (Generic)
28 import Gargantext.Prelude
29
30 import Gargantext.Database.Node.Contact -- (HyperdataContact, ContactWho, ContactWhere, ContactTouch, ContactMetaData)
31 import qualified Data.ByteString.Lazy as BSL
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 serialiseToFile :: FilePath -> [IMTUser] -> IO ()
42 serialiseToFile f d = BSL.writeFile f (serialise d)
43
44 data IMTUser = IMTUser
45 { id :: Text
46 , entite :: Maybe Text
47 , mail :: Maybe Text
48 , nom :: Maybe Text
49 , prenom :: Maybe Text
50 , fonction :: Maybe Text
51 , tel :: Maybe Text
52 , fax :: Maybe Text
53 , service :: Maybe Text
54 , groupe :: Maybe Text
55 , bureau :: Maybe Text
56 , url :: Maybe Text
57 , pservice :: Maybe Text
58 , pfonction :: Maybe Text
59 , afonction :: Maybe Text
60 , grprech :: Maybe Text
61 , lieu :: Maybe Text
62 , aprecision :: Maybe Text
63 , atel :: Maybe Text
64 , sexe :: Maybe Text
65 , statut :: Maybe Text
66 , idutilentite :: Maybe Text
67 , entite2 :: Maybe Text
68 , service2 :: Maybe Text
69 , groupe2 :: Maybe Text
70 , actif :: Maybe Text
71 , idutilsiecoles :: Maybe Text
72 , date_modification :: Maybe Text
73 } deriving (Eq, Show, Generic)
74
75 imtUser2gargContact :: IMTUser -> HyperdataContact
76 imtUser2gargContact (IMTUser id' entite' mail' nom' prenom' fonction' tel' _fax'
77 service' _groupe' bureau' url' _pservice' _pfonction' _afonction'
78 _grprech' lieu' _aprecision' _atel' _sexe' _statut' _idutilentite'
79 _entite2' _service2' _group2' _actif' _idutilsiecoles' date_modification')
80 = HyperdataContact (Just qui) (Just [ou]) (Just meta) ((<>) <$> prenom' <*> nom') entite' Nothing Nothing
81 where
82 qui = ContactWho (Just id') prenom' nom' (Just $ catMaybes [service']) Nothing
83 ou = ContactWhere (toList entite') (toList service') fonction' bureau' (Just "France") lieu' contact Nothing Nothing
84 contact = Just $ ContactTouch mail' tel' url'
85 meta = ContactMetaData (Just "IMT annuaire") date_modification'
86 toList Nothing = Nothing
87 toList (Just x) = Just [x]
88
89
90