diff --git a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java index c8c3390..adf1cf5 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java @@ -258,7 +258,7 @@ public class CKANPackage extends CKAN { } parameters.put(START_KEY, String.valueOf(offset * limit)); - if(uriInfo!=null) { + if(uriInfo != null) { MultivaluedMap queryParameters = uriInfo.getQueryParameters(); parameters = checkListParameters(queryParameters, parameters); } @@ -268,25 +268,25 @@ public class CKANPackage extends CKAN { protected void checkOrganizationFilter(String q) { Matcher m = ORGANIZATION_REGEX_PATTERN.matcher(q); - + List matches = new ArrayList<>(); while(m.find()) { matches.add(q.substring(m.start(), m.end())); } - if(matches.size()>0) { + if(matches.size() > 0) { StringBuilder error = new StringBuilder(); error.append("Organization filters is constrained to VRE. "); - if(matches.size()>1) { + if(matches.size() > 1) { error.append("Remove these filters "); - }else { + } else { error.append("Remove this filter "); } boolean first = true; for(String match : matches) { if(!first) { error.append(", "); - }else { + } else { first = false; } error.append("["); @@ -297,6 +297,9 @@ public class CKANPackage extends CKAN { } } + protected static String[] allowedFilters = new String[] {"q", "fq", "fq_list", "sort", "facet", "facet.mincount", + "facet.limit", "facet.field", "include_drafts", "include_private", "ext_bbox", "fl"}; + protected Map checkListParameters(MultivaluedMap queryParameters, Map parameters) { @@ -332,14 +335,10 @@ public class CKANPackage extends CKAN { // q=organization:nextnext } - for(String key : queryParameters.keySet()) { - // if 'rows' and 'start' are provided they replace the values imposed by caller - // provided limit and offset parameter which are the gCat interface are not passed to CKAN - if(key.compareTo(GCatConstants.LIMIT_PARAMETER) == 0 - || key.compareTo(GCatConstants.OFFSET_PARAMETER) == 0) { - continue; + for(String key : allowedFilters) { + if(queryParameters.containsKey(key)) { + parameters.put(key, queryParameters.getFirst(key)); } - parameters.put(key, queryParameters.getFirst(key)); } // parameters.put(INCLUDE_PRIVATE_KEY, String.valueOf(true));