ExplorableDatasetRest { @PUT @Path("{recordIRI}/instances/{instanceIRI}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Updates an instance of a particular class type from a Dataset in the local Catalog") public Response updateInstance(@PathParam("recordIRI") String recordIRI, @PathParam("instanceIRI") String instanceIRI, String json) { checkStringParam(recordIRI, "The Dataset Record IRI is required."); checkStringParam(instanceIRI, "The Instance IRI is required."); try (DatasetConnection conn = datasetManager.getConnection(factory.createIRI(recordIRI))) { Resource instanceId = factory.createIRI(instanceIRI); RepositoryResult<Statement> statements = conn.getStatements(instanceId, null, null); if (!statements.hasNext()) { throw ErrorUtils.sendError("The requested instance could not be found.", Response.Status.BAD_REQUEST); } RepositoryResult<Statement> reifiedDeclarations = conn.getStatements(null, sesameTransformer.mobiIRI(RDF.SUBJECT), instanceId); conn.begin(); conn.remove(statements); reifiedDeclarations.forEach(statement -> { RepositoryResult<Statement> reification = conn.getStatements(statement.getSubject(), null, null); conn.remove(reification); }); conn.add(jsonldToDeskolemizedModel(json, sesameTransformer, bNodeService)); conn.commit(); return Response.ok().build(); } catch (IllegalArgumentException e) { throw ErrorUtils.sendError(e, e.getMessage(), Response.Status.BAD_REQUEST); } catch (IllegalStateException | MobiException e) { throw ErrorUtils.sendError(e, e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR); } }  @Reference void setDatasetManager(DatasetManager datasetManager); @Reference void setFactory(ValueFactory factory); @Reference void setCatalogManager(CatalogManager catalogManager); @Reference void setModelFactory(ModelFactory modelFactory); @Reference void setSesameTransformer(SesameTransformer sesameTransformer); @Reference(policyOption = ReferencePolicyOption.GREEDY) void setOntologyManager(OntologyManager ontologyManager); @Reference void setOntologyRecordFactory(OntologyRecordFactory ontologyRecordFactory); @Reference void setBNodeService(BNodeService bNodeService); @GET @Path("{recordIRI}/class-details") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves all the data associated with ontology objects, from a Dataset in the local Catalog") Response getClassDetails(@PathParam("recordIRI") String recordIRI); @GET @Path("{recordIRI}/classes/{classIRI}/instance-details") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves an aggregated summary of all ontology objects from a Dataset in the local Catalog") Response getInstanceDetails(@Context UriInfo uriInfo,
                                @PathParam("recordIRI") String recordIRI,
                                @PathParam("classIRI") String classIRI,
                                @QueryParam("offset") int offset,
                                @QueryParam("limit") int limit,
                                @DefaultValue("true") @QueryParam("ascending") boolean asc,
                                @DefaultValue("false") @QueryParam("infer") boolean infer); @GET @Path("{recordIRI}/classes/{classIRI}/property-details") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves a list of all properties available for a class from a Dataset in the local Catalog") Response getClassPropertyDetails(@PathParam("recordIRI") String recordIRI,
                                     @PathParam("classIRI") String classIRI); @POST @Path("{recordIRI}/instances") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.TEXT_PLAIN) @RolesAllowed("user") @ApiOperation("Creates an instance of a particular class type in a Dataset in the local Catalog") Response createInstance(@PathParam("recordIRI") String recordIRI,
                            String newInstanceJson); @GET @Path("{recordIRI}/instances/{instanceIRI}") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Retrieves an instance of a particular class type from a Dataset in the local Catalog") Response getInstance(@PathParam("recordIRI") String recordIRI,
                         @PathParam("instanceIRI") String instanceIRI); @PUT @Path("{recordIRI}/instances/{instanceIRI}") @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Updates an instance of a particular class type from a Dataset in the local Catalog") Response updateInstance(@PathParam("recordIRI") String recordIRI,
                            @PathParam("instanceIRI") String instanceIRI,
                            String json); @DELETE @Path("{recordIRI}/instances/{instanceIRI}") @Produces(MediaType.APPLICATION_JSON) @RolesAllowed("user") @ApiOperation("Deletes an instance by its ID.") Response deleteInstance(@PathParam("recordIRI") String recordIRI,
                            @PathParam("instanceIRI") String instanceIRI);  }
@Test public void updateInstanceTest() { JSONObject instance = new JSONObject().element("@id", INSTANCE_ID_STR) .element(_Thing.title_IRI, new JSONArray().add(new JSONObject().element("@value", "title"))); Response response = target().path("explorable-datasets/" + encode(RECORD_ID_STR) + "/instances/" + encode(INSTANCE_ID_STR)).request().put(Entity.json(instance)); assertEquals(response.getStatus(), 200); verify(datasetConnection).begin(); verify(datasetConnection).remove(any(Iterable.class)); verify(datasetConnection).add(any(Model.class)); verify(bNodeService).deskolemize(any(Model.class)); verify(datasetConnection).commit(); }