mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
97248: Find DSO based configurations recursively through parent objects
This commit is contained in:
@@ -18,6 +18,7 @@ import org.dspace.content.Collection;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.Item;
|
||||
import org.dspace.content.WorkspaceItem;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.discovery.configuration.DiscoveryConfiguration;
|
||||
import org.dspace.discovery.configuration.DiscoveryConfigurationService;
|
||||
import org.dspace.kernel.ServiceManager;
|
||||
@@ -60,28 +61,32 @@ public class SearchUtils {
|
||||
}
|
||||
|
||||
public static DiscoveryConfiguration getDiscoveryConfiguration() {
|
||||
return getDiscoveryConfiguration(null, null);
|
||||
return getDiscoveryConfiguration(null, null, null);
|
||||
}
|
||||
|
||||
public static DiscoveryConfiguration getDiscoveryConfiguration(DSpaceObject dso) {
|
||||
return getDiscoveryConfiguration(null, dso);
|
||||
public static DiscoveryConfiguration getDiscoveryConfiguration(final Context context,
|
||||
DSpaceObject dso) {
|
||||
return getDiscoveryConfiguration(context, null, dso);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the discovery configuration to use in a specific scope for the king of search identified by the prefix. A
|
||||
* null prefix mean the normal query, other predefined values are workspace or workflow
|
||||
*
|
||||
*
|
||||
* @param context
|
||||
* @param prefix
|
||||
* the namespace of the configuration to lookup if any
|
||||
* @param dso
|
||||
* the DSpaceObject
|
||||
* @return the discovery configuration for the specified scope
|
||||
*/
|
||||
public static DiscoveryConfiguration getDiscoveryConfiguration(String prefix, DSpaceObject dso) {
|
||||
public static DiscoveryConfiguration getDiscoveryConfiguration(final Context context, String prefix,
|
||||
DSpaceObject dso) {
|
||||
if (prefix != null) {
|
||||
return getDiscoveryConfigurationByName(dso != null ? prefix + "." + dso.getHandle() : prefix);
|
||||
} else {
|
||||
return getDiscoveryConfigurationByName(dso != null ? dso.getHandle() : null);
|
||||
return getDiscoveryConfigurationByDSO(context, dso);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,6 +103,11 @@ public class SearchUtils {
|
||||
|
||||
return configurationService.getDiscoveryConfiguration(configurationName);
|
||||
}
|
||||
public static DiscoveryConfiguration getDiscoveryConfigurationByDSO(
|
||||
Context context, DSpaceObject dso) {
|
||||
DiscoveryConfigurationService configurationService = getConfigurationService();
|
||||
return configurationService.getDiscoveryDSOConfiguration(context, dso);
|
||||
}
|
||||
|
||||
public static DiscoveryConfigurationService getConfigurationService() {
|
||||
ServiceManager manager = DSpaceServicesFactory.getInstance().getServiceManager();
|
||||
@@ -114,45 +124,54 @@ public class SearchUtils {
|
||||
* A configuration object can be returned for each parent community/collection
|
||||
*
|
||||
* @param item the DSpace item
|
||||
* @param context
|
||||
* @return a list of configuration objects
|
||||
* @throws SQLException An exception that provides information on a database access error or other errors.
|
||||
*/
|
||||
public static List<DiscoveryConfiguration> getAllDiscoveryConfigurations(Item item) throws SQLException {
|
||||
public static List<DiscoveryConfiguration> getAllDiscoveryConfigurations(Item item,
|
||||
final Context context) throws SQLException {
|
||||
List<Collection> collections = item.getCollections();
|
||||
return getAllDiscoveryConfigurations(null, collections, item);
|
||||
return getAllDiscoveryConfigurations(context, null, collections, item);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the discovery configuration applicable to the provided workspace item
|
||||
*
|
||||
* @param context
|
||||
* @param witem a workspace item
|
||||
* @return a list of discovery configuration
|
||||
* @throws SQLException
|
||||
*/
|
||||
public static List<DiscoveryConfiguration> getAllDiscoveryConfigurations(WorkspaceItem witem) throws SQLException {
|
||||
public static List<DiscoveryConfiguration> getAllDiscoveryConfigurations(final Context context,
|
||||
WorkspaceItem witem) throws SQLException {
|
||||
List<Collection> collections = new ArrayList<Collection>();
|
||||
collections.add(witem.getCollection());
|
||||
return getAllDiscoveryConfigurations("workspace", collections, witem.getItem());
|
||||
return getAllDiscoveryConfigurations(context, "workspace", collections, witem.getItem());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return all the discovery configuration applicable to the provided workflow item
|
||||
*
|
||||
* @param context
|
||||
* @param witem a workflow item
|
||||
* @return a list of discovery configuration
|
||||
* @throws SQLException
|
||||
*/
|
||||
public static List<DiscoveryConfiguration> getAllDiscoveryConfigurations(WorkflowItem witem) throws SQLException {
|
||||
public static List<DiscoveryConfiguration> getAllDiscoveryConfigurations(final Context context,
|
||||
WorkflowItem witem) throws SQLException {
|
||||
List<Collection> collections = new ArrayList<Collection>();
|
||||
collections.add(witem.getCollection());
|
||||
return getAllDiscoveryConfigurations("workflow", collections, witem.getItem());
|
||||
return getAllDiscoveryConfigurations(context, "workflow", collections, witem.getItem());
|
||||
}
|
||||
|
||||
private static List<DiscoveryConfiguration> getAllDiscoveryConfigurations(String prefix,
|
||||
private static List<DiscoveryConfiguration> getAllDiscoveryConfigurations(final Context context,
|
||||
String prefix,
|
||||
List<Collection> collections, Item item)
|
||||
throws SQLException {
|
||||
Set<DiscoveryConfiguration> result = new HashSet<>();
|
||||
|
||||
for (Collection collection : collections) {
|
||||
DiscoveryConfiguration configuration = getDiscoveryConfiguration(prefix, collection);
|
||||
DiscoveryConfiguration configuration = getDiscoveryConfiguration(context, prefix, collection);
|
||||
result.add(configuration);
|
||||
}
|
||||
|
||||
|
@@ -7,12 +7,20 @@
|
||||
*/
|
||||
package org.dspace.discovery.configuration;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.dspace.content.DSpaceObject;
|
||||
import org.dspace.content.factory.ContentServiceFactory;
|
||||
import org.dspace.content.service.DSpaceObjectService;
|
||||
import org.dspace.core.Context;
|
||||
import org.dspace.core.ReloadableEntity;
|
||||
import org.dspace.discovery.IndexableObject;
|
||||
import org.dspace.discovery.indexobject.IndexableDSpaceObject;
|
||||
import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
@@ -22,6 +30,8 @@ import org.dspace.services.factory.DSpaceServicesFactory;
|
||||
*/
|
||||
public class DiscoveryConfigurationService {
|
||||
|
||||
private static final Logger log = LogManager.getLogger();
|
||||
|
||||
private Map<String, DiscoveryConfiguration> map;
|
||||
private Map<Integer, List<String>> toIgnoreMetadataFields = new HashMap<>();
|
||||
|
||||
@@ -41,25 +51,53 @@ public class DiscoveryConfigurationService {
|
||||
this.toIgnoreMetadataFields = toIgnoreMetadataFields;
|
||||
}
|
||||
|
||||
public DiscoveryConfiguration getDiscoveryConfiguration(IndexableObject dso) {
|
||||
public DiscoveryConfiguration getDiscoveryConfiguration(final Context context,
|
||||
IndexableObject dso) {
|
||||
String name;
|
||||
if (dso == null) {
|
||||
name = "default";
|
||||
} else if (dso instanceof IndexableDSpaceObject) {
|
||||
name = ((IndexableDSpaceObject) dso).getIndexedObject().getHandle();
|
||||
return getDiscoveryDSOConfiguration(context, ((IndexableDSpaceObject) dso).getIndexedObject());
|
||||
} else {
|
||||
name = dso.getUniqueIndexID();
|
||||
}
|
||||
|
||||
return getDiscoveryConfiguration(name);
|
||||
}
|
||||
|
||||
public DiscoveryConfiguration getDiscoveryDSOConfiguration(final Context context,
|
||||
DSpaceObject dso) {
|
||||
String name;
|
||||
if (dso == null) {
|
||||
name = "default";
|
||||
} else {
|
||||
name = dso.getHandle();
|
||||
}
|
||||
|
||||
DiscoveryConfiguration configuration = getDiscoveryConfiguration(name, false);
|
||||
if (configuration != null) {
|
||||
return configuration;
|
||||
}
|
||||
DSpaceObjectService<DSpaceObject> dSpaceObjectService =
|
||||
ContentServiceFactory.getInstance().getDSpaceObjectService(dso);
|
||||
DSpaceObject parentObject = null;
|
||||
try {
|
||||
parentObject = dSpaceObjectService.getParentObject(context, dso);
|
||||
} catch (SQLException e) {
|
||||
log.error(e);
|
||||
}
|
||||
return getDiscoveryDSOConfiguration(context, parentObject);
|
||||
}
|
||||
|
||||
public DiscoveryConfiguration getDiscoveryConfiguration(final String name) {
|
||||
return getDiscoveryConfiguration(name, true);
|
||||
}
|
||||
|
||||
public DiscoveryConfiguration getDiscoveryConfiguration(final String name, boolean useDefault) {
|
||||
DiscoveryConfiguration result;
|
||||
|
||||
result = StringUtils.isBlank(name) ? null : getMap().get(name);
|
||||
|
||||
if (result == null) {
|
||||
if (result == null && useDefault) {
|
||||
//No specific configuration, get the default one
|
||||
result = getMap().get("default");
|
||||
}
|
||||
@@ -68,11 +106,12 @@ public class DiscoveryConfigurationService {
|
||||
}
|
||||
|
||||
public DiscoveryConfiguration getDiscoveryConfigurationByNameOrDso(final String configurationName,
|
||||
final Context context,
|
||||
final IndexableObject dso) {
|
||||
if (StringUtils.isNotBlank(configurationName) && getMap().containsKey(configurationName)) {
|
||||
return getMap().get(configurationName);
|
||||
} else {
|
||||
return getDiscoveryConfiguration(dso);
|
||||
return getDiscoveryConfiguration(context, dso);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -86,7 +86,7 @@ public class CollectionIndexFactoryImpl extends DSpaceObjectIndexFactoryImpl<Ind
|
||||
final Collection collection = indexableCollection.getIndexedObject();
|
||||
|
||||
// Retrieve configuration
|
||||
DiscoveryConfiguration discoveryConfiguration = SearchUtils.getDiscoveryConfiguration(collection);
|
||||
DiscoveryConfiguration discoveryConfiguration = SearchUtils.getDiscoveryConfiguration(context, collection);
|
||||
DiscoveryHitHighlightingConfiguration highlightingConfiguration = discoveryConfiguration
|
||||
.getHitHighlightingConfiguration();
|
||||
List<String> highlightedMetadataFields = new ArrayList<>();
|
||||
@@ -173,4 +173,4 @@ public class CollectionIndexFactoryImpl extends DSpaceObjectIndexFactoryImpl<Ind
|
||||
|
||||
return locations;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -69,7 +69,7 @@ public class CommunityIndexFactoryImpl extends DSpaceObjectIndexFactoryImpl<Inde
|
||||
final Community community = indexableObject.getIndexedObject();
|
||||
|
||||
// Retrieve configuration
|
||||
DiscoveryConfiguration discoveryConfiguration = SearchUtils.getDiscoveryConfiguration(community);
|
||||
DiscoveryConfiguration discoveryConfiguration = SearchUtils.getDiscoveryConfiguration(context, community);
|
||||
DiscoveryHitHighlightingConfiguration highlightingConfiguration = discoveryConfiguration
|
||||
.getHitHighlightingConfiguration();
|
||||
List<String> highlightedMetadataFields = new ArrayList<>();
|
||||
@@ -135,4 +135,4 @@ public class CommunityIndexFactoryImpl extends DSpaceObjectIndexFactoryImpl<Inde
|
||||
|
||||
return locations;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -73,11 +73,11 @@ public abstract class InprogressSubmissionIndexFactoryImpl
|
||||
// Add item metadata
|
||||
List<DiscoveryConfiguration> discoveryConfigurations;
|
||||
if (inProgressSubmission instanceof WorkflowItem) {
|
||||
discoveryConfigurations = SearchUtils.getAllDiscoveryConfigurations((WorkflowItem) inProgressSubmission);
|
||||
discoveryConfigurations = SearchUtils.getAllDiscoveryConfigurations(context, (WorkflowItem) inProgressSubmission);
|
||||
} else if (inProgressSubmission instanceof WorkspaceItem) {
|
||||
discoveryConfigurations = SearchUtils.getAllDiscoveryConfigurations((WorkspaceItem) inProgressSubmission);
|
||||
discoveryConfigurations = SearchUtils.getAllDiscoveryConfigurations(context, (WorkspaceItem) inProgressSubmission);
|
||||
} else {
|
||||
discoveryConfigurations = SearchUtils.getAllDiscoveryConfigurations(item);
|
||||
discoveryConfigurations = SearchUtils.getAllDiscoveryConfigurations(item, context);
|
||||
}
|
||||
indexableItemService.addDiscoveryFields(doc, context, item, discoveryConfigurations);
|
||||
indexableCollectionService.storeCommunityCollectionLocations(doc, locations);
|
||||
|
@@ -147,7 +147,7 @@ public class ItemIndexFactoryImpl extends DSpaceObjectIndexFactoryImpl<Indexable
|
||||
}
|
||||
|
||||
// Add the item metadata
|
||||
List<DiscoveryConfiguration> discoveryConfigurations = SearchUtils.getAllDiscoveryConfigurations(item);
|
||||
List<DiscoveryConfiguration> discoveryConfigurations = SearchUtils.getAllDiscoveryConfigurations(item, context);
|
||||
addDiscoveryFields(doc, context, indexableItem.getIndexedObject(), discoveryConfigurations);
|
||||
|
||||
//mandatory facet to show status on mydspace
|
||||
|
@@ -84,7 +84,7 @@ public class DiscoveryRestRepository extends AbstractDSpaceRestRepository {
|
||||
|
||||
IndexableObject scopeObject = scopeResolver.resolveScope(context, dsoScope);
|
||||
DiscoveryConfiguration discoveryConfiguration = searchConfigurationService
|
||||
.getDiscoveryConfigurationByNameOrDso(configuration, scopeObject);
|
||||
.getDiscoveryConfigurationByNameOrDso(configuration, context, scopeObject);
|
||||
|
||||
return discoverConfigurationConverter.convert(discoveryConfiguration, utils.obtainProjection());
|
||||
}
|
||||
@@ -96,7 +96,7 @@ public class DiscoveryRestRepository extends AbstractDSpaceRestRepository {
|
||||
Context context = obtainContext();
|
||||
IndexableObject scopeObject = scopeResolver.resolveScope(context, dsoScope);
|
||||
DiscoveryConfiguration discoveryConfiguration = searchConfigurationService
|
||||
.getDiscoveryConfigurationByNameOrDso(configuration, scopeObject);
|
||||
.getDiscoveryConfigurationByNameOrDso(configuration, context, scopeObject);
|
||||
|
||||
DiscoverResult searchResult = null;
|
||||
DiscoverQuery discoverQuery = null;
|
||||
@@ -121,7 +121,7 @@ public class DiscoveryRestRepository extends AbstractDSpaceRestRepository {
|
||||
|
||||
IndexableObject scopeObject = scopeResolver.resolveScope(context, dsoScope);
|
||||
DiscoveryConfiguration discoveryConfiguration = searchConfigurationService
|
||||
.getDiscoveryConfigurationByNameOrDso(configuration, scopeObject);
|
||||
.getDiscoveryConfigurationByNameOrDso(configuration, context, scopeObject);
|
||||
|
||||
return discoverFacetConfigurationConverter.convert(configuration, dsoScope, discoveryConfiguration);
|
||||
}
|
||||
@@ -138,7 +138,7 @@ public class DiscoveryRestRepository extends AbstractDSpaceRestRepository {
|
||||
|
||||
IndexableObject scopeObject = scopeResolver.resolveScope(context, dsoScope);
|
||||
DiscoveryConfiguration discoveryConfiguration = searchConfigurationService
|
||||
.getDiscoveryConfigurationByNameOrDso(configuration, scopeObject);
|
||||
.getDiscoveryConfigurationByNameOrDso(configuration, context, scopeObject);
|
||||
|
||||
DiscoverQuery discoverQuery = queryBuilder.buildFacetQuery(context, scopeObject, discoveryConfiguration, prefix,
|
||||
query, searchFilters, dsoTypes, page, facetName);
|
||||
@@ -157,7 +157,7 @@ public class DiscoveryRestRepository extends AbstractDSpaceRestRepository {
|
||||
Pageable page = PageRequest.of(1, 1);
|
||||
IndexableObject scopeObject = scopeResolver.resolveScope(context, dsoScope);
|
||||
DiscoveryConfiguration discoveryConfiguration = searchConfigurationService
|
||||
.getDiscoveryConfigurationByNameOrDso(configuration, scopeObject);
|
||||
.getDiscoveryConfigurationByNameOrDso(configuration, context, scopeObject);
|
||||
|
||||
DiscoverResult searchResult = null;
|
||||
DiscoverQuery discoverQuery = null;
|
||||
|
Reference in New Issue
Block a user