PorteApplicativeAbilitazione.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.List;

  22. import javax.servlet.ServletException;
  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.constants.StatoFunzionalita;
  34. import org.openspcoop2.core.id.IDPortaApplicativa;
  35. import org.openspcoop2.core.id.IDServizio;
  36. import org.openspcoop2.core.mapping.MappingErogazionePortaApplicativa;
  37. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  38. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  39. import org.openspcoop2.core.registry.driver.IDAccordoFactory;
  40. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  41. import org.openspcoop2.message.constants.ServiceBinding;
  42. import org.openspcoop2.pdd.core.jmx.JMXUtils;
  43. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  44. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  45. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  46. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  47. import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneCore;
  48. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
  49. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaHelper;
  50. import org.openspcoop2.web.ctrlstat.servlet.aps.erogazioni.ErogazioniHelper;
  51. import org.openspcoop2.web.lib.mvc.Costanti;
  52. import org.openspcoop2.web.lib.mvc.ForwardParams;
  53. import org.openspcoop2.web.lib.mvc.GeneralData;
  54. import org.openspcoop2.web.lib.mvc.MessageType;
  55. import org.openspcoop2.web.lib.mvc.PageData;
  56. import org.openspcoop2.web.lib.mvc.ServletUtils;
  57. import org.openspcoop2.web.lib.mvc.TipoOperazione;
  58. import org.openspcoop2.web.lib.users.dao.PermessiUtente;

  59. /**
  60.  * porteAppChange
  61.  *
  62.  * @author Andrea Poli (apoli@link.it)
  63.  * @author Stefano Corallo (corallo@link.it)
  64.  * @author Sandra Giangrandi (sandra@link.it)
  65.  * @author $Author$
  66.  * @version $Rev$, $Date$
  67.  *
  68.  */
  69. public final class PorteApplicativeAbilitazione extends Action {

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

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

  73.         // Inizializzo PageData
  74.         PageData pd = new PageData();

  75.         GeneralHelper generalHelper = new GeneralHelper(session);

  76.         // Inizializzo GeneralData
  77.         GeneralData gd = generalHelper.initGeneralData(request);

  78.         try {
  79.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  80.            
  81.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  82.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  83.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  84.            
  85.             String changeAbilitato = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ABILITA);
  86.             String nomePorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_NOME_PORTA);
  87.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  88.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  89.             int soggInt = Integer.parseInt(idsogg);
  90.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  91.             if(idAsps == null)
  92.                 idAsps = "";
  93.            
  94.             String idTab = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
  95.             if(!porteApplicativeHelper.isModalitaCompleta() && StringUtils.isNotEmpty(idTab)) {
  96.                 ServletUtils.setObjectIntoSession(request, session, idTab, CostantiControlStation.PARAMETRO_ID_TAB);
  97.             }
  98.            
  99.             String fromAPIPageInfo = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_API_PAGE_INFO);
  100.             boolean fromApi = Costanti.CHECK_BOX_ENABLED_TRUE.equalsIgnoreCase(fromAPIPageInfo);
  101.            
  102.             String actionConferma = porteApplicativeHelper.getParameter(Costanti.PARAMETRO_ACTION_CONFIRM);
  103.            
  104.             // check su oldNomePD
  105.             PageData pdOld =  ServletUtils.getPageDataFromSession(request, session);
  106.             String oldNomePA = pdOld.getHidden(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_OLD_NOME_PA);
  107.             oldNomePA = (((oldNomePA != null) && !oldNomePA.equals("")) ? oldNomePA : nomePorta);
  108.            
  109.             // Preparo il menu
  110.             porteApplicativeHelper.makeMenu();

  111.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  112.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
  113.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteApplicativeCore);

  114.             // Prendo la porta applicativa
  115.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(Integer.parseInt(idPorta));
  116.            
  117.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(Integer.parseInt(idAsps));
  118.             AccordoServizioParteComuneSintetico aspc = apcCore.getAccordoServizioSintetico(IDAccordoFactory.getInstance().getIDAccordoFromUri(asps.getAccordoServizioParteComune()));
  119.             ServiceBinding serviceBinding = apcCore.toMessageServiceBinding(aspc.getServiceBinding());
  120.            
  121.             // in progress segnalo l'azione che si sta effettuando
  122.             if(actionConferma == null) {
  123.                 String messaggio = porteApplicativeHelper.getMessaggioConfermaModificaRegolaMappingErogazionePortaApplicativa(fromApi, pa, serviceBinding, ServletUtils.isCheckBoxEnabled(changeAbilitato), true,true);

  124.                 pd.setMessage(messaggio, MessageType.CONFIRM);
  125.                
  126.                 String[][] bottoni = {
  127.                         { Costanti.LABEL_MONITOR_BUTTON_ANNULLA,
  128.                             Costanti.LABEL_MONITOR_BUTTON_ANNULLA_CONFERMA_PREFIX +
  129.                             Costanti.LABEL_MONITOR_BUTTON_ANNULLA_CONFERMA_SUFFIX
  130.                            
  131.                         },
  132.                         { Costanti.LABEL_MONITOR_BUTTON_CONFERMA,
  133.                             Costanti.LABEL_MONITOR_BUTTON_ESEGUI_OPERAZIONE_CONFERMA_PREFIX +
  134.                             Costanti.LABEL_MONITOR_BUTTON_ESEGUI_OPERAZIONE_CONFERMA_SUFFIX }};

  135.                 pd.setBottoni(bottoni );
  136.             }

  137.             // se ho confermato effettuo la modifica altrimenti torno direttamente alla lista
  138.             if(actionConferma != null && actionConferma.equals(Costanti.PARAMETRO_ACTION_CONFIRM_VALUE_OK)) {
  139.                 // Prendo la porta applicativa
  140.                 pa = porteApplicativeCore.getPortaApplicativa(Integer.parseInt(idPorta));
  141.                 // Modifico i dati della porta applicativa nel db
  142.                 pa.setNome(nomePorta);
  143.                 IDPortaApplicativa oldIDPortaApplicativaForUpdate = new IDPortaApplicativa();
  144.                 oldIDPortaApplicativaForUpdate.setNome(oldNomePA);
  145.                 pa.setOldIDPortaApplicativaForUpdate(oldIDPortaApplicativaForUpdate);
  146.                
  147.                  // cambio solo la modalita'
  148.                 if(ServletUtils.isCheckBoxEnabled(changeAbilitato)) {
  149.                     pa.setStato(StatoFunzionalita.ABILITATO);
  150.                 }
  151.                 else{
  152.                     pa.setStato(StatoFunzionalita.DISABILITATO);
  153.                 }
  154.                
  155.                 String userLogin = ServletUtils.getUserLoginFromSession(session);
  156.    
  157.                 porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);
  158.                
  159.                 List<String> aliasJmx = porteApplicativeCore.getJmxPdDAliases();
  160.                 if(aliasJmx!=null && !aliasJmx.isEmpty()) {
  161.                     for (String alias : aliasJmx) {
  162.                         String metodo = StatoFunzionalita.ABILITATO.equals(pa.getStato()) ?
  163.                                 porteApplicativeCore.getJmxPdDConfigurazioneSistemaNomeMetodoEnablePortaApplicativa(alias) :
  164.                                 porteApplicativeCore.getJmxPdDConfigurazioneSistemaNomeMetodoDisablePortaApplicativa(alias);
  165.                         try{
  166.                             String stato = porteApplicativeCore.getInvoker().invokeJMXMethod(alias,
  167.                                     porteApplicativeCore.getJmxPdDConfigurazioneSistemaType(alias),
  168.                                     porteApplicativeCore.getJmxPdDConfigurazioneSistemaNomeRisorsaConfigurazionePdD(alias),
  169.                                     metodo,
  170.                                     pa.getNome());
  171.                             if(stato==null) {
  172.                                 throw new ServletException("Aggiornamento fallito");
  173.                             }
  174.                             if(
  175.                                 !(
  176.                                     JMXUtils.MSG_OPERAZIONE_EFFETTUATA_SUCCESSO.equals(stato)
  177.                                     ||
  178.                                     (stato!=null && stato.startsWith(JMXUtils.MSG_OPERAZIONE_EFFETTUATA_SUCCESSO_PREFIX))
  179.                                 )
  180.                             ){
  181.                                 throw new ServletException(stato);
  182.                             }
  183.                         }catch(Exception e){
  184.                             String msgErrore = "Errore durante l'aggiornamento dello stato della PortaApplicativa '"+pa.getNome()+"' via jmx (jmxMethod '"+metodo+"') (node:"+alias+"): "+e.getMessage();
  185.                             ControlStationCore.logError(msgErrore, e);
  186.                         }
  187.                     }
  188.                 }
  189.             }
  190.             // Preparo la lista
  191.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);


  192.             List<PortaApplicativa> lista = null;
  193.             int idLista = -1;
  194.            
  195.        
  196.             switch (parentPA) {
  197.             case PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE:
  198.                
  199.                 if(fromApi) {
  200.                     ErogazioniHelper apsHelper = new ErogazioniHelper(request, pd, session);
  201.                     apsHelper.prepareErogazioneChange(TipoOperazione.CHANGE, asps, null);  
  202.                 }
  203.                 else {
  204.                
  205.                     boolean datiInvocazione = ServletUtils.isCheckBoxEnabled(porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_CONFIGURAZIONE_DATI_INVOCAZIONE));
  206.                     if(datiInvocazione) {
  207.                         idLista = Liste.SERVIZI;
  208.                         ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
  209.                         boolean [] permessi = new boolean[2];
  210.                         PermessiUtente pu = ServletUtils.getUserFromSession(request, session).getPermessi();
  211.                         permessi[0] = pu.isServizi();
  212.                         permessi[1] = pu.isAccordiCooperazione();
  213.                         List<AccordoServizioParteSpecifica> listaS = null;
  214.                         String superUser   = ServletUtils.getUserLoginFromSession(session);
  215.                         if(apsCore.isVisioneOggettiGlobale(superUser)){
  216.                             listaS = apsCore.soggettiServizioList(null, ricerca,permessi,session, request);
  217.                         }else{
  218.                             listaS = apsCore.soggettiServizioList(superUser, ricerca,permessi,session, request);
  219.                         }
  220.                         AccordiServizioParteSpecificaHelper apsHelper = new AccordiServizioParteSpecificaHelper(request, pd, session);
  221.                         apsHelper.prepareServiziList(ricerca, listaS);
  222.                     }
  223.                     else {          
  224.                         idLista = Liste.CONFIGURAZIONE_EROGAZIONE;
  225.                         ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
  226.                         IDServizio idServizio2 = IDServizioFactory.getInstance().getIDServizioFromAccordo(asps);
  227.                         Long idSoggetto = asps.getIdSoggetto() != null ? asps.getIdSoggetto() : -1L;
  228.                         List<MappingErogazionePortaApplicativa> lista2 = apsCore.mappingServiziPorteAppList(idServizio2,asps.getId(),ricerca);
  229.                         AccordiServizioParteSpecificaHelper apsHelper = new AccordiServizioParteSpecificaHelper(request, pd, session);
  230.                         apsHelper.prepareServiziConfigurazioneList(lista2, idAsps, idSoggetto+"", ricerca);
  231.                     }
  232.                    
  233.                 }
  234.                    
  235.                 break;
  236.             case PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_SOGGETTO:
  237.                 idLista = Liste.PORTE_APPLICATIVE_BY_SOGGETTO;
  238.                 ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
  239.                 lista = porteApplicativeCore.porteAppList(soggInt, ricerca);
  240.                 porteApplicativeHelper.preparePorteAppList(ricerca, lista,idLista);
  241.                 break;
  242.             case PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE:
  243.             default:
  244.                 idLista = Liste.PORTE_APPLICATIVE;
  245.                 ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
  246.                 lista = porteApplicativeCore.porteAppList(null, ricerca);
  247.                 porteApplicativeHelper.preparePorteAppList(ricerca, lista,idLista);
  248.                 break;
  249.             }

  250.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  251.            
  252.             ForwardParams fwP = porteApplicativeHelper.isModalitaCompleta() ? ForwardParams.OTHER("") : PorteApplicativeCostanti.TIPO_OPERAZIONE_CONFIGURAZIONE;
  253.             // Forward control to the specified success URI
  254.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_ABILITAZIONE, fwP);
  255.         } catch (Exception e) {
  256.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  257.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_ABILITAZIONE,
  258.                     ForwardParams.OTHER(""));

  259.         }
  260.     }
  261. }