Customer

Struct Customer 

Source
pub struct Customer {
    pub href: Option<String>,
    pub id: Option<String>,
    pub name: Option<String>,
    pub status: Option<String>,
    pub status_reason: Option<String>,
    pub valid_for: Option<TimePeriod>,
    /* private fields */
}
Expand description

Customer object

Fields§

§href: Option<String>

Html Reference to this object

§id: Option<String>

Unique Id

§name: Option<String>

Name of this

§status: Option<String>

Customer status

§status_reason: Option<String>

Reason for current status

§valid_for: Option<TimePeriod>

Validity of this record

Implementations§

Source§

impl Customer

Source

pub fn new(org: Organization) -> Customer

Create new customer object against an Organization (legal entity)

#[cfg(all(feature = "tmf632", feature = "build-V4"))]
#[cfg(all(feature = "tmf632", feature = "build-V5"))]
let org = Organization::new("Legal Entity");
let cust = Customer::new(org);
Examples found in repository?
examples/create_party_role.rs (line 23)
20fn main() {
21    let individual = Individual::new("John Smith");
22    let organisation = Organization::new("A Customer".to_string());
23    let customer = Customer::new(organisation);
24    let mut role = PartyRole::new("Account Manager", RelatedParty::from(&individual));
25    role.add_party(RelatedParty::from(&customer));
26    dbg!(role);
27}
More examples
Hide additional examples
examples/create_catalog.rs (line 15)
13fn main() {
14    let org = Organization::new("A Customer");
15    let cust = Customer::new(org);
16    let mut catalog = Catalog::new("Customer A Catalog");
17    let rel_party = RelatedParty::from(&cust);
18    let cat = Category::new("Customer Category");
19    catalog.add_party(rel_party);
20    catalog.add_category(CategoryRef::from(&cat));
21
22    dbg!(catalog);
23}
examples/create_poq.rs (line 23)
19fn main() {
20    #[cfg(all(feature = "tmf679", feature = "build-V4"))]
21    {
22        let org = Organization::new("ACustomer");
23        let customer = Customer::new(org);
24        let offering = ProductOffering::new("MyOffer");
25        let mut poq = ProductOfferingQualification::new(Some(ProductOfferingRef::from(offering)));
26        poq.add_party(RelatedParty::from(&customer));
27
28        dbg!(poq);
29    }
30}
examples/create_product_order.rs (line 34)
28fn main() {
29    #[cfg(all(feature = "tmf622", feature = "build-V4"))]
30    {
31        // This example simple creates in memory structures without reference to any persistence
32        let offer = ProductOffering::new("Sample Offering");
33        let org = Organization::new("ACustomer");
34        let customer = Customer::new(org);
35        let mut person = Individual::new("John Smith");
36        person.add_contact(ContactMedium::email("John.Smith@example.com"));
37        let mut order = ProductOrder::new();
38        order.add_order_item(ProductOrderItem::from(offer));
39        order.add_party(RelatedParty::from(&customer));
40        order.add_party(RelatedParty::from(&person));
41        dbg!(order);
42    }
43}
Source

pub fn generate_code(&mut self, offset: Option<u32>)

Geneate a unique customer code via cryptographic functions Uses crate::gen_code.

Examples found in repository?
examples/create_customer.rs (line 14)
7fn main() {
8    // let org = Organization::new("ACustomer");
9    // let customer = Customer::new(org);
10
11    // dbg!(&customer);
12    let mut customer = Customer::default();
13    customer.set_id("1");
14    customer.generate_code(None);
15    customer.generate_href();
16    customer.set_market_segment("Health Industry");
17    dbg!(&customer);
18
19    customer.upgrade_to_code(None);
20    dbg!(customer);
21}
More examples
Hide additional examples
examples/validate_customer_code.rs (line 10)
5fn main() -> Result<(), String> {
6    let mut cust1 = Customer::default();
7
8    cust1.set_name("NATIONAL BEVERAGE COMPANY LIMITED");
9    cust1.id = Some(String::from("123456"));
10    cust1.generate_code(None);
11
12    let code1 = cust1
13        .get_characteristic("code")
14        .ok_or(String::from("No Value"))?;
15    let hash = cust1
16        .get_characteristic("hash")
17        .ok_or(String::from("No Value"))?;
18
19    println!(
20        "Customer: {} + ID: {} Offset=0\t generates Code: {}",
21        cust1.get_name(),
22        cust1.get_id(),
23        code1.value
24    );
25    println!("Customer: {},\tBase32: {}", cust1.get_name(), hash.value);
26
27    cust1.generate_code(Some(1));
28
29    let code1 = cust1
30        .get_characteristic("code")
31        .ok_or(String::from("No Value"))?;
32    let hash = cust1
33        .get_characteristic("hash")
34        .ok_or(String::from("No Value"))?;
35
36    println!(
37        "Customer: {} + ID: {} Offset=1\t generates Code: {}",
38        cust1.get_name(),
39        cust1.get_id(),
40        code1.value
41    );
42    println!("Customer: {},\tBase32: {}", cust1.get_name(), hash.value);
43
44    Ok(())
45}
Source

