Skip to content

Commit

Permalink
feat: Added more injections
Browse files Browse the repository at this point in the history
Refs: DEV-12343
  • Loading branch information
nirikash committed Dec 27, 2024
1 parent 5eabad6 commit da5533c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package ch.sbb.polarion.extension.pdf_exporter;

import ch.sbb.polarion.extension.pdf_exporter.util.FileResourceProvider;
import ch.sbb.polarion.extension.pdf_exporter.util.PdfExporterFileResourceProvider;
import com.google.inject.AbstractModule;
import com.polarion.platform.core.PlatformContext;
import com.polarion.platform.security.ISecurityService;
Expand All @@ -8,16 +10,7 @@ public class PdfExporterInternModule extends AbstractModule {

@Override
protected void configure() {
// PdfExporterPolarionService pdfExporterPolarionService = new PdfExporterPolarionService();
// PdfConverter pdfConverter = new PdfConverter();
ISecurityService securityService = PlatformContext.getPlatform().lookupService(ISecurityService.class);
bind(ISecurityService.class).toInstance(securityService);

// bind(PolarionService.class).toInstance(pdfExporterPolarionService);
// bind(PdfConverter.class).toInstance(pdfConverter);
// bind(PdfValidationService.class).toInstance(new PdfValidationService(pdfConverter));
// bind(PdfConverterJobsService.class).toInstance(new PdfConverterJobsService(pdfConverter, securityService));
// bind(PropertiesUtility.class).toInstance(new PropertiesUtility());
// bind(HtmlToPdfConverter.class).toInstance(new HtmlToPdfConverter());
bind(ISecurityService.class).toInstance(PlatformContext.getPlatform().lookupService(ISecurityService.class));
bind(FileResourceProvider.class).to(PdfExporterFileResourceProvider.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import ch.sbb.polarion.extension.pdf_exporter.util.velocity.VelocityEvaluator;
import ch.sbb.polarion.extension.pdf_exporter.weasyprint.WeasyPrintOptions;
import ch.sbb.polarion.extension.pdf_exporter.weasyprint.service.WeasyPrintServiceConnector;
import com.google.inject.Inject;
import com.polarion.alm.projects.model.IUniqueObject;
import lombok.SneakyThrows;
import org.jetbrains.annotations.VisibleForTesting;
Expand All @@ -26,14 +27,7 @@ public class CoverPageProcessor {
private final PdfTemplateProcessor pdfTemplateProcessor;


public CoverPageProcessor() {
placeholderProcessor = new PlaceholderProcessor();
velocityEvaluator = new VelocityEvaluator();
weasyPrintServiceConnector = new WeasyPrintServiceConnector();
coverPageSettings = new CoverPageSettings();
pdfTemplateProcessor = new PdfTemplateProcessor();
}

@Inject
public CoverPageProcessor(PlaceholderProcessor placeholderProcessor,
VelocityEvaluator velocityEvaluator,
WeasyPrintServiceConnector weasyPrintServiceConnector,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,25 @@
import ch.sbb.polarion.extension.pdf_exporter.service.PdfExporterPolarionService;
import ch.sbb.polarion.extension.pdf_exporter.settings.CssSettings;
import ch.sbb.polarion.extension.pdf_exporter.settings.HeaderFooterSettings;
import ch.sbb.polarion.extension.pdf_exporter.settings.LocalizationSettings;
import ch.sbb.polarion.extension.pdf_exporter.settings.WebhooksSettings;
import ch.sbb.polarion.extension.pdf_exporter.util.DocumentDataFactory;
import ch.sbb.polarion.extension.pdf_exporter.util.EnumValuesProvider;
import ch.sbb.polarion.extension.pdf_exporter.util.HtmlLogger;
import ch.sbb.polarion.extension.pdf_exporter.util.HtmlProcessor;
import ch.sbb.polarion.extension.pdf_exporter.util.PdfExporterFileResourceProvider;
import ch.sbb.polarion.extension.pdf_exporter.util.PdfExporterListStyleProvider;
import ch.sbb.polarion.extension.pdf_exporter.util.PdfGenerationLog;
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.placeholder.PlaceholderProcessor;
import ch.sbb.polarion.extension.pdf_exporter.util.velocity.VelocityEvaluator;
import ch.sbb.polarion.extension.pdf_exporter.weasyprint.WeasyPrintOptions;
import ch.sbb.polarion.extension.pdf_exporter.weasyprint.service.WeasyPrintServiceConnector;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.inject.Inject;
import com.polarion.alm.projects.model.IUniqueObject;
import com.polarion.alm.tracker.model.ITrackerProject;
import com.polarion.core.util.StringUtils;
import com.polarion.core.util.logging.Logger;
import com.polarion.platform.internal.security.UserAccountVault;
import lombok.AllArgsConstructor;
import org.glassfish.jersey.media.multipart.FormDataBodyPart;
import org.glassfish.jersey.media.multipart.FormDataMultiPart;
import org.glassfish.jersey.media.multipart.MultiPartFeature;
Expand All @@ -60,7 +57,6 @@
import java.util.Collections;
import java.util.List;

@AllArgsConstructor
@SuppressWarnings("java:S1200")
public class PdfConverter {
private final Logger logger = Logger.getLogger(PdfConverter.class);
Expand All @@ -76,17 +72,17 @@ public class PdfConverter {
private final HtmlProcessor htmlProcessor;
private final PdfTemplateProcessor pdfTemplateProcessor;

public PdfConverter() {
pdfExporterPolarionService = new PdfExporterPolarionService();
headerFooterSettings = new HeaderFooterSettings();
cssSettings = new CssSettings();
placeholderProcessor = new PlaceholderProcessor();
velocityEvaluator = new VelocityEvaluator();
coverPageProcessor = new CoverPageProcessor();
weasyPrintServiceConnector = new WeasyPrintServiceConnector();
PdfExporterFileResourceProvider fileResourceProvider = new PdfExporterFileResourceProvider();
htmlProcessor = new HtmlProcessor(fileResourceProvider, new LocalizationSettings(), new HtmlLinksHelper(fileResourceProvider), pdfExporterPolarionService);
pdfTemplateProcessor = new PdfTemplateProcessor();
@Inject
public PdfConverter(PdfExporterPolarionService pdfExporterPolarionService, HeaderFooterSettings headerFooterSettings, CssSettings cssSettings, PlaceholderProcessor placeholderProcessor, VelocityEvaluator velocityEvaluator, CoverPageProcessor coverPageProcessor, WeasyPrintServiceConnector weasyPrintServiceConnector, HtmlProcessor htmlProcessor, PdfTemplateProcessor pdfTemplateProcessor) {
this.pdfExporterPolarionService = pdfExporterPolarionService;
this.headerFooterSettings = headerFooterSettings;
this.cssSettings = cssSettings;
this.placeholderProcessor = placeholderProcessor;
this.velocityEvaluator = velocityEvaluator;
this.coverPageProcessor = coverPageProcessor;
this.weasyPrintServiceConnector = weasyPrintServiceConnector;
this.htmlProcessor = htmlProcessor;
this.pdfTemplateProcessor = pdfTemplateProcessor;
}

public byte[] convertToPdf(@NotNull ExportParams exportParams, @Nullable ExportMetaInfoCallback metaInfoCallback) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
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 com.google.inject.Inject;
import com.polarion.alm.shared.util.StringUtils;
import com.polarion.core.util.xml.CSSStyle;
import lombok.SneakyThrows;
Expand Down Expand Up @@ -147,6 +148,7 @@ public class HtmlProcessor {
private final HtmlLinksHelper httpLinksHelper;
private final PdfExporterPolarionService pdfExporterPolarionService;

@Inject
public HtmlProcessor(FileResourceProvider fileResourceProvider, LocalizationSettings localizationSettings, HtmlLinksHelper httpLinksHelper, PdfExporterPolarionService pdfExporterPolarionService) {
this.fileResourceProvider = fileResourceProvider;
this.localizationSettings = localizationSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import ch.sbb.polarion.extension.pdf_exporter.rest.model.WidthValidationResult;
import ch.sbb.polarion.extension.pdf_exporter.rest.model.WorkItemRefData;
import ch.sbb.polarion.extension.pdf_exporter.rest.model.conversion.ExportParams;
import com.google.inject.Inject;
import lombok.SneakyThrows;
import org.apache.pdfbox.Loader;
import org.apache.pdfbox.pdmodel.PDDocument;
Expand All @@ -23,10 +24,7 @@ public class PdfValidationService {

private final PdfConverter pdfConverter;

public PdfValidationService() {
this.pdfConverter = new PdfConverter();
}

@Inject
public PdfValidationService(PdfConverter pdfConverter) {
this.pdfConverter = pdfConverter;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import ch.sbb.polarion.extension.generic.regex.RegexMatcher;
import ch.sbb.polarion.extension.pdf_exporter.util.FileResourceProvider;
import com.google.inject.Inject;

import java.util.LinkedHashMap;
import java.util.Map;
Expand All @@ -14,6 +15,7 @@ public class HtmlLinksHelper {

private final Set<LinkInternalizer> linkInliners;

@Inject
public HtmlLinksHelper(FileResourceProvider fileResourceProvider) {
this (Set.of(
new ExternalCssInternalizer(fileResourceProvider)
Expand Down

0 comments on commit da5533c

Please sign in to comment.