PorteApplicativeMTOMRequestChange.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.  * PorteApplicativeMTOMRequestChange
  49.  *
  50.  * @author Giuliano Pintori (pintori@link.it)
  51.  * @author $Author$
  52.  * @version $Rev$, $Date$
  53.  */
  54. public class PorteApplicativeMTOMRequestChange 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.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  84.             String idporta = pa.getNome();

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

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

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

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

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

  166.                 pd.setDati(dati);

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

  168.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  169.                         PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MTOM_REQUEST, ForwardParams.CHANGE());
  170.             }

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

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

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

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

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

  182.                 pd.setDati(dati);

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

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

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

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

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



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

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

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

  223.             int idLista = Liste.PORTE_APPLICATIVE_MTOM_REQUEST;

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

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

  226.             porteApplicativeHelper.preparePorteApplicativeMTOMRequestList(idporta, ricerca, lista);

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

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

  235. }