]> gitweb.michael.orlitzky.com - dead/htsn-import.git/blobdiff - src/TSN/XML/News.hs
Rename the ImportResult constructors.
[dead/htsn-import.git] / src / TSN / XML / News.hs
index 5782d2412e2f38820724de05195bf60986572cc7..aa1a01c278dea76709a6c528beb0d9b41bf48104 100644 (file)
@@ -17,7 +17,6 @@ module TSN.XML.News (
   news_tests )
 where
 
-import Control.Monad.IO.Class ( MonadIO, liftIO )
 import Data.Data ( Data, constrFields, dataTypeConstrs, dataTypeOf )
 import Data.List.Utils ( join, split )
 import Data.Tuple.Curry ( uncurryN )
@@ -48,12 +47,11 @@ import Text.XML.HXT.Core (
   xpTriple,
   xpWrap )
 
-import Network.Services.TSN.Report ( report_error )
 import TSN.Codegen (
   tsn_codegen_config,
   tsn_db_field_namer -- Used in a test.
   )
-import TSN.DbImport ( DbImport(..) )
+import TSN.DbImport ( DbImport(..), ImportResult(..) )
 import Xml ( ToFromXml(..), pickle_unpickle )
 
 
@@ -86,7 +84,7 @@ instance ToFromXml NewsTeam where
   -- used our named fields.
   to_xml (NewsTeam {..}) = NewsTeamXml db_team_name
   -- We can't create a DefaultKey Message...
-  from_xml = error "Called from_xml on a NewsTeam"
+  from_xml = error "Called from_xml on a NewsTeam."
   -- unless we're handed one.
   from_xml_fk key = (NewsTeam key) . xml_team_name
 
@@ -124,7 +122,7 @@ instance ToFromXml NewsLocation where
   -- used our named fields.
   to_xml (NewsLocation {..}) = NewsLocationXml db_city db_state db_country
   -- We can't create a DefaultKey Message...
-  from_xml = error "Called from_xml on a NewsLocation"
+  from_xml = error "Called from_xml on a NewsLocation."
   -- unless we're given one.
   from_xml_fk key (NewsLocationXml x y z) = NewsLocation key x y z
 
@@ -317,8 +315,7 @@ instance DbImport Message where
     case root_element of
       Nothing -> do
         let errmsg = "Could not unpickle News message in dbimport."
-        liftIO $ report_error errmsg
-        return Nothing
+        return $ ImportFailed errmsg
       Just message  -> do
         news_id <- insert (from_xml message :: Message)
         let nts :: [NewsTeam] = map (from_xml_fk news_id)
@@ -328,7 +325,7 @@ instance DbImport Message where
         nt_ids <- mapM insert nts
         loc_ids <- mapM insert nlocs
 
-        return $ Just (1 + (length nt_ids) + (length loc_ids))
+        return $ ImportSucceeded (1 + (length nt_ids) + (length loc_ids))
 
 
 -- * Tasty Tests