cul_hydra 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efa13a7d8ec21a34f211463fb1026c640a2ca3bf
4
- data.tar.gz: f3c5bff14e40684c60accd573b8c7bf0fb525cf0
3
+ metadata.gz: 102ec8e3b9fefe152b73c5e4e3a0a8879e90b71e
4
+ data.tar.gz: cb023b7bdc8ff9897f4dafbf7c3a4f31e5ba4622
5
5
  SHA512:
6
- metadata.gz: 5f44c97c75dce30861be5287f19da6c22d532e9c27f1fd8094a646218ece5f197cb751610ec7d1dfad6dba5257822a8bc288c4f573fc2bdbee95a73c5141f20c
7
- data.tar.gz: 893c65d7a0f3ba682104882582f85593028cbe92c8ca1c2e81e5e3088b16c440b271212bf094c0e41a79c06a669df19ff71187dea018bf207c3273822d4800d6
6
+ metadata.gz: 9365a49063b3f98d141541fcf007992b156bdec4b98733d4dab1dda1f1d5d30eaee4fbecb7a1dba164ccbe946006b5186667f34f6593de7ff831edf6356e69d4
7
+ data.tar.gz: d354dfee384cc8ea31e2a0fd813bcdaaaca806990a96104ce7eae9c63b2271e549ad60542628cf8fb84bc8dd25b2a935e156566a2c8deb5323b099c6fe235e21
@@ -142,8 +142,8 @@ module Cul::Hydra::Models::Common
142
142
  solr_doc
143
143
  end
144
144
 
145
- def get_representative_generic_resource
146
-
145
+ # This method generally shouldn't be called with any parameters (unless we're doing testing)
146
+ def get_representative_generic_resource(force_use_of_non_pid_identifier=false)
147
147
  return self if self.is_a?(GenericResource)
148
148
  return nil unless self.is_a?(Cul::Hydra::Models::Aggregator) # Only Aggregators have struct metadata
149
149
 
@@ -163,20 +163,33 @@ module Cul::Hydra::Models::Common
163
163
  if found_struct_div
164
164
  content_ids = ng_div.attr('CONTENTIDS').split(' ') # Get all space-delimited content ids
165
165
  child_obj = nil
166
- content_ids.each do |content_id|
167
- child_obj ||= GenericAggregator.search_repo.find_by(identifier: content_id) # We don't know what type of aggregator we'll be getting back, but all we need is the pid
166
+
167
+ # Try to do a PID lookup first
168
+ unless force_use_of_non_pid_identifier
169
+ content_ids.each do |content_id|
170
+ child_obj ||= ActiveFedora::Base.exists?(content_id) ? ActiveFedora::Base.find(content_id) : nil
171
+ end
168
172
  end
169
- # If we didn't find the child object through an identifier search, we might be working with a PID instead.
170
- # Do a pid-based search
173
+
174
+ # Then fall back to identifier lookup
171
175
  if child_obj.nil?
176
+ child_pid = nil
172
177
  content_ids.each do |content_id|
173
- child_obj ||= ActiveFedora::Base.exists?(content_id) ? ActiveFedora::Base.find(content_id) : nil
178
+ child_pid ||= Cul::Hydra::RisearchMembers.get_pid_for_identifier(content_id)
179
+ if force_use_of_non_pid_identifier && child_pid && content_id == child_pid
180
+ # This really only runs when we're doing testing, if we want to specifically ensure that we're searching by a non-pid identifier
181
+ child_pid = nil
182
+ end
183
+ end
184
+
185
+ if child_pid
186
+ child_obj = ActiveFedora::Base.find(child_pid)
174
187
  end
175
188
  end
176
189
 
177
190
  if child_obj
178
191
  # Recursion! Woo!
179
- return child_obj.get_representative_generic_resource
192
+ return child_obj.get_representative_generic_resource(force_use_of_non_pid_identifier)
180
193
  else
181
194
  #Rails.logger.error "No object for dc:identifier in #{content_ids.inspect}"
182
195
  return nil
@@ -1,3 +1,4 @@
1
+ # TODO: Eventually change this class name from RisearchMembers to RisearchHelpers
1
2
  module Cul::Hydra::RisearchMembers
2
3
  module ClassMethods
3
4
  def get_recursive_member_pids(pid, verbose_output=false, cmodel_type='all')
@@ -119,6 +120,27 @@ module ClassMethods
119
120
  return count.blank? ? 0 : count[0]['count'].to_i
120
121
  end
121
122
 
123
+ def get_pid_for_identifier(identifier)
124
+
125
+ find_by_identifier_query = "select $pid from <#ri>
126
+ where $pid <http://purl.org/dc/elements/1.1/identifier> $identifier
127
+ and $identifier <mulgara:is> '#{identifier}'"
128
+
129
+ search_response = JSON(Cul::Hydra::Fedora.repository.find_by_itql(find_by_identifier_query, {
130
+ :type => 'tuples',
131
+ :format => 'json',
132
+ :limit => '1',
133
+ :stream => 'on'
134
+ }))
135
+
136
+ if search_response['results'].present?
137
+ return search_response['results'].first['pid'].gsub('info:fedora/', '')
138
+ else
139
+ return nil
140
+ end
141
+
142
+ end
143
+
122
144
  end
123
145
  extend ClassMethods
124
146
  end
@@ -1,6 +1,6 @@
1
1
  module Cul
2
2
  module Hydra
3
- VERSION = '1.0.3'
3
+ VERSION = '1.0.4'
4
4
  def self.version
5
5
  VERSION
6
6
  end
@@ -1,6 +1,6 @@
1
1
  module Cul
2
2
  module Hydra
3
- VERSION = '1.0.2'
3
+ VERSION = '1.0.3'
4
4
  def self.version
5
5
  VERSION
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cul_hydra
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Benjamin Armintor
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-05-22 00:00:00.000000000 Z
12
+ date: 2015-05-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: blacklight