All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ai.stapi.graphoperations.serializableGraph.SerializableNode Maven / Gradle / Ivy

There is a newer version: 0.3.2
Show newest version
package ai.stapi.graphoperations.serializableGraph;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import ai.stapi.graph.graphelements.Node;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class SerializableNode extends SerializableGraphElement {

  public static SerializableNode fromInputNode(Node node) {
    var attributeMap = new HashMap>();
    node.getVersionedAttributes()
        .getVersionedAttributeList()
        .forEach(attr -> attributeMap.put(
            attr.getName(),
            attr.streamAttributeVersions().map(SerializableAttributeVersion::fromAttribute).toList()
        ));

    return new SerializableNode(
        node.getId().getId(),
        node.getType(),
        attributeMap
    );
  }

  public SerializableNode(
      String id,
      String type,
      Map> attributes
  ) {
    super(id, type, attributes);
  }

  @JsonCreator
  private SerializableNode(
      @JsonProperty(GraphElementKeys.ID) String reference,

      @JsonProperty(GraphElementKeys.ATTRIBUTES)
      Map> attributes,

      @JsonProperty(GraphElementKeys.KEY) String key,
      @JsonProperty(GraphElementKeys.REV) String revision
  ) {
    super(reference, attributes, key, revision);
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy