diff --git a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java index a087250..ac5077c 100644 --- a/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java +++ b/src/main/java/org/gcube/informationsystem/resourceregistry/instances/model/entities/EntityManagement.java @@ -559,7 +559,6 @@ public abstract class EntityManagement */ } - /* public String reallyQuery(String relationType, String referenceType, UUID referenceUUID, ODirection direction, boolean polymorphic, Map constraint, boolean includeRelationInResult) throws ResourceRegistryException { @@ -569,6 +568,13 @@ public abstract class EntityManagement ObjectMapper objectMapper = new ObjectMapper(); ArrayNode arrayNode = objectMapper.createArrayNode(); + ServerRequestInfo requestInfo = RequestUtility.getRequestInfo().get(); + int limit = requestInfo.getLimit(); + int offset = requestInfo.getOffset(); + + int position = -1; + int count = 0; + Iterable references = null; if(referenceUUID != null) { @@ -589,7 +595,7 @@ public abstract class EntityManagement if(polymorphic && getOClass().isSubClassOf(referenceType)) { // OK } else { - String error = String.format("Referenced instace with UUID %s is not a %s", referenceUUID, referenceType); + String error = String.format("Referenced instance with UUID %s is not a %s", referenceUUID, referenceType); throw new InvalidQueryException(error); } } @@ -599,7 +605,7 @@ public abstract class EntityManagement references = vertexes; } else { - String error = String.format("Referenced instace with UUID %s is not a %s", referenceUUID, referenceType); + String error = String.format("Referenced instance with UUID %s is not a %s", referenceUUID, referenceType); throw new InvalidQueryException(error); } @@ -609,6 +615,7 @@ public abstract class EntityManagement Set analysed = new HashSet<>(); + outerloop: for(Object r : references) { OVertex v = (OVertex) r; @@ -697,6 +704,15 @@ public abstract class EntityManagement continue; } + + /* + * This is the only position where we can put + * pagination check because we need matching results + */ + if(++position < offset) { + continue; + } + /* JsonNode jsonNode; if(includeRelationInResult) { @@ -708,9 +724,19 @@ public abstract class EntityManagement } */ entityManagement.setAsEntryPoint(); - JsonNode node = entityManagement.serializeAsJsonNode(); + + JsonNode node = entityManagement.serializeAsJsonNode(); arrayNode.add(node); + + /* + * This is the only position where we can put + * pagination check because we need matching results + */ + if(limit > 0 && ++count >= limit) { + break outerloop; + } + } catch(ResourceRegistryException e) { logger.error("Unable to correctly serialize {}. It will be excluded from results. {}", vertex.toString(), OrientDBUtility.SHOULD_NOT_OCCUR_ERROR_MESSAGE);