Merge pull request #3196 from 4Science/CST-3962

Item not indexed due to authority value not being in a controlled vocabulary
This commit is contained in:
Tim Donohue
2021-03-31 14:24:55 -05:00
committed by GitHub
2 changed files with 47 additions and 0 deletions

View File

@@ -13,6 +13,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
@@ -315,6 +316,9 @@ public class DSpaceControlledVocabulary extends SelfNamedPlugin implements Hiera
private String getNodeLabel(String key, boolean useHierarchy) {
try {
Node node = getNode(key);
if (Objects.isNull(node)) {
return null;
}
if (useHierarchy) {
return this.buildString(node);
} else {

View File

@@ -27,6 +27,9 @@ import org.dspace.content.Collection;
import org.dspace.content.Community;
import org.dspace.content.Item;
import org.dspace.content.WorkspaceItem;
import org.dspace.content.authority.Choices;
import org.dspace.content.authority.factory.ContentAuthorityServiceFactory;
import org.dspace.content.authority.service.MetadataAuthorityService;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.content.service.ItemService;
import org.dspace.content.service.WorkspaceItemService;
@@ -36,6 +39,7 @@ import org.dspace.discovery.indexobject.IndexablePoolTask;
import org.dspace.discovery.indexobject.IndexableWorkflowItem;
import org.dspace.discovery.indexobject.IndexableWorkspaceItem;
import org.dspace.eperson.EPerson;
import org.dspace.services.ConfigurationService;
import org.dspace.services.factory.DSpaceServicesFactory;
import org.dspace.workflow.WorkflowException;
import org.dspace.xmlworkflow.WorkflowConfigurationException;
@@ -73,6 +77,10 @@ public class DiscoveryIT extends AbstractIntegrationTestWithDatabase {
.getServiceByName(IndexingService.class.getName(),
IndexingService.class);
ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService();
MetadataAuthorityService metadataAuthorityService = ContentAuthorityServiceFactory.getInstance()
.getMetadataAuthorityService();
@Test
public void solrRecordsAfterDepositOrDeletionOfWorkspaceItemTest() throws Exception {
@@ -273,6 +281,41 @@ public class DiscoveryIT extends AbstractIntegrationTestWithDatabase {
}
@Test
public void solrRecordFromMessyItemTest() throws Exception {
configurationService.setProperty("authority.controlled.dc.subject", "true");
metadataAuthorityService.clearCache();
try {
context.turnOffAuthorisationSystem();
parentCommunity = CommunityBuilder.createCommunity(context)
.withName("Parent Community").build();
Collection col1 = CollectionBuilder.createCollection(context, parentCommunity)
.withName("Collection 1").build();
context.restoreAuthSystemState();
assertSearchQuery(IndexableItem.TYPE, 0);
context.turnOffAuthorisationSystem();
ItemBuilder.createItem(context, col1)
.withTitle("Public item 1")
.withIssueDate("2021-01-21")
.withAuthor("Smith, Donald")
.withSubject("Test Value", "NOT-EXISTING", Choices.CF_ACCEPTED)
.build();
context.restoreAuthSystemState();
assertSearchQuery(IndexableItem.TYPE, 1);
} finally {
configurationService.setProperty("authority.controlled.dc.subject", "false");
metadataAuthorityService.clearCache();
}
}
private void assertSearchQuery(String resourceType, int size) throws SearchServiceException {
DiscoverQuery discoverQuery = new DiscoverQuery();
discoverQuery.setQuery("*:*");