From c2f3b693fae18e397b4f1f2f6b0fef2a7c3a464b Mon Sep 17 00:00:00 2001 From: Alex Nikonov Date: Mon, 2 Sep 2024 09:25:18 +0200 Subject: [PATCH] =?UTF-8?q?chore:=20generic=207.0.0=20usage,=20regex=20eng?= =?UTF-8?q?ine=20moved=20to=20generic,=20@Discovera=E2=80=A6=20(#179)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit chore: generic 7.0.0 usage, regex engine moved to generic, @Discoverable usage for providing data to the about page --- pom.xml | 8 +- .../exporter/PdfExporterAdminUiServlet.java | 3 - .../exporter/PdfExporterFormExtension.java | 2 +- .../converter/HtmlToPdfConverter.java | 2 +- .../pdf/exporter/converter/PdfConverter.java | 2 +- .../PdfExporterExtensionConfiguration.java | 16 +- .../ConfigurationApiController.java | 2 +- .../ConfigurationInternalController.java | 22 ++- .../UtilityResourcesInternalController.java | 2 +- .../exporter/rest/model/WorkItemRefData.java | 2 +- .../configuration/ConfigurationStatus.java | 21 --- .../rest/model/configuration/Status.java | 16 -- .../exporter/settings/CoverPageSettings.java | 2 +- .../pdf/exporter/util/HtmlProcessor.java | 4 +- .../util/LiveDocCommentsProcessor.java | 2 +- .../configuration/CORSStatusProvider.java | 31 ++++ .../ConfigurationStatusUtils.java | 135 ---------------- .../DefaultSettingsStatusProvider.java | 33 ++++ .../DleToolbarStatusProvider.java | 23 +++ .../DocumentPropertiesPaneStatusProvider.java | 30 ++++ .../LiveReportMainHeadStatusProvider.java | 23 +++ .../WeasyPrintStatusProvider.java | 48 ++++++ .../exporter/util/html/HtmlLinksHelper.java | 2 +- .../placeholder/PlaceholderProcessor.java | 2 +- .../pdf/exporter/util/regex/IRegexEngine.java | 25 --- .../util/regex/RegexEngineJavaUtilImpl.java | 52 ------- .../util/regex/RegexEngineRE2JImpl.java | 62 -------- .../pdf/exporter/util/regex/RegexMatcher.java | 117 -------------- .../webapp/pdf-exporter-admin/pages/about.jsp | 145 +----------------- .../pages/style-packages.jsp | 2 +- .../pdf-exporter-admin/pages/webhooks.jsp | 4 +- .../exporter/util/regex/RegexMatcherTest.java | 106 ------------- 32 files changed, 225 insertions(+), 721 deletions(-) delete mode 100644 src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/model/configuration/ConfigurationStatus.java delete mode 100644 src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/model/configuration/Status.java create mode 100644 src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/CORSStatusProvider.java delete mode 100644 src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/ConfigurationStatusUtils.java create mode 100644 src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/DefaultSettingsStatusProvider.java create mode 100644 src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/DleToolbarStatusProvider.java create mode 100644 src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/DocumentPropertiesPaneStatusProvider.java create mode 100644 src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/LiveReportMainHeadStatusProvider.java create mode 100644 src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/WeasyPrintStatusProvider.java delete mode 100644 src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/regex/IRegexEngine.java delete mode 100644 src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/regex/RegexEngineJavaUtilImpl.java delete mode 100644 src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/regex/RegexEngineRE2JImpl.java delete mode 100644 src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/regex/RegexMatcher.java delete mode 100644 src/test/java/ch/sbb/polarion/extension/pdf/exporter/util/regex/RegexMatcherTest.java diff --git a/pom.xml b/pom.xml index 4473e63..f0828c9 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ ch.sbb.polarion.extensions ch.sbb.polarion.extension.generic - 6.7.0 + 7.0.0 ch.sbb.polarion.extension.pdf-exporter @@ -59,6 +59,7 @@ pdf-exporter ch.sbb.polarion.extension.pdf_exporter + ch.sbb.polarion.extension.pdf.exporter ${maven-jar-plugin.Extension-Context} @@ -109,11 +110,6 @@ byte-buddy ${byte-buddy.version} - - com.google.re2j - re2j - ${re2j.version} - diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/PdfExporterAdminUiServlet.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/PdfExporterAdminUiServlet.java index 3c23f02..28f2ee8 100644 --- a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/PdfExporterAdminUiServlet.java +++ b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/PdfExporterAdminUiServlet.java @@ -1,8 +1,6 @@ package ch.sbb.polarion.extension.pdf.exporter; import ch.sbb.polarion.extension.generic.GenericUiServlet; -import ch.sbb.polarion.extension.generic.properties.CurrentExtensionConfiguration; -import ch.sbb.polarion.extension.pdf.exporter.properties.PdfExporterExtensionConfiguration; import java.io.Serial; @@ -13,6 +11,5 @@ public class PdfExporterAdminUiServlet extends GenericUiServlet { public PdfExporterAdminUiServlet() { super("pdf-exporter-admin"); - CurrentExtensionConfiguration.getInstance().setExtensionConfiguration(PdfExporterExtensionConfiguration.getInstance()); } } diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/PdfExporterFormExtension.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/PdfExporterFormExtension.java index 71d61be..eae526e 100644 --- a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/PdfExporterFormExtension.java +++ b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/PdfExporterFormExtension.java @@ -155,7 +155,7 @@ private String adjustWebhooks(String scope, String form, StylePackageModel style Collection webhooksNames = getSettingNames(WebhooksSettings.FEATURE_NAME, scope); boolean noHooks = StringUtils.isEmpty(stylePackage.getWebhooks()); String webhooksOptions = generateSelectOptions(webhooksNames, noHooks ? NamedSettings.DEFAULT_NAME : stylePackage.getWebhooks()); - form = form.replace("{WEBHOOKS_DISPLAY}", PdfExporterExtensionConfiguration.getInstance().areWebhooksEnabled() ? "" : "hidden"); + form = form.replace("{WEBHOOKS_DISPLAY}", PdfExporterExtensionConfiguration.getInstance().getWebhooksEnabled() ? "" : "hidden"); form = form.replace("{WEBHOOKS_OPTIONS}", webhooksOptions); form = form.replace("{WEBHOOKS_SELECTOR_DISPLAY}", noHooks ? "none" : "inline-block"); return form.replace("{WEBHOOKS_SELECTED}", noHooks ? "" : "checked"); diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/converter/HtmlToPdfConverter.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/converter/HtmlToPdfConverter.java index ee4d11d..8ada440 100644 --- a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/converter/HtmlToPdfConverter.java +++ b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/converter/HtmlToPdfConverter.java @@ -9,7 +9,7 @@ import ch.sbb.polarion.extension.pdf.exporter.util.PdfExporterFileResourceProvider; import ch.sbb.polarion.extension.pdf.exporter.util.PdfTemplateProcessor; import ch.sbb.polarion.extension.pdf.exporter.util.html.HtmlLinksHelper; -import ch.sbb.polarion.extension.pdf.exporter.util.regex.RegexMatcher; +import ch.sbb.polarion.extension.generic.regex.RegexMatcher; import ch.sbb.polarion.extension.pdf.exporter.weasyprint.WeasyPrintOptions; import ch.sbb.polarion.extension.pdf.exporter.weasyprint.service.WeasyPrintServiceConnector; import lombok.Getter; diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/converter/PdfConverter.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/converter/PdfConverter.java index 5879627..1fbf8ba 100644 --- a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/converter/PdfConverter.java +++ b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/converter/PdfConverter.java @@ -148,7 +148,7 @@ public byte[] convertToPdf(@NotNull ExportParams exportParams, @Nullable ExportM private @NotNull String applyWebhooks(@NotNull ExportParams exportParams, @NotNull String htmlContent) { // Skip webhooks processing among other if this functionality is not enabled by system administrator - if (!PdfExporterExtensionConfiguration.getInstance().areWebhooksEnabled() || exportParams.getWebhooks() == null) { + if (!PdfExporterExtensionConfiguration.getInstance().getWebhooksEnabled() || exportParams.getWebhooks() == null) { return htmlContent; } diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/properties/PdfExporterExtensionConfiguration.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/properties/PdfExporterExtensionConfiguration.java index 6efd98a..e0c3df8 100644 --- a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/properties/PdfExporterExtensionConfiguration.java +++ b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/properties/PdfExporterExtensionConfiguration.java @@ -1,12 +1,15 @@ package ch.sbb.polarion.extension.pdf.exporter.properties; +import ch.sbb.polarion.extension.generic.properties.CurrentExtensionConfiguration; import ch.sbb.polarion.extension.generic.properties.ExtensionConfiguration; +import ch.sbb.polarion.extension.generic.util.Discoverable; import com.polarion.core.config.impl.SystemValueReader; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.List; +@Discoverable public class PdfExporterExtensionConfiguration extends ExtensionConfiguration { public static final String WEASYPRINT_SERVICE = "weasyprint.service"; @@ -28,7 +31,7 @@ public Boolean getInternalizeExternalCss() { } @NotNull - public Boolean areWebhooksEnabled() { + public Boolean getWebhooksEnabled() { return SystemValueReader.getInstance().readBoolean(getPropertyPrefix() + WEBHOOKS_ENABLED, false); } @@ -42,16 +45,7 @@ public Boolean areWebhooksEnabled() { return supportedProperties; } - public PdfExporterExtensionConfiguration() { - super(); - } - public static PdfExporterExtensionConfiguration getInstance() { - return PdfExporterExtensionConfigurationHolder.INSTANCE; + return (PdfExporterExtensionConfiguration) CurrentExtensionConfiguration.getInstance().getExtensionConfiguration(); } - - private static class PdfExporterExtensionConfigurationHolder { - private static final PdfExporterExtensionConfiguration INSTANCE = new PdfExporterExtensionConfiguration(); - } - } diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/controller/ConfigurationApiController.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/controller/ConfigurationApiController.java index 90b7478..5bc5078 100644 --- a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/controller/ConfigurationApiController.java +++ b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/controller/ConfigurationApiController.java @@ -1,8 +1,8 @@ package ch.sbb.polarion.extension.pdf.exporter.rest.controller; +import ch.sbb.polarion.extension.generic.configuration.ConfigurationStatus; import ch.sbb.polarion.extension.generic.rest.filter.Secured; import ch.sbb.polarion.extension.generic.service.PolarionService; -import ch.sbb.polarion.extension.pdf.exporter.rest.model.configuration.ConfigurationStatus; import org.jetbrains.annotations.NotNull; import javax.ws.rs.Path; diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/controller/ConfigurationInternalController.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/controller/ConfigurationInternalController.java index a3d8855..14d7d30 100644 --- a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/controller/ConfigurationInternalController.java +++ b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/controller/ConfigurationInternalController.java @@ -1,7 +1,13 @@ package ch.sbb.polarion.extension.pdf.exporter.rest.controller; -import ch.sbb.polarion.extension.pdf.exporter.rest.model.configuration.ConfigurationStatus; -import ch.sbb.polarion.extension.pdf.exporter.util.configuration.ConfigurationStatusUtils; +import ch.sbb.polarion.extension.generic.configuration.ConfigurationStatus; +import ch.sbb.polarion.extension.generic.configuration.ConfigurationStatusProvider; +import ch.sbb.polarion.extension.pdf.exporter.util.configuration.CORSStatusProvider; +import ch.sbb.polarion.extension.pdf.exporter.util.configuration.DefaultSettingsStatusProvider; +import ch.sbb.polarion.extension.pdf.exporter.util.configuration.DleToolbarStatusProvider; +import ch.sbb.polarion.extension.pdf.exporter.util.configuration.DocumentPropertiesPaneStatusProvider; +import ch.sbb.polarion.extension.pdf.exporter.util.configuration.LiveReportMainHeadStatusProvider; +import ch.sbb.polarion.extension.pdf.exporter.util.configuration.WeasyPrintStatusProvider; import io.swagger.v3.oas.annotations.Hidden; import io.swagger.v3.oas.annotations.Operation; import org.jetbrains.annotations.NotNull; @@ -23,7 +29,7 @@ public class ConfigurationInternalController { @Path("/configuration/default-settings") @Operation(summary = "Checks default settings configuration") public @NotNull ConfigurationStatus checkDefaultSettings(@QueryParam("scope") @DefaultValue("") String scope) { - return ConfigurationStatusUtils.getSettingsStatus(scope); + return new DefaultSettingsStatusProvider().getStatus(ConfigurationStatusProvider.Context.builder().scope(scope).build()); } @GET @@ -31,7 +37,7 @@ public class ConfigurationInternalController { @Path("/configuration/document-properties-pane-config") @Operation(summary = "Checks document properties pane configuration") public @NotNull ConfigurationStatus checkDocumentPropertiesPaneConfig(@QueryParam("scope") @DefaultValue("") String scope) { - return ConfigurationStatusUtils.getDocumentPropertiesPaneStatus(scope); + return new DocumentPropertiesPaneStatusProvider().getStatus(ConfigurationStatusProvider.Context.builder().scope(scope).build()); } @GET @@ -39,7 +45,7 @@ public class ConfigurationInternalController { @Path("/configuration/dle-toolbar-config") @Operation(summary = "Checks DLE Toolbar configuration") public @NotNull ConfigurationStatus checkDleToolbarConfig() { - return ConfigurationStatusUtils.getDleToolbarStatus(); + return new DleToolbarStatusProvider().getStatus(ConfigurationStatusProvider.Context.builder().build()); } @GET @@ -47,7 +53,7 @@ public class ConfigurationInternalController { @Path("/configuration/live-report-config") @Operation(summary = "Checks Live Report configuration") public @NotNull ConfigurationStatus checkLiveReportConfig() { - return ConfigurationStatusUtils.getLiveReportMainHeadStatus(); + return new LiveReportMainHeadStatusProvider().getStatus(ConfigurationStatusProvider.Context.builder().build()); } @GET @@ -55,7 +61,7 @@ public class ConfigurationInternalController { @Path("/configuration/cors-config") @Operation(summary = "Checks CORS configuration") public @NotNull ConfigurationStatus checkCORSConfig() { - return ConfigurationStatusUtils.getCORSStatus(); + return new CORSStatusProvider().getStatus(ConfigurationStatusProvider.Context.builder().build()); } @GET @@ -63,6 +69,6 @@ public class ConfigurationInternalController { @Path("/configuration/weasyprint") @Operation(summary = "Checks WeasyPrint configuration") public @NotNull List checkWeasyPrint() { - return ConfigurationStatusUtils.getWeasyPrintStatus(); + return new WeasyPrintStatusProvider().getStatuses(ConfigurationStatusProvider.Context.builder().build()); } } diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/controller/UtilityResourcesInternalController.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/controller/UtilityResourcesInternalController.java index 2d040d3..6bd622b 100644 --- a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/controller/UtilityResourcesInternalController.java +++ b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/controller/UtilityResourcesInternalController.java @@ -90,6 +90,6 @@ public String getFileName(@QueryParam("locationPath") String locationPath, @Quer @Tag(name = "Utility resources") @Operation(summary = "Gets webhooks status - if they are enabled or not") public WebhooksStatus getWebhooksStatus() { - return WebhooksStatus.builder().enabled(PdfExporterExtensionConfiguration.getInstance().areWebhooksEnabled()).build(); + return WebhooksStatus.builder().enabled(PdfExporterExtensionConfiguration.getInstance().getWebhooksEnabled()).build(); } } diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/model/WorkItemRefData.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/model/WorkItemRefData.java index 63bc247..ed869a6 100644 --- a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/model/WorkItemRefData.java +++ b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/model/WorkItemRefData.java @@ -1,6 +1,6 @@ package ch.sbb.polarion.extension.pdf.exporter.rest.model; -import ch.sbb.polarion.extension.pdf.exporter.util.regex.RegexMatcher; +import ch.sbb.polarion.extension.generic.regex.RegexMatcher; import com.fasterxml.jackson.annotation.JsonProperty; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/model/configuration/ConfigurationStatus.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/model/configuration/ConfigurationStatus.java deleted file mode 100644 index 2477099..0000000 --- a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/model/configuration/ConfigurationStatus.java +++ /dev/null @@ -1,21 +0,0 @@ -package ch.sbb.polarion.extension.pdf.exporter.rest.model.configuration; - -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; -import org.jetbrains.annotations.NotNull; - -@Data -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class ConfigurationStatus { - private @NotNull String name; - private @NotNull Status status; - private @NotNull String details; - - public ConfigurationStatus(@NotNull String name, @NotNull Status status) { - this(name, status, ""); - } -} diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/model/configuration/Status.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/model/configuration/Status.java deleted file mode 100644 index b34d10d..0000000 --- a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/rest/model/configuration/Status.java +++ /dev/null @@ -1,16 +0,0 @@ -package ch.sbb.polarion.extension.pdf.exporter.rest.model.configuration; - -public enum Status { - OK, - WARNING, - ERROR; - - public String toHtml() { - String color = switch (this) { - case OK -> "green"; - case WARNING -> "gray"; - case ERROR -> "red"; - }; - return String.format("%s", color, this.name()); - } -} diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/settings/CoverPageSettings.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/settings/CoverPageSettings.java index 19b7415..5fb77d2 100644 --- a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/settings/CoverPageSettings.java +++ b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/settings/CoverPageSettings.java @@ -7,7 +7,7 @@ import ch.sbb.polarion.extension.pdf.exporter.rest.model.settings.coverpage.CoverPageModel; import ch.sbb.polarion.extension.pdf.exporter.service.PdfExporterPolarionService; import ch.sbb.polarion.extension.pdf.exporter.util.MediaUtils; -import ch.sbb.polarion.extension.pdf.exporter.util.regex.RegexMatcher; +import ch.sbb.polarion.extension.generic.regex.RegexMatcher; import com.polarion.core.util.logging.Logger; import com.polarion.platform.service.repository.IRepositoryReadOnlyConnection; import com.polarion.subterra.base.location.ILocation; diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/HtmlProcessor.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/HtmlProcessor.java index 5260783..04e8c02 100644 --- a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/HtmlProcessor.java +++ b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/HtmlProcessor.java @@ -10,8 +10,8 @@ import ch.sbb.polarion.extension.pdf.exporter.settings.LocalizationSettings; import ch.sbb.polarion.extension.pdf.exporter.util.exporter.CustomPageBreakPart; import ch.sbb.polarion.extension.pdf.exporter.util.html.HtmlLinksHelper; -import ch.sbb.polarion.extension.pdf.exporter.util.regex.IRegexEngine; -import ch.sbb.polarion.extension.pdf.exporter.util.regex.RegexMatcher; +import ch.sbb.polarion.extension.generic.regex.IRegexEngine; +import ch.sbb.polarion.extension.generic.regex.RegexMatcher; import com.polarion.alm.shared.util.StringUtils; import com.polarion.core.util.xml.CSSStyle; import lombok.SneakyThrows; diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/LiveDocCommentsProcessor.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/LiveDocCommentsProcessor.java index df2c76a..d9229bf 100644 --- a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/LiveDocCommentsProcessor.java +++ b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/LiveDocCommentsProcessor.java @@ -1,7 +1,7 @@ package ch.sbb.polarion.extension.pdf.exporter.util; import ch.sbb.polarion.extension.pdf.exporter.model.LiveDocComment; -import ch.sbb.polarion.extension.pdf.exporter.util.regex.RegexMatcher; +import ch.sbb.polarion.extension.generic.regex.RegexMatcher; import com.polarion.alm.server.api.model.document.ProxyDocument; import com.polarion.alm.shared.api.model.comment.CommentBase; import com.polarion.alm.shared.api.model.comment.CommentBaseFields; diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/CORSStatusProvider.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/CORSStatusProvider.java new file mode 100644 index 0000000..f2dc328 --- /dev/null +++ b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/CORSStatusProvider.java @@ -0,0 +1,31 @@ +package ch.sbb.polarion.extension.pdf.exporter.util.configuration; + +import ch.sbb.polarion.extension.generic.configuration.ConfigurationStatus; +import ch.sbb.polarion.extension.generic.configuration.ConfigurationStatusProvider; +import ch.sbb.polarion.extension.generic.configuration.Status; +import ch.sbb.polarion.extension.generic.util.Discoverable; +import com.polarion.core.config.Configuration; +import org.jetbrains.annotations.NotNull; + +import java.util.Set; + +@Discoverable +public class CORSStatusProvider extends ConfigurationStatusProvider { + + public static final String CORS = "CORS (Cross-Origin Resource Sharing)"; + + @Override + public @NotNull ConfigurationStatus getStatus(@NotNull Context context) { + boolean restEnabled = Configuration.getInstance().rest().enabled(); + if (restEnabled) { + Set corsAllowedOrigins = Configuration.getInstance().rest().corsAllowedOrigins(); + if (corsAllowedOrigins.isEmpty()) { + return new ConfigurationStatus(CORS, Status.WARNING, "CORS allowed origins are not configured"); + } else { + return new ConfigurationStatus(CORS, Status.OK, "CORS allowed origins: %s".formatted(corsAllowedOrigins.stream().toList())); + } + } else { + return new ConfigurationStatus(CORS, Status.WARNING, "Polarion REST API is not enabled, so CORS is not enabled"); + } + } +} diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/ConfigurationStatusUtils.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/ConfigurationStatusUtils.java deleted file mode 100644 index 831dffd..0000000 --- a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/ConfigurationStatusUtils.java +++ /dev/null @@ -1,135 +0,0 @@ -package ch.sbb.polarion.extension.pdf.exporter.util.configuration; - -import ch.sbb.polarion.extension.generic.settings.GenericNamedSettings; -import ch.sbb.polarion.extension.generic.settings.NamedSettingsRegistry; -import ch.sbb.polarion.extension.generic.settings.SettingsService; -import ch.sbb.polarion.extension.generic.util.ScopeUtils; -import ch.sbb.polarion.extension.pdf.exporter.converter.HtmlToPdfConverter; -import ch.sbb.polarion.extension.pdf.exporter.rest.model.configuration.ConfigurationStatus; -import ch.sbb.polarion.extension.pdf.exporter.rest.model.configuration.Status; -import ch.sbb.polarion.extension.pdf.exporter.rest.model.conversion.Orientation; -import ch.sbb.polarion.extension.pdf.exporter.rest.model.conversion.PaperSize; -import ch.sbb.polarion.extension.pdf.exporter.util.regex.RegexMatcher; -import ch.sbb.polarion.extension.pdf.exporter.weasyprint.service.WeasyPrintServiceConnector; -import ch.sbb.polarion.extension.pdf.exporter.weasyprint.service.model.WeasyPrintInfo; -import com.polarion.core.config.Configuration; -import com.polarion.subterra.base.location.ILocation; -import lombok.experimental.UtilityClass; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.Set; - -@UtilityClass -public class ConfigurationStatusUtils { - public static final String DEFAULT_SETTINGS = "Default Settings"; - public static final String DOCUMENT_PROPERTIES_PANE = "Document Properties Pane"; - public static final String DLE_TOOLBAR = "DLE Toolbar"; - public static final String LIVE_REPORT_BUTTON = "LiveReport Button"; - public static final String CORS = "CORS (Cross-Origin Resource Sharing)"; - public static final List WEASY_PRINT = List.of("WeasyPrint Python", "WeasyPrint", "WeasyPrint Service"); - - @SuppressWarnings("java:S1166") //need by design - public static @NotNull ConfigurationStatus getSettingsStatus(@NotNull String scope) { - ConfigurationStatus configurationStatus = new ConfigurationStatus(DEFAULT_SETTINGS, Status.OK, ""); - - NamedSettingsRegistry.INSTANCE.getAll().stream() - .map(GenericNamedSettings::getFeatureName) - .forEach(featureName -> { - try { - NamedSettingsRegistry.INSTANCE.getByFeatureName(featureName).readNames(scope); - } catch (Exception e) { - configurationStatus.setStatus(Status.ERROR); - configurationStatus.setDetails(e.getMessage()); - } - }); - - return configurationStatus; - } - - public static @NotNull ConfigurationStatus getDocumentPropertiesPaneStatus(@NotNull String scope) { - ILocation location = ScopeUtils.getContextLocation(scope).append(".polarion/documents/sidebar/document.xml"); - String content = new SettingsService().read(location, null); - - if (content == null) { - location = ScopeUtils.getDefaultLocation().append(".polarion/documents/sidebar/document.xml"); - content = new SettingsService().read(location, null); - return getConfigurationStatus(DOCUMENT_PROPERTIES_PANE, content, "", new ConfigurationStatus(DOCUMENT_PROPERTIES_PANE, Status.WARNING, "Not configured neither for global scope nor for current project")); - } else { - return getConfigurationStatus(DOCUMENT_PROPERTIES_PANE, content, "", new ConfigurationStatus(DOCUMENT_PROPERTIES_PANE, Status.WARNING, "Not configured for current project")); - } - } - - - public static @NotNull ConfigurationStatus getDleToolbarStatus() { - final ILocation location = ScopeUtils.getDefaultLocation().append(".polarion/context.properties"); - final String content = new SettingsService().read(location, null); - - return getConfigurationStatus(DLE_TOOLBAR, content, "scriptInjection.dleEditorHead=.*"); - } - - public static @NotNull ConfigurationStatus getLiveReportMainHeadStatus() { - final ILocation location = ScopeUtils.getDefaultLocation().append(".polarion/context.properties"); - final String content = new SettingsService().read(location, null); - - return getConfigurationStatus(LIVE_REPORT_BUTTON, content, "scriptInjection.mainHead=.*"); + } +} diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/DocumentPropertiesPaneStatusProvider.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/DocumentPropertiesPaneStatusProvider.java new file mode 100644 index 0000000..e043269 --- /dev/null +++ b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/DocumentPropertiesPaneStatusProvider.java @@ -0,0 +1,30 @@ +package ch.sbb.polarion.extension.pdf.exporter.util.configuration; + +import ch.sbb.polarion.extension.generic.configuration.ConfigurationStatus; +import ch.sbb.polarion.extension.generic.configuration.ConfigurationStatusProvider; +import ch.sbb.polarion.extension.generic.configuration.Status; +import ch.sbb.polarion.extension.generic.settings.SettingsService; +import ch.sbb.polarion.extension.generic.util.Discoverable; +import ch.sbb.polarion.extension.generic.util.ScopeUtils; +import com.polarion.subterra.base.location.ILocation; +import org.jetbrains.annotations.NotNull; + +@Discoverable +public class DocumentPropertiesPaneStatusProvider extends ConfigurationStatusProvider { + + public static final String DOCUMENT_PROPERTIES_PANE = "Document Properties Pane"; + + @Override + public @NotNull ConfigurationStatus getStatus(@NotNull Context context) { + ILocation location = ScopeUtils.getContextLocation(context.getScope()).append(".polarion/documents/sidebar/document.xml"); + String content = new SettingsService().read(location, null); + + if (content == null) { + location = ScopeUtils.getDefaultLocation().append(".polarion/documents/sidebar/document.xml"); + content = new SettingsService().read(location, null); + return getConfigurationStatus(DOCUMENT_PROPERTIES_PANE, content, "", new ConfigurationStatus(DOCUMENT_PROPERTIES_PANE, Status.WARNING, "Not configured neither for global scope nor for current project")); + } else { + return getConfigurationStatus(DOCUMENT_PROPERTIES_PANE, content, "", new ConfigurationStatus(DOCUMENT_PROPERTIES_PANE, Status.WARNING, "Not configured for current project")); + } + } +} diff --git a/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/LiveReportMainHeadStatusProvider.java b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/LiveReportMainHeadStatusProvider.java new file mode 100644 index 0000000..82978f5 --- /dev/null +++ b/src/main/java/ch/sbb/polarion/extension/pdf/exporter/util/configuration/LiveReportMainHeadStatusProvider.java @@ -0,0 +1,23 @@ +package ch.sbb.polarion.extension.pdf.exporter.util.configuration; + +import ch.sbb.polarion.extension.generic.configuration.ConfigurationStatus; +import ch.sbb.polarion.extension.generic.configuration.ConfigurationStatusProvider; +import ch.sbb.polarion.extension.generic.settings.SettingsService; +import ch.sbb.polarion.extension.generic.util.Discoverable; +import ch.sbb.polarion.extension.generic.util.ScopeUtils; +import com.polarion.subterra.base.location.ILocation; +import org.jetbrains.annotations.NotNull; + +@Discoverable +public class LiveReportMainHeadStatusProvider extends ConfigurationStatusProvider { + + public static final String LIVE_REPORT_BUTTON = "LiveReport Button"; + + @Override + public @NotNull ConfigurationStatus getStatus(@NotNull Context context) { + ILocation location = ScopeUtils.getDefaultLocation().append(".polarion/context.properties"); + String content = new SettingsService().read(location, null); + + return getConfigurationStatus(LIVE_REPORT_BUTTON, content, "scriptInjection.mainHead=