PorteApplicativeProprietaProtocolloAdd.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.pa;

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

  43. /**
  44.  * porteAppPropAdd
  45.  *
  46.  * @author Andrea Poli (apoli@link.it)
  47.  * @author Stefano Corallo (corallo@link.it)
  48.  * @author Sandra Giangrandi (sandra@link.it)
  49.  * @author $Author$
  50.  * @version $Rev$, $Date$
  51.  *
  52.  */
  53. public final class PorteApplicativeProprietaProtocolloAdd extends Action {

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

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

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

  59.         GeneralHelper generalHelper = new GeneralHelper(session);

  60.         // Inizializzo GeneralData
  61.         GeneralData gd = generalHelper.initGeneralData(request);
  62.  
  63.         try {
  64.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  65.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  66.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  67.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  68.            
  69.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  70.             int idInt = Integer.parseInt(idPorta);
  71.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  72.             String nome = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME);
  73.             String valore = porteApplicativeHelper.getLockedParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_VALORE, false);
  74.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  75.             if(idAsps == null)
  76.                 idAsps = "";
  77.            
  78.             // Wrap value
  79.             valore = porteApplicativeHelper.wrapValoreProprieta(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_VALORE, valore);
  80.            
  81.             // Preparo il menu
  82.             porteApplicativeHelper.makeMenu();

  83.             // Prendo nome, tipo e pdd del soggetto
  84.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();

  85.             // Prendo nome della porta applicativa
  86.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  87.             String idporta = pa.getNome();
  88.            
  89.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);
  90.            
  91.             String labelPerPorta = null;
  92.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  93.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  94.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_PROTOCOL_PROPERTIES_CONFIG_DI,
  95.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_PROTOCOL_PROPERTIES,
  96.                         pa);
  97.             }
  98.             else {
  99.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_PROTOCOL_PROPERTIES_CONFIG_DI+idporta;
  100.             }
  101.             lstParam.add(new Parameter(labelPerPorta,
  102.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_PROPRIETA_PROTOCOLLO_LIST,
  103.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  104.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  105.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)
  106.                      ));
  107.             lstParam.add(ServletUtils.getParameterAggiungi());

  108.             // Se nome = null, devo visualizzare la pagina per l'inserimento
  109.             // dati
  110.             if (porteApplicativeHelper.isEditModeInProgress()) {
  111.                 // setto la barra del titolo
  112.                 ServletUtils.setPageDataTitle(pd, lstParam);

  113.                 // preparo i campi
  114.                 List<DataElement> dati = new ArrayList<>();
  115.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  116.                 dati = porteApplicativeHelper.addProprietaProtocolloToDati(TipoOperazione.ADD, porteApplicativeHelper.getSize(),
  117.                         nome, valore, dati);

  118.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta,idAsps, dati);

  119.                 pd.setDati(dati);

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

  121.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_PROPRIETA_PROTOCOLLO,
  122.                         ForwardParams.ADD());
  123.             }

  124.             // Controlli sui campi immessi
  125.             boolean isOk = porteApplicativeHelper.porteAppPropCheckData(TipoOperazione.ADD);
  126.             if (!isOk) {
  127.                 // setto la barra del titolo
  128.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  131.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  132.                
  133.                 dati = porteApplicativeHelper.addProprietaProtocolloToDati(TipoOperazione.ADD, porteApplicativeHelper.getSize(),
  134.                         nome, valore, dati);

  135.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta, idAsps, dati);

  136.                 pd.setDati(dati);

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

  138.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_PROPRIETA_PROTOCOLLO,
  139.                         ForwardParams.ADD());
  140.             }

  141.             // Inserisco la property della porta applicativa nel db
  142.             Proprieta ssp = new Proprieta();
  143.             ssp.setNome(nome);
  144.             ssp.setValore(valore);
  145.             pa.addProprieta(ssp);

  146.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  147.            
  148.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);

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

  151.             int idLista = Liste.PORTE_APPLICATIVE_PROP;

  152.             ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);

  153.             List<Proprieta> lista = porteApplicativeCore.porteAppPropList(Integer.parseInt(idPorta), ricerca);

  154.             porteApplicativeHelper.preparePorteAppPropList(idporta, ricerca, lista);

  155.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  156.             // Forward control to the specified success URI
  157.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_PROPRIETA_PROTOCOLLO,
  158.                     ForwardParams.ADD());
  159.         } catch (Exception e) {
  160.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  161.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_PROPRIETA_PROTOCOLLO,
  162.                     ForwardParams.ADD());
  163.         }  
  164.     }

  165.    
  166. }