summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2018-02-20 18:37:48 +0100
committerGitHub <noreply@github.com>2018-02-20 18:37:48 +0100
commit461bebe60adff66da5a2bc98740c2a795bc5a739 (patch)
tree6708af4b60687a61c2957272564964fa6ed2225a
parent9c98d8f56edf5e849f46afba669ea9b64bf37376 (diff)
parent585261d468e0095b4948ce84a644fb8ee1ccb4c8 (diff)
downloadimag-461bebe60adff66da5a2bc98740c2a795bc5a739.zip
imag-461bebe60adff66da5a2bc98740c2a795bc5a739.tar.gz
Merge pull request #1302 from matthiasbeyer/libimagdiary/fix-set-isflag
libimagdiary: Add "isflag" support
-rw-r--r--lib/domain/libimagdiary/Cargo.toml2
-rw-r--r--lib/domain/libimagdiary/src/diary.rs10
-rw-r--r--lib/domain/libimagdiary/src/entry.rs10
-rw-r--r--lib/domain/libimagdiary/src/error.rs4
-rw-r--r--lib/domain/libimagdiary/src/lib.rs1
5 files changed, 25 insertions, 2 deletions
diff --git a/lib/domain/libimagdiary/Cargo.toml b/lib/domain/libimagdiary/Cargo.toml
index bad6e57..d8f2e51 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 896d439..e5b1b9e 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::<IsDiaryEntry>()?;
+ Ok(entry)
}
fn new_entry_now(&self, diary_name: &str) -> Result<FileLockEntry> {
@@ -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::<IsDiaryEntry>()?;
+ 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 fb52979..82c0b6b 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<bool>;
fn diary_id(&self) -> Result<DiaryId>;
}
impl DiaryEntry for Entry {
+ /// Check whether the entry is a diary entry by checking its headers
+ fn is_diary_entry(&self) -> Result<bool> {
+ self.is::<IsDiaryEntry>().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 95d3d7e..32eb955 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 16e45af..e0dba33 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;