Package gov.nysenate.openleg.api

Examples of gov.nysenate.openleg.api.AbstractApiRequest


    public void doGet(HttpServletRequest request, HttpServletResponse responsethrows ServletException, IOException
    {
        Matcher m = null;

        String uri = URLDecoder.decode(request.getRequestURI(), ENCODING);
        AbstractApiRequest apiRequest = null;

        /*
         *  /legislation/(api/(1.0/)?[format]/)?[type]/[id]
         *
         *    ex. /legislation/api/html/bill/s1234-2011
         */

        if(apiRequest == null && (m = SINGLE_PATTERN.matcher(uri)) != null && m.find()) {
            apiRequest = new SingleViewRequestrequest,
                    response,
                    m.group(SINGLE_FORMAT),
                    m.group(SINGLE_TYPE),
                    m.group(SINGLE_ID));
        }

        /*
         *  /legislation/(api/(1.0/)?)?[type](/[page number](/[page size]))?
         *
         *    ex.  legislation/bills/1/20 (first page, 20 bills a page)
         */
        if(apiRequest == null && (m = MULTI_PATTERN.matcher(uri)) != null && m.find()) {
            apiRequest = new MultiViewRequestrequest,
                    response,
                    m.group(MULTI_FORMAT),
                    m.group(MULTI_TYPE),
                    m.group(MULTI_PAGE_NUMBER),
                    m.group(MULTI_PAGE_SIZE));
        }

        /*
         *  /legislation/(api/(1.0/)?)?[key]/[value](/[page number](/[page size]))?
         *
         *    ex. /legislation/api/committee/finance
         */

        if(apiRequest == null && (m = KEY_VALUE_PATTERN.matcher(uri)) != null && m.find()) {
            logger.info(TextFormatter.append("Key value request: ", uri));
            apiRequest = new KeyValueViewRequestrequest,
                    response,
                    m.group(KEY_VALUE_FORMAT),
                    m.group(KEY_VALUE_KEY),
                    m.group(KEY_VALUE_VALUE),
                    m.group(KEY_VALUE_PAGE_NUMBER),
                    m.group(KEY_VALUE_PAGE_SIZE));
        }

        if(apiRequest == null && (m = SEARCH_PATTERN.matcher(uri)) != null && m.find()) {
            apiRequest = new SearchRequest(    request,
                    response,
                    m.group(SEARCH_FORMAT),
                    m.group(SEARCH_KEY),
                    m.group(SEARCH_VALUE),
                    m.group(SEARCH_PAGE_NUMBER),
                    m.group(SEARCH_PAGE_SIZE));
        }

        try {
            if(apiRequest == null)
                throw new ApiRequestException(TextFormatter.append("Failed to route request: ", uri));

            apiRequest.execute();
        }
        catch(ApiRequestException e) {
            logger.error(e);
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
View Full Code Here

TOP

Related Classes of gov.nysenate.openleg.api.AbstractApiRequest

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.