-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #189 from rruckley/RelatedEntity-188
Add RelatedEntity
- Loading branch information
Showing
4 changed files
with
95 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,17 @@ | ||
//! Create Document Example | ||
//! | ||
use tmflib::tmf667::document::Document; | ||
use tmflib::tmf651::agreement::Agreement; | ||
|
||
fn main() { | ||
let agreement = Agreement::new("My Aggreement"); | ||
|
||
let doc = Document::new("My Document") | ||
.doc_type("PDF"); | ||
.doc_type("PDF") | ||
.link(agreement); | ||
|
||
|
||
// doc.link_entity(agreement); | ||
|
||
dbg!(doc); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
//! Related Entity Module | ||
use serde::{Deserialize,Serialize}; | ||
|
||
use crate::Uri; | ||
use crate::HasName; | ||
|
||
/// Reference to another TMF schema | ||
#[derive(Clone,Default,Debug,Deserialize,Serialize)] | ||
pub struct RelatedEntity { | ||
/// Referenced Name | ||
pub name : String, | ||
/// Referenced Id | ||
pub id : String, | ||
/// Referenced HREF | ||
pub href : Uri, | ||
/// Referenced Role | ||
pub role : Option<String>, | ||
/// Referred Type | ||
pub referred_type: String, | ||
} | ||
|
||
/// Generate a related entity from any TMF object that has implemented HasName trait | ||
impl<T : HasName> From<T> for RelatedEntity { | ||
fn from (value: T) -> Self { | ||
RelatedEntity { | ||
name : value.get_name(), | ||
id : value.get_id(), | ||
href: value.get_href(), | ||
referred_type: T::get_class(), | ||
..Default::default() | ||
} | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
use crate::tmf651::agreement::Agreement; | ||
use crate::{HasId,HasName}; | ||
|
||
use super::RelatedEntity; | ||
|
||
const AGREEMENT_NAME : &str = "AnAgreement"; | ||
|
||
#[test] | ||
fn test_relatedentity_from() { | ||
let agreement = Agreement::new(AGREEMENT_NAME); | ||
let agree_ref = &agreement; | ||
|
||
let entity = RelatedEntity::from(agreement.clone()); | ||
|
||
assert_eq!(entity.name,agree_ref.get_name()); | ||
assert_eq!(entity.id,agree_ref.get_id().as_str()); | ||
assert_eq!(entity.href,agree_ref.get_href().as_str()); | ||
assert_eq!(entity.referred_type,Agreement::get_class()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters