Search in sources :

Example 36 with Query

use of org.b3log.latke.repository.Query in project solo by b3log.

the class SitemapProcessor method addTags.

/**
     * Adds tags (tag-articles) and tags wall (/tags.html) into the specified sitemap.
     * 
     * @param sitemap the specified sitemap
     * @throws Exception exception
     */
private void addTags(final Sitemap sitemap) throws Exception {
    final JSONObject result = tagRepository.get(new Query());
    final JSONArray tags = result.getJSONArray(Keys.RESULTS);
    for (int i = 0; i < tags.length(); i++) {
        final JSONObject tag = tags.getJSONObject(i);
        final String link = URLEncoder.encode(tag.getString(Tag.TAG_TITLE), "UTF-8");
        final URL url = new URL();
        url.setLoc(Latkes.getServePath() + "/tags/" + link);
        sitemap.addURL(url);
    }
    // Tags wall
    final URL url = new URL();
    url.setLoc(Latkes.getServePath() + "/tags.html");
    sitemap.addURL(url);
}
Also used : JSONObject(org.json.JSONObject) Query(org.b3log.latke.repository.Query) JSONArray(org.json.JSONArray) URL(org.b3log.solo.model.sitemap.URL)

Example 37 with Query

use of org.b3log.latke.repository.Query in project solo by b3log.

the class ArchiveDateRepositoryImpl method getArchiveDates.

@Override
public List<JSONObject> getArchiveDates() throws RepositoryException {
    final org.b3log.latke.repository.Query query = new Query().addSort(ArchiveDate.ARCHIVE_TIME, SortDirection.DESCENDING).setPageCount(1);
    final JSONObject result = get(query);
    final JSONArray archiveDates = result.optJSONArray(Keys.RESULTS);
    final List<JSONObject> ret = CollectionUtils.jsonArrayToList(archiveDates);
    removeForUnpublishedArticles(ret);
    return ret;
}
Also used : Query(org.b3log.latke.repository.Query) Query(org.b3log.latke.repository.Query) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray)

Example 38 with Query

use of org.b3log.latke.repository.Query in project solo by b3log.

the class ArticleRepositoryImpl method getMostCommentArticles.

@Override
public List<JSONObject> getMostCommentArticles(final int num) throws RepositoryException {
    final Query query = new Query().addSort(Article.ARTICLE_COMMENT_COUNT, SortDirection.DESCENDING).addSort(Article.ARTICLE_UPDATE_DATE, SortDirection.DESCENDING).setFilter(new PropertyFilter(Article.ARTICLE_IS_PUBLISHED, FilterOperator.EQUAL, true)).setCurrentPageNum(1).setPageSize(num).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 39 with Query

use of org.b3log.latke.repository.Query in project solo by b3log.

the class PageRepositoryImpl method getUnder.

@Override
public JSONObject getUnder(final String id) throws RepositoryException {
    final JSONObject page = get(id);
    if (null == page) {
        return null;
    }
    final Query query = new Query().setFilter(new PropertyFilter(Page.PAGE_ORDER, FilterOperator.GREATER_THAN, page.optInt(Page.PAGE_ORDER))).addSort(Page.PAGE_ORDER, SortDirection.ASCENDING).setCurrentPageNum(1).setPageSize(1).setPageCount(1);
    final JSONObject result = get(query);
    final JSONArray array = result.optJSONArray(Keys.RESULTS);
    if (1 != array.length()) {
        return null;
    }
    return array.optJSONObject(0);
}
Also used : JSONObject(org.json.JSONObject) Query(org.b3log.latke.repository.Query) JSONArray(org.json.JSONArray) PropertyFilter(org.b3log.latke.repository.PropertyFilter)

Example 40 with Query

use of org.b3log.latke.repository.Query in project solo by b3log.

the class PageRepositoryImpl method getByOrder.

@Override
public JSONObject getByOrder(final int order) throws RepositoryException {
    final Query query = new Query().setFilter(new PropertyFilter(Page.PAGE_ORDER, FilterOperator.EQUAL, order)).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)

Aggregations

Query (org.b3log.latke.repository.Query)54 JSONObject (org.json.JSONObject)54 JSONArray (org.json.JSONArray)47 PropertyFilter (org.b3log.latke.repository.PropertyFilter)28 RepositoryException (org.b3log.latke.repository.RepositoryException)9 ServiceException (org.b3log.latke.service.ServiceException)9 Test (org.testng.annotations.Test)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 PrintWriter (java.io.PrintWriter)6 StringWriter (java.io.StringWriter)6 ServletContext (javax.servlet.ServletContext)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 Date (java.util.Date)5 URL (org.b3log.solo.model.sitemap.URL)4 JSONException (org.json.JSONException)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 CompositeFilter (org.b3log.latke.repository.CompositeFilter)2 Filter (org.b3log.latke.repository.Filter)2 Transaction (org.b3log.latke.repository.Transaction)2