Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import org.dspace.content.WorkspaceItem;
import org.dspace.content.service.RelationshipService;
import org.dspace.content.service.WorkspaceItemService;
import org.dspace.core.Constants;
import org.dspace.core.Context;
import org.dspace.event.Event;
import org.dspace.identifier.IdentifierException;
import org.dspace.identifier.service.IdentifierService;
import org.dspace.versioning.service.VersionHistoryService;
Expand Down Expand Up @@ -87,6 +89,11 @@ public void deleteVersionedItem(Context c, Version versionToDelete, VersionHisto
|| workflowItemService.findByItem(c, versionToDelete.getItem()) != null) {
item.setArchived(true);
itemService.update(c, item);
} else {
// The previous version stayed archived (versioning.unarchive.previous.version = false),
// but Solr still marks it as an old version, so reindex it.
c.addEvent(new Event(Event.MODIFY, Constants.ITEM, item.getID(), null,
itemService.getIdentifiers(c, item)));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
Expand Down Expand Up @@ -339,6 +340,47 @@ public void test_discoveryXml_default_expectLatestVersionsOnly() throws Exceptio
));
}

@Test
public void test_deleteLatestVersion_archivedPreviousVersionIsFoundAgain() throws Exception {
// the CLARIN value from clarin-dspace.cfg; the test local.cfg sets it to true
configurationService.setProperty("versioning.unarchive.previous.version", false);
final String configuration = null;

Collection collection = createCollection();

// create item 1.1 (first version of item 1)
context.turnOffAuthorisationSystem();
Item i1_1 = ItemBuilder.createItem(context, collection)
.withTitle("item 1.1")
.build();
context.restoreAuthSystemState();

// create and archive item 1.2 (second version of item 1)
Item i1_2 = createNewVersion(i1_1, "item 1.2");

// item 1.1 stays archived, but only item 1.2 appears in /api/discover/search/objects
Assert.assertTrue(context.reloadEntity(i1_1).isArchived());
verifySolrField(i1_1, "latestVersion", List.of(false));
verifyRestSearchObjects(configuration, List.of(
matchSearchResult(community),
matchSearchResult(collection),
matchSearchResult(i1_2, "item 1.2")
));

// delete item 1.2, the latest version
String adminToken = getAuthToken(admin.getEmail(), password);
getClient(adminToken).perform(delete("/api/core/items/" + i1_2.getID()))
.andExpect(status().isNoContent());

// item 1.1 is the latest version again and appears in /api/discover/search/objects right away
verifySolrField(i1_1, "latestVersion", List.of(true));
verifyRestSearchObjects(configuration, List.of(
matchSearchResult(community),
matchSearchResult(collection),
matchSearchResult(i1_1, "item 1.1")
));
}

@Test
public void test_discoveryXml_defaultRelationships_allVersions() throws Exception {
final String configuration = "default-relationships";
Expand Down
Loading