Adding support for query templates
This commit is contained in:
parent
fc4ed61344
commit
b9d1a43520
|
@ -16,16 +16,16 @@ public class QueryTemplatesSecurityContext extends SecurityContext {
|
|||
|
||||
private static Logger logger = LoggerFactory.getLogger(SecurityContext.class);
|
||||
|
||||
public static final String TEMPLATES_SECURITY_CONTEXT;
|
||||
public static final UUID TEMPLATES_SECURITY_CONTEXT_UUID;
|
||||
public static final String QUERY_TEMPLATES_SECURITY_CONTEXT;
|
||||
public static final UUID QUERY_TEMPLATES_SECURITY_CONTEXT_UUID;
|
||||
|
||||
static {
|
||||
TEMPLATES_SECURITY_CONTEXT = "dddddddd-dddd-dddd-dddd-dddddddddddd";
|
||||
TEMPLATES_SECURITY_CONTEXT_UUID = UUID.fromString(TEMPLATES_SECURITY_CONTEXT);
|
||||
QUERY_TEMPLATES_SECURITY_CONTEXT = "dddddddd-dddd-dddd-dddd-dddddddddddd";
|
||||
QUERY_TEMPLATES_SECURITY_CONTEXT_UUID = UUID.fromString(QUERY_TEMPLATES_SECURITY_CONTEXT);
|
||||
}
|
||||
|
||||
public QueryTemplatesSecurityContext() throws ResourceRegistryException {
|
||||
super(TEMPLATES_SECURITY_CONTEXT_UUID, false);
|
||||
super(QUERY_TEMPLATES_SECURITY_CONTEXT_UUID, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,9 +11,9 @@ import org.gcube.informationsystem.model.reference.properties.PropagationConstra
|
|||
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsOf.ConsistsOfNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsof.ConsistsOfAlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsof.ConsistsOfAvailableInAnotherContextException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.relation.consistsof.ConsistsOfNotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.schema.SchemaViolationException;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.model.Operation;
|
||||
|
|
|
@ -0,0 +1,101 @@
|
|||
package org.gcube.informationsystem.resourceregistry.query.templates;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||
import org.gcube.informationsystem.base.reference.AccessType;
|
||||
import org.gcube.informationsystem.context.reference.entities.Context;
|
||||
import org.gcube.informationsystem.query.templates.reference.entities.QueryTemplate;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.AlreadyPresentException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.QueryTemplatesSecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
|
||||
import org.gcube.informationsystem.resourceregistry.instances.base.entities.EntityElementManagement;
|
||||
import org.gcube.informationsystem.types.reference.entities.EntityType;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.orientechnologies.orient.core.db.document.ODatabaseDocument;
|
||||
import com.orientechnologies.orient.core.record.OVertex;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
public class QueryTemplateManagement extends EntityElementManagement<Context, EntityType> {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(QueryTemplateManagement.class);
|
||||
|
||||
protected String name;
|
||||
|
||||
private void init() {
|
||||
this.typeName = QueryTemplate.NAME;
|
||||
}
|
||||
|
||||
public QueryTemplateManagement() {
|
||||
super(AccessType.QUERY_TEMPLATE);
|
||||
init();
|
||||
}
|
||||
|
||||
public QueryTemplateManagement(ODatabaseDocument oDatabaseDocument) throws ResourceRegistryException {
|
||||
this();
|
||||
this.oDatabaseDocument = oDatabaseDocument;
|
||||
getWorkingContext();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected SecurityContext getWorkingContext() throws ResourceRegistryException {
|
||||
if (workingContext == null) {
|
||||
workingContext = ContextUtility.getInstance()
|
||||
.getSecurityContextByUUID(QueryTemplatesSecurityContext.QUERY_TEMPLATES_SECURITY_CONTEXT_UUID);
|
||||
}
|
||||
return workingContext;
|
||||
}
|
||||
|
||||
public void setName(String queryTemplateName) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JsonNode createCompleteJsonNode() throws ResourceRegistryException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OVertex reallyCreate() throws AlreadyPresentException, ResourceRegistryException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OVertex reallyUpdate() throws NotFoundException, ResourceRegistryException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void reallyDelete() throws NotFoundException, ResourceRegistryException {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected NotFoundException getSpecificNotFoundException(NotFoundException e) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AlreadyPresentException getSpecificAlreadyPresentException(String message) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,110 @@
|
|||
package org.gcube.informationsystem.resourceregistry.rest;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.DELETE;
|
||||
import javax.ws.rs.GET;
|
||||
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.MediaType;
|
||||
import javax.ws.rs.core.Response;
|
||||
import javax.ws.rs.core.Response.Status;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
|
||||
import org.gcube.informationsystem.query.templates.reference.entities.QueryTemplate;
|
||||
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.exceptions.query.InvalidQueryException;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
||||
import org.gcube.informationsystem.resourceregistry.api.rest.QueryTemplatePath;
|
||||
import org.gcube.informationsystem.resourceregistry.query.templates.QueryTemplateManagement;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* @author Luca Frosini (ISTI - CNR)
|
||||
*/
|
||||
@Path(QueryTemplatePath.QUERY_TEMPLATES_PATH_PART)
|
||||
public class QueryTemplateManager {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(QueryTemplateManager.class);
|
||||
|
||||
/*
|
||||
* GET /query-templates
|
||||
*
|
||||
*/
|
||||
@GET
|
||||
@Consumes({MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8})
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String all() throws NotFoundException, ResourceRegistryException {
|
||||
logger.info("Requested to read all {}s", QueryTemplate.NAME);
|
||||
CalledMethodProvider.instance.set("listQueryTemplates");
|
||||
|
||||
QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement();
|
||||
return queryTemplateManagement.all(false);
|
||||
}
|
||||
|
||||
/*
|
||||
* PUT /query-templates/{QUERY_TEMPLATE_NAME}
|
||||
* e.g. PUT /query-templates/GetAllRunningInstances
|
||||
*
|
||||
* BODY: {...}
|
||||
*
|
||||
*/
|
||||
@PUT
|
||||
@Path("{" + AccessPath.QUERY_TEMPLATE_NAME_PATH_PARAM + "}")
|
||||
@Consumes({MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8})
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public Response updateCreate(@PathParam(AccessPath.QUERY_TEMPLATE_NAME_PATH_PARAM) String queryTemplateName, String json)
|
||||
throws InvalidQueryException, ResourceRegistryException {
|
||||
logger.info("Requested {} creation with name {} and content {}", QueryTemplate.NAME, queryTemplateName, json);
|
||||
CalledMethodProvider.instance.set("createQueryTemplate");
|
||||
|
||||
QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement();
|
||||
queryTemplateManagement.setName(queryTemplateName);
|
||||
queryTemplateManagement.setJson(json);
|
||||
String ret = queryTemplateManagement.createOrUpdate();
|
||||
return Response.status(Status.CREATED).entity(ret).type(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
.build();
|
||||
}
|
||||
|
||||
/*
|
||||
* GET /query-templates/{QUERY_TEMPLATE_NAME}
|
||||
* e.g. GET /query-templates/GetAllRunningInstances
|
||||
*
|
||||
*/
|
||||
@GET
|
||||
@Path("{" + AccessPath.QUERY_TEMPLATE_NAME_PATH_PARAM + "}")
|
||||
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
||||
public String read(@PathParam(AccessPath.QUERY_TEMPLATE_NAME_PATH_PARAM) String queryTemplateName)
|
||||
throws NotFoundException, ResourceRegistryException {
|
||||
logger.info("Requested {} with name", QueryTemplate.NAME, queryTemplateName);
|
||||
CalledMethodProvider.instance.set("readQueryTemplate");
|
||||
|
||||
QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement();
|
||||
queryTemplateManagement.setName(queryTemplateName);
|
||||
return queryTemplateManagement.read();
|
||||
}
|
||||
|
||||
/*
|
||||
* DELETE /query-templates/{QUERY_TEMPLATE_NAME}
|
||||
* e.g. DELETE /query-templates/GetAllRunningInstances
|
||||
*/
|
||||
@DELETE
|
||||
@Consumes({MediaType.TEXT_PLAIN, ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8})
|
||||
@Path("{" + AccessPath.QUERY_TEMPLATE_NAME_PATH_PARAM + "}")
|
||||
public Response delete(@PathParam(AccessPath.QUERY_TEMPLATE_NAME_PATH_PARAM) String queryTemplateName)
|
||||
throws NotFoundException, ResourceRegistryException {
|
||||
logger.info("Requested to delete {} with name {} ", QueryTemplate.NAME, queryTemplateName);
|
||||
CalledMethodProvider.instance.set("deleteQueryTemplate");
|
||||
|
||||
QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement();
|
||||
queryTemplateManagement.setName(queryTemplateName);
|
||||
queryTemplateManagement.delete();
|
||||
|
||||
return Response.status(Status.NO_CONTENT).build();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue