Skip to content

Commit

Permalink
Merge pull request #196 from rruckley/TMF634-179
Browse files Browse the repository at this point in the history
TMF634 Additional schema
  • Loading branch information
rruckley authored Nov 13, 2024
2 parents a49eb40 + 5bb70ca commit 303edfe
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 1 deletion.
78 changes: 78 additions & 0 deletions src/tmf634/catalog.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//! Resource Catalog Module
use serde::{Deserialize,Serialize};

const CLASS_PATH : &str = "catalog";

use super::MOD_PATH;

use crate::{
LIB_PATH,
HasId,
HasName,
HasValidity,
HasLastUpdate,
HasDescription,
Uri,
DateTime,
TimePeriod,
};

use tmflib_derive::{
HasId,
HasName,
HasLastUpdate,
HasDescription,
HasValidity,
};

/// Resource Catalog structure
#[derive(Clone,Default,Debug,Deserialize,HasId,HasName,HasLastUpdate,HasDescription,HasValidity,Serialize)]
pub struct Catalog {
/// Cataloge Type
pub catalog_type : Option<String>,
/// Cataloge Description
pub description: Option<String>,
/// HTTP Reference
pub href: Option<Uri>,
/// Unique Identier
pub id: Option<String>,
/// Last Update
pub last_update: Option<DateTime>,
/// Lifecycle status
pub lifecycle_status: Option<String>,
/// Name
pub name: Option<String>,
/// Validity
pub valid_for: Option<TimePeriod>,
/// Version
pub version: Option<String>,
}

impl Catalog {
/// Create a new catalog
pub fn new(name : impl Into<String>) -> Catalog {
Catalog {
name : Some(name.into()),
..Catalog::create()
}
}
}

#[cfg(test)]
mod test {
use super::Catalog;
use crate::HasDescription;

const CATALOG_NAME : &str = "CatalogueName";
const CATALOG_DESC : &str = "CatalogueDescription";

#[test]
fn test_catalog_description() {
let catalog = Catalog::new(CATALOG_NAME)
.description(CATALOG_DESC);

assert_eq!(catalog.description.is_some(),true);
assert_eq!(catalog.get_description().as_str(),CATALOG_DESC);
}
}
8 changes: 7 additions & 1 deletion src/tmf634/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@

//! TMF634 Resource Catalogue Management
#[cfg(feature = "build-V4")]
const MOD_PATH : &str = "resourceCatalog/v4";
#[cfg(feature = "build-V5")]
const MOD_PATH : &str = "resourceCatalog/v5";

pub mod resource_candidate;
pub mod catalog;
pub mod resource_category;
pub mod resource_candidate;
pub mod resource_specification;
4 changes: 4 additions & 0 deletions src/tmf634/resource_category.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//! Resource Category Module
/// Resource Catagory Structure
pub struct ResourceCategory {}
96 changes: 96 additions & 0 deletions src/tmf634/resource_specification.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
//! Resource Specification Module
use serde::{Deserialize,Serialize};
use crate::{
DateTime,
HasDescription,
HasId,
HasLastUpdate,
HasName,
HasValidity,
TimePeriod,
Uri,
LIB_PATH
};

use tmflib_derive::{
HasId,
HasName,
HasDescription,
HasLastUpdate,
HasValidity
};

use crate::common::attachment::AttachmentRefOrValue;
use crate::common::external_identifier::ExternalIdentifier;

use super::MOD_PATH;

const CLASS_PATH: &str = "resourceSpecification";

/// Resource Specification
#[derive(Clone,Default,Debug,Deserialize,HasId,HasName,HasDescription,HasLastUpdate,HasValidity,Serialize)]
pub struct ResourceSpecification {
/// Resource Specification Category
pub category: Option<String>,
/// Description
pub description: Option<String>,
/// Uri for this specification
pub href: Option<Uri>,
/// Unique Id of this specification
pub id: Option<String>,
/// Is this part of a bundle?
pub is_bundle : bool,
/// When was this recort last updated
pub last_update: Option<DateTime>,
/// Current lifecycle status
pub lifecycle_status : Option<String>,
/// Name of the specification
pub name : Option<String>,
/// Validity for this specification
pub valid_for: Option<TimePeriod>,
// Referenced types
/// Attachments
pub attachment : Vec<AttachmentRefOrValue>,
/// External identifiers
pub external_identifier : Vec<ExternalIdentifier>,
/// Features
pub feature : Vec<FeatureSpecification>,
}

impl ResourceSpecification {
/// Create a new specification with the given name
pub fn new(name : impl Into<String>) -> ResourceSpecification {
ResourceSpecification {
name : Some(name.into()),
lifecycle_status : Some(String::from("New")),
..ResourceSpecification::create_with_time()
}
}
}

/// Feature Specification for Resource
#[derive(Clone,Default,Debug,Deserialize,Serialize)]
pub struct FeatureSpecification {
/// Specificaiton Relationships
pub feature_spec_relationship : Vec<FeatureSpecificationRelationship>
}

/// Specification Relationship Type
#[derive(Clone,Default,Debug,Deserialize,Serialize)]
pub struct FeatureSpecificationRelationship {}

#[cfg(test)]
mod test {
use super::*;

const SPEC_NAME : &str = "SpecificationName";

#[test]
fn test_resourcespecification_new() {
let spec = ResourceSpecification::new(SPEC_NAME);

assert_eq!(spec.name.is_some(),true);
assert_eq!(spec.get_name().as_str(),SPEC_NAME);
}
}

0 comments on commit 303edfe

Please sign in to comment.