Content reports ported from DSpace 6.x (#8598)

* content Reports

* Fixed CheckStyle errors

* Fixed CheckStyle errors

* Fixed CheckStyle errors

* First batch of fixes: mainly Javadoc, and a bit of code re-engineering

* Fixed CheckStyle errors

* Fixed CheckStyle errors in dspace-server-webapp

* Applied requested changes for DSpace code conventions compliance

* Added GET endpoint to Filtered Items report

* Updated to latest version from main branch

* Fixed missing imports

* Fixed CheckStyle errors

* Fixed H2 database initialization

* Fixed unit tests and an integration test

* Fixed CheckStyle errors

* Fixed CheckStyle errors

* Fixed ItemServiceIT test

* Test without collection criterion

* Fixed max result count in integration test

* Disable findByMetadataQuery test to diagnose errors in other tests

* Disabled ContentReportRestRepositoryIT test to validate existing tests

* Re-enable test in dspace-api

* Re-enabled ContentReportRestRepositoryIT tests to diagnose failures

* Fixed item matching in the second test

* Fixed JSON path error

* Use projections to trigger embedding the owning collection in ItemRest only for the Filtered Items report

* Fixed usage of allowEmbedding() through non-null arguments

* Exclude owning collection from ItemRest when null/empty

* Trying an alternate way to discriminate report-based Item conversions

* Fixed embedded owning collection management

* Replaced ItemConverter with correct version

* Fixed Filtered Collections test in ContentReportRestRepositoryIT

* Fixed test

* Transferred owning collection to a separate class FilteredItemRest

* Rollback to DSpace repo version

* Fixed matcher for Filtered Collections summary

* Fixed matcher for Filtered Collections summary (take 2)

* Add printing mock request results to diagnose remaining problems

* Try logging output through System.err

* Cancelled attempt to print JSON results (does nothing)

* Attempt to fix ContentReportRestRepositoryIT tests

* Removed predefined UUIDs and handles

* Fixed import formatting

* Fixed expected results in ContentReportRestRepositoryIT

* Switched to a custom matcher for the Filtered Item report test

* Fixed import format

* Fixed JSON collection matching in Filtered Items test

* Fixed Filtered Items matcher

* Fixed expected result

* Fixed the test for now...

* Fixed test again

* Disabled non-working test

* Fixed a few typos

* Moved Filtered Collections report business logic to dspace-api

* Fixed outdated controller

* Fixed import and lost @Ignore annotation

* Retrieved a lost test correction

* Fixed Filtered Collections test

* Reverted to the last working version (except for 2nd test, which remains
disabled)

* Moved Filtered Items report business logic to dspace-api

* Fixed import style

* Added switch to enable/disable Content Reports

* Fixed an out-of-date class

* Removed unused imports

* Fixed activation configuration for Content Reports

* Added missing @Test annotation

* A forgotten Hibernate dialect configuration. I also removed obsolete
Oracle settings configuration.

* Switched to GET requests for Content Reports

* Switched to GET requests for Content Reports

* Fixed styling in imports

* Fixed imports

* Cleaned deprecated code

* Simplified regex since trim() method is invoked on each token thereafter

* Added Javadoc in the interface.

* Relocated Content Reports configuration into a new file

* Added "unauthorized" tests and cleaned up code repetitions

* Fixed parameter according to Javadoc

* Fixed Filtered Items test

* Use of @ConditionalOnProperty annotation

* Rolled back to manual parameter managing

* Second try on @ConditionalOnProperty, with proper test configuration

* Rolled back (again) to manual service activation checking (needed for
proper behaviour depending on activation and authorization)

* Eliminated inheritance between FilteredItemRest and ItemRest

* Re-established the type property in FilteredItemRest (and in
FilterCollectionRest for uniformity).

---------

Co-authored-by: Jean-François Morin <jean-francois.morin@bibl.ulaval.ca>
This commit is contained in:
jeffmorin
2024-02-28 12:48:16 -05:00
committed by GitHub
parent ee42ed5b3b
commit 1a3c0726dc
43 changed files with 3876 additions and 142 deletions

View File

@@ -49,6 +49,7 @@ import org.dspace.content.service.MetadataSchemaService;
import org.dspace.content.service.RelationshipService;
import org.dspace.content.service.WorkspaceItemService;
import org.dspace.content.virtual.VirtualMetadataPopulator;
import org.dspace.contentreport.QueryPredicate;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.core.LogHelper;
@@ -175,7 +176,6 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
private QAEventsDAO qaEventsDao;
protected ItemServiceImpl() {
super();
}
@Override
@@ -275,9 +275,8 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
+ template.getID()));
return template;
} else {
return collection.getTemplateItem();
}
return collection.getTemplateItem();
}
@Override
@@ -1190,9 +1189,8 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
if (item.getOwningCollection() == null) {
if (!isInProgressSubmission(context, item)) {
return true;
} else {
return false;
}
return false;
}
return collectionService.canEditBoolean(context, item.getOwningCollection(), false);
@@ -1284,8 +1282,8 @@ prevent the generation of resource policy entry values with null dspace_object a
if (!authorizeService
.isAnIdenticalPolicyAlreadyInPlace(context, dso, defaultPolicy.getGroup(), Constants.READ,
defaultPolicy.getID()) &&
(!appendMode && this.isNotAlreadyACustomRPOfThisTypeOnDSO(context, dso) ||
appendMode && this.shouldBeAppended(context, dso, defaultPolicy))) {
(!appendMode && isNotAlreadyACustomRPOfThisTypeOnDSO(context, dso) ||
appendMode && shouldBeAppended(context, dso, defaultPolicy))) {
ResourcePolicy newPolicy = resourcePolicyService.clone(context, defaultPolicy);
newPolicy.setdSpaceObject(dso);
newPolicy.setAction(Constants.READ);
@@ -1384,9 +1382,8 @@ prevent the generation of resource policy entry values with null dspace_object a
if (Item.ANY.equals(value)) {
return itemDAO.findByMetadataField(context, mdf, null, true);
} else {
return itemDAO.findByMetadataField(context, mdf, value, true);
}
return itemDAO.findByMetadataField(context, mdf, value, true);
}
@Override
@@ -1430,9 +1427,24 @@ prevent the generation of resource policy entry values with null dspace_object a
if (Item.ANY.equals(value)) {
return itemDAO.findByMetadataField(context, mdf, null, true);
} else {
return itemDAO.findByMetadataField(context, mdf, value, true);
}
return itemDAO.findByMetadataField(context, mdf, value, true);
}
@Override
public List<Item> findByMetadataQuery(Context context, List<QueryPredicate> queryPredicates,
List<UUID> collectionUuids, long offset, int limit)
throws SQLException {
return itemDAO.findByMetadataQuery(context, queryPredicates, collectionUuids, "text_value ~ ?",
offset, limit);
}
@Override
public long countForMetadataQuery(Context context, List<QueryPredicate> queryPredicates,
List<UUID> collectionUuids)
throws SQLException {
return itemDAO.countForMetadataQuery(context, queryPredicates, collectionUuids, "text_value ~ ?");
}
@Override
@@ -1498,20 +1510,19 @@ prevent the generation of resource policy entry values with null dspace_object a
Collection ownCollection = item.getOwningCollection();
if (ownCollection != null) {
return ownCollection;
} else {
InProgressSubmission inprogress = ContentServiceFactory.getInstance().getWorkspaceItemService()
.findByItem(context,
item);
if (inprogress == null) {
inprogress = WorkflowServiceFactory.getInstance().getWorkflowItemService().findByItem(context, item);
}
if (inprogress != null) {
return inprogress.getCollection();
}
// is a template item?
return item.getTemplateItemOf();
}
InProgressSubmission inprogress = ContentServiceFactory.getInstance().getWorkspaceItemService()
.findByItem(context,
item);
if (inprogress == null) {
inprogress = WorkflowServiceFactory.getInstance().getWorkflowItemService().findByItem(context, item);
}
if (inprogress != null) {
return inprogress.getCollection();
}
// is a template item?
return item.getTemplateItemOf();
}
@Override
@@ -1611,9 +1622,8 @@ prevent the generation of resource policy entry values with null dspace_object a
try {
if (StringUtils.isNumeric(id)) {
return findByLegacyId(context, Integer.parseInt(id));
} else {
return find(context, UUID.fromString(id));
}
return find(context, UUID.fromString(id));
} catch (IllegalArgumentException e) {
// Not a valid legacy ID or valid UUID
return null;