Search in sources :

Example 1 with AtlasElement

use of org.apache.atlas.repository.graphdb.AtlasElement in project atlas by apache.

the class AtlasGraphSONUtility method createJSONMap.

private static ObjectNode createJSONMap(final Map<String, Object> map, final List<String> propertyKeys, final boolean showTypes) {
    final ObjectNode jsonMap = JSON_NODE_FACTORY.objectNode();
    for (Object key : map.keySet()) {
        Object value = map.get(key);
        if (value != null) {
            if (value instanceof List) {
                value = createJSONList((List<Object>) value, propertyKeys, showTypes);
            } else if (value instanceof Map) {
                value = createJSONMap((Map<String, Object>) value, propertyKeys, showTypes);
            } else if (value instanceof AtlasElement) {
                value = objectNodeFromElement((AtlasElement) value, propertyKeys, showTypes ? AtlasGraphSONMode.EXTENDED : AtlasGraphSONMode.NORMAL);
            } else if (value.getClass().isArray()) {
                value = createJSONList(convertArrayToList(value), propertyKeys, showTypes);
            }
        }
        putObject(jsonMap, key.toString(), getValue(value, showTypes));
    }
    return jsonMap;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AtlasElement(org.apache.atlas.repository.graphdb.AtlasElement) JSONObject(org.codehaus.jettison.json.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with AtlasElement

use of org.apache.atlas.repository.graphdb.AtlasElement in project incubator-atlas by apache.

the class Titan0Element method setPropertyFromElementsIds.

@Override
public void setPropertyFromElementsIds(String propertyName, List<AtlasElement> values) {
    List<String> propertyValue = new ArrayList<>(values.size());
    for (AtlasElement element : values) {
        propertyValue.add(element.getId().toString());
    }
    setProperty(propertyName, propertyValue);
}
Also used : ArrayList(java.util.ArrayList) AtlasElement(org.apache.atlas.repository.graphdb.AtlasElement) Override(java.lang.Override)

Example 3 with AtlasElement

use of org.apache.atlas.repository.graphdb.AtlasElement in project incubator-atlas by apache.

the class AtlasGraphSONUtility method createJSONMap.

private static ObjectNode createJSONMap(final Map<String, Object> map, final List<String> propertyKeys, final boolean showTypes) {
    final ObjectNode jsonMap = JSON_NODE_FACTORY.objectNode();
    for (Object key : map.keySet()) {
        Object value = map.get(key);
        if (value != null) {
            if (value instanceof List) {
                value = createJSONList((List<Object>) value, propertyKeys, showTypes);
            } else if (value instanceof Map) {
                value = createJSONMap((Map<String, Object>) value, propertyKeys, showTypes);
            } else if (value instanceof AtlasElement) {
                value = objectNodeFromElement((AtlasElement) value, propertyKeys, showTypes ? AtlasGraphSONMode.EXTENDED : AtlasGraphSONMode.NORMAL);
            } else if (value.getClass().isArray()) {
                value = createJSONList(convertArrayToList(value), propertyKeys, showTypes);
            }
        }
        putObject(jsonMap, key.toString(), getValue(value, showTypes));
    }
    return jsonMap;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AtlasElement(org.apache.atlas.repository.graphdb.AtlasElement) JSONObject(org.codehaus.jettison.json.JSONObject) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 4 with AtlasElement

use of org.apache.atlas.repository.graphdb.AtlasElement in project incubator-atlas by apache.

the class GraphHelper method findElement.

private AtlasElement findElement(boolean isVertexSearch, Object... args) throws EntityNotFoundException {
    AtlasGraphQuery query = graph.query();
    for (int i = 0; i < args.length; i += 2) {
        query = query.has((String) args[i], args[i + 1]);
    }
    Iterator<AtlasElement> results = isVertexSearch ? query.vertices().iterator() : query.edges().iterator();
    AtlasElement element = (results != null && results.hasNext()) ? results.next() : null;
    if (element == null) {
        throw new EntityNotFoundException("Could not find " + (isVertexSearch ? "vertex" : "edge") + " with condition: " + getConditionString(args));
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Found {} with condition {}", string(element), getConditionString(args));
    }
    return element;
}
Also used : AtlasElement(org.apache.atlas.repository.graphdb.AtlasElement) AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery) EntityNotFoundException(org.apache.atlas.typesystem.exception.EntityNotFoundException)

Example 5 with AtlasElement

use of org.apache.atlas.repository.graphdb.AtlasElement in project atlas by apache.

the class GraphHelper method findElement.

private AtlasElement findElement(boolean isVertexSearch, Object... args) throws EntityNotFoundException {
    AtlasGraphQuery query = graph.query();
    for (int i = 0; i < args.length; i += 2) {
        query = query.has((String) args[i], args[i + 1]);
    }
    Iterator<AtlasElement> results = isVertexSearch ? query.vertices().iterator() : query.edges().iterator();
    AtlasElement element = (results != null && results.hasNext()) ? results.next() : null;
    if (element == null) {
        throw new EntityNotFoundException("Could not find " + (isVertexSearch ? "vertex" : "edge") + " with condition: " + getConditionString(args));
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("Found {} with condition {}", string(element), getConditionString(args));
    }
    return element;
}
Also used : AtlasElement(org.apache.atlas.repository.graphdb.AtlasElement) AtlasGraphQuery(org.apache.atlas.repository.graphdb.AtlasGraphQuery) EntityNotFoundException(org.apache.atlas.exception.EntityNotFoundException)

Aggregations

AtlasElement (org.apache.atlas.repository.graphdb.AtlasElement)8 ArrayList (java.util.ArrayList)6 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 Override (java.lang.Override)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 AtlasGraphQuery (org.apache.atlas.repository.graphdb.AtlasGraphQuery)2 JSONObject (org.codehaus.jettison.json.JSONObject)2 EntityNotFoundException (org.apache.atlas.exception.EntityNotFoundException)1 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)1