@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)); } } }
@Override public Resource getResource() { return ResourceFactory.getComponentResource(ResourceType.Template, dto.getId(), dto.getName()); }
final String uuid = UUID.nameUUIDFromBytes(templateDto.getName().getBytes(StandardCharsets.UTF_8)).toString(); templateDto.setId(uuid);
String attachmentName = template.getName(); if (StringUtils.isBlank(attachmentName)) { attachmentName = "template";
processGroup.authorize(authorizer, RequestAction.WRITE, NiFiUserUtils.getNiFiUser()); }, () -> serviceFacade.verifyCanAddTemplate(groupId, requestTemplateEntity.getTemplate().getName()), templateEntity -> { try {
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 Template createTemplate(TemplateDTO templateDTO, String groupId) { final ProcessGroup processGroup = flowController.getFlowManager().getGroup(groupId); if (processGroup == null) { throw new ResourceNotFoundException("Could not find Process Group with ID " + groupId); } verifyAdd(templateDTO.getName(), processGroup); TemplateUtils.scrubTemplate(templateDTO); final Template template = new Template(templateDTO); processGroup.addTemplate(template); return template; }
/** * 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 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 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 Resource getResource() { return ResourceFactory.getComponentResource(ResourceType.Template, dto.getId(), dto.getName()); }