Esempio n. 1
0
  /**
   * Return detailed information about the version whose id is passed as path argument. Returns a
   * JSON map with the fields id, creator, date, added_triples, removed_triples. Triple will be
   * represented in RDF/JSON format. @HTTP 404 in case the requested version does not exist
   *
   * @param id the ID of the version to return
   * @return a JSON map representing the version information as described above
   */
  @GET
  @Produces("application/json")
  @Path("/versions/{id:[0-9]+}")
  public Response getVersion(@PathParam("id") Long id) {
    try {
      Version version = versioningService.getVersion(id);

      if (version != null) {
        Map<String, Object> result = new HashMap<String, Object>();
        result.put("id", version.getId());
        if (version.getCreator() != null) {
          result.put("creator", version.getCreator().stringValue());
        }
        result.put("date", DateUtils.ISO8601FORMAT.format(version.getCommitTime()));

        result.put("added_triples", JSONUtils.serializeTriplesAsJson(version.getAddedTriples()));
        result.put(
            "removed_triples", JSONUtils.serializeTriplesAsJson(version.getRemovedTriples()));

        return Response.ok().entity(result).build();

      } else {
        return Response.status(Response.Status.NOT_FOUND)
            .entity("version with id " + id + " does not exist")
            .build();
      }

    } catch (SailException e) {
      return Response.serverError()
          .entity("error loading version " + id + ": " + e.getMessage())
          .build();
    }
  }
Esempio n. 2
0
  /**
   * Revert (undo) the version with the given ID. Calling this service will add all removed triples
   * and remove all added triples of the old version. If versioning is active, this will create a
   * new version as well.
   *
   * @param id
   * @return
   */
  @POST
  @Path("/versions/{id:[0-9]+}")
  public Response revertVersion(@PathParam("id") Long id) {
    try {
      Version version = versioningService.getVersion(id);

      if (version != null) {
        versioningService.removeVersion(id);

        return Response.ok().entity("success").build();

      } else {
        return Response.status(Response.Status.NOT_FOUND)
            .entity("version with id " + id + " does not exist")
            .build();
      }

    } catch (SailException e) {
      return Response.serverError()
          .entity("error deleting version " + id + ": " + e.getMessage())
          .build();
    }
  }