diff options
Diffstat (limited to 'rust/src')
-rw-r--r-- | rust/src/api_server.rs | 56 | ||||
-rw-r--r-- | rust/src/database_models.rs | 28 | ||||
-rw-r--r-- | rust/src/database_schema.rs | 19 |
3 files changed, 76 insertions, 27 deletions
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<CreatorIdentRow>, 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::<diesel::sql_types::Text, _>(entity.full_name) + ).bind::<diesel::sql_types::Text, _>(entity.display_name) + .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(entity.given_name) + .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(entity.surname) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(entity.orcid) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Json>, _>(entity.extra) .bind::<diesel::sql_types::BigInt, _>(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::<diesel::sql_types::Nullable<diesel::sql_types::Int8>, _>(entity.size) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(entity.sha1) + .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(entity.sha256) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(entity.md5) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(entity.url) + .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(entity.mimetype) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Json>, _>(entity.extra) .bind::<diesel::sql_types::BigInt, _>(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::<diesel::sql_types::Text, _>(entity.title) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(entity.release_type) + .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(entity.release_status) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Date>, _>( - entity.date.map(|v| v.naive_utc().date())) + entity.release_date.map(|v| v.naive_utc().date())) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(entity.doi) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(entity.isbn13) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(entity.volume) @@ -611,6 +627,7 @@ impl Server { .bind::<diesel::sql_types::Uuid, _>(work_id) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Uuid>, _>(container_id) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(entity.publisher) + .bind::<diesel::sql_types::Nullable<diesel::sql_types::Text>, _>(entity.language) .bind::<diesel::sql_types::Nullable<diesel::sql_types::Json>, _>(entity.extra) .bind::<diesel::sql_types::BigInt, _>(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<ReleaseRefRow> = 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<ReleaseContribRow> = 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<serde_json::Value>, - pub full_name: String, + pub display_name: String, + pub given_name: Option<String>, + pub surname: Option<String>, pub orcid: Option<String>, } @@ -129,8 +131,10 @@ pub struct FileRevRow { pub extra_json: Option<serde_json::Value>, pub size: Option<i64>, pub sha1: Option<String>, + pub sha256: Option<String>, pub md5: Option<String>, pub url: Option<String>, + pub mimetype: Option<String>, } entity_structs!("file_edit", FileEditRow, "file_ident", FileIdentRow); @@ -144,13 +148,15 @@ pub struct ReleaseRevRow { pub container_ident_id: Option<Uuid>, pub title: String, pub release_type: Option<String>, - pub date: Option<chrono::NaiveDate>, + pub release_status: Option<String>, + pub release_date: Option<chrono::NaiveDate>, pub doi: Option<String>, pub isbn13: Option<String>, pub volume: Option<String>, pub pages: Option<String>, pub issue: Option<String>, pub publisher: Option<String>, + pub language: Option<String>, } entity_structs!( @@ -179,7 +185,7 @@ pub struct ReleaseContribRow { pub creator_ident_id: Option<Uuid>, pub role: Option<String>, pub index: Option<i64>, - pub stub: Option<String>, + pub raw: Option<String>, } #[derive(Debug, Insertable)] @@ -189,7 +195,7 @@ pub struct ReleaseContribNewRow { pub creator_ident_id: Option<Uuid>, pub role: Option<String>, pub index: Option<i64>, - pub stub: Option<String>, + pub raw: Option<String>, } #[derive(Debug, Queryable, Identifiable, Associations, AsChangeset)] @@ -199,7 +205,12 @@ pub struct ReleaseRefRow { pub release_rev: i64, pub target_release_ident_id: Option<Uuid>, pub index: Option<i64>, - pub stub: Option<String>, + pub key: Option<String>, + pub raw: Option<String>, + pub container_title: Option<String>, + pub year: Option<i64>, + pub title: Option<String>, + pub locator: Option<String>, } #[derive(Debug, Insertable, AsChangeset)] @@ -208,7 +219,12 @@ pub struct ReleaseRefNewRow { pub release_rev: i64, pub target_release_ident_id: Option<Uuid>, pub index: Option<i64>, - pub stub: Option<String>, + pub key: Option<String>, + pub raw: Option<String>, + pub container_title: Option<String>, + pub year: Option<i64>, + pub title: Option<String>, + pub locator: Option<String>, } #[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<Json>, - full_name -> Text, + display_name -> Text, + given_name -> Nullable<Text>, + surname -> Nullable<Text>, orcid -> Nullable<Text>, } } @@ -118,8 +120,10 @@ table! { extra_json -> Nullable<Json>, size -> Nullable<Int8>, sha1 -> Nullable<Text>, + sha256 -> Nullable<Text>, md5 -> Nullable<Text>, url -> Nullable<Text>, + mimetype -> Nullable<Text>, } } @@ -130,7 +134,7 @@ table! { creator_ident_id -> Nullable<Uuid>, role -> Nullable<Text>, index -> Nullable<Int8>, - stub -> Nullable<Text>, + raw -> Nullable<Text>, } } @@ -160,7 +164,12 @@ table! { release_rev -> Int8, target_release_ident_id -> Nullable<Uuid>, index -> Nullable<Int8>, - stub -> Nullable<Text>, + key -> Nullable<Text>, + raw -> Nullable<Text>, + container_title -> Nullable<Text>, + year -> Nullable<Int8>, + title -> Nullable<Text>, + locator -> Nullable<Text>, } } @@ -172,13 +181,15 @@ table! { container_ident_id -> Nullable<Uuid>, title -> Text, release_type -> Nullable<Text>, - date -> Nullable<Date>, + release_status -> Nullable<Text>, + release_date -> Nullable<Date>, doi -> Nullable<Text>, isbn13 -> Nullable<Text>, volume -> Nullable<Text>, pages -> Nullable<Text>, issue -> Nullable<Text>, publisher -> Nullable<Text>, + language -> Nullable<Text>, } } |