PorteDelegateMTOMResponseChange.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.MtomProcessor;
  32. import org.openspcoop2.core.config.MtomProcessorFlow;
  33. import org.openspcoop2.core.config.MtomProcessorFlowParameter;
  34. import org.openspcoop2.core.config.PortaDelegata;
  35. import org.openspcoop2.core.registry.constants.CostantiRegistroServizi;
  36. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  37. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  38. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  39. import org.openspcoop2.web.lib.mvc.DataElement;
  40. import org.openspcoop2.web.lib.mvc.ForwardParams;
  41. import org.openspcoop2.web.lib.mvc.GeneralData;
  42. import org.openspcoop2.web.lib.mvc.PageData;
  43. import org.openspcoop2.web.lib.mvc.Parameter;
  44. import org.openspcoop2.web.lib.mvc.ServletUtils;
  45. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  46. /***
  47.  *
  48.  * PorteDelegateMTOMResponseChange
  49.  *
  50.  * @author Giuliano Pintori (pintori@link.it)
  51.  * @author $Author$
  52.  * @version $Rev$, $Date$
  53.  */
  54. public class PorteDelegateMTOMResponseChange extends Action {

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

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

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

  60.         GeneralHelper generalHelper = new GeneralHelper(session);

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

  63.         try {
  64.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  65.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  66.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  67.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  68.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  69.             int idInt = Integer.parseInt(id);
  70.             String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  71.             String nome = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME);
  72.             String contentType = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_CONTENT_TYPE);
  73.             String obbligatorio = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_OBBLIGATORIO);
  74.             String pattern = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_PATTERN);
  75.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  76.             if(idAsps == null)
  77.                 idAsps = "";
  78.            
  79.             String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  80.             if(idFruizione == null)
  81.                 idFruizione = "";
  82.             // Preparo il menu
  83.             porteDelegateHelper.makeMenu();

  84.             // Prendo il nome della porta applicativa
  85.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();

  86.             PortaDelegata pde = porteDelegateCore.getPortaDelegata(idInt);
  87.             String idporta = pde.getNome();

  88.             MtomProcessorFlowParameter flowParameterOld = null;
  89.             MtomProcessor mtomProcessor = pde.getMtomProcessor();
  90.             if(mtomProcessor.getResponseFlow()!=null){
  91.                 List<MtomProcessorFlowParameter> wsrfpArray = mtomProcessor.getResponseFlow().getParameterList();
  92.                 for (int i = 0; i < wsrfpArray.size(); i++) {
  93.                     MtomProcessorFlowParameter wsrfp = wsrfpArray.get(i);
  94.                     if (nome.equals(wsrfp.getNome())) {
  95.                         flowParameterOld = mtomProcessor.getResponseFlow().getParameter(i);
  96.                         break;
  97.                     }
  98.                 }
  99.             }
  100.        
  101.             Parameter pId = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, id);
  102.             Parameter pIdSoggetto = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idsogg);
  103.             Parameter pIdAsps = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps);
  104.             Parameter pIdFrizione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione);
  105.            
  106.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idsogg, idAsps, idFruizione);
  107.                        
  108.             Parameter[] urlParms = { pId,pIdSoggetto,pIdAsps,pIdFrizione };
  109.            
  110.             String labelPerPorta = null;
  111.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  112.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  113.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MTOM_CONFIG_DI,
  114.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MTOM_CONFIG,
  115.                         pde);
  116.             }
  117.             else {
  118.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MTOM_CONFIG_DI+idporta;
  119.             }
  120.             lstParam.add(new Parameter(labelPerPorta,
  121.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_MTOM, urlParms));
  122.            
  123.             lstParam.add(new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MTOM_RESPONSE_FLOW_DI, // + idporta,
  124.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_MTOM_RESPONSE_LIST, urlParms  
  125.             ));
  126.            
  127.             lstParam.add(new Parameter(nome , null));
  128.            
  129.             if( porteDelegateHelper.isEditModeInProgress()){
  130.                 // setto la barra del titolo
  131.                 ServletUtils.setPageDataTitle(pd, lstParam);

  132.                 // primo accesso
  133.                 if(nome == null &&
  134.                     flowParameterOld != null) {
  135.                     nome  = flowParameterOld.getNome();
  136.                 }
  137.                
  138.                 if(pattern == null &&
  139.                     flowParameterOld != null) {
  140.                     pattern  = flowParameterOld.getPattern();
  141.                 }
  142.                
  143.                 if(contentType == null &&
  144.                     flowParameterOld != null) {
  145.                     contentType  = flowParameterOld.getContentType();
  146.                 }
  147.                
  148.                 if(obbligatorio == null &&
  149.                     flowParameterOld != null){
  150.                     boolean b = flowParameterOld.getRequired();
  151.                     obbligatorio = b ? "yes" : "";
  152.                 }
  153.                
  154.                 if(nome == null)
  155.                     nome = "";
  156.                
  157.                 if(pattern == null)
  158.                     pattern = "";
  159.                
  160.                 if(contentType == null)
  161.                     contentType = "";
  162.                
  163.                 if(obbligatorio == null)
  164.                     obbligatorio = "";
  165.                    
  166.                 // preparo i campi
  167.                 List<DataElement> dati = new ArrayList<>();
  168.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  169.                 dati = porteDelegateHelper.addMTOMParameterToDati(TipoOperazione.CHANGE, dati, false, nome, pattern, contentType, obbligatorio,
  170.                         pde.getMtomProcessor().getResponseFlow().getMode());

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

  173.                 pd.setDati(dati);

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

  175.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  176.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MTOM_RESPONSE, ForwardParams.CHANGE());
  177.             }

  178.             // Controlli sui campi immessi
  179.             boolean isOk = porteDelegateHelper.MTOMParameterCheckData(TipoOperazione.CHANGE, true, true);
  180.             if (!isOk) {
  181.                 // setto la barra del titolo
  182.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

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

  186.                 dati = porteDelegateHelper.addMTOMParameterToDati(TipoOperazione.CHANGE, dati, false, nome, pattern, contentType, obbligatorio,
  187.                         pde.getMtomProcessor().getResponseFlow().getMode());

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

  190.                 pd.setDati(dati);

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

  192.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  193.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MTOM_RESPONSE,
  194.                         ForwardParams.CHANGE());
  195.             }

  196.             // Modifico i dati del message-security della porta delegata nel db
  197.             // Rimozione vecchio parametro
  198.             mtomProcessor = pde.getMtomProcessor();
  199.             if(mtomProcessor.getResponseFlow()!=null){
  200.                 List<MtomProcessorFlowParameter> wsrfpArray = mtomProcessor.getResponseFlow().getParameterList();
  201.                 for (int i = 0; i < wsrfpArray.size(); i++) {
  202.                     MtomProcessorFlowParameter wsrfp = wsrfpArray.get(i);
  203.                     if (nome.equals(wsrfp.getNome())) {
  204.                         mtomProcessor.getResponseFlow().removeParameter(i);
  205.                         break;
  206.                     }
  207.                 }
  208.             }

  209.             // Inserisco il parametro della porta delegata nel db
  210.             MtomProcessorFlowParameter nuovoParametro = new MtomProcessorFlowParameter();
  211.             nuovoParametro.setNome(nome);
  212.             nuovoParametro.setPattern(pattern);
  213.             nuovoParametro.setContentType(contentType);
  214.             if( ServletUtils.isCheckBoxEnabled(obbligatorio) || CostantiRegistroServizi.ABILITATO.equals(obbligatorio) ){
  215.                 nuovoParametro.setRequired(true);
  216.             } else
  217.                 nuovoParametro.setRequired(false);

  218.             mtomProcessor = pde.getMtomProcessor();
  219.             if (mtomProcessor == null) {
  220.                 mtomProcessor = new MtomProcessor();
  221.             }
  222.             if(mtomProcessor.getResponseFlow()==null){
  223.                 mtomProcessor.setResponseFlow(new MtomProcessorFlow());
  224.             }
  225.             mtomProcessor.getResponseFlow().addParameter(nuovoParametro);
  226.             pde.setMtomProcessor(mtomProcessor);

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

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

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

  231.             int idLista = Liste.PORTE_DELEGATE_MTOM_RESPONSE;

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

  233.             List<MtomProcessorFlowParameter> lista = porteDelegateCore.porteDelegateMTOMResponseList(Integer.parseInt(id), ricerca);

  234.             porteDelegateHelper.preparePorteDelegateMTOMResponseList(idporta, ricerca, lista);

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

  236.             // Forward control to the specified success URI
  237.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MTOM_RESPONSE,
  238.                     ForwardParams.CHANGE());
  239.         } catch (Exception e) {
  240.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  241.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MTOM_RESPONSE,
  242.                     ForwardParams.CHANGE());
  243.         }
  244.     }

  245. }