com.tinkerpop.blueprints.Edge Java Examples

The following examples show how to use com.tinkerpop.blueprints.Edge. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ActiveVersionedGraph.java    From antiquity with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Edge getEdge(Object id) {
    Preconditions.checkNotNull(id, "id must be set.");

    Edge edge;
    if (isNaturalIds()) {
        edge = ElementUtils.getSingleElement(this, VEProps.NATURAL_EDGE_ID_PROP_KEY, id, Edge.class);
    } else {
        edge = getEventableGraph().getEdge(id);
    }

    if (edge != null) {
        if (edge instanceof ActiveVersionedElement) {
            return edge;
        } else {
            utils.ensureActiveType(edge);
            return new ActiveVersionedEdge<V>(edge, this);
        }
    } else {
        log.debug("Edge with [{}] was not found.", id);
        return null;
    }
}
 
Example #2
Source File: DElementStore.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
@Override
public void removeEdge(final Edge edge, final Vertex removingVertex) {
	if (edge instanceof DEdge) {
		if (org.openntf.domino.ViewEntry.class.equals(((DEdge) edge).getDelegateType())) {
			throw new UnsupportedOperationException("ViewEntry edges cannot be removed.");
		}
	}
	startTransaction(edge);
	Vertex in = edge.getVertex(Direction.IN);
	if (!in.equals(removingVertex)) {
		((DVertex) in).removeEdge(edge);
		removeCache(in);
	}
	Vertex out = edge.getVertex(Direction.OUT);
	if (!out.equals(removingVertex)) {
		((DVertex) out).removeEdge(edge);
		removeCache(out);
	}
	removeCache(edge);
	((DEdge) edge)._remove();
}
 
Example #3
Source File: StaffProgramEdgeImporter.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@Override
public void importCollection() {
    DBCursor cursor = mongo.getCollection("staffProgramAssociation").find();
    while (cursor.hasNext()) {
        DBObject spa = cursor.next();
        Map<String, Object> body = (Map) spa.get("body");
        List<String> staffIds = (List) body.get("staffId");
        for (String staffId : staffIds) {
            for (Vertex staff : graph.getVertices("mongoid", staffId)) {
                List<String> cohortIds = (List) body.get("programId");
                for (String cohortId : cohortIds)
                    for (Vertex program : graph.getVertices("mongoid", cohortId)) {
                        Edge e = graph.addEdge(null, program, staff, "staffProgram");
                        e.setProperty("mongoid", spa.get("_id"));
                        // This may not be safe.
                        e.setProperty("endDate", body.containsKey("endDate") ? body.get("endDate") : "");
                        e.setProperty("studentRecordAccess", body.get("studentRecordAccess"));
                    }
                
            }
        }
        
    }
}
 
Example #4
Source File: DGraph.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
@Override
public DEdgeList getEdgesFromIds(final Vertex source, final Set<String> set, final String... labels) {
	DEdgeList result = new DEdgeList((DVertex) source);
	for (String id : set) {
		Edge edge = getEdge(id);
		if (edge != null) {
			for (String label : labels) {
				if (label.equals(edge.getLabel())) {
					result.add(edge);
					break;
				}
			}
		}
	}
	return result;
}
 
Example #5
Source File: IdGraph.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
public Edge addEdge(final Object id,
                    final Vertex outVertex,
                    final Vertex inVertex,
                    final String label) {
    if (uniqueIds && null != id && null != getEdge(id)) {
        throw new IllegalArgumentException("edge with given id already exists: " + id);
    }

    verifyNativeElement(outVertex);
    verifyNativeElement(inVertex);

    Edge base = baseGraph.addEdge(null, ((IdVertex) outVertex).getBaseVertex(), ((IdVertex) inVertex).getBaseVertex(), label);

    if (supportEdgeIds) {
        Object v = null == id ? edgeIdFactory.createId() : id;

        if (null != v) {
            base.setProperty(ID, v);
        }
    }

    return new IdEdge(base, this);
}
 
Example #6
Source File: AbstractEdgeHelper.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
@Override
public Set<? extends Edge> getFilteredEdges(final Vertex vertex, final Map<String, Object> filterMap) {
	Set<Edge> result = new LinkedHashSet<Edge>();
	Set<? extends Edge> rawset = getEdges(vertex);
	for (Edge edge : rawset) {
		for (String key : filterMap.keySet()) {
			Object value = edge.getProperty(key);
			if (value != null) {
				if (value.equals(filterMap.get(key))) {
					result.add(edge);
				}
			}
		}
	}
	return Collections.unmodifiableSet(result);
}
 
