2 Module : Gargantext.Viz.Phylo.API
3 Description : Phylo API
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
13 {-# OPTIONS_GHC -fno-warn-orphans #-}
16 {-# LANGUAGE RankNTypes #-}
17 {-# LANGUAGE DataKinds #-}
18 {-# LANGUAGE NoImplicitPrelude #-}
19 {-# LANGUAGE OverloadedStrings #-} -- allows to write Text literals
20 {-# LANGUAGE OverloadedLists #-} -- allows to write Map and HashMap as lists
21 {-# LANGUAGE TypeOperators #-}
22 {-# LANGUAGE FlexibleInstances #-}
24 module Gargantext.Viz.Phylo.API
28 import Gargantext.API.Types
29 import Gargantext.Database.Types.Node (PhyloId, ListId, CorpusId)
30 import Gargantext.Prelude
31 import Gargantext.Viz.Phylo
32 import Gargantext.Viz.Phylo.Example
33 import Gargantext.Viz.Phylo.Tools
34 import Gargantext.Viz.Phylo.View.ViewMaker
36 import Servant.Job.Utils (swaggerOptions)
37 import Test.QuickCheck (elements)
38 import Test.QuickCheck.Arbitrary (Arbitrary, arbitrary)
39 import Web.HttpApiData (parseUrlPiece, readTextData)
41 ------------------------------------------------------------------------
42 type PhyloAPI = Summary "Phylo API"
43 -- :> QueryParam "param" PhyloQueryView
47 -- :<|> Capture "id" PhyloId :> Post '[JSON] Phylo
48 -- :<|> Capture "id" PhyloId :> Put '[JSON] Phylo
51 phyloAPI :: PhyloId -> GargServer PhyloAPI
52 phyloAPI n = getPhylo n
54 -- :<|> pure . (postPhylo n)
57 ------------------------------------------------------------------------
58 type GetPhylo = QueryParam "listId" ListId
59 :> QueryParam "level" Level
60 :> QueryParam "filiation" Filiation
61 :> QueryParam "childs" Bool
62 :> QueryParam "depth" Level
63 :> QueryParam "metrics" [Metric]
64 :> QueryParam "periodsInf" Int
65 :> QueryParam "periodsSup" Int
66 :> QueryParam "minNodes" Int
67 :> QueryParam "taggers" [Tagger]
68 :> QueryParam "sort" Sort
69 :> QueryParam "sort" Order
70 :> QueryParam "display" DisplayMode
71 :> QueryParam "verbose" Bool
72 :> Get '[JSON] PhyloView
75 -- Add real text processing
76 -- Fix Filter parameters
77 getPhylo :: PhyloId -> GargServer GetPhylo
78 getPhylo _phyloId _lId l f b l' ms x y z ts s o d b' = do
80 fs' = maybe (Just []) (\p -> Just [p]) $ SmallBranch <$> (SBParams <$> x <*> y <*> z)
82 q = initPhyloQueryView l f b l' ms fs' ts so d b'
83 -- | TODO remove phylo for real data here
84 pure (toPhyloView q phylo)
86 ------------------------------------------------------------------------
87 type PutPhylo = (Put '[JSON] Phylo )
88 --putPhylo :: PhyloId -> Maybe ListId -> PhyloQueryBuild -> Phylo
89 putPhylo :: PhyloId -> GargServer PutPhylo
93 ------------------------------------------------------------------------
94 type PostPhylo = (Post '[JSON] Phylo)
95 --postPhylo :: CorpusId -> Maybe ListId -> PhyloQueryBuild -> Phylo
96 postPhylo :: CorpusId -> Phylo
99 ------------------------------------------------------------------------
100 -- | DELETE Phylo == delete a node
101 ------------------------------------------------------------------------
104 instance Arbitrary PhyloView
106 arbitrary = elements [phyloView]
108 -- | TODO add phyloGroup ex
109 instance Arbitrary PhyloGroup
111 arbitrary = elements []
113 instance Arbitrary Phylo
115 arbitrary = elements [phylo]
120 instance ToSchema Cluster
121 instance ToSchema EdgeType
122 instance ToSchema Filiation
123 instance ToSchema Filter
124 instance ToSchema FisParams
125 instance ToSchema HammingParams
126 instance ToSchema LouvainParams
127 instance ToSchema Metric
128 instance ToSchema Order
129 instance ToSchema Phylo
130 instance ToSchema PhyloBranch
131 instance ToSchema PhyloEdge
132 instance ToSchema PhyloGroup
133 instance ToSchema PhyloLevel
134 instance ToSchema PhyloNode
135 instance ToSchema PhyloParam
136 instance ToSchema PhyloPeaks
137 instance ToSchema PhyloPeriod
138 instance ToSchema PhyloQueryBuild
139 instance ToSchema PhyloView
140 instance ToSchema RCParams
141 instance ToSchema SBParams
142 instance ToSchema Software
143 instance ToSchema WLJParams
146 instance ToParamSchema Order
147 instance FromHttpApiData Order
149 parseUrlPiece = readTextData
152 instance ToParamSchema Metric
153 instance FromHttpApiData [Metric]
155 parseUrlPiece = readTextData
156 instance FromHttpApiData Metric
158 parseUrlPiece = readTextData
161 instance ToParamSchema DisplayMode
162 instance FromHttpApiData DisplayMode
164 parseUrlPiece = readTextData
167 instance FromHttpApiData Sort
169 parseUrlPiece = readTextData
170 instance ToParamSchema Sort
172 instance (ToSchema a) => ToSchema (Tree a)
174 declareNamedSchema = genericDeclareNamedSchemaUnrestricted
177 instance ToSchema Proximity
179 declareNamedSchema = genericDeclareNamedSchemaUnrestricted
183 instance FromHttpApiData [Tagger]
185 parseUrlPiece = readTextData
186 instance FromHttpApiData Tagger
188 parseUrlPiece = readTextData
189 instance ToParamSchema Tagger
191 instance FromHttpApiData Filiation
193 parseUrlPiece = readTextData
194 instance ToParamSchema Filiation