Merge remote-tracking branch 'origin/feature-relationship-versioning_discover-7.2' into feature-relationship-versioning-contribution

This commit is contained in:
Ben Bosman
2022-06-02 14:29:04 +02:00
6 changed files with 857 additions and 1 deletions

View File

@@ -245,6 +245,10 @@ public class ItemServiceImpl extends DSpaceObjectServiceImpl<Item> implements It
return itemDAO.findAll(context, true, true);
}
public Iterator<Item> findAllRegularItems(Context context) throws SQLException {
return itemDAO.findAllRegularItems(context);
};
@Override
public Iterator<Item> findBySubmitter(Context context, EPerson eperson) throws SQLException {
return itemDAO.findBySubmitter(context, eperson);

View File

@@ -32,8 +32,22 @@ public interface ItemDAO extends DSpaceObjectLegacySupportDAO<Item> {
public Iterator<Item> findAll(Context context, boolean archived, int limit, int offset) throws SQLException;
@Deprecated
public Iterator<Item> findAll(Context context, boolean archived, boolean withdrawn) throws SQLException;
/**
* Find all items that are:
* - NOT in the workspace
* - NOT in the workflow
* - NOT a template item for e.g. a collection
*
* This implies that the result also contains older versions of items and withdrawn items.
* @param context the DSpace context.
* @return iterator over all regular items.
* @throws SQLException if database error.
*/
public Iterator<Item> findAllRegularItems(Context context) throws SQLException;
/**
* Find all Items modified since a Date.
*

View File

@@ -79,6 +79,20 @@ public class ItemDAOImpl extends AbstractHibernateDSODAO<Item> implements ItemDA
return iterate(query);
}
@Override
public Iterator<Item> findAllRegularItems(Context context) throws SQLException {
// NOTE: This query includes archived items, withdrawn items and older versions of items.
// It does not include workspace, workflow or template items.
Query query = createQuery(
context,
"SELECT i FROM Item as i " +
"LEFT JOIN Version as v ON i = v.item " +
"WHERE i.inArchive=true or i.withdrawn=true or (i.inArchive=false and v.id IS NOT NULL) " +
"ORDER BY i.id"
);
return iterate(query);
}
@Override
public Iterator<Item> findAll(Context context, boolean archived,
boolean withdrawn, boolean discoverable, Date lastModified)

View File

@@ -112,8 +112,22 @@ public interface ItemService
* @return an iterator over the items in the archive.
* @throws SQLException if database error
*/
@Deprecated
public Iterator<Item> findAllUnfiltered(Context context) throws SQLException;
/**
* Find all items that are:
* - NOT in the workspace
* - NOT in the workflow
* - NOT a template item for e.g. a collection
*
* This implies that the result also contains older versions of items and withdrawn items.
* @param context the DSpace context.
* @return iterator over all regular items.
* @throws SQLException if database error.
*/
public Iterator<Item> findAllRegularItems(Context context) throws SQLException;
/**
* Find all the items in the archive by a given submitter. The order is
* indeterminate. Only items with the "in archive" flag set are included.

View File

@@ -103,7 +103,7 @@ public class ItemIndexFactoryImpl extends DSpaceObjectIndexFactoryImpl<Indexable
@Override
public Iterator<IndexableItem> findAll(Context context) throws SQLException {
Iterator<Item> items = itemService.findAllUnfiltered(context);
Iterator<Item> items = itemService.findAllRegularItems(context);
return new Iterator<IndexableItem>() {
@Override
public boolean hasNext() {

View File

@@ -37,16 +37,20 @@ import org.dspace.app.rest.test.AbstractControllerIntegrationTest;
import org.dspace.builder.CollectionBuilder;
import org.dspace.builder.CommunityBuilder;
import org.dspace.builder.EntityTypeBuilder;
import org.dspace.builder.GroupBuilder;
import org.dspace.builder.ItemBuilder;
import org.dspace.builder.RelationshipBuilder;
import org.dspace.builder.RelationshipTypeBuilder;
import org.dspace.builder.VersionBuilder;
import org.dspace.builder.WorkflowItemBuilder;
import org.dspace.builder.WorkspaceItemBuilder;
import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.EntityType;
import org.dspace.content.Item;
import org.dspace.content.MetadataValue;
import org.dspace.content.RelationshipType;
import org.dspace.content.WorkspaceItem;
import org.dspace.content.service.InstallItemService;
import org.dspace.content.service.ItemService;
import org.dspace.content.service.RelationshipService;
@@ -56,7 +60,9 @@ import org.dspace.discovery.DiscoverResult;
import org.dspace.discovery.IndexingService;
import org.dspace.discovery.SearchService;
import org.dspace.discovery.SolrSearchCore;
import org.dspace.discovery.indexobject.IndexableItem;
import org.dspace.versioning.Version;
import org.dspace.xmlworkflow.storedcomponents.XmlWorkflowItem;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.junit.After;
@@ -1675,4 +1681,808 @@ public class DiscoveryVersioningIT extends AbstractControllerIntegrationTest {
);
}
@Test
public void test_forceReindexAfterNewVersionInWorkspace() throws Exception {
// NOTE: VersioningConsumer updates the latest version status of relationships
// this implies the relation.* fields change so the relevant items should be re-indexed
context.turnOffAuthorisationSystem();
EntityType publicationEntityType = EntityTypeBuilder.createEntityTypeBuilder(context, "Publication")
.build();
EntityType projectEntityType = EntityTypeBuilder.createEntityTypeBuilder(context, "Project")
.build();
RelationshipType isProjectOfPublication = RelationshipTypeBuilder.createRelationshipTypeBuilder(
context, publicationEntityType, projectEntityType,
"isProjectOfPublication", "isPublicationOfProject",
null, null, null, null
)
.withCopyToLeft(false)
.withCopyToRight(false)
.build();
Collection publicationCollection = createCollection(publicationEntityType.getLabel());
// create publication 1.1
Item pub1_1 = ItemBuilder.createItem(context, publicationCollection)
.withTitle("publication 1")
.build();
String idPub1_1 = pub1_1.getID().toString();
Collection projectCollection = createCollection(projectEntityType.getLabel());
// create project 1.1
Item pro1_1 = ItemBuilder.createItem(context, projectCollection)
.withTitle("project 1")
.build();
String idPro1_1 = pro1_1.getID().toString();
// create relationship between publication 1.1 and project 1.1
RelationshipBuilder.createRelationshipBuilder(context, pub1_1, pro1_1, isProjectOfPublication)
.build();
context.restoreAuthSystemState();
// init - test relationships of publication 1.1
assertThat(
relationshipService.findByItem(context, pub1_1, -1, -1, false, false),
containsInAnyOrder(List.of(
isRel(pub1_1, isProjectOfPublication, pro1_1, BOTH, 0, 0)
))
);
// init - test relationships of project 1.1
assertThat(
relationshipService.findByItem(context, pro1_1, -1, -1, false, false),
containsInAnyOrder(List.of(
isRel(pub1_1, isProjectOfPublication, pro1_1, BOTH, 0, 0)
))
);
// init - test relation.* metadata of publication 1.1
List<MetadataValue> mdvs1 = itemService
.getMetadata(pub1_1, "relation", "isProjectOfPublication", null, Item.ANY);
Assert.assertEquals(1, mdvs1.size());
assertEquals(pro1_1.getID().toString(), mdvs1.get(0).getValue());
assertEquals(0, mdvs1.get(0).getPlace());
// init - test relation.*.latestForDiscovery metadata of publication 1.1
List<MetadataValue> mdvs1a = itemService
.getMetadata(pub1_1, "relation", "isProjectOfPublication", "latestForDiscovery", Item.ANY);
Assert.assertEquals(1, mdvs1a.size());
assertEquals(pro1_1.getID().toString(), mdvs1a.get(0).getValue());
assertEquals(-1, mdvs1a.get(0).getPlace());
// init - test relation.* metadata of project 1.1
List<MetadataValue> mdvs2 = itemService
.getMetadata(pro1_1, "relation", "isPublicationOfProject", null, Item.ANY);
Assert.assertEquals(1, mdvs2.size());
assertEquals(pub1_1.getID().toString(), mdvs2.get(0).getValue());
assertEquals(0, mdvs2.get(0).getPlace());
// init - test relation.*.latestForDiscovery metadata of project 1.1
List<MetadataValue> mdvs2a = itemService
.getMetadata(pro1_1, "relation", "isPublicationOfProject", "latestForDiscovery", Item.ANY);
Assert.assertEquals(1, mdvs2a.size());
assertEquals(pub1_1.getID().toString(), mdvs2a.get(0).getValue());
assertEquals(-1, mdvs2a.get(0).getPlace());
// init - search for related items of publication 1.1
verifyRestSearchObjects(
null, "project-relationships",
(r) -> r.param("f.isPublicationOfProject", idPub1_1 + ",equals"),
List.of(
matchSearchResult(pro1_1, "project 1")
)
);
// init - search for related items of project 1.1
verifyRestSearchObjects(
null, "publication-relationships",
(r) -> r.param("f.isProjectOfPublication", idPro1_1 + ",equals"),
List.of(
matchSearchResult(pub1_1, "publication 1")
)
);
// create new version of publication 1.1 => publication 1.2
context.turnOffAuthorisationSystem();
Item pub1_2 = VersionBuilder.createVersion(context, pub1_1, "pub 1.2").build().getItem();
String idPub1_2 = pub1_2.getID().toString();
context.commit();
indexingService.commit();
Assert.assertNotEquals(pub1_1, pub1_2);
installItemService.installItem(context, workspaceItemService.findByItem(context, pub1_2));
context.commit();
indexingService.commit();
context.restoreAuthSystemState();
// cache busting
pub1_1 = context.reloadEntity(pub1_1);
pub1_2 = context.reloadEntity(pub1_2);
pro1_1 = context.reloadEntity(pro1_1);
// after archive pub 1.2 - test relationships of publication 1.1
assertThat(
relationshipService.findByItem(context, pub1_1, -1, -1, false, false),
containsInAnyOrder(List.of(
isRel(pub1_1, isProjectOfPublication, pro1_1, RIGHT_ONLY, 0, 0)
))
);
// after archive pub 1.2 - test relationships of publication 1.2
assertThat(
relationshipService.findByItem(context, pub1_2, -1, -1, false, false),
containsInAnyOrder(List.of(
isRel(pub1_2, isProjectOfPublication, pro1_1, BOTH, 0, 0)
))
);
// after archive pub 1.2 - test relationships of project 1.1
assertThat(
relationshipService.findByItem(context, pro1_1, -1, -1, false, false),
containsInAnyOrder(List.of(
isRel(pub1_1, isProjectOfPublication, pro1_1, RIGHT_ONLY, 0, 0),
isRel(pub1_2, isProjectOfPublication, pro1_1, BOTH, 0, 0)
))
);
// after archive pub 1.2 - test relation.* metadata of publication 1.1
List<MetadataValue> mdvs3 = itemService
.getMetadata(pub1_1, "relation", "isProjectOfPublication", null, Item.ANY);
Assert.assertEquals(1, mdvs3.size());
assertEquals(pro1_1.getID().toString(), mdvs3.get(0).getValue());
assertEquals(0, mdvs3.get(0).getPlace());
verifySolrField(pub1_1, "relation.isProjectOfPublication", List.of(pro1_1.getID().toString()));
verifySolrField(pub1_1, "archived", List.of("false"));
verifySolrField(pub1_1, "latestVersion", List.of(false));
// after archive pub 1.2 - test relation.*.latestForDiscovery metadata of publication 1.1
List<MetadataValue> mdvs3a = itemService
.getMetadata(pub1_1, "relation", "isProjectOfPublication", "latestForDiscovery", Item.ANY);
Assert.assertEquals(0, mdvs3a.size());
verifySolrField(pub1_1, "relation.isProjectOfPublication.latestForDiscovery", null);
// after archive pub 1.2 - test relation.* metadata of publication 1.2
List<MetadataValue> mdvs4 = itemService
.getMetadata(pub1_2, "relation", "isProjectOfPublication", null, Item.ANY);
Assert.assertEquals(1, mdvs4.size());
assertEquals(pro1_1.getID().toString(), mdvs4.get(0).getValue());
assertEquals(0, mdvs4.get(0).getPlace());
verifySolrField(pub1_2, "relation.isProjectOfPublication", List.of(pro1_1.getID().toString()));
verifySolrField(pub1_2, "archived", List.of("true"));
verifySolrField(pub1_2, "latestVersion", List.of(true));
// after archive pub 1.2 - test relation.*.latestForDiscovery metadata of publication 1.2
List<MetadataValue> mdvs4a = itemService
.getMetadata(pub1_2, "relation", "isProjectOfPublication", "latestForDiscovery", Item.ANY);
Assert.assertEquals(1, mdvs4a.size());
assertEquals(pro1_1.getID().toString(), mdvs4a.get(0).getValue());
assertEquals(-1, mdvs4a.get(0).getPlace());
verifySolrField(
pub1_2, "relation.isProjectOfPublication.latestForDiscovery", List.of(pro1_1.getID().toString())
);
// after archive pub 1.2 - test relation.* metadata of project 1.1
List<MetadataValue> mdvs5 = itemService
.getMetadata(pro1_1, "relation", "isPublicationOfProject", null, Item.ANY);
Assert.assertEquals(1, mdvs5.size());
assertEquals(pub1_2.getID().toString(), mdvs5.get(0).getValue());
assertEquals(0, mdvs5.get(0).getPlace());
verifySolrField(pro1_1, "relation.isPublicationOfProject", List.of(pub1_2.getID().toString()));
verifySolrField(pro1_1, "archived", List.of("true"));
verifySolrField(pro1_1, "latestVersion", List.of(true));
// after archive pub 1.2 - test relation.*.latestForDiscovery metadata of project 1.1
List<MetadataValue> mdvs5a = itemService
.getMetadata(pro1_1, "relation", "isPublicationOfProject", "latestForDiscovery", Item.ANY);
Assert.assertEquals(2, mdvs5a.size());
assertThat(mdvs5a, containsInAnyOrder(
allOf(
hasProperty("value", is(pub1_1.getID().toString())),
hasProperty("place", is(-1))
),
allOf(
hasProperty("value", is(pub1_2.getID().toString())),
hasProperty("place", is(-1))
)
));
verifySolrField(pro1_1, "relation.isPublicationOfProject.latestForDiscovery", List.of(
pub1_1.getID().toString(),
pub1_2.getID().toString()
));
// after archive pub 1.2 - search for related items of publication 1.1
verifyRestSearchObjects(
null, "project-relationships",
(r) -> r.param("f.isPublicationOfProject", idPub1_1 + ",equals"),
List.of(
matchSearchResult(pro1_1, "project 1")
)
);
// after archive pub 1.2 - search for related items of publication 1.2
verifyRestSearchObjects(
null, "project-relationships",
(r) -> r.param("f.isPublicationOfProject", idPub1_2 + ",equals"),
List.of(
matchSearchResult(pro1_1, "project 1")
)
);
// after archive pub 1.2 - search for related items of project 1.1
verifyRestSearchObjects(
null, "publication-relationships",
(r) -> r.param("f.isProjectOfPublication", idPro1_1 + ",equals"),
List.of(
matchSearchResult(pub1_2, "publication 1")
)
);
// create new version of project 1.1 => project 1.2 BUT DON'T ARCHIVE YET
context.turnOffAuthorisationSystem();
Item pro1_2 = VersionBuilder.createVersion(context, context.reloadEntity(pro1_1), "pro 1.2").build().getItem();
String idPro1_2 = pro1_2.getID().toString();
context.commit();
indexingService.commit();
Assert.assertNotEquals(pro1_1, pro1_2);
context.restoreAuthSystemState();
// cache busting
pub1_1 = context.reloadEntity(pub1_1);
pub1_2 = context.reloadEntity(pub1_2);
pro1_1 = context.reloadEntity(pro1_1);
pro1_2 = context.reloadEntity(pro1_2);
// force reindex => expect that project 1.1 is still marked as latest version (for now)
indexingService.indexContent(context, new IndexableItem(pub1_1), true);
indexingService.indexContent(context, new IndexableItem(pub1_2), true);
indexingService.indexContent(context, new IndexableItem(pro1_1), true);
// NOTE: project 1.2 shouldn't be indexed yet
indexingService.commit();
// after create pro 1.2 - test relationships of publication 1.1
assertThat(
relationshipService.findByItem(context, pub1_1, -1, -1, false, false),
containsInAnyOrder(List.of(
isRel(pub1_1, isProjectOfPublication, pro1_1, RIGHT_ONLY, 0, 0)
))
);
// after create pro 1.2 - test relationships of publication 1.2
assertThat(
relationshipService.findByItem(context, pub1_2, -1, -1, false, false),
containsInAnyOrder(List.of(
isRel(pub1_2, isProjectOfPublication, pro1_1, BOTH, 0, 0),
isRel(pub1_2, isProjectOfPublication, pro1_2, LEFT_ONLY, 0, 0)
))
);
// after create pro 1.2 - test relationships of project 1.1
assertThat(
relationshipService.findByItem(context, pro1_1, -1, -1, false, false),
containsInAnyOrder(List.of(
isRel(pub1_1, isProjectOfPublication, pro1_1, RIGHT_ONLY, 0, 0),
isRel(pub1_2, isProjectOfPublication, pro1_1, BOTH, 0, 0)
))
);
// after create pro 1.2 - test relationships of project 1.2
assertThat(
relationshipService.findByItem(context, pro1_2, -1, -1, false, false),
containsInAnyOrder(List.of(
isRel(pub1_2, isProjectOfPublication, pro1_2, LEFT_ONLY, 0, 0)
))
);
// after create pro 1.2 - test relation.* metadata of publication 1.1
List<MetadataValue> mdvs6 = itemService
.getMetadata(pub1_1, "relation", "isProjectOfPublication", null, Item.ANY);
Assert.assertEquals(1, mdvs6.size());
assertEquals(pro1_1.getID().toString(), mdvs6.get(0).getValue());
assertEquals(0, mdvs6.get(0).getPlace());
verifySolrField(pub1_1, "relation.isProjectOfPublication", List.of(pro1_1.getID().toString()));
verifySolrField(pub1_1, "archived", List.of("false"));
verifySolrField(pub1_1, "latestVersion", List.of(false));
// after create pro 1.2 - test relation.*.latestForDiscovery metadata of publication 1.1
List<MetadataValue> mdvs6a = itemService
.getMetadata(pub1_1, "relation", "isProjectOfPublication", "latestForDiscovery", Item.ANY);
Assert.assertEquals(0, mdvs6a.size());
verifySolrField(pub1_1, "relation.isProjectOfPublication.latestForDiscovery", null);
// after create pro 1.2 - test relation.* metadata of publication 1.2
List<MetadataValue> mdvs7 = itemService
.getMetadata(pub1_2, "relation", "isProjectOfPublication", null, Item.ANY);
Assert.assertEquals(1, mdvs7.size());
assertEquals(pro1_1.getID().toString(), mdvs7.get(0).getValue());
assertEquals(0, mdvs7.get(0).getPlace());
verifySolrField(pub1_2, "relation.isProjectOfPublication", List.of(pro1_1.getID().toString()));
verifySolrField(pub1_2, "archived", List.of("true"));
verifySolrField(pub1_2, "latestVersion", List.of(true));
// after create pro 1.2 - test relation.*.latestForDiscovery metadata of publication 1.2
List<MetadataValue> mdvs7a = itemService
.getMetadata(pub1_2, "relation", "isProjectOfPublication", "latestForDiscovery", Item.ANY);
Assert.assertEquals(2, mdvs7a.size());
assertThat(mdvs7a, containsInAnyOrder(
allOf(
hasProperty("value", is(pro1_1.getID().toString())),
hasProperty("place", is(-1))
),
allOf(
hasProperty("value", is(pro1_2.getID().toString())),
hasProperty("place", is(-1))
)
));
verifySolrField(pub1_2, "relation.isProjectOfPublication.latestForDiscovery", List.of(
pro1_1.getID().toString(),
pro1_2.getID().toString()
));
// after create pro 1.2 - test relation.* metadata of project 1.1
List<MetadataValue> mdvs8 = itemService
.getMetadata(pro1_1, "relation", "isPublicationOfProject", null, Item.ANY);
Assert.assertEquals(1, mdvs8.size());
assertEquals(pub1_2.getID().toString(), mdvs8.get(0).getValue());
assertEquals(0, mdvs8.get(0).getPlace());
verifySolrField(pro1_1, "relation.isPublicationOfProject", List.of(pub1_2.getID().toString()));
verifySolrField(pro1_1, "archived", List.of("true"));
verifySolrField(pro1_1, "latestVersion", List.of(true));
// after create pro 1.2 - test relation.*.latestForDiscovery metadata of project 1.1
List<MetadataValue> mdvs8a = itemService
.getMetadata(pro1_1, "relation", "isPublicationOfProject", "latestForDiscovery", Item.ANY);
Assert.assertEquals(2, mdvs8a.size());
assertThat(mdvs8a, containsInAnyOrder(
allOf(
hasProperty("value", is(pub1_1.getID().toString())),
hasProperty("place", is(-1))
),
allOf(
hasProperty("value", is(pub1_2.getID().toString())),
hasProperty("place", is(-1))
)
));
verifySolrField(pro1_1, "relation.isPublicationOfProject.latestForDiscovery", List.of(
pub1_1.getID().toString(),
pub1_2.getID().toString()
));
// after create pro 1.2 - test relation.* metadata of project 1.2
List<MetadataValue> mdvs9 = itemService
.getMetadata(pro1_2, "relation", "isPublicationOfProject", null, Item.ANY);
Assert.assertEquals(1, mdvs9.size());
assertEquals(pub1_2.getID().toString(), mdvs9.get(0).getValue());
assertEquals(0, mdvs9.get(0).getPlace());
// NOTE: project 1.2 is still in the workspace,
// so it should not be indexed as an item (see ItemIndexFactory#getIndexableObjects)
verifyNotIndexed(pro1_2);
// after create pro 1.2 - test relation.*.latestForDiscovery metadata of project 1.2
List<MetadataValue> mdvs9a = itemService
.getMetadata(pro1_2, "relation", "isPublicationOfProject", "latestForDiscovery", Item.ANY);
Assert.assertEquals(0, mdvs9a.size());
// NOTE: project 1.2 is still in the workspace,
// so it should not be indexed as an item (see ItemIndexFactory#getIndexableObjects)
verifyNotIndexed(pro1_2);
// after create pro 1.2 - search for related items of publication 1.1
verifyRestSearchObjects(
null, "project-relationships",
(r) -> r.param("f.isPublicationOfProject", idPub1_1 + ",equals"),
List.of(
matchSearchResult(pro1_1, "project 1")
)
);
// after create pro 1.2 - search for related items of publication 1.2
verifyRestSearchObjects(
null, "project-relationships",
(r) -> r.param("f.isPublicationOfProject", idPub1_2 + ",equals"),
List.of(
matchSearchResult(pro1_1, "project 1")
// NOTE: project 1.2 is still in the workspace
)
);
// after create pro 1.2 - search for related items of project 1.1
verifyRestSearchObjects(
null, "publication-relationships",
(r) -> r.param("f.isProjectOfPublication", idPro1_1 + ",equals"),
List.of(
matchSearchResult(pub1_2, "publication 1")
)
);
// after create pro 1.2 - search for related items of project 1.2
verifyRestSearchObjects(
null, "publication-relationships",
(r) -> r.param("f.isProjectOfPublication", idPro1_2 + ",equals"),
List.of(
matchSearchResult(pub1_2, "publication 1")
)
);
// archive project 1.2
context.turnOffAuthorisationSystem();
installItemService.installItem(context, workspaceItemService.findByItem(context, pro1_2));
context.commit();
indexingService.commit();
context.restoreAuthSystemState();
// cache busting
pub1_1 = context.reloadEntity(pub1_1);
pub1_2 = context.reloadEntity(pub1_2);
pro1_1 = context.reloadEntity(pro1_1);
pro1_2 = context.reloadEntity(pro1_2);
// after archive pro 1.2 - test relationships of publication 1.1
assertThat(
relationshipService.findByItem(context, pub1_1, -1, -1, false, false),
containsInAnyOrder(List.of(
isRel(pub1_1, isProjectOfPublication, pro1_1, RIGHT_ONLY, 0, 0)
))
);
// after archive pro 1.2 - test relationships of publication 1.2
assertThat(
relationshipService.findByItem(context, pub1_2, -1, -1, false, false),
containsInAnyOrder(List.of(
isRel(pub1_2, isProjectOfPublication, pro1_1, LEFT_ONLY, 0, 0),
isRel(pub1_2, isProjectOfPublication, pro1_2, BOTH, 0, 0)
))
);
// after archive pro 1.2 - test relationships of project 1.1
assertThat(
relationshipService.findByItem(context, pro1_1, -1, -1, false, false),
containsInAnyOrder(List.of(
isRel(pub1_1, isProjectOfPublication, pro1_1, RIGHT_ONLY, 0, 0),
isRel(pub1_2, isProjectOfPublication, pro1_1, LEFT_ONLY, 0, 0)
))
);
// after archive pro 1.2 - test relationships of project 1.2
assertThat(
relationshipService.findByItem(context, pro1_2, -1, -1, false, false),
containsInAnyOrder(List.of(
isRel(pub1_2, isProjectOfPublication, pro1_2, BOTH, 0, 0)
))
);
// after archive pro 1.2 - test relation.* metadata of publication 1.1
List<MetadataValue> mdvs10 = itemService
.getMetadata(pub1_1, "relation", "isProjectOfPublication", null, Item.ANY);
Assert.assertEquals(1, mdvs10.size());
assertEquals(pro1_1.getID().toString(), mdvs10.get(0).getValue());
assertEquals(0, mdvs10.get(0).getPlace());
verifySolrField(pub1_1, "relation.isProjectOfPublication", List.of(pro1_1.getID().toString()));
verifySolrField(pub1_1, "archived", List.of("false"));
verifySolrField(pub1_1, "latestVersion", List.of(false));
// after archive pro 1.2 - test relation.*.latestForDiscovery metadata of publication 1.1
List<MetadataValue> mdvs10a = itemService
.getMetadata(pub1_1, "relation", "isProjectOfPublication", "latestForDiscovery", Item.ANY);
Assert.assertEquals(0, mdvs10a.size());
verifySolrField(pub1_1, "relation.isProjectOfPublication.latestForDiscovery", null);
// after archive pro 1.2 - test relation.* metadata of publication 1.2
List<MetadataValue> mdvs11 = itemService
.getMetadata(pub1_2, "relation", "isProjectOfPublication", null, Item.ANY);
Assert.assertEquals(1, mdvs11.size());
assertEquals(pro1_2.getID().toString(), mdvs11.get(0).getValue());
assertEquals(0, mdvs11.get(0).getPlace());
verifySolrField(pub1_2, "relation.isProjectOfPublication", List.of(pro1_2.getID().toString()));
verifySolrField(pub1_2, "archived", List.of("true"));
verifySolrField(pub1_2, "latestVersion", List.of(true));
// after archive pro 1.2 - test relation.*.latestForDiscovery metadata of publication 1.2
List<MetadataValue> mdvs11a = itemService
.getMetadata(pub1_2, "relation", "isProjectOfPublication", "latestForDiscovery", Item.ANY);
Assert.assertEquals(2, mdvs11a.size());
assertThat(mdvs11a, containsInAnyOrder(
allOf(
hasProperty("value", is(pro1_1.getID().toString())),
hasProperty("place", is(-1))
),
allOf(
hasProperty("value", is(pro1_2.getID().toString())),
hasProperty("place", is(-1))
)
));
verifySolrField(pub1_2, "relation.isProjectOfPublication.latestForDiscovery", List.of(
pro1_1.getID().toString(),
pro1_2.getID().toString()
));
// after archive pro 1.2 - test relation.* metadata of project 1.1
List<MetadataValue> mdvs12 = itemService
.getMetadata(pro1_1, "relation", "isPublicationOfProject", null, Item.ANY);
Assert.assertEquals(1, mdvs12.size());
assertEquals(pub1_2.getID().toString(), mdvs12.get(0).getValue());
assertEquals(0, mdvs12.get(0).getPlace());
verifySolrField(pro1_1, "relation.isPublicationOfProject", List.of(pub1_2.getID().toString()));
verifySolrField(pro1_1, "archived", List.of("false"));
verifySolrField(pro1_1, "latestVersion", List.of(false));
// after archive pro 1.2 - test relation.*.latestForDiscovery metadata of project 1.1
List<MetadataValue> mdvs12a = itemService
.getMetadata(pro1_1, "relation", "isPublicationOfProject", "latestForDiscovery", Item.ANY);
Assert.assertEquals(1, mdvs12a.size());
assertEquals(pub1_1.getID().toString(), mdvs12a.get(0).getValue());
assertEquals(-1, mdvs12a.get(0).getPlace());
verifySolrField(
pro1_1, "relation.isPublicationOfProject.latestForDiscovery", List.of(pub1_1.getID().toString())
);
// after archive pro 1.2 - test relation.* metadata of project 1.2
List<MetadataValue> mdvs13 = itemService
.getMetadata(pro1_2, "relation", "isPublicationOfProject", null, Item.ANY);
Assert.assertEquals(1, mdvs13.size());
assertEquals(pub1_2.getID().toString(), mdvs13.get(0).getValue());
assertEquals(0, mdvs13.get(0).getPlace());
verifySolrField(pro1_2, "relation.isPublicationOfProject", List.of(pub1_2.getID().toString()));
verifySolrField(pro1_2, "archived", List.of("true"));
verifySolrField(pro1_2, "latestVersion", List.of(true));
// after archive pro 1.2 - test relation.*.latestForDiscovery metadata of project 1.2
List<MetadataValue> mdvs13a = itemService
.getMetadata(pro1_2, "relation", "isPublicationOfProject", "latestForDiscovery", Item.ANY);
Assert.assertEquals(1, mdvs13a.size());
assertEquals(pub1_2.getID().toString(), mdvs13a.get(0).getValue());
assertEquals(-1, mdvs13a.get(0).getPlace());
verifySolrField(
pro1_2, "relation.isPublicationOfProject.latestForDiscovery", List.of(pub1_2.getID().toString())
);
// after archive pro 1.2 - search for related items of publication 1.1
verifyRestSearchObjects(
null, "project-relationships",
(r) -> r.param("f.isPublicationOfProject", idPub1_1 + ",equals"),
List.of(
matchSearchResult(pro1_1, "project 1")
)
);
// after archive pro 1.2 - search for related items of publication 1.2
verifyRestSearchObjects(
null, "project-relationships",
(r) -> r.param("f.isPublicationOfProject", idPub1_2 + ",equals"),
List.of(
matchSearchResult(pro1_2, "project 1")
)
);
// after archive pro 1.2 - search for related items of project 1.1
verifyRestSearchObjects(
null, "publication-relationships",
(r) -> r.param("f.isProjectOfPublication", idPro1_1 + ",equals"),
List.of(
matchSearchResult(pub1_2, "publication 1")
)
);
// after archive pro 1.2 - search for related items of project 1.2
verifyRestSearchObjects(
null, "publication-relationships",
(r) -> r.param("f.isProjectOfPublication", idPro1_2 + ",equals"),
List.of(
matchSearchResult(pub1_2, "publication 1")
)
);
}
@Test
public void test_rebuildIndexAllVersionsShouldStillBePresentInSolrCore() throws Exception {
context.turnOffAuthorisationSystem();
EntityType publicationEntityType = EntityTypeBuilder.createEntityTypeBuilder(context, "Publication")
.build();
EntityType projectEntityType = EntityTypeBuilder.createEntityTypeBuilder(context, "Project")
.build();
RelationshipType isProjectOfPublication = RelationshipTypeBuilder.createRelationshipTypeBuilder(
context, publicationEntityType, projectEntityType,
"isProjectOfPublication", "isPublicationOfProject",
null, null, null, null
)
.withCopyToLeft(false)
.withCopyToRight(false)
.build();
Collection publicationCollection = createCollection(publicationEntityType.getLabel());
Collection projectCollection = createCollection(projectEntityType.getLabel());
// create publication 1.1
Item pub1_1 = ItemBuilder.createItem(context, publicationCollection)
.withTitle("pub 1.1")
// NOTE: entity type is inherited from collection
.build();
// create project 1.1
Item pro1_1 = ItemBuilder.createItem(context, projectCollection)
.withTitle("pro 1.1")
// NOTE: entity type is inherited from collection
.build();
// create relationship between publication 1.1 and project 1.1
RelationshipBuilder.createRelationshipBuilder(context, pub1_1, pro1_1, isProjectOfPublication)
.build();
context.restoreAuthSystemState();
// create new version of publication 1.1 => publication 1.2
Item pub1_2 = createNewVersion(context.reloadEntity(pub1_1), "pub 1.2");
// create new version of publication 1.2 => publication 1.3
Item pub1_3 = createNewVersion(context.reloadEntity(pub1_2), "pub 1.3");
// create new version of publication 1.3 => publication 1.4
Item pub1_4 = createNewVersion(context.reloadEntity(pub1_3), "pub 1.4");
// cache busting
pub1_1 = context.reloadEntity(pub1_1);
pub1_2 = context.reloadEntity(pub1_2);
pub1_3 = context.reloadEntity(pub1_3);
pub1_4 = context.reloadEntity(pub1_4);
pro1_1 = context.reloadEntity(pro1_1);
// before reindex - verify publication 1.1
verifyIndexed(pub1_1);
verifySolrField(pub1_1, "archived", List.of("false"));
verifySolrField(pub1_1, "latestVersion", List.of(false));
verifySolrField(pub1_1, "relation.isProjectOfPublication", List.of(pro1_1.getID().toString()));
verifySolrField(pub1_1, "relation.isProjectOfPublication.latestForDiscovery", null);
// before reindex - verify publication 1.2
verifyIndexed(pub1_2);
verifySolrField(pub1_2, "archived", List.of("false"));
verifySolrField(pub1_2, "latestVersion", List.of(false));
verifySolrField(pub1_2, "relation.isProjectOfPublication", List.of(pro1_1.getID().toString()));
verifySolrField(pub1_2, "relation.isProjectOfPublication.latestForDiscovery", null);
// before reindex - verify publication 1.3
verifyIndexed(pub1_3);
verifySolrField(pub1_3, "archived", List.of("false"));
verifySolrField(pub1_3, "latestVersion", List.of(false));
verifySolrField(pub1_3, "relation.isProjectOfPublication", List.of(pro1_1.getID().toString()));
verifySolrField(pub1_3, "relation.isProjectOfPublication.latestForDiscovery", null);
// before reindex - verify publication 1.4
verifyIndexed(pub1_4);
verifySolrField(pub1_4, "archived", List.of("true"));
verifySolrField(pub1_4, "latestVersion", List.of(true));
verifySolrField(pub1_4, "relation.isProjectOfPublication", List.of(pro1_1.getID().toString()));
verifySolrField(pub1_4, "relation.isProjectOfPublication.latestForDiscovery", List.of(
pro1_1.getID().toString()
));
// before reindex - verify project 1.1
verifyIndexed(pro1_1);
verifySolrField(pro1_1, "archived", List.of("true"));
verifySolrField(pro1_1, "latestVersion", List.of(true));
verifySolrField(pro1_1, "relation.isPublicationOfProject", List.of(pub1_4.getID().toString()));
verifySolrField(pro1_1, "relation.isPublicationOfProject.latestForDiscovery", List.of(
pub1_1.getID().toString(), pub1_2.getID().toString(), pub1_3.getID().toString(), pub1_4.getID().toString()
));
// force reindex all items
indexingService.deleteIndex();
indexingService.createIndex(context);
// after reindex - verify publication 1.1
verifyIndexed(pub1_1);
verifySolrField(pub1_1, "archived", List.of("false"));
verifySolrField(pub1_1, "latestVersion", List.of(false));
verifySolrField(pub1_1, "relation.isProjectOfPublication", List.of(pro1_1.getID().toString()));
verifySolrField(pub1_1, "relation.isProjectOfPublication.latestForDiscovery", null);
// after reindex - verify publication 1.2
verifyIndexed(pub1_2);
verifySolrField(pub1_2, "archived", List.of("false"));
verifySolrField(pub1_2, "latestVersion", List.of(false));
verifySolrField(pub1_2, "relation.isProjectOfPublication", List.of(pro1_1.getID().toString()));
verifySolrField(pub1_2, "relation.isProjectOfPublication.latestForDiscovery", null);
// after reindex - verify publication 1.3
verifyIndexed(pub1_3);
verifySolrField(pub1_3, "archived", List.of("false"));
verifySolrField(pub1_3, "latestVersion", List.of(false));
verifySolrField(pub1_3, "relation.isProjectOfPublication", List.of(pro1_1.getID().toString()));
verifySolrField(pub1_3, "relation.isProjectOfPublication.latestForDiscovery", null);
// after reindex - verify publication 1.4
verifyIndexed(pub1_4);
verifySolrField(pub1_4, "archived", List.of("true"));
verifySolrField(pub1_4, "latestVersion", List.of(true));
verifySolrField(pub1_4, "relation.isProjectOfPublication", List.of(pro1_1.getID().toString()));
verifySolrField(pub1_4, "relation.isProjectOfPublication.latestForDiscovery", List.of(
pro1_1.getID().toString()
));
// after reindex - verify project 1.1
verifyIndexed(pro1_1);
verifySolrField(pro1_1, "archived", List.of("true"));
verifySolrField(pro1_1, "latestVersion", List.of(true));
verifySolrField(pro1_1, "relation.isPublicationOfProject", List.of(pub1_4.getID().toString()));
verifySolrField(pro1_1, "relation.isPublicationOfProject.latestForDiscovery", List.of(
pub1_1.getID().toString(), pub1_2.getID().toString(), pub1_3.getID().toString(), pub1_4.getID().toString()
));
}
// NOTE: this test makes sure that the changes to ItemIndexFactoryImpl don't break old behavior
@Test
public void test_rebuildIndex_itemInWorkspaceNotIndexed() throws Exception {
Collection collection = createCollection();
context.turnOffAuthorisationSystem();
WorkspaceItem wsi = WorkspaceItemBuilder.createWorkspaceItem(context, collection)
.withTitle("item 1")
.build();
context.restoreAuthSystemState();
verifyNotIndexed(wsi.getItem());
// force reindex all items
indexingService.deleteIndex();
indexingService.createIndex(context);
verifyNotIndexed(wsi.getItem());
}
// NOTE: this test makes sure that the changes to ItemIndexFactoryImpl don't break old behavior
@Test
public void test_rebuildIndex_itemInWorkflowNotIndexed() throws Exception {
context.turnOffAuthorisationSystem();
// NOTE: this collection uses the "selectSingleReviewer" workflow, see workflow.xml
Collection collection = CollectionBuilder.createCollection(context, community, "123456789/workflow-test-1")
.withName("collection")
.build();
// NOTE: the "selectSingleReviewer" requires the "ReviewManagers" group to be present and
// contain at least one member
GroupBuilder.createGroup(context)
.withName("ReviewManagers")
.addMember(admin)
.build();
XmlWorkflowItem wfi = WorkflowItemBuilder.createWorkflowItem(context, collection)
.withTitle("item 1")
.build();
context.restoreAuthSystemState();
verifyNotIndexed(wfi.getItem());
// force reindex all items
indexingService.deleteIndex();
indexingService.createIndex(context);
verifyNotIndexed(wfi.getItem());
}
// NOTE: this test makes sure that the changes to ItemIndexFactoryImpl don't break old behavior
@Test
public void test_rebuildIndex_templateItemNotIndexed() throws Exception {
Collection collection = createCollection();
context.turnOffAuthorisationSystem();
Item templateItem = itemService.createTemplateItem(context, collection);
context.restoreAuthSystemState();
verifyNotIndexed(templateItem);
// force reindex all items
indexingService.deleteIndex();
indexingService.createIndex(context);
verifyNotIndexed(templateItem);
}
}