| Line 1... |
Line 1... |
| 1 |
package in.shop2020.utils;
|
1 |
package in.shop2020.utils;
|
| 2 |
|
2 |
|
| 3 |
import in.shop2020.datalogger.EventType;
|
3 |
import in.shop2020.datalogger.EventType;
|
| - |
|
4 |
import in.shop2020.datalogger.SocialEventType;
|
| 4 |
import in.shop2020.datalogger.event.Event;
|
5 |
import in.shop2020.datalogger.event.Event;
|
| - |
|
6 |
import in.shop2020.datalogger.socialevent.SocialEvent;
|
| 5 |
|
7 |
|
| 6 |
import java.io.BufferedReader;
|
8 |
import java.io.BufferedReader;
|
| 7 |
import java.io.InputStreamReader;
|
9 |
import java.io.InputStreamReader;
|
| 8 |
import java.io.OutputStreamWriter;
|
10 |
import java.io.OutputStreamWriter;
|
| 9 |
import java.net.URL;
|
11 |
import java.net.URL;
|
| Line 19... |
Line 21... |
| 19 |
import org.json.JSONObject;
|
21 |
import org.json.JSONObject;
|
| 20 |
|
22 |
|
| 21 |
public class DataLogger {
|
23 |
public class DataLogger {
|
| 22 |
private static Logger log = Logger.getLogger(DataLogger.class);
|
24 |
private static Logger log = Logger.getLogger(DataLogger.class);
|
| 23 |
private static ExecutorService asyncDataLogger = Executors.newSingleThreadExecutor();
|
25 |
private static ExecutorService asyncDataLogger = Executors.newSingleThreadExecutor();
|
| - |
|
26 |
private static ExecutorService asyncSocialDataLogger = Executors.newSingleThreadExecutor();
|
| 24 |
private static ResourceBundle properties = ResourceBundle.getBundle(DataLogger.class.getName());
|
27 |
private static ResourceBundle properties = ResourceBundle.getBundle(DataLogger.class.getName());
|
| 25 |
private static String googleAppUrl = properties.getString("googleappurl");
|
28 |
private static String googleAppUrl = properties.getString("googleappurl");
|
| 26 |
|
29 |
|
| 27 |
public static void logDataOld(final EventType eType, final String sessionId, final long userId, final String email, String... logData) {
|
- |
|
| 28 |
final String strToWrite = StringUtils.join(logData, ", ");
|
- |
|
| 29 |
asyncDataLogger.execute(new Runnable() {
|
- |
|
| 30 |
@Override
|
- |
|
| 31 |
public void run() {
|
- |
|
| 32 |
log.info(eType.name() + ", " + sessionId + ", " + Long.toString(userId) + ", " + email + ", " + strToWrite);
|
- |
|
| 33 |
}
|
- |
|
| 34 |
});
|
- |
|
| 35 |
}
|
- |
|
| 36 |
|
- |
|
| 37 |
public static void logData(final EventType eType, final String sessionId, final long userId, final String email, final String... logData) {
|
30 |
public static void logData(final EventType eType, final String sessionId, final long userId, final String email, final String... logData) {
|
| 38 |
final String strToWrite = StringUtils.join(logData, ", ");
|
31 |
final String strToWrite = StringUtils.join(logData, ", ");
|
| 39 |
final Long time = (new Date()).getTime();
|
32 |
final Long time = (new Date()).getTime();
|
| 40 |
asyncDataLogger.execute(new Runnable() {
|
33 |
asyncDataLogger.execute(new Runnable() {
|
| 41 |
@Override
|
34 |
@Override
|
| Line 70... |
Line 63... |
| 70 |
in.close();
|
63 |
in.close();
|
| 71 |
|
64 |
|
| 72 |
} catch (Exception e) {
|
65 |
} catch (Exception e) {
|
| 73 |
Logger.getRootLogger().warn(e);
|
66 |
Logger.getRootLogger().warn(e);
|
| 74 |
}
|
67 |
}
|
| - |
|
68 |
}
|
| - |
|
69 |
});
|
| - |
|
70 |
}
|
| - |
|
71 |
|
| - |
|
72 |
public static void logSocialData(final SocialEventType eType, final String userId, final String... logData) {
|
| - |
|
73 |
final String strToWrite = StringUtils.join(logData, ", ");
|
| - |
|
74 |
final Long time = (new Date()).getTime();
|
| - |
|
75 |
asyncSocialDataLogger.execute(new Runnable() {
|
| - |
|
76 |
@Override
|
| - |
|
77 |
public void run() {
|
| - |
|
78 |
log.info(eType.name() + ", " + userId + ", " + strToWrite);
|
| - |
|
79 |
SocialEvent event = SocialEvent.createEvent(eType, userId, logData);
|
| - |
|
80 |
JSONObject logDataInJson = event.getLogDataInJson();
|
| - |
|
81 |
|
| - |
|
82 |
try {
|
| - |
|
83 |
String data = URLEncoder.encode("time", "UTF-8") + "=" + URLEncoder.encode(time.toString(), "UTF-8");
|
| - |
|
84 |
data += "&" + URLEncoder.encode("eventType", "UTF-8") + "=" + URLEncoder.encode(eType.name(), "UTF-8");
|
| - |
|
85 |
data += "&" + URLEncoder.encode("userId", "UTF-8") + "=" + URLEncoder.encode(userId, "UTF-8");
|
| - |
|
86 |
|
| - |
|
87 |
if (logDataInJson != null) {
|
| - |
|
88 |
data += "&" + URLEncoder.encode("jsonLogData", "UTF-8") + "=" + URLEncoder.encode(logDataInJson.toString(), "UTF-8");
|
| - |
|
89 |
}
|
| 75 |
|
90 |
|
| - |
|
91 |
// Send data
|
| - |
|
92 |
URL url = new URL("http://" + googleAppUrl + "/add-social-data-log");
|
| - |
|
93 |
URLConnection conn = url.openConnection();
|
| - |
|
94 |
conn.setDoOutput(true);
|
| - |
|
95 |
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
|
| - |
|
96 |
wr.write(data);
|
| - |
|
97 |
wr.close();
|
| - |
|
98 |
|
| - |
|
99 |
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
|
| - |
|
100 |
while (in.readLine() != null);
|
| - |
|
101 |
in.close();
|
| - |
|
102 |
|
| - |
|
103 |
} catch (Exception e) {
|
| - |
|
104 |
Logger.getRootLogger().warn(e);
|
| - |
|
105 |
}
|
| 76 |
}
|
106 |
}
|
| 77 |
});
|
107 |
});
|
| 78 |
}
|
108 |
}
|
| 79 |
}
|
109 |
}
|
| 80 |
|
110 |
|