PorteDelegateMTOMRequestAdd.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.  * PorteDelegateMTOMRequestAdd
  49.  *
  50.  * @author Giuliano Pintori (pintori@link.it)
  51.  * @author $Author$
  52.  * @version $Rev$, $Date$
  53.  */
  54. public class PorteDelegateMTOMRequestAdd 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.            
  94.             Parameter[] urlParms = { pId,pIdSoggetto,pIdAsps,pIdFrizione };
  95.            
  96.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idsogg, idAsps, idFruizione);
  97.            
  98.             String labelPerPorta = null;
  99.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  100.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  101.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MTOM_CONFIG_DI,
  102.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MTOM_CONFIG,
  103.                         pde);
  104.             }
  105.             else {
  106.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MTOM_CONFIG_DI+idporta;
  107.             }
  108.             lstParam.add(new Parameter(labelPerPorta,
  109.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_MTOM, urlParms));
  110.            
  111.             lstParam.add(new Parameter(PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_MTOM_REQUEST_FLOW_DI, // + idporta,
  112.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_MTOM_REQUEST_LIST, urlParms  
  113.             ));
  114.            
  115.             lstParam.add(ServletUtils.getParameterAggiungi());
  116.            
  117.            
  118.             if( porteDelegateHelper.isEditModeInProgress()){
  119.                     // setto la barra del titolo
  120.                     ServletUtils.setPageDataTitle(pd, lstParam);

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

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

  129.                 pd.setDati(dati);

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

  131.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  132.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MTOM_REQUEST, ForwardParams.ADD());
  133.             }

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

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

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

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

  147.                 pd.setDati(dati);

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

  149.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  150.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_MTOM_REQUEST,
  151.                         ForwardParams.ADD());
  152.             }

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

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

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

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

  176.             int idLista = Liste.PORTE_DELEGATE_MTOM_REQUEST;

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

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

  179.             porteDelegateHelper.preparePorteDelegateMTOMRequestList(idporta, ricerca, lista);

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

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

  190. }