CommitRest { @GET @Path("{commitId}/resource") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves the Commit specified by the provided ID.") public Response getCompiledResource(@PathParam("commitId") String commitId, @QueryParam("entityId") String entityId) { long start = System.currentTimeMillis(); try { checkStringParam(commitId, "Commit ID is required"); Model model; try { final List<Commit> commits; if (StringUtils.isNotBlank(entityId)) { commits = catalogManager.getCommitEntityChain(vf.createIRI(commitId), vf.createIRI(entityId)); Model entityModel = catalogManager.getCompiledResource(commits); model = entityModel.filter(vf.createIRI(entityId), null,null); } else { commits = catalogManager.getCommitChain(vf.createIRI(commitId)); model = catalogManager.getCompiledResource(commits); } return Response.ok(modelToSkolemizedString(model, RDFFormat.JSONLD, transformer, bNodeService)) .build(); } catch (IllegalArgumentException ex) { throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.BAD_REQUEST); } catch (IllegalStateException | MobiException ex) { throw ErrorUtils.sendError(ex, ex.getMessage(), Response.Status.INTERNAL_SERVER_ERROR); } } finally { logger.trace("getCompiledResource took {}ms", System.currentTimeMillis() - start); } }  @GET @Path("{commitId}") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves the Commit specified by the provided ID.") Response getCommit(@PathParam("commitId") String commitId,
                       @DefaultValue("jsonld") @QueryParam("format") String format); @GET @Path("{commitId}/history") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves the Commit history specified by the provided ID.") Response getCommitHistory(@Context UriInfo uriInfo,
                              @PathParam("commitId") String commitId,
                              @QueryParam("targetId") String targetId,
                              @QueryParam("entityId") String entityId,
                              @QueryParam("offset") int offset,
                              @QueryParam("limit") int limit); @GET @Path("{commitId}/resource") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves the Commit specified by the provided ID.") Response getCompiledResource(@PathParam("commitId") String commitId,
                                 @QueryParam("entityId") String entityId); @GET @Path("{sourceId}/difference") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves the Difference of the two specified Commits.") Response getDifference(@PathParam("sourceId") String sourceId,
                                  @QueryParam("targetId") String targetId,
                                  @DefaultValue("jsonld") @QueryParam("format") String rdfFormat);  }
@Test public void getCompiledResourceNoEntityTest() { Model expected = mf.createModel(); expected.add(vf.createIRI(COMMIT_IRIS[0]), typeIRI, vf.createIRI("http: expected.add(vf.createIRI(COMMIT_IRIS[1]), typeIRI, vf.createIRI("http: expected.add(vf.createIRI(COMMIT_IRIS[2]), typeIRI, vf.createIRI("http: when(catalogManager.getCompiledResource(any(List.class))).thenReturn(expected); Response response = target().path("commits/" + encode(COMMIT_IRIS[1]) + "/resource") .request().get(); assertEquals(response.getStatus(), 200); verify(catalogManager).getCommitChain(vf.createIRI(COMMIT_IRIS[1])); try { JSONArray result = JSONArray.fromObject(response.readEntity(String.class)); JSONObject commitObj = result.getJSONObject(0); assertTrue(commitObj.containsKey("@id")); assertEquals(commitObj.getString("@id"), COMMIT_IRIS[0]); assertTrue(result.size() == 3); } catch (Exception e) { fail("Expected no exception, but got: " + e.getMessage()); } }
@Test public void getCompiledResourceWithEntityTest() { Model expected = mf.createModel(); expected.add(vf.createIRI("http: when(catalogManager.getCommitEntityChain(any(Resource.class), any(Resource.class))).thenReturn(entityCommits); when(catalogManager.getCompiledResource(any(List.class))).thenReturn(expected); Response response = target().path("commits/" + encode(COMMIT_IRIS[1]) + "/resource") .queryParam("entityId", encode("http: assertEquals(response.getStatus(), 200); verify(catalogManager).getCommitEntityChain(vf.createIRI(COMMIT_IRIS[1]), vf.createIRI("http: try { JSONArray result = JSONArray.fromObject(response.readEntity(String.class)); JSONObject commitObj = result.getJSONObject(0); assertTrue(commitObj.containsKey("@id")); assertTrue(result.size() == 1); } catch (Exception e) { fail("Expected no exception, but got: " + e.getMessage()); } }
@Test public void getCompiledResourceEmptyModelTest() { List<Commit> emptyList = new ArrayList<>(); Model expected = mf.createModel(); when(catalogManager.getCompiledResource(any(List.class))).thenReturn(expected); when(catalogManager.getCommitEntityChain(any(Resource.class), any(Resource.class))).thenReturn(emptyList); Response response = target().path("commits/" + encode(COMMIT_IRIS[1]) + "/resource") .queryParam("entityId", encode("http: assertEquals(response.getStatus(), 200); verify(catalogManager).getCommitEntityChain(vf.createIRI(COMMIT_IRIS[1]), vf.createIRI("http: try { JSONArray result = JSONArray.fromObject(response.readEntity(String.class)); assertTrue(result.size() == 0); } catch (Exception e) { fail("Expected no exception, but got: " + e.getMessage()); } }