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
10 We can not import the IMT Client API code since it is copyrighted.
11 Here is writtent a common interface.
15 {-# LANGUAGE NoImplicitPrelude #-}
16 {-# LANGUAGE OverloadedStrings #-}
17 {-# LANGUAGE DeriveGeneric #-}
19 module Gargantext.Ext.IMTUser (deserialiseImtUsersFromFile)
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
31 ------------------------------------------------------------------------
33 instance Serialise IMTUser
35 deserialiseImtUsersFromFile :: FilePath -> IO [HyperdataContact]
36 deserialiseImtUsersFromFile filepath = map imtUser2gargContact <$> deserialiseFromFile' filepath
38 deserialiseFromFile' :: FilePath -> IO [IMTUser]
39 deserialiseFromFile' filepath = deserialise <$> BSL.readFile filepath
41 data IMTUser = IMTUser
43 , entite :: Maybe Text
46 , prenom :: Maybe Text
47 , fonction :: Maybe Text
50 , service :: Maybe Text
51 , groupe :: Maybe Text
52 , bureau :: Maybe Text
54 , pservice :: Maybe Text
55 , pfonction :: Maybe Text
56 , afonction :: Maybe Text
57 , grprech :: Maybe Text
59 , aprecision :: Maybe Text
62 , statut :: Maybe Text
63 , idutilentite :: Maybe Text
64 , entite2 :: Maybe Text
65 , service2 :: Maybe Text
66 , groupe2 :: Maybe Text
68 , idutilsiecoles :: Maybe Text
69 , date_modification :: Maybe Text
70 } deriving (Eq, Show, Generic)
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
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'