Commit fa7c1c6da9f185482c4cbcc9a328a2cca5cb85f9

Authored by Diego Ceccarelli
1 parent 3c3f8df7

fix json encoding problem

src/main/java/it/cnr/isti/hpc/trends/cli/ResiltechTrendsCLI.java
... ... @@ -20,7 +20,6 @@ import it.cnr.isti.hpc.property.ProjectProperties;
20 20 import it.cnr.isti.hpc.trends.TrendDetector;
21 21 import it.cnr.isti.hpc.trends.listener.TwitterAPIListener;
22 22 import it.cnr.isti.hpc.trends.output.FileTrendCollector;
23   -import it.cnr.isti.hpc.trends.output.ResiltechCollector;
24 23  
25 24 import javax.activity.InvalidActivityException;
26 25  
... ... @@ -52,9 +51,8 @@ public class ResiltechTrendsCLI extends AbstractCommandLineInterface {
52 51  
53 52 TrendDetector td = new TrendDetector().setMinFreq(minFreq)
54 53 .setBucketInterval(bucketInterval);
55   - td.addCollector(new FileTrendCollector("resiltech-trends.tsv")
56   - .asPlain());
57   - td.addCollector(new ResiltechCollector());
  54 + td.addCollector(new FileTrendCollector("resiltech-trends.json"));
  55 + // td.addCollector(new ResiltechCollector());
58 56 TwitterAPIListener listener = new TwitterAPIListener(td);
59 57 listener.run();
60 58 }
... ...
src/main/java/it/cnr/isti/hpc/trends/listener/TwitterAPIListener.java
... ... @@ -19,6 +19,7 @@ import it.cnr.isti.hpc.property.ProjectProperties;
19 19 import it.cnr.isti.hpc.trends.Bucket;
20 20 import it.cnr.isti.hpc.trends.Keywords;
21 21 import it.cnr.isti.hpc.trends.TrendDetector;
  22 +import it.cnr.isti.hpc.trends.util.StatusJSONImpl;
22 23  
23 24 import javax.activity.InvalidActivityException;
24 25  
... ... @@ -30,6 +31,7 @@ import twitter4j.StatusListener;
30 31 import twitter4j.TwitterStream;
31 32 import twitter4j.TwitterStreamFactory;
32 33 import twitter4j.conf.ConfigurationBuilder;
  34 +import twitter4j.json.DataObjectFactory;
33 35  
34 36 /**
35 37 * @author Diego Ceccarelli <diego.ceccarelli@isti.cnr.it>
... ... @@ -50,7 +52,7 @@ public class TwitterAPIListener extends AbstractTwitterListener {
50 52 super.run();
51 53 ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
52 54 configurationBuilder
53   - .setJSONStoreEnabled(false)
  55 + .setJSONStoreEnabled(true)
54 56 .setOAuthConsumerKey(properties.get("oauth.consumerKey"))
55 57 .setOAuthConsumerSecret(properties.get("oauth.consumerSecret"))
56 58 .setOAuthAccessToken(properties.get("oauth.accessToken"))
... ... @@ -66,7 +68,12 @@ public class TwitterAPIListener extends AbstractTwitterListener {
66 68  
67 69 twitterStream.addListener(new StatusListener() {
68 70 public void onStatus(Status status) {
69   - collect(status);
  71 + String json = DataObjectFactory.getRawJSON(status);
  72 + StatusJSONImpl s = new StatusJSONImpl();
  73 + s.setTimestamp_ms(status.getCreatedAt().getTime());
  74 + s.setText(status.getText());
  75 + s.setJson(json);
  76 + collect(s);
70 77  
71 78 }
72 79  
... ...
src/main/java/it/cnr/isti/hpc/trends/output/FileTrendCollector.java
... ... @@ -45,7 +45,7 @@ public class FileTrendCollector extends TrendCollector {
45 45 };
46 46  
47 47 private static Gson gson = new GsonBuilder().registerTypeAdapter(
48   - StatusJSONImpl.class, new StatusSerializer()).create();
  48 + Status.class, new StatusSerializer()).create();
49 49 Format format = Format.JSON;
50 50 BufferedWriter bw;
51 51  
... ...
src/main/java/it/cnr/isti/hpc/trends/output/ResiltechCollector.java
... ... @@ -17,13 +17,14 @@ package it.cnr.isti.hpc.trends.output;
17 17  
18 18 import it.cnr.isti.hpc.property.ProjectProperties;
19 19 import it.cnr.isti.hpc.trends.output.FileTrendCollector.StatusSerializer;
20   -import it.cnr.isti.hpc.trends.util.StatusJSONImpl;
21 20  
22 21 import java.io.IOException;
23 22  
24 23 import org.slf4j.Logger;
25 24 import org.slf4j.LoggerFactory;
26 25  
  26 +import twitter4j.Status;
  27 +
27 28 import com.google.gson.Gson;
28 29 import com.google.gson.GsonBuilder;
29 30 import com.sun.jersey.api.client.Client;
... ... @@ -45,7 +46,7 @@ public class ResiltechCollector extends TrendCollector {
45 46 .get("resiltec.trend.service");
46 47  
47 48 private static Gson gson = new GsonBuilder().registerTypeAdapter(
48   - StatusJSONImpl.class, new StatusSerializer()).create();
  49 + Status.class, new StatusSerializer()).create();
49 50  
50 51 Client client = Client.create();
51 52 WebResource webResource = client.resource(RESILTECH_API);
... ...
src/main/java/it/cnr/isti/hpc/trends/util/StatusJSONImpl.java
... ... @@ -121,6 +121,14 @@ public class StatusJSONImpl implements Status, java.io.Serializable {
121 121 return new Date(timestamp_ms);
122 122 }
123 123  
  124 + public long getTimestamp_ms() {
  125 + return timestamp_ms;
  126 + }
  127 +
  128 + public void setTimestamp_ms(long timestamp_ms) {
  129 + this.timestamp_ms = timestamp_ms;
  130 + }
  131 +
124 132 public long getId() {
125 133 return id;
126 134 }
... ...