diff --git a/lib/domain/libimagdiary/Cargo.toml b/lib/domain/libimagdiary/Cargo.toml index bad6e576..d8f2e51a 100644 --- a/lib/domain/libimagdiary/Cargo.toml +++ b/lib/domain/libimagdiary/Cargo.toml @@ -32,3 +32,5 @@ libimagerror = { version = "0.7.0", path = "../../../lib/core/libimagerror" libimagrt = { version = "0.7.0", path = "../../../lib/core/libimagrt" } libimagentryedit = { version = "0.7.0", path = "../../../lib/entry/libimagentryedit" } libimagentryview = { version = "0.7.0", path = "../../../lib/entry/libimagentryview" } +libimagentryutil = { version = "0.7.0", path = "../../../lib/entry/libimagentryutil" } + diff --git a/lib/domain/libimagdiary/src/diary.rs b/lib/domain/libimagdiary/src/diary.rs index 896d439a..e5b1b9e3 100644 --- a/lib/domain/libimagdiary/src/diary.rs +++ b/lib/domain/libimagdiary/src/diary.rs @@ -22,6 +22,7 @@ use std::cmp::Ordering; use libimagstore::store::FileLockEntry; use libimagstore::store::Store; use libimagerror::trace::trace_error; +use libimagentryutil::isa::Is; use chrono::offset::Local; use chrono::Datelike; @@ -29,6 +30,7 @@ use itertools::Itertools; use chrono::naive::NaiveDateTime; use chrono::Timelike; +use entry::IsDiaryEntry; use entry::DiaryEntry; use diaryid::DiaryId; use error::DiaryErrorKind as DEK; @@ -63,7 +65,9 @@ impl Diary for Store { let ndt = dt.naive_local(); let id = DiaryId::new(String::from(diary_name), ndt.year(), ndt.month(), ndt.day(), 0, 0, 0); - self.retrieve(id).chain_err(|| DEK::StoreReadError) + let mut entry = self.retrieve(id).chain_err(|| DEK::StoreReadError)?; + let _ = entry.set_isflag::()?; + Ok(entry) } fn new_entry_now(&self, diary_name: &str) -> Result { @@ -77,7 +81,9 @@ impl Diary for Store { ndt.minute(), ndt.second()); - self.retrieve(id).chain_err(|| DEK::StoreReadError) + let mut entry = self.retrieve(id).chain_err(|| DEK::StoreReadError)?; + let _ = entry.set_isflag::()?; + Ok(entry) } // Get an iterator for iterating over all entries diff --git a/lib/domain/libimagdiary/src/entry.rs b/lib/domain/libimagdiary/src/entry.rs index fb529798..82c0b6ba 100644 --- a/lib/domain/libimagdiary/src/entry.rs +++ b/lib/domain/libimagdiary/src/entry.rs @@ -18,17 +18,27 @@ // use libimagstore::store::Entry; +use libimagentryutil::isa::Is; +use libimagentryutil::isa::IsKindHeaderPathProvider; use diaryid::DiaryId; use diaryid::FromStoreId; use error::Result; +provide_kindflag_path!(pub IsDiaryEntry, "diary.is_diary_entry"); + pub trait DiaryEntry { + fn is_diary_entry(&self) -> Result; fn diary_id(&self) -> Result; } impl DiaryEntry for Entry { + /// Check whether the entry is a diary entry by checking its headers + fn is_diary_entry(&self) -> Result { + self.is::().map_err(From::from) + } + /// Get the diary id for this entry. /// /// TODO: calls Option::unwrap() as it assumes that an existing Entry has an ID that is parsable diff --git a/lib/domain/libimagdiary/src/error.rs b/lib/domain/libimagdiary/src/error.rs index 95d3d7e0..32eb9555 100644 --- a/lib/domain/libimagdiary/src/error.rs +++ b/lib/domain/libimagdiary/src/error.rs @@ -22,6 +22,10 @@ error_chain! { DiaryError, DiaryErrorKind, ResultExt, Result; } + links { + EntryUtilError(::libimagentryutil::error::EntryUtilError, ::libimagentryutil::error::EntryUtilErrorKind); + } + errors { StoreWriteError { description("Error writing store") diff --git a/lib/domain/libimagdiary/src/lib.rs b/lib/domain/libimagdiary/src/lib.rs index 16e45af8..e0dba334 100644 --- a/lib/domain/libimagdiary/src/lib.rs +++ b/lib/domain/libimagdiary/src/lib.rs @@ -43,6 +43,7 @@ extern crate itertools; #[macro_use] extern crate error_chain; #[macro_use] extern crate libimagstore; +#[macro_use] extern crate libimagentryutil; extern crate libimagerror; extern crate libimagentryedit; extern crate libimagentryview;