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