package com.ejie.m62fb.control;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.ejie.m62fb.model.M62fbCalles;
import com.ejie.m62fb.service.M62fbCallesService;
import com.ejie.x38.dto.JQGridJSONModel;
import com.ejie.x38.dto.Pagination;

/**
 * M62fbCallesController generated by UDA, 22-oct-2012 12:14:20.
 * 
XXXX
 */

@Controller
@RequestMapping(value = "/m62fbcalles")
public class M62fbCallesController {

	private static final Logger logger = LoggerFactory
			.getLogger(M62fbCallesController.class);

	@Autowired
	private M62fbCallesService m62fbCallesService;

	/**
	 * Method 'getById'.
	 * 
	 * @param codProvincia
	 *            String
	 * @param codMunicipio
	 *            String
	 * @param codCalle
	 *            String
	 * @param desCalleCas
	 *            String
	 * @param desCalleEus
	 *            String
	 * @param fecAlta
	 *            Date
	 * @param dirIpUsuario
	 *            String
	 * @param fehUltModif
	 *            Date
	 * @param codUsuUltModif
	 *            String
	 * @param ideRegistro
	 *            Integer
	 * @return m62fbCalles M62fbCalles
	 */
	@RequestMapping(value = "/{codProvincia}/{codMunicipio}/{codCalle}/{desCalleCas}", method = RequestMethod.GET)
	public @ResponseBody
	M62fbCalles getById(@PathVariable String codProvincia,
			@PathVariable String codMunicipio, @PathVariable String codCalle,
			@PathVariable String desCalleCas) {
		M62fbCalles m62fbCalles = new M62fbCalles();
		m62fbCalles.setCodProvincia(codProvincia);
		m62fbCalles.setCodMunicipio(codMunicipio);
		m62fbCalles.setCodCalle(codCalle);
		m62fbCalles.setDesCalleCas(desCalleCas);
		m62fbCalles = this.m62fbCallesService.find(m62fbCalles);
		M62fbCallesController.logger
				.info("[GET - findBy_PK] : Obtener M62fbCalles por PK");
		return m62fbCalles;
	}

	/**
	 * Method 'getAll'.
	 * 
	 * @param filterM62fbCalles
	 *            M62fbCalles
	 * @return List
	 */
	@RequestMapping(method = RequestMethod.GET)
	public @ResponseBody
	List<M62fbCalles> getAll(@ModelAttribute M62fbCalles filterM62fbCalles) {
		M62fbCallesController.logger
				.info("[GET - find_ALL] : Obtener M62fbCalles por filtro");
		return this.m62fbCallesService.findAll(filterM62fbCalles, null);
	}

	/**
	 * Method 'getAllJQGrid'.
	 * 
	 * @param filterM62fbCalles
	 *            M62fbCalles
	 * @param pagination
	 *            Pagination
	 * @return JQGridJSONModel
	 */
	@RequestMapping(method = RequestMethod.GET, headers = { "JQGridModel=true" })
	public @ResponseBody
	JQGridJSONModel getAllJQGrid(@ModelAttribute M62fbCalles filterM62fbCalles,
			@ModelAttribute Pagination pagination) {
		List<M62fbCalles> m62fbCalless = this.m62fbCallesService.findAll(
				filterM62fbCalles, pagination);
		Long recordNum = this.m62fbCallesService
				.findAllCount(filterM62fbCalles);
		M62fbCallesController.logger
				.info("[GET - jqGrid] : Obtener M62fbCalles");
		return new JQGridJSONModel(pagination, recordNum, m62fbCalless);
	}

}
