Skip to content

Commit

Permalink
Merge pull request #236 from rruckley/bug-events-235
Browse files Browse the repository at this point in the history
Bug: Events
  • Loading branch information
rruckley authored Feb 7, 2025
2 parents 610260d + 42a68b1 commit cf563d4
Show file tree
Hide file tree
Showing 12 changed files with 498 additions and 62 deletions.
3 changes: 1 addition & 2 deletions src/common/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
use serde::{Deserialize, Serialize};
use crate::{
HasId,
HasName,
TMFEvent
};

Expand Down Expand Up @@ -59,7 +58,7 @@ impl<T,U> Event<T,U> {
/// Trait for types that can generate an event
pub trait EventPayload<T> {
/// Object the event pertains to
type Subject : HasId + HasName + TMFEvent<T>;
type Subject : HasId + TMFEvent<T>;
/// Type of event generated
type EventType;
/// Convert the item into an event
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ pub trait HasRelatedParty : HasId {
}

/// Trait for generating an event
pub trait TMFEvent<T> : HasId + HasName {
pub trait TMFEvent<T> : HasId {
/// Geneate container for an TMF payload to be used in an event
fn event(&self) -> T;
}
Expand Down
44 changes: 2 additions & 42 deletions src/tmf620/catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,39 +79,6 @@ pub struct Catalog {
r#type : Option<String>,
}

// impl HasRelatedParty for Catalog {
// fn add_party(&mut self, party : RelatedParty) {
// match self.related_party.as_mut() {
// Some(v) => v.push(party),
// None => self.related_party = Some(vec![party]),
// }
// }
// fn get_by_role(&self, role : String) -> Option<Vec<&RelatedParty>> {
// match &self.related_party {
// Some(rp) => {
// let out = rp.iter()
// .filter(|p| p.role.is_some())
// .filter(|p| p.role.clone().unwrap() == role)
// .collect();
// Some(out)
// },
// None => None,
// }
// }
// fn get_party(&self, idx : usize ) -> Option<&RelatedParty> {
// match self.related_party.as_ref() {
// Some(rp) => {
// // Simple return results of get()
// rp.get(idx)
// },
// None => None,
// }
// }
// fn remove_party(&mut self, idx : usize) -> Result<RelatedParty,String> {
// Ok(self.related_party.as_mut().unwrap().remove(idx))
// }
// }

impl Catalog {
/// Create a new instance of catalog struct
pub fn new(name : impl Into<String>) -> Catalog {
Expand Down Expand Up @@ -160,9 +127,10 @@ impl EventPayload<CatalogEvent> for Catalog {
fn to_event(&self,event_type : CatalogEventType) -> Event<CatalogEvent,CatalogEventType> {
let now = Utc::now();
let event_time = chrono::DateTime::from_timestamp(now.timestamp(),0).unwrap();
let desc = format!("{:?} for {}",event_type,self.get_name());
Event {
correlation_id: None,
description: None,
description: Some(desc),
domain: Some(Catalog::get_class()),
event_id: Uuid::new_v4().to_string(),
field_path: None,
Expand Down Expand Up @@ -190,14 +158,6 @@ pub enum CatalogEventType {
CatalogBatchEvent,
}

// Notifications
/// Catalog created Event
pub struct CatalogCreateEvent {}
/// Catalog Deteted Event
pub struct CatalogDeleteEvent {}
/// Catalog Batch Event
pub struct CatalogBatchEvent {}

#[cfg(test)]
mod tests {

Expand Down
50 changes: 50 additions & 0 deletions src/tmf620/category.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use crate::tmf620::product_offering::ProductOfferingRef;
#[cfg(all(feature = "tmf620",feature = "build-V5"))]
use crate::tmf620::product_offering_v5::ProductOfferingRef;

use chrono::Utc;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use super::MOD_PATH;
use crate::{
Expand All @@ -17,8 +19,10 @@ use crate::{
HasDescription,
TimePeriod,
LIB_PATH,
TMFEvent,
Uri,
};
use crate::common::event::{Event,EventPayload};
use tmflib_derive::{
HasDescription,
HasId,
Expand Down Expand Up @@ -151,6 +155,52 @@ impl Category {
}
}

/// Container for the payload that generated the event
#[derive(Clone,Debug,Default,Deserialize,Serialize)]
pub struct CategoryEvent {
/// Impacted Category
pub category: Category,
}

impl TMFEvent<CategoryEvent> for Category {
fn event(&self) -> CategoryEvent {
CategoryEvent {
category: self.clone(),
}
}
}

impl EventPayload<CategoryEvent> for Category {
type Subject = Category;
type EventType = CategoryEventType;

fn to_event(&self,event_type : Self::EventType) -> Event<CategoryEvent,Self::EventType> {
let now = Utc::now();
let event_time = chrono::DateTime::from_timestamp(now.timestamp(),0).unwrap();
Event {
domain: Some(Category::get_class()),
event_id: Uuid::new_v4().to_string(),
href: self.href.clone(),
id: self.id.clone(),
title: self.name.clone(),
event_time: event_time.to_string(),
event_type,
event: self.event(),
..Event::default()
}
}
}

/// Category Event Type
#[derive(Clone,Default,Debug)]
pub enum CategoryEventType {
/// Category Created
#[default]
CategoryCreateEvent,
/// Category Deleted
CategoryDeleteEvent,
}

#[cfg(test)]
mod tests {
use super::Category;
Expand Down
56 changes: 55 additions & 1 deletion src/tmf620/product_offering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,19 @@ use crate::{
TimePeriod,
DateTime,
Uri,
TMFEvent,
vec_insert,
LIB_PATH,
};

use super::product_offering_price::ProductOfferingPriceRef;
use chrono::Utc;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use super::{ChannelRef,MarketSegmentRef,PlaceRef,SLARef};
use crate::tmf651::agreement::AgreementRef;

use crate::common::event::{Event,EventPayload};
use tmflib_derive::{
HasId,
HasDescription,
Expand Down Expand Up @@ -269,6 +272,57 @@ impl ProductOffering {
}
}

// Events
/// Product Specification Event Container
#[derive(Clone,Debug,Default,Deserialize,Serialize)]
pub struct ProductOfferingEvent {
product_specification: ProductOffering,
}

impl TMFEvent<ProductOfferingEvent> for ProductOffering {
fn event(&self) -> ProductOfferingEvent {
ProductOfferingEvent {
product_specification: self.clone(),
}
}
}

impl EventPayload<ProductOfferingEvent> for ProductOffering {
type Subject = ProductOffering;
type EventType = ProductOfferingEvent;
fn to_event(&self,event_type : Self::EventType) -> Event<ProductOfferingEvent,Self::EventType> {
let now = Utc::now();
let event_time = chrono::DateTime::from_timestamp(now.timestamp(),0).unwrap();
let desc = format!("{:?} for {}",event_type,self.get_name());
Event {
description: Some(desc),
domain: Some(ProductOffering::get_class()),
event_id: Uuid::new_v4().to_string(),
href: self.href.clone(),
id: self.id.clone(),
title: self.name.clone(),
event_time: event_time.to_string(),
event_type,
event: self.event(),
..Event::default()
}
}
}

/// Product Offering Event Type
#[derive(Clone,Default,Debug)]
pub enum ProductOfferingEventType {
/// Product Offering Created
#[default]
ProductOfferingCreateEvent,
/// Product Offering Attributed Changed
ProductOfferingAttributeValueChangeEvent,
/// Product Offering Status Changed
ProductOfferingStateChangeEvent,
/// Product Offering Deleted
ProductOfferingDeleteEvent,
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
61 changes: 59 additions & 2 deletions src/tmf620/product_offering_price.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
//! Product Offering Price Module
use serde::{Deserialize,Serialize};
use chrono::Utc;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use super::MOD_PATH;
use crate::{HasId,HasName, HasLastUpdate, LIB_PATH, HasValidity, TimePeriod};
use crate::{HasId,HasName, HasLastUpdate, LIB_PATH,TMFEvent,HasValidity, TimePeriod};
use crate::common::money::Money;
use crate::common::tax_item::TaxItem;
use crate::common::event::{Event,EventPayload};
use tmflib_derive::{HasId,HasLastUpdate,HasName, HasValidity};

const CLASS_PATH : &str = "productOfferingPrice";
Expand Down Expand Up @@ -106,6 +109,60 @@ impl ProductOfferingPrice {
}
}

/// Container for the payload that generated the event
#[derive(Clone,Debug,Default,Deserialize,Serialize)]
pub struct ProductOfferingPriceEvent {
/// Struct that this event relates to
pub pop: ProductOfferingPrice,
}

impl TMFEvent<ProductOfferingPriceEvent> for ProductOfferingPrice {
fn event(&self) -> ProductOfferingPriceEvent {
ProductOfferingPriceEvent {
pop : self.clone(),
}
}
}

impl EventPayload<ProductOfferingPriceEvent> for ProductOfferingPrice {
type Subject = ProductOfferingPrice;
type EventType = ProductOfferingPriceEventType;
fn to_event(&self,event_type : ProductOfferingPriceEventType) -> Event<ProductOfferingPriceEvent,ProductOfferingPriceEventType> {
let now = Utc::now();
let event_time = chrono::DateTime::from_timestamp(now.timestamp(),0).unwrap();
let desc = format!("{:?} for {}",event_type,self.get_name());
Event {
correlation_id: None,
description: Some(desc),
domain: Some(ProductOfferingPrice::get_class()),
event_id: Uuid::new_v4().to_string(),
field_path: None,
href: self.href.clone(),
id: self.id.clone(),
title: self.name.clone(),
event_time: event_time.to_string(),
priority: None,
time_occurred: None,
event_type,
event: self.event(),
}
}
}

/// Product Offering Price Event Type
#[derive(Clone,Default,Debug,Deserialize,PartialEq, Serialize)]
pub enum ProductOfferingPriceEventType {
/// POP Created
#[default]
ProductOfferingPriceCreateEvent,
/// POP Attribute Value Changed
ProductOfferingPriceAttributeValueChangeEvent,
/// POP State Changed
ProductOfferingPriceStateChangeEvent,
/// POP Deleted
ProductOfferingPriceDeleteEvent,
}

#[cfg(test)]
mod test {

Expand Down
51 changes: 51 additions & 0 deletions src/tmf620/product_specification.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! Product Specification Module
//!
use chrono::Utc;
use serde::{Deserialize, Serialize};
use uuid::Uuid;

use super::MOD_PATH;

Expand All @@ -13,8 +15,10 @@ use crate::{
HasValidity,
TimePeriod,
HasLastUpdate,
TMFEvent,
Cardinality
};
use crate::common::event::{Event,EventPayload};
use tmflib_derive::{
HasDescription,
HasId,
Expand Down Expand Up @@ -276,6 +280,53 @@ impl From<&ServiceSpecification> for ProductSpecification {
}
}

// Events
/// Product Specification Event Container
#[derive(Clone,Debug,Default,Deserialize,Serialize)]
pub struct ProductSpecificationEvent {
product_specification: ProductSpecification,
}

impl TMFEvent<ProductSpecificationEvent> for ProductSpecification {
fn event(&self) -> ProductSpecificationEvent {
ProductSpecificationEvent {
product_specification: self.clone(),
}
}
}

impl EventPayload<ProductSpecificationEvent> for ProductSpecification {
type Subject = ProductSpecification;
type EventType = ProductSpecificationEventType;
fn to_event(&self,event_type : Self::EventType) -> Event<ProductSpecificationEvent,Self::EventType> {
let now = Utc::now();
let event_time = chrono::DateTime::from_timestamp(now.timestamp(),0).unwrap();
let desc = format!("{:?} for {}",event_type,self.get_name());
Event {
description: Some(desc),
domain: Some(ProductSpecification::get_class()),
event_id: Uuid::new_v4().to_string(),
href: self.href.clone(),
id: self.id.clone(),
title: self.name.clone(),
event_time: event_time.to_string(),
event_type,
event: self.event(),
..Event::default()
}
}
}

/// Product Specification Event Type
#[derive(Clone,Default,Debug)]
pub enum ProductSpecificationEventType {
/// Product Specification Created
#[default]
ProductSpecificationCreateEvent,
/// Product Specification Deleted
ProductSpecificationDeleteEvent,
}

/// Enum to cover value with many types
#[derive(Clone, Default, Debug, Deserialize, Serialize)]
#[serde(untagged)]
Expand Down
Loading

0 comments on commit cf563d4

Please sign in to comment.