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.List;
|
---|
8 |
|
---|
9 | import de.ugoe.cs.eventbench.data.GlobalDataContainer;
|
---|
10 | import de.ugoe.cs.eventbench.web.WeblogParser;
|
---|
11 | import de.ugoe.cs.util.console.Command;
|
---|
12 | import de.ugoe.cs.util.console.Console;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | * <p>
|
---|
16 | * Command to load sessions from a web log.
|
---|
17 | * </p>
|
---|
18 | *
|
---|
19 | * @author Steffen Herbold
|
---|
20 | * @version 1.0
|
---|
21 | */
|
---|
22 | public class CMDloadSessionsFromClickstream implements Command {
|
---|
23 |
|
---|
24 | /*
|
---|
25 | * (non-Javadoc)
|
---|
26 | *
|
---|
27 | * @see de.ugoe.cs.util.console.Command#run(java.util.List)
|
---|
28 | */
|
---|
29 | @Override
|
---|
30 | public void run(List<Object> parameters) {
|
---|
31 | if (parameters.size() < 1) {
|
---|
32 | throw new InvalidParameterException();
|
---|
33 | }
|
---|
34 | String source = (String) parameters.get(0);
|
---|
35 | int timeout = -1;
|
---|
36 | int minLength = -1;
|
---|
37 | String sequencesName = "sequences";
|
---|
38 | if (parameters.size() >= 3) {
|
---|
39 | timeout = Integer.parseInt((String) parameters.get(1));
|
---|
40 | minLength = Integer.parseInt((String) parameters.get(2));
|
---|
41 | }
|
---|
42 | if (parameters.size() >= 4) {
|
---|
43 | sequencesName = (String) parameters.get(3);
|
---|
44 | }
|
---|
45 |
|
---|
46 | WeblogParser parser = new WeblogParser();
|
---|
47 | if (timeout != -1) {
|
---|
48 | parser.setTimeout(timeout);
|
---|
49 | parser.setMinLength(minLength);
|
---|
50 | }
|
---|
51 | try {
|
---|
52 | parser.parseFile(source);
|
---|
53 | } catch (FileNotFoundException e) {
|
---|
54 | Console.println(e.getMessage());
|
---|
55 | } catch (IOException e) {
|
---|
56 | Console.println(e.getMessage());
|
---|
57 | } catch (ParseException e) {
|
---|
58 | Console.println("Invalid format of date stamps.");
|
---|
59 | Console.println(e.getMessage());
|
---|
60 | }
|
---|
61 |
|
---|
62 | if (GlobalDataContainer.getInstance().addData(sequencesName,
|
---|
63 | parser.getSequences())) {
|
---|
64 | Console.traceln("Old data \"" + sequencesName + "\" overwritten");
|
---|
65 | }
|
---|
66 | }
|
---|
67 |
|
---|
68 | /*
|
---|
69 | * (non-Javadoc)
|
---|
70 | *
|
---|
71 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
72 | */
|
---|
73 | @Override
|
---|
74 | public void help() {
|
---|
75 | Console.println("Usage: loadSessionsFromClickstream <filename> {<timeout> <minSessionLength>} {<sequencesName>}");
|
---|
76 | }
|
---|
77 |
|
---|
78 | }
|
---|