@Override
  public boolean execute(final OHttpRequest iRequest, OHttpResponse iResponse) throws Exception {
    String[] urlParts =
        checkSyntax(
            iRequest.url,
            3,
            "Syntax error: cluster/<database>/<cluster-name>[/<limit>]<br>Limit is optional and is setted to 20 by default. Set expressely to 0 to have no limits.");

    iRequest.data.commandInfo = "Browse cluster";
    iRequest.data.commandDetail = urlParts[2];

    ODatabaseDocument db = null;

    try {
      db = getProfiledDatabaseInstance(iRequest);

      if (db.getClusterIdByName(urlParts[2]) > -1) {
        final int limit = urlParts.length > 3 ? Integer.parseInt(urlParts[3]) : 20;

        final List<OIdentifiable> response = new ArrayList<OIdentifiable>();
        for (ORecord rec : db.browseCluster(urlParts[2])) {
          if (limit > 0 && response.size() >= limit) break;

          response.add(rec);
        }

        iResponse.writeRecords(response);
      } else iResponse.send(OHttpUtils.STATUS_NOTFOUND_CODE, null, null, null, null);

    } finally {
      if (db != null) db.close();
    }
    return false;
  }
Example #2
0
  @SuppressWarnings("unchecked")
  public void writeResult(Object iResult, final String iFormat)
      throws InterruptedException, IOException {
    if (iResult == null)
      send(
          OHttpUtils.STATUS_OK_NOCONTENT_CODE, "", OHttpUtils.CONTENT_TEXT_PLAIN, null, null, true);
    else {
      if (iResult instanceof Map<?, ?>) {
        iResult = ((Map<?, ?>) iResult).entrySet().iterator();
      } else if (OMultiValue.isMultiValue(iResult)
          && (OMultiValue.getSize(iResult) > 0
              && !(OMultiValue.getFirstValue(iResult) instanceof OIdentifiable))) {
        final List<OIdentifiable> resultSet = new ArrayList<OIdentifiable>();
        resultSet.add(new ODocument().field("value", iResult));
        iResult = resultSet.iterator();

      } else if (iResult instanceof OIdentifiable) {
        // CONVERT SIGLE VALUE IN A COLLECTION
        final List<OIdentifiable> resultSet = new ArrayList<OIdentifiable>();
        resultSet.add((OIdentifiable) iResult);
        iResult = resultSet.iterator();
      } else if (iResult instanceof Iterable<?>)
        iResult = ((Iterable<OIdentifiable>) iResult).iterator();
      else if (OMultiValue.isMultiValue(iResult))
        iResult = OMultiValue.getMultiValueIterator(iResult);
      else {
        final List<OIdentifiable> resultSet = new ArrayList<OIdentifiable>();
        resultSet.add(new ODocument().field("value", iResult));
        iResult = resultSet.iterator();
      }

      if (iResult == null)
        send(
            OHttpUtils.STATUS_OK_NOCONTENT_CODE,
            "",
            OHttpUtils.CONTENT_TEXT_PLAIN,
            null,
            null,
            true);
      else if (iResult instanceof Iterator<?>)
        writeRecords((Iterator<OIdentifiable>) iResult, null, iFormat);
    }
  }
Example #3
0
 public void writeRecords(final Iterator<OIdentifiable> iRecords) throws IOException {
   writeRecords(iRecords, null, null);
 }
Example #4
0
  public void writeRecords(final Iterable<OIdentifiable> iRecords, final String iFetchPlan)
      throws IOException {
    if (iRecords == null) return;

    writeRecords(iRecords.iterator(), iFetchPlan, null);
  }
Example #5
0
  public void writeRecords(final Iterable<OIdentifiable> iRecords) throws IOException {
    if (iRecords == null) return;

    writeRecords(iRecords.iterator(), null, null);
  }