ConfigurazioneTracciamentoDatasourcePropertiesChange.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.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.config.Configurazione;
  31. import org.openspcoop2.core.config.OpenspcoopSorgenteDati;
  32. import org.openspcoop2.core.config.Property;
  33. import org.openspcoop2.core.config.Tracciamento;
  34. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  35. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  36. import org.openspcoop2.web.lib.mvc.DataElement;
  37. import org.openspcoop2.web.lib.mvc.DataElementType;
  38. import org.openspcoop2.web.lib.mvc.ForwardParams;
  39. import org.openspcoop2.web.lib.mvc.GeneralData;
  40. import org.openspcoop2.web.lib.mvc.PageData;
  41. import org.openspcoop2.web.lib.mvc.Parameter;
  42. import org.openspcoop2.web.lib.mvc.ServletUtils;
  43. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  44. /**
  45.  * tracciamentoDatasourcePropChange
  46.  *
  47.  * @author Andrea Poli (apoli@link.it)
  48.  * @author Stefano Corallo (corallo@link.it)
  49.  * @author Sandra Giangrandi (sandra@link.it)
  50.  * @author $Author$
  51.  * @version $Rev$, $Date$
  52.  *
  53.  */
  54. public final class ConfigurazioneTracciamentoDatasourcePropertiesChange extends Action {

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

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

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

  60.         GeneralHelper generalHelper = new GeneralHelper(session);

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

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

  64.         try {
  65.             ConfigurazioneHelper confHelper = new ConfigurazioneHelper(request, pd, session);

  66.             String id = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID);
  67.             int idInt = Integer.parseInt(id);
  68.             String idprop = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID_PROPRIETA);
  69.             int idPropInt = Integer.parseInt(idprop);
  70.             String valore = confHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_VALORE);

  71.             ConfigurazioneCore confCore = new ConfigurazioneCore();

  72.             // Preparo il menu
  73.             confHelper.makeMenu();

  74.             // Prendo l'appender
  75.             Configurazione newConfigurazione = confCore.getConfigurazioneGenerale();
  76.             Tracciamento t = newConfigurazione.getTracciamento();
  77.             List<OpenspcoopSorgenteDati> lista = t.getOpenspcoopSorgenteDatiList();
  78.             OpenspcoopSorgenteDati od = null;
  79.             for (int j = 0; j < t.sizeOpenspcoopSorgenteDatiList(); j++) {
  80.                 od = lista.get(j);
  81.                 if (idInt == od.getId().intValue()) {
  82.                     break;
  83.                 }
  84.             }
  85.             List<Property> lista1 = od.getPropertyList();
  86.             Property odp = null;
  87.             for (int i = 0; i < od.sizePropertyList(); i++) {
  88.                 odp = lista1.get(i);
  89.                 if (idPropInt == odp.getId().intValue()) {
  90.                     break;
  91.                 }
  92.             }

  93.             // Se idhid = null, devo visualizzare la pagina per la
  94.             // modifica dati
  95.             if (confHelper.isEditModeInProgress()) {
  96.                 // setto la barra del titolo
  97.                 List<Parameter> lstParam = new ArrayList<>();

  98.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_TRACCIAMENTO,
  99.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_TRANSAZIONI));
  100.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_SORGENTI_DATI_MESSAGGI_DIAGNOSTICI,
  101.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_DATASOURCE_LIST));
  102.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA + " di " + od.getNome(),
  103.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_DATASOURCE_PROPERTIES_LIST,
  104.                         new Parameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID, od.getId()+"")
  105.                         ));
  106.                 lstParam.add(new Parameter(odp.getNome(), null));

  107.                 ServletUtils.setPageDataTitle(pd, lstParam);

  108.                 // Prendo i dati dal db
  109.                 String nome = odp.getNome();
  110.                 valore = odp.getValore();

  111.                 // preparo i campi
  112.                 List<DataElement> dati = new ArrayList<>();
  113.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  114.                 DataElement dataElement = new DataElement();
  115.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  116.                 dataElement.setType(DataElementType.TITLE);
  117.                 dati.add(dataElement);
  118.                
  119.                 dati = confHelper.addNomeValoreToDati(TipoOperazione.CHANGE, dati, nome, valore, false);        

  120.                 dati = confHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, id, null, null, dati);

  121.                 dati = confHelper.addIdProprietaToDati(TipoOperazione.CHANGE, idprop, dati);

  122.                 pd.setDati(dati);

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

  124.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  125.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_TRACCIAMENTO_DATASOURCE_PROPERTIES,
  126.                         ForwardParams.CHANGE());
  127.             }

  128.             // Controlli sui campi immessi
  129.             boolean isOk = confHelper.tracciamentoDatasourcePropCheckData(TipoOperazione.CHANGE);
  130.             if (!isOk) {
  131.                 // setto la barra del titolo
  132.                 List<Parameter> lstParam = new ArrayList<>();

  133.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_GENERALE,
  134.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_GENERALE));
  135.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_ELENCO_SORGENTI_DATI_MESSAGGI_DIAGNOSTICI,
  136.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_DATASOURCE_LIST));
  137.                 lstParam.add(new Parameter(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA + " di " + od.getNome(),
  138.                         ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_TRACCIAMENTO_DATASOURCE_PROPERTIES_LIST,
  139.                         new Parameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_ID, od.getId()+"")
  140.                         ));
  141.                 lstParam.add(new Parameter(odp.getNome(), null));

  142.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  145.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  146.                
  147.                 DataElement dataElement = new DataElement();
  148.                 dataElement.setLabel(ConfigurazioneCostanti.LABEL_CONFIGURAZIONE_PROPRIETA);
  149.                 dataElement.setType(DataElementType.TITLE);
  150.                 dati.add(dataElement);
  151.                
  152.                 dati = confHelper.addNomeValoreToDati(TipoOperazione.CHANGE, dati, odp.getNome(), valore,  false);

  153.                 dati = confHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, id, null, null, dati);

  154.                 dati = confHelper.addIdProprietaToDati(TipoOperazione.CHANGE, idprop, dati);

  155.                 pd.setDati(dati);

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

  157.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  158.                         ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_TRACCIAMENTO_DATASOURCE_PROPERTIES,
  159.                         ForwardParams.CHANGE());
  160.             }

  161.             // Modifico i dati della property nel db
  162.             for (int k = 0; k < od.sizePropertyList(); k++) {
  163.                 Property tmpOdp = lista1.get(k);
  164.                 if (idPropInt == tmpOdp.getId().intValue()) {
  165.                     od.removeProperty(k);
  166.                     break;
  167.                 }
  168.             }

  169.             Property newOdp = new Property();
  170.             newOdp.setNome(odp.getNome());
  171.             newOdp.setValore(valore);
  172.             od.addProperty(newOdp);

  173.             confCore.performUpdateOperation(userLogin, confHelper.smista(), newConfigurazione);

  174.             // Preparo la lista
  175.             newConfigurazione = confCore.getConfigurazioneGenerale();
  176.             t = newConfigurazione.getTracciamento();
  177.             lista = t.getOpenspcoopSorgenteDatiList();
  178.             od = null;
  179.             for (int j = 0; j < t.sizeOpenspcoopSorgenteDatiList(); j++) {
  180.                 od = lista.get(j);
  181.                 if (idInt == od.getId().intValue()) {
  182.                     break;
  183.                 }
  184.             }
  185.            
  186.             if(od==null) {
  187.                 throw new Exception("Datasource non trovato");
  188.             }
  189.            
  190.             lista1 = od.getPropertyList();

  191.             confHelper.prepareTracciamentoDatasourcePropList(od, lista1);

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

  193.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  194.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_TRACCIAMENTO_DATASOURCE_PROPERTIES,
  195.                     ForwardParams.CHANGE());
  196.         } catch (Exception e) {
  197.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  198.                     ConfigurazioneCostanti.OBJECT_NAME_CONFIGURAZIONE_TRACCIAMENTO_DATASOURCE_PROPERTIES, ForwardParams.CHANGE());
  199.         }
  200.     }


  201. }