Exists Event for internal operations

This commit is contained in:
William Brown 2019-01-20 10:05:28 +10:00
parent 7fa2fccd15
commit a9f2bb4c11
2 changed files with 44 additions and 5 deletions

View file

@ -9,6 +9,8 @@ use error::OperationError;
// FIXME: Remove seralising here - each type should
// have it's own result type!
// TODO: Every event should have a uuid for logging analysis
#[derive(Debug)]
pub struct OpResult {}
@ -107,3 +109,22 @@ impl CreateEvent {
}
}
}
#[derive(Debug)]
pub struct ExistsEvent {
pub filter: Filter,
pub internal: bool
}
impl Message for ExistsEvent {
type Result = Result<OpResult, OperationError>;
}
impl ExistsEvent {
pub fn new_internal(filter: Filter) -> Self {
ExistsEvent {
filter: filter,
internal: true,
}
}
}

View file

@ -11,7 +11,7 @@ use be::{
use entry::Entry;
use error::OperationError;
use event::{CreateEvent, OpResult, SearchEvent, SearchResult};
use event::{CreateEvent, OpResult, SearchEvent, SearchResult, ExistsEvent};
use filter::Filter;
use log::EventLog;
use plugins::Plugins;
@ -191,12 +191,30 @@ pub trait QueryServerReadTransaction {
res
}
// Specialisation of search for exists or not
fn internal_exists(&self, filter: Filter) -> Result<bool, ()> {
unimplemented!()
fn exists(&self, au: &mut AuditScope, ee: &ExistsEvent) -> Result<bool, OperationError> {
let mut audit_be = AuditScope::new("backend_exists");
let res = self
.get_be_txn()
.exists(&mut audit_be, &ee.filter)
.map(|r| r)
.map_err(|_| OperationError::Backend);
au.append_scope(audit_be);
res
}
fn internal_search(&self, filter: Filter) -> Result<(), ()> {
// From internal, generate an exists event and dispatch
fn internal_exists(&self, au: &mut AuditScope, filter: Filter) -> Result<bool, OperationError> {
let mut audit_int = AuditScope::new("internal_exists");
// Build an exists event
let ee = ExistsEvent::new_internal(filter);
// Submit it
let res = self.exists(&mut audit_int, &ee);
au.append_scope(audit_int);
// return result
res
}
fn internal_search(&self, au: &mut AuditScope, filter: Filter) -> Result<(), ()> {
unimplemented!()
}
}