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

  82.             // Prendo il nome della porta
  83.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();

  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.            
  91.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);
  92.            
  93.             String labelPerPorta = null;
  94.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  95.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  96.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MTOM_CONFIG_DI,
  97.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MTOM_CONFIG,
  98.                         pa);
  99.             }
  100.             else {
  101.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MTOM_CONFIG_DI+idporta;
  102.             }
  103.            
  104.             lstParam.add(new Parameter(labelPerPorta,
  105.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_MTOM, urlParms));
  106.             lstParam.add(new Parameter(PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_MTOM_REQUEST_FLOW_DI, // + idporta,
  107.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_MTOM_REQUEST_LIST, urlParms  
  108.             ));
  109.             lstParam.add(ServletUtils.getParameterAggiungi());
  110.            
  111.             if( porteApplicativeHelper.isEditModeInProgress()){
  112.                    
  113.                     // setto la barra del titolo
  114.                     ServletUtils.setPageDataTitle(pd, lstParam);

  115.                 // preparo i campi
  116.                 List<DataElement> dati = new ArrayList<>();
  117.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  118.                 dati = porteApplicativeHelper.addMTOMParameterToDati(TipoOperazione.ADD, dati, true, nome, pattern, contentType, obbligatorio,
  119.                         pa.getMtomProcessor().getRequestFlow().getMode());
  120.                
  121.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD,id, idsogg,null,idAsps, dati);

  122.                 pd.setDati(dati);

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

  124.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  125.                         PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MTOM_REQUEST, ForwardParams.ADD());
  126.             }

  127.             // Controlli sui campi immessi
  128.             boolean isOk = porteApplicativeHelper.MTOMParameterCheckData(TipoOperazione.ADD,false,false);
  129.             if (!isOk) {
  130.                 // setto la barra del titolo
  131.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  134.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  135.                
  136.                 dati = porteApplicativeHelper.addMTOMParameterToDati(TipoOperazione.ADD, dati, true, nome, pattern, contentType, obbligatorio,
  137.                         pa.getMtomProcessor().getRequestFlow().getMode());

  138.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD,id, idsogg, null,idAsps, dati);

  139.                 pd.setDati(dati);

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

  141.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  142.                         PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MTOM_REQUEST,
  143.                         ForwardParams.ADD());
  144.             }

  145.             // Inserisco il parametro della porta delegata nel db
  146.             MtomProcessorFlowParameter nuovoParametro = new MtomProcessorFlowParameter();
  147.             nuovoParametro.setNome(nome);
  148.             nuovoParametro.setPattern(pattern);
  149.             nuovoParametro.setContentType(contentType);
  150.             if( ServletUtils.isCheckBoxEnabled(obbligatorio) || CostantiRegistroServizi.ABILITATO.equals(obbligatorio) ){
  151.                 nuovoParametro.setRequired(true);
  152.             } else
  153.                 nuovoParametro.setRequired(false);
  154.            
  155.             MtomProcessor mtomProcessor = pa.getMtomProcessor();
  156.             if (mtomProcessor == null) {
  157.                 mtomProcessor = new MtomProcessor();
  158.             }
  159.             if(mtomProcessor.getRequestFlow()==null){
  160.                 mtomProcessor.setRequestFlow(new MtomProcessorFlow());
  161.             }
  162.             mtomProcessor.getRequestFlow().addParameter(nuovoParametro);
  163.             pa.setMtomProcessor(mtomProcessor);

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

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

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

  168.             int idLista = Liste.PORTE_APPLICATIVE_MTOM_REQUEST;

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

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

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

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

  173.             // Forward control to the specified success URI
  174.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MTOM_REQUEST,
  175.                     ForwardParams.ADD());
  176.         } catch (Exception e) {
  177.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  178.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_MTOM_REQUEST,
  179.                     ForwardParams.ADD());
  180.         }  
  181.     }

  182. }