Commit 2897a88f authored by Alexandre Delanoë's avatar Alexandre Delanoë

[TYPES] Adding HyperdataDocumentV3 type for compatibility with previous version of Gargantext.

parent 1f90ff74
...@@ -122,7 +122,7 @@ nodeTypes = [ (NodeUser , 1) ...@@ -122,7 +122,7 @@ nodeTypes = [ (NodeUser , 1)
, (Folder , 2) , (Folder , 2)
, (NodeCorpus , 30) , (NodeCorpus , 30)
, (Annuaire , 31) , (Annuaire , 31)
, (Document , 40) , (Document , 4)
, (UserPage , 41) , (UserPage , 41)
--, (NodeSwap , 19) --, (NodeSwap , 19)
------ Lists ------ Lists
......
...@@ -69,7 +69,39 @@ $(deriveJSON (unPrefix "status_") ''Status) ...@@ -69,7 +69,39 @@ $(deriveJSON (unPrefix "status_") ''Status)
instance Arbitrary Status where instance Arbitrary Status where
arbitrary = Status <$> arbitrary <*> arbitrary <*> arbitrary arbitrary = Status <$> arbitrary <*> arbitrary <*> arbitrary
------------------------------------------------------------------------
data StatusV3 = StatusV3 { statusV3_error :: Maybe Text
, statusV3_action :: Maybe Text
} deriving (Show, Generic)
$(deriveJSON (unPrefix "statusV3_") ''StatusV3)
------------------------------------------------------------------------ ------------------------------------------------------------------------
------------------------------------------------------------------------
data HyperdataDocumentV3 = HyperdataDocumentV3 { hyperdataDocumentV3_publication_day :: Maybe Int
, hyperdataDocumentV3_language_iso2 :: Maybe Text
, hyperdataDocumentV3_publication_minute :: Maybe Int
, hyperdataDocumentV3_error :: Maybe Text
, hyperdataDocumentV3_publication_month :: Maybe Int
, hyperdataDocumentV3_language_iso3 :: Maybe Text
, hyperdataDocumentV3_publication_second :: Maybe Int
, hyperdataDocumentV3_authors :: Maybe Text
, hyperdataDocumentV3_publication_year :: Maybe Int
, hyperdataDocumentV3_publication_date :: Maybe Text
, hyperdataDocumentV3_language_name :: Maybe Text
, hyperdataDocumentV3_statuses :: Maybe [StatusV3]
, hyperdataDocumentV3_realdate_full_ :: Maybe Text
, hyperdataDocumentV3_source :: Maybe Text
, hyperdataDocumentV3_abstract :: Maybe Text
, hyperdataDocumentV3_title :: Maybe Text
, hyperdataDocumentV3_publication_hour :: Maybe Int
} deriving (Show, Generic)
$(deriveJSON (unPrefix "hyperdataDocumentV3_") ''HyperdataDocumentV3)
------------------------------------------------------------------------
data HyperdataDocument = HyperdataDocument { hyperdataDocument_bdd :: Maybe Text data HyperdataDocument = HyperdataDocument { hyperdataDocument_bdd :: Maybe Text
, hyperdataDocument_doi :: Maybe Int , hyperdataDocument_doi :: Maybe Int
, hyperdataDocument_url :: Maybe Text , hyperdataDocument_url :: Maybe Text
...@@ -85,14 +117,15 @@ data HyperdataDocument = HyperdataDocument { hyperdataDocument_bdd ...@@ -85,14 +117,15 @@ data HyperdataDocument = HyperdataDocument { hyperdataDocument_bdd
, hyperdataDocument_publication_hour :: Maybe Int , hyperdataDocument_publication_hour :: Maybe Int
, hyperdataDocument_publication_minute :: Maybe Int , hyperdataDocument_publication_minute :: Maybe Int
, hyperdataDocument_publication_second :: Maybe Int , hyperdataDocument_publication_second :: Maybe Int
, hyperdataDocument_languageIso2 :: Maybe Text , hyperdataDocument_language_iso2 :: Maybe Text
, hyperdataDocument_language_iso3 :: Maybe Text
} deriving (Show, Generic) } deriving (Show, Generic)
$(deriveJSON (unPrefix "hyperdataDocument_") ''HyperdataDocument) $(deriveJSON (unPrefix "hyperdataDocument_") ''HyperdataDocument)
toHyperdataDocuments :: [(Text, Text)] -> [HyperdataDocument] toHyperdataDocuments :: [(Text, Text)] -> [HyperdataDocument]
toHyperdataDocuments ts = map (\(t1,t2) -> HyperdataDocument Nothing Nothing Nothing Nothing (Just t1) toHyperdataDocuments ts = map (\(t1,t2) -> HyperdataDocument Nothing Nothing Nothing Nothing (Just t1)
Nothing (Just t2) Nothing Nothing Nothing Nothing (Just t2) Nothing Nothing Nothing
Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
) ts ) ts
hyperdataDocuments :: [HyperdataDocument] hyperdataDocuments :: [HyperdataDocument]
...@@ -291,6 +324,7 @@ hyperdataDocument = case decode docExample of ...@@ -291,6 +324,7 @@ hyperdataDocument = case decode docExample of
Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
Nothing Nothing Nothing Nothing Nothing Nothing Nothing Nothing
Nothing
docExample :: ByteString docExample :: ByteString
docExample = "{\"publication_day\":6,\"language_iso2\":\"en\",\"publication_minute\":0,\"publication_month\":7,\"language_iso3\":\"eng\",\"publication_second\":0,\"authors\":\"Nils Hovdenak, Kjell Haram\",\"publication_year\":2012,\"publication_date\":\"2012-07-06 00:00:00+00:00\",\"language_name\":\"English\",\"statuses\":[],\"realdate_full_\":\"2012 01 12\",\"source\":\"European journal of obstetrics, gynecology, and reproductive biology\",\"abstract\":\"The literature was searched for publications on minerals and vitamins during pregnancy and the possible influence of supplements on pregnancy outcome.\",\"title\":\"Influence of mineral and vitamin supplements on pregnancy outcome.\",\"publication_hour\":0}" docExample = "{\"publication_day\":6,\"language_iso2\":\"en\",\"publication_minute\":0,\"publication_month\":7,\"language_iso3\":\"eng\",\"publication_second\":0,\"authors\":\"Nils Hovdenak, Kjell Haram\",\"publication_year\":2012,\"publication_date\":\"2012-07-06 00:00:00+00:00\",\"language_name\":\"English\",\"statuses\":[],\"realdate_full_\":\"2012 01 12\",\"source\":\"European journal of obstetrics, gynecology, and reproductive biology\",\"abstract\":\"The literature was searched for publications on minerals and vitamins during pregnancy and the possible influence of supplements on pregnancy outcome.\",\"title\":\"Influence of mineral and vitamin supplements on pregnancy outcome.\",\"publication_hour\":0}"
......
...@@ -66,6 +66,9 @@ instance FromField HyperdataCorpus where ...@@ -66,6 +66,9 @@ instance FromField HyperdataCorpus where
instance FromField HyperdataDocument where instance FromField HyperdataDocument where
fromField = fromField' fromField = fromField'
instance FromField HyperdataDocumentV3 where
fromField = fromField'
instance FromField HyperdataProject where instance FromField HyperdataProject where
fromField = fromField' fromField = fromField'
...@@ -75,6 +78,8 @@ instance FromField HyperdataUser where ...@@ -75,6 +78,8 @@ instance FromField HyperdataUser where
instance QueryRunnerColumnDefault PGJsonb HyperdataDocument where instance QueryRunnerColumnDefault PGJsonb HyperdataDocument where
queryRunnerColumnDefault = fieldQueryRunnerColumn queryRunnerColumnDefault = fieldQueryRunnerColumn
instance QueryRunnerColumnDefault PGJsonb HyperdataDocumentV3 where
queryRunnerColumnDefault = fieldQueryRunnerColumn
instance QueryRunnerColumnDefault PGJsonb HyperdataCorpus where instance QueryRunnerColumnDefault PGJsonb HyperdataCorpus where
queryRunnerColumnDefault = fieldQueryRunnerColumn queryRunnerColumnDefault = fieldQueryRunnerColumn
...@@ -178,6 +183,7 @@ selectNodesWith' parentId maybeNodeType = proc () -> do ...@@ -178,6 +183,7 @@ selectNodesWith' parentId maybeNodeType = proc () -> do
returnA -< node returnA -< node
deleteNode :: Connection -> Int -> IO Int deleteNode :: Connection -> Int -> IO Int
deleteNode conn n = fromIntegral <$> runDelete conn nodeTable deleteNode conn n = fromIntegral <$> runDelete conn nodeTable
(\(Node n_id _ _ _ _ _ _) -> n_id .== pgInt4 n) (\(Node n_id _ _ _ _ _ _) -> n_id .== pgInt4 n)
...@@ -203,6 +209,10 @@ getNodesWithParentId' :: Connection -> Int ...@@ -203,6 +209,10 @@ getNodesWithParentId' :: Connection -> Int
-> Maybe Text -> IO [Node Value] -> Maybe Text -> IO [Node Value]
getNodesWithParentId' conn n _ = runQuery conn $ selectNodesWithParentID n getNodesWithParentId' conn n _ = runQuery conn $ selectNodesWithParentID n
getDocumentsWithParentId :: Connection -> Int -> IO [Node HyperdataDocumentV3]
getDocumentsWithParentId conn n = runQuery conn $ selectNodesWith' n (Just Document)
selectNodesWithParentID :: Int -> Query NodeRead selectNodesWithParentID :: Int -> Query NodeRead
selectNodesWithParentID n = proc () -> do selectNodesWithParentID n = proc () -> do
......
...@@ -52,6 +52,7 @@ data Doc = Doc ...@@ -52,6 +52,7 @@ data Doc = Doc
--------------------------------------------------------------- ---------------------------------------------------------------
-- | Doc 2 HyperdataDocument -- | Doc 2 HyperdataDocument
doc2hyperdataDocument :: Doc -> HyperdataDocument doc2hyperdataDocument :: Doc -> HyperdataDocument
--doc2hyperdataDocument (Doc did dt ds dpy dpm dpd dab dau) =
doc2hyperdataDocument (Doc did dt ds dpy dpm dpd dab dau) = doc2hyperdataDocument (Doc did dt ds dpy dpm dpd dab dau) =
HyperdataDocument (Just "CSV") HyperdataDocument (Just "CSV")
(Just did) (Just did)
...@@ -69,6 +70,7 @@ doc2hyperdataDocument (Doc did dt ds dpy dpm dpd dab dau) = ...@@ -69,6 +70,7 @@ doc2hyperdataDocument (Doc did dt ds dpy dpm dpd dab dau) =
Nothing Nothing
Nothing Nothing
Nothing Nothing
Nothing
--------------------------------------------------------------- ---------------------------------------------------------------
-- | Types Conversions -- | Types Conversions
toDocs :: Vector CsvDoc -> [Doc] toDocs :: Vector CsvDoc -> [Doc]
......
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