2016-12-22 17:27:26 +01:00
|
|
|
package org.gcube.informationsystem.resourceregistry.rest;
|
2016-07-18 11:57:12 +02:00
|
|
|
|
2017-09-27 12:59:00 +02:00
|
|
|
import java.util.HashMap;
|
2021-02-19 14:34:48 +01:00
|
|
|
import java.util.List;
|
2017-09-27 12:59:00 +02:00
|
|
|
import java.util.Map;
|
2016-10-27 17:46:09 +02:00
|
|
|
import java.util.UUID;
|
|
|
|
|
2017-06-16 11:23:03 +02:00
|
|
|
import javax.ws.rs.DefaultValue;
|
2016-07-18 11:57:12 +02:00
|
|
|
import javax.ws.rs.GET;
|
2017-03-28 16:01:42 +02:00
|
|
|
import javax.ws.rs.HEAD;
|
2021-09-27 18:00:18 +02:00
|
|
|
import javax.ws.rs.POST;
|
2016-07-18 11:57:12 +02:00
|
|
|
import javax.ws.rs.Path;
|
2016-08-04 15:45:07 +02:00
|
|
|
import javax.ws.rs.PathParam;
|
2016-10-27 17:46:09 +02:00
|
|
|
import javax.ws.rs.Produces;
|
2016-07-18 11:57:12 +02:00
|
|
|
import javax.ws.rs.QueryParam;
|
2017-09-27 12:59:00 +02:00
|
|
|
import javax.ws.rs.core.Context;
|
|
|
|
import javax.ws.rs.core.MultivaluedMap;
|
2017-04-11 15:22:53 +02:00
|
|
|
import javax.ws.rs.core.Response;
|
|
|
|
import javax.ws.rs.core.Response.Status;
|
2017-09-27 12:59:00 +02:00
|
|
|
import javax.ws.rs.core.UriInfo;
|
2016-07-18 11:57:12 +02:00
|
|
|
|
2017-06-28 16:26:47 +02:00
|
|
|
import org.gcube.common.authorization.library.provider.CalledMethodProvider;
|
2019-02-13 12:33:29 +01:00
|
|
|
import org.gcube.informationsystem.model.reference.entities.Resource;
|
2017-03-24 17:04:09 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.ResourceInitializer;
|
2018-06-04 15:31:13 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.AvailableInAnotherContextException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.NotFoundException;
|
2016-07-18 11:57:12 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
|
2022-02-01 16:49:12 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.contexts.ContextNotFoundException;
|
2021-10-25 11:00:54 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException;
|
2016-09-01 17:11:44 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
|
2022-07-20 12:10:03 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.ContextPath;
|
2021-07-07 11:24:47 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.InstancePath;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.api.rest.TypePath;
|
2020-01-27 17:07:37 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.contexts.entities.ContextManagement;
|
2020-01-30 11:04:16 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagementUtility;
|
2019-11-06 12:13:19 +01:00
|
|
|
import org.gcube.informationsystem.resourceregistry.instances.model.entities.ResourceManagement;
|
2021-10-25 11:00:54 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.queries.Query;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.queries.QueryImpl;
|
|
|
|
import org.gcube.informationsystem.resourceregistry.queries.json.JsonQuery;
|
2023-05-02 17:24:42 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.requests.ServerRequestInfo;
|
2021-10-22 10:24:16 +02:00
|
|
|
import org.gcube.informationsystem.resourceregistry.types.TypeManagement;
|
2021-02-19 14:34:48 +01:00
|
|
|
import org.gcube.informationsystem.types.TypeMapper;
|
|
|
|
import org.gcube.informationsystem.types.reference.Type;
|
2016-07-18 11:57:12 +02:00
|
|
|
|
2023-05-12 16:06:48 +02:00
|
|
|
import com.arcadedb.graph.Vertex.DIRECTION;
|
2017-01-11 12:06:50 +01:00
|
|
|
|
2016-07-18 11:57:12 +02:00
|
|
|
/**
|
2016-10-12 14:33:23 +02:00
|
|
|
* @author Luca Frosini (ISTI - CNR)
|
2016-07-18 11:57:12 +02:00
|
|
|
*/
|
2016-09-01 17:11:44 +02:00
|
|
|
@Path(AccessPath.ACCESS_PATH_PART)
|
2020-10-27 15:36:28 +01:00
|
|
|
public class Access extends BaseRest {
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2022-07-20 12:10:03 +02:00
|
|
|
public static final String RESOURCE_TYPE_PATH_PARAMETER = "RESOURCE_TYPE_NAME";
|
|
|
|
public static final String RELATION_TYPE_PATH_PARAMETER = "RELATION_TYPE_NAME";
|
|
|
|
public static final String REFERENCE_TYPE_PATH_PARAMETER = "REFERENCE_TYPE_NAME";
|
|
|
|
|
2021-09-02 15:06:40 +02:00
|
|
|
public Access() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
|
2018-06-06 19:26:19 +02:00
|
|
|
/*
|
2018-06-07 18:12:06 +02:00
|
|
|
* e.g. GET /access/contexts
|
2016-09-01 10:59:35 +02:00
|
|
|
*/
|
2016-07-18 11:57:12 +02:00
|
|
|
@GET
|
2018-06-06 19:26:19 +02:00
|
|
|
@Path(AccessPath.CONTEXTS_PATH_PART)
|
2017-03-24 17:04:09 +01:00
|
|
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
2018-06-08 15:05:47 +02:00
|
|
|
public String getAllContexts() throws ResourceRegistryException {
|
2021-10-25 11:40:47 +02:00
|
|
|
logger.info("Requested to read all {}s", org.gcube.informationsystem.contexts.reference.entities.Context.NAME);
|
2020-03-16 14:51:13 +01:00
|
|
|
CalledMethodProvider.instance.set("listContexts");
|
2021-03-02 09:13:53 +01:00
|
|
|
|
2023-05-05 15:48:59 +02:00
|
|
|
ServerRequestInfo serverRequestInfo = initRequestInfo();
|
2023-05-10 17:21:00 +02:00
|
|
|
serverRequestInfo.checkIncludeAllMetaQueryParameters();
|
2023-05-05 15:48:59 +02:00
|
|
|
|
2018-06-07 18:12:06 +02:00
|
|
|
ContextManagement contextManagement = new ContextManagement();
|
2018-06-06 19:26:19 +02:00
|
|
|
return contextManagement.all(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2018-06-08 09:30:02 +02:00
|
|
|
* GET /access/contexts/{CONTEXT_UUID}
|
2018-06-07 18:12:06 +02:00
|
|
|
* e.g. GET /access/contexts/c0f314e7-2807-4241-a792-2a6c79ed4fd0
|
2018-06-06 19:26:19 +02:00
|
|
|
*/
|
|
|
|
@GET
|
2022-07-20 12:10:03 +02:00
|
|
|
@Path(AccessPath.CONTEXTS_PATH_PART + "/{" + InstancesManager.UUID_PATH_PARAMETER + "}")
|
2018-06-06 19:26:19 +02:00
|
|
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
2022-07-20 12:10:03 +02:00
|
|
|
public String getContext(@PathParam(InstancesManager.UUID_PATH_PARAMETER) String uuid)
|
2018-06-06 19:26:19 +02:00
|
|
|
throws ContextNotFoundException, ResourceRegistryException {
|
2022-07-20 12:10:03 +02:00
|
|
|
if(uuid.compareTo(ContextPath.CURRENT_CONTEXT_PATH_PART)==0){
|
2018-06-12 12:22:58 +02:00
|
|
|
uuid = ContextUtility.getCurrentSecurityContext().getUUID().toString();
|
|
|
|
}
|
2021-10-25 11:40:47 +02:00
|
|
|
logger.info("Requested to read {} with id {} ", org.gcube.informationsystem.contexts.reference.entities.Context.NAME, uuid);
|
2020-03-16 14:51:13 +01:00
|
|
|
CalledMethodProvider.instance.set("readContext");
|
2018-06-12 12:22:58 +02:00
|
|
|
|
2023-05-05 15:48:59 +02:00
|
|
|
ServerRequestInfo serverRequestInfo = initRequestInfo();
|
2023-05-10 17:21:00 +02:00
|
|
|
serverRequestInfo.checkIncludeAllMetaQueryParameters();
|
2023-05-05 15:48:59 +02:00
|
|
|
|
2018-06-12 12:22:58 +02:00
|
|
|
ContextManagement contextManagement = new ContextManagement();
|
2018-06-06 19:26:19 +02:00
|
|
|
contextManagement.setUUID(UUID.fromString(uuid));
|
2021-02-05 17:50:16 +01:00
|
|
|
return contextManagement.readAsString();
|
2016-07-18 11:57:12 +02:00
|
|
|
}
|
2017-03-28 16:01:42 +02:00
|
|
|
|
2018-06-06 19:26:19 +02:00
|
|
|
/*
|
2018-06-07 18:12:06 +02:00
|
|
|
* GET /access/types/{TYPE_NAME}[?polymorphic=false]
|
|
|
|
* e.g. GET /access/types/ContactFacet?polymorphic=true
|
2018-06-06 19:26:19 +02:00
|
|
|
*/
|
|
|
|
@GET
|
2022-07-20 12:10:03 +02:00
|
|
|
@Path(AccessPath.TYPES_PATH_PART + "/{" + TypeManager.TYPE_PATH_PARAMETER + "}")
|
2018-06-06 19:26:19 +02:00
|
|
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
2022-07-20 12:10:03 +02:00
|
|
|
public String getType(@PathParam(TypeManager.TYPE_PATH_PARAMETER) String type,
|
|
|
|
@QueryParam(TypePath.POLYMORPHIC_QUERY_PARAMETER) @DefaultValue("false") Boolean polymorphic)
|
2018-06-06 19:26:19 +02:00
|
|
|
throws SchemaNotFoundException, ResourceRegistryException {
|
|
|
|
logger.info("Requested Schema for type {}", type);
|
2020-03-16 14:51:13 +01:00
|
|
|
CalledMethodProvider.instance.set("readType");
|
2018-06-07 18:12:06 +02:00
|
|
|
|
2023-05-05 15:48:59 +02:00
|
|
|
ServerRequestInfo serverRequestInfo = initRequestInfo();
|
2023-05-10 17:21:00 +02:00
|
|
|
serverRequestInfo.checkIncludeAllMetaQueryParameters();
|
2023-05-05 15:48:59 +02:00
|
|
|
|
2021-10-22 10:24:16 +02:00
|
|
|
TypeManagement typeManagement = new TypeManagement();
|
|
|
|
typeManagement.setTypeName(type);
|
|
|
|
List<Type> types = typeManagement.read(polymorphic);
|
2021-02-19 14:34:48 +01:00
|
|
|
try {
|
|
|
|
return TypeMapper.serializeTypeDefinitions(types);
|
|
|
|
}catch (Exception e) {
|
|
|
|
throw new ResourceRegistryException(e);
|
|
|
|
}
|
2018-06-06 19:26:19 +02:00
|
|
|
}
|
|
|
|
|
2018-06-07 18:12:06 +02:00
|
|
|
/*
|
|
|
|
* GET /access/instances/{TYPE_NAME}[?polymorphic=true]
|
|
|
|
* e.g. GET /access/instances/ContactFacet?polymorphic=true
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
@GET
|
2022-07-20 12:10:03 +02:00
|
|
|
@Path(AccessPath.INSTANCES_PATH_PART + "/{" + TypeManager.TYPE_PATH_PARAMETER + "}")
|
2018-06-07 18:12:06 +02:00
|
|
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
2022-07-20 12:10:03 +02:00
|
|
|
public String getAllInstances(@PathParam(TypeManager.TYPE_PATH_PARAMETER) String type,
|
|
|
|
@QueryParam(InstancePath.POLYMORPHIC_QUERY_PARAMETER) @DefaultValue("true") Boolean polymorphic)
|
2018-06-07 18:12:06 +02:00
|
|
|
throws NotFoundException, ResourceRegistryException {
|
2022-07-20 12:10:03 +02:00
|
|
|
logger.info("Requested all {}instances of {}", polymorphic ? InstancePath.POLYMORPHIC_QUERY_PARAMETER + " " : "", type);
|
2021-03-02 09:13:53 +01:00
|
|
|
CalledMethodProvider.instance.set("listInstances");
|
|
|
|
|
2023-05-05 15:48:59 +02:00
|
|
|
ServerRequestInfo serverRequestInfo = initRequestInfo();
|
|
|
|
serverRequestInfo.checkAllQueryParameters();
|
2018-06-07 18:12:06 +02:00
|
|
|
|
2021-03-05 15:04:27 +01:00
|
|
|
ElementManagement<?,?> erManagement = ElementManagementUtility.getERManagement(type);
|
2018-06-07 18:12:06 +02:00
|
|
|
return erManagement.all(polymorphic);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* HEAD /access/instances/{TYPE_NAME}/{UUID}
|
|
|
|
* e.g. HEAD /access/instances/ContactFacet/4023d5b2-8601-47a5-83ef-49ffcbfc7d86
|
|
|
|
*
|
|
|
|
*/
|
2017-03-28 16:01:42 +02:00
|
|
|
@HEAD
|
2022-07-20 12:10:03 +02:00
|
|
|
@Path(AccessPath.INSTANCES_PATH_PART + "/{" + TypeManager.TYPE_PATH_PARAMETER + "}" + "/{" + InstancesManager.UUID_PATH_PARAMETER + "}")
|
2018-06-07 18:12:06 +02:00
|
|
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
2022-07-20 12:10:03 +02:00
|
|
|
public Response instanceExists(@PathParam(TypeManager.TYPE_PATH_PARAMETER) String type,
|
|
|
|
@PathParam(InstancesManager.UUID_PATH_PARAMETER) String uuid) throws NotFoundException, ResourceRegistryException {
|
2018-06-07 18:12:06 +02:00
|
|
|
logger.info("Requested to check if {} with id {} exists", type, uuid);
|
2021-03-02 09:13:53 +01:00
|
|
|
CalledMethodProvider.instance.set("existInstance");
|
|
|
|
|
2023-05-05 15:48:59 +02:00
|
|
|
ServerRequestInfo serverRequestInfo = initRequestInfo();
|
|
|
|
serverRequestInfo.checkQueryParameter(InstancePath.HIERARCHICAL_MODE_QUERY_PARAMETER);
|
2017-06-28 16:26:47 +02:00
|
|
|
|
2021-03-05 15:04:27 +01:00
|
|
|
ElementManagement<?,?> erManagement = ElementManagementUtility.getERManagement(type);
|
2018-06-07 18:12:06 +02:00
|
|
|
|
2017-04-11 15:22:53 +02:00
|
|
|
try {
|
2018-06-07 18:12:06 +02:00
|
|
|
erManagement.setUUID(UUID.fromString(uuid));
|
2018-06-12 17:24:19 +02:00
|
|
|
boolean found = erManagement.exists();
|
2017-11-30 18:06:08 +01:00
|
|
|
if(found) {
|
2017-04-11 15:22:53 +02:00
|
|
|
return Response.status(Status.NO_CONTENT).build();
|
2017-11-30 18:06:08 +01:00
|
|
|
} else {
|
2017-04-11 15:22:53 +02:00
|
|
|
// This code should never be reached due to exception management
|
|
|
|
// anyway adding it for safety reason
|
|
|
|
return Response.status(Status.NOT_FOUND).build();
|
|
|
|
}
|
2018-06-04 15:31:13 +02:00
|
|
|
} catch(NotFoundException e) {
|
2017-04-11 15:22:53 +02:00
|
|
|
return Response.status(Status.NOT_FOUND).build();
|
2018-06-04 15:31:13 +02:00
|
|
|
} catch(AvailableInAnotherContextException e) {
|
2017-04-11 19:38:46 +02:00
|
|
|
return Response.status(Status.FORBIDDEN).build();
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(ResourceRegistryException e) {
|
2017-04-11 15:22:53 +02:00
|
|
|
throw e;
|
|
|
|
}
|
2017-03-28 16:01:42 +02:00
|
|
|
}
|
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
/*
|
2018-06-07 18:12:06 +02:00
|
|
|
* GET /access/instances/{TYPE_NAME}/{UUID}
|
|
|
|
* e.g. GET /access/instances/ContactFacet/4023d5b2-8601-47a5-83ef-49ffcbfc7d86
|
|
|
|
*
|
2016-09-01 10:59:35 +02:00
|
|
|
*/
|
2016-10-27 17:46:09 +02:00
|
|
|
@GET
|
2022-07-20 12:10:03 +02:00
|
|
|
@Path(AccessPath.INSTANCES_PATH_PART + "/{" + TypeManager.TYPE_PATH_PARAMETER + "}" + "/{" + InstancesManager.UUID_PATH_PARAMETER + "}")
|
2017-03-24 17:04:09 +01:00
|
|
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
2022-07-20 12:10:03 +02:00
|
|
|
public String getInstance(@PathParam(TypeManager.TYPE_PATH_PARAMETER) String type,
|
|
|
|
@PathParam(InstancesManager.UUID_PATH_PARAMETER) String uuid) throws NotFoundException, ResourceRegistryException {
|
2018-06-07 18:12:06 +02:00
|
|
|
logger.info("Requested to read {} with id {}", type, uuid);
|
2021-03-02 09:13:53 +01:00
|
|
|
CalledMethodProvider.instance.set("readInstance");
|
|
|
|
|
2023-05-05 15:48:59 +02:00
|
|
|
ServerRequestInfo serverRequestInfo = initRequestInfo();
|
|
|
|
serverRequestInfo.checkAllQueryParameters();
|
2020-10-27 15:36:28 +01:00
|
|
|
|
2017-01-11 12:06:50 +01:00
|
|
|
@SuppressWarnings("rawtypes")
|
2020-01-30 11:04:16 +01:00
|
|
|
ElementManagement erManagement = ElementManagementUtility.getERManagement(type);
|
2018-06-07 18:12:06 +02:00
|
|
|
|
|
|
|
erManagement.setElementType(type);
|
|
|
|
erManagement.setUUID(UUID.fromString(uuid));
|
2021-02-05 17:50:16 +01:00
|
|
|
return erManagement.read().toString();
|
2016-07-18 11:57:12 +02:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2020-11-11 14:17:03 +01:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GET /access/instances/{TYPE_NAME}/{UUID}/contexts
|
|
|
|
* e.g. GET /access/instances/ContactFacet/4023d5b2-8601-47a5-83ef-49ffcbfc7d86/contexts
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
@GET
|
2022-07-20 12:10:03 +02:00
|
|
|
@Path(AccessPath.INSTANCES_PATH_PART + "/{" + TypeManager.TYPE_PATH_PARAMETER + "}" + "/{" + InstancesManager.UUID_PATH_PARAMETER + "}/" + AccessPath.CONTEXTS_PATH_PART)
|
2020-11-11 14:17:03 +01:00
|
|
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
2022-07-20 12:10:03 +02:00
|
|
|
public String getInstanceContexts(@PathParam(TypeManager.TYPE_PATH_PARAMETER) String type,
|
|
|
|
@PathParam(InstancesManager.UUID_PATH_PARAMETER) String instanceId) throws NotFoundException, ResourceRegistryException {
|
2020-11-11 14:17:03 +01:00
|
|
|
logger.info("Requested to get contexts of {} with UUID {}", type, instanceId);
|
|
|
|
CalledMethodProvider.instance.set("getInstanceContexts");
|
|
|
|
|
2021-03-05 15:04:27 +01:00
|
|
|
ElementManagement<?,?> erManagement = ElementManagementUtility.getERManagement(type);
|
2020-11-11 14:17:03 +01:00
|
|
|
erManagement.setUUID(UUID.fromString(instanceId));
|
|
|
|
return erManagement.getContexts();
|
|
|
|
}
|
|
|
|
|
2018-06-06 19:26:19 +02:00
|
|
|
/**
|
|
|
|
* It includeSubtypes to query Entities and Relations in the current Context.<br />
|
|
|
|
* It accepts idempotent query only.. <br />
|
|
|
|
* <br />
|
|
|
|
* For query syntax please refer to<br />
|
|
|
|
*
|
|
|
|
* <a href="https://orientdb.com/docs/last/SQL-Syntax.html" target="_blank">
|
|
|
|
* https://orientdb.com/docs/last/SQL-Syntax.html </a> <br />
|
|
|
|
* <br />
|
|
|
|
*
|
2022-07-20 15:08:03 +02:00
|
|
|
* e.g. GET /access/query?q=SELECT FROM V
|
2018-06-06 19:26:19 +02:00
|
|
|
*
|
2018-06-08 15:05:47 +02:00
|
|
|
* @param query Defines the query to send to the backend.
|
2022-07-18 14:19:05 +02:00
|
|
|
* @param raw request a raw response (not a Element based response)
|
2018-06-06 19:26:19 +02:00
|
|
|
* @return The JSON representation of the result
|
2018-06-08 15:05:47 +02:00
|
|
|
* @throws InvalidQueryException if the query is invalid or not idempotent
|
2018-06-06 19:26:19 +02:00
|
|
|
*/
|
|
|
|
@GET
|
2021-09-27 18:29:23 +02:00
|
|
|
@Path(AccessPath.QUERY_PATH_PART)
|
2018-06-06 19:26:19 +02:00
|
|
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
2022-07-20 12:10:03 +02:00
|
|
|
public String graphQuery(@QueryParam(AccessPath.Q_QUERY_PARAMETER) String query,
|
|
|
|
@QueryParam(AccessPath.RAW_QUERY_PARAMETER) @DefaultValue(AccessPath.RAW_QUERY_PARAMETER_DEFAULT_VALUE) Boolean raw)
|
2018-06-08 15:05:47 +02:00
|
|
|
throws InvalidQueryException {
|
2022-07-18 16:35:44 +02:00
|
|
|
logger.info("Requested query (Raw {}):\n{}", raw, query);
|
2021-09-27 18:00:18 +02:00
|
|
|
CalledMethodProvider.instance.set("graphQuery");
|
2021-03-02 09:13:53 +01:00
|
|
|
|
2023-05-05 15:48:59 +02:00
|
|
|
ServerRequestInfo serverRequestInfo = initRequestInfo();
|
2023-05-02 14:48:38 +02:00
|
|
|
if(raw) {
|
|
|
|
// TODO Check if the role allow to request raw data
|
2023-05-05 15:48:59 +02:00
|
|
|
serverRequestInfo.checkQueryParameter(InstancePath.HIERARCHICAL_MODE_QUERY_PARAMETER);
|
2023-05-02 14:48:38 +02:00
|
|
|
}else {
|
2023-05-05 15:48:59 +02:00
|
|
|
serverRequestInfo.checkAllQueryParameters();
|
2023-05-02 14:48:38 +02:00
|
|
|
}
|
2018-06-08 15:05:47 +02:00
|
|
|
|
2018-06-06 19:26:19 +02:00
|
|
|
Query queryManager = new QueryImpl();
|
2022-07-18 16:35:44 +02:00
|
|
|
return queryManager.query(query, raw);
|
2018-06-06 19:26:19 +02:00
|
|
|
}
|
|
|
|
|
2021-09-27 18:29:23 +02:00
|
|
|
/**
|
|
|
|
* POST /access/query
|
|
|
|
*
|
|
|
|
* Content Body example:
|
|
|
|
*
|
|
|
|
* {
|
2023-04-26 21:44:03 +02:00
|
|
|
* "": "EService",
|
2021-09-27 18:29:23 +02:00
|
|
|
* "consistsOf": [
|
|
|
|
* {
|
2023-04-26 21:44:03 +02:00
|
|
|
* "": "ConsistsOf",
|
2021-09-27 18:29:23 +02:00
|
|
|
* "propagationConstraint" : {
|
|
|
|
* "add": "propagate"
|
|
|
|
* },
|
|
|
|
* "target": {
|
2023-04-26 21:44:03 +02:00
|
|
|
* "": "StateFacet",
|
2021-09-27 18:29:23 +02:00
|
|
|
* "value": "down"
|
|
|
|
* }
|
|
|
|
* },
|
|
|
|
* {
|
2023-04-26 21:44:03 +02:00
|
|
|
* "": "IsIdentifiedBy",
|
2021-09-27 18:29:23 +02:00
|
|
|
* "target": {
|
2023-04-26 21:44:03 +02:00
|
|
|
* "": "SoftwareFacet",
|
2021-09-27 18:29:23 +02:00
|
|
|
* "name": "data-transfer-service",
|
|
|
|
* "group": "DataTransfer"
|
|
|
|
* }
|
|
|
|
* },
|
|
|
|
* {
|
2023-04-26 21:44:03 +02:00
|
|
|
* "": "ConsistsOf",
|
2021-09-27 18:29:23 +02:00
|
|
|
* "target": {
|
2023-04-26 21:44:03 +02:00
|
|
|
* "": "AccessPointFacet",
|
2021-09-27 18:29:23 +02:00
|
|
|
* "endpoint": "http://pc-frosini.isti.cnr.it:8080/data-transfer-service/gcube/service"
|
|
|
|
* }
|
|
|
|
* }
|
|
|
|
* ]
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* @param jsonQuery
|
2022-03-07 11:29:03 +01:00
|
|
|
* @return the result as JSON String
|
2021-09-27 18:29:23 +02:00
|
|
|
* @throws InvalidQueryException
|
|
|
|
* @throws ResourceRegistryException
|
|
|
|
*/
|
2021-09-27 18:00:18 +02:00
|
|
|
@POST
|
|
|
|
@Path(AccessPath.QUERY_PATH_PART)
|
|
|
|
public String jsonQuery(String jsonQuery) throws InvalidQueryException, ResourceRegistryException {
|
|
|
|
logger.info("Requested json query \n{}", jsonQuery);
|
|
|
|
CalledMethodProvider.instance.set("jsonQuery");
|
|
|
|
|
2023-05-05 15:48:59 +02:00
|
|
|
ServerRequestInfo serverRequestInfo = initRequestInfo();
|
|
|
|
serverRequestInfo.checkAllQueryParameters();
|
2021-09-27 18:00:18 +02:00
|
|
|
|
2021-10-14 15:01:22 +02:00
|
|
|
JsonQuery jsonQueryManager = new JsonQuery();
|
2021-10-18 12:24:57 +02:00
|
|
|
jsonQueryManager.setJsonQuery(jsonQuery);
|
|
|
|
return jsonQueryManager.query();
|
2021-09-27 18:00:18 +02:00
|
|
|
}
|
|
|
|
|
2016-12-30 17:31:12 +01:00
|
|
|
/*
|
2022-07-14 15:48:36 +02:00
|
|
|
* /access/query/{RESOURCE_TYPE_NAME}/{RELATION_TYPE_NAME}/{ENTITY_TYPE_NAME}[?_reference={REFERENCE_ENTITY_UUID}&_polymorphic=true&_direction=out]
|
2018-06-08 15:39:04 +02:00
|
|
|
*
|
|
|
|
* e.g.
|
|
|
|
* All the EService identified By a SoftwareFacet :
|
2022-07-14 15:48:36 +02:00
|
|
|
* GET /access/query/EService/isIdentifiedBy/SoftwareFacet?_polymorphic=true&_direction=out
|
2018-06-08 15:39:04 +02:00
|
|
|
*
|
2021-01-28 22:53:10 +01:00
|
|
|
* All the EService identified By the SoftwareFacet with UUID 7bc997c3-d005-40ff-b9ed-c4b6a35851f1 :
|
2022-07-14 15:48:36 +02:00
|
|
|
* GET /access/query/EService/isIdentifiedBy/SoftwareFacet?_reference=7bc997c3-d005-40ff-b9ed-c4b6a35851f1&_polymorphic=true&_direction=out
|
2018-06-08 15:39:04 +02:00
|
|
|
*
|
|
|
|
* All the Resources identified By a ContactFacet :
|
2022-07-14 15:48:36 +02:00
|
|
|
* GET /access/query/Resource/isIdentifiedBy/ContactFacet?_polymorphic=true&_direction=out
|
2018-06-08 15:39:04 +02:00
|
|
|
*
|
|
|
|
* All the Resources with a ContactFacet :
|
2022-07-14 15:48:36 +02:00
|
|
|
* /access/query/Resource/ConsistsOf/ContactFacet?_polymorphic=true&_direction=out
|
2018-06-08 15:39:04 +02:00
|
|
|
*
|
|
|
|
* All the Eservice having an incoming (IN) Hosts relation with an HostingNode (i.e. all smartgears services)
|
2022-07-14 15:48:36 +02:00
|
|
|
* GET /access/query/EService/Hosts/HostingNode?_polymorphic=true&_direction=in
|
2018-06-08 15:39:04 +02:00
|
|
|
*
|
|
|
|
* All the Eservice having an incoming (IN) Hosts relation (i.e. hosted by) the HostingNode with UUID
|
|
|
|
* 16032d09-3823-444e-a1ff-a67de4f350a
|
2022-07-14 15:48:36 +02:00
|
|
|
* * GET /access/query/EService/hosts/HostingNode?_reference=16032d09-3823-444e-a1ff-a67de4f350a8&_polymorphic=true&_direction=in
|
2018-06-08 15:39:04 +02:00
|
|
|
*
|
2016-09-01 10:59:35 +02:00
|
|
|
*/
|
2017-11-30 18:06:08 +01:00
|
|
|
@SuppressWarnings({"rawtypes"})
|
2016-10-27 17:46:09 +02:00
|
|
|
@GET
|
2022-07-20 12:10:03 +02:00
|
|
|
@Path(AccessPath.QUERY_PATH_PART + "/" + "{" + Access.RESOURCE_TYPE_PATH_PARAMETER + "}" + "/" + "{"
|
|
|
|
+ Access.RELATION_TYPE_PATH_PARAMETER + "}" + "/" + "{" + Access.REFERENCE_TYPE_PATH_PARAMETER + "}")
|
2017-03-24 17:04:09 +01:00
|
|
|
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
|
2022-07-20 12:10:03 +02:00
|
|
|
public String getAllResourcesHavingFacet(@PathParam(Access.RESOURCE_TYPE_PATH_PARAMETER) String resourcetype,
|
|
|
|
@PathParam(Access.RELATION_TYPE_PATH_PARAMETER) String relationType,
|
|
|
|
@PathParam(Access.REFERENCE_TYPE_PATH_PARAMETER) String referenceType,
|
|
|
|
@QueryParam(AccessPath._REFERENCE_QUERY_PARAMETER) String reference,
|
|
|
|
@QueryParam(AccessPath._POLYMORPHIC_QUERY_PARAMETER) @DefaultValue("false") Boolean polymorphic,
|
|
|
|
@QueryParam(AccessPath._DIRECTION_QUERY_PARAMETER) @DefaultValue("out") String direction,
|
2021-07-07 12:01:47 +02:00
|
|
|
/*@QueryParam(AccessPath._INCLUDE_RELATION_PARAM) @DefaultValue("false") Boolean includeRelation,*/
|
2018-06-08 15:05:47 +02:00
|
|
|
@Context UriInfo uriInfo) throws ResourceRegistryException {
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2021-07-07 17:36:10 +02:00
|
|
|
logger.info("Requested {} instances having a(n) {} ({}={}} with {} ({}={}). Request URI is {})", resourcetype, relationType,
|
2022-07-20 12:10:03 +02:00
|
|
|
AccessPath._DIRECTION_QUERY_PARAMETER, direction, referenceType, AccessPath._POLYMORPHIC_QUERY_PARAMETER, polymorphic, uriInfo.getRequestUri());
|
2021-07-07 11:24:47 +02:00
|
|
|
|
2021-03-02 09:13:53 +01:00
|
|
|
CalledMethodProvider.instance.set("query");
|
|
|
|
|
2023-05-05 15:48:59 +02:00
|
|
|
ServerRequestInfo serverRequestInfo = initRequestInfo();
|
|
|
|
serverRequestInfo.checkAllQueryParameters();
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2020-01-30 11:04:16 +01:00
|
|
|
ElementManagement erManagement = ElementManagementUtility.getERManagement(resourcetype);
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-08 15:05:47 +02:00
|
|
|
if(erManagement instanceof ResourceManagement) {
|
|
|
|
UUID refereceUUID = null;
|
2023-05-12 16:06:48 +02:00
|
|
|
DIRECTION directionEnum = DIRECTION.OUT;
|
2018-06-08 15:05:47 +02:00
|
|
|
|
|
|
|
Map<String,String> constraint = new HashMap<>();
|
|
|
|
|
|
|
|
MultivaluedMap<String,String> multivaluedMap = uriInfo.getQueryParameters();
|
|
|
|
for(String key : multivaluedMap.keySet()) {
|
2021-07-07 11:24:47 +02:00
|
|
|
switch (key) {
|
2022-07-20 12:10:03 +02:00
|
|
|
case AccessPath._POLYMORPHIC_QUERY_PARAMETER:
|
2021-07-07 11:24:47 +02:00
|
|
|
break;
|
|
|
|
|
2022-07-20 12:10:03 +02:00
|
|
|
case AccessPath._DIRECTION_QUERY_PARAMETER:
|
2021-07-07 11:24:47 +02:00
|
|
|
break;
|
|
|
|
|
2022-07-20 12:10:03 +02:00
|
|
|
case AccessPath._REFERENCE_QUERY_PARAMETER:
|
2021-07-07 11:24:47 +02:00
|
|
|
break;
|
|
|
|
|
2021-07-07 12:01:47 +02:00
|
|
|
/*
|
2021-07-07 11:24:47 +02:00
|
|
|
case AccessPath._INCLUDE_RELATION_PARAM:
|
|
|
|
break;
|
2021-07-07 12:01:47 +02:00
|
|
|
*/
|
|
|
|
|
2021-07-07 11:24:47 +02:00
|
|
|
case "gcube-token":
|
|
|
|
break;
|
|
|
|
|
|
|
|
case "gcube-scope":
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
constraint.put(key, multivaluedMap.getFirst(key));
|
|
|
|
break;
|
2018-06-08 15:05:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-30 18:06:08 +01:00
|
|
|
if(reference != null) {
|
2017-01-11 12:06:50 +01:00
|
|
|
try {
|
2018-06-08 15:05:47 +02:00
|
|
|
refereceUUID = UUID.fromString(reference);
|
2017-11-30 18:06:08 +01:00
|
|
|
} catch(Exception e) {
|
2018-06-08 15:05:47 +02:00
|
|
|
String error = String.format("%s is not a valid %s", reference, UUID.class.getSimpleName());
|
|
|
|
throw new InvalidQueryException(error);
|
2017-01-11 12:06:50 +01:00
|
|
|
}
|
2017-09-28 16:58:15 +02:00
|
|
|
}
|
2018-06-08 15:05:47 +02:00
|
|
|
try {
|
2023-05-12 16:06:48 +02:00
|
|
|
directionEnum = DIRECTION.valueOf(direction.toUpperCase());
|
2018-06-08 15:05:47 +02:00
|
|
|
} catch(Exception e) {
|
2023-05-12 16:06:48 +02:00
|
|
|
String error = String.format("%s is not a valid. Allowed values are %s", direction, DIRECTION.values());
|
2018-06-08 15:05:47 +02:00
|
|
|
throw new InvalidQueryException(error);
|
2017-09-28 16:58:15 +02:00
|
|
|
}
|
2018-06-08 15:05:47 +02:00
|
|
|
|
|
|
|
return ((ResourceManagement) erManagement).query(relationType, referenceType, refereceUUID, directionEnum,
|
2021-07-07 12:01:47 +02:00
|
|
|
polymorphic, constraint); /*, includeRelation*/
|
2017-09-27 12:59:00 +02:00
|
|
|
}
|
2017-11-30 18:06:08 +01:00
|
|
|
|
2018-06-08 15:05:47 +02:00
|
|
|
String error = String.format("%s is not a %s type", resourcetype, Resource.NAME);
|
|
|
|
throw new InvalidQueryException(error);
|
2017-09-27 12:59:00 +02:00
|
|
|
}
|
|
|
|
|
2016-08-04 15:45:07 +02:00
|
|
|
}
|