Search in sources :

Example 66 with Query

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

the class SitemapProcessor method addArticles.

/**
     * Adds articles into the specified sitemap.
     * 
     * @param sitemap the specified sitemap
     * @throws Exception exception
     */
private void addArticles(final Sitemap sitemap) throws Exception {
    // XXX: query all articles?
    final Query query = new Query().setCurrentPageNum(1).setFilter(new PropertyFilter(Article.ARTICLE_IS_PUBLISHED, FilterOperator.EQUAL, true)).addSort(Article.ARTICLE_CREATE_DATE, SortDirection.DESCENDING);
    // XXX: maybe out of memory 
    final JSONObject articleResult = articleRepository.get(query);
    final JSONArray articles = articleResult.getJSONArray(Keys.RESULTS);
    for (int i = 0; i < articles.length(); i++) {
        final JSONObject article = articles.getJSONObject(i);
        final String permalink = article.getString(Article.ARTICLE_PERMALINK);
        final URL url = new URL();
        url.setLoc(Latkes.getServePath() + permalink);
        final Date updateDate = (Date) article.get(Article.ARTICLE_UPDATE_DATE);
        final String lastMod = DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(updateDate);
        url.setLastMod(lastMod);
        sitemap.addURL(url);
    }
}
Also used : Query(org.b3log.latke.repository.Query) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) PropertyFilter(org.b3log.latke.repository.PropertyFilter) URL(org.b3log.solo.model.sitemap.URL) Date(java.util.Date) ArchiveDate(org.b3log.solo.model.ArchiveDate)

Example 67 with Query

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

the class SitemapProcessor method addArchives.

/**
     * Adds archives (archive-articles) into the specified sitemap.
     * 
     * @param sitemap the specified sitemap
     * @throws Exception exception
     */
private void addArchives(final Sitemap sitemap) throws Exception {
    final JSONObject result = archiveDateRepository.get(new Query());
    final JSONArray archiveDates = result.getJSONArray(Keys.RESULTS);
    for (int i = 0; i < archiveDates.length(); i++) {
        final JSONObject archiveDate = archiveDates.getJSONObject(i);
        final long time = archiveDate.getLong(ArchiveDate.ARCHIVE_TIME);
        final String dateString = DateFormatUtils.format(time, "yyyy/MM");
        final URL url = new URL();
        url.setLoc(Latkes.getServePath() + "/archives/" + dateString);
        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 68 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 69 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 70 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)

Aggregations

Query (org.b3log.latke.repository.Query)112 JSONObject (org.json.JSONObject)105 JSONArray (org.json.JSONArray)56 PropertyFilter (org.b3log.latke.repository.PropertyFilter)47 Test (org.testng.annotations.Test)26 RepositoryException (org.b3log.latke.repository.RepositoryException)23 MockRequest (org.b3log.solo.MockRequest)23 MockResponse (org.b3log.solo.MockResponse)23 ServiceException (org.b3log.latke.service.ServiceException)14 List (java.util.List)10 Date (java.util.Date)8 URL (org.b3log.solo.model.sitemap.URL)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 PrintWriter (java.io.PrintWriter)6 StringWriter (java.io.StringWriter)6 ArrayList (java.util.ArrayList)6 ServletContext (javax.servlet.ServletContext)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 Transactional (org.b3log.latke.repository.annotation.Transactional)6 JSONException (org.json.JSONException)6