ConfigurazionePluginsArchiviChange.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.config;

  21. import java.util.ArrayList;
  22. import java.util.Date;
  23. import java.util.List;

  24. import javax.servlet.http.HttpServletRequest;
  25. import javax.servlet.http.HttpServletResponse;
  26. import javax.servlet.http.HttpSession;

  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.RegistroPlugin;
  33. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  34. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  35. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  36. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  37. import org.openspcoop2.web.lib.mvc.BinaryParameter;
  38. import org.openspcoop2.web.lib.mvc.DataElement;
  39. import org.openspcoop2.web.lib.mvc.ForwardParams;
  40. import org.openspcoop2.web.lib.mvc.GeneralData;
  41. import org.openspcoop2.web.lib.mvc.PageData;
  42. import org.openspcoop2.web.lib.mvc.Parameter;
  43. import org.openspcoop2.web.lib.mvc.ServletUtils;
  44. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  45. /**
  46.  * ConfigurazionePluginsArchiviChange
  47.  *
  48.  * @author Giuliano Pintori (pintori@link.it)
  49.  * @author $Author$
  50.  * @version $Rev$, $Date$
  51.  *
  52.  */
  53. public final class ConfigurazionePluginsArchiviChange extends Action {

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

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

  57.         // Inizializzo PageData
  58.         PageData pd = new PageData();

  59.         GeneralHelper generalHelper = new GeneralHelper(session);

  60.         // Inizializzo GeneralData
  61.         GeneralData gd = generalHelper.initGeneralData(request);

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

  63.         try {
  64.             ConfigurazioneHelper confHelper = new ConfigurazioneHelper(request, pd, session);
  65.            
  66.             String idArchivioS = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_PLUGINS_ARCHIVI_ID_ARCHIVIO);
  67.             String nome = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_PLUGINS_ARCHIVI_NOME);
  68.             String oldNome = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_PLUGINS_ARCHIVI_OLD_NOME);
  69.             String descrizione = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_PLUGINS_ARCHIVI_DESCRIZIONE);
  70.             String stato = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_PLUGINS_ARCHIVI_STATO);
  71.             String sorgente = null;
  72.             BinaryParameter jarArchivio = null;
  73.             String urlArchivio = null;
  74.             String dirArchivio = null;
  75.             String classiPlugin = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_PLUGINS_ARCHIVI_CLASSI_PLUGIN);
  76.             String [] tipoPlugin = confHelper.getParameterValues(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_PLUGINS_ARCHIVI_TIPO_PLUGIN);
  77.            
  78.            
  79.             ConfigurazioneCore confCore = new ConfigurazioneCore();
  80.             int numeroArchivi = confCore.getNumeroArchiviJarRegistroPlugin(oldNome);
  81.             RegistroPlugin oldRegistro = confCore.getDatiRegistroPlugin(oldNome);

  82.             // Preparo il menu
  83.             confHelper.makeMenu();
  84.             List<Parameter> lstParam = new ArrayList<>();
  85.            
  86.             // setto la barra del titolo
  87.             lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE, ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  88.             lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PLUGINS_REGISTRO_ARCHIVI, ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_PLUGINS_ARCHIVI_LIST));
  89.             lstParam.add(new Parameter(oldRegistro.getNome(), null));
  90.             ServletUtils.setPageDataTitle(pd, lstParam);

  91.             // Se nomehid = null, devo visualizzare la pagina per l'inserimento
  92.             // dati
  93.             if (confHelper.isEditModeInProgress()) {
  94.                
  95.                 if(nome == null) {
  96.                     idArchivioS = oldRegistro.getId() + "";
  97.                     nome = oldRegistro.getNome();
  98.                     descrizione = oldRegistro.getDescrizione();
  99.                     stato = oldRegistro.getStato().toString();
  100.                     sorgente = null;
  101.                     classiPlugin = oldRegistro.getCompatibilitaList() == null || oldRegistro.getCompatibilitaList().isEmpty() ?
  102.                             ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_PLUGINS_ARCHIVI_CLASSI_PLUGIN_QUALSIASI:
  103.                                 ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_PLUGINS_ARCHIVI_CLASSI_PLUGIN_SELEZIONATE;
  104.                     if(classiPlugin.equals(ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_PLUGINS_ARCHIVI_CLASSI_PLUGIN_SELEZIONATE)) {
  105.                         tipoPlugin =  oldRegistro.getCompatibilitaList().toArray(new String[oldRegistro.sizeCompatibilitaList()]);
  106.                     } else {
  107.                         tipoPlugin = null;
  108.                     }
  109.                     dirArchivio = "";
  110.                     urlArchivio = "";
  111.                 }
  112.                 // preparo i campi
  113.                 List<DataElement> dati = new ArrayList<>();
  114.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  115.                
  116.                 dati = confHelper.addRegistroPluginToDati(TipoOperazione.CHANGE, dati, oldNome, idArchivioS, nome, descrizione, stato, sorgente, jarArchivio, dirArchivio, urlArchivio, classiPlugin, tipoPlugin, numeroArchivi);

  117.                 pd.setDati(dati);

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

  119.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  120.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_PLUGINS_ARCHIVI,
  121.                         ForwardParams.CHANGE());
  122.             }

  123.             // Controlli sui campi immessi
  124.             boolean isOk = confHelper.registroPluginCheckData(TipoOperazione.CHANGE, oldNome, idArchivioS, nome, descrizione,
  125.                     stato, sorgente, jarArchivio, dirArchivio, urlArchivio, classiPlugin, tipoPlugin);
  126.             if (!isOk) {

  127.                 // preparo i campi
  128.                 List<DataElement> dati = new ArrayList<>();

  129.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  130.                
  131.                 dati = confHelper.addRegistroPluginToDati(TipoOperazione.CHANGE, dati, oldNome, idArchivioS, nome, descrizione, stato, sorgente, jarArchivio, dirArchivio, urlArchivio, classiPlugin, tipoPlugin, numeroArchivi);

  132.                 pd.setDati(dati);

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

  134.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  135.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_PLUGINS_ARCHIVI,
  136.                         ForwardParams.CHANGE());
  137.             }

  138.             // rileggo la configurazione
  139.             RegistroPlugin registro = confCore.getDatiRegistroPlugin(oldNome);
  140.            
  141.             registro.setOldNome(oldNome);
  142.            
  143.             registro.setNome(nome);
  144.             if(descrizione!=null && !"".equals(descrizione)) {
  145.                 registro.setDescrizione(descrizione);
  146.             }
  147.             else {
  148.                 registro.setDescrizione(null);
  149.             }
  150.             if(stato.equals(StatoFunzionalita.ABILITATO.getValue()))
  151.                 registro.setStato(StatoFunzionalita.ABILITATO);
  152.             else
  153.                 registro.setStato(StatoFunzionalita.DISABILITATO);
  154.             registro.setData(new Date());
  155.            
  156.             registro.getCompatibilitaList().clear();
  157.             if(!classiPlugin.equals(ConfigurazioneCostanti.DEFAULT_VALUE_PARAMETRO_CONFIGURAZIONE_PLUGINS_ARCHIVI_CLASSI_PLUGIN_QUALSIASI)) {
  158.                 for (String tipo : tipoPlugin) {
  159.                     registro.getCompatibilitaList().add(tipo);
  160.                 }
  161.             }
  162.            
  163.             confCore.performUpdateOperation(userLogin, confHelper.smista(), registro);
  164.            
  165.             // Aggiorno classLoader interno
  166.             confCore.updatePluginClassLoader();
  167.            
  168.             // Preparo la lista
  169.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  170.             int idLista = Liste.CONFIGURAZIONE_PLUGINS_ARCHIVI;

  171.             ricerca = confHelper.checkSearchParameters(idLista, ricerca);
  172.            
  173.             List<RegistroPlugin> lista = confCore.pluginsArchiviList(ricerca);
  174.            
  175.             confHelper.preparePluginsArchiviList(ricerca, lista);

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

  177.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  178.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_PLUGINS_ARCHIVI,
  179.                     ForwardParams.CHANGE());
  180.         } catch (Exception e) {
  181.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  182.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_PLUGINS_ARCHIVI, ForwardParams.CHANGE());
  183.         }
  184.     }


  185. }