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