use crate::research::artifact::ResearchArtifact;
use crate::research::citation::CitationMetadata;
use serde::{Deserialize, Serialize};
use super::identifiers::RelatedIdentifier;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ResourceType {
Dataset,
Software,
Publication,
Presentation,
Poster,
Image,
Video,
Other,
}
impl ResourceType {
pub fn from_artifact_type(artifact_type: crate::research::artifact::ArtifactType) -> Self {
use crate::research::artifact::ArtifactType;
match artifact_type {
ArtifactType::Dataset => Self::Dataset,
ArtifactType::Model | ArtifactType::Code => Self::Software,
ArtifactType::Paper => Self::Publication,
ArtifactType::Notebook | ArtifactType::Workflow => Self::Other,
}
}
pub fn zenodo_type(&self) -> &'static str {
match self {
Self::Dataset => "dataset",
Self::Software => "software",
Self::Publication => "publication",
Self::Presentation => "presentation",
Self::Poster => "poster",
Self::Image => "image",
Self::Video => "video",
Self::Other => "other",
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DepositMetadata {
pub title: String,
pub description: String,
pub authors: Vec<String>,
pub keywords: Vec<String>,
pub license: String,
pub resource_type: ResourceType,
pub related_identifiers: Vec<RelatedIdentifier>,
}
impl DepositMetadata {
pub fn from_artifact(artifact: &ResearchArtifact) -> Self {
Self {
title: artifact.title.clone(),
description: artifact
.description
.clone()
.unwrap_or_else(|| format!("{} - {}", artifact.title, artifact.artifact_type)),
authors: artifact.authors.iter().map(|a| a.name.clone()).collect(),
keywords: artifact.keywords.clone(),
license: artifact.license.to_string().to_lowercase(),
resource_type: ResourceType::from_artifact_type(artifact.artifact_type),
related_identifiers: artifact
.doi
.iter()
.map(RelatedIdentifier::is_identical_to)
.collect(),
}
}
pub fn from_citation(citation: &CitationMetadata) -> Self {
let mut metadata = Self::from_artifact(&citation.artifact);
if let Some(url) = &citation.url {
metadata.related_identifiers.push(RelatedIdentifier::is_supplement_to(url));
}
metadata
}
}