@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); }
templateDto.setId(uuid);
template.setId(null);
@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); }
/** * 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; }