RestUtils { public static <T extends Thing> Response createPaginatedResponse(UriInfo uriInfo, Collection<T> items, int totalSize, int limit, int offset, String type, SesameTransformer transformer) { return createPaginatedResponse(uriInfo, items, totalSize, limit, offset, type, transformer, null); }  static RDFFormat getRDFFormat(String format); static String modelToString(Model model, RDFFormat format, SesameTransformer transformer); static String modelToString(Model model, String format, SesameTransformer transformer); static String modelToSkolemizedString(Model model, RDFFormat format, SesameTransformer transformer,
                                                 BNodeService service); static String modelToSkolemizedString(Model model, String format, SesameTransformer transformer,
                                                 BNodeService service); static String groupedModelToString(Model model, RDFFormat format, SesameTransformer transformer); static String groupedModelToString(Model model, String format, SesameTransformer transformer); static String groupedModelToSkolemizedString(Model model, RDFFormat format, SesameTransformer transformer,
                                                        BNodeService service); static String groupedModelToSkolemizedString(Model model, String format, SesameTransformer transformer,
                                                        BNodeService service); static Model jsonldToModel(String jsonld, SesameTransformer transformer); static Model jsonldToDeskolemizedModel(String jsonld, SesameTransformer transformer, BNodeService service); static String modelToJsonld(Model model, SesameTransformer transformer); static String modelToSkolemizedJsonld(Model model, SesameTransformer transformer, BNodeService service); static String modelToTrig(Model model, SesameTransformer transformer); static String getRDFFormatFileExtension(String format); static String getRDFFormatMimeType(String format); static User getActiveUser(ContainerRequestContext context, EngineManager engineManager); static String getActiveUsername(ContainerRequestContext context); static Optional<User> optActiveUser(ContainerRequestContext context, EngineManager engineManager); static Optional<String> optActiveUsername(ContainerRequestContext context); static void checkStringParam(@Nullable String param, String errorMessage); static JSONObject getObjectFromJsonld(String json); static ObjectNode getObjectNodeFromJsonld(String json); static JSONObject getTypedObjectFromJsonld(String json, String type); static JsonNode getTypedObjectNodeFromJsonld(String json, String type); static IRI createIRI(String requestId, ValueFactory vf); static JSONObject thingToJsonObject(Thing thing, String type, SesameTransformer transformer); static JsonNode thingToObjectNode(Thing thing, String type, SesameTransformer transformer); static JSONObject thingToSkolemizedJsonObject(Thing thing, String type, SesameTransformer transformer,
                                                         BNodeService bNodeService); static JsonNode thingToSkolemizedObjectNode(Thing thing, String type, SesameTransformer transformer,
                                                         BNodeService bNodeService); static Response createPaginatedThingResponse(UriInfo uriInfo, Set<T> things,
                                                                          IRI sortIRI, int offset, int limit,
                                                                          boolean asc,
                                                                          Function<T, Boolean> filterFunction,
                                                                          String type, SesameTransformer transformer,
                                                                          BNodeService bNodeService); static Response createPaginatedThingResponseJackson(UriInfo uriInfo, Set<T> things,
                                                                          IRI sortIRI, int offset, int limit,
                                                                          boolean asc,
                                                                          Function<T, Boolean> filterFunction,
                                                                          String type, SesameTransformer transformer,
                                                                          BNodeService bNodeService); static Response createPaginatedResponse(UriInfo uriInfo, Collection<T> items,
                                                                     int totalSize, int limit, int offset, String type,
                                                                     SesameTransformer transformer); static Response createPaginatedResponse(UriInfo uriInfo, Collection<T> items,
                                                                     int totalSize, int limit, int offset,
                                                                     String type, SesameTransformer transformer,
                                                                      BNodeService bNodeService); static Response createPaginatedResponseJackson(UriInfo uriInfo, Collection<T> items,
                                                                            int totalSize, int limit,
                                                                            int offset, String type,
                                                                            SesameTransformer transformer,
                                                                            BNodeService bNodeService); static Response createPaginatedResponseWithJson(UriInfo uriInfo, JSONArray items, int totalSize, int limit,
                                                           int offset); static Response createPaginatedResponseWithJsonNode(UriInfo uriInfo, ArrayNode items,
                                                               int totalSize, int limit, int offset); static void validatePaginationParams(String sortIRI, Set<String> sortResources, int limit, int offset);  }
