@@ -110,8 +110,16 @@ def error_params
110110 end
111111
112112 # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
113- def next_record_page ( token , use_interstream_deltas : false )
114- streams = if token . set . present?
113+ def next_record_page ( token , use_interstream_deltas : nil )
114+ streams = if token . set &.start_with? ( 'organization/' )
115+ org_slug = token . set . split ( '/' ) . last
116+ stream = Organization . find_by! ( slug : org_slug ) . default_stream
117+ use_interstream_deltas = true if use_interstream_deltas . nil?
118+
119+ authorize! :read , stream
120+
121+ [ stream ]
122+ elsif token . set . present?
115123 Stream . accessible_by ( current_ability ) . where ( id : token . set )
116124 else
117125 Stream . accessible_by ( current_ability ) . where ( status : 'default' )
@@ -205,31 +213,57 @@ def build_list_records_response(page, token = nil)
205213 end
206214
207215 # See https://www.openarchives.org/OAI/openarchivesprotocol.html#ListSets
208- # rubocop:disable Metrics/AbcSize
209- # rubocop:disable Metrics/MethodLength
210216 def build_list_sets_response ( streams )
211217 Nokogiri ::XML ::Builder . new do |xml |
212218 build_oai_response xml , list_sets_params do
213219 xml . ListSets do
214- streams . each do |stream |
215- xml . set do
216- xml . setSpec stream . id
217- xml . setName stream . display_name
218- xml . setDescription do
219- xml [ :oai_dc ] . dc ( oai_dc_xmlns ) do
220- xml [ :dc ] . description oai_dc_description ( stream )
221- xml [ :dc ] . contributor stream . organization . slug
222- xml [ :dc ] . type oai_dc_type ( stream )
223- oai_dc_dates ( stream ) . each do |date |
224- xml [ :dc ] . date date
225- end
226- end
227- end
220+ build_organizations_list_sets_response ( xml , streams . map ( &:organization ) . uniq )
221+ build_streams_list_sets_response ( xml , streams )
222+ end
223+ end
224+ end . to_xml
225+ end
226+
227+ # rubocop:disable Metrics/AbcSize
228+ # rubocop:disable Metrics/MethodLength
229+ def build_streams_list_sets_response ( xml , streams )
230+ streams . each do |stream |
231+ xml . set do
232+ xml . setSpec stream . id
233+ xml . setName stream . display_name
234+ xml . setDescription do
235+ xml [ :oai_dc ] . dc ( oai_dc_xmlns ) do
236+ xml [ :dc ] . description oai_dc_description ( stream )
237+ xml [ :dc ] . contributor stream . organization . slug
238+ xml [ :dc ] . type oai_dc_type ( stream )
239+ oai_dc_dates ( stream ) . each do |date |
240+ xml [ :dc ] . date date
228241 end
229242 end
230243 end
231244 end
232- end . to_xml
245+ end
246+ end
247+
248+ def build_organizations_list_sets_response ( xml , organizations )
249+ organizations . each do |organization |
250+ xml . set do
251+ xml . setSpec "organization/#{ organization . slug } "
252+ xml . setName organization . name
253+ xml . setDescription do
254+ xml [ :oai_dc ] . dc ( oai_dc_xmlns ) do
255+ xml [ :dc ] . description "Seamless harvesting for #{ organization . name } "
256+ xml [ :dc ] . contributor organization . slug
257+ xml [ :dc ] . type 'organization'
258+ xml [ :dc ] . source "stream #{ organization . default_stream . id } "
259+
260+ oai_dc_dates ( organization . default_stream ) . each do |date |
261+ xml [ :dc ] . date date
262+ end
263+ end
264+ end
265+ end
266+ end
233267 end
234268 # rubocop:enable Metrics/AbcSize
235269 # rubocop:enable Metrics/MethodLength
0 commit comments