Search in sources :

Example 6 with PropertyFilter

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

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

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

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

the class LinkRepositoryImpl method getByAddress.

@Override
public JSONObject getByAddress(final String address) throws RepositoryException {
    final Query query = new Query().setFilter(new PropertyFilter(Link.LINK_ADDRESS, FilterOperator.EQUAL, address)).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 10 with PropertyFilter

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

the class PreferenceQueryService method getPreference.

/**
     * Gets the user preference.
     *
     * @return user preference, returns {@code null} if not found
     * @throws ServiceException if repository exception
     */
public JSONObject getPreference() throws ServiceException {
    try {
        final JSONObject checkInit = optionRepository.get(Option.ID_C_ADMIN_EMAIL);
        if (null == checkInit) {
            return null;
        }
        final Query query = new Query();
        query.setFilter(new PropertyFilter(Option.OPTION_CATEGORY, FilterOperator.EQUAL, Option.CATEGORY_C_PREFERENCE));
        final JSONArray opts = optionRepository.get(query).optJSONArray(Keys.RESULTS);
        final JSONObject ret = new JSONObject();
        for (int i = 0; i < opts.length(); i++) {
            final JSONObject opt = opts.optJSONObject(i);
            ret.put(opt.optString(Keys.OBJECT_ID), opt.opt(Option.OPTION_VALUE));
        }
        return ret;
    } catch (final RepositoryException e) {
        return null;
    }
}
Also used : JSONObject(org.json.JSONObject) Query(org.b3log.latke.repository.Query) JSONArray(org.json.JSONArray) PropertyFilter(org.b3log.latke.repository.PropertyFilter) RepositoryException(org.b3log.latke.repository.RepositoryException)

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