package com.ejie.m62fb.control;

import com.ejie.m62fb.service.M62fbr46s0s00Service;
import com.ejie.x38.dto.JQGridJSONModel;
import com.ejie.x38.dto.Pagination;
import com.ejie.x38.util.ObjectConversionManager;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import com.ejie.m62fb.model.M62fbr46s0s00;

/**
 * M62fbr46s0s00Controller generated by UDA, 17-oct-2012 15:03:40.
 * 
XXXX
 */

@Controller
@RequestMapping(value = "/m62fbr46s0s00")
public class M62fbr46s0s00Controller {

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

	@Autowired
	private M62fbr46s0s00Service m62fbr46s0s00Service;

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

	/**
	 * Method 'getById'.
	 * 
	 * @param idM62r46t0
	 *            Integer
	 * @param idM62r45t0
	 *            Integer
	 * @param numVivienda
	 *            Integer
	 * @param fehUltModif
	 *            Date
	 * @param codUsuUltModif
	 *            String
	 * @param ideRegistro
	 *            Integer
	 * @param fecAlta
	 *            Date
	 * @return m62fbr46s0s00 M62fbr46s0s00
	 */
	@RequestMapping(value = "/{idM62r46t0}/{idM62r45t0}/{numVivienda}/{fehUltModif}/{codUsuUltModif}/{ideRegistro}/{fecAlta}", method = RequestMethod.GET)
	public @ResponseBody
	M62fbr46s0s00 getById(@PathVariable BigDecimal idM62r46t0,
			@PathVariable BigDecimal idM62r45t0,
			@PathVariable BigDecimal numVivienda,
			@PathVariable Date fehUltModif,
			@PathVariable String codUsuUltModif,
			@PathVariable Integer ideRegistro, @PathVariable Date fecAlta) {
		M62fbr46s0s00 m62fbr46s0s00 = new M62fbr46s0s00();
		m62fbr46s0s00.setIdM62r46t0(idM62r46t0);
		m62fbr46s0s00.setIdM62r45t0(idM62r45t0);
		m62fbr46s0s00.setNumVivienda(numVivienda);
		m62fbr46s0s00.setFehUltModif(fehUltModif);
		m62fbr46s0s00.setCodUsuUltModif(codUsuUltModif);
		m62fbr46s0s00.setIdeRegistro(ideRegistro);
		m62fbr46s0s00.setFecAlta(fecAlta);
		m62fbr46s0s00 = this.m62fbr46s0s00Service.find(m62fbr46s0s00);
		M62fbr46s0s00Controller.logger
				.info("[GET - findBy_PK] : Obtener M62fbr46s0s00 por PK");
		return m62fbr46s0s00;
	}

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

	/**
	 * Method 'edit'.
	 * 
	 * @param m62fbr46s0s00
	 *            M62fbr46s0s00
	 * @return M62fbr46s0s00
	 */
	@RequestMapping(method = RequestMethod.PUT)
	public @ResponseBody
	M62fbr46s0s00 edit(@RequestBody M62fbr46s0s00 m62fbr46s0s00) {
		M62fbr46s0s00 m62fbr46s0s00Aux = this.m62fbr46s0s00Service
				.update(m62fbr46s0s00);
		M62fbr46s0s00Controller.logger
				.info("[PUT] : M62fbr46s0s00 actualizado correctamente");
		return m62fbr46s0s00Aux;
	}

	/**
	 * Method 'add'.
	 * 
	 * @param m62fbr46s0s00
	 *            M62fbr46s0s00
	 * @return M62fbr46s0s00
	 */
	@RequestMapping(method = RequestMethod.POST)
	public @ResponseBody
	M62fbr46s0s00 add(@RequestBody M62fbr46s0s00 m62fbr46s0s00) {
		M62fbr46s0s00 m62fbr46s0s00Aux = this.m62fbr46s0s00Service
				.add(m62fbr46s0s00);
		M62fbr46s0s00Controller.logger
				.info("[POST] : M62fbr46s0s00 insertado correctamente");
		return m62fbr46s0s00Aux;
	}

