DatabaseFDFlowManager extends BaseService implements FDFlowManager { @Override public FDFlowMetadata createFlow(final String agentClass, final NiFiUser user) { if (StringUtils.isBlank(agentClass)) { throw new IllegalArgumentException("Agent class cannot be null or blank"); } if (user == null || StringUtils.isBlank(user.getIdentity())) { throw new IllegalArgumentException("A user identity must be provided"); } final VersionedProcessGroup flowContent = new VersionedProcessGroup(); flowContent.setIdentifier(UUID.randomUUID().toString()); flowContent.setName(ROOT_PROCESS_GROUP_NAME); final FDFlowEntity flowEntity = new FDFlowEntity(); flowEntity.setId(UUID.randomUUID().toString()); flowEntity.setAgentClass(agentClass); flowEntity.setRootProcessGroupId(flowContent.getIdentifier()); final FDFlowEntity savedFlowEntity = flowRepository.save(flowEntity); final FDFlowEventEntity flowEventEntity = new FDFlowEventEntity(); flowEventEntity.setId(UUID.randomUUID().toString()); flowEventEntity.setFlow(savedFlowEntity); flowEventEntity.setEventType(FDFlowEventType.COMPONENT_ADDED); flowEventEntity.setEventDescription("Created root process group"); flowEventEntity.setComponentId(flowContent.getIdentifier()); flowEventEntity.setFlowRevision(BigInteger.ZERO); flowEventEntity.setUserIdentity(user.getIdentity()); flowEventEntity.setRegistryUrl(UNPUBLISHED); flowEventEntity.setRegistryBucketId(UNPUBLISHED); flowEventEntity.setRegistryFlowId(UNPUBLISHED); flowEventEntity.setRegistryVersion(0); flowEventEntity.setLastPublished(null); flowEventEntity.setLastPublishedUserIdentity(null); final String serializedFlowContent = serializeFlowContent(flowContent); flowEventEntity.setFlowContent(serializedFlowContent); flowEventEntity.setFlowFormat(CURRENT_FLOW_FORMAT); flowEventRepository.save(flowEventEntity); return modelMapper.map(savedFlowEntity, FDFlowMetadata.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; }
@Test public void testCreateFlow() { final String agentClassFoo = "Class FOO"; final NiFiUser user = new StandardNiFiUser.Builder().identity("system").build(); final FDFlowMetadata flowMetadata = flowManager.createFlow(agentClassFoo, user); entityManager.flush(); assertEquals(agentClassFoo, flowMetadata.getAgentClass()); assertNotNull(flowMetadata.getIdentifier()); assertNotNull(flowMetadata.getCreated()); assertNotNull(flowMetadata.getUpdated()); final Optional<FDFlow> flowOptional = flowManager.getFlow(flowMetadata.getIdentifier()); assertTrue(flowOptional.isPresent()); final FDFlow flow = flowOptional.get(); assertEquals(flowMetadata.getIdentifier(), flow.getFlowMetadata().getIdentifier()); assertNotNull(flow.getFlowContent()); assertNotNull(flow.getFlowContent().getIdentifier()); assertNotNull(flow.getFlowContent().getName()); }