Skip to content

Commit 6bfa7e2

Browse files
authored
Merge pull request #12 from jefferya/quick_additions_speedups
Add runtime speedups and refactors
2 parents 8919163 + 8ad63f2 commit 6bfa7e2

7 files changed

Lines changed: 432 additions & 88 deletions

File tree

README.md

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ What is content is audited:
4141
* associated to the correct community (by name as DSpace doesn't store legacy community jupiter id)
4242
* fields (labels from DSpace API): name, description, abstract, title
4343

44-
* Bitstream
44+
* Bitstream
4545
* existence
4646
* associated with the correct Item (ID & Name)
4747
* correct sequence number
@@ -107,6 +107,8 @@ I'll import into a Google Sheet to leverage the power of the grid layout
107107
`index` is empty if a thing is not found in Jupiter (e.g., a UI entered, hand-crafted test in Scholaris)
108108
`dspace_id` is nan/empty if a thing is not found in DSpace (e.g., an ERA item has not been migrated into Scholaris)
109109

110+
Note for bitstreams, all DSpace bitstreams are included in the report, including the DSpace generated bitstreams. One can limit and remove if the bundlename is not ORIGINAL.
111+
110112
#### Audit: Technical Details
111113

112114
##### How to how to extend the JSON flattening
@@ -153,7 +155,7 @@ Setup for Ruby scripts
153155

154156
Consider cloning this repository into `/tmp` and
155157

156-
* sudo -u apache bash -c "cd /var/www/sites/jupiter && RAILS_ENV=staging bundle exec rails runner /tmp/dspace_api_tools/jupiter_output_scripts/jupiter_collection_metadata_to_CSV.rb"
158+
* `sudo -u apache bash -c "cd /var/www/sites/jupiter && RAILS_ENV=staging bundle exec rails runner /tmp/dspace_api_tools/jupiter_output_scripts/jupiter_collection_metadata_to_CSV.rb"`
157159
* change `RAIL_ENV` as needed [development|staging|production]
158160
* change script as needed
159161

@@ -189,6 +191,9 @@ The steps to set up a validation run.
189191

190192
3. `./dspace_api_exports.py` to export (CSV) DSpace metadata
191193

194+
* Option for items and bitstreams: `--random_sample_by_percentage` with default 100% and range between 1-100.
195+
* Option for items and bitstreams: `--dso_type=item_quick` and `--dso_type=bitstream_guick` which leverage Solr as much as possible to reduce number of API calls (not as well tested)
196+
192197
```bash
193198
# Set environment variables
194199
export DSPACE_API_ENDPOINT=https://${SERVER_NAME}/server/api/
@@ -267,8 +272,36 @@ The steps to set up a validation run.
267272

268273
6. Audit bitstream access restrictions via the web UI
269274

275+
* Optional:to reduce runtime, split the input list of IDs into multiple files and run multiple instance of the script
276+
277+
``` bash
278+
279+
export DSPACE_ROOT_URL=
280+
export BITSTREAM_ACCESS_CONTROL_TEST_ROOT=/tmp/z3/z
281+
282+
./venv/bin/python3 src/split_csv.py \
283+
--input ${DSPACE_DIR}/scholaris_items.csv \
284+
--output ${BITSTREAM_ACCESS_CONTROL_TEST_ROOT}/split/ \
285+
--output_file_size 100
286+
287+
# To reduce runtime: remove some source files from ${BITSTREAM_ACCESS_CONTROL_TEST_OUTPUT_ROOT}
288+
289+
for file in ${BITSTREAM_ACCESS_CONTROL_TEST_ROOT}/split/*; do
290+
base_name=$(basename "$file" .csv)
291+
./venv/bin/python src/bitstream_access_control_test.py \
292+
--input ${file} \
293+
--output "${BITSTREAM_ACCESS_CONTROL_TEST_ROOT}/reports/${base_name}_result.csv" \
294+
--id_field uuid \
295+
--root_url ${DSPACE_ROOT_URL} \
296+
--logging_level ERROR \
297+
&
298+
done
299+
300+
```
301+
302+
* To run sequentially:
303+
270304
``` bash
271-
272305
export DSPACE_ROOT_URL=
273306

274307
./venv/bin/python src/bitstream_access_control_test.py \
@@ -296,6 +329,14 @@ The steps to set up a validation run.
296329
--output /tmp/x_out
297330
```
298331

332+
8. Optional: Collection item counts
333+
334+
``` bash
335+
./venv/bin/python3 src/dspace_api_exports.py \
336+
--output /tmp/z.csv \
337+
--dso_type collection_stats
338+
```
339+
299340
## dspace_api_exports.py
300341

301342
Test exporting content from the DSpace API using <https://pypi.org/project/dspace-rest-client>.
@@ -356,7 +397,7 @@ Where:
356397
* change_id: change event id (PaperTrail::Version ID)
357398
* jupiter_id: ERA ID
358399
* is_jupiter_currently_readonly: "true" if the ERA object is currently read only
359-
* read_only_event: "true" if this change event only updated the read only field and the obj updated at timestamp
400+
* read_only_event: "true" if this change event only updated the read only field and the obj updated at timestamp
360401
* changed_at: change event timestamp
361402
* event: the type of the change record: update|destroy
362403
* jupiter delta: jupiter change event details (what field plus old => new values)
@@ -381,10 +422,11 @@ Process thoughts:
381422

382423
For Item/Thesis/Collection/Community, see script for details: `jupiter_output_scripts/jupiter_delta.rb`
383424

425+
* `sudo -u apache bash -c "cd /var/www/sites/jupiter && RAILS_ENV=staging bundle exec rails runner /tmp/dspace_api_tools/jupiter_output_scripts/delta_report.rb"`
426+
* change `RAIL_ENV` as needed [development|staging|production]
427+
*
384428
Rough outline:
385429

386-
* Needs the Ruby Class used in step 1 of SAF package generation
387-
* See `require_relative` in the script to populate Jupiter to Scholaris mappings
388430
* Set date in script and run `jupiter_output_scripts/jupiter_delta.rb`
389431
* Upload CSV into Google Docs for Sharing
390432

@@ -401,7 +443,7 @@ Rough outline:
401443
Rough outline
402444

403445
* Generate CSV report of Jupiter statistics, see `jupiter_output_scripts/jupiter_statistics_metadata_to_CSV`
404-
* Generate CSV report from DSpace, `dsapce_api_exports.py`
446+
* Generate CSV report from DSpace, `dspace_api_exports.py`
405447
* The quick approach:
406448
* place both CSV reports into separate tabs in a Google Sheet
407449
* use XLOOKUP to align based on jupiter ID

jupiter_output_scripts/jupiter_delta.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def map_change_event_to_scholaris_item(change_event, obj)
5858
end
5959
end;
6060
rescue NoMethodError
61-
puts "Mapping Error on jupiter ID #{change_event.item_id} of type #{change_event.item_type} and event #{change_event.event}"
61+
puts "Mapping Error on jupiter ID #{change_event.item_id} of type #{change_event.item_type} and event #{change_event.event}. Check if object destroyed."
6262
end
6363
return scholaris_mapped_change_event
6464
end
@@ -170,4 +170,4 @@ def perform()
170170

171171
end
172172

173-
ChangesReport.new("/era_tmp/delete_me_by_2025-05-14/",Date.new(2025, 3, 15)).perform()
173+
ChangesReport.new("/era_tmp/delete_me_by_2025-05-15/",Date.new(2025, 3, 15)).perform()

src/compare_csv.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def string_compare(str1, str2):
6464
"""
6565
Compare two strings
6666
"""
67-
logging.debug("%s ---- %s", str1, str2)
67+
logging.debug("|%s| ---- |%s|", str1, str2)
6868
return str1 == str2
6969

7070

@@ -113,7 +113,7 @@ def string_compare_ignore_whitespace(str1, str2):
113113
else:
114114
ret = regex.sub("", str(str1)) == regex.sub("", str(str2))
115115
logging.debug(
116-
"%s ---- %s %s",
116+
"|%s| ---- |%s| |%s|",
117117
str(str1),
118118
str(str2),
119119
str(ret),
@@ -153,13 +153,13 @@ def string_in_list_compare_ignore_whitespace(str1, list2):
153153
Compare a string to a string representation of a list
154154
Item description is stored as an list of "things"
155155
"""
156-
logging.debug("%s ---- %s", str1, list2)
156+
logging.debug("|%s| ---- %s", str1, list2)
157157
if isinstance(str1, float):
158158
str1 = str(str1)
159159
else:
160160
str1 = remove_xml_invalid_characters(str1)
161161
list2 = utils.convert_string_list_representation_to_list(list2)
162-
logging.debug("%s ---- %s", str1, list2)
162+
logging.debug("|%s| ---- %s", str1, list2)
163163

164164
return True if not str1 and not list2 else str(str1).strip() in list2
165165

@@ -535,7 +535,7 @@ def special_type_compare(row, key, value):
535535
"comparison_types": {
536536
"name": {
537537
"columns": {"jupiter": "title", "dspace": "name"},
538-
"comparison_function": string_compare,
538+
"comparison_function": string_compare_ignore_whitespace,
539539
},
540540
"description": {
541541
"columns": {
@@ -553,7 +553,7 @@ def special_type_compare(row, key, value):
553553
},
554554
"dc.title": {
555555
"columns": {"jupiter": "title", "dspace": "metadata.dc.title"},
556-
"comparison_function": value_in_string_list_compare,
556+
"comparison_function": string_in_list_compare_ignore_whitespace,
557557
},
558558
"collection_parent_expect_to_fail_due_to_lack_of_community_provenance": {
559559
"columns": {

0 commit comments

Comments
 (0)