Skip to content

Instantly share code, notes, and snippets.

user = User.find_by(:email => "depositor@wpi.edu")
options = { title: 'Nestable Collection', description: 'Sample collection type that allows nesting of collections.', nestable: true, discoverable: true, sharable: true, allow_multiple_membership: true, require_membership: true }
def create_collection_type(machine_id, options)
coltype = Hyrax::CollectionType.find_by_machine_id(machine_id)
return coltype if coltype.present?
default_options = {
nestable: false, discoverable: false, sharable: false, allow_multiple_membership: false,
require_membership: false, assigns_workflow: false, assigns_visibility: false,
participants: [{ agent_type: Hyrax::CollectionTypeParticipant::GROUP_TYPE, agent_id: ::Ability.admin_group_name, access: Hyrax::CollectionTypeParticipant::MANAGE_ACCESS },
{ agent_type: Hyrax::CollectionTypeParticipant::GROUP_TYPE, agent_id: ::Ability.registered_group_name, access: Hyrax::CollectionTypeParticipant::CREATE_ACCESS }]
gf = GenericFile.find("abc123")
file = File.open("file name")
content = file.read
gf.content.content = content
gf.create_derivatives
gf.visibility = "open"
gf.save
@jayanthdeejay
jayanthdeejay / digest_check.rb
Created January 19, 2020 04:17 — forked from awead/digest_check.rb
Version checksum report
# Checks the shasum of each version and current content in old production
# and compares it to those in new production.
#
# To run the report, go to the Rails console and copy-in the two classes in the file.
# Then run:
#
# > report = ChecksumReport.new
#
# The report is an array of hashes, each of which looks like:
#
@jayanthdeejay
jayanthdeejay / gist:9b15dcf6803d2894dd77d8d4d5e5e05d
Created January 19, 2020 04:09 — forked from hortongn/gist:b842074c8a3cfb0a0c09c6bce4e5e80a
Find all works in a collection and update the editors for each work
c = Collection.find('d504rk335')
work_ids = []
c.member_objects.each do |member|
work_ids << member.id
end
new_edit_users = ["user1@example.com", "user2@example.com"]
def change_edit_users(work_ids, new_edit_users)
work_ids.each do |pid|
@jayanthdeejay
jayanthdeejay / analytics_test.rb
Created January 19, 2020 04:01 — forked from mjgiarlo/analytics_test.rb
legato filtering out 0-result dates?
# Inspired by https://gist.github.com/3166610
require 'google/api_client'
require 'date'
API_VERSION = 'v3'
CACHED_API_FILE = "analytics-#{API_VERSION}.cache"
# Update these to match your own apps credentials
service_account_email = 'foobar@developer.gserviceaccount.com' # Email of service account
key_file = '/tmp/foobar-privatekey.p12' # File containing your private key
2.2.1 :003 > ActiveFedora::Noid::Service.new.mint
seed is 271030524290525531404955989783767342781
counters size is 293
@rand.rand(counters.size) is 261
counters[261] is {:value=>6300353125, :max=>6324492408}
counters[261][:value] is 6300353125
counters[261][:value] is now 6300353126
=> "vt150j25g"
2.2.1 :004 > ActiveFedora::Noid::Service.new.mint
seed is 271030524290525531404955989783767342781
class Book < ActiveFedora::Base
include Hydra::Works::Work
end
class Page < ActiveFedora::Base
include Hydra::Works::Work
end
book = Book.new
page = Page.new
@jayanthdeejay
jayanthdeejay / characterization.rb
Created January 19, 2020 03:52 — forked from jcoyne/characterization.rb
Test characterization hydra pcdm goldenseal curationexperts
fs = FileSet.find('mp48sc83h')
file_name = 'tmp/uploads/mp/48/sc/83/letz_01_0020_019.tif'
service = Hydra::Works::CharacterizationService.new(fs, file_name, {})
fits_output = service.send(:extract_metadata, file_name)
terms = service.send(:parse_metadata, fits_output)
irb(main):006:0> local_file = File.open('spec/fixtures/images/world.png') => #<File:spec/fixtures/images/world.png>
irb(main):007:0> local_file = Hydra::Derivatives::IoDecorator.new(local_file)
=> #<File:spec/fixtures/images/world.png>
irb(main):008:0> local_file.mime_type = 'application/foo'
=> "application/foo"
irb(main):009:0> local_file.original_name = 'world.png'
=> "world.png"
irb(main):010:0> Hydra::Works::AddFileToFileSet.call(fs, local_file, :original_file, versioning: false)
Unable to check /var/folders/9t/rygbnddx0b1ckw6tjs3m18qm0000gq/T/20160531-85153-cfleh6 for viruses because no virus scanner is defined
=> #<FileSet id: "ww72bb63r", label: nil, relative_path: nil, import_url: nil, part_of: [], resource_type: [], creator: [], contributor: [], description: [], keyword: [], rights: [], publisher: [], date_created: [], subject: [], language: [], identifier: [], based_near: [], related_url: [], bibliographic_citation: [], source: [], head: [], tail: [], depositor: "jcoyne", title: [], date_uploaded:
@jayanthdeejay
jayanthdeejay / add_work_to_col.rb
Created June 6, 2019 19:30
Add works to collection
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?