SoggettiProprietaAdd.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.commons.Liste;
  31. import org.openspcoop2.core.registry.Proprieta;
  32. import org.openspcoop2.core.registry.Soggetto;
  33. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  34. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  35. import org.openspcoop2.web.ctrlstat.dao.SoggettoCtrlStat;
  36. import org.openspcoop2.web.ctrlstat.driver.DriverControlStationException;
  37. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  38. import org.openspcoop2.web.lib.mvc.DataElement;
  39. import org.openspcoop2.web.lib.mvc.ForwardParams;
  40. import org.openspcoop2.web.lib.mvc.GeneralData;
  41. import org.openspcoop2.web.lib.mvc.PageData;
  42. import org.openspcoop2.web.lib.mvc.Parameter;
  43. import org.openspcoop2.web.lib.mvc.ServletUtils;
  44. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  45. /**
  46.  * SoggettiProprietaAdd
  47.  *
  48.  * @author Andrea Poli (apoli@link.it)
  49.  * @author Giuliano Pintori (pintori@link.it)
  50.  * @author $Author$
  51.  * @version $Rev$, $Date$
  52.  *
  53.  */
  54. public final class SoggettiProprietaAdd extends Action {

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

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

  58.         // Inizializzo PageData
  59.         PageData pd = new PageData();

  60.         GeneralHelper generalHelper = new GeneralHelper(session);

  61.         // Inizializzo GeneralData
  62.         GeneralData gd = generalHelper.initGeneralData(request);
  63.  
  64.         try {
  65.             SoggettiHelper soggettiHelper = new SoggettiHelper(request, pd, session);
  66.            
  67.             String id = soggettiHelper.getParameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID);
  68.             long idSoggettoLong = Long.parseLong(id);
  69.            
  70.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  71.            
  72.             String nome = soggettiHelper.getParameter(SoggettiCostanti.PARAMETRO_SOGGETTI_PROP_NOME);
  73.             String valore = soggettiHelper.getLockedParameter(SoggettiCostanti.PARAMETRO_SOGGETTI_PROP_VALORE, false);  
  74.            
  75.             // Wrap value
  76.             valore = soggettiHelper.wrapValoreProprieta(SoggettiCostanti.PARAMETRO_SOGGETTI_PROP_VALORE, valore);
  77.            
  78.             // Preparo il menu
  79.             soggettiHelper.makeMenu();
  80.            
  81.             SoggettiCore soggettiCore = new SoggettiCore();
  82.            
  83.             Soggetto soggettoRegistry = null;
  84.             org.openspcoop2.core.config.Soggetto soggettoConfig = null;
  85.            
  86.             soggettoRegistry = soggettiCore.getSoggettoRegistro(idSoggettoLong);
  87.             if(soggettoRegistry==null) {
  88.                 throw new DriverControlStationException("Soggetto non trovato con id '"+idSoggettoLong+"'");
  89.             }
  90.            
  91.             soggettoConfig = soggettiCore.getSoggetto(idSoggettoLong);// core.getSoggetto(new
  92.            
  93.             String nomeprov = null;
  94.             String tipoprov = null;
  95.             if(soggettiCore.isRegistroServiziLocale()){
  96.                 nomeprov = soggettoRegistry.getNome();
  97.                 tipoprov = soggettoRegistry.getTipo();
  98.             }
  99.             else{
  100.                 nomeprov = soggettoConfig.getNome();
  101.                 tipoprov = soggettoConfig.getTipo();
  102.             }

  103.             String protocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(tipoprov);
  104.            
  105.             List<Parameter> parametersServletSoggettoChange = new ArrayList<>();
  106.             Parameter pIdSoggetto = new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID, id);
  107.             Parameter pNomeSoggetto = new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_NOME, nomeprov);
  108.             Parameter pTipoSoggetto = new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPO, tipoprov);
  109.             parametersServletSoggettoChange.add(pIdSoggetto);
  110.             parametersServletSoggettoChange.add(pNomeSoggetto);
  111.             parametersServletSoggettoChange.add(pTipoSoggetto);

  112.             List<Parameter> lstParam = new ArrayList<>();
  113.             lstParam.add(new Parameter(SoggettiCostanti.LABEL_SOGGETTI, SoggettiCostanti.SERVLET_NAME_SOGGETTI_LIST));
  114.             lstParam.add(new Parameter(soggettiHelper.getLabelNomeSoggetto(protocollo, soggettoRegistry.getTipo() , soggettoRegistry.getNome()),
  115.                     SoggettiCostanti.SERVLET_NAME_SOGGETTI_CHANGE, parametersServletSoggettoChange.toArray(new Parameter[parametersServletSoggettoChange.size()])));
  116.             if(soggettoRegistry.sizeProprietaList()>1) {
  117.                 lstParam.add(new Parameter(SoggettiCostanti.LABEL_PARAMETRO_SOGGETTI_PROPRIETA,
  118.                             SoggettiCostanti.SERVLET_NAME_SOGGETTI_PROPRIETA_LIST, parametersServletSoggettoChange.toArray(new Parameter[parametersServletSoggettoChange.size()])));
  119.             }
  120.             lstParam.add(ServletUtils.getParameterAggiungi());

  121.             // Se nome = null, devo visualizzare la pagina per l'inserimento
  122.             // dati
  123.             if (soggettiHelper.isEditModeInProgress()) {
  124.                 // setto la barra del titolo
  125.                 ServletUtils.setPageDataTitle(pd, lstParam);

  126.                 // preparo i campi
  127.                 List<DataElement> dati = new ArrayList<>();
  128.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  129.                
  130.                 dati = soggettiHelper.addSoggettoHiddenToDati(dati, id,nomeprov, tipoprov);

  131.                 dati = soggettiHelper.addProprietaToDati(TipoOperazione.ADD, soggettiHelper.getSize(), nome, valore, dati);

  132.                 pd.setDati(dati);

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

  134.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, SoggettiCostanti.OBJECT_NAME_SOGGETTI_PROPRIETA,
  135.                         ForwardParams.ADD());
  136.             }

  137.             // Controlli sui campi immessi
  138.             boolean isOk = soggettiHelper.soggettiProprietaCheckData(TipoOperazione.ADD);
  139.             if (!isOk) {
  140.                 // setto la barra del titolo
  141.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  144.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  145.                
  146.                 dati = soggettiHelper.addSoggettoHiddenToDati(dati, id,nomeprov, tipoprov);
  147.                
  148.                 dati = soggettiHelper.addProprietaToDati(TipoOperazione.ADD, soggettiHelper.getSize(), nome, valore, dati);

  149.                 pd.setDati(dati);

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

  151.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, SoggettiCostanti.OBJECT_NAME_SOGGETTI_PROPRIETA,
  152.                         ForwardParams.ADD());
  153.             }

  154.             // Inserisco la property della porta applicativa nel db
  155.             Proprieta ssp = new Proprieta();
  156.             ssp.setNome(nome);
  157.             ssp.setValore(valore);
  158.             soggettoRegistry.addProprieta(ssp);

  159.             SoggettoCtrlStat sog = new SoggettoCtrlStat(soggettoRegistry, soggettoConfig);
  160.             sog.setOldNomeForUpdate(nomeprov);
  161.             sog.setOldTipoForUpdate(tipoprov);

  162.             // eseguo l'aggiornamento
  163.             List<Object> listOggettiDaAggiornare = SoggettiUtilities.getOggettiDaAggiornare(soggettiCore, nomeprov, nomeprov, tipoprov, tipoprov, sog);
  164.             soggettiCore.performUpdateOperation(userLogin, soggettiHelper.smista(), listOggettiDaAggiornare.toArray());

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

  167.             int idLista = Liste.SOGGETTI_PROP;

  168.             ricerca = soggettiHelper.checkSearchParameters(idLista, ricerca);

  169.             List<Proprieta> lista = soggettiCore.soggettiProprietaList(Integer.parseInt(id), ricerca);

  170.             soggettiHelper.prepareSoggettiProprietaList(soggettoRegistry, id, ricerca, lista);

  171.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  172.             // Forward control to the specified success URI
  173.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, SoggettiCostanti.OBJECT_NAME_SOGGETTI_PROPRIETA,
  174.                     ForwardParams.ADD());
  175.         } catch (Exception e) {
  176.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  177.                     SoggettiCostanti.OBJECT_NAME_SOGGETTI_PROPRIETA,
  178.                     ForwardParams.ADD());
  179.         }  
  180.     }

  181.    
  182. }