From 11fdff350e0549d46a8a7b5e74451e08ce067cb2 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Tue, 12 Oct 2021 19:56:08 -0700 Subject: rust: implement scheman and API changes --- rust/src/endpoint_handlers.rs | 194 +++++++++++++++++++++++++++++++++++------- 1 file changed, 165 insertions(+), 29 deletions(-) (limited to 'rust/src/endpoint_handlers.rs') diff --git a/rust/src/endpoint_handlers.rs b/rust/src/endpoint_handlers.rs index 141c414e..9a76652b 100644 --- a/rust/src/endpoint_handlers.rs +++ b/rust/src/endpoint_handlers.rs @@ -104,35 +104,71 @@ impl Server { &self, conn: &DbConn, issnl: &Option, + issne: &Option, + issnp: &Option, + issn: &Option, wikidata_qid: &Option, expand_flags: ExpandFlags, hide_flags: HideFlags, ) -> Result { - let (ident, rev): (ContainerIdentRow, ContainerRevRow) = match (issnl, wikidata_qid) { - (Some(issnl), None) => { - check_issn(issnl)?; - container_ident::table - .inner_join(container_rev::table) - .filter(container_rev::issnl.eq(&issnl)) - .filter(container_ident::is_live.eq(true)) - .filter(container_ident::redirect_id.is_null()) - .first(conn)? - } - (None, Some(wikidata_qid)) => { - check_wikidata_qid(wikidata_qid)?; - container_ident::table - .inner_join(container_rev::table) - .filter(container_rev::wikidata_qid.eq(&wikidata_qid)) - .filter(container_ident::is_live.eq(true)) - .filter(container_ident::redirect_id.is_null()) - .first(conn)? - } - _ => { - return Err( - FatcatError::MissingOrMultipleExternalId("in lookup".to_string()).into(), - ); - } - }; + let (ident, rev): (ContainerIdentRow, ContainerRevRow) = + match (issnl, issnp, issne, issn, wikidata_qid) { + (Some(issnl), None, None, None, None) => { + check_issn(issnl)?; + container_ident::table + .inner_join(container_rev::table) + .filter(container_rev::issnl.eq(&issnl)) + .filter(container_ident::is_live.eq(true)) + .filter(container_ident::redirect_id.is_null()) + .first(conn)? + } + (None, Some(issnp), None, None, None) => { + check_issn(issnp)?; + container_ident::table + .inner_join(container_rev::table) + .filter(container_rev::issnp.eq(&issnp)) + .filter(container_ident::is_live.eq(true)) + .filter(container_ident::redirect_id.is_null()) + .first(conn)? + } + (None, None, Some(issne), None, None) => { + check_issn(issne)?; + container_ident::table + .inner_join(container_rev::table) + .filter(container_rev::issne.eq(&issne)) + .filter(container_ident::is_live.eq(true)) + .filter(container_ident::redirect_id.is_null()) + .first(conn)? + } + (None, None, None, Some(issn), None) => { + check_issn(issn)?; + container_ident::table + .inner_join(container_rev::table) + .filter( + container_rev::issnl + .eq(&issn) + .or(container_rev::issnp.eq(&issn)) + .or(container_rev::issne.eq(&issn)), + ) + .filter(container_ident::is_live.eq(true)) + .filter(container_ident::redirect_id.is_null()) + .first(conn)? + } + (None, None, None, None, Some(wikidata_qid)) => { + check_wikidata_qid(wikidata_qid)?; + container_ident::table + .inner_join(container_rev::table) + .filter(container_rev::wikidata_qid.eq(&wikidata_qid)) + .filter(container_ident::is_live.eq(true)) + .filter(container_ident::redirect_id.is_null()) + .first(conn)? + } + _ => { + return Err( + FatcatError::MissingOrMultipleExternalId("in lookup".to_string()).into(), + ); + } + }; let mut entity = ContainerEntity::db_from_row(conn, rev, Some(ident), hide_flags)?; entity.db_expand(&conn, expand_flags)?; @@ -264,6 +300,7 @@ impl Server { doaj: &Option, dblp: &Option, oai: &Option, + hdl: &Option, expand_flags: ExpandFlags, hide_flags: HideFlags, ) -> Result { @@ -281,8 +318,24 @@ impl Server { doaj, dblp, oai, + hdl, ) { - (Some(doi), None, None, None, None, None, None, None, None, None, None, None, None) => { + ( + Some(doi), + None, + 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)?; @@ -307,6 +360,7 @@ impl Server { None, None, None, + None, ) => { check_wikidata_qid(wikidata_qid)?; release_ident::table @@ -330,6 +384,7 @@ impl Server { None, None, None, + None, ) => { check_isbn13(isbn13)?; let (rev, ident, _extid): (ReleaseRevRow, ReleaseIdentRow, ReleaseExtidRow) = @@ -357,6 +412,7 @@ impl Server { None, None, None, + None, ) => { check_pmid(pmid)?; release_ident::table @@ -380,6 +436,7 @@ impl Server { None, None, None, + None, ) => { check_pmcid(pmcid)?; release_ident::table @@ -403,6 +460,7 @@ impl Server { None, None, None, + None, ) => { check_core_id(core)?; release_ident::table @@ -426,6 +484,7 @@ impl Server { None, None, None, + None, ) => { // TODO: this allows only lookup by full, versioned arxiv identifier. Probably also // want to allow lookup by "work" style identifier? @@ -455,6 +514,7 @@ impl Server { None, None, None, + None, ) => { check_jstor_id(jstor)?; let (rev, ident, _extid): (ReleaseRevRow, ReleaseIdentRow, ReleaseExtidRow) = @@ -468,7 +528,22 @@ 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, + None, + None, + None, + Some(ark), + None, + None, + None, + None, + None, + ) => { check_ark_id(ark)?; let (rev, ident, _extid): (ReleaseRevRow, ReleaseIdentRow, ReleaseExtidRow) = release_rev::table @@ -481,7 +556,22 @@ 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, + None, + None, + None, + Some(mag), + None, + None, + None, + None, + ) => { check_mag_id(mag)?; let (rev, ident, _extid): (ReleaseRevRow, ReleaseIdentRow, ReleaseExtidRow) = release_rev::table @@ -508,6 +598,7 @@ impl Server { Some(doaj), None, None, + None, ) => { check_doaj_id(doaj)?; let (rev, ident, _extid): (ReleaseRevRow, ReleaseIdentRow, ReleaseExtidRow) = @@ -535,6 +626,7 @@ impl Server { None, Some(dblp), None, + None, ) => { check_dblp_key(dblp)?; let (rev, ident, _extid): (ReleaseRevRow, ReleaseIdentRow, ReleaseExtidRow) = @@ -548,7 +640,22 @@ impl Server { .first(conn)?; (ident, rev) } - (None, None, None, None, None, None, None, None, None, None, None, None, Some(oai)) => { + ( + None, + None, + None, + None, + None, + None, + None, + None, + None, + None, + None, + None, + Some(oai), + None, + ) => { check_oai_id(oai)?; let (rev, ident, _extid): (ReleaseRevRow, ReleaseIdentRow, ReleaseExtidRow) = release_rev::table @@ -561,6 +668,35 @@ impl Server { .first(conn)?; (ident, rev) } + ( + None, + None, + None, + None, + None, + None, + None, + None, + None, + None, + None, + None, + None, + Some(hdl), + ) => { + let hdl = hdl.to_lowercase(); + check_hdl(&hdl)?; + 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("hdl".to_string())) + .filter(release_rev_extid::value.eq(hdl)) + .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(), -- cgit v1.2.3