forked from DSpace/DSpace
-
Notifications
You must be signed in to change notification settings - Fork 1
UFAL/Embargo info check #1033
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
UFAL/Embargo info check #1033
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
149 changes: 149 additions & 0 deletions
149
dspace-api/src/main/java/org/dspace/health/EmbargoInfoCheck.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| /** | ||
| * The contents of this file are subject to the license and copyright | ||
| * detailed in the LICENSE and NOTICE files at the root of the source | ||
| * tree and available online at | ||
| * | ||
| * http://www.dspace.org/license/ | ||
| */ | ||
| package org.dspace.health; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Date; | ||
| import java.util.Iterator; | ||
| import java.util.List; | ||
| import java.util.UUID; | ||
|
|
||
| import org.dspace.authorize.ResourcePolicy; | ||
| import org.dspace.content.Bitstream; | ||
| import org.dspace.content.Bundle; | ||
| import org.dspace.content.Collection; | ||
| import org.dspace.content.Community; | ||
| import org.dspace.content.Item; | ||
| import org.dspace.content.factory.ContentServiceFactory; | ||
| import org.dspace.content.service.CollectionService; | ||
| import org.dspace.content.service.CommunityService; | ||
| import org.dspace.content.service.ItemService; | ||
| import org.dspace.core.Context; | ||
|
|
||
| /** | ||
| * This check identifies DSpace objects that have a start date or end date defined in their resource policies. | ||
| * @author Matus Kasak (dspace at dataquest.sk) | ||
| */ | ||
| public class EmbargoInfoCheck extends Check { | ||
|
|
||
| private final List<EmbargoInfo> embItems = new ArrayList<>(); | ||
| private final List<EmbargoInfo> embBitstreams = new ArrayList<>(); | ||
| private final List<EmbargoInfo> embBundles = new ArrayList<>(); | ||
| private final List<EmbargoInfo> embComs = new ArrayList<>(); | ||
| private final List<EmbargoInfo> embCols = new ArrayList<>(); | ||
|
|
||
| private static final int DISPLAY_THRESHOLD = 50; | ||
|
|
||
| @Override | ||
| public String run(ReportInfo ri) { | ||
| Context context = new Context(); | ||
|
Kasinhou marked this conversation as resolved.
Outdated
|
||
| StringBuilder sb = new StringBuilder(); | ||
|
|
||
| ItemService itemService = ContentServiceFactory.getInstance().getItemService(); | ||
| CollectionService collectionService = ContentServiceFactory.getInstance().getCollectionService(); | ||
| CommunityService communityService = ContentServiceFactory.getInstance().getCommunityService(); | ||
|
|
||
| try { | ||
| Iterator<Item> items = itemService.findAll(context); | ||
| while (items.hasNext()) { | ||
| Item item = items.next(); | ||
| collectEmbargoedObjectInfos(item.getResourcePolicies(), embItems, item.getID(), null); | ||
|
milanmajchrak marked this conversation as resolved.
|
||
|
|
||
| for (Bundle bundle : item.getBundles()) { | ||
| collectEmbargoedObjectInfos(bundle.getResourcePolicies(), embBundles, bundle.getID(), item.getID()); | ||
| for (Bitstream bitstream : bundle.getBitstreams()) { | ||
| collectEmbargoedObjectInfos( | ||
| bitstream.getResourcePolicies(), embBitstreams, bitstream.getID(), item.getID()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| for (Collection col : collectionService.findAll(context)) { | ||
| collectEmbargoedObjectInfos(col.getResourcePolicies(), embCols, col.getID(), null); | ||
| } | ||
|
|
||
| for (Community com : communityService.findAll(context)) { | ||
| collectEmbargoedObjectInfos(com.getResourcePolicies(), embComs, com.getID(), null); | ||
| } | ||
|
|
||
| } catch (Exception e) { | ||
|
Kasinhou marked this conversation as resolved.
Outdated
|
||
| throw new RuntimeException("Error while processing embargo check", e); | ||
| } | ||
|
|
||
| appendReport(sb, "Items", embItems, false); | ||
| appendReport(sb, "Bitstreams", embBitstreams, true); | ||
| appendReport(sb, "Bundles", embBundles, true); | ||
| appendReport(sb, "Communities", embComs, false); | ||
| appendReport(sb, "Collections", embCols, false); | ||
|
|
||
| sb.append("\n"); | ||
| sb.append(String.format("Items: %d\n", embItems.size())); | ||
| sb.append(String.format("Bitstreams: %d\n", embBitstreams.size())); | ||
| sb.append(String.format("Bundles: %d\n", embBundles.size())); | ||
| sb.append(String.format("Communities: %d\n", embComs.size())); | ||
| sb.append(String.format("Collections: %d\n", embCols.size())); | ||
|
|
||
| context.close(); | ||
|
Kasinhou marked this conversation as resolved.
Outdated
|
||
| return sb.toString(); | ||
| } | ||
|
|
||
| /** | ||
| * Add embargo info to target list of DSpace object | ||
| */ | ||
| private void collectEmbargoedObjectInfos( | ||
| List<ResourcePolicy> policies, List<EmbargoInfo> targetList, UUID id, UUID parentId) { | ||
| for (ResourcePolicy policy : policies) { | ||
| if (policy.getStartDate() != null || policy.getEndDate() != null) { | ||
| targetList.add(new EmbargoInfo(id, policy.getStartDate(), policy.getEndDate(), parentId)); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private void appendReport(StringBuilder sb, String label, List<EmbargoInfo> list, boolean includeParent) { | ||
| int size = list.size(); | ||
| if (size == 0) { return; } | ||
|
|
||
| sb.append(String.format("\n%s (%d):\n", label, size)); | ||
| if (includeParent) { | ||
| sb.append(String.format("%-40s | %-12s | %-12s | %-40s\n", | ||
| label + " UUID", "Start Date", "End Date", "Item UUID")); | ||
| } else { | ||
| sb.append(String.format("%-40s | %-12s | %-12s\n", label + " UUID", "Start Date", "End Date")); | ||
| } | ||
| sb.append("-".repeat(113)).append("\n"); | ||
|
Kasinhou marked this conversation as resolved.
Outdated
milanmajchrak marked this conversation as resolved.
Outdated
|
||
|
|
||
| int limit = Math.min(size, DISPLAY_THRESHOLD); | ||
| for (int i = 0; i < limit; ++i) { | ||
| EmbargoInfo ei = list.get(i); | ||
| if (includeParent) { | ||
| sb.append(String.format("%-40s | %-12s | %-12s | %-40s\n", | ||
| ei.id, ei.startDate, ei.endDate, ei.parentItemId)); | ||
| } else { | ||
| sb.append(String.format("%-40s | %-12s | %-12s\n", ei.id, ei.startDate, ei.endDate)); | ||
| } | ||
| } | ||
|
|
||
| if (size > DISPLAY_THRESHOLD) { | ||
| sb.append(String.format("... (%d more rows not shown)\n", size - DISPLAY_THRESHOLD)); | ||
| } | ||
| } | ||
|
|
||
|
milanmajchrak marked this conversation as resolved.
|
||
| private static class EmbargoInfo { | ||
| UUID id; | ||
| UUID parentItemId; | ||
| Date startDate; | ||
| Date endDate; | ||
|
|
||
| EmbargoInfo(UUID id, Date startDate, Date endDate, UUID parentItemId) { | ||
| this.id = id; | ||
| this.startDate = startDate; | ||
| this.endDate = endDate; | ||
| this.parentItemId = parentItemId; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.