RecordPermissionsRest { @GET @Produces(MediaType.APPLICATION_JSON) @Path("{recordId}") @ApiOperation("Retrieves a specific record security policy by its ID.") @ActionId(Update.TYPE) @ResourceId(type = ValueType.PATH, value = "recordId") public Response retrieveRecordPolicy(@PathParam("recordId") String recordId) { try (RepositoryConnection conn = repo.getConnection()) { Optional<String> recordPolicyIdOpt = getRelatedResourceId(recordId, conn); String recordPolicyId = recordPolicyIdOpt.orElseThrow(() -> ErrorUtils.sendError("Policy for record " + recordId + " does not exist in repository", Response.Status.BAD_REQUEST)); Optional<XACMLPolicy> policy = policyManager.getPolicy(vf.createIRI(recordPolicyId)); if (!policy.isPresent()) { throw ErrorUtils.sendError("Policy could not be found", Response.Status.BAD_REQUEST); } return Response.ok(recordPolicyToJson(policy.get())).build(); } catch (IllegalStateException | MobiException ex) { throw ErrorUtils.sendError(ex, "Policy could not be retrieved", Response.Status.INTERNAL_SERVER_ERROR); } }  @Reference(target = "(id=system)") void setRepo(Repository repo); @GET @Produces(MediaType.APPLICATION_JSON) @Path("{recordId}") @ApiOperation("Retrieves a specific record security policy by its ID.") @ActionId(Update.TYPE) @ResourceId(type = ValueType.PATH, value = "recordId") Response retrieveRecordPolicy(@PathParam("recordId") String recordId); @PUT @Path("{recordId}") @Consumes(MediaType.APPLICATION_JSON) @ApiOperation("Updates an existing record security policy using the provided JSON body.") @ResourceId(type = ValueType.PATH, value = "recordId") Response updateRecordPolicy(@PathParam("recordId") String recordId, String policyJson);  }
@Test public void retrieveRecordPolicyTest() { Response response = target().path("record-permissions/" + encode(recordIRI.stringValue())).request().get(); assertEquals(response.getStatus(), 200); verify(policyManager).getPolicy(recordPolicyIRI); try { JSONObject result = JSONObject.fromObject(response.readEntity(String.class)); assertEquals(result, JSONObject.fromObject(recordJson)); } catch (Exception e) { fail("Expected no exception, but got: " + e.getMessage()); } }