PorteApplicativeMTOMResponseChange.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.MtomProcessor;
  32. import org.openspcoop2.core.config.MtomProcessorFlow;
  33. import org.openspcoop2.core.config.MtomProcessorFlowParameter;
  34. import org.openspcoop2.core.config.PortaApplicativa;
  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.  * PorteApplicativeMTOMResponseChange
  49.  *
  50.  * @author Giuliano Pintori (pintori@link.it)
  51.  * @author $Author$
  52.  * @version $Rev$, $Date$
  53.  */
  54. public class PorteApplicativeMTOMResponseChange 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.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  65.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  66.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  67.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  68.             String id = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  69.             int idInt = Integer.parseInt(id);
  70.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  71.             String nome = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME);
  72.             String contentType = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONTENT_TYPE);
  73.             String obbligatorio = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_OBBLIGATORIO);
  74.             String pattern = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_PATTERN);
  75.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  76.             if(idAsps == null)
  77.                 idAsps = "";
  78.            
  79.             // Preparo il menu
  80.             porteApplicativeHelper.makeMenu();

  81.             // Prendo il nome della porta applicativa
  82.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  83.            
  84.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  85.             String idporta = pa.getNome();

  86.             Parameter[] urlParms = {
  87.                     new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID,id)   ,
  88.                     new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO,idsogg) ,
  89.                     new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS,idAsps) };

  90.             MtomProcessorFlowParameter flowParameterOld = null;
  91.             MtomProcessor mtomProcessor = pa.getMtomProcessor();
  92.             if(mtomProcessor.getResponseFlow()!=null){
  93.                 List<MtomProcessorFlowParameter> wsrfpArray = mtomProcessor.getResponseFlow().getParameterList();
  94.                 for (int i = 0; i < wsrfpArray.size(); i++) {
  95.                     MtomProcessorFlowParameter wsrfp = wsrfpArray.get(i);
  96.                     if (nome.equals(wsrfp.getNome())) {
  97.                         flowParameterOld = mtomProcessor.getResponseFlow().getParameter(i);
  98.                         break;
  99.                     }
  100.                 }
  101.             }
  102.            
  103.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);
  104.            
  105.             String labelPerPorta = null;
  106.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  107.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  108.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MTOM_CONFIG_DI,
  109.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MTOM_CONFIG,
  110.                         pa);
  111.             }
  112.             else {
  113.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MTOM_CONFIG_DI+idporta;
  114.             }
  115.            
  116.             lstParam.add(new Parameter(labelPerPorta,
  117.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_MTOM, urlParms));
  118.             lstParam.add(new Parameter(PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MTOM_RESPONSE_FLOW_DI, // + idporta,
  119.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_MTOM_RESPONSE_LIST, urlParms  
  120.             ));
  121.             lstParam.add(new Parameter(nome, null));
  122.                        
  123.             if( porteApplicativeHelper.isEditModeInProgress()){
  124.                
  125.                 // setto la barra del titolo
  126.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  164.                 dati = porteApplicativeHelper.addMTOMParameterToDati(TipoOperazione.CHANGE, dati, false, nome, pattern, contentType, obbligatorio,
  165.                         pa.getMtomProcessor().getResponseFlow().getMode());

  166.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE,id, idsogg, null, idAsps, dati);

  167.                 pd.setDati(dati);

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

  169.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  170.                         PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MTOM_RESPONSE, ForwardParams.CHANGE());
  171.             }

  172.             // Controlli sui campi immessi
  173.             boolean isOk = porteApplicativeHelper.MTOMParameterCheckData(TipoOperazione.CHANGE, true, false);
  174.             if (!isOk) {
  175.                 // setto la barra del titolo
  176.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

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

  180.                 dati = porteApplicativeHelper.addMTOMParameterToDati(TipoOperazione.CHANGE, dati, false, nome, pattern, contentType, obbligatorio,
  181.                         pa.getMtomProcessor().getResponseFlow().getMode());

  182.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE,id, idsogg, null,idAsps, dati);

  183.                 pd.setDati(dati);

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

  185.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  186.                         PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MTOM_RESPONSE,
  187.                         ForwardParams.CHANGE());
  188.             }

  189.             // Modifico i dati del message-security della porta delegata nel db
  190.             // Rimozione vecchio parametro
  191.             mtomProcessor = pa.getMtomProcessor();
  192.             if(mtomProcessor.getResponseFlow()!=null){
  193.                 List<MtomProcessorFlowParameter> wsrfpArray = mtomProcessor.getResponseFlow().getParameterList();
  194.                 for (int i = 0; i < wsrfpArray.size(); i++) {
  195.                     MtomProcessorFlowParameter wsrfp = wsrfpArray.get(i);
  196.                     if (nome.equals(wsrfp.getNome())) {
  197.                         mtomProcessor.getResponseFlow().removeParameter(i);
  198.                         break;
  199.                     }
  200.                 }
  201.             }

  202.             // Inserisco il parametro della porta delegata nel db
  203.             MtomProcessorFlowParameter nuovoParametro = new MtomProcessorFlowParameter();
  204.             nuovoParametro.setNome(nome);
  205.             nuovoParametro.setPattern(pattern);
  206.             nuovoParametro.setContentType(contentType);
  207.             if( ServletUtils.isCheckBoxEnabled(obbligatorio) || CostantiRegistroServizi.ABILITATO.equals(obbligatorio) ){
  208.                 nuovoParametro.setRequired(true);
  209.             } else
  210.                 nuovoParametro.setRequired(false);

  211.             mtomProcessor = pa.getMtomProcessor();
  212.             if (mtomProcessor == null) {
  213.                 mtomProcessor = new MtomProcessor();
  214.             }
  215.             if(mtomProcessor.getResponseFlow()==null){
  216.                 mtomProcessor.setResponseFlow(new MtomProcessorFlow());
  217.             }
  218.             mtomProcessor.getResponseFlow().addParameter(nuovoParametro);
  219.             pa.setMtomProcessor(mtomProcessor);



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

  221.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);

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

  224.             int idLista = Liste.PORTE_APPLICATIVE_MTOM_RESPONSE;

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

  226.             List<MtomProcessorFlowParameter> lista = porteApplicativeCore.porteApplicativeMTOMResponseList(Integer.parseInt(id), ricerca);

  227.             porteApplicativeHelper.preparePorteApplicativeMTOMResponseList(idporta, ricerca, lista);

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

  229.             // Forward control to the specified success URI
  230.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MTOM_RESPONSE,
  231.                     ForwardParams.CHANGE());
  232.         } catch (Exception e) {
  233.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  234.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MTOM_RESPONSE,
  235.                     ForwardParams.CHANGE());
  236.         }
  237.     }

  238. }