/*
Copyright (C) European Community 2008 - Licensed under the EUPL V.1.0 (http://ec.europa.eu/idabc/en/document/6523)
*/
package it.hotel.controller.customer;
import it.hotel.model.customer.Customer;
import it.hotel.model.customer.manager.ICustomerManager;
import it.hotel.model.structure.Structure;
import it.hotel.model.structure.manager.IStructureManager;
import java.util.ArrayList;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.ModelAndView;
/**
*
*
*/
public class CustomerControllerDelegate {
private ICustomerManager manager;
private IStructureManager structureManager;
/**
*
* @param req
* @param resp
* @return
*/
public ModelAndView list(HttpServletRequest req, HttpServletResponse resp) {
if(req.getParameter("sort") == null){
return new ModelAndView("hotel.customer.list","elements", manager.getAll());
}else {
return new ModelAndView("hotel.customer.list","elements", manager.getAll(req.getParameter("sort")));
}
}
/**
*
* @param req
* @param resp
* @return
*/
public ModelAndView delete(HttpServletRequest req, HttpServletResponse resp) {
String id = req.getParameter("id");
manager.remove(Integer.parseInt(id));
if(manager.get(Integer.parseInt(id)) != null){
req.setAttribute("error", "delete.violate.foreign");
}
return this.list(req, resp);
}
/**
*
* @param req
* @param resp
* @return
*/
public ModelAndView update(HttpServletRequest req, HttpServletResponse resp) {
return new ModelAndView("hotel.customer.list","elements", manager.getAll());
}
/**
*
* @param req
* @param resp
* @return
*/
public ModelAndView edit(HttpServletRequest req, HttpServletResponse resp) {
String id = req.getParameter("id");
Customer customer = (Customer) manager.get(Integer.parseInt(id));
if(id != null){
ArrayList<Structure> hotels = new ArrayList<Structure>();
hotels.add(customer.getStructure());
req.setAttribute("hotels", hotels);
return new ModelAndView("hotel.customer.new", "customer", customer);
}
return this.list(req, resp);
}
/**
*
* @param req
* @param resp
* @return
*/
public ModelAndView view(HttpServletRequest req, HttpServletResponse resp) {
String id = req.getParameter("id");
if(id != null){
return new ModelAndView("hotel.customer.view", "customer", manager.get(Integer.parseInt(id)));
}
return this.list(req, resp);
}
public ICustomerManager getManager() {
return manager;
}
/**
*
* @param req
* @param resp
* @return
*/
public ModelAndView customer(HttpServletRequest req, HttpServletResponse resp) {
return new ModelAndView("hotel.customer");
}
/**
*
* @param req
* @param resp
* @return
*/
public ModelAndView create(HttpServletRequest req, HttpServletResponse resp) {
return new ModelAndView("hotel.customer.new", "customer", new Customer());
}
@Resource(name = "customerManager")
public void setManager(ICustomerManager manager) {
this.manager = manager;
}
@Resource(name = "structureManager")
public void setStructureManager(IStructureManager structureManager) {
this.structureManager = structureManager;
}
}