2022-09-28 16:58:17 +02:00
|
|
|
|
package org.gcube.gcat.rest.administration;
|
2018-12-04 12:06:22 +01:00
|
|
|
|
|
|
|
|
|
import javax.ws.rs.Consumes;
|
|
|
|
|
import javax.ws.rs.DELETE;
|
|
|
|
|
import javax.ws.rs.DefaultValue;
|
|
|
|
|
import javax.ws.rs.GET;
|
2022-04-12 11:48:12 +02:00
|
|
|
|
//import javax.ws.rs.NotAuthorizedException;
|
2018-12-04 12:06:22 +01:00
|
|
|
|
import javax.ws.rs.POST;
|
|
|
|
|
import javax.ws.rs.PUT;
|
|
|
|
|
import javax.ws.rs.Path;
|
|
|
|
|
import javax.ws.rs.PathParam;
|
|
|
|
|
import javax.ws.rs.Produces;
|
|
|
|
|
import javax.ws.rs.QueryParam;
|
|
|
|
|
import javax.ws.rs.core.Response;
|
2021-02-03 21:55:32 +01:00
|
|
|
|
import javax.xml.ws.WebServiceException;
|
2018-12-04 12:06:22 +01:00
|
|
|
|
|
2022-04-12 11:48:12 +02:00
|
|
|
|
//import org.gcube.common.authorization.control.annotations.AuthorizationControl;
|
2018-12-04 12:06:22 +01:00
|
|
|
|
import org.gcube.gcat.annotation.PATCH;
|
|
|
|
|
import org.gcube.gcat.annotation.PURGE;
|
2019-01-29 17:46:22 +01:00
|
|
|
|
import org.gcube.gcat.api.GCatConstants;
|
2022-04-12 11:48:12 +02:00
|
|
|
|
//import org.gcube.gcat.api.roles.Role;
|
2018-12-04 12:06:22 +01:00
|
|
|
|
import org.gcube.gcat.persistence.ckan.CKANGroup;
|
2022-09-28 16:58:17 +02:00
|
|
|
|
import org.gcube.gcat.rest.REST;
|
2018-12-04 12:06:22 +01:00
|
|
|
|
|
2022-09-28 16:58:17 +02:00
|
|
|
|
import com.webcohesion.enunciate.metadata.rs.ResourceGroup;
|
2022-09-28 14:45:02 +02:00
|
|
|
|
import com.webcohesion.enunciate.metadata.rs.ResourceLabel;
|
|
|
|
|
|
2018-12-04 12:06:22 +01:00
|
|
|
|
/**
|
2022-09-30 17:28:30 +02:00
|
|
|
|
* This concept is mutated by Ckan which is used as underling technology to persist items.
|
|
|
|
|
*
|
2022-09-30 17:55:26 +02:00
|
|
|
|
* Only Catalogue-Admins or above are able to invoke non-safe methods.
|
|
|
|
|
*
|
2018-12-04 12:06:22 +01:00
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
2022-09-30 17:55:26 +02:00
|
|
|
|
*
|
2018-12-04 12:06:22 +01:00
|
|
|
|
*/
|
2019-01-29 17:46:22 +01:00
|
|
|
|
@Path(Group.GROUPS)
|
2022-09-28 16:58:17 +02:00
|
|
|
|
@ResourceGroup("Administration APIs")
|
2022-09-28 14:45:02 +02:00
|
|
|
|
@ResourceLabel("Group APIs")
|
2019-09-16 14:48:18 +02:00
|
|
|
|
public class Group extends REST<CKANGroup> implements org.gcube.gcat.api.interfaces.Group<Response,Response> {
|
2018-12-04 12:06:22 +01:00
|
|
|
|
|
|
|
|
|
protected static final String GROUP_ID_PARAMETER = "GROUP_ID";
|
|
|
|
|
|
|
|
|
|
public Group() {
|
2019-01-29 17:46:22 +01:00
|
|
|
|
super(GROUPS, GROUP_ID_PARAMETER, CKANGroup.class);
|
2018-12-04 12:06:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-02-03 21:55:32 +01:00
|
|
|
|
/*
|
|
|
|
|
* Not used as REST method, implemented to respect {@link org.gcube.gcat.api.interfaces.Item} interface
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public int count() throws WebServiceException {
|
|
|
|
|
CKANGroup ckan = getInstance();
|
|
|
|
|
return ckan.count();
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-04 12:06:22 +01:00
|
|
|
|
@GET
|
2022-02-21 10:34:52 +01:00
|
|
|
|
@Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8)
|
2022-04-12 11:48:12 +02:00
|
|
|
|
// @AuthorizationControl(allowedRoles={Role.CATALOGUE_EDITOR, Role.CATALOGUE_ADMIN, Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class)
|
2022-07-26 12:05:37 +02:00
|
|
|
|
public String list(@QueryParam(GCatConstants.LIMIT_QUERY_PARAMETER) @DefaultValue("10") int limit,
|
|
|
|
|
@QueryParam(GCatConstants.OFFSET_QUERY_PARAMETER) @DefaultValue("0") int offset,
|
|
|
|
|
@QueryParam(GCatConstants.COUNT_QUERY_PARAMETER) @DefaultValue("false") Boolean countOnly) {
|
2021-02-03 21:55:32 +01:00
|
|
|
|
if(countOnly) {
|
|
|
|
|
int count = count();
|
|
|
|
|
return createCountJson(count);
|
|
|
|
|
}else {
|
|
|
|
|
return list(limit, offset);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Not used as REST method, implemented to respect {@link org.gcube.gcat.api.interfaces.Item} interface
|
|
|
|
|
*/
|
2018-12-04 12:06:22 +01:00
|
|
|
|
@Override
|
2022-07-26 12:05:37 +02:00
|
|
|
|
public String list(@QueryParam(GCatConstants.LIMIT_QUERY_PARAMETER) @DefaultValue("10") int limit,
|
|
|
|
|
@QueryParam(GCatConstants.OFFSET_QUERY_PARAMETER) @DefaultValue("0") int offset) {
|
2019-01-10 12:29:47 +01:00
|
|
|
|
return super.list(limit, offset);
|
2018-12-04 12:06:22 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-30 17:55:26 +02:00
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* A group is mainly described by the following attributes (* indicate mandatory attributes):
|
|
|
|
|
*
|
|
|
|
|
* <dl>
|
|
|
|
|
*
|
|
|
|
|
* <dt>name* (string)</dt>
|
|
|
|
|
* <dd>
|
|
|
|
|
* the name of the group, a string between 2 and 100 characters long,
|
|
|
|
|
* containing only lowercase alphanumeric characters, '-' and '_' ;
|
|
|
|
|
* </dd>
|
|
|
|
|
*
|
|
|
|
|
* <dt style="margin-top: 5px;">id (string)</dt>
|
|
|
|
|
* <dd>the id of the group;</dd>
|
|
|
|
|
*
|
|
|
|
|
* <dt style="margin-top: 5px;">title (string)</dt>
|
|
|
|
|
* <dd>the title of the group;</dd>
|
|
|
|
|
*
|
|
|
|
|
* <dt style="margin-top: 5px;">description (string)</dt>
|
|
|
|
|
* <dd>the description of the group;</dd>
|
|
|
|
|
*
|
|
|
|
|
* <dt style="margin-top: 5px;">image_url (string)</dt>
|
|
|
|
|
* <dd>the URL to an image to be displayed on the group’s page;</dd>
|
|
|
|
|
*
|
|
|
|
|
* <dt>state (string, default: 'active')</dt>
|
|
|
|
|
* <dd>
|
|
|
|
|
* the current state of the group, e.g. 'active' or 'deleted',
|
|
|
|
|
* only active groups show up in search results and other lists of groups,
|
|
|
|
|
* this parameter will be ignored if you are not authorized
|
|
|
|
|
* to change the state of the group;
|
|
|
|
|
* </dd>
|
|
|
|
|
*
|
|
|
|
|
* <dt style="margin-top: 5px;">extras (list of dataset extra dictionaries)</dt>
|
|
|
|
|
* <dd>
|
|
|
|
|
* the group’s extras, extras are arbitrary (key: value) metadata that can be added to groups,
|
|
|
|
|
* each extra dictionary should have keys 'key' (a string),
|
|
|
|
|
* 'value' (a string), and optionally 'deleted'.
|
|
|
|
|
* </dd>
|
|
|
|
|
*
|
|
|
|
|
* </dl>
|
|
|
|
|
*
|
|
|
|
|
*/
|
2018-12-04 12:06:22 +01:00
|
|
|
|
@POST
|
2022-02-21 10:34:52 +01:00
|
|
|
|
@Consumes(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8)
|
|
|
|
|
@Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8)
|
2018-12-04 12:06:22 +01:00
|
|
|
|
@Override
|
2022-04-12 11:48:12 +02:00
|
|
|
|
// @AuthorizationControl(allowedRoles={Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class)
|
2018-12-04 12:06:22 +01:00
|
|
|
|
public Response create(String json) {
|
|
|
|
|
return super.create(json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GET
|
|
|
|
|
@Path("/{" + GROUP_ID_PARAMETER + "}")
|
2022-02-21 10:34:52 +01:00
|
|
|
|
@Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8)
|
2018-12-04 12:06:22 +01:00
|
|
|
|
@Override
|
2022-04-12 11:48:12 +02:00
|
|
|
|
// @AuthorizationControl(allowedRoles={Role.CATALOGUE_EDITOR}, exception=NotAuthorizedException.class)
|
2018-12-04 12:06:22 +01:00
|
|
|
|
public String read(@PathParam(GROUP_ID_PARAMETER) String id) {
|
|
|
|
|
return super.read(id);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PUT
|
|
|
|
|
@Path("/{" + GROUP_ID_PARAMETER + "}")
|
2022-02-21 10:34:52 +01:00
|
|
|
|
@Consumes(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8)
|
|
|
|
|
@Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8)
|
2018-12-04 12:06:22 +01:00
|
|
|
|
@Override
|
2022-04-12 11:48:12 +02:00
|
|
|
|
// @AuthorizationControl(allowedRoles={Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class)
|
2018-12-04 12:06:22 +01:00
|
|
|
|
public String update(@PathParam(GROUP_ID_PARAMETER) String id, String json) {
|
|
|
|
|
return super.update(id, json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PATCH
|
|
|
|
|
@Path("/{" + GROUP_ID_PARAMETER + "}")
|
2022-02-21 10:34:52 +01:00
|
|
|
|
@Consumes(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8)
|
|
|
|
|
@Produces(GCatConstants.APPLICATION_JSON_CHARSET_UTF_8)
|
2018-12-04 12:06:22 +01:00
|
|
|
|
@Override
|
2022-04-12 11:48:12 +02:00
|
|
|
|
// @AuthorizationControl(allowedRoles={Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class)
|
2018-12-04 12:06:22 +01:00
|
|
|
|
public String patch(@PathParam(GROUP_ID_PARAMETER) String id, String json) {
|
|
|
|
|
return super.patch(id, json);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@DELETE
|
|
|
|
|
@Path("/{" + GROUP_ID_PARAMETER + "}")
|
|
|
|
|
@Override
|
2022-04-12 11:48:12 +02:00
|
|
|
|
// @AuthorizationControl(allowedRoles={Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class)
|
2018-12-04 12:06:22 +01:00
|
|
|
|
public Response delete(@PathParam(GROUP_ID_PARAMETER) String id,
|
2019-01-29 17:46:22 +01:00
|
|
|
|
@QueryParam(GCatConstants.PURGE_QUERY_PARAMETER) @DefaultValue("false") Boolean purge) {
|
2018-12-04 12:06:22 +01:00
|
|
|
|
return super.delete(id, purge);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PURGE
|
|
|
|
|
@Path("/{" + GROUP_ID_PARAMETER + "}")
|
|
|
|
|
@Override
|
2022-04-12 11:48:12 +02:00
|
|
|
|
// @AuthorizationControl(allowedRoles={Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class)
|
2018-12-04 12:06:22 +01:00
|
|
|
|
public Response purge(@PathParam(GROUP_ID_PARAMETER) String id) {
|
|
|
|
|
return delete(id, true);
|
|
|
|
|
}
|
2019-09-16 14:48:18 +02:00
|
|
|
|
|
2019-01-29 17:46:22 +01:00
|
|
|
|
@Override
|
2022-04-12 11:48:12 +02:00
|
|
|
|
// @AuthorizationControl(allowedRoles={Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class)
|
2019-01-29 17:46:22 +01:00
|
|
|
|
public Response delete(String name, boolean purge) {
|
|
|
|
|
return delete(name, new Boolean(purge));
|
|
|
|
|
}
|
2018-12-04 12:06:22 +01:00
|
|
|
|
|
|
|
|
|
}
|