1919import sys
2020
2121from dspace_rest_client .client import DSpaceClient
22+ from dspace_rest_client .models import Bundle
2223
2324from utils import utilities as utils
2425
@@ -171,7 +172,7 @@ def process_items_quick(dspace_client, output_file):
171172 logging .info ("Count: [%d]" , item_count_total )
172173
173174
174- def process_bitstreams (dspace_client , output_file , random_sample_by_percentage ):
175+ def process_bitstreams (dspace_client , output_file , random_sample_by_percentage = 100 ):
175176 """
176177 Process bitstreams: mainly for existence checks and bitstream checksums
177178 """
@@ -187,65 +188,45 @@ def process_bitstreams(dspace_client, output_file, random_sample_by_percentage):
187188 logging .info ("Not in random sample: %s (%s)" , item .name , item .uuid )
188189 continue
189190
190- if "ual.jupiterId" in item .metadata :
191- ual_jupiterid_item = utils .deconstruct_list_of_dicts_to_a_single_value (
192- item .metadata ["ual.jupiterId" ]
193- )
194- else :
195- ual_jupiterid_item = None
196191 bundles = dspace_client .get_bundles (parent = item )
197192 for bundle in bundles :
198193 bitstreams = dspace_client .get_bitstreams (bundle = bundle )
199- for bitstream in bitstreams :
200- logging .info ("%s (%s)" , bitstream .name , item .uuid )
201- logging .debug ("%s" , bitstream .to_json_pretty ())
202- logging .debug ("%s" , bundle .to_json_pretty ())
203- tmp_dict = {
204- "item.handle" : item .handle ,
205- "item.uuid" : item .uuid ,
206- "item.name" : item .name ,
207- "provenance.ual.jupiterId.item" : ual_jupiterid_item ,
208- "bundle.name" : bundle .name ,
209- "bitstream.name" : bitstream .name ,
210- "bitstream.bundleName" : bitstream .bundleName ,
211- "bitstream.checksum.value" : bitstream .checkSum ["value" ],
212- "bitstream.checksum_algorithm" : bitstream .checkSum [
213- "checkSumAlgorithm"
214- ],
215- "bitstream.sizeBytes" : bitstream .sizeBytes ,
216- "bitstream.sequenceId" : bitstream .sequenceId ,
217- "bitstream.id" : bitstream .id ,
218- "bitstream.uuid" : bitstream .uuid ,
219- }
220- if "dc.title" in bitstream .metadata :
221- tmp_dict .update (
222- {
223- "bitstream.metadata.dc.title" : bitstream .metadata [
224- "dc.title"
225- ][0 ]["value" ]
226- }
227- )
228- if "dc.source" in bitstream .metadata :
229- tmp_dict .update (
230- {
231- "bitstream.metadata.dc.source.0.value" : bitstream .metadata [
232- "dc.source"
233- ][0 ]["value" ]
234- }
235- )
236- if "dc.description" in bitstream .metadata :
237- tmp_dict .update (
238- {
239- "bitstream.metadata.dc.description" : bitstream .metadata [
240- "dc.description"
241- ][0 ]["value" ],
242- }
243- )
244-
245- utils .output_writer (tmp_dict , "bitstream" , writer )
194+ utils .output_bitstream (item , bundle , bitstreams , writer )
195+
246196 logging .info ("Count: [%d]" , count )
247197
248198
199+ def process_bitstreams_quick (dspace_client , output_file ):
200+ """
201+ Process bitstreams: mainly for existence checks and bitstream checksums
202+ Use the search API in this version
203+ """
204+ writer = utils .output_init (output_file , "bitstream" )
205+ items = dspace_client .search_objects_iter (
206+ query = "*:*" , dso_type = "item" , embeds = ["bundles" ]
207+ )
208+ count = 0
209+ for count , item in enumerate (items , start = 1 ):
210+ logging .info ("Item: %s" , item .to_json_pretty ())
211+ # refresh auth token
212+
213+ if count % 5000 == 0 :
214+ dspace_client .refresh_token ()
215+
216+ if "bundles" in item .embedded :
217+ # this could be a bug in the discovery search API the need have
218+ # ["_embedded"]["bundles"]
219+ logging .info ("Embed: %s" , item .embedded ["bundles" ]["_embedded" ]["bundles" ])
220+ for bundle in item .embedded ["bundles" ]["_embedded" ]["bundles" ]:
221+ logging .info ("Bundle: %s" , bundle )
222+ if bundle .get ("name" , None ) == "ORIGINAL" :
223+ bundle_obj = Bundle (bundle )
224+ bitstreams = dspace_client .get_bitstreams (bundle = bundle_obj )
225+ utils .output_bitstream (item , bundle_obj , bitstreams , writer )
226+
227+ logging .info ("Count items (not actual bitstreams): [%d]" , count )
228+
229+
249230def process_users (dspace_client , output_file ):
250231 """
251232 Process users
@@ -334,6 +315,8 @@ def process(dspace_client, output_file, dso_type, random_sample_percentage):
334315 process_items_quick (dspace_client , output_file )
335316 case "bitstreams" :
336317 process_bitstreams (dspace_client , output_file , random_sample_percentage )
318+ case "bitstreams_quick" :
319+ process_bitstreams_quick (dspace_client , output_file )
337320 case "users" :
338321 process_users (dspace_client , output_file )
339322 case "collection_stats" :
@@ -356,6 +339,7 @@ def main():
356339 # between the requested page size, actual result size and # of pages
357340 # If 512 items and size is set to 500,
358341 # https://github.com/DSpace/DSpace/issues/8723
342+ # http://198.168.187.81:8080/server/api/discover/search/objects?dsoType=collection&page=0&size=500
359343 dspace_client .ITER_PAGE_SIZE = 100
360344
361345 # Configure logging
0 commit comments