@Test public void testDeleteFlowEvent() { final String flowId = "2"; final List<FDFlowEvent> flowEvents = flowManager.getFlowEvents(flowId); assertEquals(3, flowEvents.size()); final FDFlowEvent flowEvent2 = flowManager.deleteFlowEvent("2"); assertNotNull(flowEvent2); final FDFlowEvent flowEvent3 = flowManager.deleteFlowEvent("3"); assertNotNull(flowEvent3); try { flowManager.deleteFlowEvent("4"); Assert.fail("Should have thrown exception"); } catch (Exception e) { } }
@Override public FDFlowEvent deleteFlowEvent(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()) { throw new ResourceNotFoundException("No flow event exists for the given id"); } if (flowEventEntity.get().getEventType() == FDFlowEventType.FLOW_PUBLISHED) { throw new IllegalArgumentException("Cannot delete event because deleting events of type " + FDFlowEventType.FLOW_PUBLISHED + " is not allowed"); } final FDFlowEntity flowEntity = flowEventEntity.get().getFlow(); final Long numEventsForFlow = flowEventRepository.countByFlow(flowEntity); if (numEventsForFlow <= 1) { throw new IllegalStateException("Cannot delete event because there is only one event for the given flow"); } flowEventRepository.delete(flowEventEntity.get()); if (flowsById.containsKey(flowEntity.getId())) { flowsById.remove(flowEntity.getId()); } return modelMapper.map(flowEventEntity.get(), FDFlowEvent.class); }
DatabaseFDFlowManager extends BaseService implements FDFlowManager { @Override public FDFlowEvent deleteFlowEvent(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()) { throw new ResourceNotFoundException("No flow event exists for the given id"); } if (flowEventEntity.get().getEventType() == FDFlowEventType.FLOW_PUBLISHED) { throw new IllegalArgumentException("Cannot delete event because deleting events of type " + FDFlowEventType.FLOW_PUBLISHED + " is not allowed"); } final FDFlowEntity flowEntity = flowEventEntity.get().getFlow(); final Long numEventsForFlow = flowEventRepository.countByFlow(flowEntity); if (numEventsForFlow <= 1) { throw new IllegalStateException("Cannot delete event because there is only one event for the given flow"); } flowEventRepository.delete(flowEventEntity.get()); if (flowsById.containsKey(flowEntity.getId())) { flowsById.remove(flowEntity.getId()); } return modelMapper.map(flowEventEntity.get(), FDFlowEvent.class); } }
DatabaseFDFlowManager extends BaseService implements FDFlowManager { @Override public FDFlowEvent deleteFlowEvent(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()) { throw new ResourceNotFoundException("No flow event exists for the given id"); } if (flowEventEntity.get().getEventType() == FDFlowEventType.FLOW_PUBLISHED) { throw new IllegalArgumentException("Cannot delete event because deleting events of type " + FDFlowEventType.FLOW_PUBLISHED + " is not allowed"); } final FDFlowEntity flowEntity = flowEventEntity.get().getFlow(); final Long numEventsForFlow = flowEventRepository.countByFlow(flowEntity); if (numEventsForFlow <= 1) { throw new IllegalStateException("Cannot delete event because there is only one event for the given flow"); } flowEventRepository.delete(flowEventEntity.get()); if (flowsById.containsKey(flowEntity.getId())) { flowsById.remove(flowEntity.getId()); } return modelMapper.map(flowEventEntity.get(), FDFlowEvent.class); } @Autowired  DatabaseFDFlowManager(final FDFlowRepository flowRepository,
                                 final FDFlowEventRepository flowEventRepository,
                                 final OptionalModelMapper modelMapper,
                                 final ObjectMapper objectMapper,
                                 final Validator validator); }
DatabaseFDFlowManager extends BaseService implements FDFlowManager { @Override public FDFlowEvent deleteFlowEvent(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()) { throw new ResourceNotFoundException("No flow event exists for the given id"); } if (flowEventEntity.get().getEventType() == FDFlowEventType.FLOW_PUBLISHED) { throw new IllegalArgumentException("Cannot delete event because deleting events of type " + FDFlowEventType.FLOW_PUBLISHED + " is not allowed"); } final FDFlowEntity flowEntity = flowEventEntity.get().getFlow(); final Long numEventsForFlow = flowEventRepository.countByFlow(flowEntity); if (numEventsForFlow <= 1) { throw new IllegalStateException("Cannot delete event because there is only one event for the given flow"); } flowEventRepository.delete(flowEventEntity.get()); if (flowsById.containsKey(flowEntity.getId())) { flowsById.remove(flowEntity.getId()); } return modelMapper.map(flowEventEntity.get(), FDFlowEvent.class); } @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); }
DatabaseFDFlowManager extends BaseService implements FDFlowManager { @Override public FDFlowEvent deleteFlowEvent(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()) { throw new ResourceNotFoundException("No flow event exists for the given id"); } if (flowEventEntity.get().getEventType() == FDFlowEventType.FLOW_PUBLISHED) { throw new IllegalArgumentException("Cannot delete event because deleting events of type " + FDFlowEventType.FLOW_PUBLISHED + " is not allowed"); } final FDFlowEntity flowEntity = flowEventEntity.get().getFlow(); final Long numEventsForFlow = flowEventRepository.countByFlow(flowEntity); if (numEventsForFlow <= 1) { throw new IllegalStateException("Cannot delete event because there is only one event for the given flow"); } flowEventRepository.delete(flowEventEntity.get()); if (flowsById.containsKey(flowEntity.getId())) { flowsById.remove(flowEntity.getId()); } return modelMapper.map(flowEventEntity.get(), FDFlowEvent.class); } @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; }