Пример #1
0
  public LocalDocument getDocument(LocalQuery query, boolean recurring) throws IOException {
    HttpResponse response;
    if (recurring) {
      response = core.post(getRecurringUrl, query.toJson());
    } else {
      response = core.post(getUrl, query.toJson());
    }

    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
      LocalDocument ld;
      try {
        ld = new LocalDocument(EntityUtils.toString(response.getEntity()));
      } catch (JsonException e) {
        throw new IOException(e);
      }
      InternalLogger.debug("Received document with ID " + ld.getID());
      currentDocument = ld;
      return ld;
    } else if (response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_FOUND) {
      InternalLogger.debug("No document found matching query");
      EntityUtils.consume(response.getEntity());
      return null;
    } else {
      logUnexpected(response);
      return null;
    }
  }
Пример #2
0
 /** Writes all outstanding updates to the document since it was initialized. */
 public boolean save(LocalDocument d) throws IOException, JsonException {
   boolean res = save(d, true);
   if (res) {
     d.markSynced();
     keepLock = false;
   }
   return res;
 }
Пример #3
0
  public boolean markDiscarded(LocalDocument d) throws IOException {
    HttpResponse response = core.post(discardedUrl, d.modifiedFieldsToJson());
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
      EntityUtils.consume(response.getEntity());

      return true;
    }

    logUnexpected(response);

    return false;
  }
Пример #4
0
  public boolean markPending(LocalDocument d) throws IOException {
    HttpResponse response = core.post(pendingUrl, d.contentFieldsToJson(null));
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
      EntityUtils.consume(response.getEntity());

      return true;
    }

    logUnexpected(response);

    return false;
  }
Пример #5
0
  private boolean save(LocalDocument d, boolean partialUpdate) throws IOException, JsonException {
    boolean hasId = d.getID() != null;
    String s;
    if (partialUpdate) {
      s = d.modifiedFieldsToJson();
    } else {
      s = d.toJson();
    }

    HttpResponse response = core.post(getWriteUrl(partialUpdate), s);
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
      if (!hasId) {
        LocalDocument updated = new LocalDocument(EntityUtils.toString(response.getEntity()));
        d.putAll(updated);
      } else {
        EntityUtils.consume(response.getEntity());
      }
      return true;
    }

    logUnexpected(response);

    return false;
  }
Пример #6
0
  /**
   * Releases the most recently read document back to the pipeline
   *
   * @return true if there was a document to release
   * @throws HttpException
   * @throws IOException
   */
  public boolean releaseLastDocument() throws IOException {
    if (currentDocument == null) {
      InternalLogger.debug("There is no document to release...");
      return false;
    }
    HttpResponse response = core.post(releaseUrl, currentDocument.contentFieldsToJson(null));
    currentDocument = null;
    if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
      EntityUtils.consume(response.getEntity());
      return true;
    }

    logUnexpected(response);

    return false;
  }
Пример #7
0
 public boolean markFailed(LocalDocument d, Throwable t) throws IOException {
   d.addError(stageName, t);
   return markFailed(d);
 }