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

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

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

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

  75.         // Inizializzo PageData
  76.         PageData pd = new PageData();

  77.         GeneralHelper generalHelper = new GeneralHelper(session);

  78.         // Inizializzo GeneralData
  79.         GeneralData gd = generalHelper.initGeneralData(request);

  80.         try {
  81.            
  82.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  83.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  84.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  85.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  86.            
  87.             String changeAbilitato = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ABILITA);
  88. //          String idPorta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  89.             String nomePorta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME_PORTA);
  90.             String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  91.             int soggInt = Integer.parseInt(idsogg);
  92.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  93.             if(idAsps == null)
  94.                 idAsps = "";
  95.            
  96.             String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  97.             if(idFruizione == null)
  98.                 idFruizione = "";
  99.            
  100.             String actionConferma = porteDelegateHelper.getParameter(Costanti.PARAMETRO_ACTION_CONFIRM);
  101.            
  102.             String idTab = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
  103.             if(!porteDelegateHelper.isModalitaCompleta() && StringUtils.isNotEmpty(idTab)) {
  104.                 ServletUtils.setObjectIntoSession(request, session, idTab, CostantiControlStation.PARAMETRO_ID_TAB);
  105.             }
  106.            
  107.             String fromAPIPageInfo = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_API_PAGE_INFO);
  108.             boolean fromApi = Costanti.CHECK_BOX_ENABLED_TRUE.equalsIgnoreCase(fromAPIPageInfo);
  109.            
  110.             // check su oldNomePD
  111.             PageData pdOld =  ServletUtils.getPageDataFromSession(request, session);
  112.             String oldNomePD = pdOld.getHidden(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_OLD_NOME_PD);
  113.             oldNomePD = (((oldNomePD != null) && !oldNomePD.equals("")) ? oldNomePD : nomePorta);
  114.             // Preparo il menu
  115.             porteDelegateHelper.makeMenu();

  116.             // Prendo nome e tipo del soggetto
  117.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  118.             SoggettiCore soggettiCore = new SoggettiCore(porteDelegateCore);
  119.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteDelegateCore);
  120.             AccordiServizioParteSpecificaCore aspsCore = new AccordiServizioParteSpecificaCore(porteDelegateCore);
  121.            
  122.             IDSoggetto idSoggettoFruitore = null;
  123.             if(porteDelegateCore.isRegistroServiziLocale()){
  124.                 org.openspcoop2.core.registry.Soggetto soggetto = soggettiCore.getSoggettoRegistro(soggInt);
  125.                 idSoggettoFruitore = new IDSoggetto(soggetto.getTipo(), soggetto.getNome());
  126.             }else{
  127.                 org.openspcoop2.core.config.Soggetto soggetto = soggettiCore.getSoggetto(soggInt);
  128.                 idSoggettoFruitore = new IDSoggetto(soggetto.getTipo(), soggetto.getNome());
  129.             }

  130.             // Prendo la porta delegata
  131.             IDPortaDelegata idpd = new IDPortaDelegata();
  132.             idpd.setNome(oldNomePD);
  133.             PortaDelegata oldPD = porteDelegateCore.getPortaDelegata(idpd);
  134.            
  135.             Long idAspsLong = -1L;
  136.             if(idAsps.equals("")) {
  137.                 PortaDelegataServizio servizio2 = oldPD.getServizio();
  138.                 idAspsLong = servizio2.getId();
  139.             } else {
  140.                 idAspsLong = Long.parseLong(idAsps);
  141.             }
  142.            
  143.             AccordoServizioParteSpecifica asps = aspsCore.getAccordoServizioParteSpecifica(idAspsLong);
  144.             AccordoServizioParteComuneSintetico aspc = apcCore.getAccordoServizioSintetico(IDAccordoFactory.getInstance().getIDAccordoFromUri(asps.getAccordoServizioParteComune()));
  145.             ServiceBinding serviceBinding = apcCore.toMessageServiceBinding(aspc.getServiceBinding());
  146.            
  147.             // in progress segnalo l'azione che si sta effettuando
  148.             if(actionConferma == null) {
  149.                 String messaggio = porteDelegateHelper.getMessaggioConfermaModificaRegolaMappingFruizionePortaDelegata(fromApi, oldPD,serviceBinding,ServletUtils.isCheckBoxEnabled(changeAbilitato), true, true);
  150.                
  151.                 pd.setMessage(messaggio, MessageType.CONFIRM);
  152.                
  153.                 String[][] bottoni = {
  154.                         { Costanti.LABEL_MONITOR_BUTTON_ANNULLA,
  155.                             Costanti.LABEL_MONITOR_BUTTON_ANNULLA_CONFERMA_PREFIX +
  156.                             Costanti.LABEL_MONITOR_BUTTON_ANNULLA_CONFERMA_SUFFIX
  157.                            
  158.                         },
  159.                         { Costanti.LABEL_MONITOR_BUTTON_CONFERMA,
  160.                             Costanti.LABEL_MONITOR_BUTTON_ESEGUI_OPERAZIONE_CONFERMA_PREFIX +
  161.                             Costanti.LABEL_MONITOR_BUTTON_ESEGUI_OPERAZIONE_CONFERMA_SUFFIX }};

  162.                 pd.setBottoni(bottoni);
  163.                
  164.             }

  165.             // se ho confermato effettuo la modifica altrimenti torno direttamente alla lista
  166.             if(actionConferma != null && actionConferma.equals(Costanti.PARAMETRO_ACTION_CONFIRM_VALUE_OK)) {
  167.                 long idPA = oldPD.getId();
  168.                 PortaDelegata portaDelegata = (PortaDelegata) oldPD.clone();// new
  169.                 portaDelegata.setId(idPA);
  170.                 portaDelegata.setNome(nomePorta);
  171.                
  172.                 // cambio solo la modalita'
  173.                 if(ServletUtils.isCheckBoxEnabled(changeAbilitato)) {
  174.                     portaDelegata.setStato(StatoFunzionalita.ABILITATO);
  175.                 }
  176.                 else{
  177.                     portaDelegata.setStato(StatoFunzionalita.DISABILITATO);
  178.                 }
  179.                 String userLogin = ServletUtils.getUserLoginFromSession(session);
  180.                 porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), portaDelegata);
  181.                
  182.                 List<String> aliasJmx = porteDelegateCore.getJmxPdDAliases();
  183.                 if(aliasJmx!=null && !aliasJmx.isEmpty()) {
  184.                     for (String alias : aliasJmx) {
  185.                         String metodo = StatoFunzionalita.ABILITATO.equals(portaDelegata.getStato()) ?
  186.                                 porteDelegateCore.getJmxPdDConfigurazioneSistemaNomeMetodoEnablePortaDelegata(alias) :
  187.                                     porteDelegateCore.getJmxPdDConfigurazioneSistemaNomeMetodoDisablePortaDelegata(alias);
  188.                         try{
  189.                             String stato = porteDelegateCore.getInvoker().invokeJMXMethod(alias,
  190.                                     porteDelegateCore.getJmxPdDConfigurazioneSistemaType(alias),
  191.                                     porteDelegateCore.getJmxPdDConfigurazioneSistemaNomeRisorsaConfigurazionePdD(alias),
  192.                                     metodo,
  193.                                     portaDelegata.getNome());
  194.                             if(stato==null) {
  195.                                 throw new ServletException("Aggiornamento fallito");
  196.                             }
  197.                             if(
  198.                                     !(
  199.                                         JMXUtils.MSG_OPERAZIONE_EFFETTUATA_SUCCESSO.equals(stato)
  200.                                         ||
  201.                                         (stato!=null && stato.startsWith(JMXUtils.MSG_OPERAZIONE_EFFETTUATA_SUCCESSO_PREFIX))
  202.                                     )
  203.                                 ){
  204.                                 throw new ServletException(stato);
  205.                             }
  206.                         }catch(Exception e){
  207.                             String msgErrore = "Errore durante l'aggiornamento dello stato della PortaDelegata '"+portaDelegata.getNome()+"' via jmx (jmxMethod '"+metodo+"') (node:"+alias+"): "+e.getMessage();
  208.                             ControlStationCore.logError(msgErrore, e);
  209.                         }
  210.                     }
  211.                 }
  212.             }
  213.             // Preparo la lista
  214.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);


  215.             int idLista = -1;
  216.             List<PortaDelegata> lista = null;
  217.            
  218.             switch (parentPD) {
  219.             case PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE:
  220.                 if(fromApi) {
  221.                     ErogazioniHelper apsHelper = new ErogazioniHelper(request, pd, session);
  222.                     apsHelper.prepareErogazioneChange(TipoOperazione.CHANGE, asps, idSoggettoFruitore);
  223.                 }
  224.                 else {
  225.                     idLista = Liste.CONFIGURAZIONE_FRUIZIONE;
  226.                     ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
  227.                     IDServizio idServizio2 = IDServizioFactory.getInstance().getIDServizioFromAccordo(asps);
  228.                    
  229.                     List<MappingFruizionePortaDelegata> listaMapping = aspsCore.serviziFruitoriMappingList((long) Integer.parseInt(idFruizione), idSoggettoFruitore, idServizio2, ricerca);
  230.                     AccordiServizioParteSpecificaHelper apsHelper = new AccordiServizioParteSpecificaHelper(request, pd, session);
  231.                     apsHelper.serviziFruitoriMappingList(listaMapping, idAsps, idsogg, idSoggettoFruitore, idFruizione, ricerca);
  232.                 }              
  233.                 break;
  234.             case PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_SOGGETTO:
  235.                 idLista = Liste.PORTE_DELEGATE_BY_SOGGETTO;
  236.                 ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
  237.                 lista = porteDelegateCore.porteDelegateList(soggInt, ricerca);
  238.                 porteDelegateHelper.preparePorteDelegateList(ricerca, lista,idLista);
  239.                 break;
  240.             case PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE:
  241.             default:
  242.                 idLista = Liste.PORTE_DELEGATE;
  243.                 ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
  244.                 lista = porteDelegateCore.porteDelegateList(null, ricerca);
  245.                 porteDelegateHelper.preparePorteDelegateList(ricerca, lista,idLista);
  246.                 break;
  247.             }

  248.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  249.            
  250.             ForwardParams fwP = porteDelegateHelper.isModalitaCompleta() ? ForwardParams.OTHER("") : PorteDelegateCostanti.TIPO_OPERAZIONE_CONFIGURAZIONE;
  251.             // Forward control to the specified success URI
  252.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_ABILITAZIONE,fwP);

  253.         } catch (Exception e) {
  254.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  255.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_ABILITAZIONE,
  256.                     ForwardParams.OTHER(""));
  257.         }  
  258.     }
  259. }