Пример #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();
    }
  }
Пример #2
0
  private List<Map<String, Object>> formatVersions(List<Version> versions) {
    List<Map<String, Object>> result = new ArrayList<Map<String, Object>>(versions.size());

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

      result.add(v_map);
    }

    return result;
  }