Example #1
0
  /**
   * Executes a the given query string (based on the language information) against a JCR repository,
   * returning a rest model based result.
   *
   * @param request a non-null {@link HttpServletRequest}
   * @param repositoryName a non-null, URL encoded {@link String} representing the name of a
   *     repository
   * @param workspaceName a non-null, URL encoded {@link String} representing the name of a
   *     workspace
   * @param language a non-null String which should be a valid query language, as recognized by the
   *     {@link javax.jcr.query.QueryManager}
   * @param statement a non-null String which should be a valid query string in the above language.
   * @param offset a numeric value which indicates the index in the result set from where results
   *     should be returned.
   * @param limit a numeric value indicating the maximum number of rows to return.
   * @param uriInfo a non-null {@link UriInfo} object which is provided by RestEASY, allowing extra
   *     request parameters to be retrieved.
   * @return a {@link RestQueryHandler} instance
   * @throws RepositoryException if any operation fails at the JCR level
   */
  public RestQueryResult executeQuery(
      HttpServletRequest request,
      String repositoryName,
      String workspaceName,
      String language,
      String statement,
      long offset,
      long limit,
      UriInfo uriInfo)
      throws RepositoryException {
    assert repositoryName != null;
    assert workspaceName != null;
    assert language != null;
    assert statement != null;

    Session session = getSession(request, repositoryName, workspaceName);
    Query query = createQuery(language, statement, session);
    bindExtraVariables(uriInfo, session.getValueFactory(), query);

    QueryResult result = query.execute();
    RestQueryResult restQueryResult = new RestQueryResult();

    String[] columnNames = result.getColumnNames();
    setColumns(result, restQueryResult, columnNames);

    String baseUrl = RestHelper.repositoryUrl(request);

    setRows(offset, limit, session, result, restQueryResult, columnNames, baseUrl);

    return restQueryResult;
  }
Example #2
0
 private void createLinksFromNodePaths(
     QueryResult result, String baseUrl, Row resultRow, RestQueryResult.RestRow restRow)
     throws RepositoryException {
   String defaultPath = resultRow.getPath();
   if (!StringUtil.isBlank(defaultPath)) {
     restRow.addValue(
         MODE_URI, RestHelper.urlFrom(baseUrl, RestHelper.ITEMS_METHOD_NAME, defaultPath));
   }
   for (String selectorName : result.getSelectorNames()) {
     try {
       String selectorPath = resultRow.getPath(selectorName);
       if (!StringUtil.isBlank(defaultPath) && !selectorPath.equals(defaultPath)) {
         restRow.addValue(
             MODE_URI + "-" + selectorName,
             RestHelper.urlFrom(baseUrl, RestHelper.ITEMS_METHOD_NAME, selectorPath));
       }
     } catch (RepositoryException e) {
       logger.debug(e, e.getMessage());
     }
   }
 }