Пример #1
0
  @VisibleForTesting
  public static String sourceOf(IndexRecord record, long timestamp, String user) {
    StringBuilder builder = new StringBuilder();
    builder.append(record.source.substring(0, record.source.length() - 1));

    if (record.source.length() > 2) builder.append(",");
    if (record.ancestor != null)
      builder
          .append("\"")
          .append(ANCESTOR_FIELD)
          .append("\":\"")
          .append(record.ancestor)
          .append("\",");
    if (record.status != null)
      builder
          .append("\"")
          .append(STATUS_FIELD)
          .append("\":\"")
          .append(record.status.name())
          .append("\",");
    if (record.comment != null)
      builder
          .append("\"")
          .append(COMMENT_FIELD)
          .append("\":\"")
          .append(record.comment)
          .append("\",");
    if (record.baseVersion != null)
      builder
          .append("\"")
          .append(BASEVERSION_FIELD)
          .append("\":\"")
          .append(record.baseVersion)
          .append("\",");
    if (!record.approvalRoles.isEmpty()) {
      builder.append("\"").append(APPROVAL_ROLES_FIELD).append("\":[");
      for (int i = 0; i < record.approvalRoles.size(); i++) {
        if (i != 0) builder.append(",");
        builder.append("\"").append(record.approvalRoles.get(i)).append("\"");
      }
      builder.append("],");
    }

    builder
        .append("\"")
        .append(BASEKEY_FIELD)
        .append("\":\"")
        .append(nonNull(record.id(), "_auto_"))
        .append("\",");
    builder.append("\"").append(TIMESTAMP_FIELD).append("\":\"").append(timestamp).append("\"");
    builder.append(",\"").append(USER_FIELD).append("\":\"").append(user).append("\"");
    builder.append("}");

    return builder.toString();
  }
Пример #2
0
    @Override
    public ActionRequest request(IndexRecord record, long timestamp, String user) {
      log.debug(
          "deleting record " + record.id() + " for " + record.type() + " at " + record.index());

      return new DeleteRequest(record.index(), record.type(), record.id());
    }
Пример #3
0
    @Override
    public ActionRequest request(IndexRecord record, long timestamp, String user) {
      log.debug(
          "updating record " + record.id() + " for " + record.type() + " at " + record.index());

      return new IndexRequest(record.index(), record.type(), record.id())
          .source(sourceOf(record, timestamp, user))
          .parent(record.parent())
          .versionType(VersionType.EXTERNAL_GTE)
          .version(timestamp);
    }
Пример #4
0
    @Override
    public ActionRequest request(IndexRecord record, long timestamp, String user) {
      final String id = emptyToNull(record.id()); // auto-generate if empty
      log.debug(
          "overwriting record "
              + nonNull(id, "_auto_")
              + " for "
              + record.type()
              + " at "
              + record.index());

      return new IndexRequest(record.index(), record.type(), id)
          .source(sourceOf(record, timestamp, user))
          .parent(record.parent())
          .versionType(VersionType.FORCE)
          .version(timestamp);
    }