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