PorteApplicativeWSRequestAdd.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.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.config.MessageSecurity;
  32. import org.openspcoop2.core.config.MessageSecurityFlow;
  33. import org.openspcoop2.core.config.MessageSecurityFlowParameter;
  34. import org.openspcoop2.core.config.PortaApplicativa;
  35. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  36. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  37. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  38. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCostanti;
  39. import org.openspcoop2.web.lib.mvc.DataElement;
  40. import org.openspcoop2.web.lib.mvc.DataElementType;
  41. import org.openspcoop2.web.lib.mvc.ForwardParams;
  42. import org.openspcoop2.web.lib.mvc.GeneralData;
  43. import org.openspcoop2.web.lib.mvc.PageData;
  44. import org.openspcoop2.web.lib.mvc.Parameter;
  45. import org.openspcoop2.web.lib.mvc.ServletUtils;
  46. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  47. /**
  48.  * porteAppWSRequestAdd
  49.  *
  50.  * @author Andrea Poli (apoli@link.it)
  51.  * @author Stefano Corallo (corallo@link.it)
  52.  * @author Sandra Giangrandi (sandra@link.it)
  53.  * @author $Author$
  54.  * @version $Rev$, $Date$
  55.  *
  56.  */
  57. public final class PorteApplicativeWSRequestAdd 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.         try {
  67.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  68.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  69.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  70.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  71.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  72.             int idInt = Integer.parseInt(idPorta);
  73.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  74.             String nome = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME);
  75.             String valore = porteApplicativeHelper.getLockedParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_VALORE, false);
  76.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  77.             if(idAsps == null)
  78.                 idAsps = "";
  79.            
  80.             // Wrap value
  81.             valore = porteApplicativeHelper.wrapValoreProprieta(valore);
  82.            
  83.             // Preparo il menu
  84.             porteApplicativeHelper.makeMenu();

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

  114.             // Se nome = null, devo visualizzare la pagina per l'inserimento
  115.             // dati
  116.             if (porteApplicativeHelper.isEditModeInProgress()) {
  117.                
  118.                 // setto la barra del titolo
  119.                 ServletUtils.setPageDataTitle(pd, lstParam);
  120.                
  121.                 // preparo i campi
  122.                 List<DataElement> dati = new ArrayList<>();
  123.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  124.                
  125.                 DataElement dataElement = new DataElement();
  126.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  127.                 dataElement.setType(DataElementType.TITLE);
  128.                 dati.add(dataElement);
  129.                
  130.                 dati = porteApplicativeHelper.addNomeValoreProprietaCifrataToDati(TipoOperazione.ADD, dati, nome, valore, false);

  131.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg,idPorta, idAsps, dati);
  132.                
  133.                 pd.setDati(dati);

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

  135.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST,
  136.                         ForwardParams.ADD());
  137.             }

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

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

  145.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  146.                
  147.                 DataElement dataElement = new DataElement();
  148.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  149.                 dataElement.setType(DataElementType.TITLE);
  150.                 dati.add(dataElement);
  151.                
  152.                 dati = porteApplicativeHelper.addNomeValoreProprietaCifrataToDati(TipoOperazione.ADD, dati, nome, valore,  false);
  153.                
  154.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta, idAsps, dati);

  155.                 pd.setDati(dati);

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

  157.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST,
  158.                         ForwardParams.ADD());
  159.             }

  160.             // Inserisco il message-security della porta applicativa nel db
  161.             MessageSecurityFlowParameter wsrfp = new MessageSecurityFlowParameter();
  162.             wsrfp.setNome(nome);
  163.             wsrfp.setValore(valore);
  164.             MessageSecurity ws = pa.getMessageSecurity();
  165.             if (ws == null) {
  166.                 ws = new MessageSecurity();
  167.             }
  168.             if(ws.getRequestFlow()==null){
  169.                 ws.setRequestFlow(new MessageSecurityFlow());
  170.             }
  171.             ws.getRequestFlow().addParameter(wsrfp);
  172.             pa.setMessageSecurity(ws);

  173.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  174.            
  175.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);

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

  178.             int idLista = Liste.PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST;

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

  180.             List<MessageSecurityFlowParameter> lista = porteApplicativeCore.porteAppMessageSecurityRequestList(idInt, ricerca);

  181.             porteApplicativeHelper.preparePorteAppMessageSecurityRequestList(idporta, ricerca, lista);

  182.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  183.             // Forward control to the specified success URI
  184.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST,
  185.                     ForwardParams.ADD());
  186.         } catch (Exception e) {
  187.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  188.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY_REQUEST,
  189.                     ForwardParams.ADD());
  190.         }  
  191.     }
  192. }