public VertexPositionEntity(VertexRefEntity vertexRefEntity, PointEntity pointEntity) { setPosition(pointEntity); setVertexRef(vertexRefEntity); }
public LayoutEntity loadLayout(Graph graph) { LayoutEntity layoutEntity = findBy(graph); if (layoutEntity != null) { layoutEntity.setLastUsed(new Date()); layoutDao.saveOrUpdate(layoutEntity); } return layoutEntity; }
public PointEntity getPosition(String namespace, String id) { Objects.requireNonNull(namespace); Objects.requireNonNull(id); Optional<VertexPositionEntity> first = vertexPositions.stream() .filter(e -> e.getVertexRef().getNamespace().equals(namespace) && e.getVertexRef().getId().equals(id)) .findFirst(); if (first.isPresent()) { VertexPositionEntity vertexPositionEntity = first.get(); return vertexPositionEntity.getPosition(); } return null; }
public void persistLayout(GraphContainer graphContainer) { final List<VertexRef> vertexRefs = toVertexRef(graphContainer.getGraph().getDisplayVertices()); final String id = calculateHash(vertexRefs); LayoutEntity layoutEntity = layoutDao.get(id); if (layoutEntity == null) { layoutEntity = new LayoutEntity(); layoutEntity.setId(id); layoutEntity.setCreated(new Date()); layoutEntity.setCreator(graphContainer.getApplicationContext().getUsername()); layoutEntity.setUpdated(new Date()); layoutEntity.setUpdator(graphContainer.getApplicationContext().getUsername()); .map(vertexRef -> { final Point p = layout.getLocation(vertexRef); PointEntity pointEntity = new PointEntity(); pointEntity.setX((int) p.getX()); pointEntity.setY((int) p.getY()); final VertexPositionEntity vertexEntity = new VertexPositionEntity(); vertexEntity.setVertexRef(toVertexRefEntity(vertexRef)); vertexEntity.setPosition(pointEntity); return vertexEntity; }) .collect(Collectors.toList()); layoutEntity.getVertexPositions().clear(); for (VertexPositionEntity eachVertexPosition : vertexPositionEntities) { layoutEntity.addVertexPosition(eachVertexPosition); layoutDao.saveOrUpdate(layoutEntity);
public boolean isPersistedLayoutEqualToCurrentLayout(Graph graph) { LayoutEntity layoutEntity = loadLayout(graph); if (layoutEntity != null) { // If we have a layout persisted, we verify if it is equal. final Map<VertexRef, Point> persistedLocations = layoutEntity.getVertexPositions() .stream() .collect(Collectors.toMap((Function<VertexPositionEntity, VertexRef>) vertexPositionEntity -> { VertexRefEntity vertexRefEntity = vertexPositionEntity.getVertexRef(); return new DefaultVertexRef(vertexRefEntity.getNamespace(), vertexRefEntity.getId()); }, vertexPositionEntity -> { PointEntity position = vertexPositionEntity.getPosition(); return new Point(position.getX(), position.getY()); })); // The locations may contain elements currently not visible, we filter them final Map<VertexRef, Point> manualLocations = new HashMap<>(); graph.getLayout().getLocations().forEach((key, value) -> { if (persistedLocations.containsKey(key)) { // layoutEntity stores int coordinates, but manualLocations are stored as double. // Convert to int to make it comparable. manualLocations.put(key, new Point((int) value.getX(), (int) value.getY())); } }); final boolean layoutIsEqual = manualLocations.equals(persistedLocations); return layoutIsEqual; } return false; // We don't have anything persisted, so they are not equal } }
public static VertexRefEntity toVertexRefEntity(VertexRef vertexRef) { Objects.requireNonNull(vertexRef); VertexRefEntity vertexRefEntity = new VertexRefEntity(); vertexRefEntity.setId(vertexRef.getId()); vertexRefEntity.setNamespace(vertexRef.getNamespace()); return vertexRefEntity; }
final Collection<Vertex> vertices = graph.getDisplayVertices(); for (Vertex vertex : vertices) { PointEntity pointEntity = layoutEntity.getPosition(vertex.getNamespace(), vertex.getId()); layout.setLocation(vertex, new Point(pointEntity.getX(), pointEntity.getY()));
public void addVertexPosition(VertexPositionEntity position) { Objects.requireNonNull(position); getVertexPositions().add(position); }
private LayoutEntity findBy(Graph graph) { List<VertexRef> vertexRefs = toVertexRef(graph.getDisplayVertices()); String id = calculateHash(vertexRefs); return layoutDao.get(id); }
public void persistLayout(GraphContainer graphContainer) { final List<VertexRef> vertexRefs = toVertexRef(graphContainer.getGraph().getDisplayVertices()); final String id = calculateHash(vertexRefs); LayoutEntity layoutEntity = layoutDao.get(id); if (layoutEntity == null) { layoutEntity = new LayoutEntity(); layoutEntity.setId(id); layoutEntity.setCreated(new Date()); layoutEntity.setCreator(graphContainer.getApplicationContext().getUsername()); layoutEntity.setUpdated(new Date()); layoutEntity.setUpdator(graphContainer.getApplicationContext().getUsername()); .map(vertexRef -> { final Point p = layout.getLocation(vertexRef); PointEntity pointEntity = new PointEntity(); pointEntity.setX((int) p.getX()); pointEntity.setY((int) p.getY()); final VertexPositionEntity vertexEntity = new VertexPositionEntity(); vertexEntity.setVertexRef(toVertexRefEntity(vertexRef)); vertexEntity.setPosition(pointEntity); return vertexEntity; }) .collect(Collectors.toList()); layoutEntity.getVertexPositions().clear(); for (VertexPositionEntity eachVertexPosition : vertexPositionEntities) { layoutEntity.addVertexPosition(eachVertexPosition); layoutDao.saveOrUpdate(layoutEntity);
public boolean isPersistedLayoutEqualToCurrentLayout(Graph graph) { LayoutEntity layoutEntity = loadLayout(graph); if (layoutEntity != null) { // If we have a layout persisted, we verify if it is equal. final Map<VertexRef, Point> persistedLocations = layoutEntity.getVertexPositions() .stream() .collect(Collectors.toMap((Function<VertexPositionEntity, VertexRef>) vertexPositionEntity -> { VertexRefEntity vertexRefEntity = vertexPositionEntity.getVertexRef(); return new DefaultVertexRef(vertexRefEntity.getNamespace(), vertexRefEntity.getId()); }, vertexPositionEntity -> { PointEntity position = vertexPositionEntity.getPosition(); return new Point(position.getX(), position.getY()); })); // The locations may contain elements currently not visible, we filter them final Map<VertexRef, Point> manualLocations = new HashMap<>(); graph.getLayout().getLocations().forEach((key, value) -> { if (persistedLocations.containsKey(key)) { // layoutEntity stores int coordinates, but manualLocations are stored as double. // Convert to int to make it comparable. manualLocations.put(key, new Point((int) value.getX(), (int) value.getY())); } }); final boolean layoutIsEqual = manualLocations.equals(persistedLocations); return layoutIsEqual; } return false; // We don't have anything persisted, so they are not equal } }
public PointEntity getPosition(String namespace, String id) { Objects.requireNonNull(namespace); Objects.requireNonNull(id); Optional<VertexPositionEntity> first = vertexPositions.stream() .filter(e -> e.getVertexRef().getNamespace().equals(namespace) && e.getVertexRef().getId().equals(id)) .findFirst(); if (first.isPresent()) { VertexPositionEntity vertexPositionEntity = first.get(); return vertexPositionEntity.getPosition(); } return null; }
public VertexPositionEntity(VertexRefEntity vertexRefEntity, PointEntity pointEntity) { setPosition(pointEntity); setVertexRef(vertexRefEntity); }
public static VertexRefEntity toVertexRefEntity(VertexRef vertexRef) { Objects.requireNonNull(vertexRef); VertexRefEntity vertexRefEntity = new VertexRefEntity(); vertexRefEntity.setId(vertexRef.getId()); vertexRefEntity.setNamespace(vertexRef.getNamespace()); return vertexRefEntity; }
final Collection<Vertex> vertices = graph.getDisplayVertices(); for (Vertex vertex : vertices) { PointEntity pointEntity = layoutEntity.getPosition(vertex.getNamespace(), vertex.getId()); layout.setLocation(vertex, new Point(pointEntity.getX(), pointEntity.getY()));
public LayoutEntity loadLayout(Graph graph) { LayoutEntity layoutEntity = findBy(graph); if (layoutEntity != null) { layoutEntity.setLastUsed(new Date()); layoutDao.saveOrUpdate(layoutEntity); } return layoutEntity; }
public void addVertexPosition(VertexPositionEntity position) { Objects.requireNonNull(position); getVertexPositions().add(position); }
private LayoutEntity findBy(Graph graph) { List<VertexRef> vertexRefs = toVertexRef(graph.getDisplayVertices()); String id = calculateHash(vertexRefs); return layoutDao.get(id); }