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