PluginFetch.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.core.plugins.dao.jdbc.fetch;

  21. import org.openspcoop2.core.constants.CostantiDB;
  22. import org.openspcoop2.generic_project.beans.IModel;
  23. import org.openspcoop2.generic_project.dao.jdbc.utils.AbstractJDBCFetch;
  24. import org.openspcoop2.generic_project.dao.jdbc.utils.GenericJDBCParameterUtilities;
  25. import org.openspcoop2.generic_project.exception.ServiceException;

  26. import java.sql.ResultSet;
  27. import java.util.Map;

  28. import org.openspcoop2.utils.TipiDatabase;
  29. import org.openspcoop2.utils.jdbc.IKeyGeneratorObject;

  30. import org.openspcoop2.core.plugins.PluginServizioCompatibilita;
  31. import org.openspcoop2.core.plugins.PluginProprietaCompatibilita;
  32. import org.openspcoop2.core.plugins.PluginServizioAzioneCompatibilita;
  33. import org.openspcoop2.core.plugins.Plugin;


  34. /**    
  35.  * PluginFetch
  36.  *
  37.  * @author Poli Andrea (poli@link.it)
  38.  * @author $Author$
  39.  * @version $Rev$, $Date$
  40.  */
  41. public class PluginFetch extends AbstractJDBCFetch {

  42.     @Override
  43.     public Object fetch(TipiDatabase tipoDatabase, IModel<?> model , ResultSet rs) throws ServiceException {
  44.        
  45.         try{
  46.             GenericJDBCParameterUtilities jdbcParameterUtilities =  
  47.                     new GenericJDBCParameterUtilities(tipoDatabase);

  48.             if(model.equals(Plugin.model())){
  49.                 Plugin object = new Plugin();
  50.                 setParameter(object, "setId", Long.class,
  51.                     jdbcParameterUtilities.readParameter(rs, "id", Long.class));
  52.                 setParameter(object, "setTipoPlugin", Plugin.model().TIPO_PLUGIN.getFieldType(),
  53.                     jdbcParameterUtilities.readParameter(rs, "tipo_plugin", Plugin.model().TIPO_PLUGIN.getFieldType()));
  54.                 setParameter(object, "setClassName", Plugin.model().CLASS_NAME.getFieldType(),
  55.                     jdbcParameterUtilities.readParameter(rs, "class_name", Plugin.model().CLASS_NAME.getFieldType()));
  56.                 setParameter(object, "setTipo", Plugin.model().TIPO.getFieldType(),
  57.                     jdbcParameterUtilities.readParameter(rs, "tipo", Plugin.model().TIPO.getFieldType()));
  58.                 setParameter(object, "setDescrizione", Plugin.model().DESCRIZIONE.getFieldType(),
  59.                     jdbcParameterUtilities.readParameter(rs, "descrizione", Plugin.model().DESCRIZIONE.getFieldType()));
  60.                 setParameter(object, "setLabel", Plugin.model().LABEL.getFieldType(),
  61.                     jdbcParameterUtilities.readParameter(rs, "label", Plugin.model().LABEL.getFieldType()));
  62.                 setParameter(object, "setStato", Plugin.model().STATO.getFieldType(),
  63.                     jdbcParameterUtilities.readParameter(rs, "stato", Plugin.model().STATO.getFieldType()));
  64.                 return object;
  65.             }
  66.             if(model.equals(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA)){
  67.                 PluginServizioCompatibilita object = new PluginServizioCompatibilita();
  68.                 setParameter(object, "setId", Long.class,
  69.                     jdbcParameterUtilities.readParameter(rs, "id", Long.class));
  70.                 setParameter(object, "setUriAccordo", Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.URI_ACCORDO.getFieldType(),
  71.                     jdbcParameterUtilities.readParameter(rs, "uri_accordo", Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.URI_ACCORDO.getFieldType()));
  72.                 setParameter(object, "setServizio", Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.SERVIZIO.getFieldType(),
  73.                     jdbcParameterUtilities.readParameter(rs, "servizio", Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.SERVIZIO.getFieldType()));
  74.                 return object;
  75.             }
  76.             if(model.equals(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.PLUGIN_SERVIZIO_AZIONE_COMPATIBILITA)){
  77.                 PluginServizioAzioneCompatibilita object = new PluginServizioAzioneCompatibilita();
  78.                 setParameter(object, "setId", Long.class,
  79.                     jdbcParameterUtilities.readParameter(rs, "id", Long.class));
  80.                 setParameter(object, "setAzione", Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.PLUGIN_SERVIZIO_AZIONE_COMPATIBILITA.AZIONE.getFieldType(),
  81.                     jdbcParameterUtilities.readParameter(rs, "azione", Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.PLUGIN_SERVIZIO_AZIONE_COMPATIBILITA.AZIONE.getFieldType()));
  82.                 return object;
  83.             }
  84.             if(model.equals(Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA)){
  85.                 PluginProprietaCompatibilita object = new PluginProprietaCompatibilita();
  86.                 setParameter(object, "setId", Long.class,
  87.                     jdbcParameterUtilities.readParameter(rs, "id", Long.class));
  88.                 setParameter(object, "setNome", Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA.NOME.getFieldType(),
  89.                     jdbcParameterUtilities.readParameter(rs, "nome", Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA.NOME.getFieldType()));
  90.                 setParameter(object, "setValore", Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA.VALORE.getFieldType(),
  91.                     jdbcParameterUtilities.readParameter(rs, "valore", Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA.VALORE.getFieldType()));
  92.                 return object;
  93.             }
  94.            
  95.             else{
  96.                 throw new ServiceException("Model ["+model.toString()+"] not supported by fetch: "+this.getClass().getName());
  97.             }  
  98.                    
  99.         }catch(Exception e){
  100.             throw new ServiceException("Model ["+model.toString()+"] occurs error in fetch: "+e.getMessage(),e);
  101.         }
  102.        
  103.     }
  104.    
  105.     @Override
  106.     public Object fetch(TipiDatabase tipoDatabase, IModel<?> model , Map<String,Object> map ) throws ServiceException {
  107.        
  108.         try{

  109.             if(model.equals(Plugin.model())){
  110.                 Plugin object = new Plugin();
  111.                 setParameter(object, "setId", Long.class,
  112.                     this.getObjectFromMap(map,"id"));
  113.                 setParameter(object, "setTipoPlugin", Plugin.model().TIPO_PLUGIN.getFieldType(),
  114.                     this.getObjectFromMap(map,"tipo-plugin"));
  115.                 setParameter(object, "setClassName", Plugin.model().CLASS_NAME.getFieldType(),
  116.                     this.getObjectFromMap(map,"class-name"));
  117.                 setParameter(object, "setTipo", Plugin.model().TIPO.getFieldType(),
  118.                     this.getObjectFromMap(map,"tipo"));
  119.                 setParameter(object, "setDescrizione", Plugin.model().DESCRIZIONE.getFieldType(),
  120.                     this.getObjectFromMap(map,"descrizione"));
  121.                 setParameter(object, "setLabel", Plugin.model().LABEL.getFieldType(),
  122.                     this.getObjectFromMap(map,"label"));
  123.                 setParameter(object, "setStato", Plugin.model().STATO.getFieldType(),
  124.                     this.getObjectFromMap(map,"stato"));
  125.                 return object;
  126.             }
  127.             if(model.equals(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA)){
  128.                 PluginServizioCompatibilita object = new PluginServizioCompatibilita();
  129.                 setParameter(object, "setId", Long.class,
  130.                     this.getObjectFromMap(map,"plugin-servizio-compatibilita.id"));
  131.                 setParameter(object, "setUriAccordo", Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.URI_ACCORDO.getFieldType(),
  132.                     this.getObjectFromMap(map,"plugin-servizio-compatibilita.uri-accordo"));
  133.                 setParameter(object, "setServizio", Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.SERVIZIO.getFieldType(),
  134.                     this.getObjectFromMap(map,"plugin-servizio-compatibilita.servizio"));
  135.                 return object;
  136.             }
  137.             if(model.equals(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.PLUGIN_SERVIZIO_AZIONE_COMPATIBILITA)){
  138.                 PluginServizioAzioneCompatibilita object = new PluginServizioAzioneCompatibilita();
  139.                 setParameter(object, "setId", Long.class,
  140.                     this.getObjectFromMap(map,"plugin-servizio-compatibilita.plugin-servizio-azione-compatibilita.id"));
  141.                 setParameter(object, "setAzione", Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.PLUGIN_SERVIZIO_AZIONE_COMPATIBILITA.AZIONE.getFieldType(),
  142.                     this.getObjectFromMap(map,"plugin-servizio-compatibilita.plugin-servizio-azione-compatibilita.azione"));
  143.                 return object;
  144.             }
  145.             if(model.equals(Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA)){
  146.                 PluginProprietaCompatibilita object = new PluginProprietaCompatibilita();
  147.                 setParameter(object, "setId", Long.class,
  148.                     this.getObjectFromMap(map,"plugin-proprieta-compatibilita.id"));
  149.                 setParameter(object, "setNome", Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA.NOME.getFieldType(),
  150.                     this.getObjectFromMap(map,"plugin-proprieta-compatibilita.nome"));
  151.                 setParameter(object, "setValore", Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA.VALORE.getFieldType(),
  152.                     this.getObjectFromMap(map,"plugin-proprieta-compatibilita.valore"));
  153.                 return object;
  154.             }
  155.            
  156.             else{
  157.                 throw new ServiceException("Model ["+model.toString()+"] not supported by fetch: "+this.getClass().getName());
  158.             }  
  159.                    
  160.         }catch(Exception e){
  161.             throw new ServiceException("Model ["+model.toString()+"] occurs error in fetch: "+e.getMessage(),e);
  162.         }
  163.        
  164.     }
  165.    
  166.    
  167.     @Override
  168.     public IKeyGeneratorObject getKeyGeneratorObject( IModel<?> model )  throws ServiceException {
  169.        
  170.         try{

  171.             if(model.equals(Plugin.model())){
  172.                 return new org.openspcoop2.utils.jdbc.CustomKeyGeneratorObject(CostantiDB.REGISTRO_CLASSI,"id","seq_plugins","plugins_init_seq");
  173.             }
  174.             if(model.equals(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA)){
  175.                 return new org.openspcoop2.utils.jdbc.CustomKeyGeneratorObject(CostantiDB.REGISTRO_CLASSI_COMPATIBILITA_SERVIZIO,"id","seq_plugins_servizi_comp","plugins_servizi_comp_init_seq");
  176.             }
  177.             if(model.equals(Plugin.model().PLUGIN_SERVIZIO_COMPATIBILITA.PLUGIN_SERVIZIO_AZIONE_COMPATIBILITA)){
  178.                 return new org.openspcoop2.utils.jdbc.CustomKeyGeneratorObject(CostantiDB.REGISTRO_CLASSI_COMPATIBILITA_AZIONE,"id","seq_plugins_azioni_comp","plugins_azioni_comp_init_seq");
  179.             }
  180.             if(model.equals(Plugin.model().PLUGIN_PROPRIETA_COMPATIBILITA)){
  181.                 return new org.openspcoop2.utils.jdbc.CustomKeyGeneratorObject(CostantiDB.REGISTRO_CLASSI_COMPATIBILITA_PROPRIETA,"id","seq_plugins_props_comp","plugins_props_comp_init_seq");
  182.             }
  183.            
  184.             else{
  185.                 throw new ServiceException("Model ["+model.toString()+"] not supported by getKeyGeneratorObject: "+this.getClass().getName());
  186.             }

  187.         }catch(Exception e){
  188.             throw new ServiceException("Model ["+model.toString()+"] occurs error in getKeyGeneratorObject: "+e.getMessage(),e);
  189.         }
  190.        
  191.     }

  192. }