1 | // Copyright 2012 Georg-August-Universität Göttingen, Germany |
---|
2 | // |
---|
3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
---|
4 | // you may not use this file except in compliance with the License. |
---|
5 | // You may obtain a copy of the License at |
---|
6 | // |
---|
7 | // http://www.apache.org/licenses/LICENSE-2.0 |
---|
8 | // |
---|
9 | // Unless required by applicable law or agreed to in writing, software |
---|
10 | // distributed under the License is distributed on an "AS IS" BASIS, |
---|
11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
---|
12 | // See the License for the specific language governing permissions and |
---|
13 | // limitations under the License. |
---|
14 | |
---|
15 | package de.ugoe.cs.autoquest.plugin.jfc.commands; |
---|
16 | |
---|
17 | import java.util.Collection; |
---|
18 | import java.util.HashMap; |
---|
19 | import java.util.List; |
---|
20 | |
---|
21 | import de.ugoe.cs.autoquest.CommandHelpers; |
---|
22 | import de.ugoe.cs.autoquest.eventcore.Event; |
---|
23 | import de.ugoe.cs.autoquest.eventcore.guimodel.GUIModel; |
---|
24 | import de.ugoe.cs.autoquest.eventcore.guimodel.IGUIElement; |
---|
25 | import de.ugoe.cs.autoquest.plugin.jfc.JFCSimplifiedLogParser; |
---|
26 | import de.ugoe.cs.autoquest.plugin.jfc.guimodel.JFCGUIElementSpec; |
---|
27 | import de.ugoe.cs.util.console.Command; |
---|
28 | import de.ugoe.cs.util.console.Console; |
---|
29 | import de.ugoe.cs.util.console.GlobalDataContainer; |
---|
30 | |
---|
31 | /** |
---|
32 | * <p> |
---|
33 | * Command to generate sessions in which the JFCGUIElements contain a special index that is required |
---|
34 | * to replay the sequences with Jacareto. |
---|
35 | * </p> |
---|
36 | * |
---|
37 | * @author Daniel May |
---|
38 | * @version 1.0 |
---|
39 | */ |
---|
40 | public class CMDparseJFCwithJacaretoIndices implements Command { |
---|
41 | |
---|
42 | @Override |
---|
43 | public void run(List<Object> parameters) { |
---|
44 | String filename; |
---|
45 | String sequencesName = "sequences"; |
---|
46 | try { |
---|
47 | filename = (String) parameters.get(0); |
---|
48 | if (parameters.size() >= 2) { |
---|
49 | sequencesName = (String) parameters.get(1); |
---|
50 | } |
---|
51 | } |
---|
52 | catch (Exception e) { |
---|
53 | throw new IllegalArgumentException(); |
---|
54 | } |
---|
55 | |
---|
56 | JFCSimplifiedLogParser parser = new JFCSimplifiedLogParser(); |
---|
57 | |
---|
58 | try { |
---|
59 | parser.parseFile(filename); |
---|
60 | } |
---|
61 | catch (Exception e) { |
---|
62 | Console.printerrln("Could not parse " + filename + ": " + e.getMessage()); |
---|
63 | return; |
---|
64 | } |
---|
65 | |
---|
66 | Collection<List<Event>> sequences = parser.getSequences(); |
---|
67 | GUIModel targets = parser.getGuiModel(); |
---|
68 | |
---|
69 | generateJacaretoIndices(targets.getRootElements(), targets); |
---|
70 | |
---|
71 | if (GlobalDataContainer.getInstance().addData(sequencesName, sequences)) { |
---|
72 | CommandHelpers.dataOverwritten(sequencesName); |
---|
73 | } |
---|
74 | |
---|
75 | if (GlobalDataContainer.getInstance().addData(sequencesName + "_targets", targets)) { |
---|
76 | CommandHelpers.dataOverwritten(sequencesName + "_targets"); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | @Override |
---|
81 | public String help() { |
---|
82 | return "parseJFCwithJacaretoIndices <filename> {<sequences>}"; |
---|
83 | } |
---|
84 | |
---|
85 | private void generateJacaretoIndices(List<IGUIElement> elements, GUIModel targets) { |
---|
86 | HashMap<String, Integer> typeCount = new HashMap<>(); |
---|
87 | |
---|
88 | for (IGUIElement child : elements) { |
---|
89 | String type = child.getSpecification().getType(); |
---|
90 | Integer count = typeCount.get(type); |
---|
91 | |
---|
92 | if (count == null) { |
---|
93 | count = 0; |
---|
94 | typeCount.put(type, count); |
---|
95 | } |
---|
96 | else { |
---|
97 | typeCount.put(type, ++count); |
---|
98 | } |
---|
99 | |
---|
100 | ((JFCGUIElementSpec) child.getSpecification()).setAltIndex(count); |
---|
101 | |
---|
102 | generateJacaretoIndices(targets.getChildren(child), targets); |
---|
103 | } |
---|
104 | } |
---|
105 | } |
---|