Fix dspace-api module per new code style

This commit is contained in:
Tim Donohue
2018-02-14 10:53:46 -06:00
parent 8ffc97f7f9
commit 8a48f782ea
1051 changed files with 53347 additions and 63373 deletions

View File

@@ -7,20 +7,27 @@
*/
package org.dspace.discovery;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.commons.collections4.CollectionUtils;
import org.dspace.discovery.configuration.DiscoverySearchFilterFacet;
import java.util.*;
/**
* This class represents a query which the discovery backend can use
*
* @author Kevin Van de Velde (kevin at atmire dot com)
*
*/
public class DiscoverQuery {
/** Main attributes for the discovery query **/
/**
* Main attributes for the discovery query
**/
private String query;
private List<String> filterQueries;
private int DSpaceObjectFilter = -1;
@@ -30,15 +37,20 @@ public class DiscoverQuery {
private int start = 0;
private int maxResults = -1;
/** Attributes used for sorting of results **/
/**
* Attributes used for sorting of results
**/
public enum SORT_ORDER {
desc,
asc
}
private String sortField;
private SORT_ORDER sortOrder;
/** Attributes required for the faceting of values **/
/**
* Attributes required for the faceting of values
**/
private List<DiscoverFacetField> facetFields;
private List<String> facetQueries;
private int facetLimit = -1;
@@ -46,10 +58,14 @@ public class DiscoverQuery {
private int facetOffset = 0;
private Map<String, DiscoverHitHighlightingField> hitHighlighting;
/** Used when you want to search for a specific field value **/
/**
* Used when you want to search for a specific field value
**/
private List<String> searchFields;
/** Misc attributes can be implementation dependent **/
/**
* Misc attributes can be implementation dependent
**/
private Map<String, List<String>> properties;
public DiscoverQuery() {
@@ -82,7 +98,7 @@ public class DiscoverQuery {
this.start = start;
}
public void setSortField(String sortField, SORT_ORDER sortOrder){
public void setSortField(String sortField, SORT_ORDER sortOrder) {
this.sortField = sortField;
this.sortOrder = sortOrder;
}
@@ -98,6 +114,7 @@ public class DiscoverQuery {
/**
* Sets the DSpace object filter, must be an DSpace Object type integer
* can be used to only return objects from a certain DSpace Object type
*
* @param DSpaceObjectFilter the DSpace object filer
*/
public void setDSpaceObjectFilter(int DSpaceObjectFilter) {
@@ -107,6 +124,7 @@ public class DiscoverQuery {
/**
* Gets the DSpace object filter
* can be used to only return objects from a certain DSpace Object type
*
* @return the DSpace object filer
*/
public int getDSpaceObjectFilter() {
@@ -115,6 +133,7 @@ public class DiscoverQuery {
/**
* The maximum number of results returned by this query
*
* @return the number of results
*/
public int getMaxResults() {
@@ -123,6 +142,7 @@ public class DiscoverQuery {
/**
* Sets the maximum number of results by this query
*
* @param maxResults the number of results
*/
public void setMaxResults(int maxResults) {
@@ -131,14 +151,16 @@ public class DiscoverQuery {
/**
* Adds new filter queries
*
* @param filterQueries the filter queries to be added
*/
public void addFilterQueries(String ...filterQueries){
public void addFilterQueries(String... filterQueries) {
this.filterQueries.addAll(Arrays.asList(filterQueries));
}
/**
* Returns the filter queries
*
* @return the filter queries in a list
*/
public List<String> getFilterQueries() {
@@ -147,9 +169,10 @@ public class DiscoverQuery {
/**
* Adds a query that will ensure that a certain field is present in the index
*
* @param fieldPresentQueries the queries to be added
*/
public void addFieldPresentQueries(String ...fieldPresentQueries){
public void addFieldPresentQueries(String... fieldPresentQueries) {
this.fieldPresentQueries.addAll(Arrays.asList(fieldPresentQueries));
}
@@ -159,14 +182,16 @@ public class DiscoverQuery {
/**
* Adds a new facet query
*
* @param facetQuery the new facet query to be added
*/
public void addFacetQuery(String facetQuery){
public void addFacetQuery(String facetQuery) {
this.facetQueries.add(facetQuery);
}
/**
* Returns the facet queries
*
* @return the facet queries for this query
*/
public List<String> getFacetQueries() {
@@ -175,14 +200,16 @@ public class DiscoverQuery {
/**
* Adds a new facet field
*
* @param facetField the new facet field to be added
*/
public void addFacetField(DiscoverFacetField facetField){
public void addFacetField(DiscoverFacetField facetField) {
facetFields.add(facetField);
}
/**
* Gets the facets fields configured
*
* @return the facet fields for this query
*/
public List<DiscoverFacetField> getFacetFields() {
@@ -191,6 +218,7 @@ public class DiscoverQuery {
/**
* Gets the minimum number of values that need to be present before a valid facet value has been found
*
* @return facetMinCount the minimum number of values to be present for a valid facet
*/
public int getFacetMinCount() {
@@ -199,6 +227,7 @@ public class DiscoverQuery {
/**
* Set the minimum number of values that need to be present before a valid facet value has been found
*
* @param facetMinCount the minimum number of values to be present for a valid facet
*/
public void setFacetMinCount(int facetMinCount) {
@@ -207,6 +236,7 @@ public class DiscoverQuery {
/**
* Gets the facet field offset
*
* @return the facet field offset
*/
public int getFacetOffset() {
@@ -215,6 +245,7 @@ public class DiscoverQuery {
/**
* Sets the facet field offset, one facet offset will be used for all the facet fields
*
* @param facetOffset an integer representing the offset
*/
public void setFacetOffset(int facetOffset) {
@@ -225,14 +256,16 @@ public class DiscoverQuery {
* Sets the fields which you want Discovery to return in the search results.
* It is HIGHLY recommended to limit the fields returned, as by default
* some backends (like Solr) will return everything.
*
* @param field field to add to the list of fields returned
*/
public void addSearchField(String field){
public void addSearchField(String field) {
this.searchFields.add(field);
}
/**
* Get list of fields which Discovery will return in the search results
*
* @return List of field names
*/
public List<String> getSearchFields() {
@@ -241,6 +274,7 @@ public class DiscoverQuery {
/**
* Returns the misc search properties
*
* @return a map containing the properties
*/
public Map<String, List<String>> getProperties() {
@@ -249,13 +283,13 @@ public class DiscoverQuery {
/**
* Adds a new search property to the misc search properties
*
* @param property the name of the property
* @param value the value of the property
* @param value the value of the property
*/
public void addProperty(String property, String value){
public void addProperty(String property, String value) {
List<String> toAddList = properties.get(property);
if(toAddList == null)
{
if (toAddList == null) {
toAddList = new ArrayList<String>();
}
@@ -264,18 +298,15 @@ public class DiscoverQuery {
properties.put(property, toAddList);
}
public DiscoverHitHighlightingField getHitHighlightingField(String field)
{
public DiscoverHitHighlightingField getHitHighlightingField(String field) {
return hitHighlighting.get(field);
}
public List<DiscoverHitHighlightingField> getHitHighlightingFields()
{
public List<DiscoverHitHighlightingField> getHitHighlightingFields() {
return new ArrayList<DiscoverHitHighlightingField>(hitHighlighting.values());
}
public void addHitHighlightingField(DiscoverHitHighlightingField hitHighlighting)
{
public void addHitHighlightingField(DiscoverHitHighlightingField hitHighlighting) {
this.hitHighlighting.put(hitHighlighting.getField(), hitHighlighting);
}
@@ -288,7 +319,7 @@ public class DiscoverQuery {
}
public void addYearRangeFacet(DiscoverySearchFilterFacet facet, FacetYearRange facetYearRange) {
if(facetYearRange.isValid()) {
if (facetYearRange.isValid()) {
int newestYear = facetYearRange.getNewestYear();
int oldestYear = facetYearRange.getOldestYear();
@@ -296,14 +327,16 @@ public class DiscoverQuery {
int gap = facetYearRange.getYearGap();
// 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
// Example: 2001 and a gap from 10 we need the following result: 2010 - 2000 ; 2000 - 1990 hence the top
// year
int topYear = getTopYear(newestYear, 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
this.addFacetField(new DiscoverFacetField(facet.getIndexFieldName(), facet.getType(), 10, facet.getSortOrderSidebar()));
this.addFacetField(new DiscoverFacetField(facet.getIndexFieldName(), facet.getType(), 10,
facet.getSortOrderSidebar()));
} else {
List<String> facetQueries = buildFacetQueriesWithGap(newestYear, oldestYear, dateFacet, gap, topYear);
for (String facetQuery : CollectionUtils.emptyIfNull(facetQueries)) {
@@ -313,7 +346,8 @@ public class DiscoverQuery {
}
}
private List<String> buildFacetQueriesWithGap(int newestYear, int oldestYear, String dateFacet, int gap, int topYear) {
private List<String> buildFacetQueriesWithGap(int newestYear, int oldestYear, String dateFacet, int gap,
int topYear) {
List<String> facetQueries = new LinkedList<>();
//Create facet queries but limit them to 11 (11 == when we need to show a "show more" url)
for (int year = topYear; year > oldestYear && (facetQueries.size() < 11); year -= gap) {