示例#1
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;
  }