Skip to content

Commit

Permalink
add conversion of project (ongoing)
Browse files Browse the repository at this point in the history
  • Loading branch information
subotic committed Sep 6, 2023
1 parent c6d7381 commit 8a9658b
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 10 deletions.
68 changes: 68 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ serde_json = "1" # JSON serialization
tracing = "0.1"
tracing-subscriber = "0.3"
tracing-test = "0.2"
url = { version = "2", features = ["serde"] }
warp = "0.3"

[package]
Expand Down Expand Up @@ -47,6 +48,7 @@ serde_json.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
tracing-test.workspace = true
url.workspace = true

[[bin]]
name = "dsp_meta"
Expand Down
17 changes: 11 additions & 6 deletions src/dsp_meta/domain/convert/project.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use hcl::Expression;
use hcl::{Attribute, Expression};
use tracing::warn;

use crate::domain::{
Expand Down Expand Up @@ -124,14 +124,11 @@ impl TryFrom<Vec<&hcl::Block>> for ExtractedProjectBlocks {
type Error = DspMetaError;

fn try_from(blocks: Vec<&hcl::Block>) -> Result<Self, Self::Error> {
let mut _alternative_names: Vec<&AlternativeName> = vec![];
let mut alternative_names: Vec<&AlternativeName> = vec![];

for block in blocks {
match block.identifier.as_str() {
"alternative_name" => {
println!("alternative_name");
dbg!(block);
}
"alternative_name" => alternative_names.push(&AlternativeName::try_from(&block)?),
"description" => {
println!("description");
dbg!(block);
Expand All @@ -149,6 +146,14 @@ impl TryFrom<Vec<&hcl::Block>> for ExtractedProjectBlocks {
}
}

impl TryFrom<&hcl::Block> for AlternativeName {
type Error = DspMetaError;

fn try_from(block: &hcl::Block) -> Result<Self, Self::Error> {
AlternativeName::default()
}
}

#[cfg(test)]
mod tests {
use hcl::{Identifier, Number};
Expand Down
44 changes: 43 additions & 1 deletion src/dsp_meta/domain/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use std::collections::HashSet;
use std::fmt::Debug;
use std::hash::Hash;

use url::Url as UrlString;

use hcl::Block;

use crate::domain::dataset::Dataset;
Expand Down Expand Up @@ -205,7 +207,7 @@ impl Default for Description {
Self::from(vec![
LangString {
iso_code: IsoCode::DE,
string: String::from("Die default Beschreibung."),
string: String::from("Die Default-Beschreibung."),
},
LangString {
iso_code: IsoCode::EN,
Expand All @@ -232,9 +234,27 @@ impl From<Vec<LangString>> for Description {
}
}

#[derive(Debug, PartialEq, Eq)]
pub struct UrlValue {
pub value: UrlString,
pub text: String,
}

impl Default for UrlValue {
fn default() -> Self {
UrlValue {
value: UrlString::try_from("https://default.xyz").unwrap(),
text: "Default URL description".to_string(),
}
}
}

#[derive(Debug, Default, Clone, PartialEq)]
pub struct HowToCite(String);

#[derive(Debug, Default, PartialEq)]
pub struct Keyword(LangString);

#[derive(Debug, Default, Clone, PartialEq)]
pub struct StartDate(String);

Expand All @@ -250,6 +270,28 @@ pub struct Grants(Vec<Grant>);
#[derive(Debug, Default, PartialEq)]
pub struct Title(String);

#[derive(Debug, Default, PartialEq)]
pub struct Discipline {
discipline_type: DisciplineType,
description: LangString,
url: UrlValue,
}

#[derive(Debug, Default, PartialEq)]
pub enum DisciplineType {
#[default]
Snf,
}

#[derive(Debug, PartialEq)]
pub struct Publication(String);

impl Default for Publication {
fn default() -> Self {
Publication("Default publication".to_string())
}
}

#[cfg(test)]
mod tests {
use hcl::body;
Expand Down
18 changes: 15 additions & 3 deletions src/dsp_meta/domain/project.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use crate::domain::convert::project::{ExtractedProjectAttributes, ExtractedProjectBlocks};
use crate::domain::{
AlternativeNames, CreatedAt, CreatedBy, Description, EndDate, HowToCite, Name, Shortcode,
StartDate, TeaserText,
AlternativeNames, CreatedAt, CreatedBy, Description, Discipline, EndDate, HowToCite, Keyword,
Name, Publication, Shortcode, StartDate, TeaserText, UrlValue,
};
use crate::errors::DspMetaError;

#[derive(Debug, Default, Clone, PartialEq)]
#[derive(Debug, Default, PartialEq)]
pub struct Project {
pub created_at: CreatedAt,
pub created_by: CreatedBy,
Expand All @@ -14,9 +14,13 @@ pub struct Project {
pub alternative_names: AlternativeNames,
pub teaser_text: TeaserText,
pub description: Description,
pub url: UrlValue,
pub how_to_cite: HowToCite,
pub start_date: StartDate,
pub end_date: Option<EndDate>,
pub keywords: Vec<Keyword>,
pub disciplines: Vec<Discipline>,
pub publications: Vec<Publication>,
}

impl TryFrom<&hcl::Block> for Project {
Expand Down Expand Up @@ -74,6 +78,10 @@ impl TryFrom<&hcl::Block> for Project {

let alternative_names = AlternativeNames::default();
let description = Description::default();
let url = UrlValue::default();
let keywords = vec![Keyword::default()];
let disciplines = vec![Discipline::default()];
let publications = vec![Publication::default()];

let project = Project {
created_at,
Expand All @@ -83,9 +91,13 @@ impl TryFrom<&hcl::Block> for Project {
alternative_names,
teaser_text,
description,
url,
how_to_cite,
start_date,
end_date,
keywords,
disciplines,
publications,
};

Ok(project)
Expand Down

0 comments on commit 8a9658b

Please sign in to comment.