mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-15 05:53:08 +00:00
75409: Delete solr record on workspaceitem deletion: Test feedback V2
This commit is contained in:
@@ -14,6 +14,7 @@ import java.util.Set;
|
|||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.content.Bundle;
|
import org.dspace.content.Bundle;
|
||||||
import org.dspace.content.DSpaceObject;
|
import org.dspace.content.DSpaceObject;
|
||||||
|
import org.dspace.content.Item;
|
||||||
import org.dspace.core.Constants;
|
import org.dspace.core.Constants;
|
||||||
import org.dspace.core.Context;
|
import org.dspace.core.Context;
|
||||||
import org.dspace.discovery.indexobject.factory.IndexFactory;
|
import org.dspace.discovery.indexobject.factory.IndexFactory;
|
||||||
@@ -21,6 +22,9 @@ import org.dspace.discovery.indexobject.factory.IndexObjectFactoryFactory;
|
|||||||
import org.dspace.event.Consumer;
|
import org.dspace.event.Consumer;
|
||||||
import org.dspace.event.Event;
|
import org.dspace.event.Event;
|
||||||
import org.dspace.services.factory.DSpaceServicesFactory;
|
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||||
|
import org.dspace.workflow.WorkflowItem;
|
||||||
|
import org.dspace.workflow.WorkflowItemService;
|
||||||
|
import org.dspace.workflow.factory.WorkflowServiceFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class for updating search indices in discovery from content events.
|
* Class for updating search indices in discovery from content events.
|
||||||
@@ -47,6 +51,9 @@ public class IndexEventConsumer implements Consumer {
|
|||||||
|
|
||||||
IndexObjectFactoryFactory indexObjectServiceFactory = IndexObjectFactoryFactory.getInstance();
|
IndexObjectFactoryFactory indexObjectServiceFactory = IndexObjectFactoryFactory.getInstance();
|
||||||
|
|
||||||
|
private WorkflowItemService workflowItemService = WorkflowServiceFactory.getInstance().getWorkflowItemService();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize() throws Exception {
|
public void initialize() throws Exception {
|
||||||
|
|
||||||
@@ -130,6 +137,13 @@ public class IndexEventConsumer implements Consumer {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.debug("consume() adding event to update queue: " + event.toString());
|
log.debug("consume() adding event to update queue: " + event.toString());
|
||||||
|
if (event.getSubjectType() == Constants.ITEM) {
|
||||||
|
WorkflowItem workflowItem = workflowItemService.findByItem(ctx, (Item) subject);
|
||||||
|
if (workflowItem != null) {
|
||||||
|
String detail = Constants.typeText[event.getSubjectType()] + "-" + event.getSubjectID().toString();
|
||||||
|
uniqueIdsToDelete.add(detail);
|
||||||
|
}
|
||||||
|
}
|
||||||
objectsToUpdate.addAll(indexObjectServiceFactory.getIndexableObjects(ctx, subject));
|
objectsToUpdate.addAll(indexObjectServiceFactory.getIndexableObjects(ctx, subject));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -175,6 +189,16 @@ public class IndexEventConsumer implements Consumer {
|
|||||||
public void end(Context ctx) throws Exception {
|
public void end(Context ctx) throws Exception {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
for (String uid : uniqueIdsToDelete) {
|
||||||
|
try {
|
||||||
|
indexer.unIndexContent(ctx, uid, false);
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("UN-Indexed Item, handle=" + uid);
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Failed while UN-indexing object: " + uid, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
// update the changed Items not deleted because they were on create list
|
// update the changed Items not deleted because they were on create list
|
||||||
for (IndexableObject iu : objectsToUpdate) {
|
for (IndexableObject iu : objectsToUpdate) {
|
||||||
/* we let all types through here and
|
/* we let all types through here and
|
||||||
@@ -183,7 +207,7 @@ public class IndexEventConsumer implements Consumer {
|
|||||||
*/
|
*/
|
||||||
iu.setIndexedObject(ctx.reloadEntity(iu.getIndexedObject()));
|
iu.setIndexedObject(ctx.reloadEntity(iu.getIndexedObject()));
|
||||||
String uniqueIndexID = iu.getUniqueIndexID();
|
String uniqueIndexID = iu.getUniqueIndexID();
|
||||||
if (uniqueIndexID != null && !uniqueIdsToDelete.contains(uniqueIndexID)) {
|
if (uniqueIndexID != null) {
|
||||||
try {
|
try {
|
||||||
indexer.indexContent(ctx, iu, true, false);
|
indexer.indexContent(ctx, iu, true, false);
|
||||||
log.debug("Indexed "
|
log.debug("Indexed "
|
||||||
@@ -195,17 +219,6 @@ public class IndexEventConsumer implements Consumer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (String uid : uniqueIdsToDelete) {
|
|
||||||
try {
|
|
||||||
indexer.unIndexContent(ctx, uid, false);
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("UN-Indexed Item, handle=" + uid);
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.error("Failed while UN-indexing object: " + uid, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} finally {
|
} finally {
|
||||||
if (!objectsToUpdate.isEmpty() || !uniqueIdsToDelete.isEmpty()) {
|
if (!objectsToUpdate.isEmpty() || !uniqueIdsToDelete.isEmpty()) {
|
||||||
|
|
||||||
|
@@ -11,6 +11,7 @@ import static org.junit.Assert.fail;
|
|||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.ArrayUtils;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.dspace.authorize.AuthorizeException;
|
import org.dspace.authorize.AuthorizeException;
|
||||||
import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
import org.dspace.authorize.factory.AuthorizeServiceFactory;
|
||||||
@@ -20,6 +21,8 @@ import org.dspace.core.I18nUtil;
|
|||||||
import org.dspace.eperson.EPerson;
|
import org.dspace.eperson.EPerson;
|
||||||
import org.dspace.eperson.factory.EPersonServiceFactory;
|
import org.dspace.eperson.factory.EPersonServiceFactory;
|
||||||
import org.dspace.eperson.service.EPersonService;
|
import org.dspace.eperson.service.EPersonService;
|
||||||
|
import org.dspace.services.ConfigurationService;
|
||||||
|
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||||
import org.dspace.storage.rdbms.DatabaseUtils;
|
import org.dspace.storage.rdbms.DatabaseUtils;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
@@ -119,6 +122,9 @@ public class AbstractUnitTest extends AbstractDSpaceTest {
|
|||||||
|
|
||||||
context.restoreAuthSystemState();
|
context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
// Ensure all tests run with Solr indexing disabled
|
||||||
|
disableSolrIndexing();
|
||||||
|
|
||||||
} catch (AuthorizeException ex) {
|
} catch (AuthorizeException ex) {
|
||||||
log.error("Error creating initial eperson or default groups", ex);
|
log.error("Error creating initial eperson or default groups", ex);
|
||||||
fail("Error creating initial eperson or default groups in AbstractUnitTest init()");
|
fail("Error creating initial eperson or default groups in AbstractUnitTest init()");
|
||||||
@@ -160,4 +166,23 @@ public class AbstractUnitTest extends AbstractDSpaceTest {
|
|||||||
c = null;
|
c = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Utility method which ensures Solr indexing is DISABLED in all Tests. We turn this off because
|
||||||
|
* Solr is NOT used in the dspace-api test framework. Instead, Solr/Discovery indexing is
|
||||||
|
* exercised in the dspace-server Integration Tests (which use an embedded Solr).
|
||||||
|
*/
|
||||||
|
protected static void disableSolrIndexing() {
|
||||||
|
// Get our currently configured list of event consumers
|
||||||
|
ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
|
||||||
|
String[] consumers = configurationService.getArrayProperty("event.dispatcher.default.consumers");
|
||||||
|
|
||||||
|
// Remove "discovery" from the configured consumers (if it exists).
|
||||||
|
// This turns off Discovery/Solr indexing after any object changes.
|
||||||
|
if (ArrayUtils.contains(consumers, "discovery")) {
|
||||||
|
consumers = ArrayUtils.removeElement(consumers, "discovery");
|
||||||
|
configurationService.setProperty("event.dispatcher.default.consumers", consumers);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -10,17 +10,33 @@ package org.dspace.discovery;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.dspace.AbstractIntegrationTestWithDatabase;
|
import org.dspace.AbstractIntegrationTestWithDatabase;
|
||||||
import org.dspace.builder.CollectionBuilder;
|
import org.dspace.builder.CollectionBuilder;
|
||||||
import org.dspace.builder.CommunityBuilder;
|
import org.dspace.builder.CommunityBuilder;
|
||||||
|
import org.dspace.builder.ItemBuilder;
|
||||||
import org.dspace.builder.WorkspaceItemBuilder;
|
import org.dspace.builder.WorkspaceItemBuilder;
|
||||||
import org.dspace.content.Collection;
|
import org.dspace.content.Collection;
|
||||||
import org.dspace.content.Community;
|
import org.dspace.content.Community;
|
||||||
|
import org.dspace.content.Item;
|
||||||
import org.dspace.content.WorkspaceItem;
|
import org.dspace.content.WorkspaceItem;
|
||||||
import org.dspace.content.factory.ContentServiceFactory;
|
import org.dspace.content.factory.ContentServiceFactory;
|
||||||
import org.dspace.content.service.WorkspaceItemService;
|
import org.dspace.content.service.WorkspaceItemService;
|
||||||
|
import org.dspace.eperson.EPerson;
|
||||||
|
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||||
|
import org.dspace.workflow.WorkflowItemService;
|
||||||
|
import org.dspace.xmlworkflow.factory.XmlWorkflowServiceFactory;
|
||||||
|
import org.dspace.xmlworkflow.service.WorkflowRequirementsService;
|
||||||
|
import org.dspace.xmlworkflow.service.XmlWorkflowService;
|
||||||
|
import org.dspace.xmlworkflow.state.Workflow;
|
||||||
|
import org.dspace.xmlworkflow.storedcomponents.ClaimedTask;
|
||||||
|
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
|
||||||
|
import org.dspace.xmlworkflow.storedcomponents.service.ClaimedTaskService;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.mock.web.MockHttpServletRequest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class will aim to test Discovery related use cases
|
* This class will aim to test Discovery related use cases
|
||||||
@@ -30,7 +46,20 @@ public class DiscoveryIT extends AbstractIntegrationTestWithDatabase {
|
|||||||
protected WorkspaceItemService workspaceItemService = ContentServiceFactory.getInstance().getWorkspaceItemService();
|
protected WorkspaceItemService workspaceItemService = ContentServiceFactory.getInstance().getWorkspaceItemService();
|
||||||
protected SearchService searchService = SearchUtils.getSearchService();
|
protected SearchService searchService = SearchUtils.getSearchService();
|
||||||
|
|
||||||
|
XmlWorkflowService workflowService = XmlWorkflowServiceFactory.getInstance().getXmlWorkflowService();
|
||||||
|
|
||||||
|
WorkflowItemService workflowItemService = XmlWorkflowServiceFactory.getInstance().getXmlWorkflowItemService();
|
||||||
|
|
||||||
|
WorkflowRequirementsService workflowRequirementsService = XmlWorkflowServiceFactory.getInstance().getWorkflowRequirementsService();
|
||||||
|
|
||||||
|
ClaimedTaskService claimedTaskService = XmlWorkflowServiceFactory.getInstance().getClaimedTaskService();
|
||||||
|
|
||||||
|
IndexingService indexer = DSpaceServicesFactory.getInstance().getServiceManager()
|
||||||
|
.getServiceByName(IndexingService.class.getName(),
|
||||||
|
IndexingService.class);
|
||||||
|
|
||||||
|
|
||||||
|
@Ignore
|
||||||
@Test
|
@Test
|
||||||
public void deleteWorkspaceItemSolrRecordAfterDeletionFromDbTest() throws Exception {
|
public void deleteWorkspaceItemSolrRecordAfterDeletionFromDbTest() throws Exception {
|
||||||
context.turnOffAuthorisationSystem();
|
context.turnOffAuthorisationSystem();
|
||||||
@@ -62,4 +91,93 @@ public class DiscoveryIT extends AbstractIntegrationTestWithDatabase {
|
|||||||
assertEquals(0, indexableObjects.size());
|
assertEquals(0, indexableObjects.size());
|
||||||
assertEquals(0, discoverResult.getTotalSearchResults());
|
assertEquals(0, discoverResult.getTotalSearchResults());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void deleteWorkspaceItemSolrRecordAfterDeletionFromDbTestn() throws Exception {
|
||||||
|
context.turnOffAuthorisationSystem();
|
||||||
|
Community community = CommunityBuilder.createCommunity(context)
|
||||||
|
.withName("Parent Community")
|
||||||
|
.build();
|
||||||
|
Collection collection = CollectionBuilder.createCollection(context, community)
|
||||||
|
.withWorkflowGroup(1, admin)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
WorkspaceItem wsi = WorkspaceItemBuilder.createWorkspaceItem(context, collection)
|
||||||
|
.withTitle("Test item")
|
||||||
|
.withIssueDate("2019-03-06")
|
||||||
|
.withSubject("ExtraEntry")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
ItemBuilder.createItem(context, collection).build();
|
||||||
|
|
||||||
|
|
||||||
|
// context.restoreAuthSystemState();
|
||||||
|
|
||||||
|
Workflow workflow = XmlWorkflowServiceFactory.getInstance().getWorkflowFactory().getWorkflow(collection);
|
||||||
|
|
||||||
|
ItemBuilder.createItem(context, collection).build();
|
||||||
|
|
||||||
|
MockHttpServletRequest httpServletRequest = new MockHttpServletRequest();
|
||||||
|
httpServletRequest.setParameter("submit_approve", "submit_approve");
|
||||||
|
|
||||||
|
XmlWorkflowItem workflowItem = workflowService.startWithoutNotify(context, wsi);
|
||||||
|
context.dispatchEvents();
|
||||||
|
indexer.commit();
|
||||||
|
|
||||||
|
assertSearchQuery("PoolTask", 1);
|
||||||
|
|
||||||
|
ItemBuilder.createItem(context, collection).build();
|
||||||
|
|
||||||
|
|
||||||
|
executeWorkflowAction(httpServletRequest, admin, workflow, workflowItem, "reviewstep", "claimaction");
|
||||||
|
|
||||||
|
|
||||||
|
context.dispatchEvents();
|
||||||
|
indexer.commit();
|
||||||
|
|
||||||
|
ItemBuilder.createItem(context, collection).build();
|
||||||
|
|
||||||
|
assertSearchQuery("PoolTask", 0);
|
||||||
|
assertSearchQuery("ClaimedTask", 1);
|
||||||
|
|
||||||
|
returnToPool(admin, workflowItem);
|
||||||
|
context.dispatchEvents();
|
||||||
|
indexer.commit();
|
||||||
|
|
||||||
|
ItemBuilder.createItem(context, collection).build();
|
||||||
|
|
||||||
|
assertSearchQuery("PoolTask", 1);
|
||||||
|
assertSearchQuery("ClaimedTask", 0);
|
||||||
|
|
||||||
|
workflowService.deleteWorkflowByWorkflowItem(context, workflowItem, admin);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void assertSearchQuery(String resourceType, int size) throws SearchServiceException {
|
||||||
|
DiscoverQuery discoverQuery = new DiscoverQuery();
|
||||||
|
discoverQuery.setQuery("*:*");
|
||||||
|
discoverQuery.addFilterQueries("search.resourcetype:" + resourceType);
|
||||||
|
DiscoverResult discoverResult = searchService.search(context, discoverQuery);
|
||||||
|
List<IndexableObject> indexableObjects = discoverResult.getIndexableObjects();
|
||||||
|
assertEquals(size, indexableObjects.size());
|
||||||
|
assertEquals(size, discoverResult.getTotalSearchResults());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void executeWorkflowAction(HttpServletRequest httpServletRequest, EPerson user,
|
||||||
|
Workflow workflow, XmlWorkflowItem workflowItem, String stepId, String actionId)
|
||||||
|
throws Exception {
|
||||||
|
context.setCurrentUser(user);
|
||||||
|
workflowService.doState(context, user, httpServletRequest, workflowItem.getID(), workflow,
|
||||||
|
workflow.getStep(stepId).getActionConfig(actionId));
|
||||||
|
context.setCurrentUser(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void returnToPool(EPerson user, XmlWorkflowItem workflowItem)
|
||||||
|
throws Exception {
|
||||||
|
context.setCurrentUser(user);
|
||||||
|
ClaimedTask task = claimedTaskService
|
||||||
|
.findByWorkflowIdAndEPerson(context, workflowItem, context.getCurrentUser());
|
||||||
|
workflowService.deleteClaimedTask(context, workflowItem, task);
|
||||||
|
workflowRequirementsService.removeClaimedUser(context, workflowItem, task.getOwner(), task.getStepID());
|
||||||
|
context.setCurrentUser(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user