package com.ejie.m62fb.control.registroVPP;

//import com.ejie.m62fu.service.M62fbDisponibilidadVivsService;
//import com.ejie.m62fb.service.M62fbr46s0s00Service;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
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.M62fbr49s0s00;
import com.ejie.m62fb.service.registroVPP.M62fbr49s0s00Service;
import com.ejie.x38.control.exception.ResourceNotFoundException;
import com.ejie.x38.dto.JQGridJSONModel;
import com.ejie.x38.dto.Pagination;

/**
 * M62fbDisponibilidadVivsController generated by UDA, 17-oct-2012 15:45:51.
 * 
XXXX
 */

@Controller
@RequestMapping(value = "/consultaficheros")
public class ConsultaFicherosController {

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

	@Autowired
	private M62fbr49s0s00Service M62fbr49s0s00Service;

	/**
	 * Method 'getCreateForm'.
	 * 
	 * @param model
	 *            Model
	 * @return String
	 */
	@RequestMapping(value = "maint", method = RequestMethod.GET)
	public String getCreateForm(Model model) {
		ConsultaFicherosController.logger
				.info("[GET - View] : consultaficheros");
		return "consultaficheros";
	}

	/**
	 * 
	 * @param idProvincia
	 * @param descripcion
	 * @param request
	 * @return
	 */
	@RequestMapping(value = "mostrarFicheros", method = RequestMethod.GET)
	public @ResponseBody
	Object getAllLike(
			HttpServletRequest request, HttpServletResponse response) {
		try {
			Pagination pagination = null;
			pagination = new Pagination();
			pagination.setPage(Long.valueOf(request.getParameter("page")));
			pagination.setRows(Long.valueOf(request.getParameter("rows")));
			pagination.setSort(request.getParameter("sidx"));
			pagination.setAscDsc(request.getParameter("sord"));
			List<M62fbr49s0s00> ficheros = this.M62fbr49s0s00Service.findAll(
					null, pagination);

			if (ficheros == null) {
				throw new Exception("No data Found.");
			}

			Long total = this.M62fbr49s0s00Service.findAllCount(null);
			JQGridJSONModel data = new JQGridJSONModel();
			data.setPage(request.getParameter("page"));
			data.setRecords(total.intValue());
			data.setTotal(total, pagination.getRows());
			data.setRows(ficheros);
			return data;
		} catch (Exception e) {
			throw new ResourceNotFoundException("No data Found.");
		}
	}



}
