Skip to content

Commit

Permalink
PPPL Department name change from PS&T to Discovery Plasma Science (#1505
Browse files Browse the repository at this point in the history
)

* Re-name PPPL subcommunity

Rename "Plasma Science and Technology" sub-community to
"Discovery Plasma Science"

* Update metadata for PPPL department name changes

* Updates to UI and tests
* Tested service to update metadata for existing records
* Rake task to run that service
* Documentation for process in /docs directory

* Remove stray require statement
  • Loading branch information
bess authored Sep 12, 2023
1 parent 4be970e commit cd69d8b
Show file tree
Hide file tree
Showing 10 changed files with 219 additions and 4 deletions.
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ Style/StringLiterals:
Rails/Output:
Exclude:
- app/models/ark.rb
- app/services/work_update_metadata_service.rb

Rails/UnknownEnv:
Enabled: false
Expand Down
2 changes: 1 addition & 1 deletion app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def subcommunities
values << "Theory"
values << "NSTX-U"
values << "NSTX"
values << "Plasma Science & Technology"
values << "Discovery Plasma Science"
values << "Theory and Computation"
values << "Stellarators"
values << "PPPL Collaborations"
Expand Down
43 changes: 43 additions & 0 deletions app/services/work_update_metadata_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

# A service to update metadata across PDC Describe
class WorkUpdateMetadataService
RENAMED_PPPL_SUBCOMMUNITIES = [
{
old: "Plasma Science & Technology",
new: "Discovery Plasma Science"
}
].freeze

# For each renamed pppl subcommunity, traverse all of the works
# and update the value
def self.update_pppl_subcommunities(user, commandline: false)
Work.all.each do |work|
resource_before = work.resource.dup
RENAMED_PPPL_SUBCOMMUNITIES.each do |renamed_subcommunity|
sc = work.resource.subcommunities
next unless sc.include? renamed_subcommunity[:old]
puts "Updating work #{work.id}" if commandline
work.resource.subcommunities = new_subcommunities(sc, renamed_subcommunity)
end
work.save
resource_after = work.resource
resource_compare = ResourceCompareService.new(resource_before, resource_after)
WorkActivity.add_work_activity(work.id, resource_compare.differences.to_json, user.id, activity_type: WorkActivity::CHANGES)
end
end

# Given a list of subcommunities, and a Hash from RENAMED_PPPL_SUBCOMMUNITIES,
# replace all instances of :old with :new
def self.new_subcommunities(sc, renamed_subcommunity)
new_subcommunities = []
sc.each do |subcommunity|
new_subcommunities << if subcommunity == renamed_subcommunity[:old]
renamed_subcommunity[:new]
else
subcommunity
end
end
new_subcommunities
end
end
12 changes: 12 additions & 0 deletions docs/bulk_metadata_updates.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Bulk Metadata Updates
When we have metadata updates that need to be undertaken thoughout the system, this is the process.

## PPPL Department Name Change
PPPL department names appear in the `subcommunities` field in PDC Describe, because that is how they were labeled in the legacy DataSpace application.
1. Update the UI and tests to reflect the new change
2. Update the change map in `WorkUpdateMetadataService`
3. Test the change locally, and follow regular software release processes
4. Once the updated code is on the server, run the rake task to update any existing records to the new PPPL department name:
```
bundle exec rake metadata:update_pppl_subcommunities\[YOUR_NETID]
```
13 changes: 13 additions & 0 deletions lib/tasks/metadata.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

namespace :metadata do
# command line syntax: bundle exec rake metadata:update_pppl_subcommunities\["netid"\]
desc "Update renamed PPPL subcommunities"
task :update_pppl_subcommunities, [:netid] => [:environment] do |_, args|
netid = args[:netid]
user = User.find_by(uid: netid)
raise("No user found for id #{netid}") unless user
WorkUpdateMetadataService.update_pppl_subcommunities(user, commandline: true)
puts "Updated subcommunities metadata, recorded user #{netid} in WorkActivity"
end
end
11 changes: 11 additions & 0 deletions spec/factories/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,17 @@
created_by_user_id { FactoryBot.create(:pppl_submitter).id }
end

factory :pppl_work_with_department_name_change do
group { Group.plasma_laboratory }
state { "awaiting_approval" }
resource do
json_from_spec = File.read(Rails.root.join("spec", "fixtures", "rename_pppl_dept1.json"))
resource = JSON.parse(json_from_spec)["resource"]
PDCMetadata::Resource.new_from_jsonb(resource)
end
created_by_user_id { FactoryBot.create(:pppl_submitter).id }
end

factory :sowing_the_seeds_work do
title { "Sowing the Seeds for More Usable Web Archives: A Usability Study of Archive-It" }
group { Group.research_data }
Expand Down
108 changes: 108 additions & 0 deletions spec/fixtures/rename_pppl_dept1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"resource": {
"titles": [
{
"title": "Data for \"The value of fusion energy to a decarbonized United States electric grid\"",
"title_type": null
}
],
"description": "Fusion could be a part of future decarbonized electricity systems, but it will need to compete with other technologies. In particular, pulsed tokamaks plants have a unique operational mode, and evaluating which characteristics make them economically competitive can help select between design pathways. Using a capacity expansion and operations model, we determined cost thresholds for pulsed tokamaks to reach a range of penetration levels in a future decarbonized US Eastern Interconnection. The required capital cost to reach a fusion capacity of 100 GW varied from $3000 to $7200/kW, and the equilibrium penetration increases rapidly with decreasing cost. The value per unit power capacity depends on the variable operational cost and on cost of its competition, particularly fission, much more than on the pulse cycle parameters. These findings can therefore provide initial cost targets for fusion more generally in the United States.",
"collection_tags": [
"Discovery Plasma Science"
],
"creators": [
{
"value": "Schwartz, Jacob A.",
"name_type": "Personal",
"given_name": "Jacob A.",
"family_name": "Schwartz",
"identifier": {
"value": "0000-0001-9636-8181",
"scheme": "ORCID",
"scheme_uri": "https://orcid.org"
},
"affiliations": [],
"sequence": 0
},
{
"value": "Ricks, Wilson",
"name_type": "Personal",
"given_name": "Wilson",
"family_name": "Ricks",
"identifier": null,
"affiliations": [],
"sequence": 1
},
{
"value": "Kolemen, Egemen",
"name_type": "Personal",
"given_name": "Egemen",
"family_name": "Kolemen",
"identifier": {
"value": "0000-0003-4212-3247",
"scheme": "ORCID",
"scheme_uri": "https://orcid.org"
},
"affiliations": [],
"sequence": 2
},
{
"value": "Jenkins, Jesse D.",
"name_type": "Personal",
"given_name": "Jesse D.",
"family_name": "Jenkins",
"identifier": {
"value": "0000-0002-9670-7793",
"scheme": "ORCID",
"scheme_uri": "https://orcid.org"
},
"affiliations": [],
"sequence": 3
}
],
"resource_type": "Dataset",
"resource_type_general": "Dataset",
"publisher": "Princeton University",
"publication_year": "2022",
"doi": "10.34770/f8em-3c49",
"rights_many": [
{
"identifier": "CC BY",
"uri": "https://creativecommons.org/licenses/by/4.0/",
"name": "Creative Commons Attribution 4.0 International"
}
],
"version_number": "1",
"related_objects": [],
"keywords": [],
"contributors": [],
"organizational_contributors": [],
"funders": [
{
"ror": "https://ror.org/01bj3aw27",
"funder_name": "United States Department of Energy",
"award_number": "DE-AC02-09CH11466",
"award_uri": ""
}
],
"domains": [
"Natural Sciences"
],
"communities": [
"Princeton Plasma Physics Laboratory"
],
"subcommunities": [
"Plasma Science & Technology",
"Fake Subcommunity"
],
"migrated": true
},
"files": [],
"group": {
"title": "Princeton Plasma Physics Lab (PPPL)",
"description": null,
"code": "PPPL",
"created_at": "2023-09-11T09:17:56.476-04:00",
"updated_at": "2023-09-11T09:17:56.476-04:00"
}
}
19 changes: 19 additions & 0 deletions spec/services/work_update_metadata_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true
require "rails_helper"

