• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / pdc_describe / 9dbcf7a4-1c56-4510-9614-74ad5a22cff6

31 Jul 2024 02:46PM UTC coverage: 1.08% (-95.1%) from 96.17%
9dbcf7a4-1c56-4510-9614-74ad5a22cff6

push

circleci

jrgriffiniii
wip

52 of 4814 relevant lines covered (1.08%)

0.01 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/app/services/work_update_metadata_service.rb
1
# frozen_string_literal: true
2

3
# A service to update metadata across PDC Describe
4
class WorkUpdateMetadataService
×
5
  RENAMED_PPPL_SUBCOMMUNITIES = [
×
6
    {
×
7
      old: "Plasma Science & Technology",
×
8
      new: "Discovery Plasma Science"
×
9
    }
×
10
  ].freeze
×
11

12
  # For each renamed pppl subcommunity, traverse all of the works
13
  # and update the value
14
  def self.update_pppl_subcommunities(user, commandline: false)
×
15
    Work.all.each do |work|
×
16
      resource_before = work.resource.dup
×
17
      RENAMED_PPPL_SUBCOMMUNITIES.each do |renamed_subcommunity|
×
18
        sc = work.resource.subcommunities
×
19
        next unless sc.include? renamed_subcommunity[:old]
×
20
        puts "Updating work #{work.id}" if commandline
×
21
        work.resource.subcommunities = new_subcommunities(sc, renamed_subcommunity)
×
22
      end
×
23
      work.save
×
24
      resource_after = work.resource
×
25
      resource_compare = ResourceCompareService.new(resource_before, resource_after)
×
26
      WorkActivity.add_work_activity(work.id, resource_compare.differences.to_json, user.id, activity_type: WorkActivity::CHANGES)
×
27
    end
×
28
  end
×
29

30
  # Given a list of subcommunities, and a Hash from RENAMED_PPPL_SUBCOMMUNITIES,
31
  # replace all instances of :old with :new
32
  def self.new_subcommunities(sc, renamed_subcommunity)
×
33
    new_subcommunities = []
×
34
    sc.each do |subcommunity|
×
35
      new_subcommunities << if subcommunity == renamed_subcommunity[:old]
×
36
                              renamed_subcommunity[:new]
×
37
                            else
×
38
                              subcommunity
×
39
                            end
×
40
    end
×
41
    new_subcommunities
×
42
  end
×
43
end
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc