Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
haskell-gargantext
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Julien Moutinho
haskell-gargantext
Commits
24ef381d
Commit
24ef381d
authored
Jun 19, 2023
by
Alexandre Delanoë
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Revert "Revert "Merge remote-tracking branch 'origin/201-dev-user-pubmed-api-key' into dev""
This reverts commit
a444cb30
.
parent
0d383903
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
123 additions
and
50 deletions
+123
-50
GraphQL.hs
src/Gargantext/API/GraphQL.hs
+2
-0
Node.hs
src/Gargantext/API/GraphQL/Node.hs
+54
-10
New.hs
src/Gargantext/API/Node/Corpus/New.hs
+1
-1
Types.hs
src/Gargantext/API/Node/Corpus/Types.hs
+21
-24
Table.hs
src/Gargantext/API/Table.hs
+5
-5
Tools.hs
src/Gargantext/Core/Viz/Phylo/API/Tools.hs
+1
-1
Corpus.hs
src/Gargantext/Database/Admin/Types/Hyperdata/Corpus.hs
+13
-9
Node.hs
src/Gargantext/Database/Query/Table/Node.hs
+26
-0
No files found.
src/Gargantext/API/GraphQL.hs
View file @
24ef381d
...
...
@@ -76,6 +76,7 @@ data Query m
,
job_logs
::
GQLAT
.
JobLogArgs
->
m
(
Map
Int
JobLog
)
,
languages
::
GQLNLP
.
LanguagesArgs
->
m
GQLNLP
.
LanguagesMap
,
nodes
::
GQLNode
.
NodeArgs
->
m
[
GQLNode
.
Node
]
,
nodes_corpus
::
GQLNode
.
CorpusArgs
->
m
[
GQLNode
.
Corpus
]
,
node_parent
::
GQLNode
.
NodeParentArgs
->
m
[
GQLNode
.
Node
]
,
user_infos
::
GQLUserInfo
.
UserInfoArgs
->
m
[
GQLUserInfo
.
UserInfo
]
,
users
::
GQLUser
.
UserArgs
->
m
[
GQLUser
.
User
m
]
...
...
@@ -120,6 +121,7 @@ rootResolver =
,
job_logs
=
GQLAT
.
resolveJobLogs
,
languages
=
GQLNLP
.
resolveLanguages
,
nodes
=
GQLNode
.
resolveNodes
,
nodes_corpus
=
GQLNode
.
resolveNodesCorpus
,
node_parent
=
GQLNode
.
resolveNodeParent
,
user_infos
=
GQLUserInfo
.
resolveUserInfos
,
users
=
GQLUser
.
resolveUsers
...
...
src/Gargantext/API/GraphQL/Node.hs
View file @
24ef381d
...
...
@@ -3,7 +3,9 @@
module
Gargantext.API.GraphQL.Node
where
import
Data.Aeson
import
Data.Either
(
Either
(
..
))
import
qualified
Data.HashMap.Strict
as
HashMap
import
Data.Morpheus.Types
(
GQLType
,
Resolver
...
...
@@ -16,23 +18,37 @@ import Gargantext.API.Prelude (GargM, GargError)
import
Gargantext.Database.Admin.Types.Node
(
NodeId
(
..
),
NodeType
)
import
qualified
Gargantext.Database.Admin.Types.Node
as
NN
import
Gargantext.Database.Query.Table.Node
(
getClosestParentIdByType
,
getNode
)
import
Gargantext.Database.Prelude
(
CmdCommon
)
import
Gargantext.Database.Prelude
(
CmdCommon
)
-- , JSONB)
import
qualified
Gargantext.Database.Schema.Node
as
N
import
Gargantext.Prelude
import
GHC.Generics
(
Generic
)
import
qualified
Prelude
import
qualified
PUBMED.Types
as
PUBMED
import
Text.Read
(
readEither
)
data
Corpus
=
Corpus
{
id
::
Int
,
name
::
Text
,
parent_id
::
Maybe
Int
,
pubmedAPIKey
::
Maybe
PUBMED
.
APIKey
,
type_id
::
Int
}
deriving
(
Show
,
Generic
,
GQLType
)
data
Node
=
Node
{
id
::
Int
,
name
::
Text
,
parent_id
::
Maybe
Int
,
type_id
::
Int
{
id
::
Int
,
name
::
Text
,
parent_id
::
Maybe
Int
,
type_id
::
Int
}
deriving
(
Show
,
Generic
,
GQLType
)
data
CorpusArgs
=
CorpusArgs
{
corpus_id
::
Int
}
deriving
(
Generic
,
GQLType
)
data
NodeArgs
=
NodeArgs
{
node_id
::
Int
{
node_id
::
Int
}
deriving
(
Generic
,
GQLType
)
type
GqlM
e
env
=
Resolver
QUERY
e
(
GargM
env
GargError
)
...
...
@@ -43,6 +59,11 @@ resolveNodes
=>
NodeArgs
->
GqlM
e
env
[
Node
]
resolveNodes
NodeArgs
{
node_id
}
=
dbNodes
node_id
resolveNodesCorpus
::
(
CmdCommon
env
)
=>
CorpusArgs
->
GqlM
e
env
[
Corpus
]
resolveNodesCorpus
CorpusArgs
{
corpus_id
}
=
dbNodesCorpus
corpus_id
dbNodes
::
(
CmdCommon
env
)
=>
Int
->
GqlM
e
env
[
Node
]
...
...
@@ -50,6 +71,13 @@ dbNodes node_id = do
node
<-
lift
$
getNode
$
NodeId
node_id
pure
[
toNode
node
]
dbNodesCorpus
::
(
CmdCommon
env
)
=>
Int
->
GqlM
e
env
[
Corpus
]
dbNodesCorpus
corpus_id
=
do
corpus
<-
lift
$
getNode
$
NodeId
corpus_id
pure
[
toCorpus
corpus
]
data
NodeParentArgs
=
NodeParentArgs
{
node_id
::
Int
...
...
@@ -79,7 +107,23 @@ dbParentNodes node_id parent_type = do
pure
[
toNode
node
]
toNode
::
NN
.
Node
json
->
Node
toNode
(
N
.
Node
{
..
})
=
Node
{
id
=
NN
.
unNodeId
_node_id
,
name
=
_node_name
,
parent_id
=
NN
.
unNodeId
<$>
_node_parent_id
,
type_id
=
_node_typename
}
toNode
N
.
Node
{
..
}
=
Node
{
id
=
NN
.
unNodeId
_node_id
,
name
=
_node_name
,
parent_id
=
NN
.
unNodeId
<$>
_node_parent_id
,
type_id
=
_node_typename
}
toCorpus
::
NN
.
Node
Value
->
Corpus
toCorpus
N
.
Node
{
..
}
=
Corpus
{
id
=
NN
.
unNodeId
_node_id
,
name
=
_node_name
,
parent_id
=
NN
.
unNodeId
<$>
_node_parent_id
,
pubmedAPIKey
=
pubmedAPIKeyFromValue
_node_hyperdata
,
type_id
=
_node_typename
}
pubmedAPIKeyFromValue
::
Value
->
Maybe
PUBMED
.
APIKey
pubmedAPIKeyFromValue
(
Object
kv
)
=
case
HashMap
.
lookup
"pubmed_api_key"
kv
of
Nothing
->
Nothing
Just
v
->
case
fromJSON
v
of
Error
_
->
Nothing
Success
v'
->
Just
v'
pubmedAPIKeyFromValue
_
=
Nothing
src/Gargantext/API/Node/Corpus/New.hs
View file @
24ef381d
...
...
@@ -56,7 +56,7 @@ import Gargantext.Database.Action.User (getUserId)
import
Gargantext.Database.Admin.Types.Hyperdata
import
Gargantext.Database.Admin.Types.Node
(
CorpusId
,
NodeType
(
..
))
import
Gargantext.Database.Prelude
(
hasConfig
)
import
Gargantext.Database.Query.Table.Node
(
getNodeWith
)
import
Gargantext.Database.Query.Table.Node
(
getNodeWith
,
updateCorpusPubmedAPIKey
)
import
Gargantext.Database.Query.Table.Node.UpdateOpaleye
(
updateHyperdata
)
import
Gargantext.Database.Schema.Node
(
node_hyperdata
)
import
Gargantext.Prelude
...
...
src/Gargantext/API/Node/Corpus/Types.hs
View file @
24ef381d
...
...
@@ -3,18 +3,12 @@
module
Gargantext.API.Node.Corpus.Types
where
import
Control.Lens
hiding
(
elements
,
Empty
)
import
Control.Monad.Fail
(
fail
)
import
Control.Monad.Reader
(
MonadReader
)
import
Data.Aeson
import
Data.Aeson.TH
(
deriveJSON
)
import
Data.Monoid
(
mempty
)
import
Data.Swagger
import
Data.Text
(
Text
)
import
qualified
Data.Text
as
T
import
GHC.Generics
(
Generic
)
import
Text.Regex.TDFA
((
=~
))
import
Protolude
((
++
))
import
Gargantext.Prelude
import
qualified
Gargantext.API.Admin.Orchestrator.Types
as
Types
...
...
@@ -30,7 +24,8 @@ data Database = Empty
deriving
(
Eq
,
Show
,
Generic
,
Enum
,
Bounded
)
deriveJSON
(
unPrefix
""
)
''
D
atabase
instance
ToSchema
Database
instance
ToSchema
Database
where
declareNamedSchema
=
genericDeclareNamedSchemaUnrestricted
defaultSchemaOptions
database2origin
::
Database
->
DataOrigin
database2origin
Empty
=
InternalOrigin
Types
.
IsTex
...
...
@@ -42,27 +37,29 @@ database2origin Isidore = ExternalOrigin Types.Isidore
------------------------------------------------------------------------
data
Datafield
=
Gargantext
|
External
(
Maybe
Database
)
|
External
Database
|
Web
|
Files
deriving
(
Eq
,
Show
,
Generic
)
instance
FromJSON
Datafield
where
parseJSON
=
withText
"Datafield"
$
\
text
->
case
text
of
"Gargantext"
->
pure
Gargantext
"Web"
->
pure
Web
"Files"
->
pure
Files
v
->
let
(
preExternal
,
_
,
postExternal
)
=
v
=~
(
"External "
::
Text
)
::
(
Text
,
Text
,
Text
)
in
if
preExternal
==
""
then
do
db
<-
parseJSON
$
String
postExternal
pure
$
External
db
else
fail
$
"Cannot match patterh 'External <db>' for string "
++
(
T
.
unpack
v
)
instance
ToJSON
Datafield
where
toJSON
(
External
db
)
=
toJSON
$
"External "
++
(
show
db
)
toJSON
s
=
toJSON
$
show
s
instance
FromJSON
Datafield
instance
ToJSON
Datafield
-- instance FromJSON Datafield where
-- parseJSON = withText "Datafield" $ \text ->
-- case text of
-- "Gargantext" -> pure Gargantext
-- "Web" -> pure Web
-- "Files" -> pure Files
-- v ->
-- let (preExternal, _, postExternal) = v =~ ("External " :: Text) :: (Text, Text, Text)
-- in
-- if preExternal == "" then do
-- db <- parseJSON $ String postExternal
-- pure $ External db
-- else fail $ "Cannot match patterh 'External <db>' for string " ++ (T.unpack v)
-- instance ToJSON Datafield where
-- toJSON (External db) = toJSON $ "External " ++ (show db)
-- toJSON s = toJSON $ show s
instance
ToSchema
Datafield
where
declareNamedSchema
_
=
do
return
$
NamedSchema
(
Just
"Datafield"
)
$
mempty
...
...
src/Gargantext/API/Table.hs
View file @
24ef381d
...
...
@@ -73,11 +73,11 @@ type TableApi = Summary "Table API"
:>
Get
'[
J
SON
]
Text
data
TableQuery
=
TableQuery
{
tq_offset
::
Offset
,
tq_limit
::
Limit
,
tq_orderBy
::
OrderBy
,
tq_view
::
TabType
,
tq_query
::
Text
{
tq_offset
::
Offset
,
tq_limit
::
Limit
,
tq_orderBy
::
OrderBy
,
tq_view
::
TabType
,
tq_query
::
Text
}
deriving
(
Generic
)
type
FacetTableResult
=
TableResult
FacetDoc
...
...
src/Gargantext/Core/Viz/Phylo/API/Tools.hs
View file @
24ef381d
...
...
@@ -12,10 +12,10 @@ Portability : POSIX
module
Gargantext.Core.Viz.Phylo.API.Tools
where
import
Data.Proxy
import
Data.Aeson
(
Value
,
decodeFileStrict
,
eitherDecode
,
encode
)
import
Data.Map.Strict
(
Map
)
import
Data.Maybe
(
catMaybes
)
import
Data.Proxy
import
Data.Set
(
Set
)
import
Data.Text
(
Text
,
pack
)
import
Data.Time.Calendar
(
fromGregorian
,
diffGregorianDurationClip
,
cdMonths
,
diffDays
,
showGregorian
)
...
...
src/Gargantext/Database/Admin/Types/Hyperdata/Corpus.hs
View file @
24ef381d
...
...
@@ -24,22 +24,26 @@ module Gargantext.Database.Admin.Types.Hyperdata.Corpus
import
Gargantext.Prelude
import
Gargantext.Database.Admin.Types.Hyperdata.CorpusField
import
Gargantext.Database.Admin.Types.Hyperdata.Prelude
import
PUBMED.Types
(
APIKey
)
------------------------------------------------------------------------
data
HyperdataCorpus
=
HyperdataCorpus
{
_hc_fields
::
!
[
HyperdataField
CorpusField
]
}
HyperdataCorpus
{
_hc_fields
::
!
[
HyperdataField
CorpusField
]
,
_hc_pubmed_api_key
::
Maybe
APIKey
}
deriving
(
Generic
)
defaultHyperdataCorpus
::
HyperdataCorpus
defaultHyperdataCorpus
=
HyperdataCorpus
[
HyperdataField
Markdown
"Corpus analysis"
(
MarkdownField
"# title
\n
## subtitle"
)
,
HyperdataField
JSON
"Metadata (Experts only)"
(
JsonField
"Title"
"Descr"
"Bool query"
"Authors"
)
]
HyperdataCorpus
{
_hc_fields
=
[
HyperdataField
Markdown
"Corpus analysis"
(
MarkdownField
"# title
\n
## subtitle"
)
,
HyperdataField
JSON
"Metadata (Experts only)"
(
JsonField
"Title"
"Descr"
"Bool query"
"Authors"
)
]
,
_hc_pubmed_api_key
=
Nothing
}
------------------------------------------------------------------------
------------------------------------------------------------------------
...
...
src/Gargantext/Database/Query/Table/Node.hs
View file @
24ef381d
...
...
@@ -29,6 +29,7 @@ import Data.Text (Text)
import
Database.PostgreSQL.Simple.SqlQQ
(
sql
)
import
Opaleye
hiding
(
FromField
)
import
Prelude
hiding
(
null
,
id
,
map
,
sum
)
import
qualified
PUBMED.Types
as
PUBMED
import
Gargantext.Core
import
Gargantext.Core.Types
...
...
@@ -327,6 +328,31 @@ insertNodesWithParent pid ns = insertNodes (set node_parent_id (pgNodeId <$> pid
insertNodesWithParentR
::
Maybe
ParentId
->
[
NodeWrite
]
->
Cmd
err
[
NodeId
]
insertNodesWithParentR
pid
ns
=
insertNodesR
(
set
node_parent_id
(
pgNodeId
<$>
pid
)
<$>
ns
)
getCorpusPubmedAPIKey
::
NodeId
->
Cmd
err
(
Maybe
PUBMED
.
APIKey
)
getCorpusPubmedAPIKey
cId
=
do
res
<-
runPGSQuery
query
params
pure
$
(
\
(
PGS
.
Only
apiKey
)
->
apiKey
)
<$>
head
res
where
query
::
PGS
.
Query
query
=
[
sql
|
SELECT hyperdata -> 'pubmed_api_key'
FROM nodes
WHERE id = ?
|]
params
=
PGS
.
Only
cId
updateCorpusPubmedAPIKey
::
NodeId
->
PUBMED
.
APIKey
->
Cmd
err
Int64
updateCorpusPubmedAPIKey
cId
apiKey
=
execPGSQuery
query
params
where
query
::
PGS
.
Query
query
=
[
sql
|
UPDATE nodes
SET hyperdata = hyperdata || ?
WHERE id = ?
|]
params
=
(
encode
$
object
[
"pubmed_api_key"
.=
apiKey
],
cId
)
------------------------------------------------------------------------
-- TODO
-- currently this function removes the child relation
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment