Added pagination support
This commit is contained in:
parent
ca51189cab
commit
dd7ad6840e
|
@ -3,8 +3,6 @@ package org.gcube.informationsystem.resourceregistry.queries.templates;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import javax.ws.rs.BadRequestException;
|
|
||||||
|
|
||||||
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
import org.gcube.com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
import org.gcube.com.fasterxml.jackson.databind.JsonNode;
|
||||||
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
import org.gcube.com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
@ -30,6 +28,8 @@ import org.gcube.informationsystem.resourceregistry.instances.base.ElementManage
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.base.entities.EntityElementManagement;
|
import org.gcube.informationsystem.resourceregistry.instances.base.entities.EntityElementManagement;
|
||||||
import org.gcube.informationsystem.resourceregistry.instances.model.Operation;
|
import org.gcube.informationsystem.resourceregistry.instances.model.Operation;
|
||||||
import org.gcube.informationsystem.resourceregistry.queries.json.JsonQuery;
|
import org.gcube.informationsystem.resourceregistry.queries.json.JsonQuery;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.requests.RequestUtility;
|
||||||
|
import org.gcube.informationsystem.resourceregistry.requests.ServerRequestInfo;
|
||||||
import org.gcube.informationsystem.resourceregistry.utils.OrientDBUtility;
|
import org.gcube.informationsystem.resourceregistry.utils.OrientDBUtility;
|
||||||
import org.gcube.informationsystem.serialization.ElementMapper;
|
import org.gcube.informationsystem.serialization.ElementMapper;
|
||||||
import org.gcube.informationsystem.types.reference.entities.EntityType;
|
import org.gcube.informationsystem.types.reference.entities.EntityType;
|
||||||
|
@ -348,13 +348,28 @@ public class QueryTemplateManagement extends EntityElementManagement<QueryTempla
|
||||||
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
public String reallyGetAll(boolean polymorphic) throws ResourceRegistryException {
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
ObjectMapper objectMapper = new ObjectMapper();
|
||||||
ArrayNode arrayNode = objectMapper.createArrayNode();
|
ArrayNode arrayNode = objectMapper.createArrayNode();
|
||||||
|
|
||||||
|
ServerRequestInfo requestInfo = RequestUtility.getRequestInfo().get();
|
||||||
|
int limit = requestInfo.getLimit();
|
||||||
|
int offset = requestInfo.getOffset();
|
||||||
|
|
||||||
|
int position = -1;
|
||||||
|
int count = 0;
|
||||||
|
|
||||||
Iterable<ODocument> iterable = oDatabaseDocument.browseClass(typeName, polymorphic);
|
Iterable<ODocument> iterable = oDatabaseDocument.browseClass(typeName, polymorphic);
|
||||||
for (ODocument vertex : iterable) {
|
for (ODocument vertex : iterable) {
|
||||||
|
if(++position < offset) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement();
|
QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement();
|
||||||
queryTemplateManagement.setElement((OVertex) vertex);
|
queryTemplateManagement.setElement((OVertex) vertex);
|
||||||
try {
|
try {
|
||||||
JsonNode jsonObject = queryTemplateManagement.serializeAsJsonNode();
|
JsonNode jsonObject = queryTemplateManagement.serializeAsJsonNode();
|
||||||
arrayNode.add(jsonObject);
|
arrayNode.add(jsonObject);
|
||||||
|
if(limit > 0 && ++count >= limit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
} catch (ResourceRegistryException e) {
|
} catch (ResourceRegistryException e) {
|
||||||
logger.error("Unable to correctly serialize {}. It will be excluded from results. {}",
|
logger.error("Unable to correctly serialize {}. It will be excluded from results. {}",
|
||||||
vertex.toString(), OrientDBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
vertex.toString(), OrientDBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);
|
||||||
|
|
|
@ -155,6 +155,7 @@ public class Access extends BaseRest {
|
||||||
ServerRequestInfo serverRequestInfo = initRequestInfo();
|
ServerRequestInfo serverRequestInfo = initRequestInfo();
|
||||||
serverRequestInfo.setAllMeta(true);
|
serverRequestInfo.setAllMeta(true);
|
||||||
serverRequestInfo.checkBooleanQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER);
|
serverRequestInfo.checkBooleanQueryParameter(ContextPath.INCLUDE_META_QUERY_PARAMETER);
|
||||||
|
serverRequestInfo.checkLimitOffset();
|
||||||
|
|
||||||
QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement();
|
QueryTemplateManagement queryTemplateManagement = new QueryTemplateManagement();
|
||||||
return queryTemplateManagement.all(false);
|
return queryTemplateManagement.all(false);
|
||||||
|
|
Loading…
Reference in New Issue