summaryrefslogtreecommitdiffstats
path: root/rust/src/endpoint_handlers.rs
diff options
context:
space:
mode:
authorMartin Czygan <martin@archive.org>2020-11-24 19:29:07 +0000
committerMartin Czygan <martin@archive.org>2020-11-24 19:29:07 +0000
commitcfd13852d7cb58fcc3387373960adaf3680f0faf (patch)
tree675954b8b34324fe22fc5a00f3fbb99a21a77a21 /rust/src/endpoint_handlers.rs
parentfcfcd3224a113fa90da2045a3c7fe90127088ebe (diff)
parent1fca5a9822944d0646d2dcba6cf54f27a0ffe5c0 (diff)
downloadfatcat-cfd13852d7cb58fcc3387373960adaf3680f0faf.tar.gz
fatcat-cfd13852d7cb58fcc3387373960adaf3680f0faf.zip
Merge branch 'bnewbold-doaj-metadata' into 'master'
DOAJ article metadata import See merge request webgroup/fatcat!89
Diffstat (limited to 'rust/src/endpoint_handlers.rs')
-rw-r--r--rust/src/endpoint_handlers.rs194
1 files changed, 182 insertions, 12 deletions
diff --git a/rust/src/endpoint_handlers.rs b/rust/src/endpoint_handlers.rs
index 64b6ed62..91ea2393 100644
--- a/rust/src/endpoint_handlers.rs
+++ b/rust/src/endpoint_handlers.rs
@@ -26,7 +26,6 @@ macro_rules! entity_auto_batch_handler {
entity_list: &[models::$model],
editor_id: FatcatId,
) -> Result<Editgroup> {
-
let editgroup_row = editgroup.db_create(conn, true)?;
let editgroup_id = FatcatId::from_uuid(&editgroup_row.id);
let edit_context = make_edit_context(editor_id, editgroup_id, true)?;
@@ -39,7 +38,7 @@ macro_rules! entity_auto_batch_handler {
.get_result(conn)?;
self.get_editgroup_handler(conn, editgroup_id)
}
- }
+ };
}
pub fn get_release_files(
@@ -262,6 +261,9 @@ impl Server {
jstor: &Option<String>,
ark: &Option<String>,
mag: &Option<String>,
+ doaj: &Option<String>,
+ dblp: &Option<String>,
+ oai: &Option<String>,
expand_flags: ExpandFlags,
hide_flags: HideFlags,
) -> Result<ReleaseEntity> {
@@ -276,8 +278,11 @@ impl Server {
jstor,
ark,
mag,
+ doaj,
+ dblp,
+ oai,
) {
- (Some(doi), None, None, None, None, None, None, None, None, None) => {
+ (Some(doi), None, None, None, None, None, None, None, None, None, None, None, None) => {
// DOIs always stored lower-case; lookups are case-insensitive
let doi = doi.to_lowercase();
check_doi(&doi)?;
@@ -288,7 +293,21 @@ impl Server {
.filter(release_ident::redirect_id.is_null())
.first(conn)?
}
- (None, Some(wikidata_qid), None, None, None, None, None, None, None, None) => {
+ (
+ None,
+ Some(wikidata_qid),
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ ) => {
check_wikidata_qid(wikidata_qid)?;
release_ident::table
.inner_join(release_rev::table)
@@ -297,7 +316,21 @@ impl Server {
.filter(release_ident::redirect_id.is_null())
.first(conn)?
}
- (None, None, Some(isbn13), None, None, None, None, None, None, None) => {
+ (
+ None,
+ None,
+ Some(isbn13),
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ ) => {
check_isbn13(isbn13)?;
let (rev, ident, _extid): (ReleaseRevRow, ReleaseIdentRow, ReleaseExtidRow) =
release_rev::table
@@ -310,7 +343,21 @@ impl Server {
.first(conn)?;
(ident, rev)
}
- (None, None, None, Some(pmid), None, None, None, None, None, None) => {
+ (
+ None,
+ None,
+ None,
+ Some(pmid),
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ ) => {
check_pmid(pmid)?;
release_ident::table
.inner_join(release_rev::table)
@@ -319,7 +366,21 @@ impl Server {
.filter(release_ident::redirect_id.is_null())
.first(conn)?
}
- (None, None, None, None, Some(pmcid), None, None, None, None, None) => {
+ (
+ None,
+ None,
+ None,
+ None,
+ Some(pmcid),
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ ) => {
check_pmcid(pmcid)?;
release_ident::table
.inner_join(release_rev::table)
@@ -328,7 +389,21 @@ impl Server {
.filter(release_ident::redirect_id.is_null())
.first(conn)?
}
- (None, None, None, None, None, Some(core), None, None, None, None) => {
+ (
+ None,
+ None,
+ None,
+ None,
+ None,
+ Some(core),
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ ) => {
check_core_id(core)?;
release_ident::table
.inner_join(release_rev::table)
@@ -337,7 +412,21 @@ impl Server {
.filter(release_ident::redirect_id.is_null())
.first(conn)?
}
- (None, None, None, None, None, None, Some(arxiv), None, None, None) => {
+ (
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ Some(arxiv),
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ ) => {
// TODO: this allows only lookup by full, versioned arxiv identifier. Probably also
// want to allow lookup by "work" style identifier?
check_arxiv_id(arxiv)?;
@@ -352,7 +441,21 @@ impl Server {
.first(conn)?;
(ident, rev)
}
- (None, None, None, None, None, None, None, Some(jstor), None, None) => {
+ (
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ Some(jstor),
+ None,
+ None,
+ None,
+ None,
+ None,
+ ) => {
check_jstor_id(jstor)?;
let (rev, ident, _extid): (ReleaseRevRow, ReleaseIdentRow, ReleaseExtidRow) =
release_rev::table
@@ -365,7 +468,7 @@ impl Server {
.first(conn)?;
(ident, rev)
}
- (None, None, None, None, None, None, None, None, Some(ark), None) => {
+ (None, None, None, None, None, None, None, None, Some(ark), None, None, None, None) => {
check_ark_id(ark)?;
let (rev, ident, _extid): (ReleaseRevRow, ReleaseIdentRow, ReleaseExtidRow) =
release_rev::table
@@ -378,7 +481,7 @@ impl Server {
.first(conn)?;
(ident, rev)
}
- (None, None, None, None, None, None, None, None, None, Some(mag)) => {
+ (None, None, None, None, None, None, None, None, None, Some(mag), None, None, None) => {
check_mag_id(mag)?;
let (rev, ident, _extid): (ReleaseRevRow, ReleaseIdentRow, ReleaseExtidRow) =
release_rev::table
@@ -391,6 +494,73 @@ impl Server {
.first(conn)?;
(ident, rev)
}
+ (
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ Some(doaj),
+ None,
+ None,
+ ) => {
+ check_doaj_id(doaj)?;
+ let (rev, ident, _extid): (ReleaseRevRow, ReleaseIdentRow, ReleaseExtidRow) =
+ release_rev::table
+ .inner_join(release_ident::table)
+ .inner_join(release_rev_extid::table)
+ .filter(release_rev_extid::extid_type.eq("doaj".to_string()))
+ .filter(release_rev_extid::value.eq(doaj))
+ .filter(release_ident::is_live.eq(true))
+ .filter(release_ident::redirect_id.is_null())
+ .first(conn)?;
+ (ident, rev)
+ }
+ (
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ None,
+ Some(dblp),
+ None,
+ ) => {
+ check_dblp_id(dblp)?;
+ let (rev, ident, _extid): (ReleaseRevRow, ReleaseIdentRow, ReleaseExtidRow) =
+ release_rev::table
+ .inner_join(release_ident::table)
+ .inner_join(release_rev_extid::table)
+ .filter(release_rev_extid::extid_type.eq("dblp".to_string()))
+ .filter(release_rev_extid::value.eq(dblp))
+ .filter(release_ident::is_live.eq(true))
+ .filter(release_ident::redirect_id.is_null())
+ .first(conn)?;
+ (ident, rev)
+ }
+ (None, None, None, None, None, None, None, None, None, None, None, None, Some(oai)) => {
+ check_oai_id(oai)?;
+ let (rev, ident, _extid): (ReleaseRevRow, ReleaseIdentRow, ReleaseExtidRow) =
+ release_rev::table
+ .inner_join(release_ident::table)
+ .inner_join(release_rev_extid::table)
+ .filter(release_rev_extid::extid_type.eq("oai".to_string()))
+ .filter(release_rev_extid::value.eq(oai))
+ .filter(release_ident::is_live.eq(true))
+ .filter(release_ident::redirect_id.is_null())
+ .first(conn)?;
+ (ident, rev)
+ }
_ => {
return Err(
FatcatError::MissingOrMultipleExternalId("in lookup".to_string()).into(),