use of org.b3log.latke.repository.PropertyFilter in project solo by b3log.
the class TagArticleRepositoryImpl method getByArticleId.
@Override
public List<JSONObject> getByArticleId(final String articleId) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Article.ARTICLE + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, articleId)).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
return CollectionUtils.jsonArrayToList(array);
}
use of org.b3log.latke.repository.PropertyFilter in project solo by b3log.
the class TagRepositoryImpl method getByTitle.
@Override
public JSONObject getByTitle(final String tagTitle) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Tag.TAG_TITLE, FilterOperator.EQUAL, tagTitle)).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
use of org.b3log.latke.repository.PropertyFilter in project solo by b3log.
the class UserRepositoryImpl method getAdmin.
@Override
public JSONObject getAdmin() throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(User.USER_ROLE, FilterOperator.EQUAL, Role.ADMIN_ROLE)).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
use of org.b3log.latke.repository.PropertyFilter in project solo by b3log.
the class ArticleRepositoryImpl method getPreviousArticle.
@Override
public JSONObject getPreviousArticle(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.LESS_THAN, currentArticleCreateDate), new PropertyFilter(Article.ARTICLE_IS_PUBLISHED, FilterOperator.EQUAL, true))).addSort(Article.ARTICLE_CREATE_DATE, SortDirection.DESCENDING).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;
}
use of org.b3log.latke.repository.PropertyFilter in project solo by b3log.
the class ArticleRepositoryImpl method getMostViewCountArticles.
@Override
public List<JSONObject> getMostViewCountArticles(final int num) throws RepositoryException {
final Query query = new Query();
query.addSort(Article.ARTICLE_VIEW_COUNT, SortDirection.DESCENDING).addSort(Article.ARTICLE_UPDATE_DATE, SortDirection.DESCENDING);
query.setFilter(new PropertyFilter(Article.ARTICLE_IS_PUBLISHED, FilterOperator.EQUAL, true));
query.setCurrentPageNum(1);
query.setPageSize(num);
query.setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
return CollectionUtils.jsonArrayToList(array);
}
Aggregations