use of org.b3log.latke.repository.Query in project solo by 88250.
the class LinkQueryService method getLinks.
/**
* Gets links by the specified request json object.
*
* @param requestJSONObject the specified request json object, for example,
* "paginationCurrentPageNum": 1,
* "paginationPageSize": 20,
* "paginationWindowSize": 10
* see {@link Pagination} for more details
* @return for example,
* <pre>
* {
* "pagination": {
* "paginationPageCount": 100,
* "paginationPageNums": [1, 2, 3, 4, 5]
* },
* "links": [{
* "oId": "",
* "linkTitle": "",
* "linkAddress": "",
* ""linkDescription": ""
* }, ....]
* }
* </pre>
* @throws ServiceException service exception
* @see Pagination
*/
public JSONObject getLinks(final JSONObject requestJSONObject) throws ServiceException {
final JSONObject ret = new JSONObject();
try {
final int currentPageNum = requestJSONObject.getInt(Pagination.PAGINATION_CURRENT_PAGE_NUM);
final int pageSize = requestJSONObject.getInt(Pagination.PAGINATION_PAGE_SIZE);
final int windowSize = requestJSONObject.getInt(Pagination.PAGINATION_WINDOW_SIZE);
final Query query = new Query().setPage(currentPageNum, pageSize).addSort(Link.LINK_ORDER, SortDirection.ASCENDING);
final JSONObject result = linkRepository.get(query);
final int pageCount = result.getJSONObject(Pagination.PAGINATION).getInt(Pagination.PAGINATION_PAGE_COUNT);
final JSONObject pagination = new JSONObject();
final List<Integer> pageNums = Paginator.paginate(currentPageNum, pageSize, pageCount, windowSize);
pagination.put(Pagination.PAGINATION_PAGE_COUNT, pageCount);
pagination.put(Pagination.PAGINATION_PAGE_NUMS, pageNums);
final List<JSONObject> links = (List<JSONObject>) result.opt(Keys.RESULTS);
ret.put(Pagination.PAGINATION, pagination);
ret.put(Link.LINKS, (Object) links);
return ret;
} catch (final Exception e) {
LOGGER.log(Level.ERROR, "Gets links failed", e);
throw new ServiceException(e);
}
}
use of org.b3log.latke.repository.Query in project solo by 88250.
the class ArticleProcessorTestCase method getRelevantArticles.
/**
* getRelevantArticles.
*
* @throws Exception exception
*/
@Test
public void getRelevantArticles() throws Exception {
final JSONObject article = getArticleRepository().getFirst(new Query());
final String articleId = article.optString(Keys.OBJECT_ID);
final MockRequest request = mockRequest();
request.setRequestURI("/article/relevant/" + articleId + ".json");
final MockResponse response = mockResponse();
mockDispatcher(request, response);
final String content = response.getString();
Assert.assertTrue(StringUtils.contains(content, "{\"relevantArticles\""));
}
use of org.b3log.latke.repository.Query in project solo by 88250.
the class ArticleConsoleTestCase method addArticle.
/**
* addArticle.
*
* @throws Exception exception
*/
public void addArticle() throws Exception {
final JSONObject article = getArticleRepository().getFirst(new Query());
article.put(Keys.OBJECT_ID, "");
article.put(Article.ARTICLE_PERMALINK, "");
final MockRequest request = mockRequest();
request.setRequestURI("/console/article/");
request.setMethod("POST");
final JSONObject requestJSON = new JSONObject();
requestJSON.put(Article.ARTICLE, article);
request.setJSON(requestJSON);
mockAdminLogin(request);
final MockResponse response = mockResponse();
mockDispatcher(request, response);
final String content = response.getString();
Assert.assertTrue(StringUtils.contains(content, "\"code\":0"));
}
use of org.b3log.latke.repository.Query in project solo by 88250.
the class ArticleConsoleTestCase method putTopArticle.
/**
* putTopArticle.
*
* @throws Exception exception
*/
public void putTopArticle() throws Exception {
final JSONObject article = getArticleRepository().getFirst(new Query());
final String articleId = article.optString(Keys.OBJECT_ID);
final MockRequest request = mockRequest();
request.setRequestURI("/console/article/puttop/" + articleId);
request.setMethod("PUT");
mockAdminLogin(request);
final MockResponse response = mockResponse();
mockDispatcher(request, response);
final String content = response.getString();
Assert.assertTrue(StringUtils.contains(content, "\"code\":0"));
}
use of org.b3log.latke.repository.Query in project solo by 88250.
the class ArticleConsoleTestCase method cancelPublishArticle.
/**
* cancelPublishArticle.
*
* @throws Exception exception
*/
public void cancelPublishArticle() throws Exception {
final JSONObject article = getArticleRepository().getFirst(new Query());
final String articleId = article.optString(Keys.OBJECT_ID);
final MockRequest request = mockRequest();
request.setRequestURI("/console/article/unpublish/" + articleId);
request.setMethod("PUT");
mockAdminLogin(request);
final MockResponse response = mockResponse();
mockDispatcher(request, response);
final String content = response.getString();
Assert.assertTrue(StringUtils.contains(content, "\"code\":0"));
}
Aggregations