Class: Bplmodels::Collection
- Inherits:
-
RelationBase
- Object
- ActiveFedora::Base
- RelationBase
- Bplmodels::Collection
- Defined in:
- app/models/bplmodels/collection.rb
Direct Known Subclasses
Class Method Summary collapse
-
.mint(args) ⇒ Object
Expects the following args: parent_pid => id of the parent object local_id => local ID of the object local_id_type => type of that local ID label => label of the collection.
Instance Method Summary collapse
- #add_oai_relationships ⇒ Object
- #fedora_name ⇒ Object
-
#insert_member(fedora_object) ⇒ Object
A collection can have another collection as a member, or an image.
- #to_solr(doc = {}) ⇒ Object
Methods inherited from RelationBase
#apply_default_permissions, #assert_content_model, #convert_to
Class Method Details
.mint(args) ⇒ Object
Expects the following args: parent_pid => id of the parent object local_id => local ID of the object local_id_type => type of that local ID label => label of the collection
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'app/models/bplmodels/collection.rb', line 104 def self.mint(args) #TODO: Duplication check here to prevent over-writes? args[:namespace_id] ||= ARK_CONFIG_GLOBAL['namespace_commonwealth_pid'] response = Typhoeus::Request.post(ARK_CONFIG_GLOBAL['url'] + "/arks.json", :params => {:ark=>{:parent_pid=>args[:parent_pid], :namespace_ark => ARK_CONFIG_GLOBAL['namespace_commonwealth_ark'], :namespace_id=>args[:namespace_id], :url_base => ARK_CONFIG_GLOBAL['ark_commonwealth_base'], :model_type => self.name, :local_original_identifier=>args[:local_id], :local_original_identifier_type=>args[:local_id_type]}}) begin as_json = JSON.parse(response.body) rescue => ex raise('Error in JSON response for minting a collection pid.') end Bplmodels::Collection.find_in_batches('id'=>as_json["pid"]) do |group| group.each { |solr_result| return as_json["pid"] } end object = self.new(:pid=>as_json["pid"]) title = Bplmodels::DatastreamInputFuncs.getProperTitle(args[:label]) object.label = args[:label] object.descMetadata.insert_title(title[0], title[1]) object.add_relationship(:is_member_of, "info:fedora/" + args[:parent_pid]) uri = ARK_CONFIG_GLOBAL['url'] + '/ark:/'+ as_json["namespace_ark"] + '/' + as_json["noid"] object.descMetadata.insert_access_links(nil, uri) object.add_oai_relationships object.read_groups = ["public"] object.edit_groups = ["superuser", "admin[#{args[:parent_pid]}]"] return object end |
Instance Method Details
#add_oai_relationships ⇒ Object
42 43 44 45 46 |
# File 'app/models/bplmodels/collection.rb', line 42 def add_oai_relationships #self.add_relationship(:oai_item_id, "oai:digitalcommonwealth.org:" + self.pid, true) self.add_relationship(:oai_set_spec, self.pid, true) self.add_relationship(:oai_set_name, self.label.gsub(' & ', ' & '), true) end |
#fedora_name ⇒ Object
48 49 50 |
# File 'app/models/bplmodels/collection.rb', line 48 def fedora_name 'collection' end |
#insert_member(fedora_object) ⇒ Object
A collection can have another collection as a member, or an image
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'app/models/bplmodels/collection.rb', line 17 def insert_member(fedora_object) if (fedora_object.instance_of?(Bplmodels::ObjectBase)) #add to the members ds #members.insert_member(:member_id=>fedora_object.pid, :member_title=>fedora_object.titleSet_display, :member_type=>fedora_object.fedora_name #add to the rels-ext ds #fedora_object.collections << self #self.objects << fedora_object #self.add_relationship(:has_image, "info:fedora/#{fedora_object.pid}") elsif (fedora_object.instance_of?(Bplmodels::Institution)) #add to the members ds members.insert_member(:member_id=>fedora_object.pid, :member_title=>fedora_object.titleSet_display, :member_type=>fedora_object.fedora_name) #add to the rels-ext ds fedora_object.collections << self self.institutions << fedora_object end fedora_object.save! self.save! end |
#to_solr(doc = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'app/models/bplmodels/collection.rb', line 52 def to_solr(doc = {} ) doc = super(doc) basic_genre_array = ['Collections'] Bplmodels::ObjectBase.find_in_batches('is_member_of_collection_ssim'=>"info:fedora/#{self.pid}") do |group| group.each { |object_id| #object_id_array << Bplmodels::ObjectBase.find(object_id['id']).adapt_to_cmodel basic_genre_array += object_id['genre_basic_ssim'] if object_id['genre_basic_ssim'].present? } end doc['genre_basic_ssim'] = basic_genre_array.uniq! doc['genre_basic_tsim'] = basic_genre_array.uniq! # description doc['abstract_tsim'] = self.descMetadata.abstract # basic genre =begin basic_genre = 'Collections' doc['genre_basic_ssim'] = basic_genre doc['genre_basic_tsim'] = basic_genre =end # institution if self.institutions collex_location = self.institutions.label.to_s doc['physical_location_ssim'] = collex_location doc['physical_location_tsim'] = collex_location doc['institution_name_ssim'] = collex_location doc['institution_name_tsim'] = collex_location doc['institution_pid_ssi'] = self.institutions.pid end exemplary_check = Bplmodels::ImageFile.find_with_conditions({"is_exemplary_image_of_ssim"=>"info:fedora/#{self.pid}"}, rows: '1', fl: 'id' ) if exemplary_check.present? doc['exemplary_image_ssi'] = exemplary_check.first["id"] end =begin if self.exemplary_image.first != nil doc['exemplary_image_ssi'] = self.exemplary_image.first.pid end =end doc end |