SoggettoFetch.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.commons.search.dao.jdbc.fetch;

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

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

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

  29. import org.openspcoop2.core.commons.search.Soggetto;
  30. import org.openspcoop2.core.commons.search.SoggettoRuolo;
  31. import org.openspcoop2.core.constants.CostantiDB;


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

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

  46.             if(model.equals(Soggetto.model())){
  47.                 Soggetto object = new Soggetto();
  48.                 setParameter(object, "setId", Long.class,
  49.                     jdbcParameterUtilities.readParameter(rs, "id", Long.class));
  50.                 setParameter(object, "setNomeSoggetto", Soggetto.model().NOME_SOGGETTO.getFieldType(),
  51.                     jdbcParameterUtilities.readParameter(rs, "nome_soggetto", Soggetto.model().NOME_SOGGETTO.getFieldType()));
  52.                 setParameter(object, "setTipoSoggetto", Soggetto.model().TIPO_SOGGETTO.getFieldType(),
  53.                     jdbcParameterUtilities.readParameter(rs, "tipo_soggetto", Soggetto.model().TIPO_SOGGETTO.getFieldType()));
  54.                 setParameter(object, "setServer", Soggetto.model().SERVER.getFieldType(),
  55.                     jdbcParameterUtilities.readParameter(rs, "server", Soggetto.model().SERVER.getFieldType()));
  56.                 setParameter(object, "setIdentificativoPorta", Soggetto.model().IDENTIFICATIVO_PORTA.getFieldType(),
  57.                     jdbcParameterUtilities.readParameter(rs, "identificativo_porta", Soggetto.model().IDENTIFICATIVO_PORTA.getFieldType()));
  58.                 return object;
  59.             }
  60.             if(model.equals(Soggetto.model().SOGGETTO_RUOLO)){
  61.                 SoggettoRuolo object = new SoggettoRuolo();
  62.                 setParameter(object, "setId", Long.class,
  63.                     jdbcParameterUtilities.readParameter(rs, "id", Long.class));
  64.                 return object;
  65.             }
  66.            
  67.             else{
  68.                 throw new ServiceException("Model ["+model.toString()+"] not supported by fetch: "+this.getClass().getName());
  69.             }  
  70.                    
  71.         }catch(Exception e){
  72.             throw new ServiceException("Model ["+model.toString()+"] occurs error in fetch: "+e.getMessage(),e);
  73.         }
  74.        
  75.     }
  76.    
  77.     @Override
  78.     public Object fetch(TipiDatabase tipoDatabase, IModel<?> model , Map<String,Object> map ) throws ServiceException {
  79.        
  80.         try{

  81.             if(model.equals(Soggetto.model())){
  82.                 Soggetto object = new Soggetto();
  83.                 setParameter(object, "setId", Long.class,
  84.                     this.getObjectFromMap(map,"id"));
  85.                 setParameter(object, "setNomeSoggetto", Soggetto.model().NOME_SOGGETTO.getFieldType(),
  86.                     this.getObjectFromMap(map,"nome-soggetto"));
  87.                 setParameter(object, "setTipoSoggetto", Soggetto.model().TIPO_SOGGETTO.getFieldType(),
  88.                     this.getObjectFromMap(map,"tipo-soggetto"));
  89.                 setParameter(object, "setServer", Soggetto.model().SERVER.getFieldType(),
  90.                     this.getObjectFromMap(map,"server"));
  91.                 setParameter(object, "setIdentificativoPorta", Soggetto.model().IDENTIFICATIVO_PORTA.getFieldType(),
  92.                     this.getObjectFromMap(map,"identificativo-porta"));
  93.                 return object;
  94.             }
  95.             if(model.equals(Soggetto.model().SOGGETTO_RUOLO)){
  96.                 SoggettoRuolo object = new SoggettoRuolo();
  97.                 setParameter(object, "setId", Long.class,
  98.                     this.getObjectFromMap(map,"soggetto-ruolo.id"));
  99.                 return object;
  100.             }
  101.            
  102.             else{
  103.                 throw new ServiceException("Model ["+model.toString()+"] not supported by fetch: "+this.getClass().getName());
  104.             }  
  105.                    
  106.         }catch(Exception e){
  107.             throw new ServiceException("Model ["+model.toString()+"] occurs error in fetch: "+e.getMessage(),e);
  108.         }
  109.        
  110.     }
  111.    
  112.    
  113.     @Override
  114.     public IKeyGeneratorObject getKeyGeneratorObject( IModel<?> model )  throws ServiceException {
  115.        
  116.         try{

  117.             if(model.equals(Soggetto.model())){
  118.                 return new org.openspcoop2.utils.jdbc.CustomKeyGeneratorObject(CostantiDB.SOGGETTI,"id","seq_"+CostantiDB.SOGGETTI,CostantiDB.SOGGETTI+"_init_seq");
  119.             }
  120.             if(model.equals(Soggetto.model().SOGGETTO_RUOLO)){
  121.                 return new org.openspcoop2.utils.jdbc.CustomKeyGeneratorObject(CostantiDB.SOGGETTI_RUOLI,"id","seq_"+CostantiDB.SOGGETTI_RUOLI,CostantiDB.SOGGETTI_RUOLI+"_init_seq");
  122.             }
  123.            
  124.             else{
  125.                 throw new ServiceException("Model ["+model.toString()+"] not supported by getKeyGeneratorObject: "+this.getClass().getName());
  126.             }

  127.         }catch(Exception e){
  128.             throw new ServiceException("Model ["+model.toString()+"] occurs error in getKeyGeneratorObject: "+e.getMessage(),e);
  129.         }
  130.        
  131.     }

  132. }