Package it.hotel.controller.structure

Source Code of it.hotel.controller.structure.StructureControllerDelegate

package it.hotel.controller.structure;

import it.hotel.controller.locale.ILocaleContainer;
import it.hotel.controller.user.IUserContainer;
import it.hotel.model.room.manager.IRoomManager;
import it.hotel.model.structure.Structure;
import it.hotel.model.structure.manager.IStructureManager;
import it.hotel.model.user.IUser;
import it.hotel.model.user.manager.IUserManager;
import it.hotel.system.SystemUtils;
import it.hotel.system.exception.SystemException;

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 StructureControllerDelegate {
 
 
  IStructureManager structureManager;
  protected IRoomManager roomManager;
  protected IUserContainer userContainer;
  protected ILocaleContainer localeContainer;
  protected IUserManager userManager;
 
 
 
 
  /**
   * Create a new ModelAndView that contains the form for
   * a new structure.
   * @param req
   * @param resp
   * @return
   */ 
  public ModelAndView factory(HttpServletRequest req, HttpServletResponse resp) {
       
    String structure = req.getParameter("structure");
    return new ModelAndView("redirect:/"+structure+"/new.htm");
       
  }
 
  /**
   * Change the active hotel for the current user
   * @param hotelid - id of hotel to change to
   * @return to the frontpage of the backoffice
   */
  public ModelAndView change(HttpServletRequest req, HttpServletResponse resp) {

    int structureId = Integer.parseInt(req.getParameter("structureId"));
    change(structureId);
    return new ModelAndView("redirect:/home.htm");
  }
 
 
  protected void change(int structureId) {
   
    IUser user = userContainer.getUser();
    user.setStructureId(structureId);
    try {
      userManager.updateUser(user);
    } catch (SystemException e) {
    }
  }
 
 
  public ModelAndView list(HttpServletRequest req, HttpServletResponse resp) {
   
    IUser user = userContainer.getUser();
    Structure structure = (Structure) structureManager.get(user.getStructureId());
    ArrayList<Structure> hotels = new ArrayList<Structure>();
    hotels.add(structure);
    if (userContainer.getUser().getRole().hasPermission("SUPERUSER"))
    {
      return new ModelAndView("hotel.structure.list.admin","elements", hotels);
    }
   
    return new ModelAndView("hotel.structure.list","elements", hotels);
    }
 
 
    public ModelAndView edit(HttpServletRequest req, HttpServletResponse resp) {
   
    String id = req.getParameter("id");
    String locale = req.getParameter("locale");
   
    String oldLocale = localeContainer.getLocale();
   
   
   

    if(id != null){
      if (locale != null)
      {
        localeContainer.setLocale(locale);
      }
      Structure hotel = (Structure) this.getStructure(Integer.parseInt(id));
      hotel.setLocale(localeContainer.getLocale());
      String clazz = hotel.getType();
      localeContainer.setLocale(oldLocale);
          return new ModelAndView("add" + clazz, "structure", hotel);     
    }
    return new ModelAndView("redirect:/Structure/list.htm");
    }
   
    public ModelAndView delete(HttpServletRequest req, HttpServletResponse resp) {
    String id = req.getParameter("id");
    String clazz = this.getClassFirstUpper(req);
    this.removeStructure(Integer.parseInt(id));
    return new ModelAndView("redirect:/Structure/list.htm");
    }
   
    public ModelAndView update(HttpServletRequest req, HttpServletResponse resp) {
     
      String clazz = this.getClassFirstUpper(req);
    return new ModelAndView("redirect:/Structure/list.htm");
    }
   
    public ModelAndView view(HttpServletRequest req, HttpServletResponse resp) {
    String id = req.getParameter("id");
   
   
    if(id != null){
      String clazz = this.getClassFirstUpper(req);
          return new ModelAndView("view" + clazz, "hotel", getStructure(Integer.parseInt(id)));     
    }
    return new ModelAndView("redirect:/Structure/list.htm");
    }
 
  @Resource(name="localeContainer")
  public void setLocaleContainer(ILocaleContainer localeContainer) {
    this.localeContainer = localeContainer;
  }

  @Resource(name="userContainer")
  public void setUserContainer(IUserContainer userContainer) {
    this.userContainer = userContainer;
  }

  @Resource(name="userManager")
  public void setUserManager(IUserManager userManager) {
    this.userManager = userManager;
  }
 
  @Resource(name="roomManager")
  public void setRoomManager(IRoomManager roomManager) {
    this.roomManager = roomManager;
  }
 
  @Resource(name="structureManager")
  public void setStructureManager(IStructureManager structureManager) { 
    this.structureManager = structureManager;
  }
 
  public Object getStructure(int id){
    SystemUtils.print("getStructure",id);
    return (Structure) structureManager.get(id);
  }
 
  private void removeStructure(int id){
    structureManager.remove(id);
  }
 
  /**
   * Return a string represents the class name of the structure with the upper case first letter
   * @param req
   * @return
   */
  private String getClassFirstUpper(HttpServletRequest req) {
   
    String id = req.getParameter("id");
    Structure structure = (Structure) structureManager.get(Integer.parseInt(id));
    String clazz = structure.getType();
    return clazz;
  }
 
  /**
   * Return a string represents the class name of the structure with the lower case first letter
   * @param req
   * @return
   */
  private String getClassFirstLower(HttpServletRequest req) {
   
    String id = req.getParameter("id");
    Structure structure = (Structure) structureManager.get(Integer.parseInt(id));
    String clazz = structure.getType().toLowerCase();
    return clazz; 
  }

}
TOP

Related Classes of it.hotel.controller.structure.StructureControllerDelegate

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.