Last active
January 20, 2020 21:46
-
-
Save jayanthdeejay/9238cbf3a24ba6f289de645ea03ca385 to your computer and use it in GitHub Desktop.
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
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 }] | |
} | |
final_options = default_options.merge(options.except(:title)) | |
Hyrax::CollectionTypes::CreateService.create_collection_type(machine_id: machine_id, title: options[:title], options: final_options) | |
end | |
def create_public_collection(user, type_gid, id, options) | |
options[:visibility] = Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC | |
create_collection(user, type_gid, id, options) | |
end | |
def create_collection(user, type_gid, id, options) | |
col = Collection.where(id: id) | |
return col.first if col.present? | |
col = Collection.new(id: id) | |
col.attributes = options.except(:visibility) | |
col.apply_depositor_metadata(user.user_key) | |
col.collection_type_gid = type_gid | |
col.visibility = options[:visibility] | |
col.save | |
Hyrax::Collections::PermissionsCreateService.create_default(collection: col, creating_user: user) | |
col | |
end | |
nestable_gid = create_collection_type('nestable_collection', options).gid | |
scae = create_public_collection(user, nestable_gid, 'scae', title: ['Special Collections, Archives, and Exhibits'], description: ['Special Collections, Archives, and Exhibits']) | |
scae.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX | |
scae.save() | |
cdn = create_public_collection(user, nestable_gid, 'cdn', title: ["Charles Dickens's Novels"], description: ["Charles Dickens's Novels"]) | |
cdn.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX | |
cdn.save() | |
nn = create_public_collection(user, nestable_gid, 'nn', title: ['Nicholas Nickleby'], description: ['Nicholas Nickleby']) | |
nn.reindex_extent = Hyrax::Adapters::NestingIndexAdapter::LIMITED_REINDEX | |
nn.save() | |
Hyrax::Collections::NestedCollectionPersistenceService.persist_nested_collection_for(parent: scae, child: cdn) | |
Hyrax::Collections::NestedCollectionPersistenceService.persist_nested_collection_for(parent: cdn, child: nn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment