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);
}
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations