PorteDelegateGestioneCanale.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.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.PortaDelegata;
  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.  * PorteDelegateGestioneCors
  55.  *
  56.  * @author Andrea Poli (apoli@link.it)
  57.  * @author Giuliano Pintori (pintori@link.it)
  58.  * @author $Author$
  59.  * @version $Rev$, $Date$
  60.  *
  61.  */
  62. public class PorteDelegateGestioneCanale extends Action {

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

  65.         TipoOperazione tipoOperazione = TipoOperazione.OTHER;

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

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

  69.         GeneralHelper generalHelper = new GeneralHelper(session);

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

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

  73.         try {
  74.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  75.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  76.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  77.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  78.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  79.             int idInt = Integer.parseInt(id);
  80.             String idSoggFruitore = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  81.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  82.             if(idAsps == null)
  83.                 idAsps = "";
  84.             String idFruizione= porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  85.             if(idFruizione == null)
  86.                 idFruizione = "";

  87.             // Preparo il menu
  88.             porteDelegateHelper.makeMenu();
  89.            
  90.             // Prendo il nome della porta
  91.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  92.             ConfigurazioneCore confCore = new ConfigurazioneCore(porteDelegateCore);
  93.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteDelegateCore);
  94.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteDelegateCore);
  95.            
  96.             long idServizio = Integer.parseInt(idAsps);
  97.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(idServizio);
  98.             IDAccordo idAccordo = IDAccordoFactory.getInstance().getIDAccordoFromUri(asps.getAccordoServizioParteComune());
  99.             AccordoServizioParteComuneSintetico as = apcCore.getAccordoServizioSintetico(idAccordo);

  100.             String canale = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_CANALI_CANALE);
  101.             String canaleStato = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_CONFIGURAZIONE_CANALI_CANALE_STATO);

  102.             PortaDelegata portaDelegata = porteDelegateCore.getPortaDelegata(idInt);
  103.             String idporta = portaDelegata.getNome();
  104.            
  105.             // carico i canali
  106.             CanaliConfigurazione gestioneCanali = confCore.getCanaliConfigurazione(false);
  107.             List<CanaleConfigurazione> canaleList = gestioneCanali != null ? gestioneCanali.getCanaleList() : new ArrayList<>();
  108.             boolean gestioneCanaliEnabled = gestioneCanali != null && org.openspcoop2.core.config.constants.StatoFunzionalita.ABILITATO.equals(gestioneCanali.getStato());
  109.            
  110.             // setto la barra del titolo
  111.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idSoggFruitore, idAsps, idFruizione);
  112.            
  113.             String labelPerPorta = null;
  114.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  115.                 lstParam.remove(lstParam.size()-1);
  116.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  117.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CANALE_CONFIG_DI,
  118.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CANALE,
  119.                         portaDelegata);
  120.             }
  121.             else {
  122.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CANALE_CONFIG_DI+idporta;
  123.             }
  124.            
  125.             if(labelPerPorta.contains(CostantiControlStation.LABEL_DEL_GRUPPO)) {
  126.                 labelPerPorta = labelPerPorta.substring(0, labelPerPorta.indexOf(CostantiControlStation.LABEL_DEL_GRUPPO));
  127.             }
  128.            
  129.             lstParam.add(new Parameter(labelPerPorta,  null));
  130.            
  131.             // edit in progress
  132.             if (porteDelegateHelper.isEditModeInProgress()) {
  133.                 ServletUtils.setPageDataTitle(pd, lstParam);
  134.                
  135.                 if(canale == null) {
  136.                     canale = portaDelegata.getCanale();
  137.                 }
  138.                 if(canaleStato==null) {
  139.                     if(canale == null) {
  140.                         canaleStato = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CANALE_STATO_DEFAULT;
  141.                     } else {
  142.                         canaleStato = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CANALE_STATO_RIDEFINITO;
  143.                     }
  144.                 }
  145.                
  146.                 // preparo i campi
  147.                 List<DataElement> dati = new ArrayList<>();
  148.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  149.                 porteDelegateHelper.addCanaleToDati(dati, tipoOperazione, canaleStato, canale, as.getCanale(), canaleList, gestioneCanaliEnabled);
  150.                
  151.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idSoggFruitore, null,idAsps,
  152.                         idFruizione, portaDelegata.getTipoSoggettoProprietario(), portaDelegata.getNomeSoggettoProprietario(), dati);

  153.                 pd.setDati(dati);

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

  155.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_GESTIONE_CANALE,   ForwardParams.OTHER(""));
  156.             }

  157.             // Controlli sui campi immessi
  158.             boolean isOk = porteDelegateHelper.canaleCheckData(canaleStato, canale, gestioneCanaliEnabled);
  159.             if (!isOk) {

  160.                 ServletUtils.setPageDataTitle(pd, lstParam);

  161.                 // preparo i campi
  162.                 List<DataElement> dati = new ArrayList<>();
  163.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  164.                
  165.                 porteDelegateHelper.addCanaleToDati(dati, tipoOperazione, canaleStato, canale, as.getCanale(), canaleList, gestioneCanaliEnabled);
  166.                
  167.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idSoggFruitore, null,idAsps,
  168.                         idFruizione, portaDelegata.getTipoSoggettoProprietario(), portaDelegata.getNomeSoggettoProprietario(), dati);

  169.                 pd.setDati(dati);

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

  171.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_GESTIONE_CANALE,   ForwardParams.OTHER(""));
  172.             }
  173.            
  174.             // canale
  175.             if(AccordiServizioParteComuneCostanti.DEFAULT_VALUE_PARAMETRO_APC_CANALE_STATO_RIDEFINITO.equals(canaleStato)) {
  176.                 portaDelegata.setCanale(canale);
  177.             } else {
  178.                 portaDelegata.setCanale(null);
  179.             }

  180.             porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), portaDelegata);
  181.        
  182.             // Faccio ricalcolare la lista dei servizi, poichè il canale può essere cambiato
  183.             ServletUtils.removeRisultatiRicercaFromSession(request, session, Liste.SERVIZI);
  184.            
  185.             // Preparo la lista
  186.             pd.setMessage(PorteDelegateCostanti.LABEL_PORTE_DELEGATE_CANALE_CON_SUCCESSO, Costanti.MESSAGE_TYPE_INFO);

  187.             portaDelegata = porteDelegateCore.getPortaDelegata(idInt);
  188.             idporta = portaDelegata.getNome();

  189.             ServletUtils.setPageDataTitle(pd, lstParam);

  190.             // preparo i campi
  191.             List<DataElement> dati = new ArrayList<>();
  192.             dati.add(ServletUtils.getDataElementForEditModeFinished());
  193.            
  194.             // ricarico la configurazione
  195.            
  196.             canale = portaDelegata.getCanale();
  197.             if(canale == null) {
  198.                 canaleStato = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CANALE_STATO_DEFAULT;
  199.             } else {
  200.                 canaleStato = CostantiControlStation.DEFAULT_VALUE_PARAMETRO_CANALE_STATO_RIDEFINITO;
  201.             }
  202.            
  203.             porteDelegateHelper.addCanaleToDati(dati, tipoOperazione, canaleStato, canale, as.getCanale(), canaleList, gestioneCanaliEnabled);
  204.            
  205.             dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.OTHER,id, idSoggFruitore, null,idAsps,
  206.                     idFruizione, portaDelegata.getTipoSoggettoProprietario(), portaDelegata.getNomeSoggettoProprietario(), dati);

  207.             pd.setDati(dati);

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

  209.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_GESTIONE_CANALE, ForwardParams.OTHER(""));
  210.         } catch (Exception e) {
  211.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  212.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_GESTIONE_CANALE, ForwardParams.OTHER(""));
  213.         }
  214.     }

  215. }