PorteApplicativeProprietaProtocolloChange.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.  * porteAppPropChange
  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 PorteApplicativeProprietaProtocolloChange 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.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  69.             int idInt = Integer.parseInt(idPorta);
  70.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  71.             String nome = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME);
  72.             String valore = porteApplicativeHelper.getLockedParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_VALORE,false);
  73.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  74.             if(idAsps == null)
  75.                 idAsps = "";
  76.            
  77.             // Wrap value
  78.             valore = porteApplicativeHelper.wrapValoreProprieta(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_VALORE, valore);
  79.            
  80.             // Preparo il menu
  81.             porteApplicativeHelper.makeMenu();

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

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

  107.             // Se valore = null, devo visualizzare la pagina per la
  108.             // modifica dati
  109.             if (porteApplicativeHelper.isEditModeInProgress()) {
  110.                 // setto la barra del titolo
  111.                 ServletUtils.setPageDataTitle(pd, lstParam);

  112.                 if(valore==null){
  113.                     for (int i = 0; i < pa.sizeProprietaList(); i++) {
  114.                         Proprieta ssp = pa.getProprieta(i);
  115.                         if (nome.equals(ssp.getNome())) {
  116.                             if(ssp.getValore()!=null){
  117.                                 valore = ssp.getValore();
  118.                             }
  119.                             break;
  120.                         }
  121.                     }
  122.                 }

  123.                 // preparo i campi
  124.                 List<DataElement> dati = new ArrayList<>();
  125.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  126.                 dati = porteApplicativeHelper.addProprietaProtocolloToDati(TipoOperazione.CHANGE, porteApplicativeHelper.getSize(), nome, valore, dati);

  127.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, idPorta, idsogg, idPorta, idAsps, dati);

  128.                 pd.setDati(dati);

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

  130.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_PROPRIETA_PROTOCOLLO,
  131.                         ForwardParams.CHANGE());
  132.             }

  133.             // Controlli sui campi immessi
  134.             boolean isOk = porteApplicativeHelper.porteAppPropCheckData(TipoOperazione.CHANGE);
  135.             if (!isOk) {
  136.                 // setto la barra del titolo
  137.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  140.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  141.                
  142.                 dati = porteApplicativeHelper.addProprietaProtocolloToDati(TipoOperazione.CHANGE, porteApplicativeHelper.getSize(), nome, valore,dati);

  143.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, idPorta, idsogg, idPorta, idAsps, dati);

  144.                 pd.setDati(dati);

  145.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  146.  
  147.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_PROPRIETA_PROTOCOLLO,
  148.                         ForwardParams.CHANGE());
  149.             }

  150.             // Modifico i dati della property della porta applicativa nel
  151.             // db
  152.             for (int i = 0; i < pa.sizeProprietaList(); i++) {
  153.                 Proprieta ssp = pa.getProprieta(i);
  154.                 if (nome.equals(ssp.getNome())) {
  155.                     pa.removeProprieta(i);
  156.                     break;
  157.                 }
  158.             }
  159.             Proprieta ssp = new Proprieta();
  160.             ssp.setNome(nome);
  161.             ssp.setValore(valore);
  162.             pa.addProprieta(ssp);

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

  164.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);

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

  167.             int idLista = Liste.PORTE_APPLICATIVE_PROP;

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

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

  170.             porteApplicativeHelper.preparePorteAppPropList(nomePorta, ricerca, lista);

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