class ExplorableDatasetRest {

    @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")
    public Response createInstance(@PathParam("recordIRI") String recordIRI,
                            String newInstanceJson) {
        checkStringParam(recordIRI, "The Dataset Record IRI is required.");
        checkStringParam(newInstanceJson, "The Instance's JSON-LD is required.");
        try (DatasetConnection conn = datasetManager.getConnection(factory.createIRI(recordIRI))) {
            Model instanceModel = jsonldToModel(newInstanceJson, sesameTransformer);
            Resource instanceId = instanceModel.stream()
                    .filter(statement -> !(statement.getSubject() instanceof BNode))
                    .findAny().orElseThrow(() ->
                    ErrorUtils.sendError("The new instance's IRI could not be found on any statement in the JSON-LD.",
                            Response.Status.INTERNAL_SERVER_ERROR)).getSubject();
            if (conn.contains(instanceId, null, null)) {
                throw ErrorUtils.sendError("The new instance's IRI is already taken.",
                        Response.Status.INTERNAL_SERVER_ERROR);
            }
            conn.add(instanceModel);
            return Response.status(201).entity(instanceId.stringValue()).build();
        } catch (IllegalArgumentException e) {
            throw ErrorUtils.sendError(e, e.getMessage(), Response.Status.BAD_REQUEST);
        } catch (IllegalStateException e) {
            throw ErrorUtils.sendError(e, e.getMessage(), Response.Status.INTERNAL_SERVER_ERROR);
        }
    }

}