@Test public void findByFlowIdTimeFrameAndMaxCountTest() { repository.add(buildFlowEvent(FLOW_1, ACTION_1, TIME_1)); repository.add(buildFlowEvent(FLOW_1, ACTION_2, TIME_2)); repository.add(buildFlowEvent(FLOW_1, ACTION_3, TIME_3)); repository.add(buildFlowEvent(FLOW_1, ACTION_4, TIME_4)); repository.add(buildFlowEvent(FLOW_2, ACTION_5, TIME_3)); List<FlowEvent> events = new ArrayList<>(repository.findByFlowIdAndTimeFrame( FLOW_1, TIME_1, TIME_4, 2)); assertEquals(2, events.size()); assertEquals(ACTION_3, events.get(0).getAction()); assertEquals(ACTION_4, events.get(1).getAction()); assertTrue(events.get(0).getTimestamp().isBefore(events.get(1).getTimestamp())); }
@Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); }
FermaFlowEventRepository extends FermaGenericRepository<FlowEvent, FlowEventData, FlowEventFrame> implements FlowEventRepository { @Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); } }
FermaFlowEventRepository extends FermaGenericRepository<FlowEvent, FlowEventData, FlowEventFrame> implements FlowEventRepository { @Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); } FermaFlowEventRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); }
FermaFlowEventRepository extends FermaGenericRepository<FlowEvent, FlowEventData, FlowEventFrame> implements FlowEventRepository { @Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); } FermaFlowEventRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override boolean existsByTaskId(String taskId); @Override Optional<FlowEvent> findByTaskId(String taskId); @Override List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount); }
FermaFlowEventRepository extends FermaGenericRepository<FlowEvent, FlowEventData, FlowEventFrame> implements FlowEventRepository { @Override public List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount) { return framedGraph().traverse(g -> { GraphTraversal<Vertex, Vertex> traversal = g.V() .hasLabel(FlowEventFrame.FRAME_LABEL) .has(FlowEventFrame.FLOW_ID_PROPERTY, flowId); if (timeFrom != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.gte(InstantLongConverter.INSTANCE.toGraphProperty(timeFrom))); } if (timeTo != null) { traversal = traversal.has(FlowEventFrame.TIMESTAMP_PROPERTY, P.lte(InstantLongConverter.INSTANCE.toGraphProperty(timeTo))); } return traversal .order().by(FlowEventFrame.TIMESTAMP_PROPERTY, Order.decr) .limit(maxCount); }).toListExplicit(FlowEventFrame.class).stream() .sorted(Comparator.comparing(FlowEventFrame::getTimestamp)) .map(FlowEvent::new) .collect(Collectors.toList()); } FermaFlowEventRepository(FramedGraphFactory<?> graphFactory, TransactionManager transactionManager); @Override boolean existsByTaskId(String taskId); @Override Optional<FlowEvent> findByTaskId(String taskId); @Override List<FlowEvent> findByFlowIdAndTimeFrame(String flowId, Instant timeFrom, Instant timeTo, int maxCount);  }