Using gcat-api refs #13216

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/data-publishing/gcat@176866 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2019-01-29 16:46:22 +00:00
parent 7b214c54e7
commit b6891d4d89
15 changed files with 207 additions and 104 deletions

54
pom.xml
View File

@ -38,7 +38,7 @@
</dependencyManagement>
<properties>
<version.jersey>2.13</version.jersey>
<version.jersey>2.24.1</version.jersey>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<webappDirectory>${project.basedir}/src/main/webapp/WEB-INF</webappDirectory>
<!-- webappDirectory>${project.build.directory}/${project.build.finalName}</webappDirectory -->
@ -54,6 +54,12 @@
<dependencies>
<dependency>
<groupId>org.gcube.data-publishing</groupId>
<artifactId>gcat-api</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<!-- ehCAChe -->
<dependency>
<groupId>javax.cache</groupId>
@ -99,13 +105,9 @@
<artifactId>jersey-container-servlet</artifactId>
<version>${version.jersey}</version>
</dependency>
<!-- Required with jersey 2.27
<dependency>
<groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId>
<version>${version.jersey}</version>
</dependency>
-->
<!-- Required with jersey 2.27 <dependency> <groupId>org.glassfish.jersey.inject</groupId>
<artifactId>jersey-hk2</artifactId> <version>${version.jersey}</version>
</dependency> -->
<dependency>
<groupId>org.glassfish.jersey.media</groupId>
@ -125,30 +127,30 @@
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>gxRest</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<!-- Libraries explicitly forced to provided -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<scope>provided</scope>
<artifactId>jackson-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<scope>provided</scope>
<artifactId>jackson-databind</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<scope>provided</scope>
<artifactId>jackson-annotations</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.resources</groupId>
@ -175,7 +177,7 @@
<artifactId>discovery-client</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-encryption</artifactId>
<scope>provided</scope>
@ -196,26 +198,26 @@
<scope>provided</scope>
</dependency>
<!-- END Libraries explicitly forced to provided -->
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-smartgears</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>de.grundid.opendatalab</groupId>
<artifactId>geojson-jackson</artifactId>
<version>1.8</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
</dependency>
<!-- Used to automatically convert XML to JSON -->
<dependency>
<groupId>org.json</groupId>
@ -225,8 +227,8 @@
<dependency>
<groupId>org.gcube.data-publishing</groupId>
<artifactId>storagehub-application-persistence</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<artifactId>storagehub-application-persistence</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>

View File

@ -121,7 +121,7 @@ public class CKANResource extends CKAN {
public JsonNode getPreviousRepresentation() {
if(previousRepresentation==null && resourceID!=null) {
super.read();
sendGetRequest(READ, getMapWithID(resourceID));
validate(result);
previousRepresentation = result;
}
@ -386,7 +386,7 @@ public class CKANResource extends CKAN {
public void delete() {
try {
deleteFile();
super.delete();
sendPostRequest(DELETE, createJsonNodeWithID(resourceID));
} catch(WebApplicationException e) {
throw e;
} catch(Exception e) {

View File

@ -1,7 +1,6 @@
package org.gcube.gcat.rest;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.core.Response.ResponseBuilder;
@ -16,24 +15,8 @@ public class BaseREST {
@Context
private UriInfo uriInfo;
public static final String GROUPS = "groups";
public static final String ITEMS = "items";
public static final String LICENSES = "licenses";
public static final String NAMESPACES = "namespaces";
public static final String ORGANIZATIONS = "organizations";
public static final String PROFILES = "profiles";
public static final String RESOURCES = "resources";
public static final String USERS = "users";
public static final String PURGE_QUERY_PARAMETER = "purge";
public static final String APPLICATION_JSON_CHARSET_UTF_8 = MediaType.APPLICATION_JSON + ";charset=UTF-8";
protected static final String LOCATION_HEADER = "Location";
public static final String LIMIT_PARAMETER = "limit";
public static final String OFFSET_PARAMETER = "offset";
protected void setCalledMethod(String method) {
CalledMethodProvider.instance.set(method);
logger.info("{}", uriInfo.getAbsolutePath());

View File

@ -15,25 +15,26 @@ import javax.ws.rs.core.Response;
import org.gcube.gcat.ResourceInitializer;
import org.gcube.gcat.annotation.PATCH;
import org.gcube.gcat.annotation.PURGE;
import org.gcube.gcat.api.GCatConstants;
import org.gcube.gcat.persistence.ckan.CKANGroup;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Path(BaseREST.GROUPS)
public class Group extends REST<CKANGroup> {
@Path(Group.GROUPS)
public class Group extends REST<CKANGroup> implements org.gcube.gcat.api.interfaces.Group<Response,Response>{
protected static final String GROUP_ID_PARAMETER = "GROUP_ID";
public Group() {
super(BaseREST.GROUPS, GROUP_ID_PARAMETER, CKANGroup.class);
super(GROUPS, GROUP_ID_PARAMETER, CKANGroup.class);
}
@GET
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
@Override
public String list(@QueryParam(BaseREST.LIMIT_PARAMETER) @DefaultValue("10") int limit,
@QueryParam(BaseREST.OFFSET_PARAMETER) @DefaultValue("0") int offset) {
public String list(@QueryParam(GCatConstants.LIMIT_PARAMETER) @DefaultValue("10") int limit,
@QueryParam(GCatConstants.OFFSET_PARAMETER) @DefaultValue("0") int offset) {
return super.list(limit, offset);
}
@ -75,7 +76,7 @@ public class Group extends REST<CKANGroup> {
@Path("/{" + GROUP_ID_PARAMETER + "}")
@Override
public Response delete(@PathParam(GROUP_ID_PARAMETER) String id,
@QueryParam(BaseREST.PURGE_QUERY_PARAMETER) @DefaultValue("false") Boolean purge) {
@QueryParam(GCatConstants.PURGE_QUERY_PARAMETER) @DefaultValue("false") Boolean purge) {
return super.delete(id, purge);
}
@ -85,5 +86,10 @@ public class Group extends REST<CKANGroup> {
public Response purge(@PathParam(GROUP_ID_PARAMETER) String id) {
return delete(id, true);
}
@Override
public Response delete(String name, boolean purge) {
return delete(name, new Boolean(purge));
}
}

View File

@ -11,28 +11,30 @@ import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response;
import javax.xml.ws.WebServiceException;
import org.gcube.gcat.ResourceInitializer;
import org.gcube.gcat.annotation.PURGE;
import org.gcube.gcat.api.GCatConstants;
import org.gcube.gcat.persistence.ckan.CKANPackage;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Path(BaseREST.ITEMS)
public class Item extends REST<CKANPackage> {
@Path(Item.ITEMS)
public class Item extends REST<CKANPackage> implements org.gcube.gcat.api.interfaces.Item<Response,Response>{
public static final String ITEM_ID_PARAMETER = "ITEM_ID";
public Item() {
super(BaseREST.ITEMS, ITEM_ID_PARAMETER, CKANPackage.class);
super(ITEMS, ITEM_ID_PARAMETER, CKANPackage.class);
}
@GET
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
@Override
public String list(@QueryParam(BaseREST.LIMIT_PARAMETER) @DefaultValue("10") int limit,
@QueryParam(BaseREST.OFFSET_PARAMETER) @DefaultValue("0") int offset) {
public String list(@QueryParam(GCatConstants.LIMIT_PARAMETER) @DefaultValue("10") int limit,
@QueryParam(GCatConstants.OFFSET_PARAMETER) @DefaultValue("0") int offset) {
return super.list(limit, offset);
}
@ -76,7 +78,7 @@ public class Item extends REST<CKANPackage> {
@Path("/{" + ITEM_ID_PARAMETER + "}")
@Override
public Response delete(@PathParam(ITEM_ID_PARAMETER) String id,
@QueryParam(BaseREST.PURGE_QUERY_PARAMETER) @DefaultValue("false") Boolean purge) {
@QueryParam(GCatConstants.PURGE_QUERY_PARAMETER) @DefaultValue("false") Boolean purge) {
return super.delete(id, purge);
}
@ -86,5 +88,10 @@ public class Item extends REST<CKANPackage> {
public Response purge(@PathParam(ITEM_ID_PARAMETER) String id) {
return super.purge(id);
}
@Override
public Response delete(String name, boolean purge) throws WebServiceException {
return delete(name, new Boolean(purge));
}
}

View File

@ -10,11 +10,11 @@ import org.gcube.gcat.persistence.ckan.CKANLicense;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Path(BaseREST.LICENSES)
public class License extends REST<CKANLicense> {
@Path(License.LICENSES)
public class License extends REST<CKANLicense> implements org.gcube.gcat.api.interfaces.License {
public License() {
super(BaseREST.LICENSES, null, CKANLicense.class);
super(LICENSES, null, CKANLicense.class);
}
@GET

View File

@ -18,13 +18,13 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Path(BaseREST.NAMESPACES)
public class Namespace extends BaseREST {
@Path(Namespace.NAMESPACES)
public class Namespace extends BaseREST implements org.gcube.gcat.api.interfaces.Namespace {
@GET
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String list() {
setCalledMethod("GET /" + BaseREST.NAMESPACES);
setCalledMethod("GET /" + NAMESPACES);
ObjectMapper mapper = new ObjectMapper();
ArrayNode arrayNode = mapper.createArrayNode();

View File

@ -15,25 +15,27 @@ import javax.ws.rs.core.Response;
import org.gcube.gcat.ResourceInitializer;
import org.gcube.gcat.annotation.PATCH;
import org.gcube.gcat.annotation.PURGE;
import org.gcube.gcat.api.GCatConstants;
import org.gcube.gcat.persistence.ckan.CKANOrganization;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Path(BaseREST.ORGANIZATIONS)
public class Organization extends REST<CKANOrganization> {
@Path(Organization.ORGANIZATIONS)
public class Organization extends REST<CKANOrganization>
implements org.gcube.gcat.api.interfaces.Organization<Response,Response> {
public static final String ORGANIZATION_ID_PARAMETER = "ORGANIZATION_ID";
public Organization() {
super(BaseREST.ORGANIZATIONS, ORGANIZATION_ID_PARAMETER, CKANOrganization.class);
super(ORGANIZATIONS, ORGANIZATION_ID_PARAMETER, CKANOrganization.class);
}
@GET
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
@Override
public String list(@QueryParam(BaseREST.LIMIT_PARAMETER) @DefaultValue("10") int limit,
@QueryParam(BaseREST.OFFSET_PARAMETER) @DefaultValue("0") int offset) {
public String list(@QueryParam(GCatConstants.LIMIT_PARAMETER) @DefaultValue("10") int limit,
@QueryParam(GCatConstants.OFFSET_PARAMETER) @DefaultValue("0") int offset) {
return super.list(limit, offset);
}
@ -75,7 +77,7 @@ public class Organization extends REST<CKANOrganization> {
@Path("/{" + ORGANIZATION_ID_PARAMETER + "}")
@Override
public Response delete(@PathParam(ORGANIZATION_ID_PARAMETER) String id,
@QueryParam(BaseREST.PURGE_QUERY_PARAMETER) @DefaultValue("false") Boolean purge) {
@QueryParam(GCatConstants.PURGE_QUERY_PARAMETER) @DefaultValue("false") Boolean purge) {
return super.delete(id, purge);
}

View File

@ -16,9 +16,12 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import javax.ws.rs.core.UriInfo;
import org.gcube.common.resources.gcore.GenericResource;
import org.gcube.common.resources.gcore.Resources;
@ -44,17 +47,20 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Path(BaseREST.PROFILES)
public class Profile extends BaseREST {
@Path(Profile.PROFILES)
public class Profile extends BaseREST implements org.gcube.gcat.api.interfaces.Profile<Response,Response> {
private static Logger logger = LoggerFactory.getLogger(Profile.class);
public static final String PROFILE_NAME_PARAMETER = "PROFILE_NAME";
@Context
private UriInfo uriInfo;
@GET
@Produces(MediaType.APPLICATION_JSON)
public String list() {
setCalledMethod("GET /" + BaseREST.PROFILES);
setCalledMethod("GET /" + PROFILES);
ObjectMapper mapper = new ObjectMapper();
ArrayNode arrayNode = mapper.createArrayNode();
@ -76,8 +82,8 @@ public class Profile extends BaseREST {
@Path("/{" + PROFILE_NAME_PARAMETER + "}")
@Produces({MediaType.APPLICATION_XML, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8})
public String read(@PathParam(PROFILE_NAME_PARAMETER) String name,
@DefaultValue(MediaType.APPLICATION_JSON) @HeaderParam("Accept") String accept) {
setCalledMethod("GET /" + BaseREST.PROFILES + "/{" + PROFILE_NAME_PARAMETER + "}");
@DefaultValue(MediaType.APPLICATION_XML) @HeaderParam("Accept") String accept) {
setCalledMethod("GET /" + PROFILES + "/{" + PROFILE_NAME_PARAMETER + "}");
try {
String profile = MetadataUtility.getInstance().getMetadataFormat(name).getMetadataSource();
if(profile != null) {
@ -192,17 +198,21 @@ public class Profile extends BaseREST {
@Path("/{" + PROFILE_NAME_PARAMETER + "}")
@Consumes(MediaType.APPLICATION_XML)
@Produces(MediaType.APPLICATION_XML)
public String createOrUpdate(@PathParam(PROFILE_NAME_PARAMETER) String name, String xml) {
setCalledMethod("PUT /" + BaseREST.PROFILES + "/{" + PROFILE_NAME_PARAMETER + "}");
public Response createOrUpdate(@PathParam(PROFILE_NAME_PARAMETER) String name, String xml) {
setCalledMethod("PUT /" + PROFILES + "/{" + PROFILE_NAME_PARAMETER + "}");
try {
MetadataUtility metadataUtility = MetadataUtility.getInstance();
metadataUtility.getDataCalogueMetadataFormatReader().validateProfile(xml);
if(metadataUtility.getMetadataFormat(name) == null) {
createGenericResource(name, xml);
ResponseBuilder responseBuilder = Response.status(Status.CREATED).entity(xml);
responseBuilder.header(LOCATION_HEADER, uriInfo.getAbsolutePath());
return responseBuilder.type(MediaType.APPLICATION_XML).build();
} else {
updateGenericResource(name, xml);
ResponseBuilder responseBuilder = Response.status(Status.OK).entity(xml);
return responseBuilder.type(MediaType.APPLICATION_XML).build();
}
return xml;
} catch(WebApplicationException e) {
throw e;
} catch(Exception e) {
@ -217,7 +227,7 @@ public class Profile extends BaseREST {
@DELETE
@Path("/{" + PROFILE_NAME_PARAMETER + "}")
public Response delete(@PathParam(PROFILE_NAME_PARAMETER) String name) {
setCalledMethod("DELETE /" + BaseREST.PROFILES + "/{" + PROFILE_NAME_PARAMETER + "}");
setCalledMethod("DELETE /" + PROFILES + "/{" + PROFILE_NAME_PARAMETER + "}");
try {
MetadataUtility metadataUtility = MetadataUtility.getInstance();
if(metadataUtility.getMetadataFormat(name) == null) {
@ -235,5 +245,21 @@ public class Profile extends BaseREST {
MetadataUtility.clearCache();
}
}
@Override
public Response create(String name, String xml) {
return createOrUpdate(name, xml);
}
@Override
public String read(String name) {
return read(name, MediaType.APPLICATION_XML);
}
@Override
public String update(String name, String xml) {
return createOrUpdate(name, xml).getEntity().toString();
}
}

View File

@ -6,9 +6,10 @@ import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import org.gcube.gcat.ResourceInitializer;
import org.gcube.gcat.api.interfaces.CRUD;
import org.gcube.gcat.persistence.ckan.CKAN;
public class REST<C extends CKAN> extends BaseREST {
public class REST<C extends CKAN> extends BaseREST implements CRUD<Response, Response> {
protected final String COLLECTION_PARAMETER;
protected final String ID_PARAMETER;
@ -35,6 +36,7 @@ public class REST<C extends CKAN> extends BaseREST {
return ckan.list(limit, offset);
}
@Override
public Response create(String json) {
setCalledMethod("POST /" + COLLECTION_PARAMETER);
C ckan = getInstance();
@ -45,6 +47,7 @@ public class REST<C extends CKAN> extends BaseREST {
return responseBuilder.type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
}
@Override
public String read(String id) {
setCalledMethod("GET /" + COLLECTION_PARAMETER + "/{" + ID_PARAMETER + "}");
C ckan = getInstance();
@ -52,6 +55,7 @@ public class REST<C extends CKAN> extends BaseREST {
return ckan.read();
}
@Override
public String update(String id, String json) {
setCalledMethod("PUT /" + COLLECTION_PARAMETER + "/{" + ID_PARAMETER + "}");
C ckan = getInstance();
@ -67,6 +71,11 @@ public class REST<C extends CKAN> extends BaseREST {
return ckan.patch(json);
}
@Override
public Response delete(String id) {
return delete(id, false);
}
public Response delete(String id, Boolean purge) {
if(purge) {
setCalledMethod("PURGE /" + COLLECTION_PARAMETER + "/{" + ID_PARAMETER + "}");

View File

@ -8,6 +8,9 @@ import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.ResponseBuilder;
import javax.ws.rs.core.Response.Status;
import org.gcube.gcat.ResourceInitializer;
import org.gcube.gcat.annotation.PATCH;
@ -16,13 +19,13 @@ import org.gcube.gcat.persistence.ckan.CKANResource;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Path(BaseREST.ITEMS + "/{" + Resource.ITEM_ID_PARAMETER + "}/" + BaseREST.RESOURCES)
public class Resource extends BaseREST {
@Path(Resource.COLLECTION)
public class Resource extends BaseREST implements org.gcube.gcat.api.interfaces.Resource<Response,Response> {
protected static final String ITEM_ID_PARAMETER = "ITEM_ID";
protected static final String ITEM_ID_PARAMETER = Item.ITEM_ID_PARAMETER;
protected static final String RESOURCE_ID_PARAMETER = "RESOURCE_ID";
protected static final String COLLECTION = BaseREST.ITEMS + "/{" + Resource.ITEM_ID_PARAMETER + "}/" + BaseREST.RESOURCES;
protected static final String COLLECTION = Item.ITEMS + "/{" + ITEM_ID_PARAMETER + "}/" + RESOURCES;
@GET
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
@ -36,10 +39,14 @@ public class Resource extends BaseREST {
@POST
@Consumes(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String create(@PathParam(ITEM_ID_PARAMETER) String itemID, String json) {
public Response create(@PathParam(ITEM_ID_PARAMETER) String itemID, String json) {
setCalledMethod("POST /" + COLLECTION);
CKANResource ckanResource = new CKANResource(itemID);
return ckanResource.create(json);
String ret = ckanResource.create(json);
ResponseBuilder responseBuilder = Response.status(Status.CREATED).entity(ret);
responseBuilder = addLocation(responseBuilder, ckanResource.getResourceID());
return responseBuilder.type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8).build();
}
@GET
@ -49,7 +56,7 @@ public class Resource extends BaseREST {
@PathParam(RESOURCE_ID_PARAMETER) String resourceID) {
setCalledMethod("GET /" + COLLECTION + "/{" + RESOURCE_ID_PARAMETER + "}");
CKANResource ckanResource = new CKANResource(itemID);
ckanResource.setName(resourceID);
ckanResource.setResourceID(resourceID);
return ckanResource.read();
}
@ -61,7 +68,7 @@ public class Resource extends BaseREST {
@PathParam(RESOURCE_ID_PARAMETER) String resourceID, String json) {
setCalledMethod("PUT /" + COLLECTION + "/{" + RESOURCE_ID_PARAMETER + "}");
CKANResource ckanResource = new CKANResource(itemID);
ckanResource.setName(resourceID);
ckanResource.setResourceID(resourceID);
return ckanResource.update(json);
}
@ -73,18 +80,19 @@ public class Resource extends BaseREST {
@PathParam(RESOURCE_ID_PARAMETER) String resourceID, String json) {
setCalledMethod("PATCH /" + COLLECTION + "/{" + RESOURCE_ID_PARAMETER + "}");
CKANResource ckanResource = new CKANResource(itemID);
ckanResource.setName(resourceID);
ckanResource.setResourceID(resourceID);
return ckanResource.patch(json);
}
@DELETE
@Path("/{" + RESOURCE_ID_PARAMETER + "}")
public void delete(@PathParam(ITEM_ID_PARAMETER) String itemID,
public Response delete(@PathParam(ITEM_ID_PARAMETER) String itemID,
@PathParam(RESOURCE_ID_PARAMETER) String resourceID) {
setCalledMethod("DELETE /" + COLLECTION + "/{" + RESOURCE_ID_PARAMETER + "}");
CKANResource ckanResource = new CKANResource(itemID);
ckanResource.setName(resourceID);
ckanResource.setResourceID(resourceID);
ckanResource.delete(false);
return Response.status(Status.NO_CONTENT).build();
}
}

View File

@ -16,13 +16,13 @@ import org.gcube.gcat.persistence.ckan.CKANUser;
/**
* @author Luca Frosini (ISTI - CNR)
*/
@Path(BaseREST.USERS)
public class User extends REST<CKANUser> {
@Path(User.USERS)
public class User extends REST<CKANUser> implements org.gcube.gcat.api.interfaces.User<Response,Response> {
protected static final String USER_ID_PARAMETER = "USER_ID";
public User() {
super(BaseREST.USERS, USER_ID_PARAMETER, CKANUser.class);
super(USERS, USER_ID_PARAMETER, CKANUser.class);
}
@GET
@ -43,8 +43,8 @@ public class User extends REST<CKANUser> {
@Path("/{" + USER_ID_PARAMETER + "}")
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
@Override
public String read(@PathParam(USER_ID_PARAMETER) String id) {
return super.read(id);
public String read(@PathParam(USER_ID_PARAMETER) String username) {
return super.read(username);
}
@PUT
@ -52,14 +52,14 @@ public class User extends REST<CKANUser> {
@Consumes(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
@Override
public String update(@PathParam(USER_ID_PARAMETER) String id, String json) {
return super.update(id, json);
public String update(@PathParam(USER_ID_PARAMETER) String username, String json) {
return super.update(username, json);
}
@DELETE
@Path("/{" + USER_ID_PARAMETER + "}")
public Response delete(@PathParam(USER_ID_PARAMETER) String id) {
return super.delete(id, false);
public Response delete(@PathParam(USER_ID_PARAMETER) String username) {
return super.delete(username, false);
}
}

View File

@ -1,8 +1,12 @@
package org.gcube.gcat.utils;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import javax.ws.rs.InternalServerErrorException;
import javax.ws.rs.WebApplicationException;
/**
@ -12,22 +16,36 @@ public class Constants {
public static final String CATALOGUE_NAME = "gCat";
private static final String PROPERTY_FILENAME = "config.properties";
private static final String TOKEN_VARNAME = "TOKEN";
private static final String CATALOGUE_APPLICATION_TOKEN;
/*
* Key : Context
* Value : Application Token
*/
protected static final Map<String,String> applicationTokens;
public static String getCatalogueApplicationToken() {
return CATALOGUE_APPLICATION_TOKEN;
try {
return applicationTokens.get(ContextUtility.getCurrentContext());
}catch (Exception e) {
throw new InternalServerErrorException("Unable to retrieve Application Token for context " + ContextUtility.getCurrentContext(), e);
}
}
static {
try {
applicationTokens = new HashMap<>();
Properties properties = new Properties();
InputStream input = Constants.class.getClassLoader().getResourceAsStream(PROPERTY_FILENAME);
// load a properties file
properties.load(input);
CATALOGUE_APPLICATION_TOKEN = properties.getProperty(TOKEN_VARNAME);
Enumeration<?> enumeration = properties.propertyNames();
while(enumeration.hasMoreElements()) {
String context = (String) enumeration.nextElement();
String applicationToken = properties.getProperty(context);
applicationTokens.put(context, applicationToken);
}
}catch (Exception e) {
throw new WebApplicationException(e);
}

View File

@ -0,0 +1,22 @@
package org.gcube.gcat.rest;
import org.gcube.gcat.ContextTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* @author Luca Frosini (ISTI - CNR)
*/
public class ResourceTest extends ContextTest {
private static Logger logger = LoggerFactory.getLogger(ProfileTest.class);
// @Test
public void read() throws Exception {
Resource resource = new Resource();
String itemID = "";
String resourceID = "";
String ret = resource.read(itemID,resourceID);
logger.debug("{}", ret);
}
}

View File

@ -0,0 +1,20 @@
package org.gcube.gcat.utils;
import org.gcube.gcat.ContextTest;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ConstantsTest extends ContextTest {
private static final Logger logger = LoggerFactory.getLogger(ConstantsTest.class);
@Test
public void testGetApplicationToken() {
logger.debug("Application token for Context {} is {}", ContextUtility.getCurrentContext(), Constants.getCatalogueApplicationToken());
}
}