1 | package de.ugoe.cs.eventbench.web.commands;
|
---|
2 |
|
---|
3 | import java.io.FileNotFoundException;
|
---|
4 | import java.io.IOException;
|
---|
5 | import java.security.InvalidParameterException;
|
---|
6 | import java.text.ParseException;
|
---|
7 | import java.util.Collection;
|
---|
8 | import java.util.List;
|
---|
9 |
|
---|
10 | import de.ugoe.cs.eventbench.CommandHelpers;
|
---|
11 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
12 | import de.ugoe.cs.eventbench.web.WeblogParser;
|
---|
13 | import de.ugoe.cs.eventbench.web.data.WebEvent;
|
---|
14 | import de.ugoe.cs.util.console.Command;
|
---|
15 | import de.ugoe.cs.util.console.Console;
|
---|
16 |
|
---|
17 | /**
|
---|
18 | * <p>
|
---|
19 | * Command to load sessions from a web log.
|
---|
20 | * </p>
|
---|
21 | *
|
---|
22 | * @author Steffen Herbold
|
---|
23 | * @version 1.0
|
---|
24 | */
|
---|
25 | public class CMDloadWebSequences 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 | if (parameters.size() < 1) {
|
---|
35 | throw new InvalidParameterException();
|
---|
36 | }
|
---|
37 | String source;
|
---|
38 | String sequencesName;
|
---|
39 | String serverUrl = null;
|
---|
40 | int timeout = -1;
|
---|
41 | int minLength = -1;
|
---|
42 | int maxLength = -1;
|
---|
43 | boolean generateFrequentUsers = false;
|
---|
44 | int frequentUserThreshold = 20;
|
---|
45 | try {
|
---|
46 | source = (String) parameters.get(0);
|
---|
47 | sequencesName = (String) parameters.get(1);
|
---|
48 | if (parameters.size() >= 3) {
|
---|
49 | serverUrl = (String) parameters.get(2);
|
---|
50 | }
|
---|
51 | if (parameters.size() >= 6) {
|
---|
52 | timeout = Integer.parseInt((String) parameters.get(3));
|
---|
53 | minLength = Integer.parseInt((String) parameters.get(4));
|
---|
54 | maxLength = Integer.parseInt((String) parameters.get(5));
|
---|
55 | }
|
---|
56 | if (parameters.size() >= 8) {
|
---|
57 | generateFrequentUsers = Boolean
|
---|
58 | .parseBoolean((String) parameters.get(6));
|
---|
59 | frequentUserThreshold = Integer.parseInt((String) parameters
|
---|
60 | .get(7));
|
---|
61 | }
|
---|
62 | } catch (Exception e) {
|
---|
63 | throw new InvalidParameterException();
|
---|
64 | }
|
---|
65 |
|
---|
66 | WeblogParser parser = new WeblogParser();
|
---|
67 | if (serverUrl != null) {
|
---|
68 | parser.setUrl(serverUrl);
|
---|
69 | }
|
---|
70 | if (timeout != -1) {
|
---|
71 | parser.setTimeout(timeout);
|
---|
72 | parser.setMinLength(minLength);
|
---|
73 | parser.setMaxLength(maxLength);
|
---|
74 | }
|
---|
75 | if (generateFrequentUsers) {
|
---|
76 | parser.setFrequentUserThreshold(frequentUserThreshold);
|
---|
77 | }
|
---|
78 | try {
|
---|
79 | parser.parseFile(source);
|
---|
80 | } catch (FileNotFoundException e) {
|
---|
81 | Console.printerrln(e.getMessage());
|
---|
82 | } catch (IOException e) {
|
---|
83 | Console.printerrln(e.getMessage());
|
---|
84 | } catch (ParseException e) {
|
---|
85 | Console.printerrln("Invalid format of date stamps.");
|
---|
86 | Console.printerrln(e.getMessage());
|
---|
87 | }
|
---|
88 |
|
---|
89 | if (GlobalDataContainer.getInstance().addData(sequencesName,
|
---|
90 | parser.getSequences())) {
|
---|
91 | CommandHelpers.dataOverwritten(sequencesName);
|
---|
92 | }
|
---|
93 | if (generateFrequentUsers) {
|
---|
94 | List<String> frequentUserIDs = parser.getFrequentUsers();
|
---|
95 | List<Collection<List<WebEvent>>> frequentUserSessions = parser
|
---|
96 | .getFrequentUserSequences();
|
---|
97 | for (int i = 0; i < frequentUserIDs.size(); i++) {
|
---|
98 | String seqName = sequencesName + "_" + frequentUserIDs.get(i);
|
---|
99 | if (GlobalDataContainer.getInstance().addData(seqName,
|
---|
100 | frequentUserSessions.get(i))) {
|
---|
101 | CommandHelpers.dataOverwritten(seqName);
|
---|
102 | }
|
---|
103 | }
|
---|
104 | }
|
---|
105 | }
|
---|
106 |
|
---|
107 | /*
|
---|
108 | * (non-Javadoc)
|
---|
109 | *
|
---|
110 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
111 | */
|
---|
112 | @Override
|
---|
113 | public void help() {
|
---|
114 | Console.println("Usage: loadWebSequences <filename> <sequencesName> {<serverUrl>} {<timeout> <minSessionLength> <maxSessionLength>} {<generateFrequentUsers> <frequentUserThreshold>}");
|
---|
115 | }
|
---|
116 |
|
---|
117 | }
|
---|