DatabaseFDFlowManager extends BaseService implements FDFlowManager { @Override public List<FDFlowEvent> getFlowEvents(final String flowId) { if (StringUtils.isBlank(flowId)) { throw new IllegalArgumentException("Flow id cannot be null or blank"); } final Optional<FDFlowEntity> flowEntity = flowRepository.findById(flowId); if (!flowEntity.isPresent()) { throw new ResourceNotFoundException("No flow exists with the provided flow id"); } final List<FDFlowEvent> events = new ArrayList<>(); flowEventRepository.findByFlowOrderByFlowRevisionAsc(flowEntity.get()).forEach(e -> { final FDFlowEvent flowEvent = modelMapper.map(e, FDFlowEvent.class); events.add(flowEvent); }); return events; } @Autowired  DatabaseFDFlowManager(final FDFlowRepository flowRepository,
                                 final FDFlowEventRepository flowEventRepository,
                                 final OptionalModelMapper modelMapper,
                                 final ObjectMapper objectMapper,
                                 final Validator validator); @Override Optional<FDFlowMetadata> getFlowMetadata(final String flowId); @Override Optional<FDFlow> getFlow(final String flowId); @Override FDFlowMetadata createFlow(final String agentClass, final NiFiUser user); @Override List<FDFlowMetadata> getAvailableFlows(); @Override List<FDFlowSummary> getFlowSummaries(); @Override FDFlowMetadata deleteFlow(final String flowId); @Override List<FDFlowEvent> getFlowEvents(final String flowId); @Override Optional<FDFlowEvent> getLatestFlowEvent(final String flowId); @Override Optional<FDFlowEvent> getLatestPublishFlowEvent(final String flowId); @Override Optional<FDFlowEvent> getFlowEvent(final String flowEventId); @Override FDFlowEvent addFlowEvent(final FDFlowEvent flowEvent, final VersionedProcessGroup flowContent, final NiFiUser user); @Override FDFlowEvent deleteFlowEvent(final String flowEventId); @Override void retainPublishEvents(final String flowId); @Override void revertToFlowRevision(final String flowId, final BigInteger flowRevision); static final FDFlowFormat CURRENT_FLOW_FORMAT; }
@Test public void testGetFlowEventsWhenFlowExists() { final String flowId = "2"; final List<FDFlowEvent> flowEvents = flowManager.getFlowEvents(flowId); assertEquals(3, flowEvents.size()); BigInteger prevRevision = new BigInteger("-1"); for (final FDFlowEvent flowEvent : flowEvents) { assertEquals(flowId, flowEvent.getFlowIdentifier()); assertNotNull(flowEvent.getIdentifier()); assertNotNull(flowEvent.getFlowRevision()); assertNotNull(flowEvent.getComponentId()); assertNotNull(flowEvent.getCreated()); assertNotNull(flowEvent.getUpdated()); assertNotNull(flowEvent.getUserIdentity()); assertNotNull(flowEvent.getEventType()); assertNotNull(flowEvent.getEventDescription()); assertNotNull(flowEvent.getFlowFormat()); assertEquals(1, flowEvent.getFlowRevision().compareTo(prevRevision)); prevRevision = flowEvent.getFlowRevision(); } }
@Test(expected = ResourceNotFoundException.class) public void testGetFlowEventsWhenFlowDoesNotExist() { flowManager.getFlowEvents("DOES-NOT-EXIST"); }