PorteDelegateMTOMResponseAdd.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.  * PorteDelegateMTOMResponseAdd
  49.  *
  50.  * @author Giuliano Pintori (pintori@link.it)
  51.  * @author $Author$
  52.  * @version $Rev$, $Date$
  53.  */
  54. public class PorteDelegateMTOMResponseAdd 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.             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 contentType = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_CONTENT_TYPE);
  74.             String obbligatorio = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_OBBLIGATORIO);
  75.             String pattern = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_PATTERN);
  76.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  77.             if(idAsps == null)
  78.                 idAsps = "";
  79.            
  80.             String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  81.             if(idFruizione == null)
  82.                 idFruizione = "";
  83.             // Preparo il menu
  84.             porteDelegateHelper.makeMenu();

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

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

  89.             Parameter pId = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, id);
  90.             Parameter pIdSoggetto = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idsogg);
  91.             Parameter pIdAsps = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps);
  92.             Parameter pIdFrizione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione);
  93.             Parameter[] urlParms = { pId,pIdSoggetto,pIdAsps,pIdFrizione };
  94.            
  95.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idsogg, idAsps, idFruizione);
  96.            
  97.             String labelPerPorta = null;
  98.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  99.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  100.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MTOM_CONFIG_DI,
  101.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MTOM_CONFIG,
  102.                         pde);
  103.             }
  104.             else {
  105.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MTOM_CONFIG_DI+idporta;
  106.             }
  107.             lstParam.add(new Parameter(labelPerPorta,
  108.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_MTOM, urlParms));
  109.            
  110.             lstParam.add(new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MTOM_RESPONSE_FLOW_DI, // + idporta,
  111.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_MTOM_RESPONSE_LIST, urlParms  
  112.             ));
  113.            
  114.             lstParam.add(ServletUtils.getParameterAggiungi());
  115.            

  116.             if( porteDelegateHelper.isEditModeInProgress()){
  117.                     // setto la barra del titolo
  118.                     ServletUtils.setPageDataTitle(pd, lstParam);

  119.                 // preparo i campi
  120.                 List<DataElement> dati = new ArrayList<>();
  121.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  122.                 dati = porteDelegateHelper.addMTOMParameterToDati(TipoOperazione.ADD, dati, true, nome, pattern, contentType, obbligatorio,
  123.                         pde.getMtomProcessor().getResponseFlow().getMode());
  124.                
  125.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.ADD, id, idsogg, null, idAsps,
  126.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  127.                 pd.setDati(dati);

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

  129.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  130.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MTOM_RESPONSE, ForwardParams.ADD());
  131.             }

  132.             // Controlli sui campi immessi
  133.             boolean isOk = porteDelegateHelper.MTOMParameterCheckData(TipoOperazione.ADD,true,true);
  134.             if (!isOk) {
  135.                 // setto la barra del titolo
  136.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  139.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  140.                
  141.                 dati = porteDelegateHelper.addMTOMParameterToDati(TipoOperazione.ADD, dati, true, nome, pattern, contentType, obbligatorio,
  142.                         pde.getMtomProcessor().getResponseFlow().getMode());

  143.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.ADD, id, idsogg, null, idAsps,
  144.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  145.                 pd.setDati(dati);

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

  147.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  148.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MTOM_RESPONSE,
  149.                         ForwardParams.ADD());
  150.             }

  151.             // Inserisco il parametro della porta delegata nel db
  152.             MtomProcessorFlowParameter nuovoParametro = new MtomProcessorFlowParameter();
  153.             nuovoParametro.setNome(nome);
  154.             nuovoParametro.setPattern(pattern);
  155.             nuovoParametro.setContentType(contentType);
  156.             if( ServletUtils.isCheckBoxEnabled(obbligatorio) || CostantiRegistroServizi.ABILITATO.equals(obbligatorio) ){
  157.                 nuovoParametro.setRequired(true);
  158.             } else
  159.                 nuovoParametro.setRequired(false);
  160.            
  161.             MtomProcessor mtomProcessor = pde.getMtomProcessor();
  162.             if (mtomProcessor == null) {
  163.                 mtomProcessor = new MtomProcessor();
  164.             }
  165.             if(mtomProcessor.getResponseFlow()==null){
  166.                 mtomProcessor.setResponseFlow(new MtomProcessorFlow());
  167.             }
  168.             mtomProcessor.getResponseFlow().addParameter(nuovoParametro);
  169.             pde.setMtomProcessor(mtomProcessor);

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

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

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

  174.             int idLista = Liste.PORTE_DELEGATE_MTOM_RESPONSE;

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

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

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

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

  179.             // Forward control to the specified success URI
  180.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MTOM_RESPONSE,
  181.                     ForwardParams.ADD());
  182.         } catch (Exception e) {
  183.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  184.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MTOM_RESPONSE,
  185.                     ForwardParams.ADD());
  186.         }  
  187.     }

  188. }