/*
Copyright (C) European Community 2008 - Licensed under the EUPL V.1.0 (http://ec.europa.eu/idabc/en/document/6523)
*/
package it.hotel.controller.room;
import it.hotel.controller.user.IUserContainer;
import it.hotel.model.room.Room;
import it.hotel.model.room.manager.IRoomManager;
import it.hotel.model.structure.Structure;
import it.hotel.model.structure.manager.IStructureManager;
import it.hotel.model.typology.manager.ITypologyManager;
import it.hotel.model.user.IUser;
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 RoomControllerDelegate {
private IRoomManager manager;
private ITypologyManager typologyManager;
protected IStructureManager structureManager;
private IUserContainer userContainer;
@Resource(name = "structureManager")
public void setStructureManager(IStructureManager structureManager) {
this.structureManager = structureManager;
}
/**
* list of all rooms for the current users hotel
* @param req
* @param resp
* @return
*/
public ModelAndView list(HttpServletRequest req, HttpServletResponse resp){
IUser user = userContainer.getUser();
if(req.getParameter("sort") == null){
ArrayList<Room> rooms = (ArrayList<Room>) manager.getRoomsFromStructure(user.getStructureId());
return new ModelAndView("hotel.room.list", "rooms", rooms);
}
else{
ArrayList<Room> rooms = (ArrayList<Room>) manager.getRoomsFromStructure(user.getStructureId());
return new ModelAndView("hotel.room.list", "rooms", rooms);
}
}
/**
*
* @param req
* @param resp
* @return
*/
public ModelAndView listFromHotel(HttpServletRequest req, HttpServletResponse resp){
int idHotel = Integer.parseInt(req.getParameter("idHotel"));
return new ModelAndView("hotel.room.list", "rooms", manager.getRoomsFromStructure(idHotel));
}
/**
*
* @param req
* @param resp
* @return
*/
public ModelAndView delete(HttpServletRequest req, HttpServletResponse resp){
int id = Integer.parseInt(req.getParameter("id"));
Room room = (Room) manager.get(id);
Structure structure = room.getStructure();
int structureId = structure.getId();
manager.remove(id);
return new ModelAndView("hotel.room.list", "rooms", manager.getRoomsFromStructure(structureId));
}
/**
*
* @param req
* @param resp
* @return
*/
public ModelAndView view(HttpServletRequest req, HttpServletResponse resp){
int id = Integer.parseInt(req.getParameter("id"));
return new ModelAndView("hotel.room.view", "room", manager.get(id));
}
/**
* produce a edit form for a room
* @param id - of room that you want to edit
* @param resp
* @return
*/
public ModelAndView edit(HttpServletRequest req, HttpServletResponse resp){
int id = Integer.parseInt(req.getParameter("id"));
Room room = (Room) manager.get(id);
Structure structure = room.getStructure();
int hotel_id_for_room = structure.getId();
req.setAttribute("typologies", typologyManager.getTypologiesFromStructure(hotel_id_for_room));
req.setAttribute("hotel", structure);
return new ModelAndView("hotel.room.new", "room", room);
}
public ITypologyManager getTypologyManager() {
return typologyManager;
}
@Resource(name = "typologyManager")
public void setTypologyManager(ITypologyManager typologyManager) {
this.typologyManager = typologyManager;
}
@Resource(name = "roomManager")
public void setManager(IRoomManager manager) {
this.manager = manager;
}
public IRoomManager getManager(){
return this.manager;
}
@Resource(name = "userContainer")
public void setUserContainer(IUserContainer userContainer) {
this.userContainer = userContainer;
}
}