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 | String sequencesName = (String) parameters.get(1);
|
---|
36 | String serverUrl = null;
|
---|
37 | int timeout = -1;
|
---|
38 | int minLength = -1;
|
---|
39 | int maxLength = -1;
|
---|
40 | if( parameters.size()>=3 ) {
|
---|
41 | serverUrl = (String) parameters.get(2);
|
---|
42 | }
|
---|
43 | if (parameters.size() >= 5) {
|
---|
44 | timeout = Integer.parseInt((String) parameters.get(3));
|
---|
45 | minLength = Integer.parseInt((String) parameters.get(4));
|
---|
46 | maxLength = Integer.parseInt((String) parameters.get(5));
|
---|
47 | }
|
---|
48 |
|
---|
49 | WeblogParser parser = new WeblogParser();
|
---|
50 | if( serverUrl!=null ) {
|
---|
51 | parser.setUrl(serverUrl);
|
---|
52 | }
|
---|
53 | if (timeout != -1) {
|
---|
54 | parser.setTimeout(timeout);
|
---|
55 | parser.setMinLength(minLength);
|
---|
56 | parser.setMaxLength(maxLength);
|
---|
57 | }
|
---|
58 | try {
|
---|
59 | parser.parseFile(source);
|
---|
60 | } catch (FileNotFoundException e) {
|
---|
61 | Console.println(e.getMessage());
|
---|
62 | } catch (IOException e) {
|
---|
63 | Console.println(e.getMessage());
|
---|
64 | } catch (ParseException e) {
|
---|
65 | Console.println("Invalid format of date stamps.");
|
---|
66 | Console.println(e.getMessage());
|
---|
67 | }
|
---|
68 |
|
---|
69 | if (GlobalDataContainer.getInstance().addData(sequencesName,
|
---|
70 | parser.getSequences())) {
|
---|
71 | Console.traceln("Old data \"" + sequencesName + "\" overwritten");
|
---|
72 | }
|
---|
73 | }
|
---|
74 |
|
---|
75 | /*
|
---|
76 | * (non-Javadoc)
|
---|
77 | *
|
---|
78 | * @see de.ugoe.cs.util.console.Command#help()
|
---|
79 | */
|
---|
80 | @Override
|
---|
81 | public void help() {
|
---|
82 | Console.println("Usage: loadSessionsFromClickstream <filename> <sequencesName> {<serverUrl>} {<timeout> <minSessionLength> <maxSessionLength>}");
|
---|
83 | }
|
---|
84 |
|
---|
85 | }
|
---|