X-Git-Url: https://git.wpitchoune.net/gitweb/?p=pnews.git;a=blobdiff_plain;f=war%2Fsrc%2Fmain%2Fjava%2Fpnews%2Fservlet%2FJSON.java;h=78379a4ca0fccb1a674fb8f35346d1d18e4e1940;hp=20afaa63103406e8eb04e800b7feb5778fa86cb2;hb=aff83c8798602b535d13edeaffdb8f4238e2bbf5;hpb=887fda403784fbf7641b7db0e560920394c5d46b diff --git a/war/src/main/java/pnews/servlet/JSON.java b/war/src/main/java/pnews/servlet/JSON.java index 20afaa6..78379a4 100644 --- a/war/src/main/java/pnews/servlet/JSON.java +++ b/war/src/main/java/pnews/servlet/JSON.java @@ -1,6 +1,7 @@ package pnews.servlet; import java.io.IOException; +import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -8,16 +9,19 @@ import com.google.gson.Gson; import com.google.gson.JsonObject; import com.rometools.rome.io.FeedException; -import pnews.Article; -import pnews.Category; +import net.wpitchoune.pnews.Article; +import net.wpitchoune.pnews.ArticleStore; +import net.wpitchoune.pnews.Category; +import net.wpitchoune.pnews.Config; public class JSON { private static final Logger LOG = Logger.getLogger(JSON.class.getName()); - public static String getStats() { + public static String getStats(ArticleProvider provider, Config config) { JsonObject jstats, jreadcounts, jcategories, jmemory; - Article[] articles; Runtime runtime; + List
articles; + Article[] allArticles; jstats = new JsonObject(); @@ -26,17 +30,19 @@ public class JSON { jreadcounts = new JsonObject(); jstats.add("read-counts", jreadcounts); - articles = ArticleStore.singleton.getArticles(); - for (Article a: articles) - if (a.readCount.get() > 0) - jreadcounts.addProperty(a.link, a.readCount); + allArticles = ArticleStore.singleton.getArticles(); + for (Article a: allArticles) + if (a.getReadCount() > 0) + jreadcounts.addProperty(a.getLink(), a.getReadCount()); jcategories = new JsonObject(); jstats.add("categories", jcategories); - for (Category cat: Category.values()) + for (Category cat: config.getCategories()) try { - jcategories.addProperty(cat.getId(), ArticleProvider.singleton.getArticles(cat).size()); + articles = provider.getArticles(cat, null); + jcategories.addProperty(cat.getLabel(), + articles.size()); } catch (IllegalArgumentException | FeedException | IOException e) { LOG.log(Level.SEVERE, "Fail to retrieve articles", e); }