Skip to content

Commit

Permalink
chore(template): return template when uploading
Browse files Browse the repository at this point in the history
  • Loading branch information
Thuan Vo committed Jun 22, 2023
1 parent 811412f commit d4ac034
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,19 @@ public LocalProbeTemplateService(FileSystem fs, Environment env) throws IOExcept
}
}

public void addTemplate(InputStream inputStream, String filename)
public ProbeTemplate addTemplate(InputStream inputStream, String filename)
throws FileAlreadyExistsException, IOException, SAXException {
Path path = fs.pathOf(env.getEnv(TEMPLATE_PATH), filename);
if (fs.exists(path)) {
throw new FileAlreadyExistsException(filename);
}
try (inputStream) {
ProbeTemplate template = new ProbeTemplate();
template.setFileName(filename);
// If validation fails this will throw a ProbeValidationException with details
template.deserialize(inputStream);
Path path = fs.pathOf(env.getEnv(TEMPLATE_PATH), filename);
if (fs.exists(path)) {
throw new FileAlreadyExistsException(template.getFileName());
}
fs.writeString(path, template.serialize());
return template;
}
}

Expand Down Expand Up @@ -138,8 +139,8 @@ public List<ProbeTemplate> getTemplates() throws FlightRecorderException {
Path fileName = path.getFileName();
if (fileName != null) {
ProbeTemplate template = new ProbeTemplate();
template.deserialize(stream);
template.setFileName(fileName.toString());
template.deserialize(stream);
templates.add(template);
}
}
Expand Down

0 comments on commit d4ac034

Please sign in to comment.