Created
June 6, 2019 19:30
-
-
Save jayanthdeejay/dc9ace0adb4f55d11a052ae6effcde89 to your computer and use it in GitHub Desktop.
Add works to collection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
worktype = Etd | |
all_specified_works = worktype.where({:resource_type => 'thesis'}) #the select is something like '{:resource_type => "thesis"}' | |
col = Collection.find('gps') | |
col.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX | |
all_specified_works.each do |work| | |
if work.member_of_collections.empty? | |
work.member_of_collections += [col] | |
end | |
year = work.date_created[0].split("-")[0] | |
if not work.year.present? | |
work.year = year | |
end | |
work.related_url = [] | |
work.save() | |
end | |
col.save() | |
worktype = Etd | |
all_specified_works = worktype.all #the select is something like '{:resource_type => "thesis"}' | |
thesi = Collection.find('thesis') | |
thesi.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX | |
diss = Collection.find('dissertation') | |
diss.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX | |
all_specified_works.each do |work| | |
if work.member_of_collections.empty? | |
if work.resource_type.include? 'Thesis' | |
work.member_of_collections += [thesi] | |
work.save() | |
end | |
if work.resource_type.include? 'Dissertation' | |
work.member_of_collections += [diss] | |
work.save() | |
end | |
end | |
end | |
thesi.save() | |
diss.save() | |
worktype = StudentWork | |
all_specified_works = worktype.where({:related_url => "Great Problems Seminar"}) #the select is something like '{:resource_type => "thesis"}' | |
all_specified_works.each do |work| | |
year = work.date_created[0].split(" ")[-1] | |
if not work.year.present? | |
work.year = year | |
work.save() | |
end | |
end | |
#trim whitespace | |
col = Collection.find('gps') | |
col.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX | |
all_gps = col.member_works | |
all_gps.each do |gps| | |
original_array = gps['contributor'] | |
new_arr = [] | |
original_array.each do |cont| | |
new_arr += [cont.strip()] | |
end | |
if gps['contributor'].to_a - new_arr != [] #if they do not contain the same items | |
gps['contributor'] = new_arr | |
gps.save() | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment