Java Code Examples for com.tinkerpop.blueprints.Edge.getProperty()

The following are Jave code examples for showing how to use getProperty() of the com.tinkerpop.blueprints.Edge class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: mesh   File: RemoveBogusWebrootProperty.java   Source Code and License Vote up 6 votes
private void migrateContainer(Vertex container) {

		boolean isPublished = false;
		Iterable<Edge> edges = container.getEdges(Direction.IN, "HAS_FIELD_CONTAINER");

		// Check whether the container is published
		for (Edge edge : edges) {
			String type = edge.getProperty("edgeType");
			if ("P".equals(type)) {
				isPublished = true;
			}
		}

		// The container is not published anywhere. Remove the bogus publish webroot info which otherwise causes publish webroot conflicts with new versions.
		if (!isPublished) {
			if (container.getProperty(WEBROOT_PUB) != null) {
				log.info("Found inconsistency on container {" + container.getProperty("uuid") + "}");
				container.removeProperty(WEBROOT_PUB);
				log.info("Inconsistency fixed");
			}
		}
	}
 
Example 2
Project: jarvisCli   File: OSQLFunctionDijkstraWithWeightMax.java   Source Code and License Vote up 6 votes
protected float getDistance(final OrientVertex node, final OrientVertex target) {
  final Iterator<Edge> edges = node.getEdges(target, paramDirection).iterator();
  if (edges.hasNext()) {
    final Edge e = edges.next();
    if (e != null && e.getLabel().equals("Frameshift") 
            && e.getProperty(paramWeightFieldName) != null 
            && ((double)e.getProperty(paramWeightFieldName) <=  paramWeightLimit)) {
 
      final Object fieldValue = e.getProperty(paramWeightFieldName);
      if (fieldValue != null) {
        if (fieldValue instanceof Float) {
          return (Float) fieldValue;
        } else if (fieldValue instanceof Number) {
          return ((Number) fieldValue).floatValue();
        }
      }
    }
    return Float.MAX_VALUE;
  }
  return Float.MAX_VALUE;
}
 
Example 3
Project: jarvisCli   File: StationService.java   Source Code and License Vote up 6 votes
public Map<String, Commodity> getStationBuyCommodities(Vertex stationVertex, Ship ship) {
    Map<String, Commodity> stationBuyCommodities = new HashMap<>();
    for (Edge exchange: stationVertex.getEdges(Direction.OUT, "Exchange")) {            

        int sellPrice = exchange.getProperty("sellPrice");
        int buyPrice = exchange.getProperty("buyPrice");
        int supply = exchange.getProperty("supply");
        int demand = exchange.getProperty("demand");
                   
        if (buyPrice > 0 && supply >= ship.getCargoSpace() && (buyPrice * ship.getCargoSpace()) <= ship.getCash()) {
            Vertex commodityVertex = exchange.getVertex(Direction.IN);
            Commodity commodity = new Commodity(commodityVertex.getProperty("name"), buyPrice, supply, sellPrice, demand);
            commodity.setGroup(commodityService.getCommodityGroup(commodity.getName()));
            stationBuyCommodities.put(commodity.getName(), commodity);
        }
    }
    return stationBuyCommodities;
}
 
Example 4
Project: jarvisCli   File: StationService.java   Source Code and License Vote up 6 votes
public Map<String, Commodity> getReleventStationSellCommodities(Vertex stationVertex, Map<String, Commodity> buyCommodities, Ship ship) {
    Map<String, Commodity> stationSellReleventCommodities = new HashMap<>();
    for (Edge exchange: stationVertex.getEdges(Direction.OUT, "Exchange")) {            

        int sellPrice = exchange.getProperty("sellPrice");
        int buyPrice = exchange.getProperty("buyPrice");
        int supply = exchange.getProperty("supply");
        int demand = exchange.getProperty("demand");
        
        if (demand > ship.getCargoSpace() && sellPrice > 0) {
            Vertex commodityVertex = exchange.getVertex(Direction.IN);
            Commodity sellCommodity = new Commodity(commodityVertex.getProperty("name"), buyPrice, supply, sellPrice, demand);
            sellCommodity.setGroup(commodityService.getCommodityGroup(sellCommodity.getName()));
            Commodity boughtCommodity = buyCommodities.get(sellCommodity.getName());
            
            if (boughtCommodity != null && boughtCommodity.getBuyPrice() < sellCommodity.getSellPrice()) {
                stationSellReleventCommodities.put(sellCommodity.getName(), sellCommodity);
            }
        }
    }
    
    return stationSellReleventCommodities;
}
 
Example 5
Project: jarvisCli   File: StationService.java   Source Code and License Vote up 6 votes
public List<Commodity> getStationCommodities(Vertex stationVertex) {
    
    List<Commodity> stationCommodities = new ArrayList<>();
    
    for (Edge exchange: stationVertex.getEdges(Direction.OUT, "Exchange")) {            

        int sellPrice = exchange.getProperty("sellPrice");
        int buyPrice = exchange.getProperty("buyPrice");
        int supply = exchange.getProperty("supply");
        int demand = exchange.getProperty("demand");
        long date = exchange.getProperty("date");
        
        if ( (demand > 0 && sellPrice > 0) || (supply > 0 && buyPrice > 0)) {
            Vertex commodityVertex = exchange.getVertex(Direction.IN);
            Commodity commodity = new Commodity(commodityVertex.getProperty("name"), buyPrice, supply, sellPrice, demand, date);
            commodity.setGroup(commodityService.getCommodityGroup(commodity.getName()));
            stationCommodities.add(commodity);
        }
    }
    
    return stationCommodities;
}
 
Example 6
Project: mesh   File: NodeImpl.java   Source Code and License Vote up 5 votes
@Override
public TransformablePage<? extends Node> getChildren(InternalActionContext ac, List<String> languageTags, String releaseUuid, ContainerType type,
		PagingParameters pagingInfo) {
	String indexName = "e." + HAS_PARENT_NODE.toLowerCase() + "_release";
	Object indexKey = DB.get().createComposedIndexKey(getId(), releaseUuid);

	GraphPermission perm = type == PUBLISHED ? READ_PUBLISHED_PERM : READ_PERM;
	return new DynamicTransformablePageImpl<NodeImpl>(ac.getUser(), indexName, indexKey, NodeImpl.class, pagingInfo, perm, (item) -> {

		// Filter out nodes which do not provide one of the specified language tags and type
		if (languageTags != null) {
			Iterator<Edge> edgeIt = item.getEdges(OUT, HAS_FIELD_CONTAINER).iterator();
			while (edgeIt.hasNext()) {
				Edge edge = edgeIt.next();
				String currentType = edge.getProperty(GraphFieldContainerEdgeImpl.EDGE_TYPE_KEY);
				if (!type.getCode().equals(currentType)) {
					continue;
				}
				String languageTag = edge.getProperty(GraphFieldContainerEdgeImpl.LANGUAGE_TAG_KEY);
				if (languageTags.contains(languageTag)) {
					return true;
				}
			}
			return false;
		}
		return true;
	}, true);
}
 
Example 7
Project: explicit-semantic-analysis   File: Brainstormer.java   Source Code and License Vote up 5 votes
void writeNeatoEdges(StringBuilder buf){
    for(Edge e : g.getEdges()){
        if(RELATED_EDGE.equals(e.getLabel())){
            String from = e.getVertex(Direction.OUT).getId().toString();
            String to = e.getVertex(Direction.IN).getId().toString();
            float score = e.getProperty(Brainstormer.SCORE_PROPERTY);
            buf.append(from).append(" -- ").append(to).append(" [label=\"").append(score).append("\"];").append('\n');
        }
    }
}
 
Example 8
Project: jarvisCli   File: StarSystemService.java   Source Code and License Vote up 5 votes
public Set<Vertex> findSystemsWithinOneFrameshiftJumpOfDistance(Vertex system, float jumpDistance) {

        Set<Vertex> systemsWithinOneJumpOfDistance = new HashSet<>();

        for (Edge edgeFrameshift : system.getEdges(com.tinkerpop.blueprints.Direction.BOTH, "Frameshift")) {
            double ly = edgeFrameshift.getProperty("ly");
            if (ly > jumpDistance) {
                // ignore any shift that is out of range
                continue;
            }

            // because we cant tell what direction the edge is from
            // system--shift--system, just try both.
            Vertex destinationSystem = null;
            destinationSystem = edgeFrameshift.getVertex(com.tinkerpop.blueprints.Direction.IN);
            if (destinationSystem == null || destinationSystem.getProperty("name").equals(system.getProperty("name"))) {
                destinationSystem = edgeFrameshift.getVertex(com.tinkerpop.blueprints.Direction.OUT);
            }

            if (destinationSystem == null) {
                continue;
            }

            systemsWithinOneJumpOfDistance.add(destinationSystem);
        }

        return systemsWithinOneJumpOfDistance;
    }
 
Example 9
Project: titan0.5.4-hbase1.1.1-custom   File: TitanOutputFormatTest.java   Source Code and License Vote up 5 votes
@Test
public void testBulkEdgePropertyUpdates() throws Exception {
    bulkLoadGraphOfTheGods(f1);
    new HadoopPipeline(f2).E().has("label", "battled").sideEffect("{it.time = it.time+1}").submit();

    clopen();

    assertEquals(12, new GremlinPipeline(g).V().count());
    assertEquals(17, new GremlinPipeline(g).E().count());

    int counter = 0;
    for (Edge edge : g.getEdges()) {
        if (edge.getLabel().equals("battled")) {
            assertEquals(edge.getPropertyKeys().size(), 1);
            int time = edge.getProperty("time");
            assertTrue(time == 2 || time == 3 || time == 13);
            counter++;
        } else {
            assertEquals(edge.getPropertyKeys().size(), 0);
        }
    }
    assertEquals(counter, 3);
    assertEquals(3, new GremlinPipeline(g).V("name", "hercules").outE("battled").count());
    assertEquals(1, new GremlinPipeline(g).V("name", "hercules").outE("father").count());
    assertEquals(1, new GremlinPipeline(g).V("name", "hercules").outE("mother").count());
    assertEquals(3, new GremlinPipeline(g).V("name", "hercules").out("battled").count());
    assertEquals(1, new GremlinPipeline(g).V("name", "hercules").out("father").count());
    assertEquals(1, new GremlinPipeline(g).V("name", "hercules").out("mother").count());
    assertEquals(5, new GremlinPipeline(g).V("name", "hercules").out().count());
}
 
Example 10
Project: poi-visio-graph   File: VisioPageParser.java   Source Code and License Vote up 5 votes
protected void doAssociateTextboxWithShape(ShapeData textBox, ShapeData other) {
	other.vertex.setProperty("label", textBox.vertex.getProperty("label"));
	other.vertex.setProperty("textRef", textBox.shapeId);
	other.vertex.setProperty("textRefWhy", "associateWithShape");
	other.hasText = true;
	other.textCenter = textBox.textCenter;
	
	// move any edges from the textbox to us
	for (Edge edge: textBox.vertex.getEdges(Direction.BOTH)) {
		
		ShapeData in = getShapeFromEdge(edge, Direction.IN);
		ShapeData out = getShapeFromEdge(edge, Direction.OUT);
		
		if (in != other && out != other) {
			
			Double x = edge.getProperty("x");
			Double y = edge.getProperty("y");
			
			if (in == textBox)
				createEdge(out, other, "reparent", x, y);
			else if (out == textBox)
				createEdge(in, other, "reparent", x, y);
			else
				throw new POIXMLException("Internal error");
		}
		
		graph.removeEdge(edge);
	}
	
	helper.onAssignText(textBox, other);
	
	// remove the textbox from the tree so others can't use it
	removeShape(textBox);
}
 
