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
157
Issues
157
List
Board
Labels
Milestones
Merge Requests
9
Merge Requests
9
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
gargantext
haskell-gargantext
Commits
ed194927
Unverified
Commit
ed194927
authored
Jan 31, 2018
by
Nicolas Pouillard
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
NodeAPI /roots, /node
parent
277e24b4
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
88 additions
and
62 deletions
+88
-62
Node.hs
src/Data/Gargantext/Database/Node.hs
+25
-23
Date.hs
src/Data/Gargantext/Parsers/Date.hs
+4
-0
Prelude.hs
src/Data/Gargantext/Prelude.hs
+7
-2
Server.hs
src/Data/Gargantext/Server.hs
+28
-25
Main.hs
src/Data/Gargantext/Types/Main.hs
+21
-12
Node.hs
src/Data/Gargantext/Types/Node.hs
+3
-0
No files found.
src/Data/Gargantext/Database/Node.hs
View file @
ed194927
...
...
@@ -19,14 +19,14 @@ import Database.PostgreSQL.Simple.Internal (Field)
import
Control.Arrow
(
returnA
)
import
Control.Lens.TH
(
makeLensesWith
,
abbreviatedFields
)
import
Data.Aeson
import
Data.Gargantext.Database.Private
(
infoGargandb
)
import
Data.Gargantext.Types
import
Data.Maybe
(
Maybe
)
import
Data.Gargantext.Prelude
import
Data.Maybe
(
Maybe
,
fromMaybe
)
import
Data.Text
(
Text
)
import
Data.Profunctor.Product.TH
(
makeAdaptorAndInstance
)
import
Data.Typeable
(
Typeable
)
import
qualified
Data.ByteString.Internal
as
DBI
import
qualified
Database.PostgreSQL.Simple
as
PGS
import
Database.PostgreSQL.Simple
(
Connection
)
import
Opaleye
-- | Types for Node Database Management
...
...
@@ -105,13 +105,13 @@ nodeTable = Table "nodes" (pNode Node { node_id = optional "id"
)
selectNodes
::
Column
PGInt4
->
Query
(
Column
(
PGText
))
selectNodes
node_
id
=
proc
()
->
do
(
Node
n_id
_tn
_u
_p
n
_d
_h
)
<-
queryNodeTable
-<
()
restrict
-<
n
_id
.==
node_
id
returnA
-<
n
selectNodes
::
Column
PGInt4
->
Query
NodeRead
selectNodes
id
=
proc
()
->
do
row
<-
queryNodeTable
-<
()
restrict
-<
n
ode_id
row
.==
id
returnA
-<
row
runGetNodes
::
PGS
.
Connection
->
Query
NodeRead
->
IO
[
Document
]
runGetNodes
::
Connection
->
Query
NodeRead
->
IO
[
Document
]
runGetNodes
=
runQuery
...
...
@@ -122,6 +122,7 @@ queryNodeTable = queryTable nodeTable
selectNodeWithParentID
::
Column
(
Nullable
PGInt4
)
->
Query
NodeRead
selectNodeWithParentID
node_id
=
proc
()
->
do
row
@
(
Node
_id
_tn
_u
p_id
_n
_d
_h
)
<-
queryNodeTable
-<
()
-- restrict -< maybe (isNull p_id) (p_id .==) node_id
restrict
-<
p_id
.==
node_id
returnA
-<
row
...
...
@@ -129,25 +130,26 @@ selectNodesWithType :: Column PGInt4 -> Query NodeRead
selectNodesWithType
type_id
=
proc
()
->
do
row
@
(
Node
_
tn
_
_
_
_
_
)
<-
queryNodeTable
-<
()
restrict
-<
tn
.==
type_id
--let noParent = ifThenElse (isNull nullableBoss) (pgString "no") (pgString "a")
--returnA -< Node _id _tn _uid (pgInt4 0) (pgString "") _d _h
returnA
-<
row
getNodesWithType
::
Column
PGInt4
->
IO
[
NodeUser
]
getNodesWithType
type_id
=
do
conn
<-
PGS
.
connect
infoGargandb
getNode
::
Connection
->
Column
PGInt4
->
IO
(
Node
Value
)
getNode
conn
id
=
do
fromMaybe
(
error
"TODO: 404"
)
.
headMay
<$>
runQuery
conn
(
limit
1
$
selectNodes
id
)
getNodesWithType
::
Connection
->
Column
PGInt4
->
IO
[
Node
Value
]
getNodesWithType
conn
type_id
=
do
runQuery
conn
$
selectNodesWithType
type_id
getNodesWithParentId
::
Column
(
Nullable
PGInt4
)
->
IO
[
Document
]
getNodesWithParentId
node_id
=
do
conn
<-
PGS
.
connect
infoGargandb
-- NP check type
getNodesWithParentId
::
Connection
->
Column
(
Nullable
PGInt4
)
->
IO
[
Node
Value
]
getNodesWithParentId
conn
node_id
=
do
runQuery
conn
$
selectNodeWithParentID
node_id
getCorpusDocument
::
Column
(
Nullable
PGInt4
)
->
IO
[
Document
]
getCorpusDocument
node_id
=
PGS
.
connect
infoGargandb
>>=
\
conn
->
runQuery
conn
(
selectNodeWithParentID
node_id
)
-- NP check type
getCorpusDocument
::
Connection
->
Column
PGInt4
->
IO
[
Document
]
getCorpusDocument
conn
node_id
=
runQuery
conn
(
selectNodeWithParentID
$
toNullable
node_id
)
getProjectCorpora
::
Column
(
Nullable
PGInt4
)
->
IO
[
Corpus
]
getProjectCorpora
node_id
=
do
conn
<-
PGS
.
connect
infoGargandb
-- NP check type
getProjectCorpora
::
Connection
->
Column
(
Nullable
PGInt4
)
->
IO
[
Corpus
]
getProjectCorpora
conn
node_id
=
do
runQuery
conn
$
selectNodeWithParentID
node_id
src/Data/Gargantext/Parsers/Date.hs
View file @
ed194927
...
...
@@ -53,6 +53,10 @@ import Safe (headMay)
-- | Final Date parser API
-- IO can be avoided here:
-- currentContext :: Lang -> IO Context
-- currentContext lang = localContext lang <$> utcToDucklingTime <$> getCurrentTime
-- parseDate1 :: Context -> Text -> SomeErrorHandling Text
parseDate1
::
Lang
->
Text
->
IO
Text
parseDate1
lang
text
=
do
maybeJson
<-
pm
jsonValue
<$>
parseDateWithDuckling
lang
text
...
...
src/Data/Gargantext/Prelude.hs
View file @
ed194927
...
...
@@ -6,7 +6,12 @@
TODO: import head impossible from Protolude: why ?
-}
module
Data.Gargantext.Prelude
where
module
Data.Gargantext.Prelude
(
module
Data
.
Gargantext
.
Prelude
,
module
Protolude
,
headMay
)
where
import
Protolude
(
Bool
(
True
,
False
),
Int
,
Double
,
Integer
,
Fractional
,
Num
,
Maybe
,
Floating
,
Char
...
...
@@ -26,7 +31,7 @@ import qualified Data.List as L hiding (head, sum)
import
qualified
Control.Monad
as
M
import
qualified
Data.Map
as
Map
import
qualified
Data.Vector
as
V
--
import Safe (headMay)
import
Safe
(
headMay
)
pf
::
(
a
->
Bool
)
->
[
a
]
->
[
a
]
...
...
src/Data/Gargantext/Server.hs
View file @
ed194927
...
...
@@ -8,34 +8,37 @@ module Data.Gargantext.Server
-- )
where
import
Prelude
hiding
(
null
)
import
Control.Monad
import
Control.Monad.IO.Class
import
Data.Aeson
import
Data.Aeson.TH
import
Network.Wai
import
Network.Wai.Handler.Warp
import
Servant
import
Servant.Multipart
import
Database.PostgreSQL.Simple
(
Connection
,
connect
)
import
Opaleye
-- | TODO, use MOCK feature of Servant to generate fake data (for tests)
import
Data.Gargantext.Types.Main
(
Node
,
NodeId
)
import
Data.Gargantext.Database.Node
(
getNodesWithParentId
,
getNode
)
import
Data.Gargantext.Database.Private
(
infoGargandb
)
data
FakeNode
=
FakeNode
{
fakeNodeId
::
Int
,
fakeNodeName
::
String
}
deriving
(
Eq
,
Show
)
-- | TODO, use MOCK feature of Servant to generate fake data (for tests)
$
(
deriveJSON
defaultOptions
''
F
akeNode
)
type
NodeAPI
=
Get
'[
J
SON
]
(
Node
Value
)
:<|>
"children"
:>
Get
'[
J
SON
]
[
Node
Value
]
type
API
=
"nodes"
:>
Get
'[
J
SON
]
[
FakeNod
e
]
:<|>
"node"
:>
Capture
"id"
Int
:>
Get
'[
J
SON
]
FakeNode
type
API
=
"roots"
:>
Get
'[
J
SON
]
[
Node
Valu
e
]
:<|>
"node"
:>
Capture
"id"
Int
:>
NodeAPI
:<|>
"echo"
:>
Capture
"string"
String
:>
Get
'[
J
SON
]
String
:<|>
"upload"
:>
MultipartForm
MultipartData
:>
Post
'[
J
SON
]
String
-- :<|> "node" :> Capture "id" Int :> Get '[JSON] Node
server
::
Server
API
server
=
pure
fakeNodes
:<|>
fakeNode
server
::
Connection
->
Server
API
server
conn
=
liftIO
(
getNodesWithParentId
conn
null
)
:<|>
nodeAPI
conn
:<|>
echo
:<|>
upload
where
...
...
@@ -43,7 +46,10 @@ server = pure fakeNodes
startGargantext
::
IO
()
startGargantext
=
print
(
"Starting server on port "
++
show
port
)
>>
run
port
app
startGargantext
=
do
print
(
"Starting server on port "
++
show
port
)
conn
<-
connect
infoGargandb
run
port
$
app
conn
where
port
=
8008
...
...
@@ -54,20 +60,17 @@ startGargantext = print ("Starting server on port " ++ show port) >> run port a
-- , MonadLog (WithSeverity Doc) m
-- , MonadIO m) => m a
-- Thanks @yannEsposito for this.
app
::
Application
app
=
serve
api
server
app
::
Connection
->
Application
app
=
serve
api
.
server
api
::
Proxy
API
api
=
Proxy
fakeNode
::
Monad
m
=>
Int
->
m
FakeNode
fakeNode
id
=
pure
(
fakeNodes
!!
id
)
fakeNodes
::
[
FakeNode
]
fakeNodes
=
[
FakeNode
1
"Poincare"
,
FakeNode
2
"Grothendieck"
]
nodeAPI
::
Connection
->
NodeId
->
Server
NodeAPI
nodeAPI
conn
id
=
liftIO
(
getNode
conn
id'
)
:<|>
liftIO
(
getNodesWithParentId
conn
(
toNullable
id'
))
where
id'
=
pgInt4
id
-- | Upload files
-- TODO Is it possible to adapt the function according to iValue input ?
...
...
src/Data/Gargantext/Types/Main.hs
View file @
ed194927
...
...
@@ -33,34 +33,43 @@ data Language = EN | FR -- | DE | IT | SP
-- All the Database is structred like a hierarchical Tree
data
Tree
b
a
=
LeafT
a
|
NodeT
b
[
Tree
b
a
]
data
Tree
a
=
NodeT
a
[
Tree
a
]
deriving
(
Show
,
Read
,
Eq
)
-- data Tree a = NodeT a [Tree a]
-- same as Data.Tree
leafT
::
a
->
Tree
a
leafT
x
=
NodeT
x
[]
-- Garg Network is a network of all Garg nodes
--gargNetwork = undefined
-- | Garg Node is Database Schema Typed as specification
-- gargNode gathers all the Nodes of all users on one Node
gargNode
::
[
Tree
NodeType
NodeType
]
gargNode
::
[
Tree
NodeType
]
gargNode
=
[
userTree
]
-- | User Tree simplified
userTree
::
Tree
NodeType
NodeType
userTree
::
Tree
NodeType
userTree
=
NodeT
NodeUser
[
projectTree
]
-- | Project Tree
projectTree
::
Tree
NodeType
NodeType
projectTree
::
Tree
NodeType
projectTree
=
NodeT
Project
[
corpusTree
]
-- | Corpus Tree
corpusTree
::
Tree
NodeType
NodeType
corpusTree
=
NodeT
Corpus
(
[
L
eafT
Document
]
<>
[
L
eafT
Lists
]
<>
[
L
eafT
Metrics
]
<>
[
L
eafT
Classification
]
corpusTree
::
Tree
NodeType
corpusTree
=
NodeT
Corpus
(
[
l
eafT
Document
]
<>
[
l
eafT
Lists
]
<>
[
l
eafT
Metrics
]
<>
[
l
eafT
Classification
]
)
-- TODO make instances of Nodes
-- NP
-- * why NodeUser and not just User ?
-- * is this supposed to hold data ?
data
NodeType
=
NodeUser
|
Project
|
Corpus
|
Document
|
DocumentCopy
|
Classification
|
Lists
...
...
@@ -91,7 +100,7 @@ type NodeName = Text
-- | Then a Node can be either a Folder or a Corpus or a Document
type
NodeUser
=
Node
HyperdataUser
type
Folder
=
Node
HyperdataFolder
type
Project
=
Folder
type
Project
=
Folder
-- NP Node HyperdataProject ?
type
Corpus
=
Node
HyperdataCorpus
type
Document
=
Node
HyperdataDocument
...
...
@@ -105,14 +114,14 @@ type Favorites = Node HyperdataFavorites
-- | Favorites Node enable Swap Node with some synonyms for clarity
type
NodeSwap
=
Node
HyperdataResource
-- | Then a Node can be a List which as some synonyms
-- | Then a Node can be a List which
h
as some synonyms
type
List
=
Node
HyperdataList
type
StopList
=
List
type
MainList
=
List
type
MapList
=
List
type
GroupList
=
List
-- | Then a Node can be a Score which as some synonyms
-- | Then a Node can be a Score which
h
as some synonyms
type
Score
=
Node
HyperdataScore
type
Occurrences
=
Score
type
Cooccurrences
=
Score
...
...
src/Data/Gargantext/Types/Node.hs
View file @
ed194927
...
...
@@ -10,6 +10,7 @@ import Data.Time (UTCTime)
import
Data.Gargantext.Utils.Prefix
(
unPrefix
)
import
Data.Aeson.TH
(
deriveJSON
)
-- node_Id... ?
data
NodePoly
id
typename
userId
parentId
name
date
hyperdata
=
Node
{
node_id
::
id
,
node_typename
::
typename
,
node_userId
::
userId
...
...
@@ -20,6 +21,7 @@ data NodePoly id typename userId parentId name date hyperdata = Node { node_id
,
node_hyperdata
::
hyperdata
-- , node_titleAbstract :: titleAbstract
}
deriving
(
Show
)
$
(
deriveJSON
(
unPrefix
"node_"
)
''
N
odePoly
)
data
Status
=
Status
{
status_Date
::
Maybe
UTCTime
...
...
@@ -77,6 +79,7 @@ data HyperdataUser = HyperdataUser { hyperdataUser_language :: Maybe Text
}
deriving
(
Show
,
Generic
)
$
(
deriveJSON
(
unPrefix
"hyperdataUser_"
)
''
H
yperdataUser
)
-- Preferences ?
data
HyperdataFolder
=
HyperdataFolder
{
hyperdataFolder_Preferences
::
Maybe
Text
}
deriving
(
Show
,
Generic
)
...
...
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