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;
}
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);
}
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);
}
}
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);
}
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;
}
Aggregations