Example 11
Project: jarvisCli   File: TradeService.java   Source Code and License Vote up 4 votes
public String sellOrientDb(Station fromStation, Ship ship, int maxJumps, String commodity) {
    Date start = new Date();
    List<Map<String, Object>> tableData = new ArrayList<>();
    OrientGraph graph = null;
    try {
        graph = orientDbService.getFactory().getTx();
        
        Vertex stationVertex = graph.getVertexByKey("Station.name", fromStation.getName());
        Vertex systemVertex = stationService.getSystemVertexForStationVertex(stationVertex);
        
        Set<Vertex> systemsWithinNShipJumps = starSystemService.findSystemsWithinNFrameshiftJumpsOfDistance(graph, systemVertex, ship.getJumpDistance(), maxJumps);
        systemsWithinNShipJumps.add(systemVertex);
        
        for (Vertex destinationSystem: systemsWithinNShipJumps) {
            Set<Vertex> systemStations = starSystemService.findStationsInSystemOrientDb(destinationSystem, null);
            for (Vertex station: systemStations) {
                for (Edge exchange: station.getEdges(Direction.OUT, "Exchange")) {            

                    int sellPrice = exchange.getProperty("sellPrice");
                    int buyPrice = exchange.getProperty("buyPrice");
                    int supply = exchange.getProperty("supply");
                    int demand = exchange.getProperty("demand");
                    long date = exchange.getProperty("date");
                    
                    if (demand > ship.getCargoSpace() && sellPrice > 0) {
                        Vertex commodityVertex = exchange.getVertex(Direction.IN);
                        if (commodityVertex.getProperty("name").equals(commodity)) {
                            Commodity sellCommodity = new Commodity(commodityVertex.getProperty("name"), buyPrice, supply, sellPrice, demand);
                            Map<String, Object> row = new HashMap<>();
                            row.put("COMMODITY", sellCommodity.getName());
                            row.put("TO SYSTEM", destinationSystem.getProperty("name"));
                            row.put("TO STATION", station.getProperty("name"));
                            row.put("UNIT PRICE", sellPrice);
                            row.put("DEMAND", demand);
                            row.put("DAYS OLD", (((new Date().getTime() - date)/1000/60/60/24) * 100)/100);
                            tableData.add(row);
                        }
                    }
                }
                
            }
        }           
        graph.commit();
    } catch(Exception e) {
        if (graph != null) {
            graph.rollback();
        }
    }
        
    if (tableData.size() == 0) {
        return "No sale available in provided range";
    }
    
    tableData = tableData.parallelStream().sorted((row1,row2)->{
        int p1 = (int) row1.get("UNIT PRICE");
        int p2 = (int) row2.get("UNIT PRICE");
        return Integer.compare(p1, p2);
    }).collect(Collectors.toList());
    
    Collections.reverse(tableData);
    
    String out = OsUtils.LINE_SEPARATOR;
    out += "From System: " + fromStation.getSystem() + OsUtils.LINE_SEPARATOR;
    out += "From Station: " + fromStation.getName() + OsUtils.LINE_SEPARATOR;
    out += "Cargo Capacity: " + ship.getCargoSpace() + OsUtils.LINE_SEPARATOR;
    out += tableData.size() + " Best stations to sell " + tableData.get(0).get("COMMODITY") + " within " + maxJumps + " jump(s) @ " + ship.getJumpDistance() + " ly or less." + OsUtils.LINE_SEPARATOR;
    out += OsUtils.LINE_SEPARATOR + TableRenderer.renderMapDataAsTable(tableData, 
            ImmutableList.of("TO SYSTEM", "TO STATION", "UNIT PRICE", "DEMAND",  "DAYS OLD"));
    
    out += OsUtils.LINE_SEPARATOR + "executed in " + (new Date().getTime() - start.getTime())/1000.0 + " seconds.";
    return out;
}
 
Example 12
Project: jarvisCli   File: TradeService.java   Source Code and License Vote up 4 votes
public String buyOrientDb(Station fromStation, Ship ship, int maxJumps, String commodity) {
    Date start = new Date();
    List<Map<String, Object>> tableData = new ArrayList<>();
    OrientGraph graph = null;
    try {
        graph = orientDbService.getFactory().getTx();
        
        Vertex stationVertex = graph.getVertexByKey("Station.name", fromStation.getName());
        Vertex systemVertex = stationService.getSystemVertexForStationVertex(stationVertex);
        
        Set<Vertex> systemsWithinNShipJumps = starSystemService.findSystemsWithinNFrameshiftJumpsOfDistance(graph, systemVertex, ship.getJumpDistance(), maxJumps);
        systemsWithinNShipJumps.add(systemVertex);
        
        for (Vertex destinationSystem: systemsWithinNShipJumps) {
            Set<Vertex> systemStations = starSystemService.findStationsInSystemOrientDb(destinationSystem, null);
            for (Vertex station: systemStations) {
                for (Edge exchange: station.getEdges(Direction.OUT, "Exchange")) {            

                    int sellPrice = exchange.getProperty("sellPrice");
                    int buyPrice = exchange.getProperty("buyPrice");
                    int supply = exchange.getProperty("supply");
                    int demand = exchange.getProperty("demand");
                    long date = exchange.getProperty("date");
                    
                    if (supply > ship.getCargoSpace() && buyPrice > 0) {
                        Vertex commodityVertex = exchange.getVertex(Direction.IN);
                        if (commodityVertex.getProperty("name").equals(commodity)) {
                            Commodity buyCommodity = new Commodity(commodityVertex.getProperty("name"), buyPrice, supply, sellPrice, demand);
                            Map<String, Object> row = new HashMap<>();
                            row.put("COMMODITY", buyCommodity.getName());
                            row.put("TO SYSTEM", destinationSystem.getProperty("name"));
                            row.put("TO STATION", station.getProperty("name"));
                            row.put("UNIT PRICE", buyPrice);
                            row.put("SUPPLY", supply);
                            row.put("DAYS OLD", (((new Date().getTime() - date)/1000/60/60/24) * 100)/100);
                            tableData.add(row);
                        }
                    }
                }
                
            }
        }           
        graph.commit();
    } catch(Exception e) {
        if (graph != null) {
            graph.rollback();
        }
    }
        
    if (tableData.size() == 0) {
        return "No purchase available in provided range";
    }
    
    tableData = tableData.parallelStream().sorted((row1,row2)->{
        int p1 = (int) row1.get("UNIT PRICE");
        int p2 = (int) row2.get("UNIT PRICE");
        return Integer.compare(p1, p2);
    }).collect(Collectors.toList());
    
    String out = OsUtils.LINE_SEPARATOR;
    out += "From System: " + fromStation.getSystem() + OsUtils.LINE_SEPARATOR;
    out += "From Station: " + fromStation.getName() + OsUtils.LINE_SEPARATOR;
    out += "Cargo Capacity: " + ship.getCargoSpace() + OsUtils.LINE_SEPARATOR;
    out += tableData.size() + " Best stations to buy " + tableData.get(0).get("COMMODITY") + " within " + maxJumps + " jump(s) @ " + ship.getJumpDistance() + " ly or less." + OsUtils.LINE_SEPARATOR;
    out += OsUtils.LINE_SEPARATOR + TableRenderer.renderMapDataAsTable(tableData, 
            ImmutableList.of("TO SYSTEM", "TO STATION", "UNIT PRICE", "SUPPLY", "DAYS OLD"));
    
    out += OsUtils.LINE_SEPARATOR + "executed in " + (new Date().getTime() - start.getTime())/1000.0 + " seconds.";
    return out;
}
 
Example 13
Project: jarvisCli   File: TradeService.java   Source Code and License Vote up 4 votes
public String bestBuyPriceOrientDb(String commodityName) {
    Date start = new Date();
    
    List<Map<String, Object>> tableData = new ArrayList<>();
    
    OrientGraph graph = null;
    try {
        graph = orientDbService.getFactory().getTx();
        //starting commodity
        OrientVertex commodityVertex = (OrientVertex) graph.getVertexByKey("Commodity.name", commodityName);
        
        for (Edge hasExchange: commodityVertex.getEdges(Direction.IN, "Exchange")) {
            
            int supply = hasExchange.getProperty("supply");
            int buyPrice = hasExchange.getProperty("buyPrice");
            long date = hasExchange.getProperty("date");
            if (supply > 0 && buyPrice > 0) {
                Vertex stationVertex = hasExchange.getVertex(Direction.OUT);
                Vertex systemVertex = stationService.getSystemVertexForStationVertex(stationVertex);
                Map<String, Object> row = new HashMap<>();
                row.put("TO SYSTEM", systemVertex.getProperty("name"));
                row.put("TO STATION", stationVertex.getProperty("name"));
                row.put("UNIT PRICE", buyPrice);
                row.put("SUPPLY", supply);
                row.put("DAYS OLD", (((new Date().getTime() - date)/1000/60/60/24) * 100)/100);
                tableData.add(row);
            }
        }
        graph.commit();
    } catch (Exception e) {
        if (graph != null) {
            graph.rollback();
        }
    }
    
    if (tableData.size() == 0) {
        return "No sale available in data";
    }
    
    tableData = tableData.parallelStream().sorted((row1,row2)->{
        int p1 = (int) row1.get("UNIT PRICE");
        int p2 = (int) row2.get("UNIT PRICE");
        return Integer.compare(p1, p2);
    }).collect(Collectors.toList());       
    
    String out = OsUtils.LINE_SEPARATOR;
    out += tableData.size() + " Best stations to buy " + commodityName + OsUtils.LINE_SEPARATOR;
    out += OsUtils.LINE_SEPARATOR + TableRenderer.renderMapDataAsTable(tableData, 
            ImmutableList.of("TO SYSTEM", "TO STATION", "UNIT PRICE", "SUPPLY", "DAYS OLD"));
    out += OsUtils.LINE_SEPARATOR + "executed in " + (new Date().getTime() - start.getTime())/1000.0 + " seconds.";
    return out;
}
 
Example 14
Project: jarvisCli   File: TradeService.java   Source Code and License Vote up 4 votes
public String bestSellPriceOrientDb(String commodityName) {
    Date start = new Date();
    
    List<Map<String, Object>> tableData = new ArrayList<>();
    
    OrientGraph graph = null;
    try {
        graph = orientDbService.getFactory().getTx();
        //starting commodity
        OrientVertex commodityVertex = (OrientVertex) graph.getVertexByKey("Commodity.name", commodityName);
        
        for (Edge hasExchange: commodityVertex.getEdges(Direction.IN, "Exchange")) {
            
            int demand = hasExchange.getProperty("demand");
            int sellPrice = hasExchange.getProperty("sellPrice");
            long date = hasExchange.getProperty("date");
            if (demand > 0 && sellPrice > 0) {
                Vertex stationVertex = hasExchange.getVertex(Direction.OUT);
                Vertex systemVertex = stationService.getSystemVertexForStationVertex(stationVertex);
                Map<String, Object> row = new HashMap<>();
                row.put("TO SYSTEM", systemVertex.getProperty("name"));
                row.put("TO STATION", stationVertex.getProperty("name"));
                row.put("UNIT PRICE", sellPrice);
                row.put("DEMAND", demand);
                row.put("DAYS OLD", (((new Date().getTime() - date)/1000/60/60/24) * 100)/100);
                tableData.add(row);
            }
        }
        graph.commit();
    } catch (Exception e) {
        if (graph != null) {
            graph.rollback();
        }
    }
    
    if (tableData.size() == 0) {
        return "No sale available in data";
    }
    
    tableData = tableData.parallelStream().sorted((row1,row2)->{
        int p1 = (int) row1.get("UNIT PRICE");
        int p2 = (int) row2.get("UNIT PRICE");
        return Integer.compare(p1, p2);
    }).collect(Collectors.toList());
    
    Collections.reverse(tableData);
    
    
    String out = OsUtils.LINE_SEPARATOR;
    out += tableData.size() + " Best stations to sell " + commodityName + OsUtils.LINE_SEPARATOR;
    out += OsUtils.LINE_SEPARATOR + TableRenderer.renderMapDataAsTable(tableData, 
            ImmutableList.of("TO SYSTEM", "TO STATION", "UNIT PRICE", "DEMAND", "DAYS OLD"));
    out += OsUtils.LINE_SEPARATOR + "executed in " + (new Date().getTime() - start.getTime())/1000.0 + " seconds.";
    return out;
}
 
Example 15
Project: titan0.5.4-hbase1.1.1-custom   File: TitanGraphTest.java   Source Code and License Vote up 4 votes
@Test
public void testEdgeTTLImplicitKey() throws Exception {
    Duration d;

    if (!features.hasCellTTL()) {
        return;
    }

    clopen(option(GraphDatabaseConfiguration.STORE_META_TTL, "edgestore"), true);

    assertEquals("$ttl", ImplicitKey.TTL.getName());

    int ttl = 24*60*60;
    EdgeLabel likes = mgmt.makeEdgeLabel("likes").make();
    EdgeLabel hasLiked = mgmt.makeEdgeLabel("hasLiked").make();
    mgmt.setTTL(likes, ttl, TimeUnit.SECONDS);
    assertEquals(ttl, mgmt.getTTL(likes).getLength(TimeUnit.SECONDS));
    assertEquals(0, mgmt.getTTL(hasLiked).getLength(TimeUnit.SECONDS));
    mgmt.commit();

    Vertex v1 = graph.addVertex(null), v2 = graph.addVertex(null);

    Edge e1 = graph.addEdge(null, v1, v2, "likes");
    Edge e2 = graph.addEdge(null, v1, v2, "hasLiked");
    graph.commit();

    // read from the edge created in this transaction
    d = e1.getProperty("$ttl");
    assertEquals(86400, d.getLength(TimeUnit.SECONDS));

    // get the edge via a vertex
    e1 = v1.getEdges(Direction.OUT, "likes").iterator().next();
    d = e1.getProperty("$ttl");
    assertEquals(86400, d.getLength(TimeUnit.SECONDS));

    // returned value of $ttl is the total time to live since commit, not remaining time
    Thread.sleep(1001);
    graph.rollback();
    e1 = v1.getEdges(Direction.OUT, "likes").iterator().next();
    d = e1.getProperty("$ttl");
    assertEquals(86400, d.getLength(TimeUnit.SECONDS));

    // no ttl on edges of this label
    d = e2.getProperty("$ttl");
    assertEquals(0, d.getLength(TimeUnit.SECONDS));
}
 
Example 16
Project: poi-visio-graph   File: VisioPageParser.java   Source Code and License Vote up 4 votes
protected void removeConnectionsAt2Dobjects() {
	
	// this is a cleanup operation -- if there are connection points
	// for 1d objects that exist at a 2d shape that they are connected
	// to, then remove the connection
	
	for (ShapeData shape: shapes) {
		
		if (!shape.is1d())
			continue;
		
		Set<Long> collected2dObjects = null;
		
		// get the connection point from the edge properties
		for (Edge edge: shape.vertex.getEdges(Direction.BOTH)) {
			Double x = edge.getProperty("x");
			if (x == null)
				continue;
			
			Double y = edge.getProperty("y");
			
			// ok, the other end must be a 1d object. Find the object.
			// Find all 2d objects that I'm connected to, and see if the
			// other object is connected to any of them.
			
			if (collected2dObjects == null)
				collected2dObjects = collect2dObjects(shape.vertex);
			
			// if both connected to the same object, see if the x/y overlaps
			Vertex other = edge.getVertex(Direction.IN);
			if (other == shape.vertex)
				other = edge.getVertex(Direction.OUT);
			
			Set<Long> other2dObjects = collect2dObjects(other);
			
			for (Long o: other2dObjects) {
				if (collected2dObjects.contains(o)) {
					ShapeData sd = getShape(o);
					if (sd.bounds.intersects(x - 0.00001, y - 0.00001, 0.00002, 0.00002)) {
						// remove edge if it overlaps
						edge.remove();
					}
				}
			}
		}
	}
}