001// Generated by delombok at Sun Jun 30 16:31:41 CEST 2019 002package com.credibledoc.substitution.doc.module.substitution.activity; 003 004import com.credibledoc.combiner.log.buffered.LogBufferedReader; 005import com.credibledoc.substitution.core.placeholder.Placeholder; 006import com.credibledoc.enricher.printable.Printable; 007import com.credibledoc.substitution.doc.module.substitution.activity.anyline.AnyLineSearchCommand; 008import com.credibledoc.substitution.doc.module.substitution.logmessage.LogMessageService; 009import com.credibledoc.substitution.doc.module.substitution.report.UmlDiagramType; 010import com.credibledoc.substitution.reporting.report.document.Document; 011import com.credibledoc.substitution.reporting.reportdocument.ReportDocument; 012import com.credibledoc.substitution.reporting.reportdocument.ReportDocumentType; 013import com.credibledoc.substitution.reporting.reportdocument.creator.ReportDocumentCreator; 014import com.credibledoc.enricher.line.LineProcessor; 015import com.credibledoc.enricher.line.LineProcessorService; 016import com.credibledoc.enricher.transformer.Transformer; 017import lombok.NonNull; 018import org.springframework.context.ApplicationContext; 019import org.springframework.stereotype.Service; 020import javax.inject.Inject; 021import java.util.ArrayList; 022import java.util.List; 023 024/** 025 * Creates document with UML part of a {@link Placeholder}. 026 * @author Kyrylo Semenko 027 */ 028@Service 029public class ActivityUmlReportService implements ReportDocumentCreator { 030 @java.lang.SuppressWarnings("all") 031 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(ActivityUmlReportService.class); 032 @NonNull 033 private final ApplicationContext applicationContext; 034 035 /** 036 * Create a stateful object of {@link ReportDocument} type. 037 * 038 * @return The stateful object, which {@link ReportDocument#getCacheLines()} method 039 * will be used for generation of PlantUML activity diagram. 040 */ 041 public ReportDocument prepareReportDocument() { 042 Document document = new Document(); 043 document.setReportDocumentType(UmlDiagramType.class); 044 List<LineProcessor> lineProcessors = new ArrayList<>(); 045 lineProcessors.add(new LineProcessor(applicationContext.getBean(AnyLineSearchCommand.class), applicationContext.getBean(AnyLineTransformer.class), document)); 046 LineProcessorService.getInstance().getLineProcessors().addAll(lineProcessors); 047 log.info("Line processors prepared"); 048 return document; 049 } 050 051 @Override 052 public Class<? extends ReportDocumentType> getReportDocumentType() { 053 return UmlDiagramType.class; 054 } 055 056 057 /** 058 * Create a part of PlantUML activity diagram, for example 059 * <pre> 060 * |Swimlane1| 061 * :foo4; 062 * </pre> 063 * from the <i>04.03.2019 18:41:13.658|main|INFO |com.credibledoc.substitution.core.configuration.ConfigurationService - Properties loaded by ClassLoader from the resource: file..</i> line. 064 */ 065 @Service 066 public static class AnyLineTransformer implements Transformer { 067 @NonNull 068 public final LogMessageService logMessageService; 069 070 @Override 071 public String transform(Printable printable, List<String> multiLine, LogBufferedReader logBufferedReader) { 072 String currentSwimlane = parseClassName(multiLine.get(0)); 073 int maxRowLength = currentSwimlane.length() * 2 + currentSwimlane.length() / 2; 074 String message = logMessageService.parseMessage(multiLine.get(0), maxRowLength); 075 String result = "|" + currentSwimlane + "|" + LogMessageService.LINE_SEPARATOR + LogMessageService.FOUR_SPACES + ":" + message + ";" + LogMessageService.LINE_SEPARATOR; 076 printable.getCacheLines().add(result); 077 return null; 078 } 079 080 private String parseClassName(String line) { 081 int separatorIndex = line.indexOf(LogMessageService.LOG_SEPARATOR); 082 String firstPart = line.substring(0, separatorIndex); 083 int lastDotIndex = firstPart.lastIndexOf(LogMessageService.DOT); 084 return firstPart.substring(lastDotIndex + LogMessageService.DOT.length()); 085 } 086 087 @Inject 088 @java.lang.SuppressWarnings("all") 089 public AnyLineTransformer(@NonNull final LogMessageService logMessageService) { 090 if (logMessageService == null) { 091 throw new java.lang.NullPointerException("logMessageService"); 092 } 093 this.logMessageService = logMessageService; 094 } 095 } 096 097 @Inject 098 @java.lang.SuppressWarnings("all") 099 public ActivityUmlReportService(@NonNull final ApplicationContext applicationContext) { 100 if (applicationContext == null) { 101 throw new java.lang.NullPointerException("applicationContext"); 102 } 103 this.applicationContext = applicationContext; 104 } 105}