FilterStatisticRepositoryImpl.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.monitor.engine.condition;

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

  23. import org.openspcoop2.core.statistiche.StatisticaGiornaliera;
  24. import org.openspcoop2.core.statistiche.StatisticaMensile;
  25. import org.openspcoop2.core.statistiche.StatisticaOraria;
  26. import org.openspcoop2.core.statistiche.StatisticaSettimanale;
  27. import org.openspcoop2.core.statistiche.dao.jdbc.converter.StatisticaGiornalieraFieldConverter;
  28. import org.openspcoop2.core.statistiche.dao.jdbc.converter.StatisticaMensileFieldConverter;
  29. import org.openspcoop2.core.statistiche.dao.jdbc.converter.StatisticaOrariaFieldConverter;
  30. import org.openspcoop2.core.statistiche.dao.jdbc.converter.StatisticaSettimanaleFieldConverter;
  31. import org.openspcoop2.core.statistiche.model.StatisticaContenutiModel;
  32. import org.openspcoop2.core.statistiche.model.StatisticaModel;
  33. import org.openspcoop2.generic_project.beans.AliasTableComplexField;
  34. import org.openspcoop2.generic_project.beans.ComplexField;
  35. import org.openspcoop2.generic_project.beans.IAliasTableField;
  36. import org.openspcoop2.generic_project.beans.IField;
  37. import org.openspcoop2.generic_project.dao.jdbc.JDBCExpression;
  38. import org.openspcoop2.generic_project.expression.IExpression;
  39. import org.openspcoop2.generic_project.expression.impl.sql.ISQLFieldConverter;
  40. import org.openspcoop2.core.plugins.utils.FilterUtils;
  41. import org.openspcoop2.monitor.sdk.condition.IStatisticFilter;
  42. import org.openspcoop2.monitor.sdk.constants.StatisticType;
  43. import org.openspcoop2.monitor.sdk.exceptions.SearchException;
  44. import org.openspcoop2.monitor.sdk.statistic.StatisticFilterName;
  45. import org.openspcoop2.utils.TipiDatabase;

  46. /**
  47.  * FilterStatisticRepositoryImpl
  48.  *
  49.  * @author Poli Andrea (apoli@link.it)
  50.  * @author $Author$
  51.  * @version $Rev$, $Date$
  52.  */
  53. public class FilterStatisticRepositoryImpl extends FilterImpl {

  54.     private StatisticType statisticType;
  55.     @SuppressWarnings("unused")
  56.     private StatisticaModel model;
  57.     private StatisticaContenutiModel contenutiModel;
  58.    
  59.     public FilterStatisticRepositoryImpl(TipiDatabase databaseType,StatisticType statisticType) throws SearchException {
  60.         super(newExpression(databaseType,statisticType),databaseType,newFieldConverter(databaseType,statisticType));
  61.         this.statisticType = statisticType;
  62.         switch (this.statisticType) {
  63.         case ORARIA:
  64.             this.model = StatisticaOraria.model().STATISTICA_BASE;
  65.             this.contenutiModel = StatisticaOraria.model().STATISTICA_ORARIA_CONTENUTI;
  66.             break;
  67.         case GIORNALIERA:
  68.             this.model = StatisticaGiornaliera.model().STATISTICA_BASE;
  69.             this.contenutiModel = StatisticaGiornaliera.model().STATISTICA_GIORNALIERA_CONTENUTI;
  70.             break;
  71.         case SETTIMANALE:
  72.             this.model = StatisticaSettimanale.model().STATISTICA_BASE;
  73.             this.contenutiModel = StatisticaSettimanale.model().STATISTICA_SETTIMANALE_CONTENUTI;
  74.             break;
  75.         case MENSILE:
  76.             this.model = StatisticaMensile.model().STATISTICA_BASE;
  77.             this.contenutiModel = StatisticaMensile.model().STATISTICA_MENSILE_CONTENUTI;
  78.             break;
  79.         }
  80.     }
  81.    
  82.    
  83.    
  84.    
  85.     private static IExpression newExpression(TipiDatabase databaseType, StatisticType statisticType) throws SearchException{
  86.         try{
  87.             return new JDBCExpression(newFieldConverter(databaseType,statisticType));
  88.         }catch(Exception e){
  89.             throw new SearchException(e.getMessage(),e);
  90.         }
  91.     }
  92.     private static ISQLFieldConverter newFieldConverter(TipiDatabase databaseType, StatisticType statisticType) throws SearchException{
  93.         switch (statisticType) {
  94.         case ORARIA:
  95.             return new StatisticaOrariaFieldConverter(databaseType);
  96.         case GIORNALIERA:
  97.             return new StatisticaGiornalieraFieldConverter(databaseType);
  98.         case SETTIMANALE:
  99.             return new StatisticaSettimanaleFieldConverter(databaseType);
  100.         case MENSILE:
  101.             return new StatisticaMensileFieldConverter(databaseType);
  102.         }
  103.         throw new SearchException("StatisticType["+statisticType+"] unknown");
  104.     }

  105.    
  106.     @Override
  107.     protected IStatisticFilter newIFilter() throws SearchException{
  108.         try{
  109.             return new FilterStatisticRepositoryImpl(this.databaseType,this.statisticType);
  110.         }catch(Exception e){
  111.             throw new SearchException(e.getMessage(),e);
  112.         }
  113.     }
  114.    
  115.     @Override
  116.     protected IExpression newIExpression() throws SearchException{
  117.         try{
  118.             return newExpression(this.databaseType,this.statisticType);
  119.         }catch(Exception e){
  120.             throw new SearchException(e.getMessage(),e);
  121.         }
  122.     }
  123.    
  124.     @Override
  125.     protected IField getIFieldForMessageType() throws SearchException{
  126.         // tipizzazione non supportata nella statistica
  127.         return null;
  128.     }
  129.    
  130.     @Override
  131.     protected List<IField> getIFieldForResourceName(StatisticFilterName statisticFilter) throws SearchException{
  132.         try{
  133.             List<IField> l = new ArrayList<IField>();
  134.             if(statisticFilter==null){
  135.                 l.add(new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_NOME_1, FilterUtils.getNextAliasStatisticsTable()));
  136.                 l.add(new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_NOME_2, FilterUtils.getNextAliasStatisticsTable()));
  137.                 l.add(new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_NOME_3, FilterUtils.getNextAliasStatisticsTable()));
  138.                 l.add(new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_NOME_4, FilterUtils.getNextAliasStatisticsTable()));
  139.                 l.add(new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_NOME_5, FilterUtils.getNextAliasStatisticsTable()));
  140.                 l.add(new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_NOME_6, FilterUtils.getNextAliasStatisticsTable()));
  141.                 l.add(new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_NOME_7, FilterUtils.getNextAliasStatisticsTable()));
  142.                 l.add(new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_NOME_8, FilterUtils.getNextAliasStatisticsTable()));
  143.                 l.add(new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_NOME_9, FilterUtils.getNextAliasStatisticsTable()));
  144.                 l.add(new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_NOME_10, FilterUtils.getNextAliasStatisticsTable()));
  145.             }
  146.             else{
  147.                 switch (statisticFilter) {
  148.                 case FILTER_1:
  149.                     l.add(this.contenutiModel.FILTRO_NOME_1);
  150.                     break;
  151.                 case FILTER_2:
  152.                     l.add(this.contenutiModel.FILTRO_NOME_2);
  153.                     break;
  154.                 case FILTER_3:
  155.                     l.add(this.contenutiModel.FILTRO_NOME_3);
  156.                     break;
  157.                 case FILTER_4:
  158.                     l.add(this.contenutiModel.FILTRO_NOME_4);
  159.                     break;
  160.                 case FILTER_5:
  161.                     l.add(this.contenutiModel.FILTRO_NOME_5);
  162.                     break;
  163.                 case FILTER_6:
  164.                     l.add(this.contenutiModel.FILTRO_NOME_6);
  165.                     break;
  166.                 case FILTER_7:
  167.                     l.add(this.contenutiModel.FILTRO_NOME_7);
  168.                     break;
  169.                 case FILTER_8:
  170.                     l.add(this.contenutiModel.FILTRO_NOME_8);
  171.                     break;
  172.                 case FILTER_9:
  173.                     l.add(this.contenutiModel.FILTRO_NOME_9);
  174.                     break;
  175.                 case FILTER_10:
  176.                     l.add(this.contenutiModel.FILTRO_NOME_10);
  177.                     break;
  178.                 }
  179.             }
  180.             return l;
  181.         }catch(Exception e){
  182.             throw new SearchException(e.getMessage(),e);
  183.         }
  184.     }
  185.    
  186.     @Override
  187.     protected IField getIFieldForResourceValue(IField fieldResourceName) throws SearchException{
  188.         try{
  189.             String aliasTable = null;
  190.             if( fieldResourceName instanceof IAliasTableField ){
  191.                 IAliasTableField af = (IAliasTableField) fieldResourceName;
  192.                 aliasTable = af.getAliasTable();
  193.             }
  194.            
  195.             if(this.contenutiModel.FILTRO_NOME_1.equals(fieldResourceName)){
  196.                 if(aliasTable!=null)
  197.                     return new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_VALORE_1, aliasTable);
  198.                 else
  199.                     return this.contenutiModel.FILTRO_VALORE_1;
  200.             }
  201.             else if(this.contenutiModel.FILTRO_NOME_2.equals(fieldResourceName)){
  202.                 if(aliasTable!=null)
  203.                     return new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_VALORE_2, aliasTable);
  204.                 else
  205.                     return this.contenutiModel.FILTRO_VALORE_2;
  206.             }
  207.             else if(this.contenutiModel.FILTRO_NOME_3.equals(fieldResourceName)){
  208.                 if(aliasTable!=null)
  209.                     return new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_VALORE_3, aliasTable);
  210.                 else
  211.                     return this.contenutiModel.FILTRO_VALORE_3;
  212.             }
  213.             else if(this.contenutiModel.FILTRO_NOME_4.equals(fieldResourceName)){
  214.                 if(aliasTable!=null)
  215.                     return new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_VALORE_4, aliasTable);
  216.                 else
  217.                     return this.contenutiModel.FILTRO_VALORE_4;
  218.             }
  219.             else if(this.contenutiModel.FILTRO_NOME_5.equals(fieldResourceName)){
  220.                 if(aliasTable!=null)
  221.                     return new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_VALORE_5, aliasTable);
  222.                 else
  223.                     return this.contenutiModel.FILTRO_VALORE_5;
  224.             }
  225.             else if(this.contenutiModel.FILTRO_NOME_6.equals(fieldResourceName)){
  226.                 if(aliasTable!=null)
  227.                     return new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_VALORE_6, aliasTable);
  228.                 else
  229.                     return this.contenutiModel.FILTRO_VALORE_6;
  230.             }
  231.             else if(this.contenutiModel.FILTRO_NOME_7.equals(fieldResourceName)){
  232.                 if(aliasTable!=null)
  233.                     return new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_VALORE_7, aliasTable);
  234.                 else
  235.                     return this.contenutiModel.FILTRO_VALORE_7;
  236.             }
  237.             else if(this.contenutiModel.FILTRO_NOME_8.equals(fieldResourceName)){
  238.                 if(aliasTable!=null)
  239.                     return new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_VALORE_8, aliasTable);
  240.                 else
  241.                     return this.contenutiModel.FILTRO_VALORE_8;
  242.             }
  243.             else if(this.contenutiModel.FILTRO_NOME_9.equals(fieldResourceName)){
  244.                 if(aliasTable!=null)
  245.                     return new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_VALORE_9, aliasTable);
  246.                 else
  247.                     return this.contenutiModel.FILTRO_VALORE_9;
  248.             }
  249.             else if(this.contenutiModel.FILTRO_NOME_10.equals(fieldResourceName)){
  250.                 if(aliasTable!=null)
  251.                     return new AliasTableComplexField((ComplexField)this.contenutiModel.FILTRO_VALORE_10, aliasTable);
  252.                 else
  253.                     return this.contenutiModel.FILTRO_VALORE_10;
  254.             }
  255.             throw new Exception("Unknown field: "+fieldResourceName);
  256.         }catch(Exception e){
  257.             throw new SearchException(e.getMessage(),e);
  258.         }
  259.     }
  260.    

  261. }