Search in sources :

Example 6 with Poll

use of org.xel.Poll in project elastic-core-maven by OrdinaryDude.

the class SearchPolls method processRequest.

@Override
protected JSONStreamAware processRequest(HttpServletRequest req) throws ParameterException {
    String query = Convert.nullToEmpty(req.getParameter("query"));
    if (query.isEmpty()) {
        return JSONResponses.missing("query");
    }
    int firstIndex = ParameterParser.getFirstIndex(req);
    int lastIndex = ParameterParser.getLastIndex(req);
    boolean includeFinished = "true".equalsIgnoreCase(req.getParameter("includeFinished"));
    JSONObject response = new JSONObject();
    JSONArray jsonArray = new JSONArray();
    try (DbIterator<Poll> polls = Poll.searchPolls(query, includeFinished, firstIndex, lastIndex)) {
        while (polls.hasNext()) {
            jsonArray.add(JSONData.poll(polls.next()));
        }
    }
    response.put("polls", jsonArray);
    return response;
}
Also used : JSONObject(org.json.simple.JSONObject) JSONArray(org.json.simple.JSONArray) Poll(org.xel.Poll)

Aggregations

Poll (org.xel.Poll)6 JSONArray (org.json.simple.JSONArray)3 JSONObject (org.json.simple.JSONObject)3 VoteWeighting (org.xel.VoteWeighting)3 Vote (org.xel.Vote)2 Account (org.xel.Account)1 Attachment (org.xel.Attachment)1