1 | package de.ugoe.cs.eventbench.jfc.commands;
|
---|
2 |
|
---|
3 | import java.io.File;
|
---|
4 | import java.security.InvalidParameterException;
|
---|
5 | import java.util.Collection;
|
---|
6 | import java.util.List;
|
---|
7 |
|
---|
8 | import de.ugoe.cs.eventbench.CommandHelpers;
|
---|
9 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
10 | import de.ugoe.cs.eventbench.jfc.JFCLogParser;
|
---|
11 | import de.ugoe.cs.eventbench.jfc.data.JFCEvent;
|
---|
12 | import de.ugoe.cs.util.console.Command;
|
---|
13 | import de.ugoe.cs.util.console.Console;
|
---|
14 |
|
---|
15 | /**
|
---|
16 | * <p>
|
---|
17 | * Command that tries to parse all files in a folder as if they were log files
|
---|
18 | * generated by the JFCMonitor. The result is one set of sequences for all files
|
---|
19 | * (not one set of sequences for each file!).
|
---|
20 | * </p>
|
---|
21 | *
|
---|
22 | * @author Steffen Herbold
|
---|
23 | * @version 1.0
|
---|
24 | */
|
---|
25 | public class CMDparseDirJFC implements Command {
|
---|
26 |
|
---|
27 | /*
|
---|
28 | * (non-Javadoc)
|
---|
29 | *
|
---|
30 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
31 | */
|
---|
32 | @Override
|
---|
33 | public void run(List<Object> parameters) {
|
---|
34 | String path;
|
---|
35 | String sequencesName = "sequences";
|
---|
36 |
|
---|
37 | try {
|
---|
38 | path = (String) parameters.get(0);
|
---|
39 | if (parameters.size() >= 2) {
|
---|
40 | sequencesName = (String) parameters.get(1);
|
---|
41 | }
|
---|
42 | } catch (Exception e) {
|
---|
43 | throw new InvalidParameterException();
|
---|
44 | }
|
---|
45 |
|
---|
46 | File folder = new File(path);
|
---|
47 | if (!folder.isDirectory()) {
|
---|
48 | Console.printerrln(path + " is not a directory");
|
---|
49 | return;
|
---|
50 | }
|
---|
51 |
|
---|
52 | JFCLogParser parser = new JFCLogParser();
|
---|
53 |
|
---|
54 | String absolutPath = folder.getAbsolutePath();
|
---|
55 | for (String filename : folder.list()) {
|
---|
56 | String source = absolutPath + "/" + filename;
|
---|
57 | Console.traceln("Processing file: " + source);
|
---|
58 |
|
---|
59 | parser.parseFile(source);
|
---|
60 | }
|
---|
61 |
|
---|
62 | Collection<List<JFCEvent>> sequences = parser.getSequences();
|
---|
63 |
|
---|
64 | if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
|
---|
65 | CommandHelpers.dataOverwritten(sequencesName);
|
---|
66 | }
|
---|
67 |
|
---|
68 | }
|
---|
69 |
|
---|
70 | /*
|
---|
71 | * (non-Javadoc)
|
---|
72 | *
|
---|
73 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
74 | */
|
---|
75 | @Override
|
---|
76 | public void help() {
|
---|
77 | Console.println("Usage: parseDirJFC <path> {<sequencesName>}");
|
---|
78 | }
|
---|
79 |
|
---|
80 | }
|
---|