PorteDelegateWSResponseAdd.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.pd;

  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.PortaDelegata;
  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.  * porteDelegateWSResponseAdd
  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 PorteDelegateWSResponseAdd 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.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  66.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  67.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  68.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  69.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  70.             int idInt = Integer.parseInt(id);
  71.             String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  72.             String nome = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME);
  73.             String valore = porteDelegateHelper.getLockedParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_VALORE,false);
  74.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  75.             if(idAsps == null)
  76.                 idAsps = "";
  77.            
  78.             // Wrap value
  79.             valore = porteDelegateHelper.wrapValoreProprieta(valore);
  80.            
  81.             String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  82.             if(idFruizione == null)
  83.                 idFruizione = "";
  84.            
  85.             // Preparo il menu
  86.             porteDelegateHelper.makeMenu();

  87.             // Prendo il nome della porta
  88.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();

  89.             PortaDelegata pde = porteDelegateCore.getPortaDelegata(idInt);
  90.             String idporta = pde.getNome();

  91.             Parameter pId = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, id);
  92.             Parameter pIdSoggetto = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idsogg);
  93.             Parameter pIdAsps = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps);
  94.             Parameter pIdFrizione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione);
  95.             Parameter[] urlParms = { pId,pIdSoggetto,pIdAsps,pIdFrizione };
  96.            
  97.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idsogg, idAsps, idFruizione);
  98.            
  99.             String labelPerPorta = null;
  100.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  101.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  102.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_CONFIG_DI,
  103.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY,
  104.                         pde);
  105.             }
  106.             else {
  107.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_CONFIG_DI+idporta;
  108.             }
  109.             lstParam.add(new Parameter(labelPerPorta,
  110.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_MESSAGE_SECURITY, urlParms));
  111.            
  112.             lstParam.add(new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_FLOW_DI, // + idporta,
  113.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE_LIST, urlParms  
  114.             ));
  115.            
  116.             lstParam.add(ServletUtils.getParameterAggiungi());
  117.            
  118.            
  119.             if( porteDelegateHelper.isEditModeInProgress()){
  120.                 // setto la barra del titolo
  121.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  124.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  125.                 dati = porteDelegateHelper.addNomeValoreProprietaCifrataToDati(TipoOperazione.ADD,dati, nome, valore,false);

  126.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.ADD, id, idsogg, null, idAsps,
  127.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  128.                 pd.setDati(dati);

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

  130.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  131.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE, ForwardParams.ADD());
  132.             }

  133.             // Controlli sui campi immessi
  134.             boolean isOk = porteDelegateHelper.porteDelegateMessageSecurityResponseCheckData(TipoOperazione.ADD);
  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.                 dati = porteDelegateHelper.addNomeValoreProprietaCifrataToDati(TipoOperazione.ADD,dati, nome, valore,false);

  142.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.ADD, id, idsogg, null, idAsps,
  143.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  144.                 pd.setDati(dati);

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

  146.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  147.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE,
  148.                         ForwardParams.ADD());
  149.             }

  150.             // Inserisco il message-security della porta delegata nel db
  151.             MessageSecurityFlowParameter wsrfp = new MessageSecurityFlowParameter();
  152.             wsrfp.setNome(nome);
  153.             wsrfp.setValore(valore);
  154.             MessageSecurity ws = pde.getMessageSecurity();
  155.             if (ws == null) {
  156.                 ws = new MessageSecurity();
  157.             }
  158.             if(ws.getResponseFlow()==null){
  159.                 ws.setResponseFlow(new MessageSecurityFlow());
  160.             }
  161.             ws.getResponseFlow().addParameter(wsrfp);
  162.             pde.setMessageSecurity(ws);

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

  164.             porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), pde);

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

  167.             int idLista = Liste.PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE;

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

  169.             List<MessageSecurityFlowParameter> lista = porteDelegateCore.porteDelegateMessageSecurityResponseList(Integer.parseInt(id), ricerca);

  170.             porteDelegateHelper.preparePorteDelegateMessageSecurityResponseList(idporta, ricerca, lista);

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

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