Example #7
Source File: DFramedTransactionalGraph.java    From org.openntf.domino with Apache License 2.0 6 votes vote down vote up
public <F> F frame(final Element element, final Class<F> kind) {
	//		Class<F> klazz = kind;
	//		DConfiguration config = (DConfiguration) this.getConfig();
	//		config.getTypeManager().initElement(klazz, this, element);
	//		for (FrameInitializer initializer : getConfig().getFrameInitializers()) {
	//			if (!(initializer instanceof JavaFrameInitializer)) {
	//				initializer.initElement(klazz, this, element);
	//			}
	//		}
	F result = null;
	if (element instanceof Edge) {
		result = frame((Edge) element, kind);
	} else if (element instanceof Vertex) {
		result = frame((Vertex) element, kind);
	} else {
		throw new IllegalStateException("Cannot frame an element of type " + element.getClass().getName());
	}
	//		for (FrameInitializer initializer : getConfig().getFrameInitializers()) {
	//			if (initializer instanceof JavaFrameInitializer) {
	//				((JavaFrameInitializer) initializer).initElement(klazz, this, result);
	//			}
	//		}
	return result;
}
 
Example #8
Source File: FramedEdgeList.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
@Override
public boolean contains(final Object arg0) {
	if (arg0 instanceof Edge) {
		return list_.contains(arg0);
	} else if (kind.isAssignableFrom(arg0.getClass())) {
		return list_.contains(((EdgeFrame) kind.cast(arg0)).asEdge());
	} else {
		throw new IllegalArgumentException(
				"Cannot set an object of type " + arg0.getClass().getName() + " to an iterator of " + kind.getName());
	}
}
 
Example #9
Source File: EntityVertexQueryIT.java    From accumulo-recipes with Apache License 2.0 5 votes vote down vote up
@Test
public void testEdges_noQuery_withLabels() {
    EntityVertex v1 = (EntityVertex) graph.getVertex(entityIndex(vertex1));
    CloseableIterable<Edge> edges = (CloseableIterable<Edge>) v1.query().labels("label1").edges();
    System.out.println(edges);
    Assert.assertEquals(2, Iterables.size(edges));
    // two edges point out from vertex1 to vertex2. This should mean vertex2 shows up twice
    assertEntitiesEqual(edge3, ((EntityEdge) Iterables.get(edges, 0)).getEntity());
    assertEntitiesEqual(edge, ((EntityEdge) Iterables.get(edges, 1)).getEntity());
}
 
Example #10
Source File: FramedEdgeList.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
@Override
public boolean remove(final Object arg0) {
	if (arg0 instanceof Edge) {
		return list_.remove(arg0);
	} else if (kind.isAssignableFrom(arg0.getClass())) {
		return list_.remove(((EdgeFrame) kind.cast(arg0)).asEdge());
	} else {
		throw new IllegalArgumentException(
				"Cannot set an object of type " + arg0.getClass().getName() + " to an iterator of " + kind.getName());
	}
}
 
Example #11
Source File: DGraphUtils.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public static Map<CaseInsensitiveString, Method> getGetters(final FramedGraph<?> graph, final EdgeFrame frame) {
	if (graph instanceof DFramedTransactionalGraph) {
		DFramedTransactionalGraph<?> dgraph = (DFramedTransactionalGraph<?>) graph;
		DTypeManager tman = dgraph.getTypeManager();
		Edge e = frame.asEdge();
		Class<?> inter = findInterface(frame);
		Class<?> type = tman.resolve(e, inter);
		return dgraph.getTypeRegistry().getPropertiesGetters(type);
	}
	throw new IllegalArgumentException("Cannot discover registered getters for graph type " + graph.getClass().getName());
}
 
Example #12
Source File: UseDefAnalyser.java    From bjoern with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void updateRead(DataObject<T> dataObject) {
	if (null == instruction || ignoreAccesses) {
		return;
	}
	for (Edge edge : instruction.getEdges(Direction.OUT, "READ")) {
		if (edge.getVertex(Direction.IN).equals(aloc)) {
			// edge exists -> skip
			return;
		}
	}
	// add read edge from instruction to aloc
	instruction.addEdge("READ", aloc);
}
 
Example #13
Source File: EventElement.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
/**
 * Raises a vertexPropertyRemoved or edgePropertyChanged event.
 */
public void setProperty(final String key, final Object value) {
    final Object oldValue = this.baseElement.getProperty(key);
    this.baseElement.setProperty(key, value);

    if (this instanceof Vertex) {
        this.onVertexPropertyChanged((Vertex) this, key, oldValue, value);
    } else if (this instanceof Edge) {
        this.onEdgePropertyChanged((Edge) this, key, oldValue, value);
    }
}
 
