Skip to content

Instantly share code, notes, and snippets.

@jrgriffiniii
Last active August 6, 2020 18:13
Show Gist options
  • Save jrgriffiniii/d85479398e13244377f9d05a0b1905e6 to your computer and use it in GitHub Desktop.
Save jrgriffiniii/d85479398e13244377f9d05a0b1905e6 to your computer and use it in GitHub Desktop.
DataSpace Collection Mapping for Certificate Programs
netid = "jrg5@princeton.edu"
DSpace.login(netid)
require "/usr/local/DR/home/dspace/ruby/dspace-jruby/program_membership_job"
program_name = "East Asian Studies Program"
collection_handle = "88435/dsp016682x659t"
job = ProgramMembershipJob.build(program_name, collection_handle)
job.perform
DSpace.commit
class ProgramMembershipJob
def self.build(program_name, collection_handle)
program_collection = DSpace.fromString(collection_handle)
new(program_name, program_collection)
end
def initialize(program_name, program_collection)
@program_name = program_name
@program_collection = program_collection
end
def collection_members
@collection_members ||= begin
itr = @program_collection.getItems
members = []
while (itr.hasNext) do
member = itr.next
members << member
end
members
end
end
def in_collection?(item)
member_ids = collection_members.map(&:getID)
member_ids.include?(item.getID)
end
def find_by_program
DSpace.findByMetadataValue("pu.certificate", @program_name, DConstants::ITEM)
end
def perform
items = find_by_program
items.each do |item|
if !in_collection?(item)
puts "Adding the Item #{item.getID} to the Collection #{@program_collection.getID}"
@program_collection.addItem(item)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment