aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--rust/src/api_entity_crud.rs109
-rw-r--r--rust/src/api_helpers.rs24
-rw-r--r--rust/src/bin/fatcat-export.rs38
-rw-r--r--rust/src/bin/fatcatd.rs3
-rw-r--r--rust/src/database_models.rs3
-rw-r--r--rust/tests/test_old_python_tests.rs27
6 files changed, 127 insertions, 77 deletions
diff --git a/rust/src/api_entity_crud.rs b/rust/src/api_entity_crud.rs
index 814b42da..8770644c 100644
--- a/rust/src/api_entity_crud.rs
+++ b/rust/src/api_entity_crud.rs
@@ -153,8 +153,10 @@ macro_rules! generic_db_create_batch {
rev_id: Some(rev_id.clone()),
is_live: edit_context.autoaccept,
redirect_id: None,
- }).collect::<Vec<Self::IdentNewRow>>(),
- ).returning($ident_table::id)
+ })
+ .collect::<Vec<Self::IdentNewRow>>(),
+ )
+ .returning($ident_table::id)
.get_results(conn)?;
let edits: Vec<Self::EditRow> = insert_into($edit_table::table)
.values(
@@ -168,8 +170,10 @@ macro_rules! generic_db_create_batch {
redirect_id: None,
prev_rev: None,
extra_json: edit_context.extra_json.clone(),
- }).collect::<Vec<Self::EditNewRow>>(),
- ).get_results(conn)?;
+ })
+ .collect::<Vec<Self::EditNewRow>>(),
+ )
+ .get_results(conn)?;
Ok(edits)
}
};
@@ -228,7 +232,8 @@ macro_rules! generic_db_delete {
$edit_table::redirect_id.eq(None::<Uuid>),
$edit_table::prev_rev.eq(current.rev_id),
$edit_table::extra_json.eq(&edit_context.extra_json),
- )).get_result(conn)?;
+ ))
+ .get_result(conn)?;
Ok(edit)
}
@@ -260,7 +265,8 @@ macro_rules! generic_db_get_history {
editgroup: eg_row.into_model_partial(),
changelog_entry: cl_row.into_model(),
})
- }).collect();
+ })
+ .collect();
history
}
};
@@ -360,7 +366,8 @@ macro_rules! generic_db_accept_edits_batch {
{entity}_ident.id = {entity}_edit.ident_id
AND {entity}_edit.editgroup_id = $1",
entity = $entity_name_str
- )).bind::<diesel::sql_types::Uuid, _>(editgroup_id.to_uuid())
+ ))
+ .bind::<diesel::sql_types::Uuid, _>(editgroup_id.to_uuid())
.execute(conn)?;
Ok(count as u64)
}
@@ -388,14 +395,14 @@ macro_rules! generic_db_accept_edits_each {
})
.collect();
/*
- // 3. upsert ident rows (in sql)
- let count: u64 = diesel::insert_into($ident_table::table)
- .values(ident_rows)
- .on_conflict()
- .do_update()
- .set(ident_rows)
- .execute(conn)?;
- */
+ // 3. upsert ident rows (in sql)
+ let count: u64 = diesel::insert_into($ident_table::table)
+ .values(ident_rows)
+ .on_conflict()
+ .do_update()
+ .set(ident_rows)
+ .execute(conn)?;
+ */
// 3. update every row individually
let count = ident_rows.len() as u64;
for row in ident_rows {
@@ -489,8 +496,10 @@ impl EntityCrud for ContainerEntity {
abbrev: model.abbrev.clone(),
coden: model.coden.clone(),
extra_json: model.extra.clone(),
- }).collect::<Vec<ContainerRevNewRow>>(),
- ).returning(container_rev::id)
+ })
+ .collect::<Vec<ContainerRevNewRow>>(),
+ )
+ .returning(container_rev::id)
.get_results(conn)?;
Ok(rev_ids)
}
@@ -568,8 +577,10 @@ impl EntityCrud for CreatorEntity {
orcid: model.orcid.clone(),
wikidata_qid: model.wikidata_qid.clone(),
extra_json: model.extra.clone(),
- }).collect::<Vec<CreatorRevNewRow>>(),
- ).returning(creator_rev::id)
+ })
+ .collect::<Vec<CreatorRevNewRow>>(),
+ )
+ .returning(creator_rev::id)
.get_results(conn)?;
Ok(rev_ids)
}
@@ -625,7 +636,8 @@ impl EntityCrud for FileEntity {
.map(|r: FileRevUrlRow| FileEntityUrls {
rel: r.rel,
url: r.url,
- }).collect();
+ })
+ .collect();
Ok(FileEntity {
sha1: rev_row.sha1,
@@ -656,8 +668,10 @@ impl EntityCrud for FileEntity {
md5: model.md5.clone(),
mimetype: model.mimetype.clone(),
extra_json: model.extra.clone(),
- }).collect::<Vec<FileRevNewRow>>(),
- ).returning(file_rev::id)
+ })
+ .collect::<Vec<FileRevNewRow>>(),
+ )
+ .returning(file_rev::id)
.get_results(conn)?;
let mut file_release_rows: Vec<FileReleaseRow> = vec![];
@@ -674,7 +688,8 @@ impl EntityCrud for FileEntity {
file_rev: *rev_id,
target_release_ident_id: FatCatId::from_str(r)?.to_uuid(),
})
- }).collect();
+ })
+ .collect();
file_release_rows.extend(these_release_rows?);
}
};
@@ -688,7 +703,8 @@ impl EntityCrud for FileEntity {
file_rev: *rev_id,
rel: u.rel.clone(),
url: u.url.clone(),
- }).collect();
+ })
+ .collect();
file_url_rows.extend(these_url_rows);
}
};
@@ -795,7 +811,8 @@ impl EntityCrud for ReleaseEntity {
Some(FatCatId::from_uuid(&new_work_ids.pop().unwrap()).to_string())
}
model
- }).collect();
+ })
+ .collect();
let model_refs: Vec<&Self> = models_with_work_ids.iter().map(|s| s).collect();
let models = model_refs.as_slice();
@@ -809,8 +826,10 @@ impl EntityCrud for ReleaseEntity {
rev_id: Some(*rev_id),
is_live: edit_context.autoaccept,
redirect_id: None,
- }).collect::<Vec<Self::IdentNewRow>>(),
- ).returning(release_ident::id)
+ })
+ .collect::<Vec<Self::IdentNewRow>>(),
+ )
+ .returning(release_ident::id)
.get_results(conn)?;
let edits: Vec<Self::EditRow> = insert_into(release_edit::table)
.values(
@@ -824,8 +843,10 @@ impl EntityCrud for ReleaseEntity {
redirect_id: None,
prev_rev: None,
extra_json: edit_context.extra_json.clone(),
- }).collect::<Vec<Self::EditNewRow>>(),
- ).get_results(conn)?;
+ })
+ .collect::<Vec<Self::EditNewRow>>(),
+ )
+ .get_results(conn)?;
Ok(edits)
}
@@ -863,7 +884,8 @@ impl EntityCrud for ReleaseEntity {
target_release_id: r
.target_release_ident_id
.map(|v| FatCatId::from_uuid(&v).to_string()),
- }).collect(),
+ })
+ .collect(),
),
};
@@ -875,7 +897,8 @@ impl EntityCrud for ReleaseEntity {
.order((
release_contrib::role.asc(),
release_contrib::index_val.asc(),
- )).get_results(conn)?
+ ))
+ .get_results(conn)?
.into_iter()
.map(|c: ReleaseContribRow| ReleaseContrib {
index: c.index_val.map(|v| v as i64),
@@ -886,7 +909,8 @@ impl EntityCrud for ReleaseEntity {
.creator_ident_id
.map(|v| FatCatId::from_uuid(&v).to_string()),
creator: None,
- }).collect(),
+ })
+ .collect(),
),
};
@@ -905,7 +929,8 @@ impl EntityCrud for ReleaseEntity {
lang: r.0.lang,
content: Some(r.1.content),
},
- ).collect(),
+ )
+ .collect(),
),
};
@@ -1033,7 +1058,8 @@ impl EntityCrud for ReleaseEntity {
locator: r.locator.clone(),
extra_json: r.extra.clone(),
})
- }).collect::<Result<Vec<ReleaseRefNewRow>>>()?;
+ })
+ .collect::<Result<Vec<ReleaseRefNewRow>>>()?;
release_ref_rows.extend(these_ref_rows);
}
};
@@ -1055,7 +1081,8 @@ impl EntityCrud for ReleaseEntity {
role: c.role.clone(),
extra_json: c.extra.clone(),
})
- }).collect::<Result<Vec<ReleaseContribNewRow>>>()?;
+ })
+ .collect::<Result<Vec<ReleaseContribNewRow>>>()?;
release_contrib_rows.extend(these_contrib_rows);
}
};
@@ -1069,7 +1096,8 @@ impl EntityCrud for ReleaseEntity {
.map(|c| AbstractsRow {
sha1: Sha1::from(c.content.clone().unwrap()).hexdigest(),
content: c.content.clone().unwrap(),
- }).collect();
+ })
+ .collect();
abstract_rows.extend(new_abstracts);
let new_release_abstract_rows: Vec<ReleaseRevAbstractNewRow> = abstract_list
.into_iter()
@@ -1086,7 +1114,8 @@ impl EntityCrud for ReleaseEntity {
lang: c.lang.clone(),
mimetype: c.mimetype.clone(),
})
- }).collect::<Result<Vec<ReleaseRevAbstractNewRow>>>()?;
+ })
+ .collect::<Result<Vec<ReleaseRevAbstractNewRow>>>()?;
release_abstract_rows.extend(new_release_abstract_rows);
}
}
@@ -1172,8 +1201,10 @@ impl EntityCrud for WorkEntity {
.iter()
.map(|model| WorkRevNewRow {
extra_json: model.extra.clone(),
- }).collect::<Vec<WorkRevNewRow>>(),
- ).returning(work_rev::id)
+ })
+ .collect::<Vec<WorkRevNewRow>>(),
+ )
+ .returning(work_rev::id)
.get_results(conn)?;
Ok(rev_ids)
}
diff --git a/rust/src/api_helpers.rs b/rust/src/api_helpers.rs
index 952cb9cd..77377531 100644
--- a/rust/src/api_helpers.rs
+++ b/rust/src/api_helpers.rs
@@ -286,7 +286,8 @@ pub fn check_pmcid(raw: &str) -> Result<()> {
Err(ErrorKind::MalformedExternalId(format!(
"not a valid PubMed Central ID (PMCID): '{}' (expected, eg, 'PMC12345')",
raw
- )).into())
+ ))
+ .into())
}
}
@@ -300,7 +301,8 @@ pub fn check_pmid(raw: &str) -> Result<()> {
Err(ErrorKind::MalformedExternalId(format!(
"not a valid PubMed ID (PMID): '{}' (expected, eg, '1234')",
raw
- )).into())
+ ))
+ .into())
}
}
@@ -314,7 +316,8 @@ pub fn check_wikidata_qid(raw: &str) -> Result<()> {
Err(ErrorKind::MalformedExternalId(format!(
"not a valid Wikidata QID: '{}' (expected, eg, 'Q1234')",
raw
- )).into())
+ ))
+ .into())
}
}
@@ -328,7 +331,8 @@ pub fn check_doi(raw: &str) -> Result<()> {
Err(ErrorKind::MalformedExternalId(format!(
"not a valid DOI: '{}' (expected, eg, '10.1234/aksjdfh')",
raw
- )).into())
+ ))
+ .into())
}
}
@@ -342,7 +346,8 @@ pub fn check_issn(raw: &str) -> Result<()> {
Err(ErrorKind::MalformedExternalId(format!(
"not a valid ISSN: '{}' (expected, eg, '1234-5678')",
raw
- )).into())
+ ))
+ .into())
}
}
@@ -356,7 +361,8 @@ pub fn check_orcid(raw: &str) -> Result<()> {
Err(ErrorKind::MalformedExternalId(format!(
"not a valid ORCID: '{}' (expected, eg, '0123-4567-3456-6789')",
raw
- )).into())
+ ))
+ .into())
}
}
@@ -419,7 +425,8 @@ pub fn check_release_type(raw: &str) -> Result<()> {
Err(ErrorKind::NotInControlledVocabulary(format!(
"not a valid release_type: '{}' (expected a CSL type, eg, 'article-journal', 'book')",
raw
- )).into())
+ ))
+ .into())
}
#[test]
@@ -460,7 +467,8 @@ pub fn check_contrib_role(raw: &str) -> Result<()> {
Err(ErrorKind::NotInControlledVocabulary(format!(
"not a valid contrib.role: '{}' (expected a CSL type, eg, 'author', 'editor')",
raw
- )).into())
+ ))
+ .into())
}
#[test]
diff --git a/rust/src/bin/fatcat-export.rs b/rust/src/bin/fatcat-export.rs
index 9dd5138e..dd3f4da4 100644
--- a/rust/src/bin/fatcat-export.rs
+++ b/rust/src/bin/fatcat-export.rs
@@ -40,7 +40,7 @@ use std::io::{BufReader, BufWriter};
const CHANNEL_BUFFER_LEN: usize = 200;
-arg_enum!{
+arg_enum! {
#[derive(PartialEq, Debug, Clone, Copy)]
pub enum ExportEntityType {
Creator,
@@ -70,16 +70,26 @@ pub fn database_worker_pool() -> Result<ConnectionPool> {
macro_rules! generic_loop_work {
($fn_name:ident, $entity_model:ident) => {
- fn $fn_name(row_receiver: channel::Receiver<IdentRow>, output_sender: channel::Sender<String>, db_conn: &DbConn, expand: Option<ExpandFlags>) {
+ fn $fn_name(
+ row_receiver: channel::Receiver<IdentRow>,
+ output_sender: channel::Sender<String>,
+ db_conn: &DbConn,
+ expand: Option<ExpandFlags>,
+ ) {
let result: Result<()> = (|| {
for row in row_receiver {
- let mut entity = $entity_model::db_get_rev(db_conn, row.rev_id.expect("valid, non-deleted row"), HideFlags::none())
- .chain_err(|| "reading entity from database")?;
+ let mut entity = $entity_model::db_get_rev(
+ db_conn,
+ row.rev_id.expect("valid, non-deleted row"),
+ HideFlags::none(),
+ )
+ .chain_err(|| "reading entity from database")?;
//let mut entity = ReleaseEntity::db_get_rev(db_conn, row.rev_id.expect("valid, non-deleted row"))?;
entity.state = Some("active".to_string()); // XXX
entity.ident = Some(row.ident_id.to_string());
if let Some(expand) = expand {
- entity.db_expand(db_conn, expand)
+ entity
+ .db_expand(db_conn, expand)
.chain_err(|| "expanding sub-entities from database")?;
}
output_sender.send(serde_json::to_string(&entity)?);
@@ -91,7 +101,7 @@ macro_rules! generic_loop_work {
}
result.unwrap()
}
- }
+ };
}
generic_loop_work!(loop_work_container, ContainerEntity);
@@ -137,14 +147,14 @@ fn parse_line(s: &str) -> Result<IdentRow> {
#[test]
fn test_parse_line() {
- assert!(
- parse_line("00000000-0000-0000-3333-000000000001\t00000000-0000-0000-3333-fff000000001\t")
- .is_ok()
- );
- assert!(
- parse_line("00000-0000-0000-3333-000000000001\t00000000-0000-0000-3333-fff000000001\t")
- .is_err()
- );
+ assert!(parse_line(
+ "00000000-0000-0000-3333-000000000001\t00000000-0000-0000-3333-fff000000001\t"
+ )
+ .is_ok());
+ assert!(parse_line(
+ "00000-0000-0000-3333-000000000001\t00000000-0000-0000-3333-fff000000001\t"
+ )
+ .is_err());
assert!(
parse_line("00000-0000-0000-3333-000000000001\t00000000-0000-0000-3333-fff000000001")
.is_err()
diff --git a/rust/src/bin/fatcatd.rs b/rust/src/bin/fatcatd.rs
index b40ac3c4..57b6a3da 100644
--- a/rust/src/bin/fatcatd.rs
+++ b/rust/src/bin/fatcatd.rs
@@ -32,7 +32,8 @@ fn main() {
Arg::with_name("https")
.long("https")
.help("Whether to use HTTPS or not"),
- ).get_matches();
+ )
+ .get_matches();
let decorator = slog_term::TermDecorator::new().build();
let drain = slog_term::CompactFormat::new(decorator).build().fuse();
diff --git a/rust/src/database_models.rs b/rust/src/database_models.rs
index e8c7ad4e..a7076e09 100644
--- a/rust/src/database_models.rs
+++ b/rust/src/database_models.rs
@@ -25,7 +25,8 @@ impl EntityState {
EntityState::Active(_) => "active",
EntityState::Redirect(_, _) => "redirect",
EntityState::Deleted => "deleted",
- }.to_string()
+ }
+ .to_string()
}
}
diff --git a/rust/tests/test_old_python_tests.rs b/rust/tests/test_old_python_tests.rs
index eae131a7..d7e5c03b 100644
--- a/rust/tests/test_old_python_tests.rs
+++ b/rust/tests/test_old_python_tests.rs
@@ -277,20 +277,19 @@ fn test_merge_works() {
// merge works
client.merge_works(work_a_id, work_b_id)
*/
+// check results
+let work_a = match client.get_work(work_a_id.clone(), None).wait().unwrap() {
+GetWorkResponse::FoundEntity(e) => e,
+_ => unreachable!(),
+};
+let _work_b = match client.get_work(work_b_id.clone(), None).wait().unwrap() {
+GetWorkResponse::FoundEntity(e) => e,
+_ => unreachable!(),
+};
+// TODO: assert_eq!(work_a.revision.unwrap(), work_b.revision.unwrap());
+assert_eq!(work_a.redirect, None);
+// TODO: assert_eq!(work_b.redirect, Some(work_a_id));
- // check results
- let work_a = match client.get_work(work_a_id.clone(), None).wait().unwrap() {
- GetWorkResponse::FoundEntity(e) => e,
- _ => unreachable!(),
- };
- let _work_b = match client.get_work(work_b_id.clone(), None).wait().unwrap() {
- GetWorkResponse::FoundEntity(e) => e,
- _ => unreachable!(),
- };
- // TODO: assert_eq!(work_a.revision.unwrap(), work_b.revision.unwrap());
- assert_eq!(work_a.redirect, None);
- // TODO: assert_eq!(work_b.redirect, Some(work_a_id));
-
- server.close().unwrap()
+server.close().unwrap()
}
*/