From 0ec7c973417f5d120db80d1c1dd3e329711a1ca4 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Mon, 4 Jun 2018 00:19:36 -0700 Subject: update rust/api for schema extensions --- rust/src/api_server.rs | 56 +++++++++++++++++++++++++++++++-------------- rust/src/database_models.rs | 28 ++++++++++++++++++----- rust/src/database_schema.rs | 19 +++++++++++---- 3 files changed, 76 insertions(+), 27 deletions(-) (limited to 'rust/src') diff --git a/rust/src/api_server.rs b/rust/src/api_server.rs index 0706fc22..c167c067 100644 --- a/rust/src/api_server.rs +++ b/rust/src/api_server.rs @@ -155,7 +155,9 @@ fn creator_row2entity(ident: Option, rev: CreatorRevRow) -> Res None => (None, None, None), }; Ok(CreatorEntity { - full_name: rev.full_name, + display_name: rev.display_name, + given_name: rev.given_name, + surname: rev.surname, orcid: rev.orcid, state: state, ident: ident_id, @@ -189,9 +191,11 @@ fn file_row2entity( Ok(FileEntity { sha1: rev.sha1, + sha256: rev.sha256, md5: rev.md5, size: rev.size.map(|v| v as i64), url: rev.url, + mimetype: rev.mimetype, releases: Some(releases), state: state, ident: ident_id, @@ -223,7 +227,12 @@ fn release_row2entity( .iter() .map(|r: &ReleaseRefRow| ReleaseRef { index: r.index.clone(), - stub: r.stub.clone(), + key: r.key.clone(), + raw: r.raw.clone(), + container_title: r.container_title.clone(), + year: r.year.clone(), + title: r.title.clone(), + locator: r.locator.clone(), target_release_id: r.target_release_ident_id.map(|v| v.to_string()), }) .collect(); @@ -236,7 +245,7 @@ fn release_row2entity( .map(|c: &ReleaseContribRow| ReleaseContrib { index: c.index, role: c.role.clone(), - creator_stub: c.stub.clone(), + raw: c.raw.clone(), creator_id: c.creator_ident_id.map(|v| v.to_string()), }) .collect(); @@ -244,7 +253,8 @@ fn release_row2entity( Ok(ReleaseEntity { title: rev.title, release_type: rev.release_type, - date: rev.date + release_status: rev.release_status, + release_date: rev.release_date .map(|v| chrono::DateTime::from_utc(v.and_hms(0, 0, 0), chrono::Utc)), doi: rev.doi, isbn13: rev.isbn13, @@ -253,6 +263,7 @@ fn release_row2entity( issue: rev.issue, container_id: rev.container_ident_id.map(|u| u.to_string()), publisher: rev.publisher, + language: rev.language, work_id: rev.work_ident_id.to_string(), refs: Some(refs), contribs: Some(contribs), @@ -481,16 +492,18 @@ impl Server { }; let edit: CreatorEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO creator_rev (full_name, orcid, extra_json) - VALUES ($1, $2, $3) + "WITH rev AS ( INSERT INTO creator_rev (display_name, given_name, surname, orcid, extra_json) + VALUES ($1, $2, $3, $4, $5) RETURNING id ), ident AS ( INSERT INTO creator_ident (rev_id) VALUES ((SELECT rev.id FROM rev)) RETURNING id ) INSERT INTO creator_edit (editgroup_id, ident_id, rev_id) VALUES - ($4, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) + ($6, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) RETURNING *", - ).bind::(entity.full_name) + ).bind::(entity.display_name) + .bind::, _>(entity.given_name) + .bind::, _>(entity.surname) .bind::, _>(entity.orcid) .bind::, _>(entity.extra) .bind::(editgroup_id) @@ -521,19 +534,21 @@ impl Server { let edit: FileEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO file_rev (size, sha1, md5, url, extra_json) - VALUES ($1, $2, $3, $4, $5) + "WITH rev AS ( INSERT INTO file_rev (size, sha1, sha256, md5, url, mimetype, extra_json) + VALUES ($1, $2, $3, $4, $5, $6, $7) RETURNING id ), ident AS ( INSERT INTO file_ident (rev_id) VALUES ((SELECT rev.id FROM rev)) RETURNING id ) INSERT INTO file_edit (editgroup_id, ident_id, rev_id) VALUES - ($6, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) + ($8, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) RETURNING *", ).bind::, _>(entity.size) .bind::, _>(entity.sha1) + .bind::, _>(entity.sha256) .bind::, _>(entity.md5) .bind::, _>(entity.url) + .bind::, _>(entity.mimetype) .bind::, _>(entity.extra) .bind::(editgroup_id) .get_result(conn)?; @@ -590,19 +605,20 @@ impl Server { }; let edit: ReleaseEditRow = diesel::sql_query( - "WITH rev AS ( INSERT INTO release_rev (title, release_type, date, doi, isbn13, volume, pages, issue, work_ident_id, container_ident_id, publisher, extra_json) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12) + "WITH rev AS ( INSERT INTO release_rev (title, release_type, release_status, release_date, doi, isbn13, volume, pages, issue, work_ident_id, container_ident_id, publisher, language, extra_json) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14) RETURNING id ), ident AS ( INSERT INTO release_ident (rev_id) VALUES ((SELECT rev.id FROM rev)) RETURNING id ) INSERT INTO release_edit (editgroup_id, ident_id, rev_id) VALUES - ($13, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) + ($15, (SELECT ident.id FROM ident), (SELECT rev.id FROM rev)) RETURNING *", ).bind::(entity.title) .bind::, _>(entity.release_type) + .bind::, _>(entity.release_status) .bind::, _>( - entity.date.map(|v| v.naive_utc().date())) + entity.release_date.map(|v| v.naive_utc().date())) .bind::, _>(entity.doi) .bind::, _>(entity.isbn13) .bind::, _>(entity.volume) @@ -611,6 +627,7 @@ impl Server { .bind::(work_id) .bind::, _>(container_id) .bind::, _>(entity.publisher) + .bind::, _>(entity.language) .bind::, _>(entity.extra) .bind::(editgroup_id) .get_result(conn)?; @@ -629,7 +646,12 @@ impl Server { .clone() .map(|v| uuid::Uuid::parse_str(&v).expect("valid UUID")), index: r.index, - stub: r.stub.clone(), + key: r.key.clone(), + container_title: r.container_title.clone(), + year: r.year, + title: r.title.clone(), + locator: r.locator.clone(), + raw: r.raw.clone(), }) .collect(); let ref_rows: Vec = insert_into(release_ref::table) @@ -656,7 +678,7 @@ impl Server { .map(|v| uuid::Uuid::parse_str(&v).expect("valid UUID")), index: c.index, role: c.role.clone(), - stub: c.creator_stub.clone(), + raw: c.raw.clone(), }) .collect(); let contrib_rows: Vec = insert_into(release_contrib::table) diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs index b62492ab..2d72795e 100644 --- a/rust/src/database_models.rs +++ b/rust/src/database_models.rs @@ -111,7 +111,9 @@ entity_structs!( pub struct CreatorRevRow { pub id: i64, pub extra_json: Option, - pub full_name: String, + pub display_name: String, + pub given_name: Option, + pub surname: Option, pub orcid: Option, } @@ -129,8 +131,10 @@ pub struct FileRevRow { pub extra_json: Option, pub size: Option, pub sha1: Option, + pub sha256: Option, pub md5: Option, pub url: Option, + pub mimetype: Option, } entity_structs!("file_edit", FileEditRow, "file_ident", FileIdentRow); @@ -144,13 +148,15 @@ pub struct ReleaseRevRow { pub container_ident_id: Option, pub title: String, pub release_type: Option, - pub date: Option, + pub release_status: Option, + pub release_date: Option, pub doi: Option, pub isbn13: Option, pub volume: Option, pub pages: Option, pub issue: Option, pub publisher: Option, + pub language: Option, } entity_structs!( @@ -179,7 +185,7 @@ pub struct ReleaseContribRow { pub creator_ident_id: Option, pub role: Option, pub index: Option, - pub stub: Option, + pub raw: Option, } #[derive(Debug, Insertable)] @@ -189,7 +195,7 @@ pub struct ReleaseContribNewRow { pub creator_ident_id: Option, pub role: Option, pub index: Option, - pub stub: Option, + pub raw: Option, } #[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] @@ -199,7 +205,12 @@ pub struct ReleaseRefRow { pub release_rev: i64, pub target_release_ident_id: Option, pub index: Option, - pub stub: Option, + pub key: Option, + pub raw: Option, + pub container_title: Option, + pub year: Option, + pub title: Option, + pub locator: Option, } #[derive(Debug, Insertable, AsChangeset)] @@ -208,7 +219,12 @@ pub struct ReleaseRefNewRow { pub release_rev: i64, pub target_release_ident_id: Option, pub index: Option, - pub stub: Option, + pub key: Option, + pub raw: Option, + pub container_title: Option, + pub year: Option, + pub title: Option, + pub locator: Option, } #[derive(Debug, Queryable, Insertable, Associations, AsChangeset)] diff --git a/rust/src/database_schema.rs b/rust/src/database_schema.rs index 2541bcd8..d60bb6ee 100644 --- a/rust/src/database_schema.rs +++ b/rust/src/database_schema.rs @@ -62,7 +62,9 @@ table! { creator_rev (id) { id -> Int8, extra_json -> Nullable, - full_name -> Text, + display_name -> Text, + given_name -> Nullable, + surname -> Nullable, orcid -> Nullable, } } @@ -118,8 +120,10 @@ table! { extra_json -> Nullable, size -> Nullable, sha1 -> Nullable, + sha256 -> Nullable, md5 -> Nullable, url -> Nullable, + mimetype -> Nullable, } } @@ -130,7 +134,7 @@ table! { creator_ident_id -> Nullable, role -> Nullable, index -> Nullable, - stub -> Nullable, + raw -> Nullable, } } @@ -160,7 +164,12 @@ table! { release_rev -> Int8, target_release_ident_id -> Nullable, index -> Nullable, - stub -> Nullable, + key -> Nullable, + raw -> Nullable, + container_title -> Nullable, + year -> Nullable, + title -> Nullable, + locator -> Nullable, } } @@ -172,13 +181,15 @@ table! { container_ident_id -> Nullable, title -> Text, release_type -> Nullable, - date -> Nullable, + release_status -> Nullable, + release_date -> Nullable, doi -> Nullable, isbn13 -> Nullable, volume -> Nullable, pages -> Nullable, issue -> Nullable, publisher -> Nullable, + language -> Nullable, } } -- cgit v1.2.3