DatabaseFDFlowManager extends BaseService implements FDFlowManager { @Override public Optional<FDFlowEvent> getFlowEvent(final String flowEventId) { if (StringUtils.isBlank(flowEventId)) { throw new IllegalArgumentException("Flow event id cannot be null or blank"); } final Optional<FDFlowEventEntity> flowEventEntity = flowEventRepository.findById(flowEventId); if (flowEventEntity.isPresent()) { final FDFlowEvent flowEvent = modelMapper.map(flowEventEntity.get(), FDFlowEvent.class); return Optional.of(flowEvent); } else { return Optional.empty(); } } @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 testGetFlowEventWhenExists() throws ParseException { final String flowEventId = "4"; final Optional<FDFlowEvent> flowEventOptional = flowManager.getFlowEvent(flowEventId); assertTrue(flowEventOptional.isPresent()); final FDFlowEvent flowEvent = flowEventOptional.get(); assertEquals(flowEventId, flowEvent.getIdentifier()); assertEquals("2", flowEvent.getFlowIdentifier()); assertEquals(new BigInteger("3"), flowEvent.getFlowRevision()); Assert.assertEquals(FDFlowEventType.FLOW_PUBLISHED, flowEvent.getEventType()); assertEquals("Created root process group", flowEvent.getEventDescription()); Assert.assertEquals(FDFlowFormat.JACKSON_JSON_V1, flowEvent.getFlowFormat()); assertEquals("root-group-2", flowEvent.getComponentId()); assertEquals("system", flowEvent.getUserIdentity()); final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS z"); assertEquals(dateFormat.parse("2018-07-26 12:54:00.000 UTC").getTime(), flowEvent.getCreated().longValue()); assertEquals(dateFormat.parse("2018-07-26 12:54:00.000 UTC").getTime(), flowEvent.getUpdated().longValue()); }
@Test public void testGetFlowEventWhenDoesNotExist() { final Optional<FDFlowEvent> flowEventOptional = flowManager.getFlowEvent("DOES-NOT-EXIST"); assertFalse(flowEventOptional.isPresent()); }