com.shampan.db.services.SearchController.java Source code

Java tutorial

Introduction

Here is the source code for com.shampan.db.services.SearchController.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.shampan.db.services;

import com.google.common.base.Strings;
import com.shampan.services.SearchService;
import io.vertx.ext.web.RoutingContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 *
 * @author Sampan-IT
 */
public class SearchController {
    private static Logger logger = LoggerFactory.getLogger(StatusController.class);

    public static void getSearchResult(RoutingContext routingContext) {
        int offset = 0;
        int limit = 10;
        String searchValue = routingContext.request().getParam("searchValue");
        /*
        If offset is incorrect then offset will be used as default
        */
        if (!Strings.isNullOrEmpty(routingContext.request().getParam("offset"))) {
            try {
                offset = Integer.parseInt(routingContext.request().getParam("offset"));
            } catch (NumberFormatException nfe) {
                logger.debug(nfe.getMessage());
            }
        }
        /*
        If limit is incorrect then limit will be used as default
        */
        if (!Strings.isNullOrEmpty(routingContext.request().getParam("limit"))) {
            try {
                limit = Integer.parseInt(routingContext.request().getParam("limit"));
            } catch (NumberFormatException nfe) {
                logger.debug(nfe.getMessage());
            }
        }
        routingContext.response().putHeader("content-type", "application/json; charset=utf-8")
                .end(SearchService.getSearchResult(searchValue, offset, limit));
    }

}