Example #14
Source File: DynamicResourceModuleIT.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
@Test
public void nodesAreReturned() {
  path.setVendorExtension("x-query", "MATCH (n) RETURN n");
  CypherInflector inflector = i.getInstance(CypherInflectorFactory.class).create("foo", path);
  Graph graph = (Graph) inflector.apply(context).getEntity();
  assertThat(graph.getVertices(), Matchers.<Vertex>iterableWithSize(2));
  assertThat(graph.getEdges(), Matchers.<Edge>iterableWithSize(0));
}
 
Example #15
Source File: HistoricVersionedGraph.java    From antiquity with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Edge getEdge(Object id) {
    Preconditions.checkNotNull(id, "id must be set.");

    List<HistoricVersionedEdge<V>> chain = buildEdgeChain(id);

    if (chain.size() == 0) {
        log.debug("Edge with [{}] was not found.", id);
        return null;
    } else {
        return chain.get(0);
    }
}
 
Example #16
Source File: UnlinkVertexCommand.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private void removeEdges(OrientGraph tx, OrientVertex vertex) {
    OrientVertex destination = tx.getVertex(documentModel.getObject().getIdentity());
    Iterable<Edge> edges = vertex.getEdges(destination, Direction.BOTH);
    for(Edge edge : edges) {
        tx.removeEdge(edge);
    }
}
 
Example #17
Source File: GraphOperations.java    From bjoern with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Add an edge from the node src to the node dst if it does
 * not already exist.
 *
 * @param src the source of the edge
 * @param dst the destination of the edge
 */
public static void addEdge(Graph graph, OctopusNode src, OctopusNode dst, String edgeType)
{
	for (Edge edge : src.getBaseVertex().getEdges(Direction.OUT,
			edgeType))
	{
		if (edge.getVertex(Direction.IN).equals(dst.getBaseVertex()))
		{
			return;
		}
	}
	graph.addEdge(0, src.getBaseVertex(), dst.getBaseVertex(), edgeType);
}
 
Example #18
Source File: TinkerGraphUtil.java    From SciGraph with Apache License 2.0 5 votes vote down vote up
public Element addElement(Element element) {
  if (element instanceof Vertex) {
    return addNode((Vertex) element);
  } else {
    return addEdge((Edge) element);
  }
}
 
Example #19
Source File: BigdataGraph.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Find edges based on a SPARQL construct query.  The query MUST construct
 * edge statements: 
 * <p>
 * construct { ?from ?edge ?to } where { ... }
 * 
 * @see {@link BigdataGraphQuery}
 */
Iterable<Edge> getEdges(final String queryStr) throws Exception { 
    
    final org.openrdf.query.GraphQuery query = 
            cxn().prepareGraphQuery(QueryLanguage.SPARQL, queryStr);
    
    final GraphQueryResult stmts = query.evaluate();
    
    /*
     * EdgeIterable will close the connection if necessary.
     */
    return new EdgeIterable(stmts);

}
 
Example #20
Source File: DFramedTransactionalGraph.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
@Override
public void removeEdge(final Edge edge) {
	IndexScanner is = getIndexScanner();
	if (is != null) {
		String mid = String.valueOf(edge.getId());
		is.removeDocument(mid);
	}
	removeCache(edge);
	((DGraph) getBaseGraph()).removeEdge(edge);
}
 
Example #21
Source File: TraitRelation.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public Collection<RelationSet> traverse(VertexWrapper vWrapper) {
    Vertex v = vWrapper.getVertex();
    Collection<VertexWrapper> vertices = new ArrayList<>();
    for (Edge e : v.getEdges(Direction.OUT)) {
        if (e.getLabel().startsWith(v.<String>getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY))) {
            VertexWrapper trait = new TermVertexWrapper(e.getVertex(Direction.IN));
            if (! trait.getPropertyKeys().contains("available_as_tag") && ! isDeleted(trait.getVertex())) {
                vertices.add(trait);
            }
        }
    }
    return Collections.singletonList(new RelationSet("traits", vertices));
}
 
Example #22
Source File: DominoGraph.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public Edge getEdge(final Vertex outVertex, final Vertex inVertex, final String label) {
	String id = DominoUtils.toUnid(outVertex.getId() + label + inVertex.getId());
	Edge result = getEdge(id);
	if (result != null) {
		((DominoEdge) result).setOutDoc((IDominoVertex) outVertex);
		((DominoEdge) result).setInDoc((IDominoVertex) inVertex);
	}
	return result;
}
 
Example #23
Source File: TagRelation.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public Pipe asPipe() {
    return new FilterFunctionPipe<>(new PipeFunction<Edge, Boolean>() {
        @Override
        public Boolean compute(Edge edge) {
            String name = edge.getVertex(Direction.OUT).getProperty(Constants.ENTITY_TYPE_PROPERTY_KEY);
            if (edge.getLabel().startsWith(name)) {
                VertexWrapper v = new TermVertexWrapper(edge.getVertex(Direction.IN));
                return v.getPropertyKeys().contains("available_as_tag") && ! isDeleted(v.getVertex());
            } else {
                return false;
            }
        }
    });
}
 
