Java Code Examples for com.tinkerpop.blueprints.Edge#setProperty()

The following examples show how to use com.tinkerpop.blueprints.Edge#setProperty() . 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: 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 2
Source File: AutoIndexTest.java    From AccumuloGraph with Apache License 2.0 6 votes vote down vote up
@Test
public void testEdgeNoAutoIndex() throws Exception {
  AccumuloGraph graph = (AccumuloGraph) GraphFactory.open(AccumuloGraphTestUtils
      .generateGraphConfig("EdgeNoAutoIndexTest").getConfiguration());
  String id1 = "A";
  String id2 = "B";
  String eid = "X";
  String key = "name";
  String value = "bananaman";

  Vertex v1 = graph.addVertex(id1);
  Vertex v2 = graph.addVertex(id2);
  Edge e = graph.addEdge(eid, v1, v2, "edge");
  e.setProperty(key, value);

  Iterable<Element> elements = graph.getGlobals()
      .getEdgeKeyIndexWrapper().readElementsFromIndex(key, value);
  assertEquals(0, count(elements));
}
 
Example 3
Source File: ActiveVersionedGraph.java    From antiquity with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Add a plain edge to the graph.
 * 
 * Note: this is not an eventable vertex.
 * 
 * @param id The id of the edge to set, if null, new id will be generated.
 * @return plain created edge.
 */
private Edge addPlainEdgeToGraph(Object id, Vertex out, Vertex in, String label) {
    validateNewId(id, Edge.class);
    final Edge edge;

    // TODO: Ensure we get raw vertices here.

    Object idVal = id == null ? edgeIdFactory.createId() : id;
    if (isNaturalIds()) {
        // we create an id just in case the underline doesn't ignore
        // supplied ids
        // and cannot recieve null but we ignore this id in the logic.
        edge = getUneventableGraph().addEdge(edgeIdFactory.createId(), out, in, label);
        edge.setProperty(VEProps.NATURAL_EDGE_ID_PROP_KEY, idVal);
    } else {
        edge = getUneventableGraph().addEdge(idVal, out, in, label);
    }

    return edge;
}
 
Example 4
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 5
Source File: StudentSectionEdgeImporter.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@Override
public void importCollection() {
    DBCursor cursor = mongo.getCollection("studentSectionAssociation").find();
    cursor.batchSize(BATCH_SIZE);
    while (cursor.hasNext()) {
        DBObject spa = cursor.next();
        @SuppressWarnings("unchecked")
        Map<String, Object> body = (Map<String, Object>) spa.get("body");
        String studentId = (String) body.get("studentId");
        String sectionId = (String) body.get("sectionId");
        for (Vertex student : graph.getVertices("mongoid", studentId)) {
            for (Vertex section : graph.getVertices("mongoid", sectionId)) {
                Edge e = graph.addEdge(null, section, student, "studentSection");
                e.setProperty("mongoid", spa.get("_id"));

                if (body.containsKey("endDate")) {
                    e.setProperty("endDate", body.get("endDate"));
                }
                
                logger.log(Level.INFO, "Adding an edge between section: " + sectionId + " --> student: " + studentId);
            }
        }            
    }        
}
 
