001package com.credibledoc.substitution.reporting.report.document;
002
003import com.credibledoc.combiner.node.file.NodeFile;
004import com.credibledoc.enricher.printable.Printable;
005import com.credibledoc.substitution.reporting.report.Report;
006import com.credibledoc.substitution.reporting.reportdocument.ReportDocument;
007import com.credibledoc.substitution.reporting.reportdocument.ReportDocumentType;
008
009import java.io.PrintWriter;
010import java.io.Writer;
011import java.util.ArrayList;
012import java.util.LinkedHashSet;
013import java.util.List;
014import java.util.Set;
015import java.util.function.Consumer;
016
017/**
018 * Contains a state of a single generated report document.
019 *
020 * @author Kyrylo Semenko
021 */
022public class Document implements ReportDocument {
023
024    /**
025     * {@link Writer} of the report document
026     */
027    private PrintWriter printWriter;
028
029    /**
030     * One report may have more files, for example application.0.log.expanded, application.1.log.expanded and so on.
031     */
032    private int fileNumber;
033
034    /**
035     * This method will be called as the last method before closing of a {@link Document} file
036     */
037    private Consumer<ReportDocument> footerMethod;
038
039    /**
040     * Transformed lines prepared to print out, for example PlantUml lines
041     */
042    private List<String> cacheLines;
043
044    /**
045     * A {@link ReportDocumentType} of this {@link Document}
046     */
047    private Class<? extends ReportDocumentType> reportDocumentType;
048
049    /**
050     * Contains {@link NodeFile}s this {@link Document} obtains data from.
051     */
052    private Set<NodeFile> nodeFiles;
053
054    /**
055     * The {@link Report} this {@link Document} belongs to
056     */
057    private Report report;
058
059    /**
060     * If the {@link Printable#checkAllLineProcessors()} is 'false', only the first applicable
061     * {@link com.credibledoc.enricher.line.LineProcessor}
062     * will be processed. Else all applicable line processors will be processed.
063     */
064    private boolean checkAllLineProcessors;
065
066    public Document() {
067        fileNumber = 1;
068        cacheLines = new ArrayList<>();
069        nodeFiles = new LinkedHashSet<>();
070    }
071
072    @Override
073    public String toString() {
074        return "Document{" +
075            ", fileNumber=" + fileNumber +
076            ", footerMethod=" + footerMethod +
077            ", cacheLines=" + cacheLines +
078            ", reportDocumentType=" + reportDocumentType +
079            ", nodeFiles=" + nodeFiles +
080            ", report=" + report +
081            ", checkAllLineProcessors=" + checkAllLineProcessors +
082            '}';
083    }
084
085    @Override
086    public PrintWriter getPrintWriter() {
087        return printWriter;
088    }
089
090    /**
091     * @param printWriter see the {@link Document#printWriter} field
092     */
093    public void setPrintWriter(PrintWriter printWriter) {
094        this.printWriter = printWriter;
095    }
096
097    /**
098     * @return The {@link Document#footerMethod} field
099     */
100    public Consumer<ReportDocument> getFooterMethod() {
101        return footerMethod;
102    }
103
104    /**
105     * @param footerMethod see the {@link Document#footerMethod} field
106     */
107    public void setFooterMethod(Consumer<ReportDocument> footerMethod) {
108        this.footerMethod = footerMethod;
109    }
110
111    @Override
112    public List<String> getCacheLines() {
113        return cacheLines;
114    }
115
116    /**
117     * @param cacheLines see the {@link Document#cacheLines} field
118     */
119    public void setCacheLines(List<String> cacheLines) {
120        this.cacheLines = cacheLines;
121    }
122
123    /**
124     * @return The {@link #reportDocumentType} field value.
125     */
126    public Class<? extends ReportDocumentType> getReportDocumentType() {
127        return reportDocumentType;
128    }
129
130    /**
131     * @param reportDocumentType see the {@link #reportDocumentType} field description.
132     */
133    public void setReportDocumentType(Class<? extends ReportDocumentType> reportDocumentType) {
134        this.reportDocumentType = reportDocumentType;
135    }
136
137    /**
138     * @return The {@link #nodeFiles} field value.
139     */
140    public Set<NodeFile> getNodeFiles() {
141        return nodeFiles;
142    }
143
144    /**
145     * @param nodeFiles see the {@link #nodeFiles} field
146     */
147    public void setNodeFiles(Set<NodeFile> nodeFiles) {
148        this.nodeFiles = nodeFiles;
149    }
150
151    /**
152     * @return The {@link #report} field value.
153     */
154    public Report getReport() {
155        return report;
156    }
157
158    /**
159     * @param report see the {@link #report} field description.
160     */
161    public void setReport(Report report) {
162        this.report = report;
163    }
164
165    /**
166     * @return The {@link #checkAllLineProcessors} field value.
167     */
168    public boolean checkAllLineProcessors() {
169        return checkAllLineProcessors;
170    }
171
172    /**
173     * @param checkAllLineProcessors see the {@link #checkAllLineProcessors} field description.
174     */
175    public void setCheckAllLineProcessors(boolean checkAllLineProcessors) {
176        this.checkAllLineProcessors = checkAllLineProcessors;
177    }
178}