PorteApplicativeConnettoriMultipliDel.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.commons.lang.StringUtils;
  27. import org.apache.struts.action.Action;
  28. import org.apache.struts.action.ActionForm;
  29. import org.apache.struts.action.ActionForward;
  30. import org.apache.struts.action.ActionMapping;
  31. import org.openspcoop2.core.commons.Liste;
  32. import org.openspcoop2.core.config.PortaApplicativa;
  33. import org.openspcoop2.core.config.PortaApplicativaServizioApplicativo;
  34. import org.openspcoop2.core.config.ServizioApplicativo;
  35. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  36. import org.openspcoop2.core.id.IDServizioApplicativo;
  37. import org.openspcoop2.core.id.IDSoggetto;
  38. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  39. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  40. import org.openspcoop2.message.constants.ServiceBinding;
  41. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  42. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  43. import org.openspcoop2.web.ctrlstat.core.Utilities;
  44. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  45. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  46. import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneCore;
  47. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
  48. import org.openspcoop2.web.ctrlstat.servlet.sa.ServiziApplicativiCore;
  49. import org.openspcoop2.web.ctrlstat.servlet.sa.ServiziApplicativiCostanti;
  50. import org.openspcoop2.web.lib.mvc.Costanti;
  51. import org.openspcoop2.web.lib.mvc.ForwardParams;
  52. import org.openspcoop2.web.lib.mvc.GeneralData;
  53. import org.openspcoop2.web.lib.mvc.MessageType;
  54. import org.openspcoop2.web.lib.mvc.PageData;
  55. import org.openspcoop2.web.lib.mvc.ServletUtils;

  56. /**
  57.  * PorteApplicativeConnettoriMultipliDel
  58.  *
  59.  * @author Andrea Poli (apoli@link.it)
  60.  * @author Giuliano Pintori (pintori@link.it)
  61.  * @author $Author$
  62.  * @version $Rev$, $Date$
  63.  *
  64.  */
  65. public final class PorteApplicativeConnettoriMultipliDel extends Action {

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

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

  69.         // Inizializzo PageData
  70.         PageData pd = new PageData();

  71.         GeneralHelper generalHelper = new GeneralHelper(session);

  72.         // Inizializzo GeneralData
  73.         GeneralData gd = generalHelper.initGeneralData(request);



  74.         try {
  75.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  76.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  77.             int idInt = Integer.parseInt(idPorta);
  78.             String objToRemove = porteApplicativeHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  79.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);
  80.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  81.             if(idAsps == null)
  82.                 idAsps = "";

  83.             String idConnTab = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_ID_CONN_TAB);
  84.             if(StringUtils.isNotEmpty(idConnTab)) {
  85.                 ServletUtils.setObjectIntoSession(request, session, idConnTab, CostantiControlStation.PARAMETRO_ID_CONN_TAB);
  86.             }

  87.             String nome = "";
  88.             String actionConferma = porteApplicativeHelper.getParameter(Costanti.PARAMETRO_ACTION_CONFIRM);

  89.             // Prendo la porta applicativa
  90.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  91.             ServiziApplicativiCore saCore = new ServiziApplicativiCore(porteApplicativeCore);
  92.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
  93.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteApplicativeCore);

  94.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  95.             long idAspsLong = Long.parseLong(idAsps);
  96.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(idAspsLong);
  97.             AccordoServizioParteComuneSintetico apc = apcCore.getAccordoServizioSintetico(asps.getIdAccordo());
  98.             ServiceBinding serviceBinding = apcCore.toMessageServiceBinding(apc.getServiceBinding());

  99.             List<Object> listaOggettiDaEliminare = new ArrayList<>();
  100.             boolean eseguiOperazione = true;

  101.             boolean connettoreUtilizzatiConfig = false;
  102.             List<String> messaggiSezioniConnettore = new ArrayList<>();
  103.             int numeroElementiDaControllare = idsToRemove.size();
  104.             for (int i = 0; i < idsToRemove.size(); i++) {
  105.                 nome = idsToRemove.get(i);
  106.            
  107.                 connettoreUtilizzatiConfig = porteApplicativeHelper. isConnettoreMultiploInUso(numeroElementiDaControllare, nome, pa, asps, apc, serviceBinding, messaggiSezioniConnettore);
  108.             } // end for elementi selezionati
  109.            
  110.             StringBuilder sbErrore = new StringBuilder();
  111.             if(connettoreUtilizzatiConfig) {
  112.                 if(idsToRemove.size() > 1) {
  113.                     sbErrore.append(PorteApplicativeCostanti.MESSAGGIO_IMPOSSIBILE_ELIMINARE_I_CONNETTORI_UTILIZZATI_IN_CONFIGURAZIONE);
  114.                 } else {
  115.                     sbErrore.append(PorteApplicativeCostanti.MESSAGGIO_IMPOSSIBILE_ELIMINARE_IL_CONNETTORE_UTILIZZATI_IN_CONFIGURAZIONE);
  116.                 }
  117.                 sbErrore.append(":").append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  118.                 for (String s : messaggiSezioniConnettore) {
  119.                     sbErrore.append(s);
  120.                 }

  121.                 eseguiOperazione = false;
  122.             }
  123.             else {
  124.                 connettoreUtilizzatiConfig = porteApplicativeHelper.isConnettoreMultiploInUsoCriteriApplicabilitaTrasformazioni(numeroElementiDaControllare, nome,
  125.                             pa, serviceBinding, messaggiSezioniConnettore);
  126.                
  127.                 if(connettoreUtilizzatiConfig) {
  128.                     if(idsToRemove.size() > 1) {
  129.                         sbErrore.append(PorteApplicativeCostanti.MESSAGGIO_IMPOSSIBILE_ELIMINARE_I_CONNETTORI_UTILIZZATI_IN_ALTRE_CONFIGURAZIONI);
  130.                     } else {
  131.                         sbErrore.append(PorteApplicativeCostanti.MESSAGGIO_IMPOSSIBILE_ELIMINARE_IL_CONNETTORE_UTILIZZATI_IN_ALTRE_CONFIGURAZIONI);
  132.                     }
  133.                     sbErrore.append(":").append(org.openspcoop2.core.constants.Costanti.WEB_NEW_LINE);
  134.                     for (String s : messaggiSezioniConnettore) {
  135.                         sbErrore.append(s);
  136.                     }
  137.    
  138.                     eseguiOperazione = false;
  139.                 }
  140.             }

  141.             // se non devo visualizzare il messaggio di errore procedo ai controlli successivi
  142.             if(!connettoreUtilizzatiConfig) {
  143.                 int numeroAbilitati = 0;
  144.                 for (int j = 0; j < pa.sizeServizioApplicativoList(); j++) {
  145.                     PortaApplicativaServizioApplicativo paSA = pa.getServizioApplicativo(j);

  146.                     boolean toDel = false;
  147.                     for (int i = 0; i < idsToRemove.size(); i++) {
  148.                         nome = idsToRemove.get(i);
  149.                         if (nome.equals(paSA.getNome())) {
  150.                             toDel = true;
  151.                             break;
  152.                         }
  153.                     }

  154.                     if(!toDel) {
  155.                         boolean abilitato = paSA.getDatiConnettore() != null ? paSA.getDatiConnettore().getStato().equals(StatoFunzionalita.ABILITATO) : true;

  156.                         if(abilitato)
  157.                             numeroAbilitati ++;
  158.                     }
  159.                 }


  160.                 if(numeroAbilitati < 1) {
  161.                     eseguiOperazione = false;
  162.                     if(idsToRemove.size() > 1) {
  163.                         sbErrore.append(PorteApplicativeCostanti.MESSAGGIO_IMPOSSIBILE_ELIMINARE_I_CONNETTORI_DEVE_RIMANARE_ALMENTO_UN_CONNETTORE_ABILITATO);
  164.                     } else {
  165.                         sbErrore.append(PorteApplicativeCostanti.MESSAGGIO_IMPOSSIBILE_ELIMINARE_IL_CONNETTORE_DEVE_RIMANARE_ALMENTO_UN_CONNETTORE_ABILITATO);
  166.                     }
  167.                 }
  168.             }

  169.             if(!eseguiOperazione &&
  170.                 actionConferma == null) {
  171.                 String messaggio = sbErrore.toString();
  172.                 String title = "Attenzione";
  173.                 String[][] bottoni = {
  174.                         { Costanti.LABEL_MONITOR_BUTTON_CHIUDI,
  175.                             Costanti.LABEL_MONITOR_BUTTON_ANNULLA_CONFERMA_PREFIX +
  176.                             Costanti.LABEL_MONITOR_BUTTON_ANNULLA_CONFERMA_SUFFIX

  177.                         }
  178.                 };
  179.                 pd.setBottoni(bottoni );
  180.                 pd.setMessage(messaggio, title, MessageType.CONFIRM);
  181.             }


  182.             if(eseguiOperazione) {
  183.                 for (int i = 0; i < idsToRemove.size(); i++) {

  184.                     nome = idsToRemove.get(i);

  185.                     for (int j = 0; j < pa.sizeServizioApplicativoList(); j++) {
  186.                         PortaApplicativaServizioApplicativo paSA = pa.getServizioApplicativo(j);
  187.                         if (nome.equals(paSA.getNome()) && !porteApplicativeHelper.isConnettoreDefault(paSA)) {
  188.                             pa.removeServizioApplicativo(j);

  189.                             // se non sto utilizzando un SA Server lo elimino
  190.                             IDServizioApplicativo idSA = new IDServizioApplicativo();
  191.                             idSA.setNome(paSA.getNome());
  192.                             IDSoggetto idSoggettoProprietario = new IDSoggetto();
  193.                             idSoggettoProprietario.setTipo(pa.getTipoSoggettoProprietario());
  194.                             idSoggettoProprietario.setNome(pa.getNomeSoggettoProprietario());
  195.                             idSA.setIdSoggettoProprietario(idSoggettoProprietario );
  196.                             ServizioApplicativo sa = saCore.getServizioApplicativo(idSA);

  197.                             if(!ServiziApplicativiCostanti.VALUE_SERVIZI_APPLICATIVI_TIPO_SERVER.equals(sa.getTipo())) {
  198.                                 listaOggettiDaEliminare.add(sa);
  199.                             }

  200.                             break;
  201.                         }
  202.                     }
  203.                 }


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

  205.                 porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);
  206.                
  207.                 if(!listaOggettiDaEliminare.isEmpty())
  208.                     porteApplicativeCore.performDeleteOperation(userLogin, porteApplicativeHelper.smista(), listaOggettiDaEliminare.toArray(new Object[listaOggettiDaEliminare.size()]));
  209.                
  210.                 ServletUtils.removeRisultatiRicercaFromSession(request, session, Liste.PORTE_APPLICATIVE_CONNETTORI_MULTIPLI);
  211.                
  212.             }

  213.             // Preparo il menu
  214.             porteApplicativeHelper.makeMenu();

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

  217.             int idLista = Liste.PORTE_APPLICATIVE_CONNETTORI_MULTIPLI;

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

  219.             // ricarico la configurazione
  220.             pa = porteApplicativeCore.getPortaApplicativa(Integer.parseInt(idPorta));
  221.             IDSoggetto idSoggettoProprietario = new IDSoggetto(pa.getTipoSoggettoProprietario(), pa.getNomeSoggettoProprietario());
  222.             List<PortaApplicativaServizioApplicativo> listaFiltrata = porteApplicativeHelper.applicaFiltriRicercaConnettoriMultipli(ricerca, idLista, pa.getServizioApplicativoList(), idSoggettoProprietario);
  223.                        
  224.             porteApplicativeHelper.preparePorteAppConnettoriMultipliList_fromDeleteConnettore(pa.getNome(), ricerca, listaFiltrata, pa);

  225.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  226.             // Forward control to the specified success URI
  227.             return ServletUtils.getStrutsForward (mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI,
  228.                     ForwardParams.DEL());
  229.         } catch (Exception e) {
  230.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  231.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_CONNETTORI_MULTIPLI,
  232.                     ForwardParams.DEL());
  233.         }  
  234.     }
  235. }