[epo] add proxy api integration

parent dac56414
...@@ -6,7 +6,6 @@ with-compiler: ghc-8.10.7 ...@@ -6,7 +6,6 @@ with-compiler: ghc-8.10.7
packages: packages:
./ ./
../openalex
source-repository-package source-repository-package
type: git type: git
...@@ -82,6 +81,11 @@ source-repository-package ...@@ -82,6 +81,11 @@ source-repository-package
location: https://gitlab.iscpif.fr/gargantext/crawlers/arxiv-api.git location: https://gitlab.iscpif.fr/gargantext/crawlers/arxiv-api.git
tag: eb130c71fa17adaceed6ff66beefbccb13df51ba tag: eb130c71fa17adaceed6ff66beefbccb13df51ba
source-repository-package
type: git
location: https://gitlab.iscpif.fr/gargantext/crawlers/epo-proxy-api.git
tag: 9225d046083853200b9045c8d71161e6a234fc5c
source-repository-package source-repository-package
type: git type: git
location: https://gitlab.iscpif.fr/gargantext/crawlers/hal.git location: https://gitlab.iscpif.fr/gargantext/crawlers/hal.git
...@@ -97,11 +101,6 @@ source-repository-package ...@@ -97,11 +101,6 @@ source-repository-package
location: https://gitlab.iscpif.fr/gargantext/iso639.git location: https://gitlab.iscpif.fr/gargantext/iso639.git
tag: 1a9e23e210a02da3b846d7cdc666541e2148334d tag: 1a9e23e210a02da3b846d7cdc666541e2148334d
source-repository-package
type: git
location: https://gitlab.iscpif.fr/gargantext/crawlers/epo-proxy-api.git
tag: eae89b09f4ce46cd3db836d5c580ac90073de7ba
source-repository-package source-repository-package
type: git type: git
location: https://gitlab.iscpif.fr/gargantext/crawlers/istex.git location: https://gitlab.iscpif.fr/gargantext/crawlers/istex.git
...@@ -110,7 +109,7 @@ source-repository-package ...@@ -110,7 +109,7 @@ source-repository-package
source-repository-package source-repository-package
type: git type: git
location: https://gitlab.iscpif.fr/gargantext/crawlers/openalex.git location: https://gitlab.iscpif.fr/gargantext/crawlers/openalex.git
tag: 1cf872fb3bd0e3e44af31247833c4b6bb7d0dca5 tag: a46abe16700449a1f863deb89380b05d89ad9723
source-repository-package source-repository-package
type: git type: git
...@@ -125,7 +124,7 @@ source-repository-package ...@@ -125,7 +124,7 @@ source-repository-package
source-repository-package source-repository-package
type: git type: git
location: https://gitlab.iscpif.fr/gargantext/haskell-gargantext-prelude location: https://gitlab.iscpif.fr/gargantext/haskell-gargantext-prelude
tag: 40135d166830690b1101180b79e9fd3663284b2b tag: 9b33568da92f92bfa89c8bd8f05b07b70fd021f9
source-repository-package source-repository-package
type: git type: git
......
...@@ -50,10 +50,11 @@ get :: ExternalAPIs ...@@ -50,10 +50,11 @@ get :: ExternalAPIs
-> Corpus.RawQuery -> Corpus.RawQuery
-> Maybe PUBMED.APIKey -> Maybe PUBMED.APIKey
-> Maybe EPO.AuthKey -> Maybe EPO.AuthKey
-> Text
-> Maybe Corpus.Limit -> Maybe Corpus.Limit
-- -> IO [HyperdataDocument] -- -> IO [HyperdataDocument]
-> IO (Either GetCorpusError (Maybe Integer, ConduitT () HyperdataDocument IO ())) -> IO (Either GetCorpusError (Maybe Integer, ConduitT () HyperdataDocument IO ()))
get externalAPI la q mPubmedAPIKey epoAuthKey limit = do get externalAPI la q mPubmedAPIKey epoAuthKey epoAPIUrl limit = do
-- For PUBMED, HAL, IsTex, Isidore and OpenAlex, we want to send the query as-it. -- For PUBMED, HAL, IsTex, Isidore and OpenAlex, we want to send the query as-it.
-- For Arxiv we parse the query into a structured boolean query we submit over. -- For Arxiv we parse the query into a structured boolean query we submit over.
case externalAPI of case externalAPI of
...@@ -73,6 +74,6 @@ get externalAPI la q mPubmedAPIKey epoAuthKey limit = do ...@@ -73,6 +74,6 @@ get externalAPI la q mPubmedAPIKey epoAuthKey limit = do
docs <- ISIDORE.get la (Corpus.getLimit <$> limit) (Just $ Corpus.getRawQuery q) Nothing docs <- ISIDORE.get la (Corpus.getLimit <$> limit) (Just $ Corpus.getRawQuery q) Nothing
pure $ Right (Just $ fromIntegral $ length docs, yieldMany docs) pure $ Right (Just $ fromIntegral $ length docs, yieldMany docs)
EPO -> do EPO -> do
first ExternalAPIError <$> EPO.get epoAuthKey q (toISO639EN la) limit first ExternalAPIError <$> EPO.get epoAuthKey epoAPIUrl q (toISO639EN la) limit
where where
parse_query = first (InvalidInputQuery q . T.pack) $ Corpus.parseQuery q parse_query = first (InvalidInputQuery q . T.pack) $ Corpus.parseQuery q
...@@ -24,20 +24,24 @@ import Servant.Client.Core (ClientError(ConnectionError)) ...@@ -24,20 +24,24 @@ import Servant.Client.Core (ClientError(ConnectionError))
get :: Maybe EPO.AuthKey get :: Maybe EPO.AuthKey
-> Text
-> Corpus.RawQuery -> Corpus.RawQuery
-> ISO639_1 -> ISO639_1
-> Maybe Corpus.Limit -> Maybe Corpus.Limit
-> IO (Either ClientError (Maybe Integer, ConduitT () HyperdataDocument IO ())) -> IO (Either ClientError (Maybe Integer, ConduitT () HyperdataDocument IO ()))
get Nothing _ _ _ = do get Nothing _ _ _ _ = do
-- throwIO $ EPO.OtherError "AuthKey is required" -- throwIO $ EPO.OtherError "AuthKey is required"
pure $ Left $ ConnectionError $ toException $ ErrorCall "AuthKey is required" pure $ Left $ ConnectionError $ toException $ ErrorCall "AuthKey is required"
get (Just authKey) q lang mLimit = do get (Just authKey) epoAPIUrl q lang mLimit = do
let _limit = Corpus.getLimit $ fromMaybe 10000 mLimit let _limit = Corpus.getLimit $ fromMaybe 10000 mLimit
case parseURI "http://localhost:3000" of case parseURI (T.unpack epoAPIUrl) of
Nothing -> pure $ Left $ ConnectionError $ toException $ ErrorCall "Cannot parse API URL" Nothing -> pure $ Left $ ConnectionError $ toException $ ErrorCall "Cannot parse API URL"
Just apiUrl -> do Just apiUrl -> do
EPO.Paginated { .. } <- EPO.searchEPOAPI apiUrl authKey 1 20 (Corpus.getRawQuery q) eRes <- EPO.searchEPOAPIC apiUrl authKey Nothing (Just 30) (Corpus.getRawQuery q)
pure $ Right ( Just $ fromIntegral total, yieldMany items .| mapC (toDoc lang) ) pure $ (\(total, itemsC) -> (Just total, itemsC .| mapC (toDoc lang))) <$> eRes
-- EPO.Paginated { .. } <- EPO.searchEPOAPI apiUrl authKey 1 20 (Corpus.getRawQuery q)
-- pure $ Right ( Just $ fromIntegral total, yieldMany items .| mapC (toDoc lang) )
toDoc :: ISO639_1 -> EPO.HyperdataDocument -> HyperdataDocument toDoc :: ISO639_1 -> EPO.HyperdataDocument -> HyperdataDocument
toDoc lang (EPO.HyperdataDocument { .. }) = toDoc lang (EPO.HyperdataDocument { .. }) =
......
...@@ -102,7 +102,7 @@ import Gargantext.Database.Action.Search (searchDocInDatabase) ...@@ -102,7 +102,7 @@ import Gargantext.Database.Action.Search (searchDocInDatabase)
import Gargantext.Database.Admin.Config (userMaster, corpusMasterName) import Gargantext.Database.Admin.Config (userMaster, corpusMasterName)
import Gargantext.Database.Admin.Types.Hyperdata import Gargantext.Database.Admin.Types.Hyperdata
import Gargantext.Database.Admin.Types.Node hiding (DEBUG) -- (HyperdataDocument(..), NodeType(..), NodeId, UserId, ListId, CorpusId, RootId, MasterCorpusId, MasterUserId) import Gargantext.Database.Admin.Types.Node hiding (DEBUG) -- (HyperdataDocument(..), NodeType(..), NodeId, UserId, ListId, CorpusId, RootId, MasterCorpusId, MasterUserId)
import Gargantext.Database.Prelude (DbCmd', DBCmd) import Gargantext.Database.Prelude (DbCmd', DBCmd, hasConfig)
import Gargantext.Database.Query.Table.ContextNodeNgrams2 import Gargantext.Database.Query.Table.ContextNodeNgrams2
import Gargantext.Database.Query.Table.Ngrams import Gargantext.Database.Query.Table.Ngrams
import Gargantext.Database.Query.Table.Node import Gargantext.Database.Query.Table.Node
...@@ -117,6 +117,7 @@ import Gargantext.Database.Schema.Node (NodePoly(..), node_id) ...@@ -117,6 +117,7 @@ import Gargantext.Database.Schema.Node (NodePoly(..), node_id)
import Gargantext.Database.Schema.Node (node_hyperdata) import Gargantext.Database.Schema.Node (node_hyperdata)
import Gargantext.Database.Types import Gargantext.Database.Types
import Gargantext.Prelude hiding (to) import Gargantext.Prelude hiding (to)
import Gargantext.Prelude.Config (GargConfig(..))
import Gargantext.Prelude.Crypto.Hash (Hash) import Gargantext.Prelude.Crypto.Hash (Hash)
import Gargantext.System.Logging import Gargantext.System.Logging
import Gargantext.Utils.Jobs (JobHandle, MonadJobStatus(..)) import Gargantext.Utils.Jobs (JobHandle, MonadJobStatus(..))
...@@ -165,7 +166,8 @@ getDataText :: (HasNodeError err) ...@@ -165,7 +166,8 @@ getDataText :: (HasNodeError err)
-> Maybe API.Limit -> Maybe API.Limit
-> DBCmd err (Either API.GetCorpusError DataText) -> DBCmd err (Either API.GetCorpusError DataText)
getDataText (ExternalOrigin api) la q mPubmedAPIKey mAuthKey li = do getDataText (ExternalOrigin api) la q mPubmedAPIKey mAuthKey li = do
eRes <- liftBase $ API.get api (_tt_lang la) q mPubmedAPIKey mAuthKey li cfg <- view hasConfig
eRes <- liftBase $ API.get api (_tt_lang la) q mPubmedAPIKey mAuthKey (_gc_epo_api_url cfg) li
pure $ DataNew <$> eRes pure $ DataNew <$> eRes
getDataText (InternalOrigin _) _la q _ _ _li = do getDataText (InternalOrigin _) _la q _ _ _li = do
(_masterUserId, _masterRootId, cId) <- getOrMk_RootWithCorpus (_masterUserId, _masterRootId, cId) <- getOrMk_RootWithCorpus
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment