@Test public void shouldFindHistoryRecordsBySwitchByIdAndPortNumber() { Instant start = new Date().toInstant(); Instant end = new Date().toInstant().plus(1, ChronoUnit.DAYS); PortHistory portUp = createPortHistory(SWITCH_ID, PORT_NUMBER, "PORT_UP", start.plus(1, ChronoUnit.HOURS)); PortHistory portDown = createPortHistory(SWITCH_ID, PORT_NUMBER, "PORT_DOWN", end); createPortHistory(new SwitchId(2L), PORT_NUMBER, "TEST1", end); createPortHistory(SWITCH_ID, 3, "TEST2", end); createPortHistory(SWITCH_ID, PORT_NUMBER, "TEST3", start.minus(1, ChronoUnit.SECONDS)); createPortHistory(SWITCH_ID, PORT_NUMBER, "TEST4", end.plus(1, ChronoUnit.HOURS)); Collection<PortHistory> portHistory = repository.findBySwitchIdAndPortNumber(SWITCH_ID, PORT_NUMBER, start, end); assertEquals(2, portHistory.size()); assertTrue(portHistory.contains(portUp)); assertTrue(portHistory.contains(portDown)); }
@Override public List<PortHistory> findBySwitchIdAndPortNumber(SwitchId switchId, int portNumber, Instant timeFrom, Instant timeTo) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(PortHistoryFrame.FRAME_LABEL) .has(PortHistoryFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PortHistoryFrame.PORT_NUMBER_PROPERTY, portNumber); if (timeFrom != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(PortHistoryFrame.TIME_PROPERTY, Order.incr); }).toListExplicit(PortHistoryFrame.class).stream() .map(PortHistory::new) .collect(Collectors.toList()); }
FermaPortHistoryRepository extends FermaGenericRepository<PortHistory, PortHistoryData, PortHistoryFrame> implements PortHistoryRepository { @Override public List<PortHistory> findBySwitchIdAndPortNumber(SwitchId switchId, int portNumber, Instant timeFrom, Instant timeTo) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(PortHistoryFrame.FRAME_LABEL) .has(PortHistoryFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PortHistoryFrame.PORT_NUMBER_PROPERTY, portNumber); if (timeFrom != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(PortHistoryFrame.TIME_PROPERTY, Order.incr); }).toListExplicit(PortHistoryFrame.class).stream() .map(PortHistory::new) .collect(Collectors.toList()); } }
FermaPortHistoryRepository extends FermaGenericRepository<PortHistory, PortHistoryData, PortHistoryFrame> implements PortHistoryRepository { @Override public List<PortHistory> findBySwitchIdAndPortNumber(SwitchId switchId, int portNumber, Instant timeFrom, Instant timeTo) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(PortHistoryFrame.FRAME_LABEL) .has(PortHistoryFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PortHistoryFrame.PORT_NUMBER_PROPERTY, portNumber); if (timeFrom != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(PortHistoryFrame.TIME_PROPERTY, Order.incr); }).toListExplicit(PortHistoryFrame.class).stream() .map(PortHistory::new) .collect(Collectors.toList()); } FermaPortHistoryRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaPortHistoryRepository extends FermaGenericRepository<PortHistory, PortHistoryData, PortHistoryFrame> implements PortHistoryRepository { @Override public List<PortHistory> findBySwitchIdAndPortNumber(SwitchId switchId, int portNumber, Instant timeFrom, Instant timeTo) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(PortHistoryFrame.FRAME_LABEL) .has(PortHistoryFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PortHistoryFrame.PORT_NUMBER_PROPERTY, portNumber); if (timeFrom != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(PortHistoryFrame.TIME_PROPERTY, Order.incr); }).toListExplicit(PortHistoryFrame.class).stream() .map(PortHistory::new) .collect(Collectors.toList()); } FermaPortHistoryRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override List<PortHistory> findBySwitchIdAndPortNumber(SwitchId switchId, int portNumber,
                                                         Instant timeFrom, Instant timeTo); }
FermaPortHistoryRepository extends FermaGenericRepository<PortHistory, PortHistoryData, PortHistoryFrame> implements PortHistoryRepository { @Override public List<PortHistory> findBySwitchIdAndPortNumber(SwitchId switchId, int portNumber, Instant timeFrom, Instant timeTo) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(PortHistoryFrame.FRAME_LABEL) .has(PortHistoryFrame.SWITCH_ID_PROPERTY, SwitchIdConverter.INSTANCE.toGraphProperty(switchId)) .has(PortHistoryFrame.PORT_NUMBER_PROPERTY, portNumber); if (timeFrom != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(PortHistoryFrame.TIME_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(PortHistoryFrame.TIME_PROPERTY, Order.incr); }).toListExplicit(PortHistoryFrame.class).stream() .map(PortHistory::new) .collect(Collectors.toList()); } FermaPortHistoryRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override List<PortHistory> findBySwitchIdAndPortNumber(SwitchId switchId, int portNumber,
                                                         Instant timeFrom, Instant timeTo);  }