	/**
	 * Method 'remove'.
	 * 
	 * @param idM62r46t0
	 *            Integer
	 * @param idM62r45t0
	 *            Integer
	 * @param numVivienda
	 *            Integer
	 * @param fehUltModif
	 *            Date
	 * @param codUsuUltModif
	 *            String
	 * @param ideRegistro
	 *            Integer
	 * @param fecAlta
	 *            Date
	 * @return m62fbr46s0s00
	 */
	@RequestMapping(value = "/{idM62r46t0}/{idM62r45t0}/{numVivienda}/{fehUltModif}/{codUsuUltModif}/{ideRegistro}/{fecAlta}", method = RequestMethod.DELETE)
	@ResponseStatus(value = HttpStatus.OK)
	public @ResponseBody
	M62fbr46s0s00 remove(@PathVariable BigDecimal idM62r46t0,
			@PathVariable BigDecimal idM62r45t0,
			@PathVariable BigDecimal numVivienda,
			@PathVariable Date fehUltModif,
			@PathVariable String codUsuUltModif,
			@PathVariable Integer ideRegistro, @PathVariable Date fecAlta) {
		M62fbr46s0s00 m62fbr46s0s00 = new M62fbr46s0s00();
		m62fbr46s0s00.setIdM62r46t0(idM62r46t0);
		m62fbr46s0s00.setIdM62r45t0(idM62r45t0);
		m62fbr46s0s00.setNumVivienda(numVivienda);
		m62fbr46s0s00.setFehUltModif(fehUltModif);
		m62fbr46s0s00.setCodUsuUltModif(codUsuUltModif);
		m62fbr46s0s00.setIdeRegistro(ideRegistro);
		m62fbr46s0s00.setFecAlta(fecAlta);
		this.m62fbr46s0s00Service.remove(m62fbr46s0s00);
		M62fbr46s0s00Controller.logger
				.info("[DELETE] : M62fbr46s0s00 borrado correctamente");
		return m62fbr46s0s00;
	}

	/**
	 * Method 'removeAll'.
	 * 
	 * @param m62fbr46s0s00Ids
	 *            List
	 * @return m62fbr46s0s00List
	 */
	@RequestMapping(value = "/deleteAll", method = RequestMethod.POST)
	@ResponseStatus(value = HttpStatus.OK)
	public @ResponseBody
	List<List<String>> removeMultiple(
			@RequestBody List<List<String>> m62fbr46s0s00Ids) {
		List<M62fbr46s0s00> m62fbr46s0s00List = new ArrayList<M62fbr46s0s00>();
		for (List<String> m62fbr46s0s00Id : m62fbr46s0s00Ids) {
			Iterator<String> iterator = m62fbr46s0s00Id.iterator();
			M62fbr46s0s00 m62fbr46s0s00 = new M62fbr46s0s00(); // NOPMD - Objeto
																// nuevo en la
																// lista
																// (parametro
																// del servicio)
			m62fbr46s0s00.setIdM62r46t0(ObjectConversionManager.convert(
					iterator.next(), BigDecimal.class));
			m62fbr46s0s00.setIdM62r45t0(ObjectConversionManager.convert(
					iterator.next(), BigDecimal.class));
			m62fbr46s0s00.setNumVivienda(ObjectConversionManager.convert(
					iterator.next(), BigDecimal.class));
			m62fbr46s0s00.setFehUltModif(ObjectConversionManager.convert(
					iterator.next(), java.util.Date.class));
			m62fbr46s0s00.setCodUsuUltModif(ObjectConversionManager.convert(
					iterator.next(), String.class));
			m62fbr46s0s00.setIdeRegistro(ObjectConversionManager.convert(
					iterator.next(), java.lang.Integer.class));
			m62fbr46s0s00.setFecAlta(ObjectConversionManager.convert(
					iterator.next(), java.util.Date.class));
			m62fbr46s0s00List.add(m62fbr46s0s00);
		}
		this.m62fbr46s0s00Service.removeMultiple(m62fbr46s0s00List);
		M62fbr46s0s00Controller.logger
				.info("[POST - DELETE_ALL] : M62fbr46s0s00 borrados correctamente");
		return m62fbr46s0s00Ids;
	}

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

}
