/** * Creates a TemplateDTO from the specified template. * * @param template template * @return dto */ public TemplateDTO createTemplateDTO(final Template template) { if (template == null) { return null; } final TemplateDTO original = template.getDetails(); final TemplateDTO copy = new TemplateDTO(); copy.setId(original.getId()); copy.setGroupId(template.getProcessGroup().getIdentifier()); copy.setName(original.getName()); copy.setDescription(original.getDescription()); copy.setTimestamp(original.getTimestamp()); copy.setUri(original.getUri()); copy.setEncodingVersion(original.getEncodingVersion()); return copy; }
@Override public TemplateDTO importTemplate(final TemplateDTO templateDTO, final String groupId, final Optional<String> idGenerationSeed) { // ensure id is set final String uuid = idGenerationSeed.isPresent() ? (UUID.nameUUIDFromBytes(idGenerationSeed.get().getBytes(StandardCharsets.UTF_8))).toString() : UUID.randomUUID().toString(); templateDTO.setId(uuid); // mark the timestamp templateDTO.setTimestamp(new Date()); // ensure default values are populated ensureDefaultPropertyValuesArePopulated(templateDTO.getSnippet()); // import the template final Template template = templateDAO.importTemplate(templateDTO, groupId); // save the flow controllerFacade.save(); // return the template dto return dtoFactory.createTemplateDTO(template); }
@Override public TemplateDTO createTemplate(final String name, final String description, final String snippetId, final String groupId, final Optional<String> idGenerationSeed) { // get the specified snippet final Snippet snippet = snippetDAO.getSnippet(snippetId); // create the template final TemplateDTO templateDTO = new TemplateDTO(); templateDTO.setName(name); templateDTO.setDescription(description); templateDTO.setTimestamp(new Date()); templateDTO.setSnippet(snippetUtils.populateFlowSnippet(snippet, true, true, true)); templateDTO.setEncodingVersion(TemplateDTO.MAX_ENCODING_VERSION); // set the id based on the specified seed final String uuid = idGenerationSeed.isPresent() ? (UUID.nameUUIDFromBytes(idGenerationSeed.get().getBytes(StandardCharsets.UTF_8))).toString() : UUID.randomUUID().toString(); templateDTO.setId(uuid); // create the template final Template template = templateDAO.createTemplate(templateDTO, groupId); // drop the snippet snippetDAO.dropSnippet(snippetId); // save the flow controllerFacade.save(); return dtoFactory.createTemplateDTO(template); }
if (requestTemplateEntity == null || requestTemplateEntity.getTemplate() == null || requestTemplateEntity.getTemplate().getSnippet() == null) { throw new IllegalArgumentException("Template details must be specified."); processGroup.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser()); }, () -> serviceFacade.verifyCanAddTemplate(groupId, requestTemplateEntity.getTemplate().getName()), templateEntity -> { try { return generateCreatedResponse(URI.create(template.getUri()), entity).build(); } catch (IllegalArgumentException | IllegalStateException e) { logger.info("Unable to import template: " + e);
@Override public String getIdentifier() { return dto.getId(); }
final FlowSnippetDTO requestTemplateContents = requestedTemplate.getSnippet(); requestInstantiateTemplateRequestEntity.setEncodingVersion(requestedTemplate.getEncodingVersion()); requestInstantiateTemplateRequestEntity.setSnippet(requestTemplateContents);
@Override public FlowControllerSchema apply(TemplateDTO templateDTO) { Map<String, Object> map = new HashMap<>(); map.put(CommonPropertyKeys.NAME_KEY, templateDTO.getName()); map.put(CommonPropertyKeys.COMMENT_KEY, templateDTO.getDescription()); return new FlowControllerSchema(map); } }
@Override public void verifyCanAddTemplate(final String name) { // ensure the name is specified if (StringUtils.isBlank(name)) { throw new IllegalArgumentException("Template name cannot be blank."); } for (final Template template : getRoot().findAllTemplates()) { final TemplateDTO existingDto = template.getDetails(); // ensure a template with this name doesnt already exist if (name.equals(existingDto.getName())) { throw new IllegalStateException(String.format("A template named '%s' already exists.", name)); } } }
/** * Scrubs the template prior to persisting in order to remove fields that shouldn't be included or are unnecessary. * * @param templateDto template */ public static void scrubTemplate(final TemplateDTO templateDto) { scrubSnippet(templateDto.getSnippet()); }
@Override public TemplateDTO exportTemplate(final String id) { final Template template = templateDAO.getTemplate(id); final TemplateDTO templateDetails = template.getDetails(); final TemplateDTO templateDTO = dtoFactory.createTemplateDTO(template); templateDTO.setSnippet(dtoFactory.copySnippetContents(templateDetails.getSnippet())); return templateDTO; }
protected String getComponentId(final TemplateDTO dto) { return dto.getId(); }
public static ConfigSchema transformTemplateToSchema(InputStream source) throws JAXBException, IOException { try { TemplateDTO templateDTO = (TemplateDTO) JAXBContext.newInstance(TemplateDTO.class).createUnmarshaller().unmarshal(source); FlowSnippetDTOEnricher enricher = new FlowSnippetDTOEnricher(); enricher.enrich(templateDTO.getSnippet(), templateDTO.getEncodingVersion()); ConfigSchema configSchema = new ConfigSchemaFunction().apply(templateDTO); return configSchema; } finally { source.close(); } }
@Override public FlowControllerSchema apply(TemplateDTO templateDTO) { Map<String, Object> map = new HashMap<>(); map.put(CommonPropertyKeys.NAME_KEY, templateDTO.getName()); map.put(CommonPropertyKeys.COMMENT_KEY, templateDTO.getDescription()); return new FlowControllerSchema(map); } }
final Template existing = rootGroup.getTemplate(template.getIdentifier()); if (existing == null) { logger.info("Imported Template '{}' to Root Group", template.getDetails().getName()); rootGroup.addTemplate(template); } else { logger.info("Template '{}' was already present in Root Group so will not import from file", template.getDetails().getName());
@Override public ConfigSchema apply(TemplateDTO templateDTO) { Map<String, Object> map = new HashMap<>(); map.put(CommonPropertyKeys.FLOW_CONTROLLER_PROPS_KEY, flowControllerSchemaFunction.apply(templateDTO).toMap()); FlowSnippetDTO snippet = templateDTO.getSnippet(); addSnippet(map, snippet); return new ConfigSchema(map); }