Search in sources :

Example 71 with Query

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

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

Example 73 with Query

use of org.b3log.latke.repository.Query 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);
}
Also used : Query(org.b3log.latke.repository.Query) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) PropertyFilter(org.b3log.latke.repository.PropertyFilter)

Example 74 with Query

use of org.b3log.latke.repository.Query 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);
}
Also used : Query(org.b3log.latke.repository.Query) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) PropertyFilter(org.b3log.latke.repository.PropertyFilter)

Example 75 with Query

use of org.b3log.latke.repository.Query 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);
}
Also used : Query(org.b3log.latke.repository.Query) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) PropertyFilter(org.b3log.latke.repository.PropertyFilter)

Aggregations

Query (org.b3log.latke.repository.Query)112 JSONObject (org.json.JSONObject)105 JSONArray (org.json.JSONArray)56 PropertyFilter (org.b3log.latke.repository.PropertyFilter)47 Test (org.testng.annotations.Test)26 RepositoryException (org.b3log.latke.repository.RepositoryException)23 MockRequest (org.b3log.solo.MockRequest)23 MockResponse (org.b3log.solo.MockResponse)23 ServiceException (org.b3log.latke.service.ServiceException)14 List (java.util.List)10 Date (java.util.Date)8 URL (org.b3log.solo.model.sitemap.URL)8 HttpServletResponse (javax.servlet.http.HttpServletResponse)7 PrintWriter (java.io.PrintWriter)6 StringWriter (java.io.StringWriter)6 ArrayList (java.util.ArrayList)6 ServletContext (javax.servlet.ServletContext)6 HttpServletRequest (javax.servlet.http.HttpServletRequest)6 Transactional (org.b3log.latke.repository.annotation.Transactional)6 JSONException (org.json.JSONException)6