Package gov.nysenate.openleg.model

Examples of gov.nysenate.openleg.model.SenateResponse


        if (type.contains("bill") || type.contains("resolution")) {
            sortField = "sortindex";
            sortOrder = false;
        }

        SenateResponse sr = null;

        // now calculate start, end idx based on pageIdx and pageSize
        int start = (pageNumber - 1) * pageSize;

        type = type.substring(0, type.length() - 1);

        try {
            queryBuilder.otype(type).and().current().and().active();
        } catch (QueryBuilderException e) {
            logger.error("Invalid query construction", e);
            throw new ApiRequestException("Invalid query construction", e);
        }

        try {
            sr = Application.getLucene().search(queryBuilder.query(), start, pageSize, sortField, sortOrder);
        }
        catch (IOException e) {
            logger.error(e);
        }

        if(sr == null || sr.getResults() == null || sr.getResults().isEmpty())
            throw new ApiRequestException(TextFormatter.append("no results for query"));

        sr.setResults(ApiHelper.buildSearchResultList(sr));

        if(type.equalsIgnoreCase("bill") && format.matches("(?i)(csv|json|mobile|rss|xml)")) {
            ArrayList<Result> searchResults = ApiHelper.buildSearchResultList(sr);
            ArrayList<Bill> bills = new ArrayList<Bill>();
            for(Result result: searchResults) {
View Full Code Here


        QueryBuilder queryBuilder = new QueryBuilder();



        SenateResponse sr = null;

        // now calculate start, end idx based on pageIdx and pageSize
        int start = (pageNumber - 1) * pageSize;

        try {
            queryBuilder.keyValue(key, "\""+value+"\"").and().otype("bill");

            String filter = request.getParameter("filter");
            if(filter != null) {
                queryBuilder.and().insertAfter(filter);
            }
            else {
                queryBuilder.and().current().and().active();
            }
        } catch (QueryBuilderException e) {
            logger.error("Invalid query construction", e);
            throw new ApiRequestException("Invalid query construction", e);
        }

        try {
            sr = Application.getLucene().search(queryBuilder.query(), start, pageSize, sortField, sortOrder);
        }
        catch (IOException e) {
            logger.error(e);
        }

        if(sr == null || sr.getResults() == null || sr.getResults().isEmpty())
            throw new ApiRequestException(TextFormatter.append("no results for query"));

        sr.setResults(ApiHelper.buildSearchResultList(sr));

        if(format.matches("(?i)(csv|json|mobile|rss|xml)")) {
            ArrayList<Result> searchResults = ApiHelper.buildSearchResultList(sr);
            ArrayList<Bill> bills = new ArrayList<Bill>();
            for(Result result: searchResults) {
View Full Code Here

        if (request.getParameter("pageSize") != null) {
            pageSize = Integer.parseInt(request.getParameter("pageSize"));
        }

        SenateResponse sr = null;
        try {
            int start = (pageNumber - 1) * pageSize;
            sr = Application.getLucene().search(term, start, pageSize, sortField, sortOrder);
            if((sr.getResults() == null || sr.getResults().isEmpty()) && this.format.contains("html")) {
                throw new ApiRequestException(TextFormatter.append("no results for query"));
            }
            ApiHelper.buildSearchResultList(sr);
        }
        catch (IOException e) {
View Full Code Here

            term += " AND active:true";
        }

        try {
            int start = (pageNumber-1) * pageSize;
            SenateResponse sr = Application.getLucene().search(term, start, pageSize, sort, sortOrder);
            ApiHelper.buildSearchResultList(sr);

            if (format.equals("json")) {
                response.setContentType("application/json");
                new Api1JsonConverter().write(sr, response.getOutputStream());
View Full Code Here

    private void doSearch(HttpServletRequest request, HttpServletResponse response, String format, String type, String term, int pageNumber, int pageSize, String sort, boolean sortOrder) throws ApiRequestException
    {
        try {
            int start = (pageNumber-1) * pageSize;
            SenateResponse sr = Application.getLucene().search(term, start, pageSize, sort, sortOrder);
            ApiHelper.buildSearchResultList(sr);

            if (format.equals("json")) {
                response.setContentType("application/json");
                new Api2JsonConverter().write(sr, response.getOutputStream());
View Full Code Here

    }

    private void doSingleView(HttpServletRequest request, HttpServletResponse response, String format, String type, String id) throws ApiRequestException
    {
        try {
            SenateResponse sr = Application.getLucene().search("otype:"+type+" AND oid:\""+id+"\"", 0, 1, null, false);
            ApiHelper.buildSearchResultList(sr);

            if (format.equals("json")) {
                response.setContentType("application/json");
                // Writing directly to the output stream here currently makes UTF8 errors.
                response.getWriter().write(new Api2JsonConverter().toString(sr));
            }
            else if (format.equals("jsonp")) {
                String callback = request.getParameter("callback");
                if (callback != null && callback != "") {
                    PrintWriter out = response.getWriter();
                    response.setContentType("application/javascript");
                    out.write(callback+"("+new Api2JsonConverter().toString(sr)+");");
                }
                else {
                    throw new ApiRequestException("callback parameter required for jsonp queries.");
                }
            }
            else if (format.equals("xml")) {
                response.setContentType("application/xml");
                new Api2XmlConverter().write(sr, response.getOutputStream());
            }
            else if (format.equals("pdf")) {
                if (sr.getResults().size() == 0) {
                    throw new ApiRequestException("No matching document could be found.");
                }

                response.setContentType("application/pdf");
                PDFConverter.write(sr.getResults().get(0).object, response.getOutputStream());
            }

        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new ApiRequestException("internal server error.", e);
View Full Code Here

        else {
            searchtext = "";
        }

        Lucene lucene = Application.getLucene();
        SenateResponse luceneResults = lucene.search(query, 0, 1000, "published", true);
        ApiHelper.buildSearchResultList(luceneResults);
        ArrayList<Transcript> transcripts = new ArrayList<Transcript>();
        for (Result result : luceneResults.getResults()) {
            transcripts.add((Transcript)result.getObject());
        }

        request.setAttribute("year", year);
        request.setAttribute("month", month);
View Full Code Here



    public SenateResponse search(String queryText, int skipCount, int retrieveCount, String sortFieldName, boolean reversed) throws IOException
    {
        SenateResponse response = new SenateResponse();

        LuceneResult result = this._search(queryText,skipCount,retrieveCount,sortFieldName,reversed);

        if (result != null) {
            response.addMetadataByKey("totalresults", result.total );

            for (Document doc : result.results) {
                String lastModified = doc.get("modified");
                if (lastModified == null || lastModified.length() == 0)
                    lastModified = new Date().getTime()+"";

                HashMap<String,String> fields = new HashMap<String,String>();
                for(IndexableField field : doc.getFields()) {
                    fields.put(field.name(), doc.get(field.name()));
                }

                response.addResult(new Result(
                        doc.get("otype"),
                        doc.get("odata"),
                        doc.get("oid"),
                        Long.parseLong(lastModified),
                        Boolean.parseBoolean(doc.get("active")),
                        fields));
            }
        }
        else {
            response.addMetadataByKey("totalresults", 0 );
        }

        return response;
    }
View Full Code Here

TOP

Related Classes of gov.nysenate.openleg.model.SenateResponse

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.