Search in sources :

Example 11 with PropertyFilter

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

the class OptionQueryService method getOptions.

/**
     * Gets options with the specified category.
     * 
     * <p>
     * All options with the specified category will be merged into one json object as the return value.
     * </p>
     * 
     * @param category the specified category
     * @return all options with the specified category, for example,
     * <pre>
     * {
     *     "${optionId}": "${optionValue}",
     *     ....
     * }
     * </pre>, returns {@code null} if not found
     * @throws ServiceException service exception
     */
public JSONObject getOptions(final String category) throws ServiceException {
    final Query query = new Query();
    query.setFilter(new PropertyFilter(Option.OPTION_CATEGORY, FilterOperator.EQUAL, category));
    try {
        final JSONObject result = optionRepository.get(query);
        final JSONArray options = result.getJSONArray(Keys.RESULTS);
        if (0 == options.length()) {
            return null;
        }
        final JSONObject ret = new JSONObject();
        for (int i = 0; i < options.length(); i++) {
            final JSONObject option = options.getJSONObject(i);
            ret.put(option.getString(Keys.OBJECT_ID), option.getString(Option.OPTION_VALUE));
        }
        return ret;
    } catch (final Exception e) {
        throw new ServiceException(e);
    }
}
Also used : Query(org.b3log.latke.repository.Query) JSONObject(org.json.JSONObject) ServiceException(org.b3log.latke.service.ServiceException) JSONArray(org.json.JSONArray) PropertyFilter(org.b3log.latke.repository.PropertyFilter) ServiceException(org.b3log.latke.service.ServiceException) RepositoryException(org.b3log.latke.repository.RepositoryException)

Example 12 with PropertyFilter

use of org.b3log.latke.repository.PropertyFilter 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 13 with PropertyFilter

use of org.b3log.latke.repository.PropertyFilter 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 14 with PropertyFilter

use of org.b3log.latke.repository.PropertyFilter 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 15 with PropertyFilter

use of org.b3log.latke.repository.PropertyFilter 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

PropertyFilter (org.b3log.latke.repository.PropertyFilter)28 Query (org.b3log.latke.repository.Query)28 JSONArray (org.json.JSONArray)28 JSONObject (org.json.JSONObject)28 Date (java.util.Date)5 RepositoryException (org.b3log.latke.repository.RepositoryException)5 ArrayList (java.util.ArrayList)3 IOException (java.io.IOException)2 CompositeFilter (org.b3log.latke.repository.CompositeFilter)2 Filter (org.b3log.latke.repository.Filter)2 RequestProcessing (org.b3log.latke.servlet.annotation.RequestProcessing)2 JSONException (org.json.JSONException)2 ParseException (java.text.ParseException)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 Transaction (org.b3log.latke.repository.Transaction)1 ServiceException (org.b3log.latke.service.ServiceException)1 AtomRenderer (org.b3log.latke.servlet.renderer.AtomRenderer)1 RssRenderer (org.b3log.latke.servlet.renderer.RssRenderer)1 ArchiveDate (org.b3log.solo.model.ArchiveDate)1 Entry (org.b3log.solo.model.feed.atom.Entry)1