PortaDelegataFieldConverter.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.converter;

  21. import org.openspcoop2.generic_project.beans.IField;
  22. import org.openspcoop2.generic_project.beans.IModel;
  23. import org.openspcoop2.generic_project.exception.ExpressionException;
  24. import org.openspcoop2.generic_project.expression.impl.sql.AbstractSQLFieldConverter;
  25. import org.openspcoop2.utils.TipiDatabase;

  26. import org.openspcoop2.core.commons.search.PortaDelegata;
  27. import org.openspcoop2.core.constants.CostantiDB;


  28. /**    
  29.  * PortaDelegataFieldConverter
  30.  *
  31.  * @author Poli Andrea (poli@link.it)
  32.  * @author $Author$
  33.  * @version $Rev$, $Date$
  34.  */
  35. public class PortaDelegataFieldConverter extends AbstractSQLFieldConverter {

  36.     private TipiDatabase databaseType;
  37.    
  38.     public PortaDelegataFieldConverter(String databaseType){
  39.         this.databaseType = TipiDatabase.toEnumConstant(databaseType);
  40.     }
  41.     public PortaDelegataFieldConverter(TipiDatabase databaseType){
  42.         this.databaseType = databaseType;
  43.     }


  44.     @Override
  45.     public IModel<?> getRootModel() throws ExpressionException {
  46.         return PortaDelegata.model();
  47.     }
  48.    
  49.     @Override
  50.     public TipiDatabase getDatabaseType() throws ExpressionException {
  51.         return this.databaseType;
  52.     }
  53.    


  54.     @Override
  55.     public String toColumn(IField field,boolean returnAlias,boolean appendTablePrefix) throws ExpressionException {
  56.        
  57.         // In the case of columns with alias, using parameter returnAlias​​,
  58.         // it is possible to drive the choice whether to return only the alias or
  59.         // the full definition of the column containing the alias
  60.        
  61.         if(field.equals(PortaDelegata.model().NOME)){
  62.             if(appendTablePrefix){
  63.                 return this.toAliasTable(field)+".nome_porta";
  64.             }else{
  65.                 return "nome_porta";
  66.             }
  67.         }
  68.         if(field.equals(PortaDelegata.model().STATO)){
  69.             if(appendTablePrefix){
  70.                 return this.toAliasTable(field)+".stato";
  71.             }else{
  72.                 return "stato";
  73.             }
  74.         }
  75.         if(field.equals(PortaDelegata.model().ID_SOGGETTO.TIPO)){
  76.             if(appendTablePrefix){
  77.                 return this.toAliasTable(field)+".tipo_soggetto";
  78.             }else{
  79.                 return "tipo_soggetto";
  80.             }
  81.         }
  82.         if(field.equals(PortaDelegata.model().ID_SOGGETTO.NOME)){
  83.             if(appendTablePrefix){
  84.                 return this.toAliasTable(field)+".nome_soggetto";
  85.             }else{
  86.                 return "nome_soggetto";
  87.             }
  88.         }
  89.         if(field.equals(PortaDelegata.model().TIPO_SOGGETTO_EROGATORE)){
  90.             if(appendTablePrefix){
  91.                 return this.toAliasTable(field)+".tipo_soggetto_erogatore";
  92.             }else{
  93.                 return "tipo_soggetto_erogatore";
  94.             }
  95.         }
  96.         if(field.equals(PortaDelegata.model().NOME_SOGGETTO_EROGATORE)){
  97.             if(appendTablePrefix){
  98.                 return this.toAliasTable(field)+".nome_soggetto_erogatore";
  99.             }else{
  100.                 return "nome_soggetto_erogatore";
  101.             }
  102.         }
  103.         if(field.equals(PortaDelegata.model().TIPO_SERVIZIO)){
  104.             if(appendTablePrefix){
  105.                 return this.toAliasTable(field)+".tipo_servizio";
  106.             }else{
  107.                 return "tipo_servizio";
  108.             }
  109.         }
  110.         if(field.equals(PortaDelegata.model().NOME_SERVIZIO)){
  111.             if(appendTablePrefix){
  112.                 return this.toAliasTable(field)+".nome_servizio";
  113.             }else{
  114.                 return "nome_servizio";
  115.             }
  116.         }
  117.         if(field.equals(PortaDelegata.model().VERSIONE_SERVIZIO)){
  118.             if(appendTablePrefix){
  119.                 return this.toAliasTable(field)+".versione_servizio";
  120.             }else{
  121.                 return "versione_servizio";
  122.             }
  123.         }
  124.         if(field.equals(PortaDelegata.model().MODE_AZIONE)){
  125.             if(appendTablePrefix){
  126.                 return this.toAliasTable(field)+".mode_azione";
  127.             }else{
  128.                 return "mode_azione";
  129.             }
  130.         }
  131.         if(field.equals(PortaDelegata.model().NOME_AZIONE)){
  132.             if(appendTablePrefix){
  133.                 return this.toAliasTable(field)+".nome_azione";
  134.             }else{
  135.                 return "nome_azione";
  136.             }
  137.         }
  138.         if(field.equals(PortaDelegata.model().NOME_PORTA_DELEGANTE_AZIONE)){
  139.             if(appendTablePrefix){
  140.                 return this.toAliasTable(field)+".nome_porta_delegante_azione";
  141.             }else{
  142.                 return "nome_porta_delegante_azione";
  143.             }
  144.         }
  145.         if(field.equals(PortaDelegata.model().CANALE)){
  146.             if(appendTablePrefix){
  147.                 return this.toAliasTable(field)+".canale";
  148.             }else{
  149.                 return "canale";
  150.             }
  151.         }
  152.         if(field.equals(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO.NOME)){
  153.             if(appendTablePrefix){
  154.                 return this.toAliasTable(field)+".nome";
  155.             }else{
  156.                 return "nome";
  157.             }
  158.         }
  159.         if(field.equals(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO.ID_SOGGETTO.TIPO)){
  160.             if(appendTablePrefix){
  161.                 return this.toAliasTable(field)+".tipo_soggetto";
  162.             }else{
  163.                 return "tipo_soggetto";
  164.             }
  165.         }
  166.         if(field.equals(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO.ID_SOGGETTO.NOME)){
  167.             if(appendTablePrefix){
  168.                 return this.toAliasTable(field)+".nome_soggetto";
  169.             }else{
  170.                 return "nome_soggetto";
  171.             }
  172.         }
  173.         if(field.equals(PortaDelegata.model().PORTA_DELEGATA_AZIONE.NOME)){
  174.             if(appendTablePrefix){
  175.                 return this.toAliasTable(field)+".azione";
  176.             }else{
  177.                 return "azione";
  178.             }
  179.         }


  180.         return super.toColumn(field,returnAlias,appendTablePrefix);
  181.        
  182.     }
  183.    
  184.     @Override
  185.     public String toTable(IField field,boolean returnAlias) throws ExpressionException {
  186.        
  187.         // In the case of table with alias, using parameter returnAlias​​,
  188.         // it is possible to drive the choice whether to return only the alias or
  189.         // the full definition of the table containing the alias
  190.        
  191.         if(field.equals(PortaDelegata.model().NOME)){
  192.             return this.toTable(PortaDelegata.model(), returnAlias);
  193.         }
  194.         if(field.equals(PortaDelegata.model().STATO)){
  195.             return this.toTable(PortaDelegata.model(), returnAlias);
  196.         }
  197.         if(field.equals(PortaDelegata.model().ID_SOGGETTO.TIPO)){
  198.             return this.toTable(PortaDelegata.model().ID_SOGGETTO, returnAlias);
  199.         }
  200.         if(field.equals(PortaDelegata.model().ID_SOGGETTO.NOME)){
  201.             return this.toTable(PortaDelegata.model().ID_SOGGETTO, returnAlias);
  202.         }
  203.         if(field.equals(PortaDelegata.model().TIPO_SOGGETTO_EROGATORE)){
  204.             return this.toTable(PortaDelegata.model(), returnAlias);
  205.         }
  206.         if(field.equals(PortaDelegata.model().NOME_SOGGETTO_EROGATORE)){
  207.             return this.toTable(PortaDelegata.model(), returnAlias);
  208.         }
  209.         if(field.equals(PortaDelegata.model().TIPO_SERVIZIO)){
  210.             return this.toTable(PortaDelegata.model(), returnAlias);
  211.         }
  212.         if(field.equals(PortaDelegata.model().NOME_SERVIZIO)){
  213.             return this.toTable(PortaDelegata.model(), returnAlias);
  214.         }
  215.         if(field.equals(PortaDelegata.model().VERSIONE_SERVIZIO)){
  216.             return this.toTable(PortaDelegata.model(), returnAlias);
  217.         }
  218.         if(field.equals(PortaDelegata.model().MODE_AZIONE)){
  219.             return this.toTable(PortaDelegata.model(), returnAlias);
  220.         }
  221.         if(field.equals(PortaDelegata.model().NOME_AZIONE)){
  222.             return this.toTable(PortaDelegata.model(), returnAlias);
  223.         }
  224.         if(field.equals(PortaDelegata.model().NOME_PORTA_DELEGANTE_AZIONE)){
  225.             return this.toTable(PortaDelegata.model(), returnAlias);
  226.         }
  227.         if(field.equals(PortaDelegata.model().CANALE)){
  228.             return this.toTable(PortaDelegata.model(), returnAlias);
  229.         }
  230.         if(field.equals(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO.NOME)){
  231.             return this.toTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO, returnAlias);
  232.         }
  233.         if(field.equals(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO.ID_SOGGETTO.TIPO)){
  234.             return this.toTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO.ID_SOGGETTO, returnAlias);
  235.         }
  236.         if(field.equals(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO.ID_SOGGETTO.NOME)){
  237.             return this.toTable(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO.ID_SOGGETTO, returnAlias);
  238.         }
  239.         if(field.equals(PortaDelegata.model().PORTA_DELEGATA_AZIONE.NOME)){
  240.             return this.toTable(PortaDelegata.model().PORTA_DELEGATA_AZIONE, returnAlias);
  241.         }


  242.         return super.toTable(field,returnAlias);
  243.        
  244.     }

  245.     @Override
  246.     public String toTable(IModel<?> model,boolean returnAlias) throws ExpressionException {
  247.        
  248.         // In the case of table with alias, using parameter returnAlias​​,
  249.         // it is possible to drive the choice whether to return only the alias or
  250.         // the full definition of the table containing the alias
  251.        
  252.         if(model.equals(PortaDelegata.model())){
  253.             return CostantiDB.PORTE_DELEGATE;
  254.         }
  255.         if(model.equals(PortaDelegata.model().ID_SOGGETTO)){
  256.             return CostantiDB.SOGGETTI;
  257.         }
  258.         if(model.equals(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO)){
  259.             return CostantiDB.PORTE_DELEGATE_SA;
  260.         }
  261.         if(model.equals(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO)){
  262.             return CostantiDB.SERVIZI_APPLICATIVI;
  263.         }
  264.         if(model.equals(PortaDelegata.model().PORTA_DELEGATA_SERVIZIO_APPLICATIVO.ID_SERVIZIO_APPLICATIVO.ID_SOGGETTO)){
  265.             return CostantiDB.SOGGETTI;
  266.         }
  267.         if(model.equals(PortaDelegata.model().PORTA_DELEGATA_AZIONE)){
  268.             return CostantiDB.PORTE_DELEGATE_AZIONI;
  269.         }


  270.         return super.toTable(model,returnAlias);
  271.        
  272.     }

  273. }