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

  122.                 if(valore==null) {
  123.                     MessageSecurity ws = pde.getMessageSecurity();
  124.                     if(ws.getResponseFlow()!=null){
  125.                         List<MessageSecurityFlowParameter> wsrfpArray = ws.getResponseFlow().getParameterList();
  126.                         for (int i = 0; i < wsrfpArray.size(); i++) {
  127.                             MessageSecurityFlowParameter wsrfp = wsrfpArray.get(i);
  128.                             if (nome.equals(wsrfp.getNome())) {
  129.                                 valore = wsrfp.getValore();
  130.                                 break;
  131.                             }
  132.                         }
  133.                     }
  134.                 }

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

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

  138.                 dati = porteDelegateHelper.addNomeValoreProprietaCifrataToDati(TipoOperazione.CHANGE, dati, nome, valore, false);

  139.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, id, idsogg, null, idAsps,
  140.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  141.                 pd.setDati(dati);

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

  143.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  144.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE, ForwardParams.CHANGE());
  145.             }

  146.             // Controlli sui campi immessi
  147.             boolean isOk = porteDelegateHelper.porteDelegateMessageSecurityResponseCheckData(TipoOperazione.CHANGE);
  148.             if (!isOk) {
  149.                 // setto la barra del titolo
  150.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

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

  154.                 dati = porteDelegateHelper.addNomeValoreProprietaCifrataToDati(TipoOperazione.CHANGE,dati, nome, valore,false);

  155.                 porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, id, idsogg, null, idAsps,
  156.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

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

  158.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  159.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE,
  160.                         ForwardParams.CHANGE());
  161.             }

  162.             // Modifico i dati del message-security della porta delegata nel db
  163.             MessageSecurity ws = pde.getMessageSecurity();
  164.             if(ws.getResponseFlow()!=null){
  165.                 List<MessageSecurityFlowParameter> wsrfpArray = ws.getResponseFlow().getParameterList();
  166.                 for (int i = 0; i < wsrfpArray.size(); i++) {
  167.                     MessageSecurityFlowParameter wsrfp = wsrfpArray.get(i);
  168.                     if (nome.equals(wsrfp.getNome())) {
  169.                         ws.getResponseFlow().removeParameter(i);
  170.                         break;
  171.                     }
  172.                 }
  173.             }

  174.             MessageSecurityFlowParameter wsrfp = new MessageSecurityFlowParameter();
  175.             wsrfp.setNome(nome);
  176.             wsrfp.setValore(valore);
  177.             if(ws.getResponseFlow()==null){
  178.                 ws.setResponseFlow(new MessageSecurityFlow());
  179.             }
  180.             ws.getResponseFlow().addParameter(wsrfp);
  181.             pde.setMessageSecurity(ws);

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

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

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

  186.             int idLista = Liste.PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE;

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

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

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

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

  191.             // Forward control to the specified success URI
  192.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE,
  193.                     ForwardParams.CHANGE());
  194.         } catch (Exception e) {
  195.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  196.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MESSAGE_SECURITY_RESPONSE,
  197.                     ForwardParams.CHANGE());
  198.         }
  199.     }
  200. }