use of org.apache.atlas.repository.graphdb.AtlasEdge in project incubator-atlas by apache.
the class GraphBackedMetadataRepositoryTest method assertEdge.
private boolean assertEdge(String id, String typeName) throws Exception {
AtlasGraph graph = TestUtils.getGraph();
Iterable<AtlasVertex> vertices = graph.query().has(Constants.GUID_PROPERTY_KEY, id).vertices();
AtlasVertex AtlasVertex = vertices.iterator().next();
Iterable<AtlasEdge> edges = AtlasVertex.getEdges(AtlasEdgeDirection.OUT, Constants.INTERNAL_PROPERTY_KEY_PREFIX + typeName + ".ref");
if (!edges.iterator().hasNext()) {
ITypedReferenceableInstance entity = repositoryService.getEntityDefinition(id);
assertNotNull(entity.get("ref"));
return true;
}
return false;
}
use of org.apache.atlas.repository.graphdb.AtlasEdge in project incubator-atlas by apache.
the class GraphHelperTest method testGetOutgoingEdgesByLabel.
@Test
public void testGetOutgoingEdgesByLabel() throws Exception {
AtlasGraph graph = TestUtils.getGraph();
AtlasVertex v1 = graph.addVertex();
AtlasVertex v2 = graph.addVertex();
graph.addEdge(v1, v2, "l1");
graph.addEdge(v1, v2, "l2");
Iterator<AtlasEdge> iterator = GraphHelper.getInstance().getOutGoingEdgesByLabel(v1, "l1");
assertTrue(iterator.hasNext());
assertTrue(iterator.hasNext());
assertNotNull(iterator.next());
assertNull(iterator.next());
assertFalse(iterator.hasNext());
assertFalse(iterator.hasNext());
}
use of org.apache.atlas.repository.graphdb.AtlasEdge in project incubator-atlas by apache.
the class Titan1Graph method removeEdge.
@Override
public void removeEdge(AtlasEdge<Titan1Vertex, Titan1Edge> edge) {
Edge wrapped = edge.getE().getWrappedElement();
wrapped.remove();
}
use of org.apache.atlas.repository.graphdb.AtlasEdge 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;
}
use of org.apache.atlas.repository.graphdb.AtlasEdge in project incubator-atlas by apache.
the class AtlasRelationshipStoreV1 method createRelationship.
private AtlasRelationship createRelationship(AtlasRelationship relationship, AtlasVertex end1Vertex, AtlasVertex end2Vertex) throws AtlasBaseException {
AtlasRelationship ret;
try {
AtlasEdge relationshipEdge = getRelationshipEdge(end1Vertex, end2Vertex, relationship);
if (relationshipEdge == null) {
relationshipEdge = createRelationshipEdge(end1Vertex, end2Vertex, relationship);
AtlasRelationshipType relationType = typeRegistry.getRelationshipTypeByName(relationship.getTypeName());
if (MapUtils.isNotEmpty(relationType.getAllAttributes())) {
for (AtlasAttribute attr : relationType.getAllAttributes().values()) {
String attrName = attr.getName();
String attrVertexProperty = attr.getVertexPropertyName();
Object attrValue = relationship.getAttribute(attrName);
AtlasGraphUtilsV1.setProperty(relationshipEdge, attrVertexProperty, attrValue);
}
}
ret = mapEdgeToAtlasRelationship(relationshipEdge);
} else {
throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_ALREADY_EXISTS, relationship.getTypeName(), relationship.getEnd1().getGuid(), relationship.getEnd2().getGuid());
}
} catch (RepositoryException e) {
throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e);
}
return ret;
}
Aggregations