RSpec.describe WorkUpdateMetadataService do
include ActiveJob::TestHelper
context "a PPPL department name change" do
let(:work) { FactoryBot.create :pppl_work_with_department_name_change }
let(:user) { FactoryBot.create :pppl_submitter }
it "renames PPPL subcommunities" do
expect(work.resource.subcommunities).to contain_exactly("Plasma Science & Technology", "Fake Subcommunity")
expect(work.work_activity).to be_empty
described_class.update_pppl_subcommunities(user)
work.reload
expect(work.resource.subcommunities).to contain_exactly("Discovery Plasma Science", "Fake Subcommunity")
expect(work.work_activity.count).to eq 1
expect(JSON.parse(work.work_activity.last.message)["subcommunities"].first["action"]).to eq "changed"
end
end
end
12 changes: 10 additions & 2 deletions spec/system/data_migration/fusion_energy_form_submission_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"Fusion could be a part of future decarbonized electricity systems, but it will need to compete with other technologies. In particular, pulsed tokamaks plants have a unique operational mode, and evaluating which characteristics make them economically competitive can help select between design pathways. Using a capacity expansion and operations model, we determined cost thresholds for pulsed tokamaks to reach a range of penetration levels in a future decarbonized US Eastern Interconnection. The required capital cost to reach a fusion capacity of 100 GW varied from $3000 to $7200/kW, and the equilibrium penetration increases rapidly with decreasing cost. The value per unit power capacity depends on the variable operational cost and on cost of its competition, particularly fission, much more than on the pulse cycle parameters. These findings can therefore provide initial cost targets for fusion more generally in the United States."
end
let(:ark) { "ark:/88435/dsp012j62s808w" }
let(:collection_tags) { ["Plasma Science & Technology"] }
let(:collection_tags) { ["Discovery Plasma Science"] }
let(:group) { "Princeton Plasma Physics Lab (PPPL)" }
let(:publisher) { "Princeton University" }
let(:doi) { "10.34770/f8em-3c49" }
Expand All @@ -23,6 +23,8 @@
it "produces and saves a valid datacite record" do
sign_in user
visit "/works/new?migrate=true"

## Required Metadata Tab
fill_in "title_main", with: title
fill_in "description", with: description
select "Creative Commons Attribution 4.0 International", from: "rights_identifiers"
Expand All @@ -42,13 +44,19 @@
find("tr:last-child input[name='creators[][given_name]']").set "Jesse D."
find("tr:last-child input[name='creators[][family_name]']").set "Jenkins"

## Additional Metadata Tab
click_on "Additional Metadata"

## Funder Information
# Funder Information
# https://ror.org/01bj3aw27 == ROR for United States Department of Energy
page.find(:xpath, "//table[@id='funding']//tr[1]//input[@name='funders[][ror]']").set "https://ror.org/01bj3aw27"
page.find(:xpath, "//table[@id='funding']//tr[1]//input[@name='funders[][award_number]']").set "DE-AC02-09CH11466"

select "Natural Sciences", from: "domains"
select "Princeton Plasma Physics Laboratory", from: "communities"
select "Discovery Plasma Science", from: "subcommunities"

## Curator Controlled Tab
click_on "Curator Controlled"
fill_in "publisher", with: publisher
fill_in "publication_year", with: 2022
Expand Down
2 changes: 1 addition & 1 deletion spec/system/user_edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
expect(page).to have_checked_field "group_messaging_#{pppl_group.id}_Theory"
expect(page).to have_checked_field "group_messaging_#{pppl_group.id}_NSTX-U"
expect(page).to have_checked_field "group_messaging_#{pppl_group.id}_NSTX"
expect(page).to have_checked_field "group_messaging_#{pppl_group.id}_Plasma Science & Technology"
expect(page).to have_checked_field "group_messaging_#{pppl_group.id}_Discovery Plasma Science"
expect(page).to have_checked_field "group_messaging_#{pppl_group.id}_Theory and Computation"
expect(page).to have_checked_field "group_messaging_#{pppl_group.id}_Stellarators"
expect(page).to have_checked_field "group_messaging_#{pppl_group.id}_PPPL Collaborations"
Expand Down

0 comments on commit cd69d8b

Please sign in to comment.