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 | public class CMDloadSessionsFromClickstream implements Command {
|
---|
16 |
|
---|
17 | @Override
|
---|
18 | public void run(List<Object> parameters) {
|
---|
19 | if( parameters.size() < 1 ) {
|
---|
20 | throw new InvalidParameterException();
|
---|
21 | }
|
---|
22 | String source = (String) parameters.get(0);
|
---|
23 | int timeout = -1;
|
---|
24 | int minLength = -1;
|
---|
25 | if( parameters.size() ==3 ) {
|
---|
26 | timeout = Integer.parseInt((String) parameters.get(1));
|
---|
27 | minLength = Integer.parseInt((String) parameters.get(2));
|
---|
28 | }
|
---|
29 |
|
---|
30 | WeblogParser parser = new WeblogParser();;
|
---|
31 | if( timeout!=-1 ) {
|
---|
32 | parser.setTimeout(timeout);
|
---|
33 | parser.setMinLength(minLength);
|
---|
34 | }
|
---|
35 | try {
|
---|
36 | parser.parseFile(source);
|
---|
37 | } catch (FileNotFoundException e) {
|
---|
38 | Console.println(e.getMessage());
|
---|
39 | } catch (IOException e) {
|
---|
40 | Console.println(e.getMessage());
|
---|
41 | } catch (ParseException e) {
|
---|
42 | Console.println("Invalid format of date stamps.");
|
---|
43 | Console.println(e.getMessage());
|
---|
44 | } catch (URISyntaxException e) {
|
---|
45 | Console.println("Invalid URI!");
|
---|
46 | Console.println(e.getMessage());
|
---|
47 | }
|
---|
48 |
|
---|
49 | if( GlobalDataContainer.getInstance().addData("sequences", parser.getSequences()) ) {
|
---|
50 | Console.traceln("Old data \"" + "sequences" + "\" overwritten");
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | @Override
|
---|
55 | public void help() {
|
---|
56 | Console.println("Usage: loadSessionsFromClickstream <filename> {<timeout> <minSessionLength>}");
|
---|
57 | }
|
---|
58 |
|
---|
59 | }
|
---|