Skip to content

Commit

Permalink
Merge remote-tracking branch 'DSpace/dspace-8_x' into task/dspace-8_x…
Browse files Browse the repository at this point in the history
…/CST-15073

# Conflicts:
#	dspace-api/src/test/java/org/dspace/identifier/VersionedHandleIdentifierProviderIT.java
  • Loading branch information
vins01-4science committed Sep 24, 2024
2 parents bd16163 + e7006c0 commit 0efc3d9
Show file tree
Hide file tree
Showing 17 changed files with 597 additions and 897 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/
package org.dspace.app.mediafilter;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -37,8 +38,9 @@
* MFM: -v verbose outputs all extracted text to STDOUT; -f force forces all
* bitstreams to be processed, even if they have been before; -n noindex does not
* recreate index after processing bitstreams; -i [identifier] limits processing
* scope to a community, collection or item; and -m [max] limits processing to a
* maximum number of items.
* scope to a community, collection or item; -m [max] limits processing to a
* maximum number of items; -fd [fromdate] takes only items starting from this date,
* filtering by last_modified in the item table.
*/
public class MediaFilterScript extends DSpaceRunnable<MediaFilterScriptConfiguration> {

Expand All @@ -60,6 +62,7 @@ public class MediaFilterScript extends DSpaceRunnable<MediaFilterScriptConfigura
private String[] filterNames;
private String[] skipIds = null;
private Map<String, List<String>> filterFormats = new HashMap<>();
private LocalDate fromDate = null;

public MediaFilterScriptConfiguration getScriptConfiguration() {
return new DSpace().getServiceManager()
Expand Down Expand Up @@ -112,6 +115,10 @@ public void setup() throws ParseException {
skipIds = commandLine.getOptionValues('s');
}

if (commandLine.hasOption('d')) {
fromDate = LocalDate.parse(commandLine.getOptionValue('d'));
}


}

Expand Down Expand Up @@ -215,6 +222,10 @@ public void internalRun() throws Exception {
mediaFilterService.setSkipList(Arrays.asList(skipIds));
}

if (fromDate != null) {
mediaFilterService.setFromDate(fromDate);
}

Context c = null;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public Options getOptions() {
.build();
options.addOption(pluginOption);

options.addOption("d", "fromdate", true, "Process only item from specified last modified date");

Option skipOption = Option.builder("s")
.longOpt("skip")
.hasArg()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@

import java.io.InputStream;
import java.sql.SQLException;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
Expand Down Expand Up @@ -93,6 +96,7 @@ public class MediaFilterServiceImpl implements MediaFilterService, InitializingB
protected boolean isVerbose = false;
protected boolean isQuiet = false;
protected boolean isForce = false; // default to not forced
protected LocalDate fromDate = null;

protected MediaFilterServiceImpl() {

Expand Down Expand Up @@ -120,6 +124,15 @@ public void applyFiltersAllItems(Context context) throws Exception {
for (Community topLevelCommunity : topLevelCommunities) {
applyFiltersCommunity(context, topLevelCommunity);
}
} else if (fromDate != null) {
Iterator<Item> itemIterator =
itemService.findByLastModifiedSince(
context,
Date.from(fromDate.atStartOfDay(ZoneId.systemDefault()).toInstant())
);
while (itemIterator.hasNext() && processed < max2Process) {
applyFiltersItem(context, itemIterator.next());
}
} else {
//otherwise, just find every item and process
Iterator<Item> itemIterator = itemService.findAll(context);
Expand Down Expand Up @@ -588,4 +601,9 @@ public void setFilterFormats(Map<String, List<String>> filterFormats) {
public void setLogHandler(DSpaceRunnableHandler handler) {
this.handler = handler;
}

@Override
public void setFromDate(LocalDate fromDate) {
this.fromDate = fromDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
package org.dspace.app.mediafilter.service;

import java.sql.SQLException;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -149,4 +150,6 @@ public void updatePoliciesOfDerivativeBitstreams(Context context, Item item, Bit
* @param handler
*/
public void setLogHandler(DSpaceRunnableHandler handler);

public void setFromDate(LocalDate fromDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public int countItems(Context context, List<Collection> collections, boolean inc
public Iterator<Item> findByLastModifiedSince(Context context, Date since)
throws SQLException {
Query query = createQuery(context,
"SELECT i.id FROM Item i WHERE last_modified > :last_modified ORDER BY id");
"SELECT i.id FROM Item i WHERE lastModified > :last_modified ORDER BY id");
query.setParameter("last_modified", since, TemporalType.TIMESTAMP);
@SuppressWarnings("unchecked")
List<UUID> uuids = query.getResultList();
Expand Down
29 changes: 13 additions & 16 deletions dspace-api/src/test/java/org/dspace/administer/StructBuilderIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,12 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.dspace.AbstractIntegrationTest;
import org.dspace.AbstractIntegrationTestWithDatabase;
import org.dspace.authorize.AuthorizeException;
import org.dspace.builder.CollectionBuilder;
import org.dspace.builder.CommunityBuilder;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.MetadataSchemaEnum;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.CollectionService;
import org.dspace.content.service.CommunityService;
Expand All @@ -38,7 +39,6 @@
import org.junit.Test;
import org.w3c.dom.Attr;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
import org.xmlunit.builder.DiffBuilder;
import org.xmlunit.diff.Comparison;
import org.xmlunit.diff.ComparisonFormatter;
Expand All @@ -52,7 +52,7 @@
* @author Mark H. Wood <[email protected]>
*/
public class StructBuilderIT
extends AbstractIntegrationTest {
extends AbstractIntegrationTestWithDatabase {
private static final Logger log = LogManager.getLogger();

private static final CommunityService communityService
Expand All @@ -79,7 +79,8 @@ public static void tearDownClass() {
* @throws IOException passed through.
*/
@Before
public void setUp() throws SQLException, AuthorizeException, IOException {
public void setUp() throws Exception {
super.setUp();
// Clear out all communities and collections.
context.turnOffAuthorisationSystem();
for (Community community : communityService.findAllTop(context)) {
Expand Down Expand Up @@ -285,19 +286,15 @@ public void testImportStructureWithHandles()
* @throws org.dspace.authorize.AuthorizeException passed through.
*/
@Test
public void testExportStructure()
throws ParserConfigurationException, SAXException, IOException,
SQLException, AuthorizeException {
public void testExportStructure() {
// Create some structure to test.
context.turnOffAuthorisationSystem();
Community community0 = communityService.create(null, context);
communityService.setMetadataSingleValue(context, community0,
MetadataSchemaEnum.DC.getName(), "title", null,
null, "Top Community 0");
Collection collection0_0 = collectionService.create(context, community0);
collectionService.setMetadataSingleValue(context, collection0_0,
MetadataSchemaEnum.DC.getName(), "title", null,
null, "Collection 0.0");
// Top level community
Community community0 = CommunityBuilder.createCommunity(context)
.withName("Top Community 0").build();
// Collection below top level community
Collection collection0_0 = CollectionBuilder.createCollection(context, community0)
.withName("Collection 0.0").build();

// Export the current structure.
System.out.println("exportStructure");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.dspace.builder.CollectionBuilder;
import org.dspace.builder.CommunityBuilder;
import org.dspace.builder.ItemBuilder;
import org.dspace.builder.WorkspaceItemBuilder;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.Item;
Expand Down Expand Up @@ -159,7 +160,7 @@ public void packagerUUIDAlreadyExistWithoutForceTest() throws Exception {
performExportScript(article.getHandle(), tempFile);
UUID id = article.getID();
itemService.delete(context, article);
WorkspaceItem workspaceItem = workspaceItemService.create(context, col1, id, false, false);
WorkspaceItem workspaceItem = WorkspaceItemBuilder.createWorkspaceItem(context, col1, id).build();
installItemService.installItem(context, workspaceItem, "123456789/0100");
performImportNoForceScript(tempFile);
Iterator<Item> items = itemService.findByCollection(context, col1);
Expand Down
78 changes: 78 additions & 0 deletions dspace-api/src/test/java/org/dspace/builder/GroupBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
import java.util.UUID;

import org.dspace.authorize.AuthorizeException;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.DSpaceObject;
import org.dspace.content.service.DSpaceObjectService;
import org.dspace.core.Context;
import org.dspace.eperson.EPerson;
Expand Down Expand Up @@ -51,6 +54,33 @@ public static GroupBuilder createGroup(final Context context) {
return builder.create(context);
}

public static GroupBuilder createCollectionAdminGroup(final Context context, Collection collection) {
GroupBuilder builder = new GroupBuilder(context);
return builder.createAdminGroup(context, collection);
}

public static GroupBuilder createCollectionSubmitterGroup(final Context context, Collection collection) {
GroupBuilder builder = new GroupBuilder(context);
return builder.createSubmitterGroup(context, collection);
}

public static GroupBuilder createCollectionDefaultReadGroup(final Context context, Collection collection,
String typeOfGroupString, int defaultRead) {
GroupBuilder builder = new GroupBuilder(context);
return builder.createDefaultReadGroup(context, collection, typeOfGroupString, defaultRead);
}

public static GroupBuilder createCollectionWorkflowRoleGroup(final Context context, Collection collection,
String roleName) {
GroupBuilder builder = new GroupBuilder(context);
return builder.createWorkflowRoleGroup(context, collection, roleName);
}

public static GroupBuilder createCommunityAdminGroup(final Context context, Community community) {
GroupBuilder builder = new GroupBuilder(context);
return builder.createAdminGroup(context, community);
}

private GroupBuilder create(final Context context) {
this.context = context;
try {
Expand All @@ -61,6 +91,54 @@ private GroupBuilder create(final Context context) {
return this;
}

private GroupBuilder createAdminGroup(final Context context, DSpaceObject container) {
this.context = context;
try {
if (container instanceof Collection) {
group = collectionService.createAdministrators(context, (Collection) container);
} else if (container instanceof Community) {
group = communityService.createAdministrators(context, (Community) container);
} else {
handleException(new IllegalArgumentException("DSpaceObject must be collection or community. " +
"Type: " + container.getType()));
}
} catch (Exception e) {
return handleException(e);
}
return this;
}

private GroupBuilder createSubmitterGroup(final Context context, Collection collection) {
this.context = context;
try {
group = collectionService.createSubmitters(context, collection);
} catch (Exception e) {
return handleException(e);
}
return this;
}

private GroupBuilder createDefaultReadGroup(final Context context, Collection collection,
String typeOfGroupString, int defaultRead) {
this.context = context;
try {
group = collectionService.createDefaultReadGroup(context, collection, typeOfGroupString, defaultRead);
} catch (Exception e) {
return handleException(e);
}
return this;
}

private GroupBuilder createWorkflowRoleGroup(final Context context, Collection collection, String roleName) {
this.context = context;
try {
group = workflowService.createWorkflowRoleGroup(context, collection, roleName);
} catch (Exception e) {
return handleException(e);
}
return this;
}

@Override
protected DSpaceObjectService<Group> getService() {
return groupService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.UUID;

import org.dspace.app.ldn.NotifyPatternToTrigger;
import org.dspace.app.ldn.NotifyServiceEntity;
Expand Down Expand Up @@ -43,14 +44,31 @@ protected WorkspaceItemBuilder(Context context) {

public static WorkspaceItemBuilder createWorkspaceItem(final Context context, final Collection col) {
WorkspaceItemBuilder builder = new WorkspaceItemBuilder(context);
return builder.create(context, col);
return builder.create(context, col, null);
}

private WorkspaceItemBuilder create(final Context context, final Collection col) {
public static WorkspaceItemBuilder createWorkspaceItem(final Context context, final Collection col, UUID uuid) {
WorkspaceItemBuilder builder = new WorkspaceItemBuilder(context);
return builder.create(context, col, uuid);
}

/**
* Create with a specific UUID (e.g. restoring items with Packager import)
*
* @param context DSpace context
* @param col Parent collection
* @param uuid Item UUID
* @return WorkspaceItemBuilder
*/
private WorkspaceItemBuilder create(final Context context, final Collection col, UUID uuid) {
this.context = context;

try {
workspaceItem = workspaceItemService.create(context, col, false);
if (uuid == null) {
workspaceItem = workspaceItemService.create(context, col, false);
} else {
workspaceItem = workspaceItemService.create(context, col, uuid, false, false);
}
item = workspaceItem.getItem();
} catch (Exception e) {
return handleException(e);
Expand Down
Loading

0 comments on commit 0efc3d9

Please sign in to comment.