PorteApplicativeGestioneCanale.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.ArrayList;
  22. import java.util.List;

  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.CanaleConfigurazione;
  32. import org.openspcoop2.core.config.CanaliConfigurazione;
  33. import org.openspcoop2.core.config.PortaApplicativa;
  34. import org.openspcoop2.core.id.IDAccordo;
  35. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  36. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  37. import org.openspcoop2.core.registry.driver.IDAccordoFactory;
  38. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  39. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  40. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  41. import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneCore;
  42. import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneCostanti;
  43. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
  44. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCore;
  45. import org.openspcoop2.web.lib.mvc.Costanti;
  46. import org.openspcoop2.web.lib.mvc.DataElement;
  47. import org.openspcoop2.web.lib.mvc.ForwardParams;
  48. import org.openspcoop2.web.lib.mvc.GeneralData;
  49. import org.openspcoop2.web.lib.mvc.PageData;
  50. import org.openspcoop2.web.lib.mvc.Parameter;
  51. import org.openspcoop2.web.lib.mvc.ServletUtils;
  52. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  53. /***
  54.  *
  55.  * PorteApplicativeGestioneCors
  56.  *
  57.  * @author Giuliano Pintori (pintori@link.it)
  58.  * @author $Author$
  59.  * @version $Rev$, $Date$
  60.  */
  61. public class PorteApplicativeGestioneCanale extends Action {

  62.     @Override
  63.     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

  64.         TipoOperazione tipoOperazione = TipoOperazione.OTHER;

  65.         HttpSession session = request.getSession(true);

  66.         // Inizializzo PageData
  67.         PageData pd = new PageData();

  68.         GeneralHelper generalHelper = new GeneralHelper(session);

  69.         // Inizializzo GeneralData
  70.         GeneralData gd = generalHelper.initGeneralData(request);

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

  72.         try {

  73.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  74.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  75.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  76.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  77.            
  78.             String id = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  79.             int idInt = Integer.parseInt(id);
  80.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  81.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  82.             if(idAsps == null)
  83.                 idAsps = "";

  84.             // Preparo il menu
  85.             porteApplicativeHelper.makeMenu();

  86.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  87.             ConfigurazioneCore confCore = new ConfigurazioneCore(porteApplicativeCore);
  88.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteApplicativeCore);
  89.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
  90.            
  91.             long idServizio = Integer.parseInt(idAsps);
  92.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(idServizio);
  93.             IDAccordo idAccordo = IDAccordoFactory.getInstance().getIDAccordoFromUri(asps.getAccordoServizioParteComune());
  94.             AccordoServizioParteComuneSintetico as = apcCore.getAccordoServizioSintetico(idAccordo);

  95.             String canale = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_CANALI_CANALE);
  96.             String canaleStato = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_CANALI_CANALE_STATO);
  97.            
  98.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  99.             String idporta = pa.getNome();
  100.            
  101.             // carico i canali
  102.             CanaliConfigurazione gestioneCanali = confCore.getCanaliConfigurazione(false);
  103.             List<CanaleConfigurazione> canaleList = gestioneCanali != null ? gestioneCanali.getCanaleList() : new ArrayList<>();
  104.             boolean gestioneCanaliEnabled = gestioneCanali != null && org.openspcoop2.core.config.constants.StatoFunzionalita.ABILITATO.equals(gestioneCanali.getStato());
  105.            
  106.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);

  107.             String labelPerPorta = null;
  108.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  109.                 lstParam.remove(lstParam.size()-1);
  110.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  111.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CANALE_CONFIG_DI,
  112.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CANALE,
  113.                         pa);
  114.             }
  115.             else {
  116.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CANALE_CONFIG_DI+idporta;
  117.             }

  118.             if(labelPerPorta.contains(CostantiControlStation.LABEL_DEL_GRUPPO)) {
  119.                 labelPerPorta = labelPerPorta.substring(0, labelPerPorta.indexOf(CostantiControlStation.LABEL_DEL_GRUPPO));
  120.             }
  121.            
  122.             lstParam.add(new Parameter(labelPerPorta,  null));

  123.             // edit in progress
  124.             if (porteApplicativeHelper.isEditModeInProgress()) {
  125.                 ServletUtils.setPageDataTitle(pd, lstParam);
  126.                
  127.                 if(canale == null) {
  128.                     canale = pa.getCanale();
  129.                 }
  130.                 if(canaleStato==null) {
  131.                     if(canale == null) {
  132.                         canaleStato = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CANALE_STATO_DEFAULT;
  133.                     } else {
  134.                         canaleStato = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CANALE_STATO_RIDEFINITO;
  135.                     }
  136.                 }

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

  140.                 porteApplicativeHelper.addCanaleToDati(dati, tipoOperazione, canaleStato, canale, as.getCanale(), canaleList, gestioneCanaliEnabled);

  141.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idsogg, null, idAsps, dati);

  142.                 pd.setDati(dati);

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

  144.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_GESTIONE_CANALE, ForwardParams.OTHER(""));
  145.             }

  146.             // Controlli sui campi immessi
  147.             boolean isOk = porteApplicativeHelper.canaleCheckData(canaleStato, canale, gestioneCanaliEnabled);
  148.             if (!isOk) {

  149.                 ServletUtils.setPageDataTitle(pd, lstParam);

  150.                 // preparo i campi
  151.                 List<DataElement> dati = new ArrayList<>();
  152.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  153.                 porteApplicativeHelper.addCanaleToDati(dati, TipoOperazione.OTHER, canaleStato, canale, as.getCanale(), canaleList, gestioneCanaliEnabled);
  154.                
  155.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idsogg, null, idAsps, dati);

  156.                 pd.setDati(dati);

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

  158.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_GESTIONE_CANALE, ForwardParams.OTHER(""));
  159.             }
  160.            
  161.            
  162.             // canale
  163.             if(AccordiServizioParteComuneCostanti.DEFAULT_VALUE_PARAMETRO_APC_CANALE_STATO_RIDEFINITO.equals(canaleStato)) {
  164.                 pa.setCanale(canale);
  165.             } else {
  166.                 pa.setCanale(null);
  167.             }

  168.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);
  169.            
  170.             // Faccio ricalcolare la lista dei servizi, poichè il canale può essere cambiato
  171.             ServletUtils.removeRisultatiRicercaFromSession(request, session, Liste.SERVIZI);
  172.            
  173.             // Preparo la lista
  174.             pd.setMessage(PorteApplicativeCostanti.LABEL_PORTE_APPLICATIVE_CANALE_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);

  175.             pa = porteApplicativeCore.getPortaApplicativa(idInt);
  176.             idporta = pa.getNome();

  177.             ServletUtils.setPageDataTitle(pd, lstParam);

  178.             // preparo i campi
  179.             List<DataElement> dati = new ArrayList<>();
  180.             dati.add(ServletUtils.getDataElementForEditModeFinished());

  181.             // ricarico la configurazione
  182.            
  183.             canale = pa.getCanale();
  184.             if(canale == null) {
  185.                 canaleStato = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CANALE_STATO_DEFAULT;
  186.             } else {
  187.                 canaleStato = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CANALE_STATO_RIDEFINITO;
  188.             }

  189.             porteApplicativeHelper.addCanaleToDati(dati, TipoOperazione.OTHER, canaleStato, canale, as.getCanale(), canaleList, gestioneCanaliEnabled);

  190.             dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idsogg, null, idAsps, dati);

  191.             pd.setDati(dati);

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

  193.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_GESTIONE_CANALE, ForwardParams.OTHER(""));
  194.         } catch (Exception e) {
  195.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  196.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_GESTIONE_CANALE, ForwardParams.OTHER(""));
  197.         }
  198.     }

  199. }