diff --git a/dspace-api/pom.xml b/dspace-api/pom.xml index f9ca96ffd6..fe6bd7d022 100644 --- a/dspace-api/pom.xml +++ b/dspace-api/pom.xml @@ -188,6 +188,12 @@ commons-fileupload commons-fileupload + + + commons-httpclient + commons-httpclient + + commons-io commons-io diff --git a/dspace-discovery/dspace-discovery-solr/src/main/java/org/dspace/browse/SolrBrowseCreateDAO.java b/dspace-api/src/main/java/org/dspace/browse/SolrBrowseCreateDAO.java similarity index 97% rename from dspace-discovery/dspace-discovery-solr/src/main/java/org/dspace/browse/SolrBrowseCreateDAO.java rename to dspace-api/src/main/java/org/dspace/browse/SolrBrowseCreateDAO.java index 53b90fb947..538d75431b 100644 --- a/dspace-discovery/dspace-discovery-solr/src/main/java/org/dspace/browse/SolrBrowseCreateDAO.java +++ b/dspace-api/src/main/java/org/dspace/browse/SolrBrowseCreateDAO.java @@ -1,533 +1,533 @@ -/** - * 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.browse; - -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.commons.lang.StringUtils; -import org.apache.log4j.Logger; -import org.apache.solr.common.SolrInputDocument; -import org.dspace.content.DCValue; -import org.dspace.content.DSpaceObject; -import org.dspace.content.Item; -import org.dspace.content.authority.ChoiceAuthorityManager; -import org.dspace.content.authority.MetadataAuthorityManager; -import org.dspace.core.ConfigurationManager; -import org.dspace.core.Context; -import org.dspace.discovery.SolrServiceImpl; -import org.dspace.discovery.SolrServiceIndexPlugin; -import org.dspace.sort.OrderFormat; -import org.dspace.sort.SortException; -import org.dspace.sort.SortOption; -import org.dspace.utils.DSpace; - -/** - * - * @author Andrea Bollini (CILEA) - * - */ -public class SolrBrowseCreateDAO implements BrowseCreateDAO, - SolrServiceIndexPlugin -{ - private static final String INFO_NOSQL_TO_RUN = "No SQL to run: data are stored in the SOLR Search Core. PLEASE NOTE THAT YOU MUST UPDATE THE DISCOVERY INDEX AFTER ANY CHANGES TO THE BROWSE CONFIGURATION"; - - // reference to a DBMS BrowseCreateDAO needed to remove old tables when - // switching from DBMS to SOLR - private BrowseCreateDAO dbCreateDAO; - - private static final Logger log = Logger - .getLogger(SolrBrowseCreateDAO.class); - - private BrowseIndex[] bis; - - public SolrBrowseCreateDAO() - { - try - { - bis = BrowseIndex.getBrowseIndices(); - } - catch (BrowseException e) - { - log.error(e.getMessage(), e); - throw new IllegalStateException(e); - } - - for (BrowseIndex bi : bis) - bi.generateMdBits(); - } - - public SolrBrowseCreateDAO(Context context) throws BrowseException - { - // For compatibility with previous versions - String db = ConfigurationManager.getProperty("db.name"); - if ("postgres".equals(db)) - { - dbCreateDAO = new BrowseCreateDAOPostgres(context); - } - else if ("oracle".equals(db)) - { - dbCreateDAO = new BrowseCreateDAOOracle(context); - } - else - { - throw new BrowseException( - "The configuration for db.name is either invalid, or contains an unrecognised database"); - } - - try - { - bis = BrowseIndex.getBrowseIndices(); - } - catch (BrowseException e) - { - log.error(e.getMessage(), e); - throw new IllegalStateException(e); - } - - for (BrowseIndex bi : bis) - bi.generateMdBits(); - } - - @Override - public void additionalIndex(Context context, DSpaceObject dso, SolrInputDocument doc) - { - if (!(dso instanceof Item)) - { - return; - } - Item item = (Item) dso; - - // faceting for metadata browsing. It is different than search facet - // because if there are authority with variants support we wan't all the - // variants to go in the facet... they are sorted by count so just the - // prefered label is relevant - for (BrowseIndex bi : bis) - { - log.debug("Indexing for item " + item.getID() + ", for index: " - + bi.getTableName()); - - if (bi.isMetadataIndex()) - { - // values to show in the browse list - Set distFValues = new HashSet(); - // value for lookup without authority - Set distFVal = new HashSet(); - // value for lookup with authority - Set distFAuths = new HashSet(); - // value for lookup when partial search (the item mapper tool use it) - Set distValuesForAC = new HashSet(); - - // now index the new details - but only if it's archived and not - // withdrawn - if (item.isArchived() || item.isWithdrawn()) - { - // get the metadata from the item - for (int mdIdx = 0; mdIdx < bi.getMetadataCount(); mdIdx++) - { - String[] md = bi.getMdBits(mdIdx); - DCValue[] values = item.getMetadata(md[0], md[1], - md[2], Item.ANY); - - // if we have values to index on, then do so - if (values != null && values.length > 0) - { - int minConfidence = MetadataAuthorityManager - .getManager().getMinConfidence( - values[0].schema, - values[0].element, - values[0].qualifier); - - boolean ignoreAuthority = new DSpace() - .getConfigurationService() - .getPropertyAsType( - "discovery.browse.authority.ignore." - + bi.getName(), - new DSpace() - .getConfigurationService() - .getPropertyAsType( - "discovery.browse.authority.ignore", - new Boolean(false)), - true); - for (int x = 0; x < values.length; x++) - { - // Ensure that there is a value to index before - // inserting it - if (StringUtils.isEmpty(values[x].value)) - { - log.error("Null metadata value for item " - + item.getID() - + ", field: " - + values[x].schema - + "." - + values[x].element - + (values[x].qualifier == null ? "" - : "." + values[x].qualifier)); - } - else - { - if (bi.isAuthorityIndex() - && (values[x].authority == null || values[x].confidence < minConfidence)) - { - // if we have an authority index only - // authored metadata will go here! - log.debug("Skipping item=" - + item.getID() + ", field=" - + values[x].schema + "." - + values[x].element + "." - + values[x].qualifier - + ", value=" + values[x].value - + ", authority=" - + values[x].authority - + ", confidence=" - + values[x].confidence - + " (BAD AUTHORITY)"); - continue; - } - - // is there any valid (with appropriate - // confidence) authority key? - if ((ignoreAuthority && !bi.isAuthorityIndex()) - || (values[x].authority != null && values[x].confidence >= minConfidence)) - { - distFAuths.add(values[x].authority); - distValuesForAC.add(values[x].value); - - String preferedLabel = null; - boolean ignorePrefered = new DSpace() - .getConfigurationService() - .getPropertyAsType( - "discovery.browse.authority.ignore-prefered." - + bi.getName(), - new DSpace() - .getConfigurationService() - .getPropertyAsType( - "discovery.browse.authority.ignore-prefered", - new Boolean( - false)), - true); - if (!ignorePrefered) - { - preferedLabel = ChoiceAuthorityManager - .getManager() - .getLabel( - values[x].schema, - values[x].element, - values[x].qualifier, - values[x].authority, - values[x].language); - } - List variants = null; - - boolean ignoreVariants = new DSpace() - .getConfigurationService() - .getPropertyAsType( - "discovery.browse.authority.ignore-variants." - + bi.getName(), - new DSpace() - .getConfigurationService() - .getPropertyAsType( - "discovery.browse.authority.ignore-variants", - new Boolean( - false)), - true); - if (!ignoreVariants) - { - variants = ChoiceAuthorityManager - .getManager() - .getVariants( - values[x].schema, - values[x].element, - values[x].qualifier, - values[x].authority, - values[x].language); - } - - if (StringUtils - .isNotBlank(preferedLabel)) - { - String nLabel = OrderFormat - .makeSortString( - preferedLabel, - values[x].language, - bi.getDataType()); - distFValues - .add(nLabel - + SolrServiceImpl.FILTER_SEPARATOR - + preferedLabel - + SolrServiceImpl.AUTHORITY_SEPARATOR - + values[x].authority); - distValuesForAC.add(preferedLabel); - } - - if (variants != null) - { - for (String var : variants) - { - String nVal = OrderFormat - .makeSortString( - var, - values[x].language, - bi.getDataType()); - distFValues - .add(nVal - + SolrServiceImpl.FILTER_SEPARATOR - + var - + SolrServiceImpl.AUTHORITY_SEPARATOR - + values[x].authority); - distValuesForAC.add(var); - } - } - } - else - // put it in the browse index as if it - // hasn't have an authority key - { - // get the normalised version of the - // value - String nVal = OrderFormat - .makeSortString( - values[x].value, - values[x].language, - bi.getDataType()); - distFValues - .add(nVal - + SolrServiceImpl.FILTER_SEPARATOR - + values[x].value); - distFVal.add(values[x].value); - distValuesForAC.add(values[x].value); - } - } - } - } - } - } - - for (String facet : distFValues) - { - doc.addField(bi.getDistinctTableName() + "_filter", facet); - } - for (String facet : distFAuths) - { - doc.addField(bi.getDistinctTableName() - + "_authority_filter", facet); - } - for (String facet : distValuesForAC) - { - doc.addField(bi.getDistinctTableName() + "_partial", facet); - } - for (String facet : distFVal) - { - doc.addField(bi.getDistinctTableName()+"_value_filter", facet); - } - } - } - - // Add sorting options as configurated for the browse system - try - { - for (SortOption so : SortOption.getSortOptions()) - { - DCValue[] dcvalue = item.getMetadata(so.getMetadata()); - if (dcvalue != null && dcvalue.length > 0) - { - String nValue = OrderFormat - .makeSortString(dcvalue[0].value, - dcvalue[0].language, so.getType()); - doc.addField("bi_sort_" + so.getNumber() + "_sort", nValue); - } - } - } - catch (SortException e) - { - // we can't solve it so rethrow as runtime exception - throw new RuntimeException(e.getMessage(), e); - } - } - - @Override - public void deleteByItemID(String table, int itemID) throws BrowseException - { - } - - @Override - public void deleteCommunityMappings(int itemID) throws BrowseException - { - } - - @Override - public void updateCommunityMappings(int itemID) throws BrowseException - { - } - - @Override - public void insertIndex(String table, int itemID, Map sortCols) - throws BrowseException - { - } - - @Override - public boolean updateIndex(String table, int itemID, Map sortCols) - throws BrowseException - { - return false; - } - - @Override - public int getDistinctID(String table, String value, String authority, - String sortValue) throws BrowseException - { - // TODO Auto-generated method stub - return 0; - } - - @Override - public int insertDistinctRecord(String table, String value, - String authority, String sortValue) throws BrowseException - { - // TODO Auto-generated method stub - return 0; - } - - @Override - public String dropIndexAndRelated(String table, boolean execute) - throws BrowseException - { - return dbCreateDAO.dropIndexAndRelated(table, execute); - } - - @Override - public String dropSequence(String sequence, boolean execute) - throws BrowseException - { - return dbCreateDAO.dropSequence(sequence, execute); - } - - @Override - public String dropView(String view, boolean execute) throws BrowseException - { - return dbCreateDAO.dropView(view, execute); - } - - @Override - public String createSequence(String sequence, boolean execute) - throws BrowseException - { - return INFO_NOSQL_TO_RUN; - } - - @Override - public String createPrimaryTable(String table, List sortCols, - boolean execute) throws BrowseException - { - return INFO_NOSQL_TO_RUN; - } - - @Override - public String[] createDatabaseIndices(String table, List sortCols, - boolean value, boolean execute) throws BrowseException - { - return new String[] { INFO_NOSQL_TO_RUN }; - } - - @Override - public String[] createMapIndices(String disTable, String mapTable, - boolean execute) throws BrowseException - { - return new String[] { INFO_NOSQL_TO_RUN }; - } - - @Override - public String createCollectionView(String table, String view, - boolean execute) throws BrowseException - { - return INFO_NOSQL_TO_RUN; - } - - @Override - public String createCommunityView(String table, String view, boolean execute) - throws BrowseException - { - return INFO_NOSQL_TO_RUN; - } - - @Override - public String createDistinctTable(String table, boolean execute) - throws BrowseException - { - return INFO_NOSQL_TO_RUN; - } - - @Override - public String createDistinctMap(String table, String map, boolean execute) - throws BrowseException - { - return INFO_NOSQL_TO_RUN; - } - - public MappingResults updateDistinctMappings(String table, int itemID, - Set distinctIDs) throws BrowseException - { - return new MappingResults() - { - - @Override - public List getRetainedDistinctIds() - { - return new ArrayList(); - } - - @Override - public List getRemovedDistinctIds() - { - return new ArrayList(); - } - - @Override - public List getAddedDistinctIds() - { - return new ArrayList(); - } - }; - } - - @Override - public boolean testTableExistence(String table) throws BrowseException - { - return dbCreateDAO.testTableExistence(table); - } - - @Override - public List deleteMappingsByItemID(String mapTable, int itemID) - throws BrowseException - { - return new ArrayList(); - } - - @Override - public void pruneExcess(String table, boolean withdrawn) - throws BrowseException - { - } - - @Override - public void pruneMapExcess(String map, boolean withdrawn, - List distinctIds) throws BrowseException - { - } - - @Override - public void pruneDistinct(String table, String map, - List distinctIds) throws BrowseException - { - } - -} +/** + * 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.browse; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.apache.solr.common.SolrInputDocument; +import org.dspace.content.DCValue; +import org.dspace.content.DSpaceObject; +import org.dspace.content.Item; +import org.dspace.content.authority.ChoiceAuthorityManager; +import org.dspace.content.authority.MetadataAuthorityManager; +import org.dspace.core.ConfigurationManager; +import org.dspace.core.Context; +import org.dspace.discovery.SolrServiceImpl; +import org.dspace.discovery.SolrServiceIndexPlugin; +import org.dspace.sort.OrderFormat; +import org.dspace.sort.SortException; +import org.dspace.sort.SortOption; +import org.dspace.utils.DSpace; + +/** + * + * @author Andrea Bollini (CILEA) + * + */ +public class SolrBrowseCreateDAO implements BrowseCreateDAO, + SolrServiceIndexPlugin +{ + private static final String INFO_NOSQL_TO_RUN = "No SQL to run: data are stored in the SOLR Search Core. PLEASE NOTE THAT YOU MUST UPDATE THE DISCOVERY INDEX AFTER ANY CHANGES TO THE BROWSE CONFIGURATION"; + + // reference to a DBMS BrowseCreateDAO needed to remove old tables when + // switching from DBMS to SOLR + private BrowseCreateDAO dbCreateDAO; + + private static final Logger log = Logger + .getLogger(SolrBrowseCreateDAO.class); + + private BrowseIndex[] bis; + + public SolrBrowseCreateDAO() + { + try + { + bis = BrowseIndex.getBrowseIndices(); + } + catch (BrowseException e) + { + log.error(e.getMessage(), e); + throw new IllegalStateException(e); + } + + for (BrowseIndex bi : bis) + bi.generateMdBits(); + } + + public SolrBrowseCreateDAO(Context context) throws BrowseException + { + // For compatibility with previous versions + String db = ConfigurationManager.getProperty("db.name"); + if ("postgres".equals(db)) + { + dbCreateDAO = new BrowseCreateDAOPostgres(context); + } + else if ("oracle".equals(db)) + { + dbCreateDAO = new BrowseCreateDAOOracle(context); + } + else + { + throw new BrowseException( + "The configuration for db.name is either invalid, or contains an unrecognised database"); + } + + try + { + bis = BrowseIndex.getBrowseIndices(); + } + catch (BrowseException e) + { + log.error(e.getMessage(), e); + throw new IllegalStateException(e); + } + + for (BrowseIndex bi : bis) + bi.generateMdBits(); + } + + @Override + public void additionalIndex(Context context, DSpaceObject dso, SolrInputDocument doc) + { + if (!(dso instanceof Item)) + { + return; + } + Item item = (Item) dso; + + // faceting for metadata browsing. It is different than search facet + // because if there are authority with variants support we wan't all the + // variants to go in the facet... they are sorted by count so just the + // prefered label is relevant + for (BrowseIndex bi : bis) + { + log.debug("Indexing for item " + item.getID() + ", for index: " + + bi.getTableName()); + + if (bi.isMetadataIndex()) + { + // values to show in the browse list + Set distFValues = new HashSet(); + // value for lookup without authority + Set distFVal = new HashSet(); + // value for lookup with authority + Set distFAuths = new HashSet(); + // value for lookup when partial search (the item mapper tool use it) + Set distValuesForAC = new HashSet(); + + // now index the new details - but only if it's archived and not + // withdrawn + if (item.isArchived() || item.isWithdrawn()) + { + // get the metadata from the item + for (int mdIdx = 0; mdIdx < bi.getMetadataCount(); mdIdx++) + { + String[] md = bi.getMdBits(mdIdx); + DCValue[] values = item.getMetadata(md[0], md[1], + md[2], Item.ANY); + + // if we have values to index on, then do so + if (values != null && values.length > 0) + { + int minConfidence = MetadataAuthorityManager + .getManager().getMinConfidence( + values[0].schema, + values[0].element, + values[0].qualifier); + + boolean ignoreAuthority = new DSpace() + .getConfigurationService() + .getPropertyAsType( + "discovery.browse.authority.ignore." + + bi.getName(), + new DSpace() + .getConfigurationService() + .getPropertyAsType( + "discovery.browse.authority.ignore", + new Boolean(false)), + true); + for (int x = 0; x < values.length; x++) + { + // Ensure that there is a value to index before + // inserting it + if (StringUtils.isEmpty(values[x].value)) + { + log.error("Null metadata value for item " + + item.getID() + + ", field: " + + values[x].schema + + "." + + values[x].element + + (values[x].qualifier == null ? "" + : "." + values[x].qualifier)); + } + else + { + if (bi.isAuthorityIndex() + && (values[x].authority == null || values[x].confidence < minConfidence)) + { + // if we have an authority index only + // authored metadata will go here! + log.debug("Skipping item=" + + item.getID() + ", field=" + + values[x].schema + "." + + values[x].element + "." + + values[x].qualifier + + ", value=" + values[x].value + + ", authority=" + + values[x].authority + + ", confidence=" + + values[x].confidence + + " (BAD AUTHORITY)"); + continue; + } + + // is there any valid (with appropriate + // confidence) authority key? + if ((ignoreAuthority && !bi.isAuthorityIndex()) + || (values[x].authority != null && values[x].confidence >= minConfidence)) + { + distFAuths.add(values[x].authority); + distValuesForAC.add(values[x].value); + + String preferedLabel = null; + boolean ignorePrefered = new DSpace() + .getConfigurationService() + .getPropertyAsType( + "discovery.browse.authority.ignore-prefered." + + bi.getName(), + new DSpace() + .getConfigurationService() + .getPropertyAsType( + "discovery.browse.authority.ignore-prefered", + new Boolean( + false)), + true); + if (!ignorePrefered) + { + preferedLabel = ChoiceAuthorityManager + .getManager() + .getLabel( + values[x].schema, + values[x].element, + values[x].qualifier, + values[x].authority, + values[x].language); + } + List variants = null; + + boolean ignoreVariants = new DSpace() + .getConfigurationService() + .getPropertyAsType( + "discovery.browse.authority.ignore-variants." + + bi.getName(), + new DSpace() + .getConfigurationService() + .getPropertyAsType( + "discovery.browse.authority.ignore-variants", + new Boolean( + false)), + true); + if (!ignoreVariants) + { + variants = ChoiceAuthorityManager + .getManager() + .getVariants( + values[x].schema, + values[x].element, + values[x].qualifier, + values[x].authority, + values[x].language); + } + + if (StringUtils + .isNotBlank(preferedLabel)) + { + String nLabel = OrderFormat + .makeSortString( + preferedLabel, + values[x].language, + bi.getDataType()); + distFValues + .add(nLabel + + SolrServiceImpl.FILTER_SEPARATOR + + preferedLabel + + SolrServiceImpl.AUTHORITY_SEPARATOR + + values[x].authority); + distValuesForAC.add(preferedLabel); + } + + if (variants != null) + { + for (String var : variants) + { + String nVal = OrderFormat + .makeSortString( + var, + values[x].language, + bi.getDataType()); + distFValues + .add(nVal + + SolrServiceImpl.FILTER_SEPARATOR + + var + + SolrServiceImpl.AUTHORITY_SEPARATOR + + values[x].authority); + distValuesForAC.add(var); + } + } + } + else + // put it in the browse index as if it + // hasn't have an authority key + { + // get the normalised version of the + // value + String nVal = OrderFormat + .makeSortString( + values[x].value, + values[x].language, + bi.getDataType()); + distFValues + .add(nVal + + SolrServiceImpl.FILTER_SEPARATOR + + values[x].value); + distFVal.add(values[x].value); + distValuesForAC.add(values[x].value); + } + } + } + } + } + } + + for (String facet : distFValues) + { + doc.addField(bi.getDistinctTableName() + "_filter", facet); + } + for (String facet : distFAuths) + { + doc.addField(bi.getDistinctTableName() + + "_authority_filter", facet); + } + for (String facet : distValuesForAC) + { + doc.addField(bi.getDistinctTableName() + "_partial", facet); + } + for (String facet : distFVal) + { + doc.addField(bi.getDistinctTableName()+"_value_filter", facet); + } + } + } + + // Add sorting options as configurated for the browse system + try + { + for (SortOption so : SortOption.getSortOptions()) + { + DCValue[] dcvalue = item.getMetadata(so.getMetadata()); + if (dcvalue != null && dcvalue.length > 0) + { + String nValue = OrderFormat + .makeSortString(dcvalue[0].value, + dcvalue[0].language, so.getType()); + doc.addField("bi_sort_" + so.getNumber() + "_sort", nValue); + } + } + } + catch (SortException e) + { + // we can't solve it so rethrow as runtime exception + throw new RuntimeException(e.getMessage(), e); + } + } + + @Override + public void deleteByItemID(String table, int itemID) throws BrowseException + { + } + + @Override + public void deleteCommunityMappings(int itemID) throws BrowseException + { + } + + @Override + public void updateCommunityMappings(int itemID) throws BrowseException + { + } + + @Override + public void insertIndex(String table, int itemID, Map sortCols) + throws BrowseException + { + } + + @Override + public boolean updateIndex(String table, int itemID, Map sortCols) + throws BrowseException + { + return false; + } + + @Override + public int getDistinctID(String table, String value, String authority, + String sortValue) throws BrowseException + { + // TODO Auto-generated method stub + return 0; + } + + @Override + public int insertDistinctRecord(String table, String value, + String authority, String sortValue) throws BrowseException + { + // TODO Auto-generated method stub + return 0; + } + + @Override + public String dropIndexAndRelated(String table, boolean execute) + throws BrowseException + { + return dbCreateDAO.dropIndexAndRelated(table, execute); + } + + @Override + public String dropSequence(String sequence, boolean execute) + throws BrowseException + { + return dbCreateDAO.dropSequence(sequence, execute); + } + + @Override + public String dropView(String view, boolean execute) throws BrowseException + { + return dbCreateDAO.dropView(view, execute); + } + + @Override + public String createSequence(String sequence, boolean execute) + throws BrowseException + { + return INFO_NOSQL_TO_RUN; + } + + @Override + public String createPrimaryTable(String table, List sortCols, + boolean execute) throws BrowseException + { + return INFO_NOSQL_TO_RUN; + } + + @Override + public String[] createDatabaseIndices(String table, List sortCols, + boolean value, boolean execute) throws BrowseException + { + return new String[] { INFO_NOSQL_TO_RUN }; + } + + @Override + public String[] createMapIndices(String disTable, String mapTable, + boolean execute) throws BrowseException + { + return new String[] { INFO_NOSQL_TO_RUN }; + } + + @Override + public String createCollectionView(String table, String view, + boolean execute) throws BrowseException + { + return INFO_NOSQL_TO_RUN; + } + + @Override + public String createCommunityView(String table, String view, boolean execute) + throws BrowseException + { + return INFO_NOSQL_TO_RUN; + } + + @Override + public String createDistinctTable(String table, boolean execute) + throws BrowseException + { + return INFO_NOSQL_TO_RUN; + } + + @Override + public String createDistinctMap(String table, String map, boolean execute) + throws BrowseException + { + return INFO_NOSQL_TO_RUN; + } + + public MappingResults updateDistinctMappings(String table, int itemID, + Set distinctIDs) throws BrowseException + { + return new MappingResults() + { + + @Override + public List getRetainedDistinctIds() + { + return new ArrayList(); + } + + @Override + public List getRemovedDistinctIds() + { + return new ArrayList(); + } + + @Override + public List getAddedDistinctIds() + { + return new ArrayList(); + } + }; + } + + @Override + public boolean testTableExistence(String table) throws BrowseException + { + return dbCreateDAO.testTableExistence(table); + } + + @Override + public List deleteMappingsByItemID(String mapTable, int itemID) + throws BrowseException + { + return new ArrayList(); + } + + @Override + public void pruneExcess(String table, boolean withdrawn) + throws BrowseException + { + } + + @Override + public void pruneMapExcess(String map, boolean withdrawn, + List distinctIds) throws BrowseException + { + } + + @Override + public void pruneDistinct(String table, String map, + List distinctIds) throws BrowseException + { + } + +} diff --git a/dspace-discovery/dspace-discovery-solr/src/main/java/org/dspace/browse/SolrBrowseDAO.java b/dspace-api/src/main/java/org/dspace/browse/SolrBrowseDAO.java similarity index 96% rename from dspace-discovery/dspace-discovery-solr/src/main/java/org/dspace/browse/SolrBrowseDAO.java rename to dspace-api/src/main/java/org/dspace/browse/SolrBrowseDAO.java index b120c2de3d..6cdf9410b7 100644 --- a/dspace-discovery/dspace-discovery-solr/src/main/java/org/dspace/browse/SolrBrowseDAO.java +++ b/dspace-api/src/main/java/org/dspace/browse/SolrBrowseDAO.java @@ -1,759 +1,759 @@ -/** - * 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.browse; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; -import java.util.List; - -import org.apache.log4j.Logger; -import org.dspace.content.DSpaceObject; -import org.dspace.content.Item; -import org.dspace.core.Constants; -import org.dspace.core.Context; -import org.dspace.discovery.DiscoverFacetField; -import org.dspace.discovery.DiscoverQuery; -import org.dspace.discovery.DiscoverQuery.SORT_ORDER; -import org.dspace.discovery.DiscoverResult; -import org.dspace.discovery.DiscoverResult.FacetResult; -import org.dspace.discovery.DiscoverResult.SearchDocument; -import org.dspace.discovery.SearchService; -import org.dspace.discovery.SearchServiceException; -import org.dspace.discovery.configuration.DiscoveryConfigurationParameters; -import org.dspace.utils.DSpace; - -/** - * - * @author Andrea Bollini (CILEA) - * - */ -public class SolrBrowseDAO implements BrowseDAO -{ - public SolrBrowseDAO(Context context) - { - this.context = context; - } - - static private class FacetValueComparator implements Comparator - { - @Override - public int compare(Object o1, Object o2) - { - String s1 = "", s2 = ""; - if (o1 instanceof FacetResult && o2 instanceof String) - { - FacetResult c = (FacetResult) o1; - s1 = c.getSortValue(); - s2 = (String) o2; - } - else if (o2 instanceof FacetResult && o1 instanceof String) - { - FacetResult c = (FacetResult) o2; - s1 = (String) o1; - s2 = c.getSortValue(); - } - // both object are FacetResult so they are already sorted - return s1.compareTo(s2); - } - } - - /** Log4j log */ - private static Logger log = Logger.getLogger(SolrBrowseDAO.class); - - /** The DSpace context */ - private Context context; - - // SQL query related attributes for this class - - /** table(s) to select from */ - private String table = null; - - /** field to look for focus value in */ - private String focusField = null; - - /** value to start browse from in focus field */ - private String focusValue = null; - - /** field to look for value in */ - private String valueField = null; - - /** value to restrict browse to (e.g. author name) */ - private String value = null; - - private String authority = null; - - /** exact or partial matching of the value */ - private boolean valuePartial = false; - - /** the table that defines the mapping for the relevant container */ - private String containerTable = null; - - /** - * the name of the field which contains the container id (e.g. - * collection_id) - */ - private String containerIDField = null; - - /** the database id of the container we are constraining to */ - private int containerID = -1; - - /** the column that we are sorting results by */ - private String orderField = null; - - /** whether to sort results ascending or descending */ - private boolean ascending = true; - - /** the limit of number of results to return */ - private int limit = -1; - - /** the offset of the start point */ - private int offset = 0; - - /** whether to use the equals comparator in value comparisons */ - private boolean equalsComparator = true; - - /** whether this is a distinct browse or not */ - private boolean distinct = false; - - private String facetField; - - // administrative attributes for this class - - DSpace dspace = new DSpace(); - - SearchService searcher = dspace.getServiceManager().getServiceByName( - SearchService.class.getName(), SearchService.class); - - private DiscoverResult sResponse = null; - - private boolean itemsWithdrawn = false; - private boolean itemsPrivate = false; - - private boolean showFrequencies; - - private DiscoverResult getSolrResponse() throws BrowseException - { - if (sResponse == null) - { - DiscoverQuery query = new DiscoverQuery(); - addLocationScopeFilter(query); - addStatusFilter(query); - if (distinct) - { - DiscoverFacetField dff = new DiscoverFacetField(facetField, - DiscoveryConfigurationParameters.TYPE_TEXT, -1, - DiscoveryConfigurationParameters.SORT.VALUE); - query.addFacetField(dff); - query.setFacetMinCount(1); - query.setMaxResults(0); - } - else - { - query.setMaxResults(limit > 0 ? limit : 20); - if (offset > 0) - { - query.setStart(offset); - } - - // caution check first authority, value is always present! - if (authority != null) - { - query.addFilterQueries("{!field f="+facetField + "_authority_filter}" - + authority); - } - else if (value != null && !valuePartial) - { - query.addFilterQueries("{!field f="+facetField + "_value_filter}" + value); - } - else if (valuePartial) - { - query.addFilterQueries("{!field f="+facetField + "_partial}" + value); - } - // filter on item to be sure to don't include any other object - // indexed in the Discovery Search core - query.addFilterQueries("search.resourcetype:" + Constants.ITEM); - if (orderField != null) - { - query.setSortField("bi_" + orderField + "_sort", - ascending ? SORT_ORDER.asc : SORT_ORDER.desc); - } - } - try - { - sResponse = searcher.search(context, query, itemsWithdrawn); - } - catch (SearchServiceException e) - { - throw new BrowseException(e); - } - } - return sResponse; - } - - private void addStatusFilter(DiscoverQuery query) - { - if (itemsWithdrawn) - { - query.addFilterQueries("withdrawn:true"); - if (itemsPrivate) - { - query.addFilterQueries("discoverable:false"); - } - else - { - query.addFilterQueries("NOT(discoverable:false)"); - } - } - else - { - query.addFilterQueries("NOT(withdrawn:true)"); - } - } - - private void addLocationScopeFilter(DiscoverQuery query) - { - if (containerID > 0) - { - if (containerIDField.startsWith("collection")) - { - query.addFilterQueries("location.coll:" + containerID); - } - else if (containerIDField.startsWith("community")) - { - query.addFilterQueries("location.comm:" + containerID); - } - } - } - - @Override - public int doCountQuery() throws BrowseException - { - DiscoverResult resp = getSolrResponse(); - int count = 0; - if (distinct) - { - List facetResults = resp.getFacetResult(facetField); - count = facetResults.size(); - } - else - { - // we need to cast to int to respect the BrowseDAO contract... - count = (int) resp.getTotalSearchResults(); - // FIXME null the response cache - // the BrowseEngine send fake argument to the BrowseDAO for the - // count... - sResponse = null; - } - return count; - } - - @Override - public List doValueQuery() throws BrowseException - { - DiscoverResult resp = getSolrResponse(); - List facet = resp.getFacetResult(facetField); - int count = doCountQuery(); - int start = offset > 0 ? offset : 0; - int max = limit > 0 ? limit : 20; - List result = new ArrayList(); - if (ascending) - { - for (int i = start; i < (start + max) && i < count; i++) - { - FacetResult c = facet.get(i); - String freq = showFrequencies ? String.valueOf(c.getCount()) - : ""; - result.add(new String[] { c.getDisplayedValue(), - c.getAuthorityKey(), freq }); - } - } - else - { - for (int i = count - start - 1; i >= count - (start + max) - && i >= 0; i--) - { - FacetResult c = facet.get(i); - String freq = showFrequencies ? String.valueOf(c.getCount()) - : ""; - result.add(new String[] { c.getDisplayedValue(), - c.getAuthorityKey(), freq }); - } - } - - return result; - } - - @Override - public List doQuery() throws BrowseException - { - DiscoverResult resp = getSolrResponse(); - - List bitems = new ArrayList(); - for (DSpaceObject solrDoc : resp.getDspaceObjects()) - { - // FIXME introduce project, don't retrieve Item immediately when - // processing the query... - Item item = (Item) solrDoc; - BrowseItem bitem = new BrowseItem(context, item.getID(), - item.isArchived(), item.isWithdrawn()); - bitems.add(bitem); - } - return bitems; - } - - @Override - public String doMaxQuery(String column, String table, int itemID) - throws BrowseException - { - DiscoverQuery query = new DiscoverQuery(); - query.setQuery("search.resourceid:" + itemID - + " AND search.resourcetype:" + Constants.ITEM); - query.setMaxResults(1); - DiscoverResult resp = null; - try - { - resp = searcher.search(context, query); - } - catch (SearchServiceException e) - { - throw new BrowseException(e); - } - if (resp.getTotalSearchResults() > 0) - { - SearchDocument doc = resp.getSearchDocument( - resp.getDspaceObjects().get(0)).get(0); - return (String) doc.getSearchFieldValues(column).get(0); - } - return null; - } - - @Override - public int doOffsetQuery(String column, String value, boolean isAscending) - throws BrowseException - { - DiscoverQuery query = new DiscoverQuery(); - addLocationScopeFilter(query); - addStatusFilter(query); - query.setMaxResults(0); - query.addFilterQueries("search.resourcetype:" + Constants.ITEM); - if (isAscending) - { - query.setQuery("bi_"+column + "_sort" + ": [* TO \"" + value + "\"]"); - } - else - { - query.setQuery("bi_" + column + "_sort" + ": [\"" + value + "\" TO *]"); - } - DiscoverResult resp = null; - try - { - resp = searcher.search(context, query); - } - catch (SearchServiceException e) - { - throw new BrowseException(e); - } - return (int) resp.getTotalSearchResults(); - } - - @Override - public int doDistinctOffsetQuery(String column, String value, - boolean isAscending) throws BrowseException - { - DiscoverResult resp = getSolrResponse(); - List facets = resp.getFacetResult(facetField); - Comparator comparator = new SolrBrowseDAO.FacetValueComparator(); - Collections.sort(facets, comparator); - int x = Collections.binarySearch(facets, value, comparator); - int ascValue = (x >= 0) ? x : -(x + 1); - if (isAscending) - { - return ascValue; - } - else - { - return doCountQuery() - ascValue; - } - } - - @Override - public boolean isEnableBrowseFrequencies() - { - return showFrequencies; - } - - @Override - public void setEnableBrowseFrequencies(boolean enableBrowseFrequencies) - { - showFrequencies = enableBrowseFrequencies; - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#getContainerID() - */ - public int getContainerID() - { - return containerID; - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#getContainerIDField() - */ - public String getContainerIDField() - { - return containerIDField; - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#getContainerTable() - */ - public String getContainerTable() - { - return containerTable; - } - - // FIXME is this in use? - public String[] getCountValues() - { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#getFocusField() - */ - public String getJumpToField() - { - return focusField; - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#getFocusValue() - */ - public String getJumpToValue() - { - return focusValue; - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#getLimit() - */ - public int getLimit() - { - return limit; - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#getOffset() - */ - public int getOffset() - { - return offset; - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#getOrderField() - */ - public String getOrderField() - { - return orderField; - } - - // is this in use? - public String[] getSelectValues() - { - return null; - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#getTable() - */ - public String getTable() - { - return table; - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#getValue() - */ - public String getFilterValue() - { - return value; - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#getValueField() - */ - public String getFilterValueField() - { - return valueField; - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#isAscending() - */ - public boolean isAscending() - { - return ascending; - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#isDistinct() - */ - public boolean isDistinct() - { - return this.distinct; - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#setAscending(boolean) - */ - public void setAscending(boolean ascending) - { - this.ascending = ascending; - - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#setContainerID(int) - */ - public void setContainerID(int containerID) - { - this.containerID = containerID; - - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#setContainerIDField(java.lang.String) - */ - public void setContainerIDField(String containerIDField) - { - this.containerIDField = containerIDField; - - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#setContainerTable(java.lang.String) - */ - public void setContainerTable(String containerTable) - { - this.containerTable = containerTable; - - } - - // is this in use? - public void setCountValues(String[] fields) - { - // this.countValues = fields; - - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#setDistinct(boolean) - */ - public void setDistinct(boolean bool) - { - this.distinct = bool; - - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#setEqualsComparator(boolean) - */ - public void setEqualsComparator(boolean equalsComparator) - { - this.equalsComparator = equalsComparator; - - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#setFocusField(java.lang.String) - */ - public void setJumpToField(String focusField) - { - this.focusField = focusField; - - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#setFocusValue(java.lang.String) - */ - public void setJumpToValue(String focusValue) - { - this.focusValue = focusValue; - - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#setLimit(int) - */ - public void setLimit(int limit) - { - this.limit = limit; - - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#setOffset(int) - */ - public void setOffset(int offset) - { - this.offset = offset; - - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#setOrderField(java.lang.String) - */ - public void setOrderField(String orderField) - { - this.orderField = orderField; - - } - - // is this in use? - public void setSelectValues(String[] selectValues) - { - // this.selectValues = selectValues; - - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#setTable(java.lang.String) - */ - public void setTable(String table) - { - if (table.equals(BrowseIndex.getWithdrawnBrowseIndex().getTableName())) - { - itemsWithdrawn = true; - itemsPrivate = false; - } - else if (table.equals(BrowseIndex.getPrivateBrowseIndex().getTableName())) - { - itemsPrivate = true; - // items private are also withdrawn - itemsWithdrawn = true; - } - facetField = table; - } - - public void setFilterMappingTables(String tableDis, String tableMap) - { - if (tableDis != null) - { - this.facetField = tableDis; - } - // this.fields = tableDis; - // this.tableMap = tableMap; - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#setValue(java.lang.String) - */ - public void setFilterValue(String value) - { - this.value = value; - - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#setFilterValuePartial(boolean) - */ - public void setFilterValuePartial(boolean part) - { - this.valuePartial = part; - - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#setValueField(java.lang.String) - */ - public void setFilterValueField(String valueField) - { - this.valueField = valueField; - - } - - /* - * (non-Javadoc) - * - * @see org.dspace.browse.BrowseDAO#useEqualsComparator() - */ - public boolean useEqualsComparator() - { - return equalsComparator; - } - - @Override - public String getAuthorityValue() - { - return authority; - } - - @Override - public void setAuthorityValue(String value) - { - this.authority = value; - } -} +/** + * 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.browse; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; + +import org.apache.log4j.Logger; +import org.dspace.content.DSpaceObject; +import org.dspace.content.Item; +import org.dspace.core.Constants; +import org.dspace.core.Context; +import org.dspace.discovery.DiscoverFacetField; +import org.dspace.discovery.DiscoverQuery; +import org.dspace.discovery.DiscoverQuery.SORT_ORDER; +import org.dspace.discovery.DiscoverResult; +import org.dspace.discovery.DiscoverResult.FacetResult; +import org.dspace.discovery.DiscoverResult.SearchDocument; +import org.dspace.discovery.SearchService; +import org.dspace.discovery.SearchServiceException; +import org.dspace.discovery.configuration.DiscoveryConfigurationParameters; +import org.dspace.utils.DSpace; + +/** + * + * @author Andrea Bollini (CILEA) + * + */ +public class SolrBrowseDAO implements BrowseDAO +{ + public SolrBrowseDAO(Context context) + { + this.context = context; + } + + static private class FacetValueComparator implements Comparator + { + @Override + public int compare(Object o1, Object o2) + { + String s1 = "", s2 = ""; + if (o1 instanceof FacetResult && o2 instanceof String) + { + FacetResult c = (FacetResult) o1; + s1 = c.getSortValue(); + s2 = (String) o2; + } + else if (o2 instanceof FacetResult && o1 instanceof String) + { + FacetResult c = (FacetResult) o2; + s1 = (String) o1; + s2 = c.getSortValue(); + } + // both object are FacetResult so they are already sorted + return s1.compareTo(s2); + } + } + + /** Log4j log */ + private static Logger log = Logger.getLogger(SolrBrowseDAO.class); + + /** The DSpace context */ + private Context context; + + // SQL query related attributes for this class + + /** table(s) to select from */ + private String table = null; + + /** field to look for focus value in */ + private String focusField = null; + + /** value to start browse from in focus field */ + private String focusValue = null; + + /** field to look for value in */ + private String valueField = null; + + /** value to restrict browse to (e.g. author name) */ + private String value = null; + + private String authority = null; + + /** exact or partial matching of the value */ + private boolean valuePartial = false; + + /** the table that defines the mapping for the relevant container */ + private String containerTable = null; + + /** + * the name of the field which contains the container id (e.g. + * collection_id) + */ + private String containerIDField = null; + + /** the database id of the container we are constraining to */ + private int containerID = -1; + + /** the column that we are sorting results by */ + private String orderField = null; + + /** whether to sort results ascending or descending */ + private boolean ascending = true; + + /** the limit of number of results to return */ + private int limit = -1; + + /** the offset of the start point */ + private int offset = 0; + + /** whether to use the equals comparator in value comparisons */ + private boolean equalsComparator = true; + + /** whether this is a distinct browse or not */ + private boolean distinct = false; + + private String facetField; + + // administrative attributes for this class + + DSpace dspace = new DSpace(); + + SearchService searcher = dspace.getServiceManager().getServiceByName( + SearchService.class.getName(), SearchService.class); + + private DiscoverResult sResponse = null; + + private boolean itemsWithdrawn = false; + private boolean itemsPrivate = false; + + private boolean showFrequencies; + + private DiscoverResult getSolrResponse() throws BrowseException + { + if (sResponse == null) + { + DiscoverQuery query = new DiscoverQuery(); + addLocationScopeFilter(query); + addStatusFilter(query); + if (distinct) + { + DiscoverFacetField dff = new DiscoverFacetField(facetField, + DiscoveryConfigurationParameters.TYPE_TEXT, -1, + DiscoveryConfigurationParameters.SORT.VALUE); + query.addFacetField(dff); + query.setFacetMinCount(1); + query.setMaxResults(0); + } + else + { + query.setMaxResults(limit > 0 ? limit : 20); + if (offset > 0) + { + query.setStart(offset); + } + + // caution check first authority, value is always present! + if (authority != null) + { + query.addFilterQueries("{!field f="+facetField + "_authority_filter}" + + authority); + } + else if (value != null && !valuePartial) + { + query.addFilterQueries("{!field f="+facetField + "_value_filter}" + value); + } + else if (valuePartial) + { + query.addFilterQueries("{!field f="+facetField + "_partial}" + value); + } + // filter on item to be sure to don't include any other object + // indexed in the Discovery Search core + query.addFilterQueries("search.resourcetype:" + Constants.ITEM); + if (orderField != null) + { + query.setSortField("bi_" + orderField + "_sort", + ascending ? SORT_ORDER.asc : SORT_ORDER.desc); + } + } + try + { + sResponse = searcher.search(context, query, itemsWithdrawn); + } + catch (SearchServiceException e) + { + throw new BrowseException(e); + } + } + return sResponse; + } + + private void addStatusFilter(DiscoverQuery query) + { + if (itemsWithdrawn) + { + query.addFilterQueries("withdrawn:true"); + if (itemsPrivate) + { + query.addFilterQueries("discoverable:false"); + } + else + { + query.addFilterQueries("NOT(discoverable:false)"); + } + } + else + { + query.addFilterQueries("NOT(withdrawn:true)"); + } + } + + private void addLocationScopeFilter(DiscoverQuery query) + { + if (containerID > 0) + { + if (containerIDField.startsWith("collection")) + { + query.addFilterQueries("location.coll:" + containerID); + } + else if (containerIDField.startsWith("community")) + { + query.addFilterQueries("location.comm:" + containerID); + } + } + } + + @Override + public int doCountQuery() throws BrowseException + { + DiscoverResult resp = getSolrResponse(); + int count = 0; + if (distinct) + { + List facetResults = resp.getFacetResult(facetField); + count = facetResults.size(); + } + else + { + // we need to cast to int to respect the BrowseDAO contract... + count = (int) resp.getTotalSearchResults(); + // FIXME null the response cache + // the BrowseEngine send fake argument to the BrowseDAO for the + // count... + sResponse = null; + } + return count; + } + + @Override + public List doValueQuery() throws BrowseException + { + DiscoverResult resp = getSolrResponse(); + List facet = resp.getFacetResult(facetField); + int count = doCountQuery(); + int start = offset > 0 ? offset : 0; + int max = limit > 0 ? limit : 20; + List result = new ArrayList(); + if (ascending) + { + for (int i = start; i < (start + max) && i < count; i++) + { + FacetResult c = facet.get(i); + String freq = showFrequencies ? String.valueOf(c.getCount()) + : ""; + result.add(new String[] { c.getDisplayedValue(), + c.getAuthorityKey(), freq }); + } + } + else + { + for (int i = count - start - 1; i >= count - (start + max) + && i >= 0; i--) + { + FacetResult c = facet.get(i); + String freq = showFrequencies ? String.valueOf(c.getCount()) + : ""; + result.add(new String[] { c.getDisplayedValue(), + c.getAuthorityKey(), freq }); + } + } + + return result; + } + + @Override + public List doQuery() throws BrowseException + { + DiscoverResult resp = getSolrResponse(); + + List bitems = new ArrayList(); + for (DSpaceObject solrDoc : resp.getDspaceObjects()) + { + // FIXME introduce project, don't retrieve Item immediately when + // processing the query... + Item item = (Item) solrDoc; + BrowseItem bitem = new BrowseItem(context, item.getID(), + item.isArchived(), item.isWithdrawn()); + bitems.add(bitem); + } + return bitems; + } + + @Override + public String doMaxQuery(String column, String table, int itemID) + throws BrowseException + { + DiscoverQuery query = new DiscoverQuery(); + query.setQuery("search.resourceid:" + itemID + + " AND search.resourcetype:" + Constants.ITEM); + query.setMaxResults(1); + DiscoverResult resp = null; + try + { + resp = searcher.search(context, query); + } + catch (SearchServiceException e) + { + throw new BrowseException(e); + } + if (resp.getTotalSearchResults() > 0) + { + SearchDocument doc = resp.getSearchDocument( + resp.getDspaceObjects().get(0)).get(0); + return (String) doc.getSearchFieldValues(column).get(0); + } + return null; + } + + @Override + public int doOffsetQuery(String column, String value, boolean isAscending) + throws BrowseException + { + DiscoverQuery query = new DiscoverQuery(); + addLocationScopeFilter(query); + addStatusFilter(query); + query.setMaxResults(0); + query.addFilterQueries("search.resourcetype:" + Constants.ITEM); + if (isAscending) + { + query.setQuery("bi_"+column + "_sort" + ": [* TO \"" + value + "\"]"); + } + else + { + query.setQuery("bi_" + column + "_sort" + ": [\"" + value + "\" TO *]"); + } + DiscoverResult resp = null; + try + { + resp = searcher.search(context, query); + } + catch (SearchServiceException e) + { + throw new BrowseException(e); + } + return (int) resp.getTotalSearchResults(); + } + + @Override + public int doDistinctOffsetQuery(String column, String value, + boolean isAscending) throws BrowseException + { + DiscoverResult resp = getSolrResponse(); + List facets = resp.getFacetResult(facetField); + Comparator comparator = new SolrBrowseDAO.FacetValueComparator(); + Collections.sort(facets, comparator); + int x = Collections.binarySearch(facets, value, comparator); + int ascValue = (x >= 0) ? x : -(x + 1); + if (isAscending) + { + return ascValue; + } + else + { + return doCountQuery() - ascValue; + } + } + + @Override + public boolean isEnableBrowseFrequencies() + { + return showFrequencies; + } + + @Override + public void setEnableBrowseFrequencies(boolean enableBrowseFrequencies) + { + showFrequencies = enableBrowseFrequencies; + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#getContainerID() + */ + public int getContainerID() + { + return containerID; + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#getContainerIDField() + */ + public String getContainerIDField() + { + return containerIDField; + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#getContainerTable() + */ + public String getContainerTable() + { + return containerTable; + } + + // FIXME is this in use? + public String[] getCountValues() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#getFocusField() + */ + public String getJumpToField() + { + return focusField; + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#getFocusValue() + */ + public String getJumpToValue() + { + return focusValue; + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#getLimit() + */ + public int getLimit() + { + return limit; + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#getOffset() + */ + public int getOffset() + { + return offset; + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#getOrderField() + */ + public String getOrderField() + { + return orderField; + } + + // is this in use? + public String[] getSelectValues() + { + return null; + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#getTable() + */ + public String getTable() + { + return table; + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#getValue() + */ + public String getFilterValue() + { + return value; + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#getValueField() + */ + public String getFilterValueField() + { + return valueField; + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#isAscending() + */ + public boolean isAscending() + { + return ascending; + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#isDistinct() + */ + public boolean isDistinct() + { + return this.distinct; + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#setAscending(boolean) + */ + public void setAscending(boolean ascending) + { + this.ascending = ascending; + + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#setContainerID(int) + */ + public void setContainerID(int containerID) + { + this.containerID = containerID; + + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#setContainerIDField(java.lang.String) + */ + public void setContainerIDField(String containerIDField) + { + this.containerIDField = containerIDField; + + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#setContainerTable(java.lang.String) + */ + public void setContainerTable(String containerTable) + { + this.containerTable = containerTable; + + } + + // is this in use? + public void setCountValues(String[] fields) + { + // this.countValues = fields; + + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#setDistinct(boolean) + */ + public void setDistinct(boolean bool) + { + this.distinct = bool; + + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#setEqualsComparator(boolean) + */ + public void setEqualsComparator(boolean equalsComparator) + { + this.equalsComparator = equalsComparator; + + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#setFocusField(java.lang.String) + */ + public void setJumpToField(String focusField) + { + this.focusField = focusField; + + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#setFocusValue(java.lang.String) + */ + public void setJumpToValue(String focusValue) + { + this.focusValue = focusValue; + + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#setLimit(int) + */ + public void setLimit(int limit) + { + this.limit = limit; + + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#setOffset(int) + */ + public void setOffset(int offset) + { + this.offset = offset; + + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#setOrderField(java.lang.String) + */ + public void setOrderField(String orderField) + { + this.orderField = orderField; + + } + + // is this in use? + public void setSelectValues(String[] selectValues) + { + // this.selectValues = selectValues; + + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#setTable(java.lang.String) + */ + public void setTable(String table) + { + if (table.equals(BrowseIndex.getWithdrawnBrowseIndex().getTableName())) + { + itemsWithdrawn = true; + itemsPrivate = false; + } + else if (table.equals(BrowseIndex.getPrivateBrowseIndex().getTableName())) + { + itemsPrivate = true; + // items private are also withdrawn + itemsWithdrawn = true; + } + facetField = table; + } + + public void setFilterMappingTables(String tableDis, String tableMap) + { + if (tableDis != null) + { + this.facetField = tableDis; + } + // this.fields = tableDis; + // this.tableMap = tableMap; + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#setValue(java.lang.String) + */ + public void setFilterValue(String value) + { + this.value = value; + + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#setFilterValuePartial(boolean) + */ + public void setFilterValuePartial(boolean part) + { + this.valuePartial = part; + + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#setValueField(java.lang.String) + */ + public void setFilterValueField(String valueField) + { + this.valueField = valueField; + + } + + /* + * (non-Javadoc) + * + * @see org.dspace.browse.BrowseDAO#useEqualsComparator() + */ + public boolean useEqualsComparator() + { + return equalsComparator; + } + + @Override + public String getAuthorityValue() + { + return authority; + } + + @Override + public void setAuthorityValue(String value) + { + this.authority = value; + } +} diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/DiscoverFacetField.java b/dspace-api/src/main/java/org/dspace/discovery/DiscoverFacetField.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/DiscoverFacetField.java rename to dspace-api/src/main/java/org/dspace/discovery/DiscoverFacetField.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/DiscoverFilterQuery.java b/dspace-api/src/main/java/org/dspace/discovery/DiscoverFilterQuery.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/DiscoverFilterQuery.java rename to dspace-api/src/main/java/org/dspace/discovery/DiscoverFilterQuery.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/DiscoverHitHighlightingField.java b/dspace-api/src/main/java/org/dspace/discovery/DiscoverHitHighlightingField.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/DiscoverHitHighlightingField.java rename to dspace-api/src/main/java/org/dspace/discovery/DiscoverHitHighlightingField.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/DiscoverQuery.java b/dspace-api/src/main/java/org/dspace/discovery/DiscoverQuery.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/DiscoverQuery.java rename to dspace-api/src/main/java/org/dspace/discovery/DiscoverQuery.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/DiscoverResult.java b/dspace-api/src/main/java/org/dspace/discovery/DiscoverResult.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/DiscoverResult.java rename to dspace-api/src/main/java/org/dspace/discovery/DiscoverResult.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/IndexClient.java b/dspace-api/src/main/java/org/dspace/discovery/IndexClient.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/IndexClient.java rename to dspace-api/src/main/java/org/dspace/discovery/IndexClient.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/IndexEventConsumer.java b/dspace-api/src/main/java/org/dspace/discovery/IndexEventConsumer.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/IndexEventConsumer.java rename to dspace-api/src/main/java/org/dspace/discovery/IndexEventConsumer.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/IndexingService.java b/dspace-api/src/main/java/org/dspace/discovery/IndexingService.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/IndexingService.java rename to dspace-api/src/main/java/org/dspace/discovery/IndexingService.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/SearchService.java b/dspace-api/src/main/java/org/dspace/discovery/SearchService.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/SearchService.java rename to dspace-api/src/main/java/org/dspace/discovery/SearchService.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/SearchServiceException.java b/dspace-api/src/main/java/org/dspace/discovery/SearchServiceException.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/SearchServiceException.java rename to dspace-api/src/main/java/org/dspace/discovery/SearchServiceException.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/SearchUtils.java b/dspace-api/src/main/java/org/dspace/discovery/SearchUtils.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/SearchUtils.java rename to dspace-api/src/main/java/org/dspace/discovery/SearchUtils.java diff --git a/dspace-discovery/dspace-discovery-solr/src/main/java/org/dspace/discovery/SolrServiceImpl.java b/dspace-api/src/main/java/org/dspace/discovery/SolrServiceImpl.java similarity index 100% rename from dspace-discovery/dspace-discovery-solr/src/main/java/org/dspace/discovery/SolrServiceImpl.java rename to dspace-api/src/main/java/org/dspace/discovery/SolrServiceImpl.java diff --git a/dspace-discovery/dspace-discovery-solr/src/main/java/org/dspace/discovery/SolrServiceIndexOutputPlugin.java b/dspace-api/src/main/java/org/dspace/discovery/SolrServiceIndexOutputPlugin.java similarity index 100% rename from dspace-discovery/dspace-discovery-solr/src/main/java/org/dspace/discovery/SolrServiceIndexOutputPlugin.java rename to dspace-api/src/main/java/org/dspace/discovery/SolrServiceIndexOutputPlugin.java diff --git a/dspace-discovery/dspace-discovery-solr/src/main/java/org/dspace/discovery/SolrServiceIndexPlugin.java b/dspace-api/src/main/java/org/dspace/discovery/SolrServiceIndexPlugin.java similarity index 100% rename from dspace-discovery/dspace-discovery-solr/src/main/java/org/dspace/discovery/SolrServiceIndexPlugin.java rename to dspace-api/src/main/java/org/dspace/discovery/SolrServiceIndexPlugin.java diff --git a/dspace-discovery/dspace-discovery-solr/src/main/java/org/dspace/discovery/SolrServiceResourceRestrictionPlugin.java b/dspace-api/src/main/java/org/dspace/discovery/SolrServiceResourceRestrictionPlugin.java similarity index 100% rename from dspace-discovery/dspace-discovery-solr/src/main/java/org/dspace/discovery/SolrServiceResourceRestrictionPlugin.java rename to dspace-api/src/main/java/org/dspace/discovery/SolrServiceResourceRestrictionPlugin.java diff --git a/dspace-discovery/dspace-discovery-solr/src/main/java/org/dspace/discovery/SolrServiceSearchPlugin.java b/dspace-api/src/main/java/org/dspace/discovery/SolrServiceSearchPlugin.java similarity index 100% rename from dspace-discovery/dspace-discovery-solr/src/main/java/org/dspace/discovery/SolrServiceSearchPlugin.java rename to dspace-api/src/main/java/org/dspace/discovery/SolrServiceSearchPlugin.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoveryConfiguration.java b/dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoveryConfiguration.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoveryConfiguration.java rename to dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoveryConfiguration.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoveryConfigurationException.java b/dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoveryConfigurationException.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoveryConfigurationException.java rename to dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoveryConfigurationException.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoveryConfigurationParameters.java b/dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoveryConfigurationParameters.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoveryConfigurationParameters.java rename to dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoveryConfigurationParameters.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoveryConfigurationService.java b/dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoveryConfigurationService.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoveryConfigurationService.java rename to dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoveryConfigurationService.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoveryHitHighlightFieldConfiguration.java b/dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoveryHitHighlightFieldConfiguration.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoveryHitHighlightFieldConfiguration.java rename to dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoveryHitHighlightFieldConfiguration.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoveryHitHighlightingConfiguration.java b/dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoveryHitHighlightingConfiguration.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoveryHitHighlightingConfiguration.java rename to dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoveryHitHighlightingConfiguration.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoveryMoreLikeThisConfiguration.java b/dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoveryMoreLikeThisConfiguration.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoveryMoreLikeThisConfiguration.java rename to dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoveryMoreLikeThisConfiguration.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoveryRecentSubmissionsConfiguration.java b/dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoveryRecentSubmissionsConfiguration.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoveryRecentSubmissionsConfiguration.java rename to dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoveryRecentSubmissionsConfiguration.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoverySearchFilter.java b/dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoverySearchFilter.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoverySearchFilter.java rename to dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoverySearchFilter.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoverySearchFilterFacet.java b/dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoverySearchFilterFacet.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoverySearchFilterFacet.java rename to dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoverySearchFilterFacet.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoverySortConfiguration.java b/dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoverySortConfiguration.java similarity index 90% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoverySortConfiguration.java rename to dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoverySortConfiguration.java index 51c565a126..fd68c2dc83 100644 --- a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoverySortConfiguration.java +++ b/dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoverySortConfiguration.java @@ -15,10 +15,6 @@ package org.dspace.discovery.configuration; -import org.apache.commons.collections.iterators.ArrayListIterator; -import org.dspace.discovery.DiscoverQuery; -import org.springframework.beans.factory.annotation.Required; - import java.util.ArrayList; import java.util.List; diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoverySortFieldConfiguration.java b/dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoverySortFieldConfiguration.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoverySortFieldConfiguration.java rename to dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoverySortFieldConfiguration.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoverySpringLoader.java b/dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoverySpringLoader.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/DiscoverySpringLoader.java rename to dspace-api/src/main/java/org/dspace/discovery/configuration/DiscoverySpringLoader.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/HierarchicalSidebarFacetConfiguration.java b/dspace-api/src/main/java/org/dspace/discovery/configuration/HierarchicalSidebarFacetConfiguration.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/HierarchicalSidebarFacetConfiguration.java rename to dspace-api/src/main/java/org/dspace/discovery/configuration/HierarchicalSidebarFacetConfiguration.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/SidebarFacetConfiguration.java b/dspace-api/src/main/java/org/dspace/discovery/configuration/SidebarFacetConfiguration.java similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/java/org/dspace/discovery/configuration/SidebarFacetConfiguration.java rename to dspace-api/src/main/java/org/dspace/discovery/configuration/SidebarFacetConfiguration.java diff --git a/dspace-discovery/dspace-discovery-provider/src/main/resources/spring/spring-dspace-addon-discovery-configuration-services.xml b/dspace-api/src/main/resources/spring/spring-dspace-addon-discovery-configuration-services.xml similarity index 100% rename from dspace-discovery/dspace-discovery-provider/src/main/resources/spring/spring-dspace-addon-discovery-configuration-services.xml rename to dspace-api/src/main/resources/spring/spring-dspace-addon-discovery-configuration-services.xml diff --git a/dspace-discovery/dspace-discovery-solr/src/main/resources/spring/spring-dspace-addon-discovery-services.xml b/dspace-api/src/main/resources/spring/spring-dspace-addon-discovery-services.xml similarity index 100% rename from dspace-discovery/dspace-discovery-solr/src/main/resources/spring/spring-dspace-addon-discovery-services.xml rename to dspace-api/src/main/resources/spring/spring-dspace-addon-discovery-services.xml diff --git a/dspace-discovery/dspace-discovery-jspui-api/pom.xml b/dspace-discovery/dspace-discovery-jspui-api/pom.xml deleted file mode 100644 index 1bb773cbb0..0000000000 --- a/dspace-discovery/dspace-discovery-jspui-api/pom.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - 4.0.0 - jar - dspace-discovery-jspui-api - DSpace Discovery :: Discovery JSPUI API - - - org.dspace - dspace-discovery - 3.0-SNAPSHOT - .. - - - - - - org.dspace - dspace-jspui-api - - - solr-solrj - org.apache.solr - - - - - - net.sf.flexjson - flexjson - 2.1 - - - - - javax.servlet - servlet-api - provided - - - - org.dspace - dspace-discovery-provider - - - - - - - - - diff --git a/dspace-discovery/dspace-discovery-jspui-webapp/pom.xml b/dspace-discovery/dspace-discovery-jspui-webapp/pom.xml deleted file mode 100644 index ac59c15dfc..0000000000 --- a/dspace-discovery/dspace-discovery-jspui-webapp/pom.xml +++ /dev/null @@ -1,102 +0,0 @@ - - - - 4.0.0 - war - dspace-discovery-jspui-webapp - DSpace Discovery :: Discovery JSPUI Webapp - - - org.dspace - dspace-discovery - 3.0-SNAPSHOT - .. - - - - - - org.dspace - dspace-jspui-api - - - solr-solrj - org.apache.solr - - - - - - org.dspace - dspace-discovery-jspui-api - 3.0-SNAPSHOT - - - - - javax.servlet - servlet-api - provided - - - - - - - - - - org.apache.maven.plugins - maven-war-plugin - - false - true - classes - false - WEB-INF/lib/*.jar - WEB-INF/lib/*.jar - - - true - ${basedir}/src/main/webapp - - WEB-INF/web.xml - - - - - - - prepare-package - - - - - com.mycila.maven-license-plugin - maven-license-plugin - - - - **/*.LICENSE - **/jquery* - - - - - - - - diff --git a/dspace-discovery/dspace-discovery-provider/pom.xml b/dspace-discovery/dspace-discovery-provider/pom.xml deleted file mode 100644 index 7bd8dcd63a..0000000000 --- a/dspace-discovery/dspace-discovery-provider/pom.xml +++ /dev/null @@ -1,100 +0,0 @@ - - - 4.0.0 - jar - org.dspace - dspace-discovery-provider - 3.0-SNAPSHOT - DSpace Discovery :: Discovery Provider Library - - - - - Build Information - $Id: pom.xml 5367 2010-09-30 00:30:11Z mdiggory $ - $URL: https://scm.dspace.org/svn/repo/modules/dspace-discovery/trunk/provider/pom.xml $ - - - org.dspace - dspace-discovery - 3.0-SNAPSHOT - .. - - - - - - org.dspace - dspace-api - - - - commons-httpclient - commons-httpclient - - - - javax.servlet - servlet-api - provided - - - - - - - - org.apache.cocoon - cocoon-maven-plugin - 1.0.0-M2 - - - prepare - compile - - prepare - - - - - - org.mortbay.jetty - maven-jetty-plugin - 6.1.7 - - - - 8888 - 30000 - - - ${project.build.directory}/rcl/webapp - / - - - org.apache.cocoon.mode - dev - - - - - - - maven-eclipse-plugin - 2.5 - - - - diff --git a/dspace-discovery/dspace-discovery-solr/pom.xml b/dspace-discovery/dspace-discovery-solr/pom.xml deleted file mode 100644 index 53348b6a9c..0000000000 --- a/dspace-discovery/dspace-discovery-solr/pom.xml +++ /dev/null @@ -1,52 +0,0 @@ - - - 4.0.0 - jar - org.dspace - dspace-discovery-solr - 3.0-SNAPSHOT - DSpace Discovery :: Discovery Solr Implementation - - - org.dspace - dspace-discovery - 3.0-SNAPSHOT - .. - - - - - org.dspace - dspace-discovery-provider - - - - javax.servlet - servlet-api - provided - - - - org.apache.solr - solr-solrj - 3.5.0 - - - org.slf4j - slf4j-api - - - org.slf4j - jcl-over-slf4j - - - - - - commons-io - commons-io - provided - - - - diff --git a/dspace-discovery/dspace-discovery-xmlui-api/pom.xml b/dspace-discovery/dspace-discovery-xmlui-api/pom.xml deleted file mode 100644 index bd9d36ef7a..0000000000 --- a/dspace-discovery/dspace-discovery-xmlui-api/pom.xml +++ /dev/null @@ -1,119 +0,0 @@ - - - - 4.0.0 - jar - org.dspace - dspace-discovery-xmlui-api - 3.0-SNAPSHOT - DSpace Discovery :: Discovery XMLUI API - - - org.dspace - dspace-discovery - 3.0-SNAPSHOT - .. - - - - - - org.dspace - dspace-xmlui-api - - - solr-solrj - org.apache.solr - - - - - - - javax.servlet - servlet-api - provided - - - - - org.dspace - dspace-discovery-provider - - - - - - - - org.apache.cocoon - cocoon-maven-plugin - 1.0.0 - - - prepare - compile - - prepare - - - - - - - org.mortbay.jetty - maven-jetty-plugin - 6.1.7 - - - - 8888 - 30000 - - - ${project.build.directory}/rcl/webapp - / - - - org.apache.cocoon.mode - dev - - - - - - - - - diff --git a/dspace-discovery/dspace-discovery-xmlui-webapp/pom.xml b/dspace-discovery/dspace-discovery-xmlui-webapp/pom.xml deleted file mode 100644 index e7c08e7ada..0000000000 --- a/dspace-discovery/dspace-discovery-xmlui-webapp/pom.xml +++ /dev/null @@ -1,139 +0,0 @@ - - - - 4.0.0 - war - org.dspace - dspace-discovery-xmlui-webapp - 3.0-SNAPSHOT - DSpace Discovery :: Discovery XMLUI Webapp - - - org.dspace - dspace-discovery - 3.0-SNAPSHOT - .. - - - - - - org.dspace - dspace-xmlui-api - - - solr-solrj - org.apache.solr - - - - - - org.dspace - dspace-discovery-xmlui-api - 3.0-SNAPSHOT - - - - - javax.servlet - servlet-api - provided - - - - - - - - - - org.apache.cocoon - cocoon-maven-plugin - 1.0.0 - - - prepare - compile - - prepare - - - - - - org.apache.maven.plugins - maven-war-plugin - - false - true - classes - false - WEB-INF/lib/*.jar - WEB-INF/lib/*.jar - - - true - ${basedir}/src/main/webapp - - WEB-INF/web.xml - - - - - - - prepare-package - - - - - org.mortbay.jetty - maven-jetty-plugin - 6.1.7 - - - - 8888 - 30000 - - - ${project.build.directory}/rcl/webapp - / - - - org.apache.cocoon.mode - dev - - - - - - com.mycila.maven-license-plugin - maven-license-plugin - - - - **/*.LICENSE - **/jquery* - - - - - - - - diff --git a/dspace-discovery/pom.xml b/dspace-discovery/pom.xml index 50654d6eea..e7b18a9cc4 100644 --- a/dspace-discovery/pom.xml +++ b/dspace-discovery/pom.xml @@ -16,12 +16,6 @@ - dspace-discovery-provider - dspace-discovery-solr - dspace-discovery-xmlui-api - dspace-discovery-xmlui-webapp - dspace-discovery-jspui-api - dspace-discovery-jspui-webapp diff --git a/dspace-jspui/dspace-jspui-api/pom.xml b/dspace-jspui/dspace-jspui-api/pom.xml index 0bfc464076..fbda093020 100644 --- a/dspace-jspui/dspace-jspui-api/pom.xml +++ b/dspace-jspui/dspace-jspui-api/pom.xml @@ -68,6 +68,12 @@ spring-webmvc jar + + net.sf.flexjson + flexjson + 2.1 + + diff --git a/dspace-discovery/dspace-discovery-jspui-api/src/main/java/org/dspace/app/webui/discovery/DiscoverUtility.java b/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/discovery/DiscoverUtility.java similarity index 96% rename from dspace-discovery/dspace-discovery-jspui-api/src/main/java/org/dspace/app/webui/discovery/DiscoverUtility.java rename to dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/discovery/DiscoverUtility.java index c68dfb569a..a273ac5f47 100644 --- a/dspace-discovery/dspace-discovery-jspui-api/src/main/java/org/dspace/app/webui/discovery/DiscoverUtility.java +++ b/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/discovery/DiscoverUtility.java @@ -1,722 +1,716 @@ -/** - * 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.webui.discovery; - -import java.io.UnsupportedEncodingException; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -import javax.servlet.http.HttpServletRequest; - -import org.apache.commons.lang.StringUtils; -import org.apache.log4j.Logger; -import org.dspace.app.webui.util.UIUtil; -import org.dspace.content.DSpaceObject; -import org.dspace.core.Context; -import org.dspace.core.LogManager; -import org.dspace.discovery.DiscoverFacetField; -import org.dspace.discovery.DiscoverFilterQuery; -import org.dspace.discovery.DiscoverQuery; -import org.dspace.discovery.DiscoverQuery.SORT_ORDER; -import org.dspace.discovery.DiscoverResult; -import org.dspace.discovery.SearchServiceException; -import org.dspace.discovery.SearchUtils; -import org.dspace.discovery.configuration.DiscoveryConfiguration; -import org.dspace.discovery.configuration.DiscoveryConfigurationParameters; -import org.dspace.discovery.configuration.DiscoverySearchFilterFacet; -import org.dspace.discovery.configuration.DiscoverySortConfiguration; -import org.dspace.discovery.configuration.DiscoverySortFieldConfiguration; -import org.dspace.discovery.configuration.SidebarFacetConfiguration; -import org.dspace.handle.HandleManager; -import org.dspace.search.QueryArgs; -import org.dspace.search.QueryResults; - -public class DiscoverUtility -{ - /** log4j category */ - private static Logger log = Logger.getLogger(DiscoverUtility.class); - - /** - * Get the scope of the search using the parameter found in the request - * - * @param context - * @param request - * @return - * @throws IllegalStateException - * @throws SQLException - */ - public static DSpaceObject getSearchScope(Context context, - HttpServletRequest request) throws IllegalStateException, - SQLException - { - // Get the location parameter, if any - String location = request.getParameter("location"); - if (location == null) - { - if (UIUtil.getCollectionLocation(request) != null) - { - return UIUtil.getCollectionLocation(request); - } - if (UIUtil.getCommunityLocation(request) != null) - { - return UIUtil.getCommunityLocation(request); - } - return null; - } - DSpaceObject scope = HandleManager.resolveToObject(context, location); - return scope; - } - - /** - * Build a DiscoverQuery object using the parameter in the request - * - * @param request - * @return - * @throws SearchServiceException - */ - public static DiscoverQuery getDiscoverQuery(Context context, - HttpServletRequest request, DSpaceObject scope, boolean enableFacet) - { - DiscoverQuery queryArgs = new DiscoverQuery(); - DiscoveryConfiguration discoveryConfiguration = SearchUtils - .getDiscoveryConfiguration(scope); - - List userFilters = setupBasicQuery(context, - discoveryConfiguration, request, queryArgs); - - setPagination(request, queryArgs, discoveryConfiguration); - - if (enableFacet - && !"submit_export_metadata".equals(UIUtil.getSubmitButton( - request, "submit"))) - { - setFacet(context, request, scope, queryArgs, - discoveryConfiguration, userFilters); - } - - return queryArgs; - } - - /** - * Build the DiscoverQuery object for an autocomplete search using - * parameters in the request - * - * @param context - * @param request - * @param scope - * @return - */ - public static DiscoverQuery getDiscoverAutocomplete(Context context, - HttpServletRequest request, DSpaceObject scope) - { - DiscoverQuery queryArgs = new DiscoverQuery(); - DiscoveryConfiguration discoveryConfiguration = SearchUtils.getDiscoveryConfiguration(); - - setupBasicQuery(context, discoveryConfiguration, request, queryArgs); - String autoIndex = request.getParameter("auto_idx"); - String autoQuery = request.getParameter("auto_query"); - String sort = request.getParameter("auto_sort"); - String autoType = request.getParameter("auto_type"); - if ("contains".equals(autoType) || "notcontains".equals(autoType)) - { - autoType = DiscoveryConfigurationParameters.TYPE_STANDARD; - } - else if ("authority".equals(autoType) || "notauthority".equals(autoType)) - { - autoType = DiscoveryConfigurationParameters.TYPE_AUTHORITY; - } - else - { - autoType = DiscoveryConfigurationParameters.TYPE_AC; - } - DiscoveryConfigurationParameters.SORT sortBy = DiscoveryConfigurationParameters.SORT.VALUE; - if (StringUtils.isNotBlank(sort)) - { - if ("count".equalsIgnoreCase(sort)) - { - sortBy = DiscoveryConfigurationParameters.SORT.COUNT; - } - else - { - sortBy = DiscoveryConfigurationParameters.SORT.VALUE; - } - } - // no user choices... default for autocomplete should be alphabetic - // sorting in all cases except empty query where count is preferable - else if ("".equals(autoQuery)) - { - sortBy = DiscoveryConfigurationParameters.SORT.COUNT; - } - if (autoIndex == null) - { - autoIndex = "all"; - } - if (autoQuery == null) - { - autoQuery = ""; - } - - int limit = UIUtil.getIntParameter(request, "autocomplete.limit"); - if (limit == -1) - { - limit = 10; - } - DiscoverFacetField autocompleteField = new DiscoverFacetField(autoIndex, - autoType, - limit, sortBy, autoQuery.toLowerCase()); - queryArgs.addFacetField(autocompleteField); - queryArgs.setMaxResults(0); - queryArgs.setFacetMinCount(1); - return queryArgs; - } - - /** - * Setup the basic query arguments: the main query and all the filters - * (default + user). Return the list of user filter - * - * @param context - * @param request - * @param queryArgs - * the query object to populate - * @return the list of user filer (as filter query) - */ - private static List setupBasicQuery(Context context, - DiscoveryConfiguration discoveryConfiguration, - HttpServletRequest request, DiscoverQuery queryArgs) - { - // Get the query - String query = request.getParameter("query"); - if (StringUtils.isNotBlank(query)) - { - queryArgs.setQuery(query); - } - - List defaultFilterQueries = discoveryConfiguration - .getDefaultFilterQueries(); - if (defaultFilterQueries != null) - { - for (String f : defaultFilterQueries) - { - queryArgs.addFacetQuery(f); - } - } - List filters = getFilters(request); - List userFilters = new ArrayList(); - for (String[] f : filters) - { - try - { - String newFilterQuery = SearchUtils.getSearchService() - .toFilterQuery(context, f[0], f[1], f[2]) - .getFilterQuery(); - if (newFilterQuery != null) - { - queryArgs.addFilterQueries(newFilterQuery); - userFilters.add(newFilterQuery); - } - } - catch (SQLException e) - { - log.error(LogManager.getHeader(context, - "Error in discovery while setting up user facet query", - "filter_field: " + f[0] + ",filter_type:" - + f[1] + ",filer_value:" - + f[2]), e); - } - - } - - return userFilters; - - } - - private static void setPagination(HttpServletRequest request, - DiscoverQuery queryArgs, - DiscoveryConfiguration discoveryConfiguration) - { - int start = UIUtil.getIntParameter(request, "start"); - // can't start earlier than 0 in the results! - if (start < 0) - { - start = 0; - } - - String sortBy = request.getParameter("sort_by"); - String sortOrder = request.getParameter("order"); - - DiscoverySortConfiguration searchSortConfiguration = discoveryConfiguration - .getSearchSortConfiguration(); - if (sortBy == null) - { - // Attempt to find the default one, if none found we use SCORE - sortBy = "score"; - if (searchSortConfiguration != null) - { - for (DiscoverySortFieldConfiguration sortFieldConfiguration : searchSortConfiguration - .getSortFields()) - { - if (sortFieldConfiguration.equals(searchSortConfiguration - .getDefaultSort())) - { - sortBy = SearchUtils - .getSearchService() - .toSortFieldIndex( - sortFieldConfiguration - .getMetadataField(), - sortFieldConfiguration.getType()); - } - } - } - } - - if (sortOrder == null && searchSortConfiguration != null) - { - sortOrder = searchSortConfiguration.getDefaultSortOrder() - .toString(); - } - if (sortBy != null) - { - if ("asc".equalsIgnoreCase(sortOrder)) - { - queryArgs.setSortField(sortBy, SORT_ORDER.asc); - } - else - { - queryArgs.setSortField(sortBy, SORT_ORDER.desc); - } - } - - int rpp = UIUtil.getIntParameter(request, "rpp"); - // Override the page setting if exporting metadata - if ("submit_export_metadata".equals(UIUtil.getSubmitButton(request, - "submit"))) - { - queryArgs.setStart(0); - queryArgs.setMaxResults(Integer.MAX_VALUE); - // search only for items other objects are not exported - queryArgs.addFilterQueries("search.resourcetype:2"); - } - else - { - // String groupBy = request.getParameter("group_by"); - // - // // Enable groupBy collapsing if designated - // if (groupBy != null && !groupBy.equalsIgnoreCase("none")) { - // /** Construct a Collapse Field Query */ - // queryArgs.addProperty("collapse.field", groupBy); - // queryArgs.addProperty("collapse.threshold", "1"); - // queryArgs.addProperty("collapse.includeCollapsedDocs.fl", - // "handle"); - // queryArgs.addProperty("collapse.facet", "before"); - // - // //queryArgs.a type:Article^2 - // - // // TODO: This is a hack to get Publications (Articles) to always - // be at the top of Groups. - // // TODO: I think the can be more transparently done in the solr - // solrconfig.xml with DISMAX and boosting - // /** sort in groups to get publications to top */ - // queryArgs.setSortField("dc.type", DiscoverQuery.SORT_ORDER.asc); - // - // } - - if (rpp > 0) - { - queryArgs.setMaxResults(rpp); - } - else - { - queryArgs.setMaxResults(discoveryConfiguration.getDefaultRpp()); - } - queryArgs.setStart(start); - } - } - - private static void setFacet(Context context, HttpServletRequest request, - DSpaceObject scope, DiscoverQuery queryArgs, - DiscoveryConfiguration discoveryConfiguration, - List userFilters) - { - List facets = discoveryConfiguration - .getSidebarFacets(); - - log.info("facets for scope, " + scope + ": " - + (facets != null ? facets.size() : null)); - if (facets != null) - { - queryArgs.setFacetMinCount(1); - } - - /** enable faceting of search results */ - if (facets != null) - { - queryArgs.setFacetMinCount(1); - for (DiscoverySearchFilterFacet facet : facets) - { - if (facet.getType().equals( - DiscoveryConfigurationParameters.TYPE_DATE)) - { - String dateFacet = facet.getIndexFieldName() + ".year"; - List filterQueriesList = queryArgs - .getFilterQueries(); - String[] filterQueries = new String[0]; - if (filterQueriesList != null) - { - filterQueries = new String[filterQueries.length]; - filterQueries = filterQueriesList - .toArray(filterQueries); - } - try - { - // Get a range query so we can create facet - // queries - // ranging from out first to our last date - // Attempt to determine our oldest & newest year - // by - // checking for previously selected filters - int oldestYear = -1; - int newestYear = -1; - - for (String filterQuery : filterQueries) - { - if (filterQuery.startsWith(dateFacet + ":")) - { - // Check for a range - Pattern pattern = Pattern - .compile("\\[(.*? TO .*?)\\]"); - Matcher matcher = pattern.matcher(filterQuery); - boolean hasPattern = matcher.find(); - if (hasPattern) - { - filterQuery = matcher.group(0); - // We have a range - // Resolve our range to a first & - // endyear - int tempOldYear = Integer - .parseInt(filterQuery.split(" TO ")[0] - .replace("[", "").trim()); - int tempNewYear = Integer - .parseInt(filterQuery.split(" TO ")[1] - .replace("]", "").trim()); - - // Check if we have a further filter - // (or - // a first one found) - if (tempNewYear < newestYear - || oldestYear < tempOldYear - || newestYear == -1) - { - oldestYear = tempOldYear; - newestYear = tempNewYear; - } - - } - else - { - if (filterQuery.indexOf(" OR ") != -1) - { - // Should always be the case - filterQuery = filterQuery.split(" OR ")[0]; - } - // We should have a single date - oldestYear = Integer.parseInt(filterQuery - .split(":")[1].trim()); - newestYear = oldestYear; - // No need to look further - break; - } - } - } - // Check if we have found a range, if not then - // retrieve our first & last year by using solr - if (oldestYear == -1 && newestYear == -1) - { - - DiscoverQuery yearRangeQuery = new DiscoverQuery(); - yearRangeQuery.setFacetMinCount(1); - yearRangeQuery.setMaxResults(1); - // Set our query to anything that has this - // value - yearRangeQuery.addFieldPresentQueries(dateFacet); - // Set sorting so our last value will appear - // on - // top - yearRangeQuery.setSortField(dateFacet + "_sort", - DiscoverQuery.SORT_ORDER.asc); - yearRangeQuery.addFilterQueries(filterQueries); - yearRangeQuery.addSearchField(dateFacet); - DiscoverResult lastYearResult = SearchUtils - .getSearchService().search(context, scope, - yearRangeQuery); - - if (0 < lastYearResult.getDspaceObjects().size()) - { - java.util.List searchDocuments = lastYearResult - .getSearchDocument(lastYearResult - .getDspaceObjects().get(0)); - if (0 < searchDocuments.size() - && 0 < searchDocuments - .get(0) - .getSearchFieldValues(dateFacet) - .size()) - { - oldestYear = Integer - .parseInt(searchDocuments - .get(0) - .getSearchFieldValues( - dateFacet).get(0)); - } - } - // Now get the first year - yearRangeQuery.setSortField(dateFacet + "_sort", - DiscoverQuery.SORT_ORDER.desc); - DiscoverResult firstYearResult = SearchUtils - .getSearchService().search(context, scope, - yearRangeQuery); - if (0 < firstYearResult.getDspaceObjects().size()) - { - java.util.List searchDocuments = firstYearResult - .getSearchDocument(firstYearResult - .getDspaceObjects().get(0)); - if (0 < searchDocuments.size() - && 0 < searchDocuments - .get(0) - .getSearchFieldValues(dateFacet) - .size()) - { - newestYear = Integer - .parseInt(searchDocuments - .get(0) - .getSearchFieldValues( - dateFacet).get(0)); - } - } - // No values found! - if (newestYear == -1 || oldestYear == -1) - { - continue; - } - - } - - int gap = 1; - // Attempt to retrieve our gap by the algorithm - // below - int yearDifference = newestYear - oldestYear; - if (yearDifference != 0) - { - while (10 < ((double) yearDifference / gap)) - { - gap *= 10; - } - } - // We need to determine our top year so we can - // start - // our count from a clean year - // Example: 2001 and a gap from 10 we need the - // following result: 2010 - 2000 ; 2000 - 1990 - // hence - // the top year - int topYear = (int) (Math.ceil((float) (newestYear) - / gap) * gap); - - if (gap == 1) - { - // We need a list of our years - // We have a date range add faceting for our - // field - // The faceting will automatically be - // limited to - // the 10 years in our span due to our - // filterquery - queryArgs.addFacetField(new DiscoverFacetField( - facet.getIndexFieldName(), facet.getType(), - 10, facet.getSortOrder())); - } - else - { - java.util.List facetQueries = new ArrayList(); - // Create facet queries but limit then to 11 - // (11 - // == when we need to show a show more url) - for (int year = topYear - gap; year > oldestYear - && (facetQueries.size() < 11); year -= gap) - { - // Add a filter to remove the last year - // only - // if we aren't the last year - int bottomYear = year - gap; - // Make sure we don't go below our last - // year - // found - if (bottomYear < oldestYear) - { - bottomYear = oldestYear; - } - - // Also make sure we don't go above our - // newest year - int currentTop = year; - if ((year == topYear)) - { - currentTop = newestYear; - } - else - { - // We need to do -1 on this one to - // get a - // better result - currentTop--; - } - facetQueries.add(dateFacet + ":[" + bottomYear - + " TO " + currentTop + "]"); - } - for (String facetQuery : facetQueries) - { - queryArgs.addFacetQuery(facetQuery); - } - } - } - catch (Exception e) - { - log.error( - LogManager - .getHeader( - context, - "Error in discovery while setting up date facet range", - "date facet: " + dateFacet), e); - } - } - else - { - int facetLimit = facet.getFacetLimit(); - - int facetPage = UIUtil.getIntParameter(request, - facet.getIndexFieldName() + "_page"); - if (facetPage < 0) - { - facetPage = 0; - } - // at most all the user filters belong to this facet - int alreadySelected = userFilters.size(); - - // Add one to our facet limit to make sure that if - // we - // have more then the shown facets that we show our - // show - // more url - // add the already selected facet so to have a full - // top list - // if possible - queryArgs.addFacetField(new DiscoverFacetField(facet - .getIndexFieldName(), - DiscoveryConfigurationParameters.TYPE_TEXT, - facetLimit + 1 + alreadySelected, facet - .getSortOrder(), facetPage * facetLimit)); - } - } - } - } - - public static List getFilters(HttpServletRequest request) - { - String submit = UIUtil.getSubmitButton(request, "submit"); - int ignore = -1; - if (submit.startsWith("submit_filter_remove_")) - { - ignore = Integer.parseInt(submit.substring("submit_filter_remove_".length())); - } - List appliedFilters = new ArrayList(); - - List filterValue = new ArrayList(); - List filterOp = new ArrayList(); - List filterField = new ArrayList(); - for (int idx = 1; ; idx++) - { - String op = request.getParameter("filter_type_"+idx); - if (StringUtils.isBlank(op)) - { - break; - } - else if (idx != ignore) - { - filterOp.add(op); - filterField.add(request.getParameter("filter_field_"+idx)); - filterValue.add(request.getParameter("filter_value_"+idx)); - } - } - - String op = request.getParameter("filtertype"); - if (StringUtils.isNotBlank(op)) - { - filterOp.add(op); - filterField.add(request.getParameter("filtername")); - filterValue.add(request.getParameter("filterquery")); - } - - for (int idx = 0; idx < filterOp.size(); idx++) - { - appliedFilters.add(new String[] { filterField.get(idx), - filterOp.get(idx), filterValue.get(idx) }); - } - return appliedFilters; - } - - // /** - // * Build the query from the advanced search form - // * - // * @param request - // * @return - // */ - // public static String buildQuery(HttpServletRequest request) - // { - // int num_field = UIUtil.getIntParameter(request, "num_search_field"); - // if (num_field <= 0) - // { - // num_field = 3; - // } - // StringBuffer query = new StringBuffer(); - // buildQueryPart(query, request.getParameter("field"), - // request.getParameter("query"), null); - // for (int i = 1; i < num_field; i++) - // { - // buildQueryPart(query, request.getParameter("field" + i), - // request.getParameter("query" + i), - // request.getParameter("conjuction" + i)); - // } - // return query.toString(); - // } - // - // private static void buildQueryPart(StringBuffer currQuery, String field, - // String queryPart, String conjuction) - // { - // if (StringUtils.isBlank(queryPart)) - // { - // return; - // } - // else - // { - // StringBuffer tmp = new StringBuffer(queryPart); - // if (StringUtils.isNotBlank(field)) - // { - // tmp.insert(0, field + ":(").append(")"); - // } - // - // if (StringUtils.isNotBlank(conjuction) && currQuery.length() > 0) - // { - // currQuery.append(conjuction); - // } - // currQuery.append(tmp); - // } - // } - -} +/** + * 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.webui.discovery; + +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.lang.StringUtils; +import org.apache.log4j.Logger; +import org.dspace.app.webui.util.UIUtil; +import org.dspace.content.DSpaceObject; +import org.dspace.core.Context; +import org.dspace.core.LogManager; +import org.dspace.discovery.DiscoverFacetField; +import org.dspace.discovery.DiscoverQuery; +import org.dspace.discovery.DiscoverQuery.SORT_ORDER; +import org.dspace.discovery.DiscoverResult; +import org.dspace.discovery.SearchServiceException; +import org.dspace.discovery.SearchUtils; +import org.dspace.discovery.configuration.DiscoveryConfiguration; +import org.dspace.discovery.configuration.DiscoveryConfigurationParameters; +import org.dspace.discovery.configuration.DiscoverySearchFilterFacet; +import org.dspace.discovery.configuration.DiscoverySortConfiguration; +import org.dspace.discovery.configuration.DiscoverySortFieldConfiguration; +import org.dspace.handle.HandleManager; + +public class DiscoverUtility +{ + /** log4j category */ + private static Logger log = Logger.getLogger(DiscoverUtility.class); + + /** + * Get the scope of the search using the parameter found in the request + * + * @param context + * @param request + * @return + * @throws IllegalStateException + * @throws SQLException + */ + public static DSpaceObject getSearchScope(Context context, + HttpServletRequest request) throws IllegalStateException, + SQLException + { + // Get the location parameter, if any + String location = request.getParameter("location"); + if (location == null) + { + if (UIUtil.getCollectionLocation(request) != null) + { + return UIUtil.getCollectionLocation(request); + } + if (UIUtil.getCommunityLocation(request) != null) + { + return UIUtil.getCommunityLocation(request); + } + return null; + } + DSpaceObject scope = HandleManager.resolveToObject(context, location); + return scope; + } + + /** + * Build a DiscoverQuery object using the parameter in the request + * + * @param request + * @return + * @throws SearchServiceException + */ + public static DiscoverQuery getDiscoverQuery(Context context, + HttpServletRequest request, DSpaceObject scope, boolean enableFacet) + { + DiscoverQuery queryArgs = new DiscoverQuery(); + DiscoveryConfiguration discoveryConfiguration = SearchUtils + .getDiscoveryConfiguration(scope); + + List userFilters = setupBasicQuery(context, + discoveryConfiguration, request, queryArgs); + + setPagination(request, queryArgs, discoveryConfiguration); + + if (enableFacet + && !"submit_export_metadata".equals(UIUtil.getSubmitButton( + request, "submit"))) + { + setFacet(context, request, scope, queryArgs, + discoveryConfiguration, userFilters); + } + + return queryArgs; + } + + /** + * Build the DiscoverQuery object for an autocomplete search using + * parameters in the request + * + * @param context + * @param request + * @param scope + * @return + */ + public static DiscoverQuery getDiscoverAutocomplete(Context context, + HttpServletRequest request, DSpaceObject scope) + { + DiscoverQuery queryArgs = new DiscoverQuery(); + DiscoveryConfiguration discoveryConfiguration = SearchUtils.getDiscoveryConfiguration(); + + setupBasicQuery(context, discoveryConfiguration, request, queryArgs); + String autoIndex = request.getParameter("auto_idx"); + String autoQuery = request.getParameter("auto_query"); + String sort = request.getParameter("auto_sort"); + String autoType = request.getParameter("auto_type"); + if ("contains".equals(autoType) || "notcontains".equals(autoType)) + { + autoType = DiscoveryConfigurationParameters.TYPE_STANDARD; + } + else if ("authority".equals(autoType) || "notauthority".equals(autoType)) + { + autoType = DiscoveryConfigurationParameters.TYPE_AUTHORITY; + } + else + { + autoType = DiscoveryConfigurationParameters.TYPE_AC; + } + DiscoveryConfigurationParameters.SORT sortBy = DiscoveryConfigurationParameters.SORT.VALUE; + if (StringUtils.isNotBlank(sort)) + { + if ("count".equalsIgnoreCase(sort)) + { + sortBy = DiscoveryConfigurationParameters.SORT.COUNT; + } + else + { + sortBy = DiscoveryConfigurationParameters.SORT.VALUE; + } + } + // no user choices... default for autocomplete should be alphabetic + // sorting in all cases except empty query where count is preferable + else if ("".equals(autoQuery)) + { + sortBy = DiscoveryConfigurationParameters.SORT.COUNT; + } + if (autoIndex == null) + { + autoIndex = "all"; + } + if (autoQuery == null) + { + autoQuery = ""; + } + + int limit = UIUtil.getIntParameter(request, "autocomplete.limit"); + if (limit == -1) + { + limit = 10; + } + DiscoverFacetField autocompleteField = new DiscoverFacetField(autoIndex, + autoType, + limit, sortBy, autoQuery.toLowerCase()); + queryArgs.addFacetField(autocompleteField); + queryArgs.setMaxResults(0); + queryArgs.setFacetMinCount(1); + return queryArgs; + } + + /** + * Setup the basic query arguments: the main query and all the filters + * (default + user). Return the list of user filter + * + * @param context + * @param request + * @param queryArgs + * the query object to populate + * @return the list of user filer (as filter query) + */ + private static List setupBasicQuery(Context context, + DiscoveryConfiguration discoveryConfiguration, + HttpServletRequest request, DiscoverQuery queryArgs) + { + // Get the query + String query = request.getParameter("query"); + if (StringUtils.isNotBlank(query)) + { + queryArgs.setQuery(query); + } + + List defaultFilterQueries = discoveryConfiguration + .getDefaultFilterQueries(); + if (defaultFilterQueries != null) + { + for (String f : defaultFilterQueries) + { + queryArgs.addFacetQuery(f); + } + } + List filters = getFilters(request); + List userFilters = new ArrayList(); + for (String[] f : filters) + { + try + { + String newFilterQuery = SearchUtils.getSearchService() + .toFilterQuery(context, f[0], f[1], f[2]) + .getFilterQuery(); + if (newFilterQuery != null) + { + queryArgs.addFilterQueries(newFilterQuery); + userFilters.add(newFilterQuery); + } + } + catch (SQLException e) + { + log.error(LogManager.getHeader(context, + "Error in discovery while setting up user facet query", + "filter_field: " + f[0] + ",filter_type:" + + f[1] + ",filer_value:" + + f[2]), e); + } + + } + + return userFilters; + + } + + private static void setPagination(HttpServletRequest request, + DiscoverQuery queryArgs, + DiscoveryConfiguration discoveryConfiguration) + { + int start = UIUtil.getIntParameter(request, "start"); + // can't start earlier than 0 in the results! + if (start < 0) + { + start = 0; + } + + String sortBy = request.getParameter("sort_by"); + String sortOrder = request.getParameter("order"); + + DiscoverySortConfiguration searchSortConfiguration = discoveryConfiguration + .getSearchSortConfiguration(); + if (sortBy == null) + { + // Attempt to find the default one, if none found we use SCORE + sortBy = "score"; + if (searchSortConfiguration != null) + { + for (DiscoverySortFieldConfiguration sortFieldConfiguration : searchSortConfiguration + .getSortFields()) + { + if (sortFieldConfiguration.equals(searchSortConfiguration + .getDefaultSort())) + { + sortBy = SearchUtils + .getSearchService() + .toSortFieldIndex( + sortFieldConfiguration + .getMetadataField(), + sortFieldConfiguration.getType()); + } + } + } + } + + if (sortOrder == null && searchSortConfiguration != null) + { + sortOrder = searchSortConfiguration.getDefaultSortOrder() + .toString(); + } + if (sortBy != null) + { + if ("asc".equalsIgnoreCase(sortOrder)) + { + queryArgs.setSortField(sortBy, SORT_ORDER.asc); + } + else + { + queryArgs.setSortField(sortBy, SORT_ORDER.desc); + } + } + + int rpp = UIUtil.getIntParameter(request, "rpp"); + // Override the page setting if exporting metadata + if ("submit_export_metadata".equals(UIUtil.getSubmitButton(request, + "submit"))) + { + queryArgs.setStart(0); + queryArgs.setMaxResults(Integer.MAX_VALUE); + // search only for items other objects are not exported + queryArgs.addFilterQueries("search.resourcetype:2"); + } + else + { + // String groupBy = request.getParameter("group_by"); + // + // // Enable groupBy collapsing if designated + // if (groupBy != null && !groupBy.equalsIgnoreCase("none")) { + // /** Construct a Collapse Field Query */ + // queryArgs.addProperty("collapse.field", groupBy); + // queryArgs.addProperty("collapse.threshold", "1"); + // queryArgs.addProperty("collapse.includeCollapsedDocs.fl", + // "handle"); + // queryArgs.addProperty("collapse.facet", "before"); + // + // //queryArgs.a type:Article^2 + // + // // TODO: This is a hack to get Publications (Articles) to always + // be at the top of Groups. + // // TODO: I think the can be more transparently done in the solr + // solrconfig.xml with DISMAX and boosting + // /** sort in groups to get publications to top */ + // queryArgs.setSortField("dc.type", DiscoverQuery.SORT_ORDER.asc); + // + // } + + if (rpp > 0) + { + queryArgs.setMaxResults(rpp); + } + else + { + queryArgs.setMaxResults(discoveryConfiguration.getDefaultRpp()); + } + queryArgs.setStart(start); + } + } + + private static void setFacet(Context context, HttpServletRequest request, + DSpaceObject scope, DiscoverQuery queryArgs, + DiscoveryConfiguration discoveryConfiguration, + List userFilters) + { + List facets = discoveryConfiguration + .getSidebarFacets(); + + log.info("facets for scope, " + scope + ": " + + (facets != null ? facets.size() : null)); + if (facets != null) + { + queryArgs.setFacetMinCount(1); + } + + /** enable faceting of search results */ + if (facets != null) + { + queryArgs.setFacetMinCount(1); + for (DiscoverySearchFilterFacet facet : facets) + { + if (facet.getType().equals( + DiscoveryConfigurationParameters.TYPE_DATE)) + { + String dateFacet = facet.getIndexFieldName() + ".year"; + List filterQueriesList = queryArgs + .getFilterQueries(); + String[] filterQueries = new String[0]; + if (filterQueriesList != null) + { + filterQueries = new String[filterQueries.length]; + filterQueries = filterQueriesList + .toArray(filterQueries); + } + try + { + // Get a range query so we can create facet + // queries + // ranging from out first to our last date + // Attempt to determine our oldest & newest year + // by + // checking for previously selected filters + int oldestYear = -1; + int newestYear = -1; + + for (String filterQuery : filterQueries) + { + if (filterQuery.startsWith(dateFacet + ":")) + { + // Check for a range + Pattern pattern = Pattern + .compile("\\[(.*? TO .*?)\\]"); + Matcher matcher = pattern.matcher(filterQuery); + boolean hasPattern = matcher.find(); + if (hasPattern) + { + filterQuery = matcher.group(0); + // We have a range + // Resolve our range to a first & + // endyear + int tempOldYear = Integer + .parseInt(filterQuery.split(" TO ")[0] + .replace("[", "").trim()); + int tempNewYear = Integer + .parseInt(filterQuery.split(" TO ")[1] + .replace("]", "").trim()); + + // Check if we have a further filter + // (or + // a first one found) + if (tempNewYear < newestYear + || oldestYear < tempOldYear + || newestYear == -1) + { + oldestYear = tempOldYear; + newestYear = tempNewYear; + } + + } + else + { + if (filterQuery.indexOf(" OR ") != -1) + { + // Should always be the case + filterQuery = filterQuery.split(" OR ")[0]; + } + // We should have a single date + oldestYear = Integer.parseInt(filterQuery + .split(":")[1].trim()); + newestYear = oldestYear; + // No need to look further + break; + } + } + } + // Check if we have found a range, if not then + // retrieve our first & last year by using solr + if (oldestYear == -1 && newestYear == -1) + { + + DiscoverQuery yearRangeQuery = new DiscoverQuery(); + yearRangeQuery.setFacetMinCount(1); + yearRangeQuery.setMaxResults(1); + // Set our query to anything that has this + // value + yearRangeQuery.addFieldPresentQueries(dateFacet); + // Set sorting so our last value will appear + // on + // top + yearRangeQuery.setSortField(dateFacet + "_sort", + DiscoverQuery.SORT_ORDER.asc); + yearRangeQuery.addFilterQueries(filterQueries); + yearRangeQuery.addSearchField(dateFacet); + DiscoverResult lastYearResult = SearchUtils + .getSearchService().search(context, scope, + yearRangeQuery); + + if (0 < lastYearResult.getDspaceObjects().size()) + { + java.util.List searchDocuments = lastYearResult + .getSearchDocument(lastYearResult + .getDspaceObjects().get(0)); + if (0 < searchDocuments.size() + && 0 < searchDocuments + .get(0) + .getSearchFieldValues(dateFacet) + .size()) + { + oldestYear = Integer + .parseInt(searchDocuments + .get(0) + .getSearchFieldValues( + dateFacet).get(0)); + } + } + // Now get the first year + yearRangeQuery.setSortField(dateFacet + "_sort", + DiscoverQuery.SORT_ORDER.desc); + DiscoverResult firstYearResult = SearchUtils + .getSearchService().search(context, scope, + yearRangeQuery); + if (0 < firstYearResult.getDspaceObjects().size()) + { + java.util.List searchDocuments = firstYearResult + .getSearchDocument(firstYearResult + .getDspaceObjects().get(0)); + if (0 < searchDocuments.size() + && 0 < searchDocuments + .get(0) + .getSearchFieldValues(dateFacet) + .size()) + { + newestYear = Integer + .parseInt(searchDocuments + .get(0) + .getSearchFieldValues( + dateFacet).get(0)); + } + } + // No values found! + if (newestYear == -1 || oldestYear == -1) + { + continue; + } + + } + + int gap = 1; + // Attempt to retrieve our gap by the algorithm + // below + int yearDifference = newestYear - oldestYear; + if (yearDifference != 0) + { + while (10 < ((double) yearDifference / gap)) + { + gap *= 10; + } + } + // We need to determine our top year so we can + // start + // our count from a clean year + // Example: 2001 and a gap from 10 we need the + // following result: 2010 - 2000 ; 2000 - 1990 + // hence + // the top year + int topYear = (int) (Math.ceil((float) (newestYear) + / gap) * gap); + + if (gap == 1) + { + // We need a list of our years + // We have a date range add faceting for our + // field + // The faceting will automatically be + // limited to + // the 10 years in our span due to our + // filterquery + queryArgs.addFacetField(new DiscoverFacetField( + facet.getIndexFieldName(), facet.getType(), + 10, facet.getSortOrder())); + } + else + { + java.util.List facetQueries = new ArrayList(); + // Create facet queries but limit then to 11 + // (11 + // == when we need to show a show more url) + for (int year = topYear - gap; year > oldestYear + && (facetQueries.size() < 11); year -= gap) + { + // Add a filter to remove the last year + // only + // if we aren't the last year + int bottomYear = year - gap; + // Make sure we don't go below our last + // year + // found + if (bottomYear < oldestYear) + { + bottomYear = oldestYear; + } + + // Also make sure we don't go above our + // newest year + int currentTop = year; + if ((year == topYear)) + { + currentTop = newestYear; + } + else + { + // We need to do -1 on this one to + // get a + // better result + currentTop--; + } + facetQueries.add(dateFacet + ":[" + bottomYear + + " TO " + currentTop + "]"); + } + for (String facetQuery : facetQueries) + { + queryArgs.addFacetQuery(facetQuery); + } + } + } + catch (Exception e) + { + log.error( + LogManager + .getHeader( + context, + "Error in discovery while setting up date facet range", + "date facet: " + dateFacet), e); + } + } + else + { + int facetLimit = facet.getFacetLimit(); + + int facetPage = UIUtil.getIntParameter(request, + facet.getIndexFieldName() + "_page"); + if (facetPage < 0) + { + facetPage = 0; + } + // at most all the user filters belong to this facet + int alreadySelected = userFilters.size(); + + // Add one to our facet limit to make sure that if + // we + // have more then the shown facets that we show our + // show + // more url + // add the already selected facet so to have a full + // top list + // if possible + queryArgs.addFacetField(new DiscoverFacetField(facet + .getIndexFieldName(), + DiscoveryConfigurationParameters.TYPE_TEXT, + facetLimit + 1 + alreadySelected, facet + .getSortOrder(), facetPage * facetLimit)); + } + } + } + } + + public static List getFilters(HttpServletRequest request) + { + String submit = UIUtil.getSubmitButton(request, "submit"); + int ignore = -1; + if (submit.startsWith("submit_filter_remove_")) + { + ignore = Integer.parseInt(submit.substring("submit_filter_remove_".length())); + } + List appliedFilters = new ArrayList(); + + List filterValue = new ArrayList(); + List filterOp = new ArrayList(); + List filterField = new ArrayList(); + for (int idx = 1; ; idx++) + { + String op = request.getParameter("filter_type_"+idx); + if (StringUtils.isBlank(op)) + { + break; + } + else if (idx != ignore) + { + filterOp.add(op); + filterField.add(request.getParameter("filter_field_"+idx)); + filterValue.add(request.getParameter("filter_value_"+idx)); + } + } + + String op = request.getParameter("filtertype"); + if (StringUtils.isNotBlank(op)) + { + filterOp.add(op); + filterField.add(request.getParameter("filtername")); + filterValue.add(request.getParameter("filterquery")); + } + + for (int idx = 0; idx < filterOp.size(); idx++) + { + appliedFilters.add(new String[] { filterField.get(idx), + filterOp.get(idx), filterValue.get(idx) }); + } + return appliedFilters; + } + + // /** + // * Build the query from the advanced search form + // * + // * @param request + // * @return + // */ + // public static String buildQuery(HttpServletRequest request) + // { + // int num_field = UIUtil.getIntParameter(request, "num_search_field"); + // if (num_field <= 0) + // { + // num_field = 3; + // } + // StringBuffer query = new StringBuffer(); + // buildQueryPart(query, request.getParameter("field"), + // request.getParameter("query"), null); + // for (int i = 1; i < num_field; i++) + // { + // buildQueryPart(query, request.getParameter("field" + i), + // request.getParameter("query" + i), + // request.getParameter("conjuction" + i)); + // } + // return query.toString(); + // } + // + // private static void buildQueryPart(StringBuffer currQuery, String field, + // String queryPart, String conjuction) + // { + // if (StringUtils.isBlank(queryPart)) + // { + // return; + // } + // else + // { + // StringBuffer tmp = new StringBuffer(queryPart); + // if (StringUtils.isNotBlank(field)) + // { + // tmp.insert(0, field + ":(").append(")"); + // } + // + // if (StringUtils.isNotBlank(conjuction) && currQuery.length() > 0) + // { + // currQuery.append(conjuction); + // } + // currQuery.append(tmp); + // } + // } + +} diff --git a/dspace-discovery/dspace-discovery-jspui-api/src/main/java/org/dspace/app/webui/discovery/DiscoveryJSONRequest.java b/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/discovery/DiscoveryJSONRequest.java similarity index 97% rename from dspace-discovery/dspace-discovery-jspui-api/src/main/java/org/dspace/app/webui/discovery/DiscoveryJSONRequest.java rename to dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/discovery/DiscoveryJSONRequest.java index 94723d59b8..a1c69fa554 100644 --- a/dspace-discovery/dspace-discovery-jspui-api/src/main/java/org/dspace/app/webui/discovery/DiscoveryJSONRequest.java +++ b/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/discovery/DiscoveryJSONRequest.java @@ -1,82 +1,82 @@ -/** - * 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.webui.discovery; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.dspace.app.webui.json.JSONRequest; -import org.dspace.authorize.AuthorizeException; -import org.dspace.content.DSpaceObject; -import org.dspace.core.Context; -import org.dspace.discovery.DiscoverQuery; -import org.dspace.discovery.DiscoverResult; -import org.dspace.discovery.DiscoverResult.FacetResult; -import org.dspace.discovery.SearchUtils; - -import flexjson.JSONSerializer; - -public class DiscoveryJSONRequest extends JSONRequest -{ - - public void doJSONRequest(Context context, HttpServletRequest request, - HttpServletResponse resp) throws AuthorizeException, IOException - { - String reqPath = request.getPathInfo(); - // remove the first slash if present - if (reqPath.startsWith("/")) - { - reqPath = reqPath.substring(1); - } - - if (reqPath.equalsIgnoreCase(getSubPath() + "/autocomplete")) - { - doAutocomplete(context, request, resp); - return; - } - // unkwon action (in future we can implement ajax for pagination, etc.) - resp.sendError(HttpServletResponse.SC_NOT_FOUND); - return; - } - - private void doAutocomplete(Context context, HttpServletRequest request, - HttpServletResponse resp) - { - try - { - DSpaceObject scope = DiscoverUtility.getSearchScope(context, - request); - DiscoverQuery autocompleteQuery = DiscoverUtility - .getDiscoverAutocomplete(context, request, scope); - DiscoverResult qResults = SearchUtils.getSearchService().search( - context, autocompleteQuery); - // extract the only facet present in the result response - Set facets = qResults.getFacetResults().keySet(); - List fResults = new ArrayList(); - if (facets != null && facets.size() > 0) - { - String autocompleteField = (String) facets.toArray()[0]; - fResults = qResults - .getFacetResult(autocompleteField); - } - JSONSerializer serializer = new JSONSerializer(); - serializer.rootName("autocomplete"); - serializer.exclude("class","asFilterQuery"); - serializer.deepSerialize(fResults, resp.getWriter()); - } - catch (Exception e) - { - throw new RuntimeException(e.getMessage(), e); - } - } -} +/** + * 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.webui.discovery; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; +import java.util.Set; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.dspace.app.webui.json.JSONRequest; +import org.dspace.authorize.AuthorizeException; +import org.dspace.content.DSpaceObject; +import org.dspace.core.Context; +import org.dspace.discovery.DiscoverQuery; +import org.dspace.discovery.DiscoverResult; +import org.dspace.discovery.DiscoverResult.FacetResult; +import org.dspace.discovery.SearchUtils; + +import flexjson.JSONSerializer; + +public class DiscoveryJSONRequest extends JSONRequest +{ + + public void doJSONRequest(Context context, HttpServletRequest request, + HttpServletResponse resp) throws AuthorizeException, IOException + { + String reqPath = request.getPathInfo(); + // remove the first slash if present + if (reqPath.startsWith("/")) + { + reqPath = reqPath.substring(1); + } + + if (reqPath.equalsIgnoreCase(getSubPath() + "/autocomplete")) + { + doAutocomplete(context, request, resp); + return; + } + // unkwon action (in future we can implement ajax for pagination, etc.) + resp.sendError(HttpServletResponse.SC_NOT_FOUND); + return; + } + + private void doAutocomplete(Context context, HttpServletRequest request, + HttpServletResponse resp) + { + try + { + DSpaceObject scope = DiscoverUtility.getSearchScope(context, + request); + DiscoverQuery autocompleteQuery = DiscoverUtility + .getDiscoverAutocomplete(context, request, scope); + DiscoverResult qResults = SearchUtils.getSearchService().search( + context, autocompleteQuery); + // extract the only facet present in the result response + Set facets = qResults.getFacetResults().keySet(); + List fResults = new ArrayList(); + if (facets != null && facets.size() > 0) + { + String autocompleteField = (String) facets.toArray()[0]; + fResults = qResults + .getFacetResult(autocompleteField); + } + JSONSerializer serializer = new JSONSerializer(); + serializer.rootName("autocomplete"); + serializer.exclude("class","asFilterQuery"); + serializer.deepSerialize(fResults, resp.getWriter()); + } + catch (Exception e) + { + throw new RuntimeException(e.getMessage(), e); + } + } +} diff --git a/dspace-discovery/dspace-discovery-jspui-api/src/main/java/org/dspace/app/webui/discovery/DiscoverySearchRequestProcessor.java b/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/discovery/DiscoverySearchRequestProcessor.java similarity index 97% rename from dspace-discovery/dspace-discovery-jspui-api/src/main/java/org/dspace/app/webui/discovery/DiscoverySearchRequestProcessor.java rename to dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/discovery/DiscoverySearchRequestProcessor.java index 15536b5e21..fa5113f4ed 100644 --- a/dspace-discovery/dspace-discovery-jspui-api/src/main/java/org/dspace/app/webui/discovery/DiscoverySearchRequestProcessor.java +++ b/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/discovery/DiscoverySearchRequestProcessor.java @@ -1,484 +1,483 @@ -/** - * 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.webui.discovery; - -import java.io.IOException; -import java.io.PrintWriter; -import java.sql.SQLException; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; -import java.util.Locale; -import java.util.Map; -import java.util.ResourceBundle; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.xml.transform.Transformer; -import javax.xml.transform.TransformerException; -import javax.xml.transform.TransformerFactory; -import javax.xml.transform.dom.DOMSource; -import javax.xml.transform.stream.StreamResult; - -import org.apache.log4j.Logger; -import org.dspace.app.bulkedit.DSpaceCSV; -import org.dspace.app.bulkedit.MetadataExport; -import org.dspace.app.util.OpenSearch; -import org.dspace.app.util.SyndicationFeed; -import org.dspace.app.webui.search.SearchProcessorException; -import org.dspace.app.webui.search.SearchRequestProcessor; -import org.dspace.app.webui.util.JSPManager; -import org.dspace.app.webui.util.UIUtil; -import org.dspace.authorize.AuthorizeManager; -import org.dspace.content.Collection; -import org.dspace.content.Community; -import org.dspace.content.DSpaceObject; -import org.dspace.content.Item; -import org.dspace.content.ItemIterator; -import org.dspace.core.ConfigurationManager; -import org.dspace.core.Context; -import org.dspace.core.I18nUtil; -import org.dspace.core.LogManager; -import org.dspace.discovery.DiscoverQuery; -import org.dspace.discovery.DiscoverResult; -import org.dspace.discovery.SearchServiceException; -import org.dspace.discovery.SearchUtils; -import org.dspace.discovery.configuration.DiscoveryConfiguration; -import org.dspace.discovery.configuration.DiscoverySearchFilter; -import org.dspace.discovery.configuration.DiscoverySearchFilterFacet; -import org.dspace.discovery.configuration.DiscoverySortFieldConfiguration; -import org.w3c.dom.Document; - -public class DiscoverySearchRequestProcessor implements SearchRequestProcessor -{ - private static String msgKey = "org.dspace.app.webui.servlet.FeedServlet"; - - /** log4j category */ - private static Logger log = Logger.getLogger(DiscoverySearchRequestProcessor.class); - - // locale-sensitive metadata labels - private Map> localeLabels = null; - - public synchronized void init() - { - if (localeLabels == null) - { - localeLabels = new HashMap>(); - } - } - - public void doOpenSearch(Context context, HttpServletRequest request, - HttpServletResponse response) throws SearchProcessorException, - IOException, ServletException - { - init(); - - // dispense with simple service document requests - String scope = request.getParameter("scope"); - if (scope != null && "".equals(scope)) - { - scope = null; - } - String path = request.getPathInfo(); - if (path != null && path.endsWith("description.xml")) - { - String svcDescrip = OpenSearch.getDescription(scope); - response.setContentType(OpenSearch - .getContentType("opensearchdescription")); - response.setContentLength(svcDescrip.length()); - response.getWriter().write(svcDescrip); - return; - } - - // get enough request parameters to decide on action to take - String format = request.getParameter("format"); - if (format == null || "".equals(format)) - { - // default to atom - format = "atom"; - } - - // do some sanity checking - if (!OpenSearch.getFormats().contains(format)) - { - response.sendError(HttpServletResponse.SC_BAD_REQUEST); - return; - } - - // then the rest - we are processing the query - DSpaceObject container; - try - { - container = DiscoverUtility.getSearchScope(context, - request); - } - catch (Exception e) - { - throw new SearchProcessorException(e.getMessage(), e); - } - DiscoverQuery queryArgs = DiscoverUtility.getDiscoverQuery(context, - request, container, false); - String query = queryArgs.getQuery(); - - // Perform the search - DiscoverResult qResults = null; - try - { - qResults = SearchUtils.getSearchService().search(context, - container, queryArgs); - } - catch (SearchServiceException e) - { - log.error( - LogManager.getHeader(context, "opensearch", "query=" - + queryArgs.getQuery() + ",scope=" + scope - + ",error=" + e.getMessage()), e); - throw new RuntimeException(e.getMessage(), e); - } - - // Log - log.info(LogManager.getHeader(context, "opensearch", - "scope=" + scope + ",query=\"" + query + "\",results=(" - + qResults.getTotalSearchResults() + ")")); - - // format and return results - Map labelMap = getLabels(request); - DSpaceObject[] dsoResults = new DSpaceObject[qResults - .getDspaceObjects().size()]; - qResults.getDspaceObjects().toArray(dsoResults); - Document resultsDoc = OpenSearch.getResultsDoc(format, query, - (int)qResults.getTotalSearchResults(), qResults.getStart(), - qResults.getMaxResults(), container, dsoResults, labelMap); - try - { - Transformer xf = TransformerFactory.newInstance().newTransformer(); - response.setContentType(OpenSearch.getContentType(format)); - xf.transform(new DOMSource(resultsDoc), - new StreamResult(response.getWriter())); - } - catch (TransformerException e) - { - log.error(e); - throw new ServletException(e.toString()); - } - } - - private Map getLabels(HttpServletRequest request) - { - // Get access to the localized resource bundle - Locale locale = UIUtil.getSessionLocale(request); - Map labelMap = localeLabels.get(locale.toString()); - if (labelMap == null) - { - labelMap = getLocaleLabels(locale); - localeLabels.put(locale.toString(), labelMap); - } - return labelMap; - } - - private Map getLocaleLabels(Locale locale) - { - Map labelMap = new HashMap(); - labelMap.put(SyndicationFeed.MSG_UNTITLED, I18nUtil.getMessage(msgKey + ".notitle", locale)); - labelMap.put(SyndicationFeed.MSG_LOGO_TITLE, I18nUtil.getMessage(msgKey + ".logo.title", locale)); - labelMap.put(SyndicationFeed.MSG_FEED_DESCRIPTION, I18nUtil.getMessage(msgKey + ".general-feed.description", locale)); - labelMap.put(SyndicationFeed.MSG_UITYPE, SyndicationFeed.UITYPE_JSPUI); - for (String selector : SyndicationFeed.getDescriptionSelectors()) - { - labelMap.put("metadata." + selector, I18nUtil.getMessage(SyndicationFeed.MSG_METADATA + selector, locale)); - } - return labelMap; - } - - public void doSimpleSearch(Context context, HttpServletRequest request, - HttpServletResponse response) throws SearchProcessorException, - IOException, ServletException - { - Item[] resultsItems; - Collection[] resultsCollections; - Community[] resultsCommunities; - DSpaceObject scope; - try - { - scope = DiscoverUtility.getSearchScope(context, request); - } - catch (IllegalStateException e) - { - throw new SearchProcessorException(e.getMessage(), e); - } - catch (SQLException e) - { - throw new SearchProcessorException(e.getMessage(), e); - } - - DiscoveryConfiguration discoveryConfiguration = SearchUtils - .getDiscoveryConfiguration(scope); - List sortFields = discoveryConfiguration - .getSearchSortConfiguration().getSortFields(); - List sortOptions = new ArrayList(); - for (DiscoverySortFieldConfiguration sortFieldConfiguration : sortFields) - { - String sortField = SearchUtils.getSearchService().toSortFieldIndex( - sortFieldConfiguration.getMetadataField(), - sortFieldConfiguration.getType()); - sortOptions.add(sortField); - } - request.setAttribute("sortOptions", sortOptions); - - DiscoverQuery queryArgs = DiscoverUtility.getDiscoverQuery(context, - request, scope, true); - - List availableFacet = discoveryConfiguration - .getSidebarFacets(); - - request.setAttribute("facetsConfig", - availableFacet != null ? availableFacet - : new ArrayList()); - int etal = UIUtil.getIntParameter(request, "etal"); - if (etal == -1) - { - etal = ConfigurationManager - .getIntProperty("webui.itemlist.author-limit"); - } - - request.setAttribute("etal", etal); - - String query = queryArgs.getQuery(); - request.setAttribute("query", query); - request.setAttribute("queryArgs", queryArgs); - List availableFilters = discoveryConfiguration - .getSearchFilters(); - request.setAttribute("availableFilters", availableFilters); - - List appliedFilters = DiscoverUtility.getFilters(request); - request.setAttribute("appliedFilters", appliedFilters); - List appliedFilterQueries = new ArrayList(); - for (String[] filter : appliedFilters) - { - appliedFilterQueries.add(filter[0] + "::" + filter[1] + "::" - + filter[2]); - } - request.setAttribute("appliedFilterQueries", appliedFilterQueries); - List scopes = new ArrayList(); - if (scope == null) - { - Community[] topCommunities; - try - { - topCommunities = Community.findAllTop(context); - } - catch (SQLException e) - { - throw new SearchProcessorException(e.getMessage(), e); - } - for (Community com : topCommunities) - { - scopes.add(com); - } - } - else - { - try - { - DSpaceObject pDso = scope.getParentObject(); - while (pDso != null) - { - // add to the available scopes in reverse order - scopes.add(0, pDso); - pDso = pDso.getParentObject(); - } - scopes.add(scope); - if (scope instanceof Community) - { - Community[] comms = ((Community) scope).getSubcommunities(); - for (Community com : comms) - { - scopes.add(com); - } - Collection[] colls = ((Community) scope).getCollections(); - for (Collection col : colls) - { - scopes.add(col); - } - } - } - catch (SQLException e) - { - throw new SearchProcessorException(e.getMessage(), e); - } - } - request.setAttribute("scope", scope); - request.setAttribute("scopes", scopes); - - // Perform the search - DiscoverResult qResults = null; - try - { - qResults = SearchUtils.getSearchService().search(context, scope, - queryArgs); - List resultsListComm = new ArrayList(); - List resultsListColl = new ArrayList(); - List resultsListItem = new ArrayList(); - - for (DSpaceObject dso : qResults.getDspaceObjects()) - { - if (dso instanceof Item) - { - resultsListItem.add((Item) dso); - } - else if (dso instanceof Collection) - { - resultsListColl.add((Collection) dso); - - } - else if (dso instanceof Community) - { - resultsListComm.add((Community) dso); - } - } - - // Make objects from the handles - make arrays, fill them out - resultsCommunities = new Community[resultsListComm.size()]; - resultsCollections = new Collection[resultsListColl.size()]; - resultsItems = new Item[resultsListItem.size()]; - - resultsCommunities = resultsListComm.toArray(resultsCommunities); - resultsCollections = resultsListColl.toArray(resultsCollections); - resultsItems = resultsListItem.toArray(resultsItems); - - // Log - log.info(LogManager.getHeader(context, "search", "scope=" + scope - + ",query=\"" + query + "\",results=(" - + resultsCommunities.length + "," - + resultsCollections.length + "," + resultsItems.length - + ")")); - - // Pass in some page qualities - // total number of pages - long pageTotal = 1 + ((qResults.getTotalSearchResults() - 1) / qResults - .getMaxResults()); - - // current page being displayed - long pageCurrent = 1 + (qResults.getStart() / qResults - .getMaxResults()); - - // pageLast = min(pageCurrent+3,pageTotal) - long pageLast = ((pageCurrent + 3) > pageTotal) ? pageTotal - : (pageCurrent + 3); - - // pageFirst = max(1,pageCurrent-3) - long pageFirst = ((pageCurrent - 3) > 1) ? (pageCurrent - 3) : 1; - - // Pass the results to the display JSP - request.setAttribute("items", resultsItems); - request.setAttribute("communities", resultsCommunities); - request.setAttribute("collections", resultsCollections); - - request.setAttribute("pagetotal", new Long(pageTotal)); - request.setAttribute("pagecurrent", new Long(pageCurrent)); - request.setAttribute("pagelast", new Long(pageLast)); - request.setAttribute("pagefirst", new Long(pageFirst)); - - request.setAttribute("queryresults", qResults); - - try - { - if (AuthorizeManager.isAdmin(context)) - { - // Set a variable to create admin buttons - request.setAttribute("admin_button", new Boolean(true)); - } - } - catch (SQLException e) - { - throw new SearchProcessorException(e.getMessage(), e); } - - if ("submit_export_metadata".equals(UIUtil.getSubmitButton(request, - "submit"))) - { - exportMetadata(context, response, resultsItems); - } - } - catch (SearchServiceException e) - { - log.error( - LogManager.getHeader(context, "search", "query=" - + queryArgs.getQuery() + ",scope=" + scope - + ",error=" + e.getMessage()), e); - request.setAttribute("search.error", true); - request.setAttribute("search.error.message", e.getMessage()); - } - - JSPManager.showJSP(request, response, "/search/discovery.jsp"); - } - - /** - * Export the search results as a csv file - * - * @param context - * The DSpace context - * @param response - * The request object - * @param items - * The result items - * @throws IOException - * @throws ServletException - */ - protected void exportMetadata(Context context, - HttpServletResponse response, Item[] items) throws IOException, - ServletException - { - // Log the attempt - log.info(LogManager.getHeader(context, "metadataexport", - "exporting_search")); - - // Export a search view - ArrayList iids = new ArrayList(); - for (Item item : items) - { - iids.add(item.getID()); - } - ItemIterator ii = new ItemIterator(context, iids); - MetadataExport exporter = new MetadataExport(context, ii, false); - - // Perform the export - DSpaceCSV csv = exporter.export(); - - // Return the csv file - response.setContentType("text/csv; charset=UTF-8"); - response.setHeader("Content-Disposition", - "attachment; filename=search-results.csv"); - PrintWriter out = response.getWriter(); - out.write(csv.toString()); - out.flush(); - out.close(); - log.info(LogManager.getHeader(context, "metadataexport", - "exported_file:search-results.csv")); - return; - } - - /** - * Method for constructing the discovery advanced search form - * - * @author Andrea Bollini - */ - @Override - public void doAdvancedSearch(Context context, HttpServletRequest request, - HttpServletResponse response) throws SearchProcessorException, - IOException, ServletException - { - // just redirect to the simple search servlet. - // The advanced form is always displayed with Discovery togheter with - // the search result - // the first access to the advanced form performs a search for - // "anythings" (SOLR *:*) - response.sendRedirect(request.getContextPath() + "/simple-search"); - } - -} +/** + * 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.webui.discovery; + +import java.io.IOException; +import java.io.PrintWriter; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Locale; +import java.util.Map; + +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerException; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.apache.log4j.Logger; +import org.dspace.app.bulkedit.DSpaceCSV; +import org.dspace.app.bulkedit.MetadataExport; +import org.dspace.app.util.OpenSearch; +import org.dspace.app.util.SyndicationFeed; +import org.dspace.app.webui.search.SearchProcessorException; +import org.dspace.app.webui.search.SearchRequestProcessor; +import org.dspace.app.webui.util.JSPManager; +import org.dspace.app.webui.util.UIUtil; +import org.dspace.authorize.AuthorizeManager; +import org.dspace.content.Collection; +import org.dspace.content.Community; +import org.dspace.content.DSpaceObject; +import org.dspace.content.Item; +import org.dspace.content.ItemIterator; +import org.dspace.core.ConfigurationManager; +import org.dspace.core.Context; +import org.dspace.core.I18nUtil; +import org.dspace.core.LogManager; +import org.dspace.discovery.DiscoverQuery; +import org.dspace.discovery.DiscoverResult; +import org.dspace.discovery.SearchServiceException; +import org.dspace.discovery.SearchUtils; +import org.dspace.discovery.configuration.DiscoveryConfiguration; +import org.dspace.discovery.configuration.DiscoverySearchFilter; +import org.dspace.discovery.configuration.DiscoverySearchFilterFacet; +import org.dspace.discovery.configuration.DiscoverySortFieldConfiguration; +import org.w3c.dom.Document; + +public class DiscoverySearchRequestProcessor implements SearchRequestProcessor +{ + private static String msgKey = "org.dspace.app.webui.servlet.FeedServlet"; + + /** log4j category */ + private static Logger log = Logger.getLogger(DiscoverySearchRequestProcessor.class); + + // locale-sensitive metadata labels + private Map> localeLabels = null; + + public synchronized void init() + { + if (localeLabels == null) + { + localeLabels = new HashMap>(); + } + } + + public void doOpenSearch(Context context, HttpServletRequest request, + HttpServletResponse response) throws SearchProcessorException, + IOException, ServletException + { + init(); + + // dispense with simple service document requests + String scope = request.getParameter("scope"); + if (scope != null && "".equals(scope)) + { + scope = null; + } + String path = request.getPathInfo(); + if (path != null && path.endsWith("description.xml")) + { + String svcDescrip = OpenSearch.getDescription(scope); + response.setContentType(OpenSearch + .getContentType("opensearchdescription")); + response.setContentLength(svcDescrip.length()); + response.getWriter().write(svcDescrip); + return; + } + + // get enough request parameters to decide on action to take + String format = request.getParameter("format"); + if (format == null || "".equals(format)) + { + // default to atom + format = "atom"; + } + + // do some sanity checking + if (!OpenSearch.getFormats().contains(format)) + { + response.sendError(HttpServletResponse.SC_BAD_REQUEST); + return; + } + + // then the rest - we are processing the query + DSpaceObject container; + try + { + container = DiscoverUtility.getSearchScope(context, + request); + } + catch (Exception e) + { + throw new SearchProcessorException(e.getMessage(), e); + } + DiscoverQuery queryArgs = DiscoverUtility.getDiscoverQuery(context, + request, container, false); + String query = queryArgs.getQuery(); + + // Perform the search + DiscoverResult qResults = null; + try + { + qResults = SearchUtils.getSearchService().search(context, + container, queryArgs); + } + catch (SearchServiceException e) + { + log.error( + LogManager.getHeader(context, "opensearch", "query=" + + queryArgs.getQuery() + ",scope=" + scope + + ",error=" + e.getMessage()), e); + throw new RuntimeException(e.getMessage(), e); + } + + // Log + log.info(LogManager.getHeader(context, "opensearch", + "scope=" + scope + ",query=\"" + query + "\",results=(" + + qResults.getTotalSearchResults() + ")")); + + // format and return results + Map labelMap = getLabels(request); + DSpaceObject[] dsoResults = new DSpaceObject[qResults + .getDspaceObjects().size()]; + qResults.getDspaceObjects().toArray(dsoResults); + Document resultsDoc = OpenSearch.getResultsDoc(format, query, + (int)qResults.getTotalSearchResults(), qResults.getStart(), + qResults.getMaxResults(), container, dsoResults, labelMap); + try + { + Transformer xf = TransformerFactory.newInstance().newTransformer(); + response.setContentType(OpenSearch.getContentType(format)); + xf.transform(new DOMSource(resultsDoc), + new StreamResult(response.getWriter())); + } + catch (TransformerException e) + { + log.error(e); + throw new ServletException(e.toString()); + } + } + + private Map getLabels(HttpServletRequest request) + { + // Get access to the localized resource bundle + Locale locale = UIUtil.getSessionLocale(request); + Map labelMap = localeLabels.get(locale.toString()); + if (labelMap == null) + { + labelMap = getLocaleLabels(locale); + localeLabels.put(locale.toString(), labelMap); + } + return labelMap; + } + + private Map getLocaleLabels(Locale locale) + { + Map labelMap = new HashMap(); + labelMap.put(SyndicationFeed.MSG_UNTITLED, I18nUtil.getMessage(msgKey + ".notitle", locale)); + labelMap.put(SyndicationFeed.MSG_LOGO_TITLE, I18nUtil.getMessage(msgKey + ".logo.title", locale)); + labelMap.put(SyndicationFeed.MSG_FEED_DESCRIPTION, I18nUtil.getMessage(msgKey + ".general-feed.description", locale)); + labelMap.put(SyndicationFeed.MSG_UITYPE, SyndicationFeed.UITYPE_JSPUI); + for (String selector : SyndicationFeed.getDescriptionSelectors()) + { + labelMap.put("metadata." + selector, I18nUtil.getMessage(SyndicationFeed.MSG_METADATA + selector, locale)); + } + return labelMap; + } + + public void doSimpleSearch(Context context, HttpServletRequest request, + HttpServletResponse response) throws SearchProcessorException, + IOException, ServletException + { + Item[] resultsItems; + Collection[] resultsCollections; + Community[] resultsCommunities; + DSpaceObject scope; + try + { + scope = DiscoverUtility.getSearchScope(context, request); + } + catch (IllegalStateException e) + { + throw new SearchProcessorException(e.getMessage(), e); + } + catch (SQLException e) + { + throw new SearchProcessorException(e.getMessage(), e); + } + + DiscoveryConfiguration discoveryConfiguration = SearchUtils + .getDiscoveryConfiguration(scope); + List sortFields = discoveryConfiguration + .getSearchSortConfiguration().getSortFields(); + List sortOptions = new ArrayList(); + for (DiscoverySortFieldConfiguration sortFieldConfiguration : sortFields) + { + String sortField = SearchUtils.getSearchService().toSortFieldIndex( + sortFieldConfiguration.getMetadataField(), + sortFieldConfiguration.getType()); + sortOptions.add(sortField); + } + request.setAttribute("sortOptions", sortOptions); + + DiscoverQuery queryArgs = DiscoverUtility.getDiscoverQuery(context, + request, scope, true); + + List availableFacet = discoveryConfiguration + .getSidebarFacets(); + + request.setAttribute("facetsConfig", + availableFacet != null ? availableFacet + : new ArrayList()); + int etal = UIUtil.getIntParameter(request, "etal"); + if (etal == -1) + { + etal = ConfigurationManager + .getIntProperty("webui.itemlist.author-limit"); + } + + request.setAttribute("etal", etal); + + String query = queryArgs.getQuery(); + request.setAttribute("query", query); + request.setAttribute("queryArgs", queryArgs); + List availableFilters = discoveryConfiguration + .getSearchFilters(); + request.setAttribute("availableFilters", availableFilters); + + List appliedFilters = DiscoverUtility.getFilters(request); + request.setAttribute("appliedFilters", appliedFilters); + List appliedFilterQueries = new ArrayList(); + for (String[] filter : appliedFilters) + { + appliedFilterQueries.add(filter[0] + "::" + filter[1] + "::" + + filter[2]); + } + request.setAttribute("appliedFilterQueries", appliedFilterQueries); + List scopes = new ArrayList(); + if (scope == null) + { + Community[] topCommunities; + try + { + topCommunities = Community.findAllTop(context); + } + catch (SQLException e) + { + throw new SearchProcessorException(e.getMessage(), e); + } + for (Community com : topCommunities) + { + scopes.add(com); + } + } + else + { + try + { + DSpaceObject pDso = scope.getParentObject(); + while (pDso != null) + { + // add to the available scopes in reverse order + scopes.add(0, pDso); + pDso = pDso.getParentObject(); + } + scopes.add(scope); + if (scope instanceof Community) + { + Community[] comms = ((Community) scope).getSubcommunities(); + for (Community com : comms) + { + scopes.add(com); + } + Collection[] colls = ((Community) scope).getCollections(); + for (Collection col : colls) + { + scopes.add(col); + } + } + } + catch (SQLException e) + { + throw new SearchProcessorException(e.getMessage(), e); + } + } + request.setAttribute("scope", scope); + request.setAttribute("scopes", scopes); + + // Perform the search + DiscoverResult qResults = null; + try + { + qResults = SearchUtils.getSearchService().search(context, scope, + queryArgs); + List resultsListComm = new ArrayList(); + List resultsListColl = new ArrayList(); + List resultsListItem = new ArrayList(); + + for (DSpaceObject dso : qResults.getDspaceObjects()) + { + if (dso instanceof Item) + { + resultsListItem.add((Item) dso); + } + else if (dso instanceof Collection) + { + resultsListColl.add((Collection) dso); + + } + else if (dso instanceof Community) + { + resultsListComm.add((Community) dso); + } + } + + // Make objects from the handles - make arrays, fill them out + resultsCommunities = new Community[resultsListComm.size()]; + resultsCollections = new Collection[resultsListColl.size()]; + resultsItems = new Item[resultsListItem.size()]; + + resultsCommunities = resultsListComm.toArray(resultsCommunities); + resultsCollections = resultsListColl.toArray(resultsCollections); + resultsItems = resultsListItem.toArray(resultsItems); + + // Log + log.info(LogManager.getHeader(context, "search", "scope=" + scope + + ",query=\"" + query + "\",results=(" + + resultsCommunities.length + "," + + resultsCollections.length + "," + resultsItems.length + + ")")); + + // Pass in some page qualities + // total number of pages + long pageTotal = 1 + ((qResults.getTotalSearchResults() - 1) / qResults + .getMaxResults()); + + // current page being displayed + long pageCurrent = 1 + (qResults.getStart() / qResults + .getMaxResults()); + + // pageLast = min(pageCurrent+3,pageTotal) + long pageLast = ((pageCurrent + 3) > pageTotal) ? pageTotal + : (pageCurrent + 3); + + // pageFirst = max(1,pageCurrent-3) + long pageFirst = ((pageCurrent - 3) > 1) ? (pageCurrent - 3) : 1; + + // Pass the results to the display JSP + request.setAttribute("items", resultsItems); + request.setAttribute("communities", resultsCommunities); + request.setAttribute("collections", resultsCollections); + + request.setAttribute("pagetotal", new Long(pageTotal)); + request.setAttribute("pagecurrent", new Long(pageCurrent)); + request.setAttribute("pagelast", new Long(pageLast)); + request.setAttribute("pagefirst", new Long(pageFirst)); + + request.setAttribute("queryresults", qResults); + + try + { + if (AuthorizeManager.isAdmin(context)) + { + // Set a variable to create admin buttons + request.setAttribute("admin_button", new Boolean(true)); + } + } + catch (SQLException e) + { + throw new SearchProcessorException(e.getMessage(), e); } + + if ("submit_export_metadata".equals(UIUtil.getSubmitButton(request, + "submit"))) + { + exportMetadata(context, response, resultsItems); + } + } + catch (SearchServiceException e) + { + log.error( + LogManager.getHeader(context, "search", "query=" + + queryArgs.getQuery() + ",scope=" + scope + + ",error=" + e.getMessage()), e); + request.setAttribute("search.error", true); + request.setAttribute("search.error.message", e.getMessage()); + } + + JSPManager.showJSP(request, response, "/search/discovery.jsp"); + } + + /** + * Export the search results as a csv file + * + * @param context + * The DSpace context + * @param response + * The request object + * @param items + * The result items + * @throws IOException + * @throws ServletException + */ + protected void exportMetadata(Context context, + HttpServletResponse response, Item[] items) throws IOException, + ServletException + { + // Log the attempt + log.info(LogManager.getHeader(context, "metadataexport", + "exporting_search")); + + // Export a search view + ArrayList iids = new ArrayList(); + for (Item item : items) + { + iids.add(item.getID()); + } + ItemIterator ii = new ItemIterator(context, iids); + MetadataExport exporter = new MetadataExport(context, ii, false); + + // Perform the export + DSpaceCSV csv = exporter.export(); + + // Return the csv file + response.setContentType("text/csv; charset=UTF-8"); + response.setHeader("Content-Disposition", + "attachment; filename=search-results.csv"); + PrintWriter out = response.getWriter(); + out.write(csv.toString()); + out.flush(); + out.close(); + log.info(LogManager.getHeader(context, "metadataexport", + "exported_file:search-results.csv")); + return; + } + + /** + * Method for constructing the discovery advanced search form + * + * @author Andrea Bollini + */ + @Override + public void doAdvancedSearch(Context context, HttpServletRequest request, + HttpServletResponse response) throws SearchProcessorException, + IOException, ServletException + { + // just redirect to the simple search servlet. + // The advanced form is always displayed with Discovery togheter with + // the search result + // the first access to the advanced form performs a search for + // "anythings" (SOLR *:*) + response.sendRedirect(request.getContextPath() + "/simple-search"); + } + +} diff --git a/dspace-discovery/dspace-discovery-jspui-api/src/main/java/org/dspace/app/webui/discovery/SideBarFacetProcessor.java b/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/discovery/SideBarFacetProcessor.java similarity index 97% rename from dspace-discovery/dspace-discovery-jspui-api/src/main/java/org/dspace/app/webui/discovery/SideBarFacetProcessor.java rename to dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/discovery/SideBarFacetProcessor.java index d7cda10f24..87f2f03030 100644 --- a/dspace-discovery/dspace-discovery-jspui-api/src/main/java/org/dspace/app/webui/discovery/SideBarFacetProcessor.java +++ b/dspace-jspui/dspace-jspui-api/src/main/java/org/dspace/app/webui/discovery/SideBarFacetProcessor.java @@ -1,97 +1,97 @@ -/** - * 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.webui.discovery; - -import java.util.ArrayList; -import java.util.List; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.log4j.Logger; -import org.dspace.authorize.AuthorizeException; -import org.dspace.content.Collection; -import org.dspace.content.Community; -import org.dspace.content.DSpaceObject; -import org.dspace.core.Context; -import org.dspace.core.LogManager; -import org.dspace.discovery.DiscoverQuery; -import org.dspace.discovery.DiscoverResult; -import org.dspace.discovery.SearchServiceException; -import org.dspace.discovery.SearchUtils; -import org.dspace.discovery.configuration.DiscoveryConfiguration; -import org.dspace.discovery.configuration.DiscoverySearchFilterFacet; -import org.dspace.plugin.CollectionHomeProcessor; -import org.dspace.plugin.CommunityHomeProcessor; -import org.dspace.plugin.PluginException; -import org.dspace.plugin.SiteHomeProcessor; - -public class SideBarFacetProcessor implements CollectionHomeProcessor, - CommunityHomeProcessor, SiteHomeProcessor -{ - /** log4j category */ - private static Logger log = Logger.getLogger(SideBarFacetProcessor.class); - - @Override - public void process(Context context, HttpServletRequest request, - HttpServletResponse response, Community community) - throws PluginException, AuthorizeException - { - process(context, request, response, (DSpaceObject) community); - } - - @Override - public void process(Context context, HttpServletRequest request, - HttpServletResponse response, Collection collection) - throws PluginException, AuthorizeException - { - process(context, request, response, (DSpaceObject) collection); - } - - @Override - public void process(Context context, HttpServletRequest request, - HttpServletResponse response) throws PluginException, - AuthorizeException - { - process(context, request, response, (DSpaceObject) null); - } - - private void process(Context context, HttpServletRequest request, - HttpServletResponse response, DSpaceObject scope) - { - DiscoverQuery queryArgs = DiscoverUtility.getDiscoverQuery(context, - request, scope, true); - queryArgs.setMaxResults(0); - DiscoverResult qResults; - try - { - qResults = SearchUtils.getSearchService().search(context, scope, - queryArgs); - request.setAttribute("discovery.fresults", - qResults.getFacetResults()); - DiscoveryConfiguration discoveryConfiguration = SearchUtils - .getDiscoveryConfiguration(scope); - List availableFacet = discoveryConfiguration - .getSidebarFacets(); - - request.setAttribute("facetsConfig", - availableFacet != null ? availableFacet - : new ArrayList()); - if (scope !=null) - { - request.setAttribute("discovery.searchScope", - "/handle/" + scope.getHandle()); - } - } - catch (SearchServiceException e) - { - log.error(LogManager.getHeader(context, - "discovery-process-sidebar", "scope=" + scope)); - } - } -} +/** + * 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.webui.discovery; + +import java.util.ArrayList; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.log4j.Logger; +import org.dspace.authorize.AuthorizeException; +import org.dspace.content.Collection; +import org.dspace.content.Community; +import org.dspace.content.DSpaceObject; +import org.dspace.core.Context; +import org.dspace.core.LogManager; +import org.dspace.discovery.DiscoverQuery; +import org.dspace.discovery.DiscoverResult; +import org.dspace.discovery.SearchServiceException; +import org.dspace.discovery.SearchUtils; +import org.dspace.discovery.configuration.DiscoveryConfiguration; +import org.dspace.discovery.configuration.DiscoverySearchFilterFacet; +import org.dspace.plugin.CollectionHomeProcessor; +import org.dspace.plugin.CommunityHomeProcessor; +import org.dspace.plugin.PluginException; +import org.dspace.plugin.SiteHomeProcessor; + +public class SideBarFacetProcessor implements CollectionHomeProcessor, + CommunityHomeProcessor, SiteHomeProcessor +{ + /** log4j category */ + private static Logger log = Logger.getLogger(SideBarFacetProcessor.class); + + @Override + public void process(Context context, HttpServletRequest request, + HttpServletResponse response, Community community) + throws PluginException, AuthorizeException + { + process(context, request, response, (DSpaceObject) community); + } + + @Override + public void process(Context context, HttpServletRequest request, + HttpServletResponse response, Collection collection) + throws PluginException, AuthorizeException + { + process(context, request, response, (DSpaceObject) collection); + } + + @Override + public void process(Context context, HttpServletRequest request, + HttpServletResponse response) throws PluginException, + AuthorizeException + { + process(context, request, response, (DSpaceObject) null); + } + + private void process(Context context, HttpServletRequest request, + HttpServletResponse response, DSpaceObject scope) + { + DiscoverQuery queryArgs = DiscoverUtility.getDiscoverQuery(context, + request, scope, true); + queryArgs.setMaxResults(0); + DiscoverResult qResults; + try + { + qResults = SearchUtils.getSearchService().search(context, scope, + queryArgs); + request.setAttribute("discovery.fresults", + qResults.getFacetResults()); + DiscoveryConfiguration discoveryConfiguration = SearchUtils + .getDiscoveryConfiguration(scope); + List availableFacet = discoveryConfiguration + .getSidebarFacets(); + + request.setAttribute("facetsConfig", + availableFacet != null ? availableFacet + : new ArrayList()); + if (scope !=null) + { + request.setAttribute("discovery.searchScope", + "/handle/" + scope.getHandle()); + } + } + catch (SearchServiceException e) + { + log.error(LogManager.getHeader(context, + "discovery-process-sidebar", "scope=" + scope)); + } + } +} diff --git a/dspace-discovery/dspace-discovery-jspui-webapp/src/main/webapp/css/discovery.css b/dspace-jspui/dspace-jspui-webapp/src/main/webapp/css/discovery.css similarity index 98% rename from dspace-discovery/dspace-discovery-jspui-webapp/src/main/webapp/css/discovery.css rename to dspace-jspui/dspace-jspui-webapp/src/main/webapp/css/discovery.css index 61519cd396..bf97df8403 100644 --- a/dspace-discovery/dspace-discovery-jspui-webapp/src/main/webapp/css/discovery.css +++ b/dspace-jspui/dspace-jspui-webapp/src/main/webapp/css/discovery.css @@ -1,34 +1,34 @@ -/** - * 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/ - */ -h3.facets {margin-left:0px;} -div.facetsBox {margin:2px;min-width: 180px;width: 180px;} -div.facetsBox ul {list-style: none; list-style-position: inside; padding:0px;} -div.facet {margin-left:0px;margin-right:0px;border: 1px solid #CCCCCC; padding: 5px;} -li.facet-next, li.facet-previous {margin-bottom:10px; margin-top:10px;font-weight: bold;} -li.facet-next {text-align: right;} -.facetName {font-weight: bold;} -div.discovery-query {border: 1px solid #CCCCCC;background-color: #EEEEEE;padding:10px;white-space: nowrap;} -div.discovery-query a {font-size: smaller;display: block;margin:2px;margin-left:5px;} -div.discovery-search-appliedFilters {margin-top: 10px; background-color: #FFFFFF; border: 1px solid #CCCCCC;padding:10px;} -div.discovery-search-appliedFilters span {font-weight: bold;display:block;margin-bottom:5px;} -div.discovery-query label {font-weight: bold;margin:5px;} -div.discovery-query select {margin-bottom:5px;} -div.discovery-search-filters{border: 1px solid #CCCCCC;padding:10px;} -div.discovery-search-filters span {display:block;margin:5px;} -div.discovery-search-filters span.discovery-search-filters-heading {font-weight: bold}; -div.discovery-search-filters select {margin:5px;} -div.discovery-pagination-controls {margin-top: 10px; background-color: #EEEEEE; border: 1px solid #CCCCCC;padding:10px;} - -.clearfix:after {clear: both;content: ".";display: block;height: 0;visibility: hidden;} -.pagination-masked.top {margin-top: 5px;} -div.discovery-result-pagination {margin: 20px;margin-bottom:0px;line-height: 1em;padding: 10px;vertical-align: middle;} -div.discovery-result-pagination h2.info, div.discovery-result-pagination p.info {float: left;margin:0px;} -div.discovery-result-pagination ul.links {float: right;margin:0px;list-style: none outside none;} -div.discovery-result-pagination ul.links li {display: inline; padding-left: 2px; padding-right: 2px;} -.current-page-link {color: #CCCCCC;font-weight: bold;} -div.discovery-result-results {padding:10px;} +/** + * 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/ + */ +h3.facets {margin-left:0px;} +div.facetsBox {margin:2px;min-width: 180px;width: 180px;} +div.facetsBox ul {list-style: none; list-style-position: inside; padding:0px;} +div.facet {margin-left:0px;margin-right:0px;border: 1px solid #CCCCCC; padding: 5px;} +li.facet-next, li.facet-previous {margin-bottom:10px; margin-top:10px;font-weight: bold;} +li.facet-next {text-align: right;} +.facetName {font-weight: bold;} +div.discovery-query {border: 1px solid #CCCCCC;background-color: #EEEEEE;padding:10px;white-space: nowrap;} +div.discovery-query a {font-size: smaller;display: block;margin:2px;margin-left:5px;} +div.discovery-search-appliedFilters {margin-top: 10px; background-color: #FFFFFF; border: 1px solid #CCCCCC;padding:10px;} +div.discovery-search-appliedFilters span {font-weight: bold;display:block;margin-bottom:5px;} +div.discovery-query label {font-weight: bold;margin:5px;} +div.discovery-query select {margin-bottom:5px;} +div.discovery-search-filters{border: 1px solid #CCCCCC;padding:10px;} +div.discovery-search-filters span {display:block;margin:5px;} +div.discovery-search-filters span.discovery-search-filters-heading {font-weight: bold}; +div.discovery-search-filters select {margin:5px;} +div.discovery-pagination-controls {margin-top: 10px; background-color: #EEEEEE; border: 1px solid #CCCCCC;padding:10px;} + +.clearfix:after {clear: both;content: ".";display: block;height: 0;visibility: hidden;} +.pagination-masked.top {margin-top: 5px;} +div.discovery-result-pagination {margin: 20px;margin-bottom:0px;line-height: 1em;padding: 10px;vertical-align: middle;} +div.discovery-result-pagination h2.info, div.discovery-result-pagination p.info {float: left;margin:0px;} +div.discovery-result-pagination ul.links {float: right;margin:0px;list-style: none outside none;} +div.discovery-result-pagination ul.links li {display: inline; padding-left: 2px; padding-right: 2px;} +.current-page-link {color: #CCCCCC;font-weight: bold;} +div.discovery-result-results {padding:10px;} diff --git a/dspace-discovery/dspace-discovery-jspui-webapp/src/main/webapp/discovery/static-sidebar-facet.jsp b/dspace-jspui/dspace-jspui-webapp/src/main/webapp/discovery/static-sidebar-facet.jsp similarity index 100% rename from dspace-discovery/dspace-discovery-jspui-webapp/src/main/webapp/discovery/static-sidebar-facet.jsp rename to dspace-jspui/dspace-jspui-webapp/src/main/webapp/discovery/static-sidebar-facet.jsp diff --git a/dspace-discovery/dspace-discovery-jspui-webapp/src/main/webapp/search/discovery.jsp b/dspace-jspui/dspace-jspui-webapp/src/main/webapp/search/discovery.jsp similarity index 100% rename from dspace-discovery/dspace-discovery-jspui-webapp/src/main/webapp/search/discovery.jsp rename to dspace-jspui/dspace-jspui-webapp/src/main/webapp/search/discovery.jsp diff --git a/dspace-stats/pom.xml b/dspace-stats/pom.xml deleted file mode 100644 index 1e521b956b..0000000000 --- a/dspace-stats/pom.xml +++ /dev/null @@ -1,255 +0,0 @@ - - - - dspace-parent - org.dspace - 3.0-SNAPSHOT - .. - - - 4.0.0 - org.dspace - dspace-stats - DSpace Solr Statistics Logging Client Library - 3.0-SNAPSHOT - Library of Shared UsageEvent and EventConsumer Tools for Logging to Solr. - - - - - maven-dependency-plugin - 2.3 - - - setupTestEnvironment - generate-test-resources - - unpack - - - ${project.build.directory}/testing - - - org.dspace - dspace-parent - ${project.version} - zip - testEnvironment - - - - - - - - edu.iu.ul.maven.plugins - fileweaver - 1.0 - - - - ${project.build.directory}/testing - dspace.cfg.woven - - ${project.build.directory}/testing/dspace/config/dspace.cfg - ${project.build.directory}/testing/dspace.cfg.more - - - ${project.build.directory}/testing/dspace - - - - - - - edit-dspace-cfg - process-test-resources - - weave - - - - - - maven-surefire-plugin - - - ${project.build.directory}/testing/dspace - ${project.build.directory}/testing/dspace.cfg.woven - true - ${project.build.directory}/testing/dspace/etc/h2/database_schema.sql - - - - - - - - - Ben Bosman - ben at atmire.com - http://www.atmire.com - @MIRE - http://www.atmire.com - +1 - - - Mark Diggory - mdiggory at atmire.com - http://www.atmire.com - @MIRE - http://www.atmire.com - -5 - - - Lieven Droogmans - lieven at atmire.com - http://www.atmire.com - @MIRE - http://www.atmire.com - +1 - - - Art Lowel - art at atmire.com - http://www.atmire.com - @MIRE - http://www.atmire.com - +1 - - - Kevin Van de velde - kevin at atmire.com - http://www.atmire.com - @MIRE - http://www.atmire.com - +1 - - - - - - - - org.dspace - dspace-services-api - - - org.dspace - dspace-api - - - org.apache.solr - solr-solrj - ${lucene.version} - - - org.slf4j - jcl-over-slf4j - - - org.slf4j - slf4j-api - - - - - commons-configuration - commons-configuration - 1.8 - - - org.dspace.dependencies - dspace-geoip - 1.2.3 - - - org.apache.ant - ant - - - org.dspace.dnsjava - dnsjava - 2.0.6 - - - javax.servlet - servlet-api - provided - - - org.ostermiller - utils - 1.07.00 - - - org.databene - contiperf - 1.07 - jar - test - - - org.dspace.dependencies.jmockit - dspace-jmockit - 0.999.4 - jar - test - - - com.h2database - h2 - 1.3.158 - jar - test - - - junit - junit - 4.8.2 - jar - test - - - org.elasticsearch - elasticsearch - 0.18.6 - - - commons-cli - commons-cli - - - - com.google.code.gson - gson - 2.1 - compile - - - - - false - - - maven-javadoc-plugin - 2.8 - - 128m - 1g - - - - maven-jxr-plugin - 2.3 - - true - - - - maven-site-plugin - 3.0 - - - - diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/AbstractRecentSubmissionTransformer.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/AbstractRecentSubmissionTransformer.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/AbstractRecentSubmissionTransformer.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/AbstractRecentSubmissionTransformer.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/AbstractSearch.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/AbstractSearch.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/AbstractSearch.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/AbstractSearch.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/BrowseFacet.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/BrowseFacet.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/BrowseFacet.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/BrowseFacet.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/CollectionRecentSubmissions.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/CollectionRecentSubmissions.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/CollectionRecentSubmissions.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/CollectionRecentSubmissions.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/CollectionSearch.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/CollectionSearch.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/CollectionSearch.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/CollectionSearch.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/CommunityRecentSubmissions.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/CommunityRecentSubmissions.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/CommunityRecentSubmissions.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/CommunityRecentSubmissions.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/CommunitySearch.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/CommunitySearch.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/CommunitySearch.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/CommunitySearch.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/DiscoverySearchLoggerAction.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/DiscoverySearchLoggerAction.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/DiscoverySearchLoggerAction.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/DiscoverySearchLoggerAction.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/DiscoveryUIUtils.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/DiscoveryUIUtils.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/DiscoveryUIUtils.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/DiscoveryUIUtils.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/Navigation.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/Navigation.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/Navigation.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/Navigation.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/RelatedItems.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/RelatedItems.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/RelatedItems.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/RelatedItems.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SearchFacetFilter.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SearchFacetFilter.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SearchFacetFilter.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SearchFacetFilter.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SidebarFacetsTransformer.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SidebarFacetsTransformer.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SidebarFacetsTransformer.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SidebarFacetsTransformer.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SimpleSearch.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SimpleSearch.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SimpleSearch.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SimpleSearch.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SiteRecentSubmissions.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SiteRecentSubmissions.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SiteRecentSubmissions.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SiteRecentSubmissions.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SiteViewer.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SiteViewer.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SiteViewer.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/SiteViewer.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/json/JSONDiscoverySearcher.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/json/JSONDiscoverySearcher.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/json/JSONDiscoverySearcher.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/aspect/discovery/json/JSONDiscoverySearcher.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/opensearch/AbstractOpenSearchGenerator.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/opensearch/AbstractOpenSearchGenerator.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/opensearch/AbstractOpenSearchGenerator.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/opensearch/AbstractOpenSearchGenerator.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/opensearch/DescriptionOpenSearchGenerator.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/opensearch/DescriptionOpenSearchGenerator.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/opensearch/DescriptionOpenSearchGenerator.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/opensearch/DescriptionOpenSearchGenerator.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/opensearch/DiscoveryOpenSearchGenerator.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/opensearch/DiscoveryOpenSearchGenerator.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/opensearch/DiscoveryOpenSearchGenerator.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/opensearch/DiscoveryOpenSearchGenerator.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/opensearch/StandardOpenSearchGenerator.java b/dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/opensearch/StandardOpenSearchGenerator.java similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/java/org/dspace/app/xmlui/opensearch/StandardOpenSearchGenerator.java rename to dspace-xmlui/dspace-xmlui-api/src/main/java/org/dspace/app/xmlui/opensearch/StandardOpenSearchGenerator.java diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/resources/aspects/Discovery/i18n/messages.xml b/dspace-xmlui/dspace-xmlui-api/src/main/resources/aspects/Discovery/i18n/messages.xml similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/resources/aspects/Discovery/i18n/messages.xml rename to dspace-xmlui/dspace-xmlui-api/src/main/resources/aspects/Discovery/i18n/messages.xml diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/resources/aspects/Discovery/sitemap.xmap b/dspace-xmlui/dspace-xmlui-api/src/main/resources/aspects/Discovery/sitemap.xmap similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/resources/aspects/Discovery/sitemap.xmap rename to dspace-xmlui/dspace-xmlui-api/src/main/resources/aspects/Discovery/sitemap.xmap diff --git a/dspace-discovery/dspace-discovery-xmlui-api/src/main/resources/aspects/Feedback/sitemap.xmap b/dspace-xmlui/dspace-xmlui-api/src/main/resources/aspects/Feedback/sitemap.xmap similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-api/src/main/resources/aspects/Feedback/sitemap.xmap rename to dspace-xmlui/dspace-xmlui-api/src/main/resources/aspects/Feedback/sitemap.xmap diff --git a/dspace-discovery/dspace-discovery-xmlui-webapp/src/main/webapp/aspects/json-solr.xmap b/dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/aspects/json-solr.xmap similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-webapp/src/main/webapp/aspects/json-solr.xmap rename to dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/aspects/json-solr.xmap diff --git a/dspace-discovery/dspace-discovery-xmlui-webapp/src/main/webapp/static/css/discovery/discovery-style.css b/dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/static/css/discovery/discovery-style.css similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-webapp/src/main/webapp/static/css/discovery/discovery-style.css rename to dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/static/css/discovery/discovery-style.css diff --git a/dspace-discovery/dspace-discovery-xmlui-webapp/src/main/webapp/static/js/discovery/discovery-results.js b/dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/static/js/discovery/discovery-results.js similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-webapp/src/main/webapp/static/js/discovery/discovery-results.js rename to dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/static/js/discovery/discovery-results.js diff --git a/dspace-discovery/dspace-discovery-xmlui-webapp/src/main/webapp/static/js/discovery/search-controls.js b/dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/static/js/discovery/search-controls.js similarity index 100% rename from dspace-discovery/dspace-discovery-xmlui-webapp/src/main/webapp/static/js/discovery/search-controls.js rename to dspace-xmlui/dspace-xmlui-webapp/src/main/webapp/static/js/discovery/search-controls.js diff --git a/dspace/modules/additions/pom.xml b/dspace/modules/additions/pom.xml index 93be2466bc..15ccaa14b9 100644 --- a/dspace/modules/additions/pom.xml +++ b/dspace/modules/additions/pom.xml @@ -79,14 +79,6 @@ org.dspace dspace-services-utils - - org.dspace - dspace-discovery-provider - - - org.dspace - dspace-discovery-solr - javax.servlet servlet-api diff --git a/dspace/modules/jspui/pom.xml b/dspace/modules/jspui/pom.xml index 4e68d06d02..0abf6f6697 100644 --- a/dspace/modules/jspui/pom.xml +++ b/dspace/modules/jspui/pom.xml @@ -68,11 +68,6 @@ - - org.dspace - dspace-discovery-jspui-webapp - war - org.dspace dspace-jspui-webapp @@ -102,29 +97,11 @@ war - - org.dspace - dspace-discovery-jspui-api - 3.0-SNAPSHOT - - - - org.dspace - dspace-discovery-jspui-webapp - 3.0-SNAPSHOT - war - - org.dspace dspace-jspui-api - - org.dspace - dspace-discovery-provider - - javax.servlet servlet-api diff --git a/dspace/modules/lni/pom.xml b/dspace/modules/lni/pom.xml index fd553d3262..5dfb03a91e 100644 --- a/dspace/modules/lni/pom.xml +++ b/dspace/modules/lni/pom.xml @@ -96,11 +96,6 @@ dspace-lni-core - - org.dspace - dspace-discovery-provider - - javax.servlet servlet-api diff --git a/dspace/modules/sword/pom.xml b/dspace/modules/sword/pom.xml index 26f5bdcc37..f7bf80f450 100644 --- a/dspace/modules/sword/pom.xml +++ b/dspace/modules/sword/pom.xml @@ -96,10 +96,6 @@ org.dspace dspace-sword-api - - org.dspace - dspace-discovery-provider - javax.servlet servlet-api diff --git a/dspace/modules/swordv2/pom.xml b/dspace/modules/swordv2/pom.xml index 821b91f867..007455c51f 100644 --- a/dspace/modules/swordv2/pom.xml +++ b/dspace/modules/swordv2/pom.xml @@ -104,11 +104,6 @@ classes - - org.dspace - dspace-discovery-provider - - javax.servlet servlet-api diff --git a/dspace/modules/xmlui/pom.xml b/dspace/modules/xmlui/pom.xml index 767e2cda07..eb267378d1 100644 --- a/dspace/modules/xmlui/pom.xml +++ b/dspace/modules/xmlui/pom.xml @@ -122,25 +122,6 @@ war - - org.dspace - dspace-discovery-solr - 3.0-SNAPSHOT - - - - org.dspace - dspace-discovery-xmlui-api - 3.0-SNAPSHOT - - - - org.dspace - dspace-discovery-xmlui-webapp - 3.0-SNAPSHOT - war - - org.dspace dspace-sword-client-xmlui-api diff --git a/pom.xml b/pom.xml index 5b47c51493..9250d2a6e6 100644 --- a/pom.xml +++ b/pom.xml @@ -223,19 +223,6 @@ - - - dspace-discovery - - true - - - dspace-discovery - - - @@ -290,19 +277,6 @@ - - - dspace-sword-client - - true - - - dspace-sword-client - - - @@ -341,15 +315,12 @@ dspace-api - dspace-stats - dspace-discovery dspace-jspui dspace-xmlui dspace-lni dspace-oai dspace-sword dspace-swordv2 - dspace-sword-client @@ -530,16 +501,6 @@ [1.8.0.0,1.9.0.0) war - - org.dspace - dspace-discovery-provider - 3.0-SNAPSHOT - - - org.dspace - dspace-discovery-solr - 3.0-SNAPSHOT -