diff --git a/lib/domain/libimagtodo/src/error.rs b/lib/domain/libimagtodo/src/error.rs index 621d3249..de39049f 100644 --- a/lib/domain/libimagtodo/src/error.rs +++ b/lib/domain/libimagtodo/src/error.rs @@ -23,7 +23,10 @@ generate_error_module!( StoreError => "Store Error", StoreIdError => "Store Id handling error", ImportError => "Error importing", - UTF8Error => "Encountered non-UTF8 characters while reading input" + UTF8Error => "Encountered non-UTF8 characters while reading input", + HeaderFieldMissing => "Header field missing", + HeaderTypeError => "Header field type error", + UuidParserError => "Uuid parser error" ); ); diff --git a/lib/domain/libimagtodo/src/lib.rs b/lib/domain/libimagtodo/src/lib.rs index ee85dab5..6c0c482e 100644 --- a/lib/domain/libimagtodo/src/lib.rs +++ b/lib/domain/libimagtodo/src/lib.rs @@ -47,5 +47,6 @@ module_entry_path_mod!("todo"); pub mod error; pub mod result; +pub mod task; pub mod taskstore; diff --git a/lib/domain/libimagtodo/src/task.rs b/lib/domain/libimagtodo/src/task.rs new file mode 100644 index 00000000..b2b70696 --- /dev/null +++ b/lib/domain/libimagtodo/src/task.rs @@ -0,0 +1,47 @@ +// +// imag - the personal information management suite for the commandline +// Copyright (C) 2015, 2016 Matthias Beyer and contributors +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; version +// 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +// + +use error::TodoErrorKind as TEK; +use error::MapErrInto; +use result::Result; + +use libimagstore::store::Entry; +use libimagerror::into::IntoError; + +use uuid::Uuid; +use toml::Value; +use toml_query::read::TomlValueReadExt; + +pub trait Task { + fn get_uuid(&self) -> Result; +} + +impl Task for Entry { + fn get_uuid(&self) -> Result { + match self.get_header().read("todo.uuid") { + Ok(Some(&Value::String(ref uuid))) => { + Uuid::parse_str(uuid).map_err_into(TEK::UuidParserError) + }, + Ok(Some(_)) => Err(TEK::HeaderTypeError.into_error()), + Ok(None) => Err(TEK::HeaderFieldMissing.into_error()), + Err(e) => Err(e).map_err_into(TEK::StoreError), + } + } +} +