public Set<String> getKeys(ObjectNode node) {
    Set<String> keys = new LinkedHashSet<>();
    if (node == null) {
      return keys;
    }

    Iterator<String> it = node.fieldNames();
    while (it.hasNext()) {
      keys.add(it.next());
    }

    return keys;
  }
Exemplo n.º 2
0
 @Override
 public List<String> getAttributeNames() {
   return ImmutableList.copyOf(data.fieldNames());
 }
Exemplo n.º 3
0
 @Override
 public boolean isEmpty() {
   return !data.fieldNames().hasNext();
 }
Exemplo n.º 4
0
    private ViewObject processObjectNode(ObjectNode objectNode) {

      Set<ObjectId> nodeIds = null;
      Set<String> valueFields = new HashSet<>();
      Map<String, ViewArray> arrayFields = new HashMap<>();
      Map<String, ViewObject> refFields = new HashMap<>();
      Map<String, ViewArray> backRefFields = new HashMap<>();
      Map<String, ViewObject> latestBackRefFields = new HashMap<>();

      for (Iterator<String> fieldIter = objectNode.fieldNames(); fieldIter.hasNext(); ) {
        String fieldName = fieldIter.next();
        JsonNode value = objectNode.get(fieldName);

        if (value == null || value.isNull()) {
          throw new IllegalArgumentException(
              "All fields present in example view data must have associated values. Field "
                  + fieldName
                  + " does not.");
        }

        if (fieldName.equals(ReservedFields.VIEW_OBJECT_ID)) {
          String text = value.textValue();
          if (isValidRefValue(text)) {
            nodeIds = parseObjectIds(text);
          } else {
            throw new IllegalArgumentException(
                "Encountered an instanceId that is not an objectId in string form." + value);
          }
        } else if (fieldName.equals(ReservedFields.VIEW_CLASS)) {
          // ignore
        } else if (fieldName.startsWith(ReservedFields.ALL_BACK_REF_FIELD_PREFIX)) {
          if (value.isArray() && value.size() == 1 && value.get(0).isObject()) {
            ViewArray viewArray = processArrayNode((ArrayNode) value);
            if (viewArray.element == null) {
              throw new IllegalArgumentException(
                  "Back reference field "
                      + fieldName
                      + " does not contain valid example view data");
            }
            backRefFields.put(removeFieldNameModifier(fieldName), viewArray);
          } else {
            throw new IllegalArgumentException(
                "Back-Reference fields (fields beginning with "
                    + ReservedFields.ALL_BACK_REF_FIELD_PREFIX
                    + ") must hold"
                    + " values that are one element arrays of json objects. "
                    + fieldName
                    + " does not.");
          }
        } else if (fieldName.startsWith(ReservedFields.LATEST_BACK_REF_FIELD_PREFIX)) {
          if (!value.isObject()) {
            throw new IllegalArgumentException(
                "Latest Back reference field "
                    + fieldName
                    + " does not contain valid example view data");
          }
          latestBackRefFields.put(
              removeFieldNameModifier(fieldName), processObjectNode((ObjectNode) value));
        } else if (value.isArray()) {
          ViewArray viewArray = processArrayNode((ArrayNode) value);

          // if there was an object within the array, it is a refs field.
          // if not it's just an array of literal values and we treat it as
          // an opaque value field
          if (viewArray.element != null) {
            arrayFields.put(fieldName, processArrayNode((ArrayNode) value));
          } else {
            valueFields.add(fieldName);
          }
        } else if (value.isObject()) {
          refFields.put(fieldName, processObjectNode((ObjectNode) value));
        } else {
          valueFields.add(fieldName);
        }
      }

      return new ViewObject(
          nodeIds, valueFields, arrayFields, refFields, backRefFields, latestBackRefFields);
    }