DatabaseFDFlowManager extends BaseService implements FDFlowManager { @Override public Optional<FDFlow> getFlow(final String flowId) { if (StringUtils.isBlank(flowId)) { throw new IllegalArgumentException("Flow id cannot be null or blank"); } FDFlow flow = flowsById.get(flowId); if (flow == null) { final Optional<FDFlowEntity> flowEntity = flowRepository.findById(flowId); if (!flowEntity.isPresent()) { return Optional.empty(); } final Optional<FDFlowEventEntity> latestFlowEvent = flowEventRepository.findFirstByFlowOrderByFlowRevisionDesc(flowEntity.get()); if (!latestFlowEvent.isPresent()) { throw new IllegalStateException("Could not find any flow content for the given flow"); } final FDFlowMetadata flowMetadata = modelMapper.map(flowEntity.get(), FDFlowMetadata.class); final VersionedProcessGroup flowContent = deserialize(latestFlowEvent.get().getFlowContent()); final FDVersionInfo versionInfo = createVersionInfo(latestFlowEvent.get()); final BigInteger localFlowRevision = latestFlowEvent.get().getFlowRevision(); flow = new FDFlow(); flow.setFlowMetadata(flowMetadata); flow.setFlowContent(flowContent); flow.setVersionInfo(versionInfo); flow.setLocalFlowRevision(localFlowRevision); flowsById.put(flowId, flow); } return Optional.of(flow); } @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 testGetFlowWhenDoesNotExist() { final Optional<FDFlow> flowOptional = flowManager.getFlow("DOES-NOT-EXIST"); assertFalse(flowOptional.isPresent()); }