Skip to content

Commit

Permalink
Finished changes in docs
Browse files Browse the repository at this point in the history
  • Loading branch information
baubakg committed Oct 4, 2024
2 parents f4a71b4 + ac844b6 commit cb07dc6
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 26 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ The following dependency needs to be added to your pom file:
<dependency>
<groupId>com.adobe.campaign.tests</groupId>
<artifactId>log-parser</artifactId>
<version>1.0.10</version>
<version>1.11.1</version>
</dependency>
```
## Running the Log Parser
Expand Down Expand Up @@ -470,6 +470,9 @@ You can get a print out of the command line options by running the command with
All reports are stored in the directory `log-parser-reports/export/`.

## Changelog
### 1.11.1
- [#188](https://github.com/adobe/log-parser/issues/188) We solved problems with exporting when the directory hierarchy is not present.

### 1.11.0
- **(new feature)** [#10](https://github.com/adobe/log-parser/issues/10) We now have an executable for the log-parser. You can perform a log parsing using the command line. For more information please read the section on [Command-line Execution of the Log-Parser](#command-line-execution-of-the-log-parser).
- **(new feature)** [#127](https://github.com/adobe/log-parser/issues/127) You can now compare two LogData Objects. This is a light compare that checks that for a given key, if it is absent, added or changes in frequency.
Expand Down
Binary file modified diagrams/Log_Parser-Processes.drawio.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 10 additions & 1 deletion diagrams/Log_Parser.drawio
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<mxfile host="Electron" modified="2024-08-06T21:48:41.274Z" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/21.5.0 Chrome/112.0.5615.204 Electron/24.5.1 Safari/537.36" etag="IxRyfKH6_R-m68x0ZdZq" version="21.5.0" type="device" pages="3">
<mxfile host="Electron" modified="2024-10-04T10:09:17.651Z" agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) draw.io/21.5.0 Chrome/112.0.5615.204 Electron/24.5.1 Safari/537.36" etag="vQgtGz6c1c2_e02nvOvv" version="21.5.0" type="device" pages="3">
<diagram id="GF7U1PxuMcIbTAeL1bwN" name="Classes">
<mxGraphModel dx="1114" dy="824" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" background="#FFFFFF" math="0" shadow="0">
<root>
Expand Down Expand Up @@ -310,6 +310,15 @@
<mxCell id="GjdqCvJivDHMyhRgbLtD-0" value="enrich" style="strokeWidth=2;html=1;shape=mxgraph.flowchart.terminator;whiteSpace=wrap;shadow=1;labelBackgroundColor=#FFFFFF;" parent="dgaH53lybmkEFGB52cs7-1" vertex="1">
<mxGeometry x="970" y="366" width="100" height="60" as="geometry" />
</mxCell>
<mxCell id="Optskv5YCS5HUoDn0TRo-0" value="JSON" style="shape=document;whiteSpace=wrap;html=1;boundedLbl=1;labelBackgroundColor=#FFFFFF;strokeColor=#000000;fillColor=#FFFFFF;fontSize=12;align=center;" vertex="1" parent="dgaH53lybmkEFGB52cs7-1">
<mxGeometry x="840" y="630" width="110" height="63" as="geometry" />
</mxCell>
<mxCell id="Optskv5YCS5HUoDn0TRo-1" value="" style="edgeStyle=orthogonalEdgeStyle;rounded=0;orthogonalLoop=1;jettySize=auto;html=1;exitX=1;exitY=0.75;exitDx=0;exitDy=0;entryX=0;entryY=0.25;entryDx=0;entryDy=0;dashed=1;" edge="1" parent="dgaH53lybmkEFGB52cs7-1" source="dgaH53lybmkEFGB52cs7-42" target="Optskv5YCS5HUoDn0TRo-0">
<mxGeometry relative="1" as="geometry">
<mxPoint x="730" y="282" as="sourcePoint" />
<mxPoint x="850" y="582" as="targetPoint" />
</mxGeometry>
</mxCell>
</root>
</mxGraphModel>
</diagram>
Expand Down
39 changes: 24 additions & 15 deletions src/main/java/com/adobe/campaign/tests/logparser/core/LogData.java
Original file line number Diff line number Diff line change
Expand Up @@ -415,20 +415,25 @@ public File exportLogDataToCSV(String in_fileName) {
*/
public File exportLogDataToCSV(Collection<String> in_headerSet, String in_csvFileName)
throws LogDataExportToFileException {
File l_exportFile = LogParserFileUtils.createNewFile(in_csvFileName);
File l_exportFile = null;
try {
l_exportFile = LogParserFileUtils.createNewFile(in_csvFileName);

try (CSVPrinter printer = new CSVPrinter(new FileWriter(l_exportFile), CSVFormat.DEFAULT)) {
printer.printRecord(in_headerSet);
try (CSVPrinter printer = new CSVPrinter(new FileWriter(l_exportFile), CSVFormat.DEFAULT)) {
printer.printRecord(in_headerSet);

for (StdLogEntry lt_entry : this.getEntries().values()) {
Map lt_values = lt_entry.fetchValueMapPrintable();
printer.printRecord(in_headerSet.stream().map(h -> lt_values.get(h)).collect(Collectors.toList()));
for (StdLogEntry lt_entry : this.getEntries().values()) {
Map lt_values = lt_entry.fetchValueMapPrintable();
printer.printRecord(in_headerSet.stream().map(h -> lt_values.get(h)).collect(Collectors.toList()));
}
}

} catch (IOException ex) {
throw new LogDataExportToFileException("Encountered error while exporting the log data to a CSV file.", ex);
}



return l_exportFile;
}

Expand Down Expand Up @@ -459,9 +464,10 @@ public File exportLogDataToHTML(String in_reportTitle, String in_htmlFileName) {
* @return an HTML file containing the LogData as a table
*/
public File exportLogDataToHTML(Collection<String> in_headerSet, String in_reportTitle, String in_htmlFileName) {
File l_exportFile = LogParserFileUtils.createNewFile(in_htmlFileName);
File l_exportFile;

try {
l_exportFile = LogParserFileUtils.createNewFile(in_htmlFileName);
StringBuilder sb = new StringBuilder();
sb.append(HTMLReportUtils.fetchSTDPageStart("diffTable.css"));
//Creating the overview report
Expand All @@ -485,7 +491,7 @@ public File exportLogDataToHTML(Collection<String> in_headerSet, String in_repor

FileUtils.writeStringToFile(l_exportFile, sb.toString(), "UTF-8");
} catch (IOException e) {
throw new LogDataExportToFileException("We were unable to write to the file " + l_exportFile.getPath());
throw new LogDataExportToFileException("We were unable to write to the file " + in_htmlFileName, e);
}

return l_exportFile;
Expand Down Expand Up @@ -535,15 +541,18 @@ public File exportLogDataToJSON(String in_jsonFileName) throws LogDataExportToFi
*/
public File exportLogDataToJSON(Collection<String> in_headerSet, String in_jsonFileName)
throws LogDataExportToFileException {
File l_exportFile = LogParserFileUtils.createNewFile(in_jsonFileName);
List<Map<String, String>> jsonList = new ArrayList<>();
jsonList.addAll(this.getEntries().values().stream().map(StdLogEntry::fetchValueMapPrintable)
.collect(Collectors.toList()));
File l_exportFile;

try {
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.writeValue(l_exportFile,
objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonList));
l_exportFile= LogParserFileUtils.createNewFile(in_jsonFileName);
List<Map<String, String>> jsonList = new ArrayList<>();
jsonList.addAll(this.getEntries().values().stream().map(StdLogEntry::fetchValueMapPrintable)
.collect(Collectors.toList()));


ObjectMapper objectMapper = new ObjectMapper();
objectMapper.writeValue(l_exportFile,
objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(jsonList));
} catch (IOException e) {
throw new LogDataExportToFileException("Encountered error while exporting the log data to a JSON file.", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,11 @@ public static <T extends StdLogEntry> File generateDiffReport(LogData<T> in_logD
public static <T extends StdLogEntry> File generateDiffReport(Map<String, LogDataComparison<T>> in_comparisonReport,
List<String> in_headers, String in_reportName) {
StringBuilder sb = new StringBuilder();
File l_exportFile = LogParserFileUtils.createNewFile(in_reportName + ".html");

File l_exportFile = null;
String l_exportFilePath = in_reportName + ".html";
try {
l_exportFile = LogParserFileUtils.createNewFile(l_exportFilePath);
l_exportFilePath = l_exportFile.getPath();
sb.append(HTMLReportUtils.fetchSTDPageStart("diffTable.css"));

//Creating the overview report
Expand Down Expand Up @@ -319,8 +321,9 @@ public static <T extends StdLogEntry> File generateDiffReport(Map<String, LogDat
sb.append("</html>");

FileUtils.writeStringToFile(l_exportFile, sb.toString(), "UTF-8");

} catch (IOException e) {
throw new LogDataExportToFileException("We were unable to write to the file "+ l_exportFile.getPath());
throw new LogDataExportToFileException("We were unable to write to the file "+ l_exportFilePath);
}
return l_exportFile;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
import org.apache.logging.log4j.Logger;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class LogParserFileUtils {
public static final String LOG_PARSER_EXPORTS = "log_parser_output/exports";
Expand All @@ -34,8 +37,8 @@ public static void cleanFile(File in_file) {
* @param in_fileName a file name
* @return the file object
*/
public static File createFile(String in_fileName) {

public static File createFile(String in_fileName) throws IOException {
Files.createDirectories(Paths.get(LOG_PARSER_EXPORTS));
return new File(LOG_PARSER_EXPORTS,in_fileName);
}

Expand All @@ -44,7 +47,7 @@ public static File createFile(String in_fileName) {
* @param in_fileName A file name
* @return a file object which is completely new and empty
*/
public static File createNewFile(String in_fileName) {
public static File createNewFile(String in_fileName) throws IOException {
File lr_file = createFile(in_fileName);
cleanFile(lr_file);
return lr_file;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.*;

Expand All @@ -35,6 +35,18 @@

public class LogDataTest {

@BeforeMethod(alwaysRun = true)
@AfterClass
public void CleanUp() throws IOException {
File l_stdOutPutFile = new File(LogParser.OUTPUT_ROOT);

if (l_stdOutPutFile.exists()) {
FileUtils.deleteDirectory(l_stdOutPutFile);
}

}


/**
* Testing that we correctly create a cube
* <p>
Expand Down Expand Up @@ -1397,7 +1409,9 @@ public void testExportDataFileExists()

//Create the file so it is deleted
File l_duplicateFile = new File(LogParserFileUtils.LOG_PARSER_EXPORTS, l_fileNameToExpect);
l_duplicateFile.createNewFile();
//Files.
//l_duplicateFile.createNewFile();
LogParserFileUtils.createNewFile(LogParserFileUtils.LOG_PARSER_EXPORTS+"/"+l_fileNameToExpect);

assertThat("We should have the key for amcDataSource",
l_logData.getEntries().containsKey(l_searchItem1));
Expand Down

0 comments on commit cb07dc6

Please sign in to comment.