Search in sources :

Example 1 with ElementPropertiesRule

use of org.apache.atlas.repository.graphdb.titan1.graphson.AtlasElementPropertyConfig.ElementPropertiesRule in project incubator-atlas by apache.

the class AtlasGraphSONUtility method objectNodeFromElement.

/**
     * Creates GraphSON for a single graph element.
     */
private ObjectNode objectNodeFromElement(final AtlasElement element) {
    final boolean isEdge = element instanceof AtlasEdge;
    final boolean showTypes = mode == AtlasGraphSONMode.EXTENDED;
    final List<String> propertyKeys = isEdge ? this.edgePropertyKeys : this.vertexPropertyKeys;
    final ElementPropertiesRule elementPropertyConfig = isEdge ? this.edgePropertiesRule : this.vertexPropertiesRule;
    final ObjectNode jsonElement = createJSONMap(createPropertyMap(element, propertyKeys, elementPropertyConfig, normalized), propertyKeys, showTypes);
    if ((isEdge && this.includeReservedEdgeId) || (!isEdge && this.includeReservedVertexId)) {
        putObject(jsonElement, AtlasGraphSONTokens.INTERNAL_ID, element.getId());
    }
    // are graph implementations that have AtlasEdge extend from AtlasVertex
    if (element instanceof AtlasEdge) {
        final AtlasEdge edge = (AtlasEdge) element;
        if (this.includeReservedEdgeId) {
            putObject(jsonElement, AtlasGraphSONTokens.INTERNAL_ID, element.getId());
        }
        if (this.includeReservedEdgeType) {
            jsonElement.put(AtlasGraphSONTokens.INTERNAL_TYPE, AtlasGraphSONTokens.EDGE);
        }
        if (this.includeReservedEdgeOutV) {
            putObject(jsonElement, AtlasGraphSONTokens.INTERNAL_OUT_V, edge.getOutVertex().getId());
        }
        if (this.includeReservedEdgeInV) {
            putObject(jsonElement, AtlasGraphSONTokens.INTERNAL_IN_V, edge.getInVertex().getId());
        }
        if (this.includeReservedEdgeLabel) {
            jsonElement.put(AtlasGraphSONTokens.INTERNAL_LABEL, edge.getLabel());
        }
    } else if (element instanceof AtlasVertex) {
        if (this.includeReservedVertexId) {
            putObject(jsonElement, AtlasGraphSONTokens.INTERNAL_ID, element.getId());
        }
        if (this.includeReservedVertexType) {
            jsonElement.put(AtlasGraphSONTokens.INTERNAL_TYPE, AtlasGraphSONTokens.VERTEX);
        }
    }
    return jsonElement;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ElementPropertiesRule(org.apache.atlas.repository.graphdb.titan1.graphson.AtlasElementPropertyConfig.ElementPropertiesRule) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Aggregations

ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)1 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)1 ElementPropertiesRule (org.apache.atlas.repository.graphdb.titan1.graphson.AtlasElementPropertyConfig.ElementPropertiesRule)1