|
|
@ -81,8 +81,8 @@ impl Storage { |
|
|
|
|
|
|
|
|
|
|
|
/// Define a relation between two data objects
|
|
|
|
/// Define a relation between two data objects
|
|
|
|
pub fn define_relation(&mut self, mut rel: model::RelationModel) -> Result<ID, StorageError> { |
|
|
|
pub fn define_relation(&mut self, mut rel: model::RelationModel) -> Result<ID, StorageError> { |
|
|
|
if rel.name.is_empty() { |
|
|
|
if rel.name.is_empty() || rel.reciprocal_name.is_empty() { |
|
|
|
return Err(StorageError::ConstraintViolation("name must not be empty".into())); |
|
|
|
return Err(StorageError::ConstraintViolation("names must not be empty".into())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !self.obj_models.contains_key(&rel.object) { |
|
|
|
if !self.obj_models.contains_key(&rel.object) { |
|
|
@ -378,6 +378,10 @@ impl Storage { |
|
|
|
|
|
|
|
|
|
|
|
// Updates
|
|
|
|
// Updates
|
|
|
|
pub fn update_object(&mut self, model : ObjectModel) -> Result<(), StorageError> { |
|
|
|
pub fn update_object(&mut self, model : ObjectModel) -> Result<(), StorageError> { |
|
|
|
|
|
|
|
if model.name.is_empty() { |
|
|
|
|
|
|
|
return Err(StorageError::ConstraintViolation(format!("Model name must not be empty.").into())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if !self.obj_models.contains_key(&model.id) { |
|
|
|
if !self.obj_models.contains_key(&model.id) { |
|
|
|
return Err(StorageError::NotExist(format!("Object model ID {} does not exist.", model.id).into())); |
|
|
|
return Err(StorageError::NotExist(format!("Object model ID {} does not exist.", model.id).into())); |
|
|
|
} |
|
|
|
} |
|
|
@ -391,6 +395,10 @@ impl Storage { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
pub fn update_relation(&mut self, mut rel : RelationModel) -> Result<(), StorageError> { |
|
|
|
pub fn update_relation(&mut self, mut rel : RelationModel) -> Result<(), StorageError> { |
|
|
|
|
|
|
|
if rel.name.is_empty() || rel.reciprocal_name.is_empty() { |
|
|
|
|
|
|
|
return Err(StorageError::ConstraintViolation(format!("Relation names must not be empty.").into())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Object and Related can't be changed, so we re-fill them from the existing model
|
|
|
|
// Object and Related can't be changed, so we re-fill them from the existing model
|
|
|
|
if let Some(existing) = self.rel_models.get(&rel.id) { |
|
|
|
if let Some(existing) = self.rel_models.get(&rel.id) { |
|
|
|
rel.object = existing.object; |
|
|
|
rel.object = existing.object; |
|
|
|