pub fn get_characteristic(&self, characteristic: &str) -> Option<Characteristic>

Try to find characteristic with given name

Examples found in repository?
examples/validate_customer_code.rs (line 13)
5fn main() -> Result<(), String> {
6    let mut cust1 = Customer::default();
7
8    cust1.set_name("NATIONAL BEVERAGE COMPANY LIMITED");
9    cust1.id = Some(String::from("123456"));
10    cust1.generate_code(None);
11
12    let code1 = cust1
13        .get_characteristic("code")
14        .ok_or(String::from("No Value"))?;
15    let hash = cust1
16        .get_characteristic("hash")
17        .ok_or(String::from("No Value"))?;
18
19    println!(
20        "Customer: {} + ID: {} Offset=0\t generates Code: {}",
21        cust1.get_name(),
22        cust1.get_id(),
23        code1.value
24    );
25    println!("Customer: {},\tBase32: {}", cust1.get_name(), hash.value);
26
27    cust1.generate_code(Some(1));
28
29    let code1 = cust1
30        .get_characteristic("code")
31        .ok_or(String::from("No Value"))?;
32    let hash = cust1
33        .get_characteristic("hash")
34        .ok_or(String::from("No Value"))?;
35
36    println!(
37        "Customer: {} + ID: {} Offset=1\t generates Code: {}",
38        cust1.get_name(),
39        cust1.get_id(),
40        code1.value
41    );
42    println!("Customer: {},\tBase32: {}", cust1.get_name(), hash.value);
43
44    Ok(())
45}
Source

pub fn replace_characteristic( &mut self, characteristic: Characteristic, ) -> Option<Characteristic>

Replace a characteristic returning the old value if found. Creates the characteristic array if it doesn’t exist. Creates the characteristic entry if it doesn’t exist. Replaces the characteristic entry if it does exist.

§Returns

Will return the previous value if it existed. This

§Example
let mut cust = Customer::default();
let char = Characteristic::from(("Validated","NotYet"));
let old_char = cust.replace_characteristic(char);

assert_eq!(old_char.is_none(),true);
Source

pub fn name(&mut self, name: String)

Set the name of the customer

Source

pub fn set_market_segment( &mut self, segment: impl Into<String>, ) -> Option<Characteristic>

Set the market segment

Examples found in repository?
examples/create_customer.rs (line 16)
7fn main() {
8    // let org = Organization::new("ACustomer");
9    // let customer = Customer::new(org);
10
11    // dbg!(&customer);
12    let mut customer = Customer::default();
13    customer.set_id("1");
14    customer.generate_code(None);
15    customer.generate_href();
16    customer.set_market_segment("Health Industry");
17    dbg!(&customer);
18
19    customer.upgrade_to_code(None);
20    dbg!(customer);
21}
Source

pub fn get_market_segment(&self) -> Option<Characteristic>

Get the market segment

Source

pub fn upgrade_to_code(&mut self, offset: Option<u32>) -> Option<Characteristic>

Upgrade the customer to a cryptographic code to replace a sequential Id. Will return the newly generated cryptographic code. Takes the following steps:

  • Moves existing ID into characteristic of ‘Id’
  • Generate cryptographic code via generate_code
  • Replace Id, with newly genreated code.
  • Returns new code.
§Returns

Will return the new code.

