From 9779afe1e5a1e15544906aad2705ed980203a580 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Fri, 27 Sep 2019 17:33:10 +0200 Subject: [PATCH] Added organization parameter to allow client to specify the target organization in item listing (in VO and ROOT) refs #17635 --- .../gcat/persistence/ckan/CKANPackage.java | 31 +++++++++++++++++-- src/main/java/org/gcube/gcat/rest/REST.java | 2 +- 2 files changed, 29 insertions(+), 4 deletions(-) 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 d335f2d..3056a28 100644 --- a/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java +++ b/src/main/java/org/gcube/gcat/persistence/ckan/CKANPackage.java @@ -88,6 +88,8 @@ public class CKANPackage extends CKAN { protected static final String SEARCHABLE_KEY = "searchable"; protected static final String CAPACITY_KEY = "capacity"; + + // protected static final String INCLUDE_PRIVATE_KEY = "include_private"; // protected static final String INCLUDE_DRAFTS_KEY = "include_drafts"; @@ -195,7 +197,7 @@ public class CKANPackage extends CKAN { } if(organizationID == null || gotOrganization.compareTo(organizationID) != 0) { throw new BadRequestException( - "You can only publish in the Organization associate to the current VRE"); + "You can only publish in the Organization associated to the current VRE"); } } } else { @@ -250,8 +252,31 @@ public class CKANPackage extends CKAN { parameters.put(START_KEY, String.valueOf(offset * limit)); String organizationName = getOrganizationName(); - String organizationQueryString = String.format(ORGANIZATION_FILTER_TEMPLATE, organizationName); - parameters.put(Q_KEY, organizationQueryString); + ScopeBean scopeBean = new ScopeBean(ContextUtility.getCurrentContext()); + + /* + * List is filter per organization only is the request arriving in a VRE. + * If the request arrive form a VO or from ROOT the request return the item in all organizations + * in the catalog. + */ + String organizationQueryString = null; + if(scopeBean.is(Type.VRE)) { + organizationQueryString = String.format(ORGANIZATION_FILTER_TEMPLATE, organizationName); + }else { + /* + * We provide the possibility for the client to get the list of an item in an organization + * if the request arrives from a VO o from the ROOT + */ + MultivaluedMap queryParameters = uriInfo.getQueryParameters(); + if(queryParameters!=null && queryParameters.containsKey(GCatConstants.ORGANIZATION_PARAMETER)) { + String org = queryParameters.getFirst(GCatConstants.ORGANIZATION_PARAMETER); + organizationQueryString = String.format(ORGANIZATION_FILTER_TEMPLATE, org); + } + } + + if(organizationQueryString!=null) { + parameters.put(Q_KEY, organizationQueryString); + } // parameters.put(INCLUDE_PRIVATE_KEY, String.valueOf(true)); diff --git a/src/main/java/org/gcube/gcat/rest/REST.java b/src/main/java/org/gcube/gcat/rest/REST.java index 45b8ab8..09d790d 100644 --- a/src/main/java/org/gcube/gcat/rest/REST.java +++ b/src/main/java/org/gcube/gcat/rest/REST.java @@ -24,6 +24,7 @@ public class REST extends BaseREST implements CRUD extends BaseREST implements CRUD