Search in sources :

Example 81 with AtlasVertex

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

the class GraphBackedTypeStore method createVertices.

/**
     * Finds or creates type vertices with the information specified.
     *
     * @param infoList
     * @return list with the vertices corresponding to the types in the list.
     * @throws AtlasException
     */
private List<AtlasVertex> createVertices(List<TypeVertexInfo> infoList) throws AtlasException {
    List<AtlasVertex> result = new ArrayList<>(infoList.size());
    List<String> typeNames = Lists.transform(infoList, new Function<TypeVertexInfo, String>() {

        @Override
        public String apply(TypeVertexInfo input) {
            return input.getTypeName();
        }
    });
    Map<String, AtlasVertex> vertices = findVertices(typeNames);
    for (TypeVertexInfo info : infoList) {
        AtlasVertex vertex = vertices.get(info.getTypeName());
        if (!GraphHelper.elementExists(vertex)) {
            LOG.debug("Adding vertex {}{}", PROPERTY_PREFIX, info.getTypeName());
            vertex = graph.addVertex();
            // Mark as type AtlasVertex
            setProperty(vertex, Constants.VERTEX_TYPE_PROPERTY_KEY, VERTEX_TYPE);
            setProperty(vertex, Constants.TYPE_CATEGORY_PROPERTY_KEY, info.getCategory());
            setProperty(vertex, Constants.TYPENAME_PROPERTY_KEY, info.getTypeName());
        }
        String newDescription = info.getTypeDescription();
        if (newDescription != null) {
            String oldDescription = getPropertyKey(Constants.TYPEDESCRIPTION_PROPERTY_KEY);
            if (!newDescription.equals(oldDescription)) {
                setProperty(vertex, Constants.TYPEDESCRIPTION_PROPERTY_KEY, newDescription);
            }
        } else {
            LOG.debug(" type description is null ");
        }
        result.add(vertex);
    }
    return result;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ArrayList(java.util.ArrayList)

Example 82 with AtlasVertex

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

the class TypePersistenceVisitor method visitAttributeNames.

@Override
public void visitAttributeNames(String typeName, List<String> attrNames) throws AtlasException {
    AtlasVertex vertex = typeVertices.get(typeName);
    setProperty(vertex, GraphBackedTypeStore.getPropertyKey(typeName), attrNames);
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex)

Example 83 with AtlasVertex

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

the class TypePersistenceVisitor method visitAttribute.

@Override
public void visitAttribute(String typeName, AttributeInfo attribute) throws AtlasException {
    AtlasVertex vertex = typeVertices.get(typeName);
    String propertyKey = GraphBackedTypeStore.getPropertyKey(typeName, attribute.name);
    try {
        setProperty(vertex, propertyKey, attribute.toJson());
    } catch (JSONException e) {
        throw new StorageException(typeName, e);
    }
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) JSONException(org.codehaus.jettison.json.JSONException)

Example 84 with AtlasVertex

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

the class EntityGraphRetriever method getClassification.

public AtlasClassification getClassification(String guid, String classificationName) throws AtlasBaseException {
    AtlasVertex instanceVertex = AtlasGraphUtilsV1.findByGuid(guid);
    if (instanceVertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
    }
    List<AtlasClassification> classifications = getClassifications(instanceVertex, classificationName);
    if (CollectionUtils.isEmpty(classifications)) {
        throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classificationName);
    }
    return classifications.get(0);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification)

Example 85 with AtlasVertex

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

the class EntityGraphRetriever method mapVertexToStruct.

private AtlasStruct mapVertexToStruct(AtlasVertex entityVertex, String edgeLabel, AtlasEdge edge, AtlasEntityExtInfo entityExtInfo) throws AtlasBaseException {
    AtlasStruct ret = null;
    if (edge == null) {
        edge = graphHelper.getEdgeForLabel(entityVertex, edgeLabel);
    }
    if (GraphHelper.elementExists(edge)) {
        final AtlasVertex referenceVertex = edge.getInVertex();
        ret = new AtlasStruct(GraphHelper.getTypeName(referenceVertex));
        mapAttributes(referenceVertex, ret, entityExtInfo);
    }
    return ret;
}
Also used : AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex)

Aggregations

AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)164 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)53 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)26 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)21 ArrayList (java.util.ArrayList)20 Test (org.testng.annotations.Test)19 HashMap (java.util.HashMap)16 Id (org.apache.atlas.typesystem.persistence.Id)14 Map (java.util.Map)13 List (java.util.List)12 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)12 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)12 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)12 AtlasException (org.apache.atlas.AtlasException)11 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)11 RepositoryException (org.apache.atlas.repository.RepositoryException)11 AtlasGraphQuery (org.apache.atlas.repository.graphdb.AtlasGraphQuery)11 AtlasType (org.apache.atlas.type.AtlasType)11 HashSet (java.util.HashSet)8 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)8