crossref_client/response/work.rs
1// see https://github.com/Crossref/rest-api-doc/blob/master/api_format.md
2
3use crate::response::{FacetMap, QueryResponse};
4use chrono::{Datelike, NaiveDate};
5use serde::de::Deserializer;
6use serde::{Deserialize, Serialize};
7
8/// The relations a work asserts or is the object of, keyed by relation name.
9///
10/// The names come from the
11/// [crossref relations schema](https://github.com/CrossRef/rest-api-doc/blob/master/api_format.md#relations)
12/// -- `is-review-of`, `is-preprint-of`, `is-identical-to` and so on.
13pub type Relations = std::collections::HashMap<String, RelatedItems>;
14
15/// The related items of one relation kind.
16///
17/// Crossref deposits these as an array, which is why the field used to be typed
18/// as a bare `serde_json::Value`: it had been modelled as a single [`Relation`]
19/// and an array is what actually arrives. A lone object is still accepted and
20/// read as a list of one, so neither shape can cost a page of a crawl.
21#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
22#[serde(transparent)]
23pub struct RelatedItems(pub Vec<Relation>);
24
25impl<'de> Deserialize<'de> for RelatedItems {
26 fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
27 #[derive(Deserialize)]
28 #[serde(untagged)]
29 enum OneOrMany {
30 Many(Vec<Relation>),
31 One(Relation),
32 }
33
34 Ok(match OneOrMany::deserialize(deserializer)? {
35 OneOrMany::Many(items) => RelatedItems(items),
36 OneOrMany::One(item) => RelatedItems(vec![item]),
37 })
38 }
39}
40
41impl std::ops::Deref for RelatedItems {
42 type Target = [Relation];
43
44 fn deref(&self) -> &Self::Target {
45 &self.0
46 }
47}
48
49impl IntoIterator for RelatedItems {
50 type Item = Relation;
51 type IntoIter = std::vec::IntoIter<Relation>;
52
53 fn into_iter(self) -> Self::IntoIter {
54 self.0.into_iter()
55 }
56}
57
58impl<'a> IntoIterator for &'a RelatedItems {
59 type Item = &'a Relation;
60 type IntoIter = std::slice::Iter<'a, Relation>;
61
62 fn into_iter(self) -> Self::IntoIter {
63 self.0.iter()
64 }
65}
66
67/// the payload of a `/works` response, and of the `works` route of any other
68/// component
69#[derive(Debug, Clone, Deserialize, Serialize)]
70#[serde(rename_all = "kebab-case")]
71pub struct WorkList {
72 /// if facets were part of the request they are also included in the response
73 #[serde(default)]
74 pub facets: FacetMap,
75 /// the number of items that match the response
76 pub total_results: usize,
77 /// crossref responses for large number of items are divided in pages, number of elements to expect in `items`
78 pub items_per_page: Option<usize>,
79 /// if a query was set in the request, this will also be part in the response
80 pub query: Option<QueryResponse>,
81 /// all work items that are returned
82 pub items: Vec<Work>,
83 /// deep page through `/works` result sets
84 pub next_cursor: Option<String>,
85}
86
87/// the main return type of the crossref api
88/// represents a publication
89/// based on the [crossref rest-api-doc](https://github.com/CrossRef/rest-api-doc/blob/master/api_format.md#work)
90/// with minor adjustments
91#[derive(Debug, Clone, Deserialize, Serialize)]
92#[serde(rename_all = "kebab-case")]
93pub struct Work {
94 /// Name of work's publisher
95 ///
96 /// Optional for the same reason as [`Work::type_`]: it is deposited by the
97 /// member, not assigned by crossref.
98 pub publisher: Option<String>,
99 /// Work titles, including translated titles
100 ///
101 /// Absent for roughly 5% of works -- most `component` records and a
102 /// scattering of datasets carry no title at all -- so an untitled work
103 /// deserializes to an empty list rather than failing the whole page.
104 #[serde(default)]
105 pub title: Vec<String>,
106 /// Work titles in the work's original publication language
107 pub original_title: Option<Vec<String>>,
108 /// the language of this work
109 pub language: Option<String>,
110 /// Abstract as a JSON string or a JATS XML snippet encoded into a JSON string
111 pub short_title: Option<Vec<String>>,
112 /// Abstract as a JSON string or a JATS XML snippet encoded into a JSON string
113 #[serde(rename = "abstract")]
114 pub abstract_: Option<String>,
115 /// Count of outbound references deposited with Crossref
116 pub references_count: Option<i32>,
117 /// Count of inbound references deposited with Crossref
118 pub is_referenced_by_count: Option<i32>,
119 /// Currently always `Crossref`
120 pub source: Option<String>,
121 /// which issue of the containing journal this work appeared in
122 pub journal_issue: Option<Issue>,
123 /// DOI prefix identifier of the form `http://id.crossref.org/prefix/DOI_PREFIX`
124 pub prefix: Option<String>,
125 /// DOI of the work
126 #[serde(rename = "DOI")]
127 pub doi: String,
128 /// URL form of the work's DOI
129 #[serde(rename = "URL")]
130 pub url: Option<String>,
131 /// Member identifier of the form `http://id.crossref.org/member/MEMBER_ID`
132 ///
133 /// Absent from a handful of records whose depositing member no longer exists.
134 pub member: Option<String>,
135 /// Enumeration, one of the type ids from `https://api.crossref.org/v1/types`
136 ///
137 /// Crossref validates member deposits loosely, so nearly every field can be
138 /// absent from a record -- roughly one work in 20 000 has no type. Only
139 /// [`Work::doi`] is required, and even that assumes the query did not drop
140 /// it with [`WorksQuery::elements`](crate::WorksQuery::elements).
141 #[serde(rename = "type")]
142 pub type_: Option<String>,
143 /// the day this work entry was created
144 ///
145 /// Absent when the query narrowed the response with
146 /// [`WorksQuery::elements`](crate::WorksQuery::elements).
147 pub created: Option<Date>,
148 /// Date on which the DOI was first registered
149 pub date: Option<Date>,
150 /// Date on which the work metadata was most recently updated
151 pub deposited: Option<Date>,
152 /// the score of the publication if any
153 /// not included in the crossrif api spec
154 pub score: Option<f32>,
155 /// Date on which the work metadata was most recently indexed.
156 /// Re-indexing does not imply a metadata change, see `deposited` for the most recent metadata change date
157 ///
158 /// Absent when the query narrowed the response with
159 /// [`WorksQuery::elements`](crate::WorksQuery::elements).
160 pub indexed: Option<Date>,
161 /// Earliest of `published-print` and `published-online`
162 pub issued: Option<PartialDate>,
163 /// ate on which posted content was made available online
164 pub posted: Option<PartialDate>,
165 /// Date on which a work was accepted, after being submitted, during a submission process
166 pub accepted: Option<PartialDate>,
167 /// Work subtitles, including original language and translated
168 pub subtitle: Option<Vec<String>>,
169 /// Full titles of the containing work (usually a book or journal)
170 pub container_title: Option<Vec<String>>,
171 /// Abbreviated titles of the containing work
172 pub short_container_title: Option<Vec<String>>,
173 /// Group title for posted content
174 pub group_title: Option<String>,
175 /// Issue number of an article's journal
176 pub issue: Option<String>,
177 /// Volume number of an article's journal
178 pub volume: Option<String>,
179 /// Pages numbers of an article within its journal
180 pub page: Option<String>,
181 /// the number of the corresponding article
182 pub article_number: Option<String>,
183 /// Date on which the work was published in print
184 pub published_print: Option<PartialDate>,
185 /// Date on which the work was published online
186 pub published_online: Option<PartialDate>,
187 /// Subject category names, a controlled vocabulary from Sci-Val.
188 /// Available for most journal articles
189 pub subject: Option<Vec<String>>,
190 /// ISSNs of the containing journal, print and electronic
191 #[serde(rename = "ISSN")]
192 pub issn: Option<Vec<String>>,
193 /// List of ISSNs with ISSN type information
194 pub issn_type: Option<Vec<ISSN>>,
195 /// ISBNs of the containing book
196 #[serde(rename = "ISBN")]
197 pub isbn: Option<Vec<String>>,
198 /// names of the archives that preserve this work
199 pub archive: Option<Vec<String>>,
200 /// the licenses this work is published under
201 pub license: Option<Vec<License>>,
202 /// the bodies that funded the work, and the awards they made
203 pub funder: Option<Vec<FundingBody>>,
204 /// Crossmark assertions the publisher made about the work
205 pub assertion: Option<Vec<Assertion>>,
206 /// the work's authors, in the order they were deposited
207 pub author: Option<Vec<Contributor>>,
208 /// the editors of the containing work
209 pub editor: Option<Vec<Contributor>>,
210 /// the chairs of the containing proceedings
211 pub chair: Option<Vec<Contributor>>,
212 /// the work's translators
213 pub translator: Option<Vec<Contributor>>,
214 /// works this one is an editorial update to, e.g. a retraction or correction
215 pub update_to: Option<Vec<Update>>,
216 /// Link to an update policy covering Crossmark updates for this work
217 pub update_policy: Option<String>,
218 /// URLs to full-text locations
219 pub link: Option<Vec<ResourceLink>>,
220 /// the clinical trials the work reports on
221 pub clinical_trial_number: Option<Vec<ClinicalTrialNumber>>,
222 /// Other identifiers for the work provided by the depositing member
223 pub alternative_id: Option<Vec<String>>,
224 /// List of references made by the work
225 pub reference: Option<Vec<Reference>>,
226 /// Information on domains that support Crossmark for this work
227 pub content_domain: Option<ContentDomain>,
228 /// Relations to other works
229 pub relation: Option<Relations>,
230 /// Peer review metadata, on works of type `peer-review`
231 pub review: Option<Review>,
232}
233
234impl Work {
235 /// A short citation key for this work, in the common `AuthorYear` style.
236 ///
237 /// Built from the family names of the authors and the issued year:
238 /// `Smith2019` for a single author, `Smith&Jones2019` for two, and
239 /// `SmithEtAl2019` for three or more.
240 ///
241 /// Returns [`None`] if the work carries no author with a family name, or
242 /// no issued date to take a year from.
243 pub fn citekey(&self) -> Option<String> {
244 let authors = self.author.as_deref()?;
245 let family = |c: &Contributor| c.family.clone().unwrap_or_default();
246
247 let names = match authors {
248 [] => return None,
249 [single] => single.family.clone()?,
250 [first, second] => format!("{}&{}", family(first), family(second)),
251 [first, ..] => format!("{}EtAl", family(first)),
252 };
253
254 let year = self.issued.as_ref()?.as_date_field()?.year();
255 Some(format!("{}{}", names, year))
256 }
257}
258
259/// Helper struct to represent dates in the cross ref api as nested arrays of numbers
260#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
261pub struct DateParts(pub Vec<Vec<Option<u32>>>);
262
263impl DateParts {
264 /// converts the nested array of numbers into the corresponding [DateField]
265 /// standalone years are allowed.
266 /// if an array is empty, [None] will be returned
267 pub fn as_date(&self) -> Option<DateField> {
268 /// converts an array of numbers into chrono [NaiveDate] if it contains at least a single value
269 fn naive(v: &[Option<u32>]) -> Option<NaiveDate> {
270 match v.len() {
271 0 => None,
272 1 => NaiveDate::from_ymd_opt(v[0]? as i32, 0, 0),
273 2 => NaiveDate::from_ymd_opt(v[0]? as i32, v[1]?, 0),
274 3 => NaiveDate::from_ymd_opt(v[0]? as i32, v[1]?, v[2]?),
275 _ => None,
276 }
277 }
278
279 match self.0.len() {
280 0 => None,
281 1 => Some(DateField::Single(naive(&self.0[0])?)),
282 2 => Some(DateField::Range {
283 from: naive(&self.0[0])?,
284 to: naive(&self.0[1])?,
285 }),
286 _ => Some(DateField::Multi(
287 self.0
288 .iter()
289 .map(|x| naive(x))
290 .collect::<Option<Vec<_>>>()?,
291 )),
292 }
293 }
294}
295
296/// a body that funded the work, and the awards it made
297#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
298pub struct FundingBody {
299 /// Funding body primary name
300 ///
301 /// Members occasionally deposit a funder entry carrying only an award list.
302 pub name: Option<String>,
303 /// Optional [Open Funder Registry](http://www.crossref.org/fundingdata/registry.html) DOI uniquely identifing the funding body
304 #[serde(rename = "DOI")]
305 pub doi: Option<String>,
306 /// Award number(s) for awards given by the funding body
307 pub award: Option<Vec<String>>,
308 /// Either `crossref` or `publisher`
309 #[serde(rename = "doi-asserted-by")]
310 pub doi_asserted_by: Option<String>,
311}
312
313/// a clinical trial the work reports on
314#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
315pub struct ClinicalTrialNumber {
316 /// Identifier of the clinical trial
317 #[serde(rename = "clinical-trial-number")]
318 pub clinical_trial_number: String,
319 /// DOI of the clinical trial regsitry that assigned the trial number
320 pub registry: String,
321 /// One of `preResults`, `results` or `postResults`
322 #[serde(rename = "type")]
323 pub type_: Option<String>,
324}
325
326/// someone credited on the work: an author, editor, chair or translator
327///
328/// A contributor is either a person, with `family` and usually `given`, or an
329/// organisation, with `name`. Members deposit both, so neither is guaranteed.
330#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
331pub struct Contributor {
332 /// an honorific before the name, e.g. `Prof.`
333 pub prefix: Option<String>,
334 /// a suffix after the name, e.g. `Jr.`
335 pub suffix: Option<String>,
336 /// the family name, for a person
337 pub family: Option<String>,
338 /// the given names, for a person
339 pub given: Option<String>,
340 /// the full name, for an organisation
341 pub name: Option<String>,
342 /// URL-form of an [ORCID](http://orcid.org) identifier
343 #[serde(rename = "ORCID")]
344 pub orcid: Option<String>,
345 /// If true, record owner asserts that the ORCID user completed ORCID OAuth authentication
346 #[serde(rename = "authenticated-orcid")]
347 pub authenticated_orcid: Option<bool>,
348 /// the institutions this contributor is affiliated with
349 pub affiliation: Vec<Affiliation>,
350 /// `first` for the first contributor listed, `additional` for the rest
351 pub sequence: String,
352}
353
354/// an institution a contributor is affiliated with
355#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
356pub struct Affiliation {
357 /// the affiliation's name
358 ///
359 /// Members occasionally deposit a bare `{}` affiliation.
360 pub name: Option<String>,
361 /// identifiers for the institution, in practice [ROR](https://ror.org) ids
362 ///
363 /// How crossref now models affiliations; select works that carry one with
364 /// [`WorksFilter::HasAffiliationRorId`](crate::WorksFilter::HasAffiliationRorId).
365 #[serde(default)]
366 pub id: Vec<InstitutionId>,
367}
368
369/// an identifier for an institution, as deposited on an [`Affiliation`]
370#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
371#[serde(rename_all = "kebab-case")]
372pub struct InstitutionId {
373 /// the identifier itself, e.g. `https://ror.org/00hx57361`
374 pub id: String,
375 /// what kind of identifier it is, in practice always `ROR`
376 pub id_type: Option<String>,
377 /// either `crossref` or `publisher`
378 pub asserted_by: Option<String>,
379}
380
381/// represents full date information for an item
382#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
383#[serde(rename_all = "kebab-case")]
384pub struct Date {
385 /// Contains an ordered array of year, month, day of month.
386 /// Only year is required. Note that the field contains a nested array,
387 /// e.g. [ [ 2006, 5, 19 ] ] to conform to citeproc JSON dates
388 pub date_parts: DateParts,
389 /// Seconds since UNIX epoch
390 pub timestamp: usize,
391 /// ISO 8601 date time
392 pub date_time: String,
393}
394
395impl Date {
396 /// converts the nested array of numbers into the correct representation of chrono [NaiveDate]
397 pub fn as_date_field(&self) -> Option<DateField> {
398 self.date_parts.as_date()
399 }
400}
401
402impl std::fmt::Display for Date {
403 /// Renders the date as `%Y-%m-%d`; ranges as `from-to` and multi dates as a
404 /// comma separated list. An unparsable date renders as the empty string.
405 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
406 match self.as_date_field() {
407 Some(DateField::Single(date)) => write!(f, "{}", date.format("%Y-%m-%d")),
408 Some(DateField::Range { from, to }) => {
409 write!(f, "{}-{}", from.format("%Y-%m-%d"), to.format("%Y-%m-%d"))
410 }
411 Some(DateField::Multi(dates)) => {
412 let joined = dates
413 .iter()
414 .map(|date| date.format("%Y-%m-%d").to_string())
415 .collect::<Vec<_>>()
416 .join(",");
417 f.write_str(&joined)
418 }
419 None => Ok(()),
420 }
421 }
422}
423
424/// represents an incomplete date only consisting of year or year and month
425#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
426pub struct PartialDate {
427 /// Contains an ordered array of year, month, day of month.
428 /// Only year is required
429 /// e.g. `[ [`2006`] ]` to conform to citeproc JSON dates
430 #[serde(rename = "date-parts")]
431 pub date_parts: DateParts,
432}
433
434impl PartialDate {
435 /// converts the nested array of numbers into the correct representation of chrono [NaiveDate]
436 pub fn as_date_field(&self) -> Option<DateField> {
437 self.date_parts.as_date()
438 }
439}
440
441/// Helper struct to capture all possible occurrences of dates in the crossref api, a nested Vec of numbers
442#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
443pub enum DateField {
444 /// only a single date vector
445 Single(NaiveDate),
446 /// two date vectors represent a range
447 Range {
448 /// start date of the range
449 from: NaiveDate,
450 /// end date of the range
451 to: NaiveDate,
452 },
453 /// more than two date vectors are present
454 Multi(Vec<NaiveDate>),
455}
456
457impl DateField {
458 /// The year to cite the work by: the only year for a single date, and the
459 /// first for a range or a list.
460 pub fn year(&self) -> i32 {
461 match self {
462 DateField::Single(date) => date.year(),
463 DateField::Range { from, to: _ } => from.year(),
464 DateField::Multi(dates) => dates[0].year(),
465 }
466 }
467}
468
469/// metadata about when the `Work` entry was updated
470#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
471pub struct Update {
472 /// Date on which the update was published
473 pub updated: PartialDate,
474 /// DOI of the updated work
475 #[serde(rename = "DOI")]
476 pub doi: String,
477 /// The type of update, for example retraction or correction
478 #[serde(rename = "type")]
479 pub type_: String,
480 /// A display-friendly label for the update type
481 pub label: Option<String>,
482}
483
484/// a [Crossmark](https://www.crossref.org/services/crossmark/) claim the
485/// publisher made about the work, e.g. its peer review status or funding
486#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
487pub struct Assertion {
488 /// what is being asserted, as a machine-readable name
489 pub name: String,
490 /// the asserted value
491 pub value: Option<String>,
492 /// a link backing the assertion up
493 #[serde(rename = "URL")]
494 pub url: Option<String>,
495 /// where the assertion is explained
496 pub explanation: Option<Explanation>,
497 /// a display-friendly form of `name`
498 pub label: Option<String>,
499 /// where to place this assertion when displaying the group
500 pub order: Option<i32>,
501 /// the group of assertions this one is displayed under
502 pub group: Option<AssertionGroup>,
503}
504
505/// where a Crossmark assertion is explained
506///
507/// Always a link. The free-text variant this used to carry alongside it was
508/// inferred from the field's original `Option<String>` type rather than
509/// observed, and no free-text explanation turned up in the 38 800 works sampled
510/// from the live api since.
511#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
512pub struct Explanation {
513 /// link to a page describing the assertion
514 #[serde(rename = "URL")]
515 pub url: String,
516}
517
518/// the issue of a journal a work appeared in
519#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
520#[serde(rename_all = "kebab-case")]
521pub struct Issue {
522 /// Date on which the work was published in print
523 pub published_print: Option<PartialDate>,
524 /// Date on which the work was published online
525 pub published_online: Option<PartialDate>,
526 /// Issue number of an article's journal
527 pub issue: Option<String>,
528}
529
530/// the heading a set of [`Assertion`]s is displayed under
531#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
532pub struct AssertionGroup {
533 /// the group's machine-readable name
534 pub name: String,
535 /// a display-friendly form of `name`
536 pub label: Option<String>,
537}
538
539/// the registration agency that minted a DOI, e.g. `crossref` or `datacite`
540#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
541pub struct Agency {
542 /// the agency's identifier
543 pub id: String,
544 /// a display-friendly form of `id`
545 pub label: Option<String>,
546}
547
548/// how the `Work` is licensed
549#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
550#[serde(rename_all = "kebab-case")]
551pub struct License {
552 /// Either `vor` (version of record,) `am` (accepted manuscript) or `unspecified`
553 pub content_version: String,
554 /// Number of days between the publication date of the work and the start date of this license
555 pub delay_in_days: i32,
556 /// Date on which this license begins to take effect
557 ///
558 /// A few members deposit a license with a url and delay but no start date.
559 pub start: Option<PartialDate>,
560 /// Link to a web page describing this license
561 #[serde(rename = "URL")]
562 pub url: String,
563}
564
565/// metadata about a related resource
566#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
567#[serde(rename_all = "kebab-case")]
568pub struct ResourceLink {
569 /// Either `text-mining`, `similarity-checking` or `unspecified`
570 pub intended_application: String,
571 /// Either `vor` (version of record,) `am` (accepted manuscript) or `unspecified`
572 pub content_version: String,
573 /// Direct link to a full-text download location
574 #[serde(rename = "URL")]
575 pub url: String,
576 /// Content type (or MIME type) of the full-text object
577 pub content_type: Option<String>,
578}
579
580#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
581#[serde(rename_all = "kebab-case")]
582#[allow(missing_docs)]
583pub struct Reference {
584 pub key: String,
585 #[serde(rename = "DOI")]
586 pub doi: Option<String>,
587 /// One of `crossref` or `publisher`
588 pub doi_asserted_by: Option<String>,
589 pub issue: Option<String>,
590 pub first_page: Option<String>,
591 pub volume: Option<String>,
592 pub edition: Option<String>,
593 pub component: Option<String>,
594 pub standard_designator: Option<String>,
595 pub standards_body: Option<String>,
596 pub author: Option<String>,
597 pub year: Option<String>,
598 pub unstructured: Option<String>,
599 pub journal_title: Option<String>,
600 pub article_title: Option<String>,
601 pub series_title: Option<String>,
602 pub volume_title: Option<String>,
603 #[serde(rename = "ISSN")]
604 pub issn: Option<String>,
605 /// One of `pissn` or `eissn`
606 pub issn_type: Option<String>,
607 #[serde(rename = "ISBN")]
608 pub isbn: Option<String>,
609 pub isbn_type: Option<String>,
610}
611
612/// ISSN info for the `Work`
613#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
614#[serde(rename_all = "kebab-case")]
615pub struct ISSN {
616 /// identifier
617 pub value: String,
618 /// One of `eissn`, `pissn` or `lissn`
619 #[serde(rename = "type")]
620 pub type_: String,
621}
622
623#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
624#[serde(rename_all = "kebab-case")]
625#[allow(missing_docs)]
626pub struct ContentDomain {
627 pub domain: Vec<String>,
628 /// whether the publisher restricts Crossmark usage to `domain`
629 ///
630 /// Omitted alongside an empty `domain` on a large share of works, where it
631 /// carries no meaning; treated as `false`.
632 #[serde(default)]
633 pub crossmark_restriction: bool,
634}
635
636#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
637#[serde(rename_all = "kebab-case")]
638#[allow(missing_docs)]
639pub struct Relation {
640 pub id_type: Option<String>,
641 pub id: Option<String>,
642 pub asserted_by: Option<String>,
643}
644
645#[derive(Debug, Clone, PartialEq, Eq, Deserialize, Serialize)]
646#[serde(rename_all = "kebab-case")]
647#[allow(missing_docs)]
648pub struct Review {
649 pub running_number: Option<String>,
650 pub revision_round: Option<String>,
651 /// One of `pre-publication` or `post-publication`
652 pub stage: Option<String>,
653 /// One of `major-revision` or `minor-revision` or `reject` or `reject-with-resubmit` or `accept`
654 pub recommendation: Option<String>,
655 /// One of `referee-report` or `editor-report` or `author-comment` or `community-comment` or `aggregate`
656 #[serde(rename = "type")]
657 pub type_: String,
658 pub competing_interest_statement: Option<String>,
659 pub language: Option<String>,
660}
661
662#[cfg(test)]
663mod tests {
664 use super::*;
665 use serde_json::*;
666 #[derive(Debug, Eq, PartialEq, Serialize, Deserialize)]
667 struct Demo {
668 pub date_parts: DateParts,
669 }
670 #[test]
671 fn date_parts_serde() {
672 let demo = Demo {
673 date_parts: DateParts(vec![vec![Some(2017), Some(10), Some(11)]]),
674 };
675 let expected = r##"{"date_parts":[[2017,10,11]]}"##;
676 assert_eq!(expected, &to_string(&demo).unwrap());
677 assert_eq!(demo, from_str::<Demo>(expected).unwrap());
678 }
679
680 #[test]
681 fn serialize_work() {
682 let work_str = r##"{
683 "indexed": {
684 "date-parts": [
685 [
686 2019,
687 2,
688 26
689 ]
690 ],
691 "date-time": "2019-02-26T10:43:14Z",
692 "timestamp": 1551177794515
693 },
694 "reference-count": 105,
695 "publisher": "American Psychological Association (APA)",
696 "issue": "1",
697 "content-domain": {
698 "domain": [],
699 "crossmark-restriction": false
700 },
701 "short-container-title": [
702 "American Psychologist"
703 ],
704 "DOI": "10.1037/0003-066x.59.1.29",
705 "type": "journal-article",
706 "created": {
707 "date-parts": [
708 [
709 2004,
710 1,
711 21
712 ]
713 ],
714 "date-time": "2004-01-21T14:31:19Z",
715 "timestamp": 1074695479000
716 },
717 "page": "29-40",
718 "source": "Crossref",
719 "is-referenced-by-count": 84,
720 "title": [
721 "How the Mind Hurts and Heals the Body."
722 ],
723 "prefix": "10.1037",
724 "volume": "59",
725 "author": [
726 {
727 "given": "Oakley",
728 "family": "Ray",
729 "sequence": "first",
730 "affiliation": []
731 }
732 ],
733 "member": "15",
734 "published-online": {
735 "date-parts": [
736 [
737 2004
738 ]
739 ]
740 },
741 "container-title": [
742 "American Psychologist"
743 ],
744 "original-title": [],
745 "language": "en",
746 "link": [
747 {
748 "URL": "http://psycnet.apa.org/journals/amp/59/1/29.pdf",
749 "content-type": "unspecified",
750 "content-version": "vor",
751 "intended-application": "similarity-checking"
752 }
753 ],
754 "deposited": {
755 "date-parts": [
756 [
757 2018,
758 4,
759 8
760 ]
761 ],
762 "date-time": "2018-04-08T18:56:17Z",
763 "timestamp": 1523213777000
764 },
765 "score": 1,
766 "subtitle": [],
767 "short-title": [],
768 "issued": {
769 "date-parts": [
770 [
771 null
772 ]
773 ]
774 },
775 "references-count": 105,
776 "journal-issue": {
777 "published-online": {
778 "date-parts": [
779 [
780 2004
781 ]
782 ]
783 },
784 "issue": "1"
785 },
786 "alternative-id": [
787 "2004-10043-004",
788 "14736318"
789 ],
790 "URL": "http://dx.doi.org/10.1037/0003-066x.59.1.29",
791 "relation": {},
792 "ISSN": [
793 "1935-990X",
794 "0003-066X"
795 ],
796 "issn-type": [
797 {
798 "value": "0003-066X",
799 "type": "print"
800 },
801 {
802 "value": "1935-990X",
803 "type": "electronic"
804 }
805 ]
806 }
807"##;
808
809 let _work: Work = from_str(work_str).unwrap();
810 }
811}