mirror of
https://github.com/hannobraun/Fornjot
synced 2025-11-28 02:12:08 +00:00
Add ValidationCommand
This is preparation for the validation service to accept more commands.
This commit is contained in:
parent
158ce3a34e
commit
137c2d3e70
@ -11,7 +11,7 @@ use crate::objects::{Object, Objects, WithHandle};
|
||||
pub use self::{
|
||||
objects::{InsertObject, Operation},
|
||||
service::{Service, State},
|
||||
validation::{Validation, ValidationFailed},
|
||||
validation::{Validation, ValidationCommand, ValidationFailed},
|
||||
};
|
||||
|
||||
/// The kernel services
|
||||
@ -46,7 +46,10 @@ impl Services {
|
||||
.execute(Operation::InsertObject { object }, &mut object_events);
|
||||
|
||||
for object_event in object_events {
|
||||
self.validation.execute(object_event, &mut Vec::new());
|
||||
let command = ValidationCommand::ValidateObject {
|
||||
object: object_event.object,
|
||||
};
|
||||
self.validation.execute(command, &mut Vec::new());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,12 @@
|
||||
use std::{collections::BTreeMap, thread};
|
||||
|
||||
use crate::{
|
||||
objects::{BehindHandle, Object},
|
||||
objects::{BehindHandle, Object, WithHandle},
|
||||
storage::ObjectId,
|
||||
validate::ValidationError,
|
||||
};
|
||||
|
||||
use super::{objects::InsertObject, State};
|
||||
use super::State;
|
||||
|
||||
/// Errors that occurred while validating the objects inserted into the stores
|
||||
#[derive(Default)]
|
||||
@ -33,16 +33,18 @@ impl Drop for Validation {
|
||||
}
|
||||
|
||||
impl State for Validation {
|
||||
type Command = InsertObject;
|
||||
type Command = ValidationCommand;
|
||||
type Event = ValidationFailed;
|
||||
|
||||
fn decide(&self, command: Self::Command, events: &mut Vec<Self::Event>) {
|
||||
let ValidationCommand::ValidateObject { object } = command;
|
||||
|
||||
let mut errors = Vec::new();
|
||||
command.object.validate(&mut errors);
|
||||
object.validate(&mut errors);
|
||||
|
||||
for err in errors {
|
||||
events.push(ValidationFailed {
|
||||
object: command.object.clone().into(),
|
||||
object: object.clone().into(),
|
||||
err,
|
||||
});
|
||||
}
|
||||
@ -53,6 +55,15 @@ impl State for Validation {
|
||||
}
|
||||
}
|
||||
|
||||
/// The command accepted by the validation service
|
||||
pub enum ValidationCommand {
|
||||
/// Validate the provided object
|
||||
ValidateObject {
|
||||
/// The object to validate
|
||||
object: Object<WithHandle>,
|
||||
},
|
||||
}
|
||||
|
||||
/// The event produced by the validation service
|
||||
#[derive(Clone)]
|
||||
pub struct ValidationFailed {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user