Make annotations unnamed (automatically UUID named)
It makes no sense to name annotations, a user only cares about whether there are annotations or not, or their contents. A name has no meaning in this context. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
This commit is contained in:
parent
b010d69e62
commit
ed01f8b463
4 changed files with 29 additions and 31 deletions
|
@ -25,6 +25,9 @@ toml = "0.4"
|
||||||
toml-query = "0.8"
|
toml-query = "0.8"
|
||||||
failure = "0.1"
|
failure = "0.1"
|
||||||
failure_derive = "0.1"
|
failure_derive = "0.1"
|
||||||
|
uuid = { version = "0.7", features = ["v4"] }
|
||||||
|
log = "0.4.0"
|
||||||
|
|
||||||
|
|
||||||
libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
|
libimagstore = { version = "0.10.0", path = "../../../lib/core/libimagstore" }
|
||||||
libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" }
|
libimagerror = { version = "0.10.0", path = "../../../lib/core/libimagerror" }
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
|
use uuid::Uuid;
|
||||||
|
|
||||||
use libimagstore::store::Entry;
|
use libimagstore::store::Entry;
|
||||||
use libimagstore::store::FileLockEntry;
|
use libimagstore::store::FileLockEntry;
|
||||||
|
@ -28,7 +29,6 @@ use libimagentrylink::internal::InternalLinker;
|
||||||
use libimagentryutil::isa::Is;
|
use libimagentryutil::isa::Is;
|
||||||
use libimagentryutil::isa::IsKindHeaderPathProvider;
|
use libimagentryutil::isa::IsKindHeaderPathProvider;
|
||||||
|
|
||||||
use toml_query::read::TomlValueReadTypeExt;
|
|
||||||
use toml_query::insert::TomlValueInsertExt;
|
use toml_query::insert::TomlValueInsertExt;
|
||||||
|
|
||||||
use failure::Fallible as Result;
|
use failure::Fallible as Result;
|
||||||
|
@ -37,9 +37,10 @@ use failure::Error;
|
||||||
use failure::err_msg;
|
use failure::err_msg;
|
||||||
|
|
||||||
use iter::*;
|
use iter::*;
|
||||||
|
use module_path::ModuleEntryPath;
|
||||||
|
|
||||||
pub trait Annotateable {
|
pub trait Annotateable {
|
||||||
fn annotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result<FileLockEntry<'a>>;
|
fn annotate<'a>(&mut self, store: &'a Store) -> Result<FileLockEntry<'a>>;
|
||||||
fn denotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result<Option<FileLockEntry<'a>>>;
|
fn denotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result<Option<FileLockEntry<'a>>>;
|
||||||
fn annotations<'a>(&self, store: &'a Store) -> Result<AnnotationIter<'a>>;
|
fn annotations<'a>(&self, store: &'a Store) -> Result<AnnotationIter<'a>>;
|
||||||
fn is_annotation(&self) -> Result<bool>;
|
fn is_annotation(&self) -> Result<bool>;
|
||||||
|
@ -50,9 +51,11 @@ provide_kindflag_path!(IsAnnotation, "annotation.is_annotation");
|
||||||
impl Annotateable for Entry {
|
impl Annotateable for Entry {
|
||||||
|
|
||||||
/// Annotate an entry, returns the new entry which is used to annotate
|
/// Annotate an entry, returns the new entry which is used to annotate
|
||||||
fn annotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result<FileLockEntry<'a>> {
|
fn annotate<'a>(&mut self, store: &'a Store) -> Result<FileLockEntry<'a>> {
|
||||||
use module_path::ModuleEntryPath;
|
let ann_name = Uuid::new_v4().to_hyphenated().to_string();
|
||||||
store.retrieve(ModuleEntryPath::new(ann_name).into_storeid()?)
|
debug!("Creating annotation with name = {}", ann_name);
|
||||||
|
|
||||||
|
store.retrieve(ModuleEntryPath::new(ann_name.clone()).into_storeid()?)
|
||||||
.and_then(|mut anno| {
|
.and_then(|mut anno| {
|
||||||
{
|
{
|
||||||
let _ = anno.set_isflag::<IsAnnotation>()?;
|
let _ = anno.set_isflag::<IsAnnotation>()?;
|
||||||
|
@ -70,25 +73,19 @@ impl Annotateable for Entry {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks the current entry for all annotations and removes the one where the name is
|
// Removes the annotation `ann_name` from the current entry.
|
||||||
/// `ann_name`, which is then returned
|
// Fails if there's no such annotation entry or if the link to that annotation entry does not
|
||||||
|
// exist.
|
||||||
fn denotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result<Option<FileLockEntry<'a>>> {
|
fn denotate<'a>(&mut self, store: &'a Store, ann_name: &str) -> Result<Option<FileLockEntry<'a>>> {
|
||||||
for annotation in self.annotations(store)? {
|
if let Some(mut annotation) = store.get(ModuleEntryPath::new(ann_name).into_storeid()?)? {
|
||||||
let mut anno = annotation?;
|
let _ = self.remove_internal_link(&mut annotation)?;
|
||||||
let name = match anno.get_header().read_string("annotation.name")? {
|
Ok(Some(annotation))
|
||||||
Some(ref name) => name.clone(),
|
} else {
|
||||||
None => continue,
|
// error: annotation does not exist
|
||||||
};
|
Err(format_err!("Annotation '{}' does not exist", ann_name)).map_err(Error::from)
|
||||||
|
|
||||||
if name == ann_name {
|
|
||||||
let _ = self.remove_internal_link(&mut anno)?;
|
|
||||||
return Ok(Some(anno));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(None)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Get all annotations of an entry
|
/// Get all annotations of an entry
|
||||||
fn annotations<'a>(&self, store: &'a Store) -> Result<AnnotationIter<'a>> {
|
fn annotations<'a>(&self, store: &'a Store) -> Result<AnnotationIter<'a>> {
|
||||||
self.get_internal_links()
|
self.get_internal_links()
|
||||||
|
|
|
@ -18,21 +18,17 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
use libimagstore::store::Store;
|
use libimagstore::store::Store;
|
||||||
|
use libimagstore::storeid::StoreIdIterator;
|
||||||
|
|
||||||
use failure::Fallible as Result;
|
use failure::Fallible as Result;
|
||||||
use iter::*;
|
|
||||||
|
|
||||||
pub trait AnnotationFetcher<'a> {
|
|
||||||
|
|
||||||
fn all_annotations(&'a self) -> Result<AnnotationIter<'a>>;
|
|
||||||
|
|
||||||
|
pub trait AnnotationFetcher {
|
||||||
|
fn all_annotations(&self) -> Result<StoreIdIterator>;
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> AnnotationFetcher<'a> for Store {
|
impl<'a> AnnotationFetcher for Store {
|
||||||
|
fn all_annotations(&self) -> Result<StoreIdIterator> {
|
||||||
fn all_annotations(&'a self) -> Result<AnnotationIter<'a>> {
|
self.entries().map(|iter| iter.in_collection("annotation").without_store())
|
||||||
Ok(AnnotationIter::new(self.entries()?.without_store(), self))
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,9 @@
|
||||||
|
|
||||||
extern crate toml;
|
extern crate toml;
|
||||||
extern crate toml_query;
|
extern crate toml_query;
|
||||||
extern crate failure;
|
#[macro_use] extern crate failure;
|
||||||
|
#[macro_use] extern crate log;
|
||||||
|
extern crate uuid;
|
||||||
|
|
||||||
#[macro_use] extern crate libimagstore;
|
#[macro_use] extern crate libimagstore;
|
||||||
extern crate libimagerror;
|
extern crate libimagerror;
|
||||||
|
|
Loading…
Reference in a new issue