Removed uneeded parameters

This commit is contained in:
Luca Frosini 2022-07-18 16:35:44 +02:00
parent b8d8585eab
commit 8e83ce6d98
5 changed files with 11 additions and 37 deletions

View File

@ -7,6 +7,6 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.Inval
*/
public interface Query {
public String query(String query, Integer limit, String fetchPlan, boolean raw) throws InvalidQueryException;
public String query(String query, boolean raw) throws InvalidQueryException;
}

View File

@ -1,14 +1,10 @@
package org.gcube.informationsystem.resourceregistry.queries;
import java.util.HashMap;
import java.util.Map;
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
import org.gcube.com.fasterxml.jackson.databind.node.ArrayNode;
import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegistryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException;
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
@ -31,12 +27,7 @@ public class QueryImpl implements Query {
private static Logger logger = LoggerFactory.getLogger(QueryImpl.class);
@Override
public String query(String query, Integer limit, String fetchPlan, boolean raw) throws InvalidQueryException {
if(limit == null) {
limit = AccessPath.DEFAULT_LIMIT;
}
limit = (limit <= 0) ? AccessPath.UNBOUNDED : limit;
public String query(String query, boolean raw) throws InvalidQueryException {
ODatabaseDocument oDatabaseDocument = null;
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
@ -46,22 +37,9 @@ public class QueryImpl implements Query {
oDatabaseDocument = securityContext.getDatabaseDocument(PermissionMode.READER);
oDatabaseDocument.begin();
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(query);
stringBuffer.append(" limit :limit");
Map<String, Object> map = new HashMap<>();
map.put("limit", limit);
logger.debug("Going to execute query '{} limit {}'", query);
if(fetchPlan!=null) {
stringBuffer.append(" fetchplan ");
stringBuffer.append(fetchPlan);
logger.debug("Going to execute query '{} limit {} fetchPlan {}'", query, limit, fetchPlan);
}else {
logger.debug("Going to execute query '{} limit {}'", query, limit);
}
OResultSet resultSet = oDatabaseDocument.query(stringBuffer.toString(), map);
OResultSet resultSet = oDatabaseDocument.query(query);
ObjectMapper objectMapper = new ObjectMapper();
ArrayNode arrayNode = objectMapper.createArrayNode();

View File

@ -14,7 +14,6 @@ import org.gcube.informationsystem.resourceregistry.api.exceptions.ResourceRegis
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaException;
import org.gcube.informationsystem.resourceregistry.api.exceptions.types.SchemaNotFoundException;
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
import org.gcube.informationsystem.resourceregistry.contexts.ContextUtility;
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext;
import org.gcube.informationsystem.resourceregistry.contexts.security.SecurityContext.PermissionMode;
@ -43,6 +42,8 @@ public class JsonQuery {
private static Logger logger = LoggerFactory.getLogger(JsonQuery.class);
private static final Integer UNBOUNDED_LIMIT = -1;
protected ObjectMapper objectMapper;
protected JsonNode jsonQuery;
protected JsonQueryERElement entryPoint;
@ -108,8 +109,6 @@ public class JsonQuery {
ODatabaseDocument current = ContextUtility.getCurrentODatabaseDocumentFromThreadLocal();
oDatabaseDocument = null;
try {
Integer limit = AccessPath.UNBOUNDED;
SecurityContext securityContext = ContextUtility.getCurrentSecurityContext();
oDatabaseDocument = securityContext.getDatabaseDocument(PermissionMode.READER);
@ -119,7 +118,7 @@ public class JsonQuery {
stringBuffer.append(" limit :limit");
Map<String, Object> map = new HashMap<>();
map.put("limit", limit);
map.put("limit", JsonQuery.UNBOUNDED_LIMIT);
OResultSet resultSet = oDatabaseDocument.query(stringBuffer.toString(), map);

View File

@ -241,18 +241,16 @@ public class Access extends BaseRest {
@Path(AccessPath.QUERY_PATH_PART)
@Produces(ResourceInitializer.APPLICATION_JSON_CHARSET_UTF_8)
public String graphQuery(@QueryParam(AccessPath.QUERY_PARAM) String query,
@QueryParam(AccessPath.LIMIT_PARAM) Integer limit,
@QueryParam(AccessPath.FETCH_PLAN_PARAM) @DefaultValue(AccessPath.DEFAULT_FETCH_PLAN_PARAM) String fetchPlan,
@QueryParam(AccessPath.RAW_PARAM) @DefaultValue(AccessPath.DEFAULT_RAW_PARAM) Boolean raw)
throws InvalidQueryException {
logger.info("Requested query (fetch plan {}, limit {}, Raw {}):\n{}", fetchPlan, limit, raw, query);
logger.info("Requested query (Raw {}):\n{}", raw, query);
CalledMethodProvider.instance.set("graphQuery");
checkHierarchicalMode();
checkIncludeInstancesContexts();
Query queryManager = new QueryImpl();
return queryManager.query(query, limit, fetchPlan, raw);
return queryManager.query(query, raw);
}
/**

View File

@ -14,7 +14,6 @@ import org.gcube.informationsystem.model.reference.entities.Resource;
import org.gcube.informationsystem.model.reference.relations.ConsistsOf;
import org.gcube.informationsystem.model.reference.relations.IsRelatedTo;
import org.gcube.informationsystem.resourceregistry.api.exceptions.queries.InvalidQueryException;
import org.gcube.informationsystem.resourceregistry.api.rest.AccessPath;
import org.gcube.informationsystem.resourceregistry.api.utils.Utility;
import org.gcube.informationsystem.resourceregistry.instances.ERManagementTest;
import org.gcube.informationsystem.resourceregistry.instances.base.ElementManagement;
@ -59,11 +58,11 @@ public class QueryTest extends ERManagementTest {
QueryImpl queryImpl = new QueryImpl();
String query = "select from SoftwareFacet";
String ret = queryImpl.query(query, -7, AccessPath.DEFAULT_FETCH_PLAN_PARAM, false);
String ret = queryImpl.query(query, false);
logger.debug(ret);
ret = queryImpl.query(query, -7, null, false);
ret = queryImpl.query(query, false);
logger.debug(ret);
}