From e4c733a86f304286e11d60e884a4e667acc16ad1 Mon Sep 17 00:00:00 2001 From: Joshua Matsuoka Date: Tue, 21 May 2024 13:28:19 -0400 Subject: [PATCH] chore(cleanup): Abstract away document type (#389) * Abstract away document type * Update src/main/java/io/cryostat/core/templates/RemoteTemplateService.java Co-authored-by: Andrew Azores Signed-off-by: Joshua Matsuoka * Fix Typo --------- Signed-off-by: Joshua Matsuoka Co-authored-by: Andrew Azores --- .../io/cryostat/core/templates/RemoteTemplateService.java | 7 ++++--- .../java/io/cryostat/core/templates/TemplateService.java | 7 ++----- .../cryostat/core/templates/RemoteTemplateServiceTest.java | 6 +++--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/main/java/io/cryostat/core/templates/RemoteTemplateService.java b/src/main/java/io/cryostat/core/templates/RemoteTemplateService.java index 30371cd7..958a9a82 100644 --- a/src/main/java/io/cryostat/core/templates/RemoteTemplateService.java +++ b/src/main/java/io/cryostat/core/templates/RemoteTemplateService.java @@ -33,7 +33,6 @@ import io.cryostat.core.net.JFRConnection; import org.jsoup.Jsoup; -import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; import org.jsoup.parser.Parser; import org.jsoup.select.Elements; @@ -55,7 +54,7 @@ protected TemplateType providedTemplateType() { } @Override - public Optional getXml(String templateName, TemplateType type) + public Optional getXml(String templateName, TemplateType type) throws FlightRecorderException { if (!providedTemplateType().equals(type)) { return Optional.empty(); @@ -68,7 +67,8 @@ public Optional getXml(String templateName, TemplateType type) Elements els = doc.getElementsByTag("configuration"); if (els.isEmpty()) { throw new MalformedXMLException( - "Document did not contain \"configuration\" element"); + "Document did not contain \"configuration\"" + + " element"); } if (els.size() > 1) { throw new MalformedXMLException( @@ -83,6 +83,7 @@ public Optional getXml(String templateName, TemplateType type) } return configuration.attr("label").equals(templateName); }) + .map(doc -> doc.toString()) .findFirst(); } catch (org.openjdk.jmc.flightrecorder.configuration.FlightRecorderException | IOException diff --git a/src/main/java/io/cryostat/core/templates/TemplateService.java b/src/main/java/io/cryostat/core/templates/TemplateService.java index ad039a14..b36d8285 100644 --- a/src/main/java/io/cryostat/core/templates/TemplateService.java +++ b/src/main/java/io/cryostat/core/templates/TemplateService.java @@ -23,18 +23,15 @@ import io.cryostat.core.FlightRecorderException; -import org.jsoup.nodes.Document; - public interface TemplateService { List