SoggettiRuoliAdd.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.soggetti;

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

  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.RuoliSoggetto;
  31. import org.openspcoop2.core.registry.RuoloSoggetto;
  32. import org.openspcoop2.core.registry.Soggetto;
  33. import org.openspcoop2.core.registry.constants.RuoloContesto;
  34. import org.openspcoop2.core.registry.constants.RuoloTipologia;
  35. import org.openspcoop2.core.registry.driver.FiltroRicercaRuoli;
  36. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  37. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  38. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  39. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  40. import org.openspcoop2.web.ctrlstat.servlet.ruoli.RuoliCostanti;
  41. import org.openspcoop2.web.lib.mvc.DataElement;
  42. import org.openspcoop2.web.lib.mvc.DataElementType;
  43. import org.openspcoop2.web.lib.mvc.ForwardParams;
  44. import org.openspcoop2.web.lib.mvc.GeneralData;
  45. import org.openspcoop2.web.lib.mvc.PageData;
  46. import org.openspcoop2.web.lib.mvc.Parameter;
  47. import org.openspcoop2.web.lib.mvc.ServletUtils;
  48. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  49. /**
  50.  * SoggettiRuoliAdd
  51.  *
  52.  * @author Andrea Poli (apoli@link.it)
  53.  * @author $Author$
  54.  * @version $Rev$, $Date$
  55.  *
  56.  */
  57. public final class SoggettiRuoliAdd extends Action {

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

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

  61.         // Inizializzo PageData
  62.         PageData pd = new PageData();

  63.         GeneralHelper generalHelper = new GeneralHelper(session);

  64.         // Inizializzo GeneralData
  65.         GeneralData gd = generalHelper.initGeneralData(request);

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

  67.         try {
  68.             SoggettiHelper soggettiHelper = new SoggettiHelper(request, pd, session);

  69.             String id = soggettiHelper.getParameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID);
  70.             int idSogg = Integer.parseInt(id);
  71.            
  72.             String nome = soggettiHelper.getParameter(CostantiControlStation.PARAMETRO_RUOLO);

  73.             String accessDaChangeTmp = soggettiHelper.getParameter(SoggettiCostanti.PARAMETRO_SOGGETTO_RUOLI_ACCESSO_DA_CHANGE);
  74.             boolean accessDaChange = ServletUtils.isCheckBoxEnabled(accessDaChangeTmp);

  75.             SoggettiCore soggettiCore = new SoggettiCore();

  76.             Soggetto soggettoRegistry = soggettiCore.getSoggettoRegistro(idSogg);
  77.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(soggettoRegistry.getTipo());
  78.             String tmpTitle = soggettiHelper.getLabelNomeSoggetto(protocollo, soggettoRegistry.getTipo() , soggettoRegistry.getNome());
  79.            
  80.             FiltroRicercaRuoli filtroRuoli = new FiltroRicercaRuoli();
  81.             filtroRuoli.setContesto(RuoloContesto.PORTA_APPLICATIVA);
  82.             filtroRuoli.setTipologia(RuoloTipologia.INTERNO);
  83.            
  84.             List<String> ruoli = new ArrayList<>();
  85.             if(soggettoRegistry.getRuoli()!=null && soggettoRegistry.getRuoli().getRuoloList()!=null && !soggettoRegistry.getRuoli().getRuoloList().isEmpty()){
  86.                 for (RuoloSoggetto ruoloSoggetto : soggettoRegistry.getRuoli().getRuoloList()) {
  87.                     ruoli.add(ruoloSoggetto.getNome());
  88.                 }
  89.             }
  90.            
  91.            
  92.             // Preparo il menu
  93.             soggettiHelper.makeMenu();

  94.             // Se nomehid = null, devo visualizzare la pagina per l'inserimento
  95.             // dati
  96.             if (soggettiHelper.isEditModeInProgress()) {
  97.                
  98.                 // setto la barra del titolo
  99.                 if(accessDaChange) {
  100.                     ServletUtils.setPageDataTitle_ServletFirst(pd, SoggettiCostanti.LABEL_SOGGETTI,
  101.                             SoggettiCostanti.SERVLET_NAME_SOGGETTI_LIST);
  102.                     ServletUtils.appendPageDataTitle(pd,
  103.                             new Parameter(tmpTitle,
  104.                                     SoggettiCostanti.SERVLET_NAME_SOGGETTI_CHANGE,
  105.                                     new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID,soggettoRegistry.getId()+""),
  106.                                     new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_NOME,soggettoRegistry.getNome()),
  107.                                     new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPO,soggettoRegistry.getTipo())));
  108.                     ServletUtils.appendPageDataTitle(pd,
  109.                             new Parameter(RuoliCostanti.LABEL_RUOLI, SoggettiCostanti.SERVLET_NAME_SOGGETTI_RUOLI_LIST,
  110.                                     new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID,soggettoRegistry.getId()+""),
  111.                                     new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_RUOLI_ACCESSO_DA_CHANGE,accessDaChangeTmp)
  112.                                     )
  113.                             );
  114.                     ServletUtils.appendPageDataTitle(pd,
  115.                             ServletUtils.getParameterAggiungi());
  116.                 }
  117.                 else {
  118.                     List<Parameter> lstParm = new ArrayList<>();
  119.                     lstParm.add(new Parameter(SoggettiCostanti.LABEL_SOGGETTI, SoggettiCostanti.SERVLET_NAME_SOGGETTI_LIST));
  120.                     lstParm.add(new Parameter("Ruoli di " + tmpTitle, SoggettiCostanti.SERVLET_NAME_SOGGETTI_RUOLI_LIST,
  121.                             new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID,soggettoRegistry.getId()+""),
  122.                             new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_RUOLI_ACCESSO_DA_CHANGE,accessDaChangeTmp)
  123.                             )
  124.                     );
  125.                     lstParm.add(ServletUtils.getParameterAggiungi());
  126.                     ServletUtils.setPageDataTitle(pd,lstParm);
  127.                 }
  128.                
  129.                 // preparo i campi
  130.                 List<DataElement> dati = new ArrayList<>();
  131.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  132.                 DataElement de = new DataElement();
  133.                 de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_ID);
  134.                 de.setValue(id);
  135.                 de.setType(DataElementType.HIDDEN);
  136.                 dati.add(de);
  137.                
  138.                 dati = soggettiHelper.addRuoliToDati(TipoOperazione.ADD, dati, false, filtroRuoli, nome, ruoli, false, true, true, accessDaChangeTmp, false);
  139.                
  140.                 pd.setDati(dati);

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

  142.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  143.                         SoggettiCostanti.OBJECT_NAME_SOGGETTI_RUOLI,
  144.                         ForwardParams.ADD());
  145.             }

  146.             // Controlli sui campi immessi
  147.             boolean isOk = soggettiHelper.ruoloCheckData(TipoOperazione.ADD, nome, ruoli);
  148.             if (!isOk) {
  149.                 // setto la barra del titolo
  150.                 List<Parameter> lstParm = new ArrayList<>();
  151.                 lstParm.add(new Parameter(SoggettiCostanti.LABEL_SOGGETTI, SoggettiCostanti.SERVLET_NAME_SOGGETTI_LIST));
  152.                 lstParm.add(new Parameter("Ruoli di " + tmpTitle, SoggettiCostanti.SERVLET_NAME_SOGGETTI_RUOLI_LIST,
  153.                         new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID,soggettoRegistry.getId()+"")));
  154.                 lstParm.add(ServletUtils.getParameterAggiungi());
  155.                 ServletUtils.setPageDataTitle(pd,lstParm);

  156.                 // preparo i campi
  157.                 List<DataElement> dati = new ArrayList<>();
  158.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  159.                
  160.                 DataElement de = new DataElement();
  161.                 de.setName(SoggettiCostanti.PARAMETRO_SOGGETTO_ID);
  162.                 de.setValue(id);
  163.                 de.setType(DataElementType.HIDDEN);
  164.                 dati.add(de);
  165.                
  166.                 dati = soggettiHelper.addRuoliToDati(TipoOperazione.ADD, dati, false, filtroRuoli, nome, ruoli, false, true, true, accessDaChangeTmp, false);

  167.                 pd.setDati(dati);

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

  169.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  170.                         SoggettiCostanti.OBJECT_NAME_SOGGETTI_RUOLI,
  171.                         ForwardParams.ADD());
  172.             }

  173.             // Inserisco
  174.             RuoloSoggetto ruoloSoggetto = new RuoloSoggetto();
  175.             ruoloSoggetto.setNome(nome);
  176.             if(soggettoRegistry.getRuoli()==null){
  177.                 soggettoRegistry.setRuoli(new RuoliSoggetto());
  178.             }
  179.             soggettoRegistry.getRuoli().addRuolo(ruoloSoggetto);
  180.            
  181.             soggettiCore.performUpdateOperation(userLogin, soggettiHelper.smista(), soggettoRegistry);

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

  184.             List<String> lista = soggettiCore.soggettiRuoliList(idSogg, ricerca);
  185.                    
  186.             soggettiHelper.prepareRuoliList(ricerca, lista);

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

  188.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  189.                     SoggettiCostanti.OBJECT_NAME_SOGGETTI_RUOLI,
  190.                     ForwardParams.ADD());
  191.         } catch (Exception e) {
  192.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  193.                     SoggettiCostanti.OBJECT_NAME_SOGGETTI_RUOLI, ForwardParams.ADD());
  194.         }
  195.     }


  196. }