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)
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
30 import Gargantext.Database.Node.Contact -- (HyperdataContact, ContactWho, ContactWhere, ContactTouch, ContactMetaData)
31 import qualified Data.ByteString.Lazy as BSL
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 serialiseToFile :: FilePath -> [IMTUser] -> IO ()
42 serialiseToFile f d = BSL.writeFile f (serialise d)
44 data IMTUser = IMTUser
46 , entite :: Maybe Text
49 , prenom :: Maybe Text
50 , fonction :: Maybe Text
53 , service :: Maybe Text
54 , groupe :: Maybe Text
55 , bureau :: Maybe Text
57 , pservice :: Maybe Text
58 , pfonction :: Maybe Text
59 , afonction :: Maybe Text
60 , grprech :: Maybe Text
62 , aprecision :: Maybe Text
65 , statut :: Maybe Text
66 , idutilentite :: Maybe Text
67 , entite2 :: Maybe Text
68 , service2 :: Maybe Text
69 , groupe2 :: Maybe Text
71 , idutilsiecoles :: Maybe Text
72 , date_modification :: Maybe Text
73 } deriving (Eq, Show, Generic)
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
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]