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

  90.             // Prendo il nome della porta
  91.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();

  92.             PortaDelegata pde = porteDelegateCore.getPortaDelegata(idInt);
  93.             String idporta = pde.getNome();

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

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

  128.                 DataElement dataElement = new DataElement();
  129.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  130.                 dataElement.setType(DataElementType.TITLE);
  131.                 dati.add(dataElement);
  132.                
  133.                 dati = porteDelegateHelper.addNomeValoreProprietaCifrataToDati(TipoOperazione.ADD,dati, nome, valore,false);
  134.                
  135.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.ADD, id, idsogg, null, idAsps,
  136.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  137.                 pd.setDati(dati);

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

  139.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  140.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST, ForwardParams.ADD());
  141.             }

  142.             // Controlli sui campi immessi
  143.             boolean isOk = porteDelegateHelper.porteDelegateMessageSecurityRequestCheckData(TipoOperazione.ADD);
  144.             if (!isOk) {
  145.                 // setto la barra del titolo
  146.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  149.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  150.                
  151.                 DataElement dataElement = new DataElement();
  152.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  153.                 dataElement.setType(DataElementType.TITLE);
  154.                 dati.add(dataElement);
  155.                
  156.                 dati = porteDelegateHelper.addNomeValoreProprietaCifrataToDati(TipoOperazione.ADD,dati, nome, valore,false);

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

  159.                 pd.setDati(dati);

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

  161.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  162.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST,
  163.                         ForwardParams.ADD());
  164.             }

  165.             // Inserisco il message-security della porta delegata nel db
  166.             MessageSecurityFlowParameter wsrfp = new MessageSecurityFlowParameter();
  167.             wsrfp.setNome(nome);
  168.             wsrfp.setValore(valore);
  169.             MessageSecurity ws = pde.getMessageSecurity();
  170.             if (ws == null) {
  171.                 ws = new MessageSecurity();
  172.             }
  173.             if(ws.getRequestFlow()==null){
  174.                 ws.setRequestFlow(new MessageSecurityFlow());
  175.             }
  176.             ws.getRequestFlow().addParameter(wsrfp);
  177.             pde.setMessageSecurity(ws);

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

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

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

  182.             int idLista = Liste.PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST;

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

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

  185.             porteDelegateHelper.preparePorteDelegateMessageSecurityRequestList(idporta, ricerca, lista);

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

  187.             // Forward control to the specified success URI
  188.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST,
  189.                     ForwardParams.ADD());
  190.         } catch (Exception e) {
  191.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  192.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_REQUEST,
  193.                     ForwardParams.ADD());
  194.         }  
  195.     }
  196. }