Package org.magicbox.controller

Source Code of org.magicbox.controller.GruppiController

/*
* Copyright Massimiliano Dessi' (desmax74@yahoo.it)
*
* Licensed under Apache License Version 2.0
* (http://www.apache.org/licenses/LICENSE-2.0),
*
* for commercial use, under
* GNU General Public License Version 2 or later (the "GPL")
* http://www.gnu.org/licenses/gpl.html
*/
package org.magicbox.controller;

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

import org.magicbox.controller.util.WebUtils;
import org.magicbox.domain.Gruppo;
import org.magicbox.exception.GruppoNonTrovatoException;
import org.magicbox.service.GruppiService;
import org.magicbox.service.UtentiManager;
import org.magicbox.util.Constant;
import org.springframework.web.bind.ServletRequestUtils;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.multiaction.MultiActionController;

/**
* Controller per gestione gruppi
*
* @author Massimiliano Dessì (desmax74@yahoo.it)
* @since jdk 1.6.0
* @version 3.0
*/
public class GruppiController extends MultiActionController {

    public ModelAndView elenco(HttpServletRequest req, HttpServletResponse res) throws Exception {
        return new ModelAndView("gruppi/elencoGruppi", Constant.GRUPPI, gruppiService.getGruppiCentro(WebUtils.getIdCentro(req)));
    }

    public ModelAndView gruppo(HttpServletRequest req, HttpServletResponse res) throws Exception {

        long id = ServletRequestUtils.getRequiredLongParameter(req, Constant.ID);

        Gruppo gruppo = gruppiService.getGruppo(id, WebUtils.getIdCentro(req));

        if (gruppo != null) {
            ModelAndView mav = new ModelAndView("gruppi/dettaglioGruppo");
            mav.addObject(Constant.GRUPPO, gruppo);
            mav.addObject(Constant.UTENTI_GRUPPO, utentiManager.getUtentiGruppo(gruppo.getIdCentro(), id));
            mav.addObject(Constant.UTENTI_LIBERI, utentiManager.getUtentiCentroLiberi(gruppo.getIdCentro()));
            return mav;
        } else {
            throw new GruppoNonTrovatoException();
        }
    }

    public ModelAndView selezione(HttpServletRequest req, HttpServletResponse res) throws Exception {

        long id = ServletRequestUtils.getRequiredLongParameter(req, Constant.ID);
        String ids = req.getParameter(Constant.INSERITI_HIDDEN);
        utentiManager.updateCancellazioneGruppo(id);
        if (ids != null && ids.length() > 0) {
            utentiManager.aggiornaUtenti(WebUtils.extractIdFromString(ids, separatore), id);
        }
        return new ModelAndView(Constant.REDIRECT_ELENCO_GRUPPI);

    }

    public ModelAndView conferma(HttpServletRequest req, HttpServletResponse res) throws Exception {
        long id = ServletRequestUtils.getRequiredLongParameter(req, Constant.ID);
        return new ModelAndView("gruppi/confermaEliminazioneGruppo", Constant.GRUPPO, gruppiService.getGruppo(id, WebUtils.getIdCentro(req)));
    }

    public ModelAndView elimina(HttpServletRequest req, HttpServletResponse res) throws Exception {
        long id = ServletRequestUtils.getRequiredLongParameter(req, Constant.ID);
        gruppiService.deleteGruppo(id, WebUtils.getIdCentro(req));
        return new ModelAndView(Constant.REDIRECT_ELENCO_GRUPPI);
    }

    public void setGruppiService(GruppiService gruppiService) {
        this.gruppiService = gruppiService;
    }

    public void setUtentiManager(UtentiManager utentiManager) {
        this.utentiManager = utentiManager;
    }

    public void setSeparatore(String separatore) {
        this.separatore = separatore;
    }

    private GruppiService gruppiService;
    private UtentiManager utentiManager;
    private String separatore;
}
TOP

Related Classes of org.magicbox.controller.GruppiController

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.