@Test public void createPaginatedResponseTest() { Set<Thing> set = getTestThings(Collections.singletonMap(testPropIRI, "VALUE")); Response response = RestUtils.createPaginatedThingResponse(uriInfo, set, testPropIRI, 0, 1, true, (Function<Thing, Boolean>) null, "http: Object object = response.getEntity(); assertTrue(object instanceof JSONArray); JSONArray array = (JSONArray) object; assertTrue(array.get(0) instanceof JSONObject); JSONObject jsonObject = (JSONObject) array.get(0); assertEquals(jsonObject.getJSONArray(testPropIRI.stringValue()).getJSONObject(0).getString("@value"), "VALUE 1"); assertEquals(response.getLinks().size(), 1); Link link = response.getLinks().iterator().next(); assertEquals(link.getRel(), "next"); assertTrue(link.getUri().getRawPath().equals("/rest/tests")); response = RestUtils.createPaginatedThingResponse(uriInfo, set, testPropIRI, 1, 1, true, (Function<Thing, Boolean>) null, "http: service); object = response.getEntity(); assertTrue(object instanceof JSONArray); array = (JSONArray) object; assertTrue(array.get(0) instanceof JSONObject); jsonObject = (JSONObject) array.get(0); assertEquals(jsonObject.getJSONArray(testPropIRI.stringValue()).getJSONObject(0).getString("@value"), "VALUE 2"); assertEquals(response.getLinks().size(), 2); assertTrue(response.getLinks().stream() .allMatch(lnk -> (lnk.getRel().equals("prev") || lnk.getRel().equals("next")) && lnk.getUri().getRawPath().equals("/rest/tests"))); response = RestUtils.createPaginatedThingResponse(uriInfo, set, testPropIRI, 2, 1, true, (Function<Thing, Boolean>) null, "http: service); object = response.getEntity(); assertTrue(object instanceof JSONArray); array = (JSONArray) object; assertTrue(array.get(0) instanceof JSONObject); jsonObject = (JSONObject) array.get(0); assertEquals(jsonObject.getJSONArray(testPropIRI.stringValue()).getJSONObject(0).getString("@value"), "VALUE 3"); assertEquals(response.getLinks().size(), 1); link = response.getLinks().iterator().next(); assertEquals(link.getRel(), "prev"); assertTrue(link.getUri().getRawPath().equals("/rest/tests")); response = RestUtils.createPaginatedThingResponse(uriInfo, set, testPropIRI, 0, 1, false, (Function<Thing, Boolean>) null, "http: service); object = response.getEntity(); assertTrue(object instanceof JSONArray); array = (JSONArray) object; assertTrue(array.get(0) instanceof JSONObject); jsonObject = (JSONObject) array.get(0); assertEquals(jsonObject.getJSONArray(testPropIRI.stringValue()).getJSONObject(0).getString("@value"), "VALUE 3"); assertEquals(response.getLinks().size(), 1); link = response.getLinks().iterator().next(); assertEquals(link.getRel(), "next"); assertTrue(link.getUri().getRawPath().equals("/rest/tests")); response = RestUtils.createPaginatedThingResponse(uriInfo, set, testPropIRI, 1, 1, false, (Function<Thing, Boolean>) null, "http: service); object = response.getEntity(); assertTrue(object instanceof JSONArray); array = (JSONArray) object; assertTrue(array.get(0) instanceof JSONObject); jsonObject = (JSONObject) array.get(0); assertEquals(jsonObject.getJSONArray(testPropIRI.stringValue()).getJSONObject(0).getString("@value"), "VALUE 2"); assertEquals(response.getLinks().size(), 2); assertTrue(response.getLinks().stream() .allMatch(lnk -> (lnk.getRel().equals("prev") || lnk.getRel().equals("next")) && lnk.getUri().getRawPath().equals("/rest/tests"))); response = RestUtils.createPaginatedThingResponse(uriInfo, set, testPropIRI, 2, 1, false, (Function<Thing, Boolean>) null, "http: service); object = response.getEntity(); assertTrue(object instanceof JSONArray); array = (JSONArray) object; assertTrue(array.get(0) instanceof JSONObject); jsonObject = (JSONObject) array.get(0); assertEquals(jsonObject.getJSONArray(testPropIRI.stringValue()).getJSONObject(0).getString("@value"), "VALUE 1"); assertEquals(response.getLinks().size(), 1); link = response.getLinks().iterator().next(); assertEquals(link.getRel(), "prev"); assertTrue(link.getUri().getRawPath().equals("/rest/tests")); response = RestUtils.createPaginatedThingResponse(uriInfo, set, testPropIRI, 0, 10, true, (Function<Thing, Boolean>) null, "http: service); assertEquals(response.getLinks().size(), 0); }