public ObjectNode resolveProperties()

in streams-util/src/main/java/org/apache/streams/util/schema/SchemaStoreImpl.java [196:259]


  public ObjectNode resolveProperties(Schema schema, ObjectNode fieldNode, String resourceId) {
    // this should return something more suitable like:
    //   Map<String, Pair<Schema, ObjectNode>>
    ObjectNode schemaProperties = NODE_FACTORY.objectNode();
    ObjectNode parentProperties = NODE_FACTORY.objectNode();
    if (fieldNode == null) {
      ObjectNode schemaContent = (ObjectNode) schema.getContent();
      if (schemaContent.has("properties")) {
        schemaProperties = (ObjectNode) schemaContent.get("properties");
        if (schema.getParentContent() != null) {
          ObjectNode parentContent = (ObjectNode) schema.getParentContent();
          if (parentContent.has("properties")) {
            parentProperties = (ObjectNode) parentContent.get("properties");
          }
        }
      }
    } else if (fieldNode.size() > 0) {
      if (fieldNode.has("properties") && fieldNode.get("properties").isObject() && fieldNode.get("properties").size() > 0) {
        schemaProperties = (ObjectNode) fieldNode.get("properties");
      }
      URI parentUri = null;
      if ( fieldNode.has("$ref") || fieldNode.has("extends") ) {
        JsonNode refNode = fieldNode.get("$ref");
        JsonNode extendsNode = fieldNode.get("extends");
        if (refNode != null && refNode.isValueNode()) {
          parentUri = URI.create(refNode.asText());
        } else if (extendsNode != null && extendsNode.isObject()) {
          parentUri = URI.create(extendsNode.get("$ref").asText());
        }
        ObjectNode parentContent = null;
        URI absoluteUri;
        if (parentUri.isAbsolute()) {
          absoluteUri = parentUri;
        } else {
          absoluteUri = schema.getUri().resolve(parentUri);
          if (!absoluteUri.isAbsolute() || (absoluteUri.isAbsolute() && !getByUri(absoluteUri).isPresent() )) {
            absoluteUri = schema.getParentUri().resolve(parentUri);
          }
        }
        if (absoluteUri.isAbsolute()) {
          if (getByUri(absoluteUri).isPresent()) {
            parentContent = (ObjectNode) getByUri(absoluteUri).get().getContent();
          }
          if (parentContent != null && parentContent.isObject() && parentContent.has("properties")) {
            parentProperties = (ObjectNode) parentContent.get("properties");
          } else if (absoluteUri.getPath().endsWith("#properties")) {
            absoluteUri = URI.create(absoluteUri.toString().replace("#properties", ""));
            parentProperties = (ObjectNode) getByUri(absoluteUri).get().getContent().get("properties");
          }
        }
      }


    }

    ObjectNode resolvedProperties = NODE_FACTORY.objectNode();
    if (parentProperties != null && parentProperties.size() > 0) {
      resolvedProperties = PropertyUtil.mergeProperties(schemaProperties, parentProperties);
    } else {
      resolvedProperties = schemaProperties.deepCopy();
    }

    return resolvedProperties;
  }