Skip to content

Commit

Permalink
Deleted old comments and test code
Browse files Browse the repository at this point in the history
  • Loading branch information
brendan-oconnell committed Sep 5, 2024
1 parent 3c3bd58 commit 000ef5b
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 89 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

151 changes: 74 additions & 77 deletions thoth-api/src/graphql/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1973,35 +1973,6 @@ impl MutationRoot {
#[graphql(description = "Values to apply to existing location")] data: PatchLocation,
) -> FieldResult<Location> {
context.token.jwt.as_ref().ok_or(ThothError::Unauthorised)?;
let current_location = Location::from_id(&context.db, &data.location_id).unwrap();

context
.account_access
.can_edit(current_location.publisher_id(&context.db)?)?;

if data.publication_id != current_location.publication_id {
context
.account_access
.can_edit(publisher_id_from_publication_id(
&context.db,
data.publication_id,
)?)?;
}

// check has been commented out to allow for changing canonical location. If this check
// is left in place, canonical location can't be updated because check is violated during
// the mutation when there are (temporarily) two canonical locations before the mutation
// is completed. Equivalent check is maintained in the DB, so hopefully this can
// be left out and the check will still be completed at the DB level, preventing more
// than one canonical location.
// if data.canonical != current_location.canonical {
// // This looks at any time you want to change canonical location.
// // Each publication must have exactly one canonical location.
// // Updating an existing location would always violate this,
// // as it should always result in either zero or two canonical locations.
// return Err(ThothError::CanonicalLocationError.into());
// }


let all_location_platforms = Some(vec![
LocationPlatform::ProjectMuse,
Expand All @@ -2023,33 +1994,59 @@ impl MutationRoot {
LocationPlatform::Other,
]);

// get current publication
let publication = Publication::from_id(&context.db, &data.publication_id).unwrap();
// get all locations from current publication
let locations = Publication::locations(&publication, context, Some(100), Some(0), Some(LocationOrderBy::default()), all_location_platforms);
// println!("publication contains: {:?}", publication);
// println!("locations are: {:?}", locations);
println!("PatchLocation data is: {:?}", &data);
// example of PatchLocation data:
// PatchLocation { location_id: b2e14c78-5fbe-4526-8206-f28dd335a981,
// publication_id: 5ece37a1-3aae-4e9c-8580-5c1d38375f4a,
// landing_page: Some("https://thoth-arch.lib.cam.ac.uk/handle/1811/86ggggggaaa444555444333121121"),
// full_text_url: Some("https://fulltext30.com"),
// location_platform: Zenodo, canonical: false }
let location = Location::from_id(&context.db, &data.location_id).unwrap();
let mut canonical_location: Option<PatchLocation> = None;

// for location in locations {
// println!("Individual Location is: {:?}", location);
// }
context
.account_access
.can_edit(location.publisher_id(&context.db)?)?;

if data.publication_id != location.publication_id {
context
.account_access
.can_edit(publisher_id_from_publication_id(
&context.db,
data.publication_id,
)?)?;
}

// example of publication variable:
// Publication { publication_id: 5ece37a1-3aae-4e9c-8580-5c1d38375f4a,
// publication_type: Pdf, work_id: 5fb9a23a-bf8e-4527-9c9c-3786b7219285,
// isbn: Some(Isbn("978-1-80064-730-5")), created_at: Timestamp(2022-06-13T08:24:51.502655Z),
// updated_at: Timestamp(2022-06-13T08:24:51.502655Z), width_mm: None,
// width_in: None, height_mm: None, height_in: None, depth_mm: None, depth_in: None, weight_g: None, weight_oz: None }
if data.canonical != location.canonical {
return Err(ThothError::CanonicalLocationError.into());
}

let publication = Publication::from_id(&context.db, &data.publication_id).unwrap();

// get all locations from current publication
let locations = Publication::locations(
&publication,
context,
Some(100),
Some(0),
Some(LocationOrderBy::default()),
all_location_platforms,
);

if let Ok(locations) = locations {
for location in locations {
if location.canonical {
canonical_location = Some(PatchLocation {
location_id: location.location_id,
publication_id: location.publication_id,
landing_page: location.landing_page.clone(),
full_text_url: location.full_text_url.clone(),
location_platform: location.location_platform.clone(),
canonical: location.canonical,
});
break;
}
}
}

if let Some(canonical_location) = canonical_location {
println!("Canonical PatchLocation: {:?}", canonical_location);
} else {
println!("No canonical location found.");
}

if data.canonical {
data.canonical_record_complete(&context.db)?;
Expand All @@ -2058,25 +2055,25 @@ impl MutationRoot {
// let account_id = context.token.jwt.as_ref().unwrap().account_id(&context.db);
let connection = &mut context.db.get().unwrap();

let zenodo_location_id = Uuid::parse_str("b2e14c78-5fbe-4526-8206-f28dd335a981").unwrap();
let zenodo_patch_location = PatchLocation {
location_id: Uuid::parse_str("b2e14c78-5fbe-4526-8206-f28dd335a981").unwrap(),
publication_id: Uuid::parse_str("5ece37a1-3aae-4e9c-8580-5c1d38375f4a").unwrap(),
landing_page: Some("https://thoth-arch.lib.cam.ac.uk/handle/1811/hardcoded_zenodo".to_string()),
full_text_url: Some("https://fulltext30zenodo.com".to_string()),
location_platform: LocationPlatform::Zenodo,
canonical: true,
};

let scienceopen_location_id = Uuid::parse_str("8b5791e5-15c2-42aa-8211-65041d8cf2e5").unwrap();
let scienceopen_patch_location = PatchLocation {
location_id: Uuid::parse_str("8b5791e5-15c2-42aa-8211-65041d8cf2e5").unwrap(),
publication_id: Uuid::parse_str("5ece37a1-3aae-4e9c-8580-5c1d38375f4a").unwrap(),
landing_page: Some("https://thoth-arch.lib.cam.ac.uk/handle/1811/hardcoded_scienceopen".to_string()),
full_text_url: Some("https://fulltext30scienceopen.com".to_string()),
location_platform: LocationPlatform::ScienceOpen,
canonical: false,
};
// let zenodo_location_id = Uuid::parse_str("b2e14c78-5fbe-4526-8206-f28dd335a981").unwrap();
// let zenodo_patch_location = PatchLocation {
// location_id: Uuid::parse_str("b2e14c78-5fbe-4526-8206-f28dd335a981").unwrap(),
// publication_id: Uuid::parse_str("5ece37a1-3aae-4e9c-8580-5c1d38375f4a").unwrap(),
// landing_page: Some("https://thoth-arch.lib.cam.ac.uk/handle/1811/hardcoded_zenodo".to_string()),
// full_text_url: Some("https://fulltext30zenodo.com".to_string()),
// location_platform: LocationPlatform::Zenodo,
// canonical: false,
// };

// let scienceopen_location_id = Uuid::parse_str("8b5791e5-15c2-42aa-8211-65041d8cf2e5").unwrap();
// let scienceopen_patch_location = PatchLocation {
// location_id: Uuid::parse_str("8b5791e5-15c2-42aa-8211-65041d8cf2e5").unwrap(),
// publication_id: Uuid::parse_str("5ece37a1-3aae-4e9c-8580-5c1d38375f4a").unwrap(),
// landing_page: Some("https://thoth-arch.lib.cam.ac.uk/handle/1811/hardcoded_scienceopen".to_string()),
// full_text_url: Some("https://fulltext30scienceopen.com".to_string()),
// location_platform: LocationPlatform::ScienceOpen,
// canonical: true,
// };

// if in transaction you try to set the new canonical to true first, you have two canonical locations at the same time,
// and get
Expand All @@ -2089,13 +2086,13 @@ impl MutationRoot {
// if not canonical location and want to make canonical, update existing canonical
// to set to false, set new to true
connection.transaction(|connection| {
// diesel::update(location::table.find(data.location_id))
diesel::update(location::table.find(scienceopen_location_id))
.set(scienceopen_patch_location)
// .set(&data)
.get_result::<Location>(connection);
diesel::update(location::table.find(zenodo_location_id))
.set(zenodo_patch_location)
diesel::update(location::table.find(data.location_id))
// diesel::update(location::table.find(zenodo_location_id))
// .set(zenodo_patch_location)
.set(&data)
// .get_result::<Location>(connection);
// diesel::update(location::table.find(scienceopen_location_id))
// .set(scienceopen_patch_location)
// .set(&data)
.get_result::<Location>(connection)
.map_err(|e| e.into())
Expand Down
10 changes: 0 additions & 10 deletions thoth-app/src/models/location/location_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@ use serde::Serialize;
use thoth_api::model::location::Location;
use uuid::Uuid;

// locationId: Uuid!
// publicationId: Uuid!
// landingPage: String
// fullTextUrl: String
// locationPlatform: LocationPlatform!
// canonical: Boolean!
// createdAt: Timestamp!
// updatedAt: Timestamp!
// publication: Publication!

pub const LOCATION_QUERY: &str = "
query LocationQuery($locationId: Uuid!) {
location(locationId: $locationId) {
Expand Down

0 comments on commit 000ef5b

Please sign in to comment.