Added organization parameter to allow client to specify the target

organization in item listing (in VO and ROOT) refs #17635
This commit is contained in:
Luca Frosini 2019-09-27 17:33:10 +02:00
parent 56261f96ab
commit 9779afe1e5
2 changed files with 29 additions and 4 deletions

View File

@ -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<String, String> 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));

View File

@ -24,6 +24,7 @@ public class REST<C extends CKAN> extends BaseREST implements CRUD<Response,Resp
protected C getInstance() {
try {
C ckan = reference.newInstance();
ckan.setUriInfo(uriInfo);
return ckan;
} catch(Exception e) {
throw new InternalServerErrorException();
@ -40,7 +41,6 @@ public class REST<C extends CKAN> extends BaseREST implements CRUD<Response,Resp
public Response create(String json) {
setCalledMethod("POST /" + COLLECTION_PARAMETER);
C ckan = getInstance();
ckan.setUriInfo(uriInfo);
String ret = ckan.create(json);
ResponseBuilder responseBuilder = Response.status(Status.CREATED).entity(ret);