001// Generated by delombok at Sat May 11 08:17:52 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 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 * 038 039 * @return The stateful object, which {@link ReportDocument#getCacheLines()} method 040 041 * will be used for generation of PlantUML activity diagram. 042 */ 043 public ReportDocument prepareReportDocument() { 044 ReportDocument reportDocument = new ReportDocument(); 045 reportDocument.setReportDocumentType(ReportDocumentType.DOCUMENT_PART_UML); 046 List<LineProcessor> lineProcessors = new ArrayList<>(); 047 lineProcessors.add(new LineProcessor(applicationContext.getBean(AnyLineSearchCommand.class), applicationContext.getBean(AnyLineTransformer.class), reportDocument)); 048 LineProcessorService.getInstance().getLineProcessors().addAll(lineProcessors); 049 log.info("Line processors prepared"); 050 return reportDocument; 051 } 052 053 @Override 054 public ReportDocumentType getReportDocumentType() { 055 return ReportDocumentType.DOCUMENT_PART_UML; 056 } 057 058 059 /** 060 * Create a part of PlantUML activity diagram, for example 061 062 * <pre> 063 064 * |Swimlane1| 065 066 * :foo4; 067 068 * </pre> 069 070 * 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. 071 */ 072 @Service 073 public static class AnyLineTransformer implements Transformer { 074 @NonNull 075 public final LogMessageService logMessageService; 076 077 @Override 078 public String transform(Deriving deriving, List<String> multiLine, LogBufferedReader logBufferedReader) { 079 String currentSwimlane = parseClassName(multiLine.get(0)); 080 int maxRowLength = currentSwimlane.length() * 2 + currentSwimlane.length() / 2; 081 String message = logMessageService.parseMessage(multiLine.get(0), maxRowLength); 082 String result = "|" + currentSwimlane + "|" + LogMessageService.LINE_SEPARATOR + LogMessageService.FOUR_SPACES + ":" + message + ";" + LogMessageService.LINE_SEPARATOR; 083 deriving.getCacheLines().add(result); 084 return null; 085 } 086 087 private String parseClassName(String line) { 088 int separatorIndex = line.indexOf(LogMessageService.LOG_SEPARATOR); 089 String firstPart = line.substring(0, separatorIndex); 090 int lastDotIndex = firstPart.lastIndexOf(LogMessageService.DOT); 091 return firstPart.substring(lastDotIndex + LogMessageService.DOT.length()); 092 } 093 094 @Inject 095 @java.lang.SuppressWarnings("all") 096 public AnyLineTransformer(@NonNull final LogMessageService logMessageService) { 097 if (logMessageService == null) { 098 throw new java.lang.NullPointerException("logMessageService"); 099 } 100 this.logMessageService = logMessageService; 101 } 102 } 103 104 @Inject 105 @java.lang.SuppressWarnings("all") 106 public ActivityUmlReportService(@NonNull final ApplicationContext applicationContext) { 107 if (applicationContext == null) { 108 throw new java.lang.NullPointerException("applicationContext"); 109 } 110 this.applicationContext = applicationContext; 111 } 112}