X-Git-Url: http://git.wpitchoune.net/gitweb/?a=blobdiff_plain;f=war%2Fsrc%2Fmain%2Fjava%2Fpnews%2Fservlet%2FJSON.java;h=13509ed05b7da9c2b420f8768ba5cb218271cbb6;hb=6f411daf8bfd05580744e3c46a8c1497e8cd7898;hp=9d331f25b6c6bb747dcd339f150bc50db54f8fce;hpb=4e2f57c6c5a2d60a09b0b47c1a3bdd470a8ea54f;p=pnews.git diff --git a/war/src/main/java/pnews/servlet/JSON.java b/war/src/main/java/pnews/servlet/JSON.java index 9d331f2..13509ed 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; @@ -14,10 +15,11 @@ import pnews.Category; public class JSON { private static final Logger LOG = Logger.getLogger(JSON.class.getName()); - public static String getStats() { - JsonObject jstats, jreadcounts, jcategories, jcategory, jmemory; - Article[] articles; + public static String getStats(ArticleProvider provider, Config config) { + JsonObject jstats, jreadcounts, jcategories, jmemory; Runtime runtime; + List
articles; + Article[] allArticles; jstats = new JsonObject(); @@ -26,17 +28,19 @@ public class JSON { jreadcounts = new JsonObject(); jstats.add("read-counts", jreadcounts); - articles = ArticleStore.singleton.getArticles(); - for (Article a: articles) + allArticles = ArticleStore.singleton.getArticles(); + for (Article a: allArticles) if (a.readCount.get() > 0) jreadcounts.addProperty(a.link, a.readCount); 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); + jcategories.addProperty(cat.getLabel(), + articles.size()); } catch (IllegalArgumentException | FeedException | IOException e) { LOG.log(Level.SEVERE, "Fail to retrieve articles", e); }