Example #24
Source File: AbstractDependencyRule.java    From light with Apache License 2.0 5 votes vote down vote up
protected void addDependency(Map<String, Object> data) throws Exception {
    String json = null;
    OrientGraph graph = ServiceLocator.getInstance().getGraph();
    try {
        graph.begin();
        Vertex sourceRule = graph.getVertexByKey("Rule.ruleClass", data.get("sourceRuleClass"));
        Vertex destRule = graph.getVertexByKey("Rule.ruleClass", data.get("destRuleClass"));
        Edge edge = sourceRule.addEdge("Depend", destRule);
        edge.setProperty("content", data.get("content"));
        graph.commit();
        //json = edge.getRecord().toJSON();
    } catch (Exception e) {
        logger.error("Exception:", e);
        graph.rollback();
        throw e;
    } finally {
        graph.shutdown();
    }
    Map<String, Object> pageMap = ServiceLocator.getInstance().getMemoryImage("pageMap");
    ConcurrentMap<Object, Object> cache = (ConcurrentMap<Object, Object>)pageMap.get("cache");
    if(cache == null) {
        cache = new ConcurrentLinkedHashMap.Builder<Object, Object>()
                .maximumWeightedCapacity(1000)
                .build();
        pageMap.put("cache", cache);
    }
    cache.put(data.get("pageId"), json);
}
 
Example #25
Source File: EdgeHelper.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public static Vertex getOther(final Edge edge, final Vertex vertex) {
    final Vertex temp = edge.getVertex(Direction.IN);
    if (temp.equals(vertex))
        return edge.getVertex(Direction.OUT);
    else
        return temp;
}
 
Example #26
Source File: IndexedItemsListParser.java    From AccumuloGraph with Apache License 2.0 5 votes vote down vote up
/**
 * Create a parser for items of the specified element class.
 * This may be Vertex, Edge, or Element.
 * @param elementClass
 */
public IndexedItemsListParser(Class<? extends Element> elementClass) {
  // Validate element class.
  if (!Vertex.class.equals(elementClass) &&
      !Edge.class.equals(elementClass) &&
      !Element.class.equals(elementClass)) {
    throw new IllegalArgumentException("elementClass must be Vertex, Edge or Element");
  }
  this.elementClass = elementClass;
}
 
Example #27
Source File: ActiveVersionedEdgeIterable.java    From antiquity with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Iterator<Edge> iterator() {
    return new Iterator<Edge>() {
        private final Iterator<Edge> itty = rawIterable.iterator();

        public void remove() {
            this.itty.remove();
        }

        public Edge next() {
            Edge edge = this.itty.next();
            graph.utils.ensureActiveType(edge);

            if (edge instanceof ActiveVersionedEdge) {
                // TODO: currently for safety, this condition may occur? if
                // so then why?
                return edge;
            } else {
                return new ActiveVersionedEdge<V>(edge, graph);
            }
        }

        public boolean hasNext() {
            return this.itty.hasNext();
        }
    };
}
 
Example #28
Source File: ElementCaches.java    From AccumuloGraph with Apache License 2.0 5 votes vote down vote up
public ElementCaches(AccumuloGraphConfiguration config) {
  if (config.getVertexCacheEnabled()) {
    vertexCache = new ElementCache<Vertex>(config.getVertexCacheSize(),
        config.getVertexCacheTimeout());
  }

  if (config.getEdgeCacheEnabled()) {
    edgeCache = new ElementCache<Edge>(config.getEdgeCacheSize(),
        config.getEdgeCacheTimeout());
  }
}
 
Example #29
Source File: FramedEdgeList.java    From org.openntf.domino with Apache License 2.0 5 votes vote down vote up
public FramedEdgeList(final FramedGraph<? extends Graph> framedGraph, final Vertex sourceVertex, final Iterable<Edge> list,
		final Class<T> kind) {
	super(framedGraph, list, kind);
	//		System.out.println("TEMP DEBUG new FramedEdgeList created from a " + list.getClass().getName());
	sourceVertex_ = sourceVertex;
	if (list instanceof List) {
		list_ = (List<Edge>) list;
	} else {
		list_ = new ArrayList<Edge>();
		for (Edge e : list) {
			list_.add(e);
		}
	}
}
 
Example #30
Source File: BigdataGraph.java    From database with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Add an edge.
 */
@Override
public Edge addEdge(final Object key, final Vertex from, final Vertex to, 
        final String label) {
    
    return addEdge(key, from, to, label, false);
    
}