source: main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/UserTracker.java

Last change on this file was 38769, checked in by anupama, 2 months ago

Following Dr Bainbridge's task description and with his fixes: changes to get the Networked Derby Driver that we now use to use the shorter URL to the usersDB of the form jdbc:derby://derbyserver:derbyport/usersDB, instead of the full path to usersDB after the protocol. It needed setting derby.system.home JAVA_OPT when starting up the derby server in build.xml, then the tomcat greenstone3.xml file needed to refer to the shorter URL. Then classes that used to pass the full path need to pass the shorter form. And those classes called from the comandline with full usersDB path, like ModifyUsersDB, needed to now pass the shorter path. So build.xml needed further updating when calling ModifyUsersDB. The full path still works (for example, you can connect to both the original jdbc:derby URL and the shorter URL now from Squirrel SQL Client now), but the code now uses the shorter path.

  • Property svn:executable set to *
File size: 4.8 KB
Line 
1package org.greenstone.gsdl3.service;
2
3import java.io.File;
4import java.io.Serializable;
5import java.util.ArrayList;
6import java.util.HashMap;
7
8import org.apache.log4j.Logger;
9import org.greenstone.gsdl3.util.DerbyWrapper;
10import org.greenstone.gsdl3.util.GSXML;
11import org.greenstone.gsdl3.util.XMLConverter;
12import org.greenstone.util.GlobalProperties;
13import org.w3c.dom.Document;
14import org.w3c.dom.Element;
15
16public class UserTracker extends ServiceRack
17{
18 static Logger logger = Logger.getLogger(org.greenstone.gsdl3.service.UserTracker.class.getName());
19
20 /**************************************************
21 * The list of services the User Tracker supports *
22 *************************************************/
23 protected static final String RECORD_USER_ACTION = "RecordUserAction";
24 protected static final String GET_ACTIVITY_ON_PAGE = "GetActivityOnPage";
25 /*************************************************/
26
27 String[] services = { RECORD_USER_ACTION, GET_ACTIVITY_ON_PAGE };
28
29 // the parameters these services use
30 protected static final String USER_PARAM = "username";
31 protected static final String COLLECTION_PARAM = "collection";
32 protected static final String SITE_PARAM = "site";
33 protected static final String OID_PARAM = "oid";
34 protected static final String ACTION_PARAM = "action";
35
36 /** configure this service */
37 public boolean configure(Element info, Element extra_info)
38 {
39 if (!super.configure(info, extra_info))
40 {
41 return false;
42 }
43
44 logger.info("Configuring UserTracker...");
45 this.config_info = info;
46
47 for (int i = 0; i < services.length; i++)
48 {
49 Element service = this.desc_doc.createElement(GSXML.SERVICE_ELEM);
50 service.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
51 service.setAttribute(GSXML.NAME_ATT, services[i]);
52 this.short_service_info.appendChild(service);
53 }
54
55 // should any of the params be saved to the session?
56 // assuming not at this stage. But if they do need to be, then
57 // sture them here in save_params.
58 // this.save_params.add(XXX_PARAM);
59 return true;
60 }
61
62 protected Element getServiceDescription(Document doc, String service_id, String lang, String subset)
63 {
64 for (int i = 0; i < services.length; i++)
65 {
66 if (service_id.equals(services[i]))
67 {
68 Element service_elem = doc.createElement(GSXML.SERVICE_ELEM);
69 service_elem.setAttribute(GSXML.TYPE_ATT, GSXML.SERVICE_TYPE_RETRIEVE);
70 service_elem.setAttribute(GSXML.NAME_ATT, services[i]);
71 return service_elem;
72 }
73 }
74
75 return null;
76 }
77
78 protected synchronized Element processRecordUserAction(Element request)
79 {
80 Document result_doc = XMLConverter.newDOM();
81 Element result = GSXML.createBasicResponse(result_doc, RECORD_USER_ACTION);
82
83 Element paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
84 if (paramList == null)
85 {
86 GSXML.addError(result, "Request has no parameter list");
87 return result;
88 }
89
90 HashMap<String, Serializable> params = GSXML.extractParams(paramList, true);
91 String username = (String) params.get(USER_PARAM);
92 String collection = (String) params.get(COLLECTION_PARAM);
93 String site = (String) params.get(SITE_PARAM);
94 String oid = (String) params.get(OID_PARAM);
95 String action = (String) params.get(ACTION_PARAM);
96
97 DerbyWrapper database = new DerbyWrapper(DerbyWrapper.USERSDB_DIR);
98 database.addUserAction(username, site, collection, oid, action);
99 database.closeDatabase();
100
101 return result;
102 }
103
104 protected synchronized Element processGetActivityOnPage(Element request)
105 {
106 Document result_doc = XMLConverter.newDOM();
107 Element result = GSXML.createBasicResponse(result_doc, GET_ACTIVITY_ON_PAGE);
108 try
109 {
110
111 Element paramList = (Element) GSXML.getChildByTagName(request, GSXML.PARAM_ELEM + GSXML.LIST_MODIFIER);
112 if (paramList == null)
113 {
114 GSXML.addError(result, "Request has no parameter list");
115 return result;
116 }
117
118 HashMap<String, Serializable> params = GSXML.extractParams(paramList, true);
119 String collection = (String) params.get(COLLECTION_PARAM);
120 String site = (String) params.get(SITE_PARAM);
121 String oid = (String) params.get(OID_PARAM);
122
123 DerbyWrapper database = new DerbyWrapper(DerbyWrapper.USERSDB_DIR);
124 ArrayList<HashMap<String, String>> userActions = database.getMostRecentUserActions(site, collection, oid);
125
126 Element userList = result_doc.createElement("userList");
127 for (HashMap<String, String> userAction : userActions)
128 {
129 Element user = result_doc.createElement("user");
130 user.setAttribute("username", userAction.get("username"));
131 user.setAttribute("action", userAction.get("action"));
132 userList.appendChild(user);
133 }
134 result.appendChild(userList);
135 }
136 catch (Exception ex)
137 {
138 ex.printStackTrace();
139 }
140 return result;
141 }
142}
Note: See TracBrowser for help on using the repository browser.