mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
101549: Make BrowseIndexRestRepository#findAll also return hierarchicalBrowses
This commit is contained in:
@@ -22,11 +22,13 @@ import org.dspace.sort.SortOption;
|
||||
* This class holds all the information about a specifically configured
|
||||
* BrowseIndex. It is responsible for parsing the configuration, understanding
|
||||
* about what sort options are available, and what the names of the database
|
||||
* tables that hold all the information are actually called.
|
||||
* tables that hold all the information are actually called. Hierarchical browse
|
||||
* indexes also contain information about the vocabulary they're using, see:
|
||||
* {@link org.dspace.content.authority.DSpaceControlledVocabularyIndex}
|
||||
*
|
||||
* @author Richard Jones
|
||||
*/
|
||||
public final class BrowseIndex {
|
||||
public class BrowseIndex {
|
||||
/** the configuration number, as specified in the config */
|
||||
/**
|
||||
* used for single metadata browse tables for generating the table name
|
||||
@@ -102,7 +104,7 @@ public final class BrowseIndex {
|
||||
*
|
||||
* @param baseName The base of the table name
|
||||
*/
|
||||
private BrowseIndex(String baseName) {
|
||||
protected BrowseIndex(String baseName) {
|
||||
try {
|
||||
number = -1;
|
||||
tableBaseName = baseName;
|
||||
|
@@ -9,6 +9,7 @@ package org.dspace.content.authority;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.dspace.browse.BrowseIndex;
|
||||
import org.dspace.discovery.configuration.DiscoverySearchFilterFacet;
|
||||
|
||||
/**
|
||||
@@ -18,7 +19,7 @@ import org.dspace.discovery.configuration.DiscoverySearchFilterFacet;
|
||||
*
|
||||
* @author Marie Verdonck (Atmire) on 04/05/2023
|
||||
*/
|
||||
public class DSpaceControlledVocabularyIndex {
|
||||
public class DSpaceControlledVocabularyIndex extends BrowseIndex {
|
||||
|
||||
protected DSpaceControlledVocabulary vocabulary;
|
||||
protected Set<String> metadataFields;
|
||||
@@ -26,6 +27,7 @@ public class DSpaceControlledVocabularyIndex {
|
||||
|
||||
public DSpaceControlledVocabularyIndex(DSpaceControlledVocabulary controlledVocabulary, Set<String> metadataFields,
|
||||
DiscoverySearchFilterFacet facetConfig) {
|
||||
super(controlledVocabulary.vocabularyName);
|
||||
this.vocabulary = controlledVocabulary;
|
||||
this.metadataFields = metadataFields;
|
||||
this.facetConfig = facetConfig;
|
||||
|
@@ -8,6 +8,7 @@
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import static org.dspace.app.rest.model.BrowseIndexRest.BROWSE_TYPE_FLAT;
|
||||
import static org.dspace.app.rest.model.BrowseIndexRest.BROWSE_TYPE_HIERARCHICAL;
|
||||
import static org.dspace.app.rest.model.BrowseIndexRest.BROWSE_TYPE_VALUE_LIST;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -16,6 +17,7 @@ import java.util.List;
|
||||
import org.dspace.app.rest.model.BrowseIndexRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.browse.BrowseIndex;
|
||||
import org.dspace.content.authority.DSpaceControlledVocabularyIndex;
|
||||
import org.dspace.sort.SortException;
|
||||
import org.dspace.sort.SortOption;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -33,19 +35,29 @@ public class BrowseIndexConverter implements DSpaceConverter<BrowseIndex, Browse
|
||||
public BrowseIndexRest convert(BrowseIndex obj, Projection projection) {
|
||||
BrowseIndexRest bir = new BrowseIndexRest();
|
||||
bir.setProjection(projection);
|
||||
bir.setId(obj.getName());
|
||||
bir.setDataType(obj.getDataType());
|
||||
bir.setOrder(obj.getDefaultOrder());
|
||||
List<String> metadataList = new ArrayList<String>();
|
||||
if (obj.isMetadataIndex()) {
|
||||
String id = obj.getName();
|
||||
if (obj instanceof DSpaceControlledVocabularyIndex) {
|
||||
DSpaceControlledVocabularyIndex vocObj = (DSpaceControlledVocabularyIndex) obj;
|
||||
metadataList = new ArrayList<>(vocObj.getMetadataFields());
|
||||
id = vocObj.getVocabulary().getPluginInstanceName();
|
||||
bir.setFacetType(vocObj.getFacetConfig().getIndexFieldName());
|
||||
bir.setVocabulary(vocObj.getVocabulary().getPluginInstanceName());
|
||||
bir.setBrowseType(BROWSE_TYPE_HIERARCHICAL);
|
||||
} else if (obj.isMetadataIndex()) {
|
||||
for (String s : obj.getMetadata().split(",")) {
|
||||
metadataList.add(s.trim());
|
||||
}
|
||||
bir.setDataType(obj.getDataType());
|
||||
bir.setOrder(obj.getDefaultOrder());
|
||||
bir.setBrowseType(BROWSE_TYPE_VALUE_LIST);
|
||||
} else {
|
||||
metadataList.add(obj.getSortOption().getMetadata());
|
||||
bir.setDataType(obj.getDataType());
|
||||
bir.setOrder(obj.getDefaultOrder());
|
||||
bir.setBrowseType(BROWSE_TYPE_FLAT);
|
||||
}
|
||||
bir.setId(id);
|
||||
bir.setMetadataList(metadataList);
|
||||
|
||||
List<BrowseIndexRest.SortOption> sortOptionsList = new ArrayList<BrowseIndexRest.SortOption>();
|
||||
@@ -56,7 +68,9 @@ public class BrowseIndexConverter implements DSpaceConverter<BrowseIndex, Browse
|
||||
} catch (SortException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
}
|
||||
bir.setSortOptions(sortOptionsList);
|
||||
if (!bir.getBrowseType().equals(BROWSE_TYPE_HIERARCHICAL)) {
|
||||
bir.setSortOptions(sortOptionsList);
|
||||
}
|
||||
return bir;
|
||||
}
|
||||
|
||||
|
@@ -1,42 +0,0 @@
|
||||
/**
|
||||
* The contents of this file are subject to the license and copyright
|
||||
* detailed in the LICENSE and NOTICE files at the root of the source
|
||||
* tree and available online at
|
||||
*
|
||||
* http://www.dspace.org/license/
|
||||
*/
|
||||
package org.dspace.app.rest.converter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import org.dspace.app.rest.model.BrowseIndexRest;
|
||||
import org.dspace.app.rest.projection.Projection;
|
||||
import org.dspace.content.authority.DSpaceControlledVocabularyIndex;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* This is the converter from a {@link org.dspace.content.authority.DSpaceControlledVocabularyIndex} to a
|
||||
* {@link org.dspace.app.rest.model.BrowseIndexRest#BROWSE_TYPE_HIERARCHICAL} {@link org.dspace.app.rest.model.BrowseIndexRest}
|
||||
*
|
||||
* @author Marie Verdonck (Atmire) on 04/05/2023
|
||||
*/
|
||||
@Component
|
||||
public class HierarchicalBrowseConverter implements DSpaceConverter<DSpaceControlledVocabularyIndex, BrowseIndexRest> {
|
||||
|
||||
@Override
|
||||
public BrowseIndexRest convert(DSpaceControlledVocabularyIndex obj, Projection projection) {
|
||||
BrowseIndexRest bir = new BrowseIndexRest();
|
||||
bir.setProjection(projection);
|
||||
bir.setId(obj.getVocabulary().getPluginInstanceName());
|
||||
bir.setBrowseType(BrowseIndexRest.BROWSE_TYPE_HIERARCHICAL);
|
||||
bir.setFacetType(obj.getFacetConfig().getIndexFieldName());
|
||||
bir.setVocabulary(obj.getVocabulary().getPluginInstanceName());
|
||||
bir.setMetadataList(new ArrayList<>(obj.getMetadataFields()));
|
||||
return bir;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<DSpaceControlledVocabularyIndex> getModelClass() {
|
||||
return DSpaceControlledVocabularyIndex.class;
|
||||
}
|
||||
}
|
@@ -7,6 +7,7 @@
|
||||
*/
|
||||
package org.dspace.app.rest.repository;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@@ -68,7 +69,10 @@ public class BrowseIndexRestRepository extends DSpaceRestRepository<BrowseIndexR
|
||||
@Override
|
||||
public Page<BrowseIndexRest> findAll(Context context, Pageable pageable) {
|
||||
try {
|
||||
List<BrowseIndex> indexes = Arrays.asList(BrowseIndex.getBrowseIndices());
|
||||
List<BrowseIndex> indexes = new ArrayList<>(Arrays.asList(BrowseIndex.getBrowseIndices()));
|
||||
choiceAuthorityService.getChoiceAuthoritiesNames()
|
||||
.stream().filter(name -> choiceAuthorityService.getVocabularyIndex(name) != null)
|
||||
.forEach(name -> indexes.add(choiceAuthorityService.getVocabularyIndex(name)));
|
||||
return converter.toRestPage(indexes, pageable, indexes.size(), utils.obtainProjection());
|
||||
} catch (BrowseException e) {
|
||||
throw new RuntimeException(e.getMessage(), e);
|
||||
|
Reference in New Issue
Block a user