GruppiAdd.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */


  20. package org.openspcoop2.web.ctrlstat.servlet.gruppi;

  21. import java.util.List;
  22. import java.util.ArrayList;

  23. import javax.servlet.http.HttpServletRequest;
  24. import javax.servlet.http.HttpServletResponse;
  25. import javax.servlet.http.HttpSession;

  26. import org.apache.struts.action.Action;
  27. import org.apache.struts.action.ActionForm;
  28. import org.apache.struts.action.ActionForward;
  29. import org.apache.struts.action.ActionMapping;
  30. import org.openspcoop2.core.registry.Gruppo;
  31. import org.openspcoop2.core.registry.constants.ServiceBinding;
  32. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  33. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  34. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  35. import org.openspcoop2.web.lib.mvc.DataElement;
  36. import org.openspcoop2.web.lib.mvc.ForwardParams;
  37. import org.openspcoop2.web.lib.mvc.GeneralData;
  38. import org.openspcoop2.web.lib.mvc.PageData;
  39. import org.openspcoop2.web.lib.mvc.ServletUtils;
  40. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  41. /**
  42.  * GruppiAdd
  43.  *
  44.  * @author Andrea Poli (apoli@link.it)
  45.  * @author Giuliano Pintori (pintori@link.it)
  46.  * @author $Author$
  47.  * @version $Rev$, $Date$
  48.  *
  49.  */
  50. public final class GruppiAdd extends Action {

  51.     @Override
  52.     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

  53.         HttpSession session = request.getSession(true);

  54.         // Inizializzo PageData
  55.         PageData pd = new PageData();

  56.         GeneralHelper generalHelper = new GeneralHelper(session);

  57.         // Inizializzo GeneralData
  58.         GeneralData gd = generalHelper.initGeneralData(request);

  59.         String userLogin = ServletUtils.getUserLoginFromSession(session);  

  60.         try {
  61.             GruppiHelper gruppiHelper = new GruppiHelper(request, pd, session);

  62.             String nome = gruppiHelper.getParameter(GruppiCostanti.PARAMETRO_GRUPPO_NOME);
  63.             String descrizione = gruppiHelper.getParameter(GruppiCostanti.PARAMETRO_GRUPPO_DESCRIZIONE);
  64.             String serviceBinding = gruppiHelper.getParameter(GruppiCostanti.PARAMETRO_GRUPPO_SERVICE_BINDING);
  65.             if (serviceBinding == null) {
  66.                 serviceBinding = GruppiCostanti.DEFAULT_VALUE_PARAMETRO_GRUPPO_SERVICE_BINDING_QUALSIASI;
  67.             }


  68.             GruppiCore gruppiCore = new GruppiCore();

  69.             // Preparo il menu
  70.             gruppiHelper.makeMenu();

  71.             // Se nomehid = null, devo visualizzare la pagina per l'inserimento
  72.             // dati
  73.             if (gruppiHelper.isEditModeInProgress()) {
  74.                
  75.                 // setto la barra del titolo
  76.                 ServletUtils.setPageDataTitle_ServletAdd(pd, GruppiCostanti.LABEL_GRUPPI, GruppiCostanti.SERVLET_NAME_GRUPPI_LIST);

  77.                 // preparo i campi
  78.                 List<DataElement> dati = new ArrayList<>();
  79.                 dati.add(ServletUtils.getDataElementForEditModeFinished());


  80.                 dati = gruppiHelper.addGruppoToDati(TipoOperazione.ADD, null, nome != null ? nome : "", descrizione != null ? descrizione : "", serviceBinding, dati);

  81.                 pd.setDati(dati);

  82.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  83.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, GruppiCostanti.OBJECT_NAME_GRUPPI, ForwardParams.ADD());
  84.             }

  85.             // Controlli sui campi immessi
  86.             boolean isOk = gruppiHelper.gruppoCheckData(TipoOperazione.ADD, null);
  87.             if (!isOk) {
  88.                
  89.                 // setto la barra del titolo
  90.                 ServletUtils.setPageDataTitle_ServletAdd(pd, GruppiCostanti.LABEL_GRUPPI, GruppiCostanti.SERVLET_NAME_GRUPPI_LIST);

  91.                 // preparo i campi
  92.                 List<DataElement> dati = new ArrayList<>();

  93.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  94.                
  95.                 dati = gruppiHelper.addGruppoToDati(TipoOperazione.ADD, null, nome, descrizione, serviceBinding, dati);

  96.                 pd.setDati(dati);

  97.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  98.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, GruppiCostanti.OBJECT_NAME_GRUPPI, ForwardParams.ADD());
  99.             }

  100.             // Inserisco il registro nel db
  101.             Gruppo gruppo = new Gruppo();
  102.             gruppo.setNome(nome);
  103.             gruppo.setDescrizione(descrizione);
  104.             if(!serviceBinding.equals(GruppiCostanti.DEFAULT_VALUE_PARAMETRO_GRUPPO_SERVICE_BINDING_QUALSIASI))
  105.                 gruppo.setServiceBinding(ServiceBinding.valueOf(serviceBinding));
  106.             else
  107.                 gruppo.setServiceBinding(null);
  108.             gruppo.setSuperUser(userLogin);
  109.            
  110.             gruppiCore.performCreateOperation(userLogin, gruppiHelper.smista(), gruppo);

  111.             // Preparo la lista
  112.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  113.             List<Gruppo> lista = null;
  114.             if(gruppiCore.isVisioneOggettiGlobale(userLogin)){
  115.                 lista = gruppiCore.gruppiList(null, ricerca);
  116.             }else{
  117.                 lista = gruppiCore.gruppiList(userLogin, ricerca);
  118.             }
  119.            
  120.             gruppiHelper.prepareGruppiList(ricerca, lista);

  121.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  122.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, GruppiCostanti.OBJECT_NAME_GRUPPI, ForwardParams.ADD());
  123.         } catch (Exception e) {
  124.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping, GruppiCostanti.OBJECT_NAME_GRUPPI, ForwardParams.ADD());
  125.         }
  126.     }


  127. }