PorteApplicativeWSResponseAdd.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.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.ControlStationCore;
  36. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  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.  * porteAppWSResponseAdd
  47.  *
  48.  * @author Andrea Poli (apoli@link.it)
  49.  * @author Stefano Corallo (corallo@link.it)
  50.  * @author Sandra Giangrandi (sandra@link.it)
  51.  * @author $Author$
  52.  * @version $Rev$, $Date$
  53.  *
  54.  */
  55. public final class PorteApplicativeWSResponseAdd extends Action {

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

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

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

  61.         GeneralHelper generalHelper = new GeneralHelper(session);

  62.         // Inizializzo GeneralData
  63.         GeneralData gd = generalHelper.initGeneralData(request);

  64.         try {
  65.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  66.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  67.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  68.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  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(valore);
  80.            
  81.             // Preparo il menu
  82.             porteApplicativeHelper.makeMenu();

  83.             // Prendo il nome della porta
  84.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  85.            
  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_MESSAGE_SECURITY_CONFIG_DI,
  95.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MESSAGE_SECURITY,
  96.                         pa);
  97.             }
  98.             else {
  99.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MESSAGE_SECURITY_CONFIG_DI+idporta;
  100.             }
  101.             lstParam.add(new Parameter(labelPerPorta,
  102.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY,
  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.             lstParam.add(new Parameter(PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE_FLOW_DI, // + idporta,
  107.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE_LIST,
  108.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  109.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  110.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)));
  111.             lstParam.add(ServletUtils.getParameterAggiungi());

  112.             // Se nome = null, devo visualizzare la pagina per l'inserimento
  113.             // dati
  114.             if (porteApplicativeHelper.isEditModeInProgress()) {
  115.                
  116.                 // setto la barra del titolo
  117.                 ServletUtils.setPageDataTitle(pd, lstParam);

  118.                 // preparo i campi
  119.                 List<DataElement> dati = new ArrayList<>();
  120.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  121.                 dati = porteApplicativeHelper.addNomeValoreProprietaCifrataToDati(TipoOperazione.ADD, dati, nome, valore,false);

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

  123.                 pd.setDati(dati);

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

  125.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE,
  126.                         ForwardParams.ADD());
  127.             }

  128.             // Controlli sui campi immessi
  129.             boolean isOk = porteApplicativeHelper.porteAppMessageSecurityResponseCheckData(TipoOperazione.ADD);
  130.             if (!isOk) {
  131.                 // setto la barra del titolo
  132.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  135.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  136.                
  137.                 dati = porteApplicativeHelper.addNomeValoreProprietaCifrataToDati(TipoOperazione.ADD,dati, nome, valore,false);

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

  139.                 pd.setDati(dati);

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

  141.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE,
  142.                         ForwardParams.ADD());
  143.             }

  144.             // Inserisco il message-security della porta applicativa nel db
  145.             MessageSecurityFlowParameter wsrfp = new MessageSecurityFlowParameter();
  146.             wsrfp.setNome(nome);
  147.             wsrfp.setValore(valore);
  148.             MessageSecurity ws = pa.getMessageSecurity();
  149.             if (ws == null) {
  150.                 ws = new MessageSecurity();
  151.             }
  152.             if(ws.getResponseFlow()==null){
  153.                 ws.setResponseFlow(new MessageSecurityFlow());
  154.             }
  155.             ws.getResponseFlow().addParameter(wsrfp);
  156.             pa.setMessageSecurity(ws);

  157.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  158.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);

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

  161.             int idLista = Liste.PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE;

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

  163.             List<MessageSecurityFlowParameter> lista = porteApplicativeCore.porteAppMessageSecurityResponseList(idInt, ricerca);

  164.             porteApplicativeHelper.preparePorteAppMessageSecurityResponseList(idporta, ricerca, lista);

  165.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  166.             // Forward control to the specified success URI
  167.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE,
  168.                     ForwardParams.ADD());

  169.         } catch (Exception e) {
  170.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  171.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MESSAGE_SECURITY_RESPONSE,
  172.                     ForwardParams.ADD());
  173.         }  
  174.     }
  175. }