]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Types/Node.hs
[MOCK] all routes completed, builds but need to be adapted to fite the practices.
[gargantext.git] / src / Gargantext / Types / Node.hs
1 {-|
2 Module : Gargantext.Types.Nodes
3 Description : Main Types of Nodes
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 -}
11
12 {-# LANGUAGE DeriveGeneric #-}
13 {-# LANGUAGE TemplateHaskell #-}
14 {-# LANGUAGE OverloadedStrings #-}
15 {-# LANGUAGE FlexibleInstances #-}
16
17 -- {-# LANGUAGE DuplicateRecordFields #-}
18
19 module Gargantext.Types.Node where
20
21 import Gargantext.Prelude
22
23 import Text.Show (Show())
24 import Data.Text (Text, unpack)
25 import Text.Read (read)
26 import GHC.Generics (Generic)
27 import Data.Eq (Eq)
28 import Data.Time (UTCTime)
29 import Gargantext.Utils.Prefix (unPrefix)
30 import Data.Aeson.TH (deriveJSON)
31 import Data.Aeson
32 import Servant
33 import Data.Either
34
35 import Test.QuickCheck.Arbitrary
36 import Test.QuickCheck (elements)
37
38 -- Instances:
39 import Data.Time.Segment (jour)
40 import Data.Aeson (Value(),toJSON)
41
42
43 ------------------------------------------------------------------------
44 data Status = Status { status_Date :: Maybe UTCTime
45 , status_Error :: Maybe Text
46 , status_Action :: Maybe Text
47 , status_Complete :: Maybe Bool
48 , status_Progress :: Maybe Int
49 } deriving (Show, Generic)
50 $(deriveJSON (unPrefix "status_") ''Status)
51
52 instance Arbitrary Status where
53 arbitrary = elements [Status Nothing Nothing Nothing Nothing Nothing]
54
55
56 ------------------------------------------------------------------------
57 data HyperdataDocument = HyperdataDocument { hyperdataDocument_Bdd :: Maybe Text
58 , hyperdataDocument_Doi :: Maybe Text
59 , hyperdataDocument_Url :: Maybe Text
60 , hyperdataDocument_Page :: Maybe Int
61 , hyperdataDocument_Title :: Maybe Text
62 , hyperdataDocument_Authors :: Maybe Text
63 , hyperdataDocument_Abstract :: Maybe Text
64 , hyperdataDocument_Statuses :: Maybe [Status]
65 , hyperdataDocument_Publication_date :: Maybe Text
66 , hyperdataDocument_Publication_year :: Maybe Double
67 , hyperdataDocument_Publication_month :: Maybe Double
68 , hyperdataDocument_Publication_hour :: Maybe Double
69 , hyperdataDocument_Publication_minute :: Maybe Double
70 , hyperdataDocument_Publication_second :: Maybe Double
71 , hyperdataDocument_LanguageIso2 :: Maybe Text
72 } deriving (Show, Generic)
73 $(deriveJSON (unPrefix "hyperdataDocument_") ''HyperdataDocument)
74
75 hyperdataDocuments :: [HyperdataDocument]
76 hyperdataDocuments = [HyperdataDocument Nothing Nothing Nothing Nothing (Just "Title")
77 Nothing (Just "Abstract") Nothing Nothing
78 Nothing Nothing Nothing Nothing Nothing Nothing
79 ]
80
81
82 instance Arbitrary HyperdataDocument where
83 arbitrary = elements hyperdataDocuments
84
85 ------------------------------------------------------------------------
86 data LanguageNodes = LanguageNodes { languageNodes___unknown__ :: [Int]}
87 deriving (Show, Generic)
88 $(deriveJSON (unPrefix "languageNodes_") ''LanguageNodes)
89
90
91 ------------------------------------------------------------------------
92
93 data Resource = Resource { resource_Url :: Maybe Text
94 , resource_Path :: Maybe Text
95 , resource_Type :: Maybe Int
96 , resource_Extracted :: Maybe Bool
97 } deriving (Show, Generic)
98 $(deriveJSON (unPrefix "resource_") ''Resource)
99
100 instance Arbitrary Resource where
101 arbitrary = elements [Resource Nothing Nothing Nothing Nothing]
102
103 data HyperdataCorpus = HyperdataCorpus { hyperdataCorpus_Action :: Maybe Text
104 , hyperdataCorpus_Statuses :: Maybe [Status]
105 , hyperdataCorpus_Languages :: Maybe LanguageNodes
106 , hyperdataCorpus_Resources :: Maybe [Resource]
107 , hyperdataCorpus_Language_id :: Maybe Text
108 , hyperdataCorpus_Skipped_docs :: Maybe [Int]
109 } deriving (Show, Generic)
110 $(deriveJSON (unPrefix "hyperdataCorpus_") ''HyperdataCorpus)
111
112
113 data HyperdataUser = HyperdataUser { hyperdataUser_language :: Maybe Text
114 } deriving (Show, Generic)
115 $(deriveJSON (unPrefix "hyperdataUser_") ''HyperdataUser)
116
117 -- Preferences ?
118
119 data HyperdataFolder = HyperdataFolder { hyperdataFolder_Preferences :: Maybe Text
120 } deriving (Show, Generic)
121 $(deriveJSON (unPrefix "hyperdataFolder_") ''HyperdataFolder)
122
123
124 data HyperdataProject = HyperdataProject { hyperdataProject_Preferences :: Maybe Text
125 } deriving (Show, Generic)
126 $(deriveJSON (unPrefix "hyperdataProject_") ''HyperdataProject)
127
128
129
130 data HyperdataList = HyperdataList { hyperdataList_Preferences :: Maybe Text
131 } deriving (Show, Generic)
132 $(deriveJSON (unPrefix "hyperdataList_") ''HyperdataList)
133
134 data HyperdataScore = HyperdataScore { hyperdataScore_Preferences :: Maybe Text
135 } deriving (Show, Generic)
136 $(deriveJSON (unPrefix "hyperdataScore_") ''HyperdataScore)
137
138
139
140 data HyperdataFavorites = HyperdataFavorites { hyperdataFavorites_Preferences :: Maybe Text
141 } deriving (Show, Generic)
142 $(deriveJSON (unPrefix "hyperdataFavorites_") ''HyperdataFavorites)
143
144 data HyperdataResource = HyperdataResource { hyperdataResource_Preferences :: Maybe Text
145 } deriving (Show, Generic)
146 $(deriveJSON (unPrefix "hyperdataResource_") ''HyperdataResource)
147
148
149
150 -- TODO add the Graph Structure here
151 data HyperdataGraph = HyperdataGraph { hyperdataGraph_Preferences :: Maybe Text
152 } deriving (Show, Generic)
153 $(deriveJSON (unPrefix "hyperdataGraph_") ''HyperdataGraph)
154
155
156 -- TODO add the Graph Structure here
157 data HyperdataPhylo = HyperdataPhylo { hyperdataPhylo_Preferences :: Maybe Text
158 } deriving (Show, Generic)
159 $(deriveJSON (unPrefix "hyperdataPhylo_") ''HyperdataPhylo)
160
161 -- | TODO FEATURE: Notebook saved in the node (to work with Python or Haskell)
162 data HyperdataNotebook = HyperdataNotebook { hyperdataNotebook_Preferences :: Maybe Text
163 } deriving (Show, Generic)
164 $(deriveJSON (unPrefix "hyperdataNotebook_") ''HyperdataNotebook)
165
166
167
168 -- | NodePoly indicates that Node has a Polymorphism Type
169 type Node json = NodePoly NodeId NodeTypeId NodeUserId (Maybe NodeParentId) NodeName UTCTime json -- NodeVector
170
171 -- type Node json = NodePoly NodeId NodeTypeId UserId ParentId NodeName UTCTime json
172 type NodeTypeId = Int
173 type NodeId = Int
174 type NodeParentId = Int
175 type NodeUserId = Int
176 type NodeName = Text
177 --type NodeVector = Vector
178
179 --type NodeUser = Node HyperdataUser
180
181 -- | Then a Node can be either a Folder or a Corpus or a Document
182 type NodeUser = Node HyperdataUser
183 type Folder = Node HyperdataFolder
184 type Project = Folder -- NP Node HyperdataProject ?
185 type Corpus = Node HyperdataCorpus
186 type Document = Node HyperdataDocument
187
188 data NodeType = NodeUser | Project | Corpus | Document | DocumentCopy
189 | Classification
190 | Lists
191 | Metrics | Occurrences
192 deriving (Show, Read, Eq, Generic)
193
194 instance FromJSON NodeType
195 instance ToJSON NodeType
196 instance FromHttpApiData NodeType where parseUrlPiece = Right . read . unpack
197
198
199 ------------------------------------------------------------------------
200 data NodePoly id typename userId parentId name date hyperdata = Node { node_id :: id
201 , node_typename :: typename
202 , node_userId :: userId
203 -- , nodeHashId :: hashId
204 , node_parentId :: parentId
205 , node_name :: name
206 , node_date :: date
207 , node_hyperdata :: hyperdata
208 -- , node_titleAbstract :: titleAbstract
209 } deriving (Show)
210 $(deriveJSON (unPrefix "node_") ''NodePoly)
211
212 instance Arbitrary (NodePoly NodeId NodeTypeId (Maybe NodeUserId) NodeParentId NodeName UTCTime Value) where
213 arbitrary = elements [Node 1 1 (Just 1) 1 "name" (jour 2018 01 01) (toJSON ("{}"::Text))]
214
215
216 instance Arbitrary (NodePoly NodeId NodeTypeId NodeUserId (Maybe NodeParentId) NodeName UTCTime Value) where
217 arbitrary = elements [Node 1 1 1 (Just 1) "name" (jour 2018 01 01) (toJSON ("{}"::Text))]
218
219
220