Example 6
Source File: StaffCohortEdgeImporter.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@Override
public void importCollection() {
    DBCursor cursor = mongo.getCollection("staffCohortAssociation").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("cohortId");
                for (String cohortId : cohortIds)
                    for (Vertex program : graph.getVertices("mongoid", cohortId)) {
                        Edge e = graph.addEdge(null, program, staff, "staffCohort");
                        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 7
Source File: StudentCohortEdgeImporter.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@Override
public void importCollection() {
    DBCursor cursor = mongo.getCollection("studentCohortAssociation").find();
    while (cursor.hasNext()) {
        DBObject spa = cursor.next();
        Map<String, Object> body = (Map) spa.get("body");
        for (Vertex student : graph.getVertices("mongoid", body.get("studentId"))) {
            for (Vertex program : graph.getVertices("mongoid", body.get("cohortId"))) {
                Edge e = graph.addEdge(null, program, student, "studentCohort");
                e.setProperty("mongoid", spa.get("_id"));
                // This may not be safe.
                e.setProperty("endDate", body.get("endDate"));
            }
            
        }
        
    }
    
}
 
Example 8
Source File: TeacherSectionEdgeImporter.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@Override
public void importCollection() {
    DBCursor cursor = mongo.getCollection("teacherSectionAssociation").find();
    while (cursor.hasNext()) {
        DBObject spa = cursor.next();
        @SuppressWarnings("unchecked")
        Map<String, Object> body = (Map<String, Object>) spa.get("body");
        String teacherId = (String) body.get("teacherId");
        String sectionId = (String) body.get("sectionId");
        for (Vertex student : graph.getVertices("mongoid", teacherId)) {
            logger.log(Level.INFO, "Found teacherId {0}", body.get("teacherId"));
            for (Vertex program : graph.getVertices("mongoid", body.get("sectionId"))) {
                logger.log(Level.INFO, "Found sectionId {0}", body.get("sectionId"));
                Edge e = graph.addEdge(null, program, student, "teacherSection");
                e.setProperty("mongoid", spa.get("_id"));
                // This may not be safe.
                e.setProperty("endDate", body.get("endDate"));
            }
            
        }
        
    }
}
 
Example 9
Source File: StudentProgramEdgeImporter.java    From secure-data-service with Apache License 2.0 6 votes vote down vote up
@Override
public void importCollection() {
    DBCursor cursor = mongo.getCollection("studentProgramAssociation").find();
    while (cursor.hasNext()) {
        DBObject spa = cursor.next();
        Map<String, Object> body = (Map) spa.get("body");
        for (Vertex student : graph.getVertices("mongoid", body.get("studentId"))) {
            for (Vertex program : graph.getVertices("mongoid", body.get("programId"))) {
                Edge e = graph.addEdge(null, program, student, "studentProgram");
                e.setProperty("mongoid", spa.get("_id"));
                // This may not be safe.
                e.setProperty("endDate", body.get("endDate"));
            }
            
        }

    }

}
 
Example 10
Source File: AutoIndexTest.java    From AccumuloGraph with Apache License 2.0 5 votes vote down vote up
@Test
public void testEdgeAutoIndex() throws Exception {
  AccumuloGraph graph = (AccumuloGraph) GraphFactory.open(AccumuloGraphTestUtils
      .generateGraphConfig("EdgeAutoIndex").setAutoIndex(true).getConfiguration());
  String id1 = "A";
  String id2 = "B";
  String eid = "X";
  String key = "name";
  String value = "bananaman";

  Vertex v1 = graph.addVertex(id1);
  Vertex v2 = graph.addVertex(id2);
  Edge e = graph.addEdge(eid, v1, v2, "edge");
  e.setProperty(key, value);

  Iterable<Element> elements = graph.getGlobals()
      .getEdgeKeyIndexWrapper().readElementsFromIndex(key, value);
  int count = 0;
  for (Element element : elements) {
    assertTrue(element instanceof Edge);
    assertEquals(eid, element.getId());
    assertEquals(value, element.getProperty(key));
    count++;
  }
  assertEquals(1, count);

  graph.removeVertex(v1);
  elements = graph.getGlobals()
      .getEdgeKeyIndexWrapper().readElementsFromIndex(key, value);
  assertEquals(0, count(elements));
}
 
Example 11
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 12
Source File: ActiveVersionedGraph.java    From antiquity with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Version removed vertices
 * 
 * @param nextVer next version (to be committed) of the graph
 * @param maxVer current max version of the graph
 * @param vertices A map of removed vertices where key=removed vertex &
 *        value=A map of the removed vertex's properties.
 */
protected void versionRemovedVertices(V nextVer, V maxVer, Map<Vertex, Map<String, Object>> vertices) {
    for (Map.Entry<Vertex, Map<String, Object>> v : vertices.entrySet()) {
        // we can't touch the vertex as it's deleted already
        // utils.ensureActiveType(v.getKey());
        // ActiveVersionedVertex<V> av = new
        // ActiveVersionedVertex<V>(v.getKey(), this);
        if (!v.getValue().containsKey(VEProps.REF_TO_LATEST_HISTORIC_ID_KEY)) {
            throw new IllegalStateException("Expected removed vertx to contain key: "
                    + VEProps.REF_TO_LATEST_HISTORIC_ID_KEY);
        }

        HistoricVersionedVertex<V> hv =
                getHistoricGraph().getLatestHistoricRevision(
                        (String) v.getValue().get(VEProps.REF_TO_LATEST_HISTORIC_ID_KEY));

        // Remove ALL vertex's edges, must be invoked on getRaw to avoid
        // filtering.
        for (Edge e : hv.getRaw().getEdges(Direction.BOTH)) {
            if (utils.isInternal(e)) {
                continue;
            }

            utils.ensureHistoricType(e);
            e.setProperty(VEProps.REMOVED_PROP_KEY, nextVer);
            e.setProperty(VEProps.VALID_MAX_VERSION_PROP_KEY, maxVer);
        }


        hv.getRaw().setProperty(VEProps.REMOVED_PROP_KEY, nextVer);
        hv.getRaw().setProperty(VEProps.VALID_MAX_VERSION_PROP_KEY, maxVer);
    }
}
 
Example 13
Source File: ActiveVersionedGraph.java    From antiquity with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Add a corresponding historic edge to the specified active edge
 * 
 * @param a active edge to add corresponding historic edge for
 * @param startVersion the start version the historic edge
 * @param endVersion the end version the historic edge
 * @param oldValues The old (before modification) values of the specified
 *        active edge.
 * @return an added historic edge.
 */
private HistoricVersionedEdge<V> addHistoricEdge(ActiveVersionedEdge<V> a, V startVersion, V endVersion,
        Map<String, Object> oldValues) {

    ActiveVersionedVertex<V> out = (ActiveVersionedVertex<V>) a.getVertex(Direction.OUT);
    ActiveVersionedVertex<V> in = (ActiveVersionedVertex<V>) a.getVertex(Direction.IN);

    if (out == null) {
        throw new IllegalStateException("Expected out vertex to exist.");
    }

    if (in == null) {
        throw new IllegalStateException("Expected in vertex to exist.");
    }

    HistoricVersionedVertex<V> hOut = getHistoricGraph().getLatestHistoricRevision(out);
    HistoricVersionedVertex<V> hIn = getHistoricGraph().getLatestHistoricRevision(in);

    Edge edge = addPlainEdgeToGraph(null, hOut.getRaw(), hIn.getRaw(), a.getLabel());
    edge.setProperty(VEProps.REF_TO_ACTIVE_ID_KEY, a.getId());
    edge.setProperty(VEProps.HISTORIC_ELEMENT_PROP_KEY, true);

    // FIXME: Range is right?
    HistoricVersionedEdge<V> hv =
            new HistoricVersionedEdge(edge, this.getHistoricGraph(), Range.range(startVersion, startVersion));
    utils.setStartVersion(hv, startVersion);
    utils.setEndVersion(hv, endVersion);

    return hv;
}
 
Example 14
Source File: StudentSchoolEdgeImporter.java    From secure-data-service with Apache License 2.0 5 votes vote down vote up
/**
 * Imports student school associations (as edges) into the graph structure.
 */
@Override
public void importCollection() {
    logger.log(Level.INFO, "Importing collection into graph: " + STUDENT_SCHOOL_ASSOCIATION);
    
    DBCursor cursor = mongo.getCollection(STUDENT_SCHOOL_ASSOCIATION).find();
    cursor.batchSize(BATCH_SIZE);
    while (cursor.hasNext()) {
        DBObject association = cursor.next();
        
        @SuppressWarnings("unchecked")
        Map<String, Object> body = (Map<String, Object>) association.get("body");
        String studentId = (String) body.get("studentId");
        String schoolId = (String) body.get("schoolId");
        for (Vertex student : graph.getVertices("mongoid", studentId)) {
            for (Vertex school : graph.getVertices("mongoid", schoolId)) {
                Edge e = graph.addEdge(null, school, student, "studentSchoolAssociation");
                e.setProperty("mongoid", association.get("_id"));
                
                if (body.containsKey("exitWithdrawDate")) {
                    e.setProperty("exitWithdrawDate", body.get("exitWithdrawDate"));
                }
                
                logger.log(Level.INFO, "Adding an edge between school: " + schoolId + " --> student: " + studentId);
            }
        }            
    }
}
 
Example 15
Source File: EdgeProcessor.java    From bjoern with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void processRow(String[] row)
{
	if (row.length < 3)
		return;

	String srcId = row[0];
	String dstId = row[1];
	String label = row[2];

	Graph graph = importer.getGraph();

	Vertex outVertex = lookupVertex(srcId, graph);
	Vertex inVertex = lookupVertex(dstId, graph);

	if (outVertex == null)
	{
		logger.info("Cannot resolve source node {} for {} -> {}", srcId,
				srcId, dstId);
		return;
	}

	if (inVertex == null)
	{
		logger.info("Cannot resolve destination node {} for {} -> {}",
				dstId, srcId, dstId);
		return;
	}

	Edge edge = graph.addEdge(0, outVertex, inVertex, label);

	for (int i = 3; i < row.length; i++)
	{
		edge.setProperty(importer.getEdgeKeys()[i], row[i]);
	}
}
 
Example 16
Source File: VersionedGraphTestSuite.java    From antiquity with GNU General Public License v3.0 4 votes vote down vote up
/**
 * The test ensures that added vertices and edges are retrieved via
 * {@link ActiveVersionedGraph#getVertices()} and
 * {@link ActiveVersionedGraph#getEdges()}
 */
@Test
public void testGetVerticesAndEdges() {
    // -- active assertions
    int vnum = toList(graph.getVertices()).size();
    int eNum = toList(graph.getEdges()).size();

    int hvNum = toList(graph.getHistoricGraph().getVertices()).size();
    int heNum = toList(graph.getHistoricGraph().getEdges()).size();
    Vertex v1 = graph.addVertex(null);
    CIT();
    v1.setProperty("name", "hello");
    CIT();
    Vertex v2 = graph.addVertex(null);
    CIT();
    v2.setProperty("name", "world");
    assertThat(graph.getVertices(), hasAmount(vnum + 2));
    CIT();
    assertThat(graph.getVertices(), hasAmount(vnum + 2));
    assertThat(graph.getVertices("name", "hello"), hasAmount(1));
    assertThat(graph.getVertices("name", "world"), hasAmount(1));


    // edges
    Edge e1 = graph.addEdge(null, v1, v2, "LINK1");
    CIT();
    e1.setProperty("name", "link1");
    CIT();
    Edge e2 = graph.addEdge(null, v1, v2, "LINK2");
    CIT();
    e2.setProperty("name", "link2");
    assertThat(graph.getEdges(), hasAmount(eNum + 2));
    CIT();
    assertThat(graph.getEdges(), hasAmount(eNum + 2));
    assertThat(graph.getEdges("name", "link1"), hasAmount(1));
    assertThat(graph.getEdges("name", "link2"), hasAmount(1));

    // -- historic assertions
    assertThat(graph.getHistoricGraph().getVertices(), hasAmount(hvNum + 4));
    assertThat(graph.getHistoricGraph().getEdges(), hasAmount(heNum + 2));
    // TODO: more advances tests
}
 
Example 17
Source File: VersionedGraphTestSuite.java    From antiquity with GNU General Public License v3.0 4 votes vote down vote up
@Test
public void simpleSingleEdgeAddTest() {
    // -- active assertions
    int aAmount = toList(graph.getEdges()).size();
    Vertex v1 = graph.addVertex(null);
    Vertex v2 = graph.addVertex(null);
    Edge e = graph.addEdge(null, v1, v2, "LINK");
    String eId = (String)e.getId();
    CIT();
    V edgeVer = last();
    e.setProperty("key", "foo");
    CIT();
    //hack
    if (graph.getBaseGraph() instanceof Neo4j2Graph) {
        ((Neo4j2Graph)graph.getBaseGraph()).autoStartTransaction(true);
    }
    e = graph.getEdge(eId);
    // query for active before transaction is committed
    assertThat(e, instanceOf(ActiveVersionedEdge.class));
    assertThat(graph.getEdges(), hasAmount(aAmount + 1));

    Edge aE1L = graph.getEdge(e.getId());
    assertThat(aE1L, notNullValue());
    assertThat(aE1L, instanceOf(ActiveVersionedEdge.class));
    assertThat((String) aE1L.getProperty("key"), is("foo"));
    assertThat(e.getProperty("key"), is(graph.getEdge(aE1L.getId()).getProperty("key")));;
    CIT();
    // expect edge to reach its vertices
    assertThat(aE1L.getVertex(Direction.OUT).getId(), is(v1.getId()));
    assertThat(aE1L.getVertex(Direction.IN).getId(), is(v2.getId()));


    // TODO: Assert after commit the elements look just like as before
    // commit
    // expect same behavior after commit too
    assertThat(graph.getEdges(), hasAmount(aAmount + 1));

    // -- historic assertions
    // query historic after transaction committed
    HistoricVersionedEdge<V> hE1L = (HistoricVersionedEdge<V>) graph.getHistoricGraph().getEdge(e.getId());
    assertThat(hE1L, notNullValue());
    assertThat(hE1L, instanceOf(HistoricVersionedEdge.class));
    assertThat((String) hE1L.getProperty("key"), is("foo"));
    assertThat(graph.utils.getVersionRange(hE1L), is(Range.range(edgeVer, graph.getMaxPossibleGraphVersion())));
    assertThat(hE1L.getVersion(), is(Range.range(edgeVer, edgeVer)));
    // not the same instance but ids shell be equal
    assertThat(aE1L.getId(), is(hE1L.getId()));
    // expect edge to reach its vertices
    assertThat(hE1L.getVertex(Direction.OUT).getId(), is(v1.getId()));
    assertThat(hE1L.getVertex(Direction.IN).getId(), is(v2.getId()));
}
 
Example 18
Source File: CFGScanDroid.java    From CFGScanDroid with GNU General Public License v2.0 4 votes vote down vote up
public static Graph buildGraph() {
	TinkerGraph graph = new TinkerGraph("/tmp/cfggraph", TinkerGraph.FileType.GRAPHML); 
	graph.createIndex("signatureName", Vertex.class);
	graph.createIndex("sha256", Vertex.class);
	graph.createIndex("md5", Vertex.class);
	graph.createIndex("type", Vertex.class);

	Map sigLookup = new HashMap<String, Vertex>();
	Map fileLookup = new HashMap<String, Vertex>();
	
	for(Match match : matches) {
		// check map for sig
		CFGSig matchSig = match.getSignature();
		String sigString = matchSig.getStringSignature();
		Vertex sigVertex = (Vertex)sigLookup.get(sigString);

		if(sigVertex == null) {
			// create vertex
			sigVertex = graph.addVertex(null);
			sigVertex.setProperty("type", "signature");
			sigVertex.setProperty("signature", sigString);
			sigVertex.setProperty("signatureName", matchSig.getName());
			// add sig to map
			sigLookup.put(sigString, sigVertex);
		}

		// check map for file
		String fileSHA256 = match.getFileSHA256();
		Vertex fileVertex = (Vertex)fileLookup.get(fileSHA256);

		if(fileVertex == null) {
			// create vertex
			fileVertex = graph.addVertex(null);
			sigVertex.setProperty("type", "file");
			fileVertex.setProperty("sha256", fileSHA256);
			fileVertex.setProperty("md5", match.getFileMD5());
			fileVertex.setProperty("fileNameList", new ArrayList<String>());
			// add file to map
			fileLookup.put(fileSHA256, fileVertex);
		}

		// what idiot would scan the same file multiple times with different names?
		List<String> fileNames = fileVertex.getProperty("fileNameList");
		if(!fileNames.contains(match.getFileName())) {
			fileNames.add(match.getFileName());
		}

		// TODO: comment this out and see if it still works
		fileVertex.setProperty("fileNameList", fileNames);

		// create edge(sig, file)
		Edge matchEdge = graph.addEdge(null, sigVertex, fileVertex, "matches");

		ControlFlowGraph cfg = match.getControlFlowGraph();
		matchEdge.setProperty("method", cfg.getIdentifier(false));
		// matchEdge.setProperty("fileBytes", cfg.getMethodBytesAsHexString());
	}

	return graph;
}
 
Example 19
Source File: ActiveVersionedGraph.java    From antiquity with GNU General Public License v3.0 3 votes vote down vote up
/**
 * Add an active edge to the underline.
 * 
 * @param id specify explicit id, if null id will be generated, id may be
 *        ignored if underline ignores supplied ids.
 * @param out the out vertex of the edge.
 * @param in the in vrtex of the edge.
 * @param label the label of the edge.
 * @return the created active edge.
 */
private ActiveVersionedEdge addActiveEdgeInUnderline(Object id, ActiveVersionedVertex<V> out,
        ActiveVersionedVertex<V> in, String label) {
    Edge edge = addPlainEdgeToGraph(id, out.getRaw(), in.getRaw(), label);
    edge.setProperty(VEProps.HISTORIC_ELEMENT_PROP_KEY, false);

    return new ActiveVersionedEdge<V>(edge, this);
}
 
Example 20
Source File: GraphHelper.java    From org.openntf.domino with Apache License 2.0 3 votes vote down vote up
/**
 * Add an edge to the graph with specified id and provided properties.
 *
 * @param graph      the graph to create the edge in
 * @param id         the id of the edge to create
 * @param outVertex  the outgoing/tail vertex of the edge
 * @param inVertex   the incoming/head vertex of the edge
 * @param label      the label of the edge
 * @param properties the properties of the edge to add (must be String,Object,String,Object,...)
 * @return the edge created in the graph with the provided properties set
 */
public static Edge addEdge(final Graph graph, final Object id, final Vertex outVertex, final Vertex inVertex, final String label, final Object... properties) {
    if ((properties.length % 2) != 0)
        throw new RuntimeException("There must be an equal number of keys and values");
    final Edge edge = graph.addEdge(id, outVertex, inVertex, label);
    for (int i = 0; i < properties.length; i = i + 2) {
        edge.setProperty((String) properties[i], properties[i + 1]);
    }
    return edge;
}