Search in sources :

Example 91 with JSONArray

use of org.json.JSONArray in project solo by b3log.

the class ArticleRepositoryImpl method getNextArticle.

@Override
public JSONObject getNextArticle(final String articleId) throws RepositoryException {
    final JSONObject currentArticle = get(articleId);
    final Date currentArticleCreateDate = (Date) currentArticle.opt(Article.ARTICLE_CREATE_DATE);
    final Query query = new Query().setFilter(CompositeFilterOperator.and(new PropertyFilter(Article.ARTICLE_CREATE_DATE, FilterOperator.GREATER_THAN, currentArticleCreateDate), new PropertyFilter(Article.ARTICLE_IS_PUBLISHED, FilterOperator.EQUAL, true))).addSort(Article.ARTICLE_CREATE_DATE, SortDirection.ASCENDING).setCurrentPageNum(1).setPageSize(1).setPageCount(1).addProjection(Article.ARTICLE_TITLE, String.class).addProjection(Article.ARTICLE_PERMALINK, String.class).addProjection(Article.ARTICLE_ABSTRACT, String.class);
    final JSONObject result = get(query);
    final JSONArray array = result.optJSONArray(Keys.RESULTS);
    if (1 != array.length()) {
        return null;
    }
    final JSONObject ret = new JSONObject();
    final JSONObject article = array.optJSONObject(0);
    try {
        ret.put(Article.ARTICLE_TITLE, article.getString(Article.ARTICLE_TITLE));
        ret.put(Article.ARTICLE_PERMALINK, article.getString(Article.ARTICLE_PERMALINK));
        ret.put(Article.ARTICLE_ABSTRACT, article.getString((Article.ARTICLE_ABSTRACT)));
    } catch (final JSONException e) {
        throw new RepositoryException(e);
    }
    return ret;
}
Also used : JSONObject(org.json.JSONObject) Query(org.b3log.latke.repository.Query) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) PropertyFilter(org.b3log.latke.repository.PropertyFilter) RepositoryException(org.b3log.latke.repository.RepositoryException) Date(java.util.Date)

Example 92 with JSONArray

use of org.json.JSONArray in project solo by b3log.

the class ArticleRepositoryImpl method getByPermalink.

@Override
public JSONObject getByPermalink(final String permalink) throws RepositoryException {
    final Query query = new Query().setFilter(new PropertyFilter(Article.ARTICLE_PERMALINK, FilterOperator.EQUAL, permalink)).setPageCount(1);
    final JSONObject result = get(query);
    final JSONArray array = result.optJSONArray(Keys.RESULTS);
    if (0 == array.length()) {
        return null;
    }
    return array.optJSONObject(0);
}
Also used : Query(org.b3log.latke.repository.Query) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) PropertyFilter(org.b3log.latke.repository.PropertyFilter)

Example 93 with JSONArray

use of org.json.JSONArray in project solo by b3log.

the class ArticleRepositoryImpl method getRecentArticles.

@Override
public List<JSONObject> getRecentArticles(final int fetchSize) throws RepositoryException {
    final Query query = new Query();
    query.setFilter(new PropertyFilter(Article.ARTICLE_IS_PUBLISHED, FilterOperator.EQUAL, true));
    query.addSort(Article.ARTICLE_UPDATE_DATE, SortDirection.DESCENDING);
    query.setCurrentPageNum(1);
    query.setPageSize(fetchSize);
    query.setPageCount(1);
    final JSONObject result = get(query);
    final JSONArray array = result.optJSONArray(Keys.RESULTS);
    return CollectionUtils.jsonArrayToList(array);
}
Also used : Query(org.b3log.latke.repository.Query) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) PropertyFilter(org.b3log.latke.repository.PropertyFilter)

Example 94 with JSONArray

use of org.json.JSONArray in project solo by b3log.

the class CommentRepositoryImpl method getRecentComments.

@Override
@SuppressWarnings("unchecked")
public List<JSONObject> getRecentComments(final int num) throws RepositoryException {
    final Query query = new Query().addSort(Keys.OBJECT_ID, SortDirection.DESCENDING).setCurrentPageNum(1).setPageSize(num).setPageCount(1);
    List<JSONObject> ret;
    final JSONObject result = get(query);
    final JSONArray array = result.optJSONArray(Keys.RESULTS);
    ret = CollectionUtils.jsonArrayToList(array);
    // Removes unpublished article related comments
    removeForUnpublishedArticles(ret);
    return ret;
}
Also used : Query(org.b3log.latke.repository.Query) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 95 with JSONArray

use of org.json.JSONArray in project solo by b3log.

the class LinkRepositoryImpl method getMaxOrder.

@Override
public int getMaxOrder() throws RepositoryException {
    final Query query = new Query();
    query.addSort(Link.LINK_ORDER, SortDirection.DESCENDING);
    final JSONObject result = get(query);
    final JSONArray array = result.optJSONArray(Keys.RESULTS);
    if (0 == array.length()) {
        return -1;
    }
    return array.optJSONObject(0).optInt(Link.LINK_ORDER);
}
Also used : Query(org.b3log.latke.repository.Query) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Aggregations

JSONArray (org.json.JSONArray)1710 JSONObject (org.json.JSONObject)1191 JSONException (org.json.JSONException)738 ArrayList (java.util.ArrayList)323 IOException (java.io.IOException)243 Test (org.junit.Test)207 HashMap (java.util.HashMap)108 ClientException (edu.umass.cs.gnscommon.exceptions.client.ClientException)96 List (java.util.List)63 DefaultGNSTest (edu.umass.cs.gnsserver.utils.DefaultGNSTest)61 File (java.io.File)54 HashSet (java.util.HashSet)54 Date (java.util.Date)47 Query (org.b3log.latke.repository.Query)47 RandomString (edu.umass.cs.gnscommon.utils.RandomString)44 GraphObject (com.abewy.android.apps.klyph.core.graph.GraphObject)43 FileNotFoundException (java.io.FileNotFoundException)40 Map (java.util.Map)40 GuidEntry (edu.umass.cs.gnsclient.client.util.GuidEntry)36 VolleyError (com.android.volley.VolleyError)35