001package com.credibledoc.substitution.doc.module.substitution.launching;
002
003import com.credibledoc.enricher.line.LineProcessor;
004import com.credibledoc.enricher.line.LineProcessorService;
005import com.credibledoc.substitution.core.placeholder.Placeholder;
006import com.credibledoc.substitution.reporting.reportdocument.ReportDocument;
007import com.credibledoc.substitution.reporting.reportdocument.ReportDocumentType;
008import com.credibledoc.substitution.reporting.reportdocument.creator.ReportDocumentCreator;
009import lombok.NonNull;
010import lombok.RequiredArgsConstructor;
011import lombok.extern.slf4j.Slf4j;
012import org.springframework.context.ApplicationContext;
013import org.springframework.stereotype.Service;
014
015import javax.inject.Inject;
016import java.util.ArrayList;
017import java.util.List;
018
019/**
020 * Creates document with UML part of a {@link Placeholder}.
021 * @author Kyrylo Semenko
022 */
023@Service
024@RequiredArgsConstructor(onConstructor = @__(@Inject))
025@Slf4j
026public class LaunchingUmlReportService implements ReportDocumentCreator {
027
028    @NonNull
029    private final ApplicationContext applicationContext;
030
031    /**
032     * Create a stateful object of {@link ReportDocument} type.
033     *
034     * @return The stateful object, which {@link ReportDocument#getCacheLines()} method
035     * will be used for generation of PlantUML activity diagram.
036     */
037    public ReportDocument prepareReportDocument() {
038        ReportDocument reportDocument = new ReportDocument();
039        reportDocument.setReportDocumentType(ReportDocumentType.DOCUMENT_PART_UML);
040
041        List<LineProcessor> lineProcessors = new ArrayList<>();
042        lineProcessors.add(
043                new LineProcessor(
044                        applicationContext.getBean(LaunchingSearchCommand.class),
045                        applicationContext.getBean(LaunchingTransformer.class),
046                        reportDocument));
047        lineProcessors.add(
048                new LineProcessor(
049                        applicationContext.getBean(ConfigurationLoadingSearchCommand.class),
050                        applicationContext.getBean(ConfigurationLoadingTransformer.class),
051                        reportDocument));
052        lineProcessors.add(
053                new LineProcessor(
054                        applicationContext.getBean(ContentReplacedSearchCommand.class),
055                        applicationContext.getBean(ContentReplacedTransformer.class),
056                        reportDocument));
057        lineProcessors.add(
058            new LineProcessor(
059                applicationContext.getBean(FinishedSearchCommand.class),
060                applicationContext.getBean(FinishedTransformer.class),
061                reportDocument));
062
063        LineProcessorService.getInstance().getLineProcessors().addAll(lineProcessors);
064        log.info("Line processors prepared");
065        return reportDocument;
066    }
067
068    @Override
069    public ReportDocumentType getReportDocumentType() {
070        return ReportDocumentType.DOCUMENT_PART_UML;
071    }
072
073}