§Example
let mut cust = Customer::default();
cust.set_id("1");
let char = cust.upgrade_to_code(None);
Examples found in repository?
examples/create_customer.rs (line 19)
7fn main() {
8    // let org = Organization::new("ACustomer");
9    // let customer = Customer::new(org);
10
11    // dbg!(&customer);
12    let mut customer = Customer::default();
13    customer.set_id("1");
14    customer.generate_code(None);
15    customer.generate_href();
16    customer.set_market_segment("Health Industry");
17    dbg!(&customer);
18
19    customer.upgrade_to_code(None);
20    dbg!(customer);
21}

Trait Implementations§

Source§

impl Clone for Customer

Source§

fn clone(&self) -> Customer

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Customer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Customer

Source§

fn default() -> Customer

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Customer

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl EventPayload<CustomerEvent> for Customer

Source§

type Subject = Customer

Object the event pertains to
Source§

type EventType = CustomerEventType

Type of event generated
Source§

fn to_event( &self, event_type: Self::EventType, ) -> Event<CustomerEvent, Self::EventType>

Convert the item into an event
Source§

impl From<&Customer> for RelatedParty

Source§

fn from(cust: &Customer) -> Self

Converts to this type from the input type.
Source§

impl From<&Organization> for Customer

Source§

fn from(value: &Organization) -> Self

Converts to this type from the input type.
Source§

impl HasId for Customer

Source§

fn generate_id(&mut self)

Generate and store a new ID. This will also regenerated the HREF field via generate_href()
Source§

fn generate_href(&mut self)

Generate a new HTML reference. Read more
Source§

fn get_id(&self) -> String

Extract the id of this object into a new String
Source§

fn get_href(&self) -> String

Extract the HREF of this object into a new String
Source§

fn get_class() -> String

Get the class of this object. This is also used to form part of the URL via generate_href()
Source§

fn get_class_href() -> String

Get Class HREF, this represents the generate path to the class.
Source§

fn get_mod_path() -> String

Get the module path
Source§

fn set_id(&mut self, id: impl Into<String>)

Set the id on the object, also triggers generate_href().
Source§

fn id(self, id: impl Into<String>) -> Self

Builder pattern to set id on create() NB: This can be used to set an explicit id on create instead of auto-generate via [create]
Source§

fn get_uuid() -> String

Get a new UUID in simple format (no seperators)
Source§

fn get_full_href(&self, hostname: impl Into<String>) -> String

Generate a complete URL for a given hostname
Source§

fn create() -> Self

Create a new instance of a TMF object that has id and href fields. Read more
Source§

impl HasName for Customer

Source§

fn get_name(&self) -> String

Return name of object
Source§

fn set_name(&mut self, name: impl Into<String>)

Set the name, trimming any whitespace
Source§

fn name(self, name: impl Into<String>) -> Self

Builder pattern to set name on create, usually coverered by new()
Source§

fn find(&self, pattern: &str) -> bool

Match against the name
Source§

fn as_entity(&self) -> EntityRef

Return a EntityRef for this object
Source§

impl HasReference for Customer

Source§

type RefType = RelatedParty

Reference type assocaited with Self.
Source§

fn as_ref(&self) -> Option<Self::RefType>

Return a reference version of an object, if none exists, return None.
Source§

fn as_entity_ref(&self) -> RelatedEntity

Get object as an EntityRef
Source§

impl HasValidity for Customer

Source§

fn get_validity(&self) -> Option<TimePeriod>

Get the current validity, might not be set
Source§

fn get_validity_end(&self) -> Option<TimeStamp>

Get the end of the validity period, might not be set
Source§

fn get_validity_start(&self) -> Option<TimeStamp>

Get the start of the validity period, might not be set
Source§

fn set_validity(&mut self, validity: TimePeriod)

Set the validity by passing in a TimePeriod
Source§

fn set_validity_end(&mut self, end: TimeStamp) -> TimePeriod

Set only the end of the validty period, returns updated TimePeriod
Source§

fn set_validity_start(&mut self, start: TimeStamp) -> TimePeriod

Set only the start of the validity period, returns updated TimePeriod
Source§

fn is_valid(&self) -> bool

Return true as follows: Read more
Source§

fn validity(self, validity: TimePeriod) -> Self

Builder pattern function to add validity on create
Source§

impl Serialize for Customer

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TMFEvent<CustomerEvent> for Customer

Source§

fn event(&self) -> CustomerEvent

Geneate container for an TMF payload to be used in an event

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,