2018-12-04 12:06:22 +01:00
|
|
|
package org.gcube.gcat.rest;
|
|
|
|
|
|
|
|
import javax.ws.rs.Consumes;
|
|
|
|
import javax.ws.rs.DELETE;
|
|
|
|
import javax.ws.rs.DefaultValue;
|
|
|
|
import javax.ws.rs.GET;
|
2022-04-01 15:49:44 +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-01 15:49:44 +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-01 15:49:44 +02:00
|
|
|
import org.gcube.gcat.api.roles.Role;
|
2018-12-04 12:06:22 +01:00
|
|
|
import org.gcube.gcat.persistence.ckan.CKANOrganization;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
|
|
|
*/
|
2019-01-29 17:46:22 +01:00
|
|
|
@Path(Organization.ORGANIZATIONS)
|
|
|
|
public class Organization extends REST<CKANOrganization>
|
|
|
|
implements org.gcube.gcat.api.interfaces.Organization<Response,Response> {
|
2018-12-04 12:06:22 +01:00
|
|
|
|
|
|
|
public static final String ORGANIZATION_ID_PARAMETER = "ORGANIZATION_ID";
|
|
|
|
|
|
|
|
public Organization() {
|
2019-01-29 17:46:22 +01:00
|
|
|
super(ORGANIZATIONS, ORGANIZATION_ID_PARAMETER, CKANOrganization.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 {
|
|
|
|
CKANOrganization 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)
|
2021-02-03 21:55:32 +01:00
|
|
|
public String list(@QueryParam(GCatConstants.LIMIT_PARAMETER) @DefaultValue("10") int limit,
|
|
|
|
@QueryParam(GCatConstants.OFFSET_PARAMETER) @DefaultValue("0") int offset,
|
2021-02-04 09:40:33 +01:00
|
|
|
@QueryParam(GCatConstants.COUNT_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
|
2019-01-29 17:46:22 +01:00
|
|
|
public String list(@QueryParam(GCatConstants.LIMIT_PARAMETER) @DefaultValue("10") int limit,
|
|
|
|
@QueryParam(GCatConstants.OFFSET_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
|
|
|
}
|
|
|
|
|
|
|
|
@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-01 15:49:44 +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("/{" + ORGANIZATION_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
|
|
|
|
public String read(@PathParam(ORGANIZATION_ID_PARAMETER) String id) {
|
|
|
|
return super.read(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
@PUT
|
|
|
|
@Path("/{" + ORGANIZATION_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-01 15:49:44 +02:00
|
|
|
@AuthorizationControl(allowedRoles={Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class)
|
2018-12-04 12:06:22 +01:00
|
|
|
public String update(@PathParam(ORGANIZATION_ID_PARAMETER) String id, String json) {
|
|
|
|
return super.update(id, json);
|
|
|
|
}
|
|
|
|
|
|
|
|
@PATCH
|
|
|
|
@Path("/{" + ORGANIZATION_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-01 15:49:44 +02:00
|
|
|
@AuthorizationControl(allowedRoles={Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class)
|
2018-12-04 12:06:22 +01:00
|
|
|
public String patch(@PathParam(ORGANIZATION_ID_PARAMETER) String id, String json) {
|
|
|
|
return super.patch(id, json);
|
|
|
|
}
|
|
|
|
|
|
|
|
@DELETE
|
|
|
|
@Path("/{" + ORGANIZATION_ID_PARAMETER + "}")
|
|
|
|
@Override
|
2022-04-01 15:49:44 +02:00
|
|
|
@AuthorizationControl(allowedRoles={Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class)
|
2018-12-04 12:06:22 +01:00
|
|
|
public Response delete(@PathParam(ORGANIZATION_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("/{" + ORGANIZATION_ID_PARAMETER + "}")
|
2022-04-01 15:49:44 +02:00
|
|
|
@AuthorizationControl(allowedRoles={Role.CATALOGUE_MANAGER}, exception=NotAuthorizedException.class)
|
2018-12-04 12:06:22 +01:00
|
|
|
public Response purge(@PathParam(ORGANIZATION_ID_PARAMETER) String id) {
|
|
|
|
return super.purge(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|