예제 #1
0
  /**
   * Return a list of versions that affect the resource whose uri is passed as argument. For each
   * version, the result will contain the id, the creator, and the date when the version was
   * recorded. Further details for a version can be requested by calling the
   * /versioning/versions/{id} webservice.
   *
   * <p>Note that resource_uri is an optional parameter. In case no resource uri is given, all
   * versions recorded by the LMF are returned, which can take a considerable amount of time. @HTTP
   * 200 in case the versions were retrieved successfully @HTTP 404 in case the resource passed as
   * argument resource_uri could not be found
   *
   * @param resource_uri the URI of the resource for which to return the versions (optional, see
   *     warning above)
   * @return a JSON list of versions, each a map with the properties "id" (long), "creator" (uri),
   *     "date" (ISO 8601 String)
   */
  @GET
  @Produces("application/json")
  @Path("/versions/list")
  public Response getVersions(
      @QueryParam("resource") String resource_uri,
      @QueryParam("from") String dateFrom,
      @QueryParam("to") String dateTo) {
    try {
      RepositoryConnection conn = sesameService.getConnection();
      try {
        if (resource_uri != null) {
          URI resource = ResourceUtils.getUriResource(conn, resource_uri);
          if (resource != null && resource instanceof KiWiUriResource) {

            if (dateFrom == null && dateTo == null) {
              return Response.ok()
                  .entity(formatVersions(versioningService.listVersions(resource)))
                  .build();
            } else {
              Date dateFromD = DateUtils.parseDate(dateFrom);
              Date dateToD = DateUtils.parseDate(dateTo);
              return Response.ok()
                  .entity(
                      formatVersions(versioningService.listVersions(resource, dateFromD, dateToD)))
                  .build();
            }
          } else {
            return Response.status(Response.Status.NOT_FOUND)
                .entity("resource with URI " + resource_uri + " was not found in the system")
                .build();
          }
        } else {
          if (dateFrom == null && dateTo == null) {
            return Response.ok().entity(formatVersions(versioningService.listVersions())).build();
          } else {
            Date dateFromD = DateUtils.parseDate(dateFrom);
            Date dateToD = DateUtils.parseDate(dateTo);
            return Response.ok()
                .entity(formatVersions(versioningService.listVersions(dateFromD, dateToD)))
                .build();
          }
        }
      } finally {
        conn.commit();
        conn.close();
      }
    } catch (RepositoryException ex) {
      return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build();
    } catch (SailException ex) {
      return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(ex.getMessage()).build();
    }
  }
  @Override
  public void meet(ValueConstant node) throws RuntimeException {
    String val = node.getValue().stringValue();

    switch (optypes.peek()) {
      case STRING:
      case URI:
        builder.append("'").append(val).append("'");
        break;
      case INT:
        builder.append(Integer.parseInt(val));
        break;
      case DECIMAL:
      case DOUBLE:
        builder.append(Double.parseDouble(val));
        break;
      case BOOL:
        builder.append(Boolean.parseBoolean(val));
        break;
      case DATE:
        builder.append("'").append(sqlDateFormat.format(DateUtils.parseDate(val))).append("'");
        break;

        // in this case we should return a node ID and also need to make sure it actually exists
      case TERM:
      case NODE:
        KiWiNode n = parent.getConverter().convert(node.getValue());
        builder.append(n.getId());
        break;

      default:
        throw new IllegalArgumentException("unsupported value type: " + optypes.peek());
    }
  }