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 | }
|
---|
50 |
|
---|
51 | JFCLogParser parser = new JFCLogParser();
|
---|
52 |
|
---|
53 | String absolutPath = folder.getAbsolutePath();
|
---|
54 | for (String filename : folder.list()) {
|
---|
55 | String source = absolutPath + "/" + filename;
|
---|
56 | Console.traceln("Processing file: " + source);
|
---|
57 |
|
---|
58 | parser.parseFile(source);
|
---|
59 | }
|
---|
60 |
|
---|
61 | Collection<List<JFCEvent>> sequences = parser.getSequences();
|
---|
62 |
|
---|
63 | if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) {
|
---|
64 | CommandHelpers.dataOverwritten(sequencesName);
|
---|
65 | }
|
---|
66 |
|
---|
67 | }
|
---|
68 |
|
---|
69 | /*
|
---|
70 | * (non-Javadoc)
|
---|
71 | *
|
---|
72 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
73 | */
|
---|
74 | @Override
|
---|
75 | public void help() {
|
---|
76 | Console.println("Usage: parseDirJFC <path> {<sequencesName>}");
|
---|
77 | }
|
---|
78 |
|
---|
79 | }
|
---|