FilterImpl.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 org.openspcoop2.monitor.engine.utils.ContentFormatter;
  22. import org.openspcoop2.monitor.sdk.condition.IFilter;
  23. import org.openspcoop2.monitor.sdk.condition.IStatisticFilter;
  24. import org.openspcoop2.monitor.sdk.constants.LikeMode;
  25. import org.openspcoop2.monitor.sdk.constants.MessageType;
  26. import org.openspcoop2.monitor.sdk.exceptions.SearchException;
  27. import org.openspcoop2.monitor.sdk.statistic.StatisticFilterName;
  28. import org.openspcoop2.monitor.sdk.statistic.StatisticResourceFilter;
  29. import org.openspcoop2.monitor.sdk.statistic.StatisticFilter;

  30. import java.util.ArrayList;
  31. import java.util.Collection;
  32. import java.util.Iterator;
  33. import java.util.List;
  34. import java.util.Map;

  35. import org.slf4j.Logger;
  36. import org.openspcoop2.generic_project.beans.IField;
  37. import org.openspcoop2.generic_project.exception.ExpressionException;
  38. import org.openspcoop2.generic_project.exception.ExpressionNotImplementedException;
  39. import org.openspcoop2.generic_project.expression.IExpression;
  40. import org.openspcoop2.generic_project.expression.impl.sql.ISQLFieldConverter;
  41. import org.openspcoop2.utils.LoggerWrapperFactory;
  42. import org.openspcoop2.utils.TipiDatabase;


  43. /**
  44.  * FilterImpl
  45.  *
  46.  * @author Poli Andrea (apoli@link.it)
  47.  * @author $Author$
  48.  * @version $Rev$, $Date$
  49.  */
  50. public abstract class FilterImpl implements IStatisticFilter {
  51.    

  52.     protected IExpression expression;
  53.     protected TipiDatabase databaseType;
  54.     protected ISQLFieldConverter fieldConverter;
  55.     private String idStatistic;
  56.     protected FilterImpl(IExpression expression,TipiDatabase databaseType, ISQLFieldConverter fieldConverter) {
  57.         this.expression = expression;
  58.         this.databaseType = databaseType;
  59.         this.fieldConverter = fieldConverter;
  60.     }
  61.     public IExpression getExpression() {
  62.         return this.expression;
  63.     }
  64.    
  65.     protected static Logger logger = LoggerWrapperFactory.getLogger(FilterImpl.class);
  66.    
  67.    
  68.    
  69.     /* ************ UTILS *********** */
  70.    
  71.     protected abstract IStatisticFilter newIFilter() throws SearchException;
  72.    
  73.     protected abstract IExpression newIExpression() throws SearchException;
  74.    
  75.     protected abstract IField getIFieldForMessageType() throws SearchException;
  76.    
  77.     protected abstract List<IField> getIFieldForResourceName(StatisticFilterName statisticFilter) throws SearchException;

  78.     protected abstract IField getIFieldForResourceValue(IField fieldResourceName) throws SearchException;
  79.    
  80.     private void check(StatisticResourceFilter resourceStatID) throws SearchException{
  81.         if(resourceStatID.getStatisticFilterName()==null){
  82.             throw new SearchException("Required StatisticFilterName undefined");
  83.         }
  84.         if(resourceStatID.getResourceID()==null){
  85.             throw new SearchException("Required ResourceID undefined");
  86.         }
  87.     }
  88.     private void check(StatisticFilter resource) throws SearchException{
  89.         if(resource.getStatisticFilterName()==null){
  90.             throw new SearchException("Required StatisticFilterName undefined");
  91.         }
  92.         if(resource.getResourceID()==null){
  93.             throw new SearchException("Required ResourceID undefined");
  94.         }
  95.         if(resource.getValue()==null){
  96.             throw new SearchException("Required Value undefined");
  97.         }
  98.     }
  99.    
  100.    
  101.     /* ************ ID STATISTICA *********** */
  102.    
  103.     /**
  104.      * Return optional statistic id
  105.      *
  106.      * @return statistic id
  107.      */
  108.     public String getIdStatistic() {
  109.         return this.idStatistic;
  110.     }
  111.     @Override
  112.     public void setIdStatistic(String idStatistic) {
  113.         this.idStatistic = idStatistic;
  114.     }
  115.    
  116.    
  117.    
  118.    
  119.     /* ************ STATE OF EXPRESSION *********** */
  120.    
  121.     /**
  122.      * Make the negation of the expression
  123.      *
  124.      * @return the instance of itself
  125.      * @throws ExpressionNotImplementedException Method not implemented
  126.      * @throws ExpressionException Error Processing
  127.      */
  128.     @Override
  129.     public IStatisticFilter not() throws SearchException{
  130.         try{
  131.             this.expression.not();
  132.             return this;
  133.         }catch(Exception e){
  134.             throw new SearchException(e.getMessage(),e);
  135.         }
  136.     }
  137.    
  138.     /**
  139.      * Use the conjunction "AND" for all expressions
  140.      *
  141.      * @return the instance of itself
  142.      * @throws ExpressionNotImplementedException Method not implemented
  143.      * @throws ExpressionException Error Processing
  144.      */
  145.     @Override
  146.     public IStatisticFilter and() throws SearchException{
  147.         try{
  148.             this.expression.and();
  149.             return this;
  150.         }catch(Exception e){
  151.             throw new SearchException(e.getMessage(),e);
  152.         }
  153.     }

  154.     /**
  155.      * Use the conjunction "OR" for all expressions
  156.      *
  157.      * @return the instance of itself
  158.      * @throws ExpressionNotImplementedException Method not implemented
  159.      * @throws ExpressionException Error Processing
  160.      */
  161.     @Override
  162.     public IStatisticFilter or() throws SearchException{
  163.         try{
  164.             this.expression.or();
  165.             return this;
  166.         }catch(Exception e){
  167.             throw new SearchException(e.getMessage(),e);
  168.         }
  169.     }
  170.    
  171.    
  172.    
  173.    
  174.    
  175.     /* ************ COMPARATOR *********** */
  176.    
  177.     /**
  178.      * Create an expression of equality
  179.      * Example:  (field = value)
  180.      *
  181.      * @param resourceID Resource identifier
  182.      * @param value Value
  183.      * @return the instance of itself enriched with expression that represents the constraint
  184.      * @throws SearchException
  185.      */
  186.     @Override
  187.     public IFilter equals(String resourceID, Object value) throws SearchException{
  188.         return this._equals(null, resourceID, value);
  189.     }
  190.     @Override
  191.     public IStatisticFilter equals(StatisticResourceFilter resourceID, Object value) throws SearchException{
  192.         return this._equals(resourceID, null, value);
  193.     }
  194.     private IStatisticFilter _equals(StatisticResourceFilter resourceStatID, String resourceID, Object value) throws SearchException{
  195.         try{    
  196.             StatisticFilterName statisticFilter = null;
  197.             if(resourceStatID!=null){
  198.                 this.check(resourceStatID);
  199.                 statisticFilter = resourceStatID.getStatisticFilterName();
  200.                 resourceID = resourceStatID.getResourceID();
  201.             }
  202.             List<IField> fieldsResourceName = this.getIFieldForResourceName(statisticFilter);
  203.             if(fieldsResourceName.size()==1){
  204.                 IExpression expr = this.newIExpression();
  205.                 expr.and();
  206.                 IField fieldResourceName = fieldsResourceName.get(0);
  207.                 expr.equals(fieldResourceName, resourceID);
  208.                 expr.equals(this.getIFieldForResourceValue(fieldResourceName), ContentFormatter.toString(value));
  209.                 this.expression.and(expr);
  210.             }
  211.             else{
  212.                 IExpression exprEsterna = this.newIExpression();
  213.                 exprEsterna.or();
  214.                 for (IField fieldResourceName : fieldsResourceName) {
  215.                     IExpression expr = this.newIExpression();
  216.                     expr.and();
  217.                     expr.equals(fieldResourceName, resourceID);
  218.                     expr.equals(this.getIFieldForResourceValue(fieldResourceName), ContentFormatter.toString(value));
  219.                     exprEsterna.or(expr);
  220.                 }
  221.                 this.expression.and(exprEsterna);
  222.             }
  223.             return this;
  224.         }catch(Exception e){
  225.             throw new SearchException(e.getMessage(),e);
  226.         }
  227.     }

  228.     /**
  229.      * Create an expression of inequality
  230.      * Example:  (field <> value)
  231.      *
  232.      * @param resourceID Resource identifier
  233.      * @param value Value
  234.      * @return the instance of itself enriched with expression that represents the constraint
  235.      * @throws SearchException
  236.      */
  237.     @Override
  238.     public IFilter notEquals(String resourceID, Object value) throws SearchException{
  239.         return this._notEquals(null, resourceID, value);
  240.     }
  241.     @Override
  242.     public IStatisticFilter notEquals(StatisticResourceFilter resourceID, Object value) throws SearchException{
  243.         return this._notEquals(resourceID, null, value);
  244.     }
  245.     private IStatisticFilter _notEquals(StatisticResourceFilter resourceStatID, String resourceID, Object value) throws SearchException{
  246.         try{
  247.             StatisticFilterName statisticFilter = null;
  248.             if(resourceStatID!=null){
  249.                 this.check(resourceStatID);
  250.                 statisticFilter = resourceStatID.getStatisticFilterName();
  251.                 resourceID = resourceStatID.getResourceID();
  252.             }
  253.             List<IField> fieldsResourceName = this.getIFieldForResourceName(statisticFilter);
  254.             if(fieldsResourceName.size()==1){
  255.                 IExpression expr = this.newIExpression();
  256.                 expr.and();
  257.                 IField fieldResourceName = fieldsResourceName.get(0);
  258.                 expr.equals(fieldResourceName, resourceID);
  259.                 expr.notEquals(this.getIFieldForResourceValue(fieldResourceName), ContentFormatter.toString(value));
  260.                 this.expression.and(expr);
  261.             }
  262.             else{
  263.                 IExpression exprEsterna = this.newIExpression();
  264.                 exprEsterna.or();
  265.                 for (IField fieldResourceName : fieldsResourceName) {
  266.                     IExpression expr = this.newIExpression();
  267.                     expr.and();
  268.                     expr.equals(fieldResourceName, resourceID);
  269.                     expr.notEquals(this.getIFieldForResourceValue(fieldResourceName), ContentFormatter.toString(value));
  270.                     exprEsterna.or(expr);
  271.                 }
  272.                 this.expression.and(exprEsterna);
  273.             }
  274.             return this;
  275.         }catch(Exception e){
  276.             throw new SearchException(e.getMessage(),e);
  277.         }
  278.     }

  279.     /**
  280.      * Create an expression of equality to each resource in the collection of the keys of the Map
  281.      * Use the conjunction "AND" for all expressions
  282.      * Example:  ( field[0]=values[0] AND field[1]=values[1] ..... AND field[N]=values[N] )
  283.      *
  284.      * @param propertyNameValues Map that contains identifiers and their values
  285.      * @return the instance of itself enriched with expression that represents the constraint
  286.      * @throws SearchException
  287.      */
  288.     @Override
  289.     public IFilter allEquals(Map<String, Object> propertyNameValues) throws SearchException{
  290.         return this.allEquals(propertyNameValues, true);
  291.     }
  292.     @Override
  293.     public IStatisticFilter allEquals(List<StatisticFilter> propertyNameValues) throws SearchException{
  294.         return this.allEquals(propertyNameValues, true);
  295.     }

  296.     /**
  297.      * Create an expression of inequality to each resource in the collection of the keys of the Map
  298.      * Use the conjunction "AND" for all expressions
  299.      * Example:  ( field[0]<>values[0] AND field[1]<>values[1] ..... AND field[N]<>values[N] )
  300.      *
  301.      * @param propertyNameValues Map that contains identifiers and their values
  302.      * @return the instance of itself enriched with expression that represents the constraint
  303.      * @throws SearchException
  304.      */
  305.     @Override
  306.     public IFilter allNotEquals(Map<String, Object> propertyNameValues)
  307.     throws SearchException{
  308.         return this.allNotEquals(propertyNameValues, true);
  309.     }
  310.     @Override
  311.     public IStatisticFilter allNotEquals(List<StatisticFilter> propertyNameValues)
  312.     throws SearchException{
  313.         return this.allEquals(propertyNameValues, true);
  314.     }
  315.    
  316.     /**
  317.      * Create an expression of equality to each resource in the collection of the keys of the Map
  318.      * Use the conjunction defined by <var>andConjunction</var> for all expressions
  319.      * Example:  ( field[0]=values[0] <var>andConjunction</var> field[1]=values[1] ..... <var>andConjunction</var> field[N]=values[N] )
  320.      *
  321.      * @param propertyNameValues Map that contains identifiers and their values
  322.      * @return the instance of itself enriched with expression that represents the constraint
  323.      * @throws SearchException
  324.      */
  325.     @Override
  326.     public IFilter allEquals(Map<String, Object> propertyNameValues,boolean andConjunction) throws SearchException{
  327.         try{
  328.             if(propertyNameValues.size()>0){
  329.                 IExpression exprAll = this.newIExpression();
  330.                 if(andConjunction)
  331.                     exprAll.and();
  332.                 else
  333.                     exprAll.or();
  334.                 Iterator<String> keys = propertyNameValues.keySet().iterator();
  335.                 while (keys.hasNext()) {
  336.                     String resourceID = (String) keys.next();
  337.                     Object value = propertyNameValues.get(resourceID);
  338.                     FilterImpl f = (FilterImpl) this.newFilter();
  339.                     f.equals(resourceID, value);
  340.                     exprAll.and(f.getExpression());
  341.                 }
  342.                 this.expression.and(exprAll);
  343.             }
  344.             return this;
  345.         }catch(Exception e){
  346.             throw new SearchException(e.getMessage(),e);
  347.         }
  348.     }
  349.     @Override
  350.     public IStatisticFilter allEquals(List<StatisticFilter> propertyNameValues,boolean andConjunction) throws SearchException{
  351.         try{
  352.             if(propertyNameValues.size()>0){
  353.                 IExpression exprAll = this.newIExpression();
  354.                 if(andConjunction)
  355.                     exprAll.and();
  356.                 else
  357.                     exprAll.or();
  358.                 for (StatisticFilter statisticsFilter : propertyNameValues) {
  359.                     this.check(statisticsFilter);
  360.                     FilterImpl f = (FilterImpl) this.newFilter();
  361.                     StatisticResourceFilter sf = new StatisticResourceFilter();
  362.                     sf.setResourceID(statisticsFilter.getResourceID());
  363.                     sf.setStatisticFilterName(statisticsFilter.getStatisticFilterName());
  364.                     f.equals(sf, statisticsFilter.getValue());
  365.                     exprAll.and(f.getExpression());
  366.                 }
  367.                 this.expression.and(exprAll);
  368.             }
  369.             return this;
  370.         }catch(Exception e){
  371.             throw new SearchException(e.getMessage(),e);
  372.         }
  373.     }

  374.     /**
  375.      * Create an expression of inequality to each resource in the collection of the keys of the Map
  376.      * Use the conjunction defined by <var>andConjunction</var> for all expressions
  377.      * Example:  ( field[0]<>values[0] <var>andConjunction</var> field[1]<>values[1] ..... <var>andConjunction</var> field[N]<>values[N] )
  378.      *
  379.      * @param propertyNameValues Map that contains identifiers and their values
  380.      * @return the instance of itself enriched with expression that represents the constraint
  381.      * @throws SearchException
  382.      */
  383.     @Override
  384.     public IFilter allNotEquals(Map<String, Object> propertyNameValues,boolean andConjunction)
  385.     throws SearchException{
  386.         try{
  387.             if(propertyNameValues.size()>0){
  388.                 IExpression exprAll = this.newIExpression();
  389.                 if(andConjunction)
  390.                     exprAll.and();
  391.                 else
  392.                     exprAll.or();
  393.                 Iterator<String> keys = propertyNameValues.keySet().iterator();
  394.                 while (keys.hasNext()) {
  395.                     String resourceID = (String) keys.next();
  396.                     Object value = propertyNameValues.get(resourceID);
  397.                     FilterImpl f = (FilterImpl) this.newFilter();
  398.                     f.notEquals(resourceID, value);
  399.                     exprAll.and(f.getExpression());
  400.                 }
  401.                 this.expression.and(exprAll);
  402.             }
  403.             return this;
  404.         }catch(Exception e){
  405.             throw new SearchException(e.getMessage(),e);
  406.         }
  407.     }
  408.     @Override
  409.     public IStatisticFilter allNotEquals(List<StatisticFilter> propertyNameValues,boolean andConjunction)
  410.     throws SearchException{
  411.         try{
  412.             if(propertyNameValues.size()>0){
  413.                 IExpression exprAll = this.newIExpression();
  414.                 if(andConjunction)
  415.                     exprAll.and();
  416.                 else
  417.                     exprAll.or();
  418.                 for (StatisticFilter statisticsFilter : propertyNameValues) {
  419.                     this.check(statisticsFilter);
  420.                     FilterImpl f = (FilterImpl) this.newFilter();
  421.                     StatisticResourceFilter sf = new StatisticResourceFilter();
  422.                     sf.setResourceID(statisticsFilter.getResourceID());
  423.                     sf.setStatisticFilterName(statisticsFilter.getStatisticFilterName());
  424.                     f.notEquals(sf, statisticsFilter.getValue());
  425.                     exprAll.and(f.getExpression());
  426.                 }
  427.                 this.expression.and(exprAll);
  428.             }
  429.             return this;
  430.         }catch(Exception e){
  431.             throw new SearchException(e.getMessage(),e);
  432.         }
  433.     }

  434.     /**
  435.      * Create an expression "greaterThan"
  436.      * Example:  (field > value)
  437.      *
  438.      * @param resourceID Resource identifier
  439.      * @param value Value
  440.      * @return the instance of itself enriched with expression that represents the constraint
  441.      * @throws SearchException
  442.      */
  443.     @Override
  444.     public IFilter greaterThan(String resourceID, Object value)
  445.     throws SearchException{
  446.         return this._greaterThan(null, resourceID, value);
  447.     }
  448.     @Override
  449.     public IStatisticFilter greaterThan(StatisticResourceFilter resourceID, Object value)
  450.     throws SearchException{
  451.         return this._greaterThan(resourceID, null, value);
  452.     }
  453.     private IStatisticFilter _greaterThan(StatisticResourceFilter resourceStatID, String resourceID, Object value)
  454.     throws SearchException{
  455.         try{
  456.             StatisticFilterName statisticFilter = null;
  457.             if(resourceStatID!=null){
  458.                 this.check(resourceStatID);
  459.                 statisticFilter = resourceStatID.getStatisticFilterName();
  460.                 resourceID = resourceStatID.getResourceID();
  461.             }
  462.             List<IField> fieldsResourceName = this.getIFieldForResourceName(statisticFilter);
  463.             if(fieldsResourceName.size()==1){
  464.                 IExpression expr = this.newIExpression();
  465.                 expr.and();
  466.                 IField fieldResourceName = fieldsResourceName.get(0);
  467.                 expr.equals(fieldResourceName, resourceID);
  468.                 expr.greaterThan(this.getIFieldForResourceValue(fieldResourceName), ContentFormatter.toString(value));
  469.                 this.expression.and(expr);
  470.             }
  471.             else{
  472.                 IExpression exprEsterna = this.newIExpression();
  473.                 exprEsterna.or();
  474.                 for (IField fieldResourceName : fieldsResourceName) {
  475.                     IExpression expr = this.newIExpression();
  476.                     expr.and();
  477.                     expr.equals(fieldResourceName, resourceID);
  478.                     expr.greaterThan(this.getIFieldForResourceValue(fieldResourceName), ContentFormatter.toString(value));
  479.                     exprEsterna.or(expr);
  480.                 }
  481.                 this.expression.and(exprEsterna);
  482.             }
  483.             return this;
  484.         }catch(Exception e){
  485.             throw new SearchException(e.getMessage(),e);
  486.         }
  487.     }
  488.    
  489.     /**
  490.      * Create an expression "greaterEquals"
  491.      * Example:  (field >= value)
  492.      *
  493.      * @param resourceID Resource identifier
  494.      * @param value Value
  495.      * @return the instance of itself enriched with expression that represents the constraint
  496.      * @throws SearchException
  497.      */
  498.     @Override
  499.     public IFilter greaterEquals(String resourceID, Object value)
  500.     throws SearchException{
  501.         return this._greaterEquals(null, resourceID, value);
  502.     }
  503.     @Override
  504.     public IStatisticFilter greaterEquals(StatisticResourceFilter resourceID, Object value)
  505.     throws SearchException{
  506.         return this._greaterEquals(resourceID, null, value);
  507.     }
  508.     private IStatisticFilter _greaterEquals(StatisticResourceFilter resourceStatID,String resourceID, Object value)
  509.             throws SearchException{
  510.         try{
  511.             StatisticFilterName statisticFilter = null;
  512.             if(resourceStatID!=null){
  513.                 this.check(resourceStatID);
  514.                 statisticFilter = resourceStatID.getStatisticFilterName();
  515.                 resourceID = resourceStatID.getResourceID();
  516.             }
  517.             List<IField> fieldsResourceName = this.getIFieldForResourceName(statisticFilter);
  518.             if(fieldsResourceName.size()==1){
  519.                 IExpression expr = this.newIExpression();
  520.                 expr.and();
  521.                 IField fieldResourceName = fieldsResourceName.get(0);
  522.                 expr.equals(fieldResourceName, resourceID);
  523.                 expr.greaterEquals(this.getIFieldForResourceValue(fieldResourceName), ContentFormatter.toString(value));
  524.                 this.expression.and(expr);
  525.             }
  526.             else{
  527.                 IExpression exprEsterna = this.newIExpression();
  528.                 exprEsterna.or();
  529.                 for (IField fieldResourceName : fieldsResourceName) {
  530.                     IExpression expr = this.newIExpression();
  531.                     expr.and();
  532.                     expr.equals(fieldResourceName, resourceID);
  533.                     expr.greaterEquals(this.getIFieldForResourceValue(fieldResourceName), ContentFormatter.toString(value));
  534.                     exprEsterna.or(expr);
  535.                 }
  536.                 this.expression.and(exprEsterna);
  537.             }
  538.             return this;
  539.         }catch(Exception e){
  540.             throw new SearchException(e.getMessage(),e);
  541.         }
  542.     }
  543.    
  544.     /**
  545.      * Create an expression "lessThan"
  546.      * Example:  (field < value)
  547.      *
  548.      * @param resourceID Resource identifier
  549.      * @param value Value
  550.      * @return the instance of itself enriched with expression that represents the constraint
  551.      * @throws SearchException
  552.      */
  553.     @Override
  554.     public IFilter lessThan(String resourceID, Object value)
  555.     throws SearchException{
  556.         return this._lessThan(null, resourceID, value);
  557.     }
  558.     @Override
  559.     public IStatisticFilter lessThan(StatisticResourceFilter resourceID, Object value)
  560.     throws SearchException{
  561.         return this._lessThan(resourceID, null, value);
  562.     }
  563.     private IStatisticFilter _lessThan(StatisticResourceFilter resourceStatID,String resourceID, Object value)
  564.             throws SearchException{
  565.         try{
  566.             StatisticFilterName statisticFilter = null;
  567.             if(resourceStatID!=null){
  568.                 this.check(resourceStatID);
  569.                 statisticFilter = resourceStatID.getStatisticFilterName();
  570.                 resourceID = resourceStatID.getResourceID();
  571.             }
  572.             List<IField> fieldsResourceName = this.getIFieldForResourceName(statisticFilter);
  573.             if(fieldsResourceName.size()==1){
  574.                 IExpression expr = this.newIExpression();
  575.                 expr.and();
  576.                 IField fieldResourceName = fieldsResourceName.get(0);
  577.                 expr.equals(fieldResourceName, resourceID);
  578.                 expr.lessThan(this.getIFieldForResourceValue(fieldResourceName), ContentFormatter.toString(value));
  579.                 this.expression.and(expr);
  580.             }
  581.             else{
  582.                 IExpression exprEsterna = this.newIExpression();
  583.                 exprEsterna.or();
  584.                 for (IField fieldResourceName : fieldsResourceName) {
  585.                     IExpression expr = this.newIExpression();
  586.                     expr.and();
  587.                     expr.equals(fieldResourceName, resourceID);
  588.                     expr.lessThan(this.getIFieldForResourceValue(fieldResourceName), ContentFormatter.toString(value));
  589.                     exprEsterna.or(expr);
  590.                 }
  591.                 this.expression.and(exprEsterna);
  592.             }
  593.             return this;
  594.         }catch(Exception e){
  595.             throw new SearchException(e.getMessage(),e);
  596.         }
  597.     }
  598.    
  599.     /**
  600.      * Create an expression "lessEquals"
  601.      * Example:  (field <= value)
  602.      *
  603.      * @param resourceID Resource identifier
  604.      * @param value Value
  605.      * @return the instance of itself enriched with expression that represents the constraint
  606.      * @throws SearchException
  607.      */
  608.     @Override
  609.     public IFilter lessEquals(String resourceID, Object value)
  610.     throws SearchException{
  611.         return this._lessEquals(null, resourceID, value);
  612.     }
  613.     @Override
  614.     public IStatisticFilter lessEquals(StatisticResourceFilter resourceID, Object value)
  615.     throws SearchException{
  616.         return this._lessEquals(resourceID, null, value);
  617.     }
  618.     private IStatisticFilter _lessEquals(StatisticResourceFilter resourceStatID,String resourceID, Object value)
  619.             throws SearchException{
  620.         try{
  621.             StatisticFilterName statisticFilter = null;
  622.             if(resourceStatID!=null){
  623.                 this.check(resourceStatID);
  624.                 statisticFilter = resourceStatID.getStatisticFilterName();
  625.                 resourceID = resourceStatID.getResourceID();
  626.             }
  627.             List<IField> fieldsResourceName = this.getIFieldForResourceName(statisticFilter);
  628.             if(fieldsResourceName.size()==1){
  629.                 IExpression expr = this.newIExpression();
  630.                 expr.and();
  631.                 IField fieldResourceName = fieldsResourceName.get(0);
  632.                 expr.equals(fieldResourceName, resourceID);
  633.                 expr.lessEquals(this.getIFieldForResourceValue(fieldResourceName), ContentFormatter.toString(value));
  634.                 this.expression.and(expr);
  635.             }
  636.             else{
  637.                 IExpression exprEsterna = this.newIExpression();
  638.                 exprEsterna.or();
  639.                 for (IField fieldResourceName : fieldsResourceName) {
  640.                     IExpression expr = this.newIExpression();
  641.                     expr.and();
  642.                     expr.equals(fieldResourceName, resourceID);
  643.                     expr.lessEquals(this.getIFieldForResourceValue(fieldResourceName), ContentFormatter.toString(value));
  644.                     exprEsterna.or(expr);
  645.                 }
  646.                 this.expression.and(exprEsterna);
  647.             }
  648.             return this;
  649.         }catch(Exception e){
  650.             throw new SearchException(e.getMessage(),e);
  651.         }
  652.     }
  653.    
  654.    
  655.    
  656.    
  657.    
  658.    
  659.    
  660.    
  661.    
  662.     /* ************ SPECIAL COMPARATOR *********** */
  663.    
  664.     /**
  665.      * Create an expression "is null"
  666.      * Example:  ( field is null )
  667.      *
  668.      * @param resourceID Resource identifier
  669.      * @return the instance of itself enriched with expression that represents the constraint
  670.      * @throws SearchException
  671.      */
  672.     @Override
  673.     public IFilter isNull(String resourceID) throws SearchException{
  674.         return this._isNull(null, resourceID);
  675.     }
  676.     @Override
  677.     public IStatisticFilter isNull(StatisticResourceFilter resourceID) throws SearchException{
  678.         return this._isNull(resourceID, null);
  679.     }
  680.     private IStatisticFilter _isNull(StatisticResourceFilter resourceStatID,String resourceID) throws SearchException{
  681.         try{
  682.             StatisticFilterName statisticFilter = null;
  683.             if(resourceStatID!=null){
  684.                 this.check(resourceStatID);
  685.                 statisticFilter = resourceStatID.getStatisticFilterName();
  686.                 resourceID = resourceStatID.getResourceID();
  687.             }
  688.             List<IField> fieldsResourceName = this.getIFieldForResourceName(statisticFilter);
  689.             if(fieldsResourceName.size()==1){
  690.                 IExpression expr = this.newIExpression();
  691.                 expr.and();
  692.                 IField fieldResourceName = fieldsResourceName.get(0);
  693.                 expr.equals(fieldResourceName, resourceID);
  694.                 expr.isNull(this.getIFieldForResourceValue(fieldResourceName));
  695.                 this.expression.and(expr);
  696.             }
  697.             else{
  698.                 IExpression exprEsterna = this.newIExpression();
  699.                 exprEsterna.or();
  700.                 for (IField fieldResourceName : fieldsResourceName) {
  701.                     IExpression expr = this.newIExpression();
  702.                     expr.and();
  703.                     expr.equals(fieldResourceName, resourceID);
  704.                     expr.isNull(this.getIFieldForResourceValue(fieldResourceName));
  705.                     exprEsterna.or(expr);
  706.                 }
  707.                 this.expression.and(exprEsterna);
  708.             }
  709.             return this;
  710.         }catch(Exception e){
  711.             throw new SearchException(e.getMessage(),e);
  712.         }
  713.     }
  714.    
  715.     /**
  716.      * Create an expression "is not null"
  717.      * Example:  ( field is not null )
  718.      *
  719.      * @param resourceID Resource identifier
  720.      * @return the instance of itself enriched with expression that represents the constraint
  721.      * @throws SearchException
  722.      */
  723.     @Override
  724.     public IFilter isNotNull(String resourceID) throws SearchException{
  725.         return this._isNotNull(null, resourceID);
  726.     }
  727.     @Override
  728.     public IStatisticFilter isNotNull(StatisticResourceFilter resourceID) throws SearchException{
  729.         return this._isNotNull(resourceID,null);
  730.     }
  731.     private IStatisticFilter _isNotNull(StatisticResourceFilter resourceStatID,String resourceID) throws SearchException{
  732.         try{
  733.             StatisticFilterName statisticFilter = null;
  734.             if(resourceStatID!=null){
  735.                 this.check(resourceStatID);
  736.                 statisticFilter = resourceStatID.getStatisticFilterName();
  737.                 resourceID = resourceStatID.getResourceID();
  738.             }
  739.             List<IField> fieldsResourceName = this.getIFieldForResourceName(statisticFilter);
  740.             if(fieldsResourceName.size()==1){
  741.                 IExpression expr = this.newIExpression();
  742.                 expr.and();
  743.                 IField fieldResourceName = fieldsResourceName.get(0);
  744.                 expr.equals(fieldResourceName, resourceID);
  745.                 expr.isNotNull(this.getIFieldForResourceValue(fieldResourceName));
  746.                 this.expression.and(expr);
  747.             }
  748.             else{
  749.                 IExpression exprEsterna = this.newIExpression();
  750.                 exprEsterna.or();
  751.                 for (IField fieldResourceName : fieldsResourceName) {
  752.                     IExpression expr = this.newIExpression();
  753.                     expr.and();
  754.                     expr.equals(fieldResourceName, resourceID);
  755.                     expr.isNotNull(this.getIFieldForResourceValue(fieldResourceName));
  756.                     exprEsterna.or(expr);
  757.                 }
  758.                 this.expression.and(exprEsterna);
  759.             }
  760.             return this;
  761.         }catch(Exception e){
  762.             throw new SearchException(e.getMessage(),e);
  763.         }
  764.     }
  765.    
  766.     /**
  767.      * Create an expression "is empty"
  768.      * Example:  ( field = '' )
  769.      *
  770.      * @param resourceID Resource identifier
  771.      * @return the instance of itself enriched with expression that represents the constraint
  772.      * @throws SearchException
  773.      */
  774.     @Override
  775.     public IFilter isEmpty(String resourceID) throws SearchException{
  776.         return this._isEmpty(null, resourceID);
  777.     }
  778.     @Override
  779.     public IStatisticFilter isEmpty(StatisticResourceFilter resourceID) throws SearchException{
  780.         return this._isEmpty(resourceID,null);
  781.     }
  782.     private IStatisticFilter _isEmpty(StatisticResourceFilter resourceStatID,String resourceID) throws SearchException{
  783.         try{
  784.             StatisticFilterName statisticFilter = null;
  785.             if(resourceStatID!=null){
  786.                 this.check(resourceStatID);
  787.                 statisticFilter = resourceStatID.getStatisticFilterName();
  788.                 resourceID = resourceStatID.getResourceID();
  789.             }
  790.             List<IField> fieldsResourceName = this.getIFieldForResourceName(statisticFilter);
  791.             if(fieldsResourceName.size()==1){
  792.                 IExpression expr = this.newIExpression();
  793.                 expr.and();
  794.                 IField fieldResourceName = fieldsResourceName.get(0);
  795.                 expr.equals(fieldResourceName, resourceID);
  796.                 expr.isEmpty(this.getIFieldForResourceValue(fieldResourceName));
  797.                 this.expression.and(expr);
  798.             }
  799.             else{
  800.                 IExpression exprEsterna = this.newIExpression();
  801.                 exprEsterna.or();
  802.                 for (IField fieldResourceName : fieldsResourceName) {
  803.                     IExpression expr = this.newIExpression();
  804.                     expr.and();
  805.                     expr.equals(fieldResourceName, resourceID);
  806.                     expr.isEmpty(this.getIFieldForResourceValue(fieldResourceName));
  807.                     exprEsterna.or(expr);
  808.                 }
  809.                 this.expression.and(exprEsterna);
  810.             }
  811.             return this;
  812.         }catch(Exception e){
  813.             throw new SearchException(e.getMessage(),e);
  814.         }
  815.     }
  816.    
  817.     /**
  818.      * Create an expression "is not empty"
  819.      * Example:  ( field <> '' )
  820.      *
  821.      * @param resourceID Resource identifier
  822.      * @return the instance of itself enriched with expression that represents the constraint
  823.      * @throws SearchException
  824.      */
  825.     @Override
  826.     public IFilter isNotEmpty(String resourceID) throws SearchException{
  827.         return this._isNotEmpty(null, resourceID);
  828.     }
  829.     @Override
  830.     public IStatisticFilter isNotEmpty(StatisticResourceFilter resourceID) throws SearchException{
  831.         return this._isNotEmpty(resourceID, null);
  832.     }
  833.     private IStatisticFilter _isNotEmpty(StatisticResourceFilter resourceStatID,String resourceID) throws SearchException{
  834.         try{
  835.             StatisticFilterName statisticFilter = null;
  836.             if(resourceStatID!=null){
  837.                 this.check(resourceStatID);
  838.                 statisticFilter = resourceStatID.getStatisticFilterName();
  839.                 resourceID = resourceStatID.getResourceID();
  840.             }
  841.             List<IField> fieldsResourceName = this.getIFieldForResourceName(statisticFilter);
  842.             if(fieldsResourceName.size()==1){
  843.                 IExpression expr = this.newIExpression();
  844.                 expr.and();
  845.                 IField fieldResourceName = fieldsResourceName.get(0);
  846.                 expr.equals(fieldResourceName, resourceID);
  847.                 expr.isNotEmpty(this.getIFieldForResourceValue(fieldResourceName));
  848.                 this.expression.and(expr);
  849.             }
  850.             else{
  851.                 IExpression exprEsterna = this.newIExpression();
  852.                 exprEsterna.or();
  853.                 for (IField fieldResourceName : fieldsResourceName) {
  854.                     IExpression expr = this.newIExpression();
  855.                     expr.and();
  856.                     expr.equals(fieldResourceName, resourceID);
  857.                     expr.isNotEmpty(this.getIFieldForResourceValue(fieldResourceName));
  858.                     exprEsterna.or(expr);
  859.                 }
  860.                 this.expression.and(exprEsterna);
  861.             }
  862.             return this;
  863.         }catch(Exception e){
  864.             throw new SearchException(e.getMessage(),e);
  865.         }
  866.     }
  867.    
  868.    
  869.    
  870.    
  871.    
  872.    
  873.    
  874.    
  875.     /* ************ BETWEEN *********** */
  876.    
  877.     /**
  878.      * Create an expression "between"
  879.      * Example:  ( field BEETWEEN lower AND high )
  880.      *
  881.      * @param resourceID Resource identifier
  882.      * @param lower Lower limit value to be applied to the constraint
  883.      * @param high Higher limit value to be applied to the constraint
  884.      * @return the instance of itself enriched with expression that represents the constraint
  885.      * @throws SearchException
  886.      */
  887.     @Override
  888.     public IFilter between(String resourceID, Object lower, Object high)
  889.     throws SearchException{
  890.         return this._between(null, resourceID, lower, high);
  891.     }
  892.     @Override
  893.     public IStatisticFilter between(StatisticResourceFilter resourceID, Object lower, Object high)
  894.     throws SearchException{
  895.         return this._between(resourceID, null, lower, high);
  896.     }
  897.     private IStatisticFilter _between(StatisticResourceFilter resourceStatID,String resourceID, Object lower, Object high)
  898.             throws SearchException{
  899.         try{
  900.             StatisticFilterName statisticFilter = null;
  901.             if(resourceStatID!=null){
  902.                 this.check(resourceStatID);
  903.                 statisticFilter = resourceStatID.getStatisticFilterName();
  904.                 resourceID = resourceStatID.getResourceID();
  905.             }
  906.             List<IField> fieldsResourceName = this.getIFieldForResourceName(statisticFilter);
  907.             if(fieldsResourceName.size()==1){
  908.                 IExpression expr = this.newIExpression();
  909.                 expr.and();
  910.                 IField fieldResourceName = fieldsResourceName.get(0);
  911.                 expr.equals(fieldResourceName, resourceID);
  912.                 expr.between(this.getIFieldForResourceValue(fieldResourceName),ContentFormatter.toString(lower),ContentFormatter.toString(high));
  913.                 this.expression.and(expr);
  914.             }
  915.             else{
  916.                 IExpression exprEsterna = this.newIExpression();
  917.                 exprEsterna.or();
  918.                 for (IField fieldResourceName : fieldsResourceName) {
  919.                     IExpression expr = this.newIExpression();
  920.                     expr.and();
  921.                     expr.equals(fieldResourceName, resourceID);
  922.                     expr.between(this.getIFieldForResourceValue(fieldResourceName),ContentFormatter.toString(lower),ContentFormatter.toString(high));
  923.                     exprEsterna.or(expr);
  924.                 }
  925.                 this.expression.and(exprEsterna);
  926.             }
  927.             return this;
  928.         }catch(Exception e){
  929.             throw new SearchException(e.getMessage(),e);
  930.         }
  931.     }
  932.    
  933.    
  934.    
  935.    
  936.    
  937.    
  938.    
  939.     /* ************ LIKE *********** */
  940.    
  941.     /**
  942.      * Create an expression "like"
  943.      * Example:  ( field like '%value%' )
  944.      *
  945.      * @param resourceID Resource identifier
  946.      * @param value Value
  947.      * @return the instance of itself enriched with expression that represents the constraint
  948.      * @throws SearchException
  949.      */
  950.     @Override
  951.     public IFilter like(String resourceID, String value) throws SearchException{
  952.         return this._like(null, resourceID, value);
  953.     }
  954.     @Override
  955.     public IStatisticFilter like(StatisticResourceFilter resourceID, String value) throws SearchException{
  956.         return this._like(resourceID, null, value);
  957.     }
  958.     private IStatisticFilter _like(StatisticResourceFilter resourceStatID,String resourceID, String value) throws SearchException{
  959.         try{
  960.             StatisticFilterName statisticFilter = null;
  961.             if(resourceStatID!=null){
  962.                 this.check(resourceStatID);
  963.                 statisticFilter = resourceStatID.getStatisticFilterName();
  964.                 resourceID = resourceStatID.getResourceID();
  965.             }
  966.             List<IField> fieldsResourceName = this.getIFieldForResourceName(statisticFilter);
  967.             if(fieldsResourceName.size()==1){
  968.                 IExpression expr = this.newIExpression();
  969.                 expr.and();
  970.                 IField fieldResourceName = fieldsResourceName.get(0);
  971.                 expr.equals(fieldResourceName, resourceID);
  972.                 expr.like(this.getIFieldForResourceValue(fieldResourceName),value);
  973.                 this.expression.and(expr);
  974.             }
  975.             else{
  976.                 IExpression exprEsterna = this.newIExpression();
  977.                 exprEsterna.or();
  978.                 for (IField fieldResourceName : fieldsResourceName) {
  979.                     IExpression expr = this.newIExpression();
  980.                     expr.and();
  981.                     expr.equals(fieldResourceName, resourceID);
  982.                     expr.like(this.getIFieldForResourceValue(fieldResourceName),value);
  983.                     exprEsterna.or(expr);
  984.                 }
  985.                 this.expression.and(exprEsterna);
  986.             }
  987.             return this;
  988.         }catch(Exception e){
  989.             throw new SearchException(e.getMessage(),e);
  990.         }
  991.     }
  992.    
  993.     /**
  994.      * Create an expression "like"
  995.      * Example:  
  996.      *   LikeMode.ANYWHERE -> ( field like '%value%' )
  997.      *   LikeMode.EXACT -> ( field like 'value' )
  998.      *   LikeMode.END -> ( field like '%value' )
  999.      *   LikeMode.START -> ( field like 'value%' )
  1000.      *
  1001.      * @param resourceID Resource identifier
  1002.      * @param value Value
  1003.      * @param mode LikeMode
  1004.      * @return the instance of itself enriched with expression that represents the constraint
  1005.      * @throws SearchException
  1006.      */
  1007.     @Override
  1008.     public IFilter like(String resourceID, String value, LikeMode mode) throws SearchException{
  1009.         return this._like(null, resourceID, value, mode);
  1010.     }
  1011.     @Override
  1012.     public IStatisticFilter like(StatisticResourceFilter resourceID, String value, LikeMode mode) throws SearchException{
  1013.         return this._like(resourceID, null, value, mode);
  1014.     }
  1015.     private IStatisticFilter _like(StatisticResourceFilter resourceStatID,String resourceID, String value, LikeMode mode) throws SearchException{
  1016.         try{
  1017.             StatisticFilterName statisticFilter = null;
  1018.             if(resourceStatID!=null){
  1019.                 this.check(resourceStatID);
  1020.                 statisticFilter = resourceStatID.getStatisticFilterName();
  1021.                 resourceID = resourceStatID.getResourceID();
  1022.             }
  1023.             List<IField> fieldsResourceName = this.getIFieldForResourceName(statisticFilter);
  1024.             if(fieldsResourceName.size()==1){
  1025.                 IExpression expr = this.newIExpression();
  1026.                 expr.and();
  1027.                 IField fieldResourceName = fieldsResourceName.get(0);
  1028.                 expr.equals(fieldResourceName, resourceID);
  1029.                 expr.like(this.getIFieldForResourceValue(fieldResourceName),value,mode.getLikeGenericProjectValue());
  1030.                 this.expression.and(expr);
  1031.             }
  1032.             else{
  1033.                 IExpression exprEsterna = this.newIExpression();
  1034.                 exprEsterna.or();
  1035.                 for (IField fieldResourceName : fieldsResourceName) {
  1036.                     IExpression expr = this.newIExpression();
  1037.                     expr.and();
  1038.                     expr.equals(fieldResourceName, resourceID);
  1039.                     expr.like(this.getIFieldForResourceValue(fieldResourceName),value,mode.getLikeGenericProjectValue());
  1040.                     exprEsterna.or(expr);
  1041.                 }
  1042.                 this.expression.and(exprEsterna);
  1043.             }
  1044.             return this;
  1045.         }catch(Exception e){
  1046.             throw new SearchException(e.getMessage(),e);
  1047.         }
  1048.     }
  1049.    
  1050.     /**
  1051.      * Create an expression "like" case-insensitive
  1052.      * Example:  ( toLower(field) like '%toLower(value)%' )  
  1053.      *
  1054.      * @param resourceID Resource identifier
  1055.      * @param value Value
  1056.      * @return the instance of itself enriched with expression that represents the constraint
  1057.      * @throws SearchException
  1058.      */
  1059.     @Override
  1060.     public IFilter ilike(String resourceID, String value) throws SearchException{
  1061.         return this._ilike(null, resourceID, value);
  1062.     }
  1063.     @Override
  1064.     public IStatisticFilter ilike(StatisticResourceFilter resourceID, String value) throws SearchException{
  1065.         return this._ilike(resourceID, null, value);
  1066.     }
  1067.     private IStatisticFilter _ilike(StatisticResourceFilter resourceStatID,String resourceID, String value) throws SearchException{
  1068.         try{
  1069.             StatisticFilterName statisticFilter = null;
  1070.             if(resourceStatID!=null){
  1071.                 this.check(resourceStatID);
  1072.                 statisticFilter = resourceStatID.getStatisticFilterName();
  1073.                 resourceID = resourceStatID.getResourceID();
  1074.             }
  1075.             List<IField> fieldsResourceName = this.getIFieldForResourceName(statisticFilter);
  1076.             if(fieldsResourceName.size()==1){
  1077.                 IExpression expr = this.newIExpression();
  1078.                 expr.and();
  1079.                 IField fieldResourceName = fieldsResourceName.get(0);
  1080.                 expr.equals(fieldResourceName, resourceID);
  1081.                 expr.ilike(this.getIFieldForResourceValue(fieldResourceName),value);
  1082.                 this.expression.and(expr);
  1083.             }
  1084.             else{
  1085.                 IExpression exprEsterna = this.newIExpression();
  1086.                 exprEsterna.or();
  1087.                 for (IField fieldResourceName : fieldsResourceName) {
  1088.                     IExpression expr = this.newIExpression();
  1089.                     expr.and();
  1090.                     expr.equals(fieldResourceName, resourceID);
  1091.                     expr.ilike(this.getIFieldForResourceValue(fieldResourceName),value);
  1092.                     exprEsterna.or(expr);
  1093.                 }
  1094.                 this.expression.and(exprEsterna);
  1095.             }
  1096.             return this;
  1097.         }catch(Exception e){
  1098.             throw new SearchException(e.getMessage(),e);
  1099.         }
  1100.     }
  1101.    
  1102.     /**
  1103.      * Create an expression "like" case-insensitive
  1104.      * Example:  
  1105.      *   LikeMode.ANYWHERE -> ( toLower(field) like '%toLower(value)%' )
  1106.      *   LikeMode.EXACT -> ( toLower(field) like 'toLower(value)' )
  1107.      *   LikeMode.END -> ( toLower(field) like '%toLower(value)' )
  1108.      *   LikeMode.START -> ( toLower(field) like 'toLower(value)%' )
  1109.      *
  1110.      * @param resourceID Resource identifier
  1111.      * @param value Value
  1112.      * @param mode LikeMode
  1113.      * @return the instance of itself enriched with expression that represents the constraint
  1114.      * @throws SearchException
  1115.      */
  1116.     @Override
  1117.     public IFilter ilike(String resourceID, String value, LikeMode mode) throws SearchException{
  1118.         return this._ilike(null, resourceID, value, mode);
  1119.     }
  1120.     @Override
  1121.     public IStatisticFilter ilike(StatisticResourceFilter resourceID, String value, LikeMode mode) throws SearchException{
  1122.         return this._ilike(resourceID, null, value, mode);
  1123.     }
  1124.     private IStatisticFilter _ilike(StatisticResourceFilter resourceStatID,String resourceID, String value, LikeMode mode) throws SearchException{
  1125.         try{
  1126.             StatisticFilterName statisticFilter = null;
  1127.             if(resourceStatID!=null){
  1128.                 this.check(resourceStatID);
  1129.                 statisticFilter = resourceStatID.getStatisticFilterName();
  1130.                 resourceID = resourceStatID.getResourceID();
  1131.             }
  1132.             List<IField> fieldsResourceName = this.getIFieldForResourceName(statisticFilter);
  1133.             if(fieldsResourceName.size()==1){
  1134.                 IExpression expr = this.newIExpression();
  1135.                 expr.and();
  1136.                 IField fieldResourceName = fieldsResourceName.get(0);
  1137.                 expr.equals(fieldResourceName, resourceID);
  1138.                 expr.ilike(this.getIFieldForResourceValue(fieldResourceName),value,mode.getLikeGenericProjectValue());
  1139.                 this.expression.and(expr);
  1140.             }
  1141.             else{
  1142.                 IExpression exprEsterna = this.newIExpression();
  1143.                 exprEsterna.or();
  1144.                 for (IField fieldResourceName : fieldsResourceName) {
  1145.                     IExpression expr = this.newIExpression();
  1146.                     expr.and();
  1147.                     expr.equals(fieldResourceName, resourceID);
  1148.                     expr.ilike(this.getIFieldForResourceValue(fieldResourceName),value,mode.getLikeGenericProjectValue());
  1149.                     exprEsterna.or(expr);
  1150.                 }
  1151.                 this.expression.and(exprEsterna);
  1152.             }
  1153.             return this;
  1154.         }catch(Exception e){
  1155.             throw new SearchException(e.getMessage(),e);
  1156.         }
  1157.     }

  1158.    
  1159.    

  1160.    
  1161.    

  1162.     /* ************ IN *********** */
  1163.    
  1164.     /**
  1165.      * Create an expression "in" verifying that the value of <var>field</var> is one of those given in the param <var>values</var>
  1166.      * Example:  ( field IN ('values[0]', 'values[1]', ... ,'values[n]')  )
  1167.      *
  1168.      * @param resourceID Resource identifier
  1169.      * @param values Values
  1170.      * @return the instance of itself enriched with expression that represents the constraint
  1171.      * @throws SearchException
  1172.      */
  1173.     @Override
  1174.     public IFilter in(String resourceID, Object ... values)
  1175.     throws SearchException{
  1176.         return this._in(null, resourceID, values);
  1177.     }
  1178.     @Override
  1179.     public IStatisticFilter in(StatisticResourceFilter resourceID, Object ... values)
  1180.     throws SearchException{
  1181.         return this._in(resourceID, null, values);
  1182.     }
  1183.     private IStatisticFilter _in(StatisticResourceFilter resourceStatID,String resourceID, Object ... values)
  1184.             throws SearchException{
  1185.         try{
  1186.             StatisticFilterName statisticFilter = null;
  1187.             if(resourceStatID!=null){
  1188.                 this.check(resourceStatID);
  1189.                 statisticFilter = resourceStatID.getStatisticFilterName();
  1190.                 resourceID = resourceStatID.getResourceID();
  1191.             }
  1192.             List<IField> fieldsResourceName = this.getIFieldForResourceName(statisticFilter);
  1193.             if(fieldsResourceName.size()==1){
  1194.                 IExpression expr = this.newIExpression();
  1195.                 expr.and();
  1196.                 IField fieldResourceName = fieldsResourceName.get(0);
  1197.                 expr.equals(fieldResourceName, resourceID);
  1198.                 expr.in(this.getIFieldForResourceValue(fieldResourceName),ContentFormatter.toString(values));
  1199.                 this.expression.and(expr);
  1200.             }
  1201.             else{
  1202.                 IExpression exprEsterna = this.newIExpression();
  1203.                 exprEsterna.or();
  1204.                 for (IField fieldResourceName : fieldsResourceName) {
  1205.                     IExpression expr = this.newIExpression();
  1206.                     expr.and();
  1207.                     expr.equals(fieldResourceName, resourceID);
  1208.                     expr.in(this.getIFieldForResourceValue(fieldResourceName),ContentFormatter.toString(values));
  1209.                     exprEsterna.or(expr);
  1210.                 }
  1211.                 this.expression.and(exprEsterna);
  1212.             }
  1213.             return this;
  1214.         }catch(Exception e){
  1215.             throw new SearchException(e.getMessage(),e);
  1216.         }
  1217.     }
  1218.        
  1219.     /**
  1220.      * Create an expression "in" verifying that the value of <var>field</var> is one of those given in the param <var>values</var>
  1221.      * Example:  ( field IN ('values[0]', 'values[1]', ... ,'values[n]')  )
  1222.      *
  1223.      * @param resourceID Resource identifier
  1224.      * @param values Values
  1225.      * @return the instance of itself enriched with expression that represents the constraint
  1226.      * @throws SearchException
  1227.      */
  1228.     @Override
  1229.     public IFilter in(String resourceID, Collection<?> values)
  1230.     throws SearchException {
  1231.         return this._in(null, resourceID, values);
  1232.     }
  1233.     @Override
  1234.     public IStatisticFilter in(StatisticResourceFilter resourceID, Collection<?> values)
  1235.     throws SearchException {
  1236.         return this._in(resourceID, null, values);
  1237.     }
  1238.     private IStatisticFilter _in(StatisticResourceFilter resourceStatID,String resourceID, Collection<?> values)
  1239.             throws SearchException {
  1240.         try{
  1241.            
  1242.             List<String> collectionString = new ArrayList<>();
  1243.             for (Object o : values) {
  1244.                 collectionString.add(ContentFormatter.toString(o));
  1245.             }
  1246.            
  1247.             StatisticFilterName statisticFilter = null;
  1248.             if(resourceStatID!=null){
  1249.                 this.check(resourceStatID);
  1250.                 statisticFilter = resourceStatID.getStatisticFilterName();
  1251.                 resourceID = resourceStatID.getResourceID();
  1252.             }
  1253.             List<IField> fieldsResourceName = this.getIFieldForResourceName(statisticFilter);
  1254.             if(fieldsResourceName.size()==1){
  1255.                 IExpression expr = this.newIExpression();
  1256.                 expr.and();
  1257.                 IField fieldResourceName = fieldsResourceName.get(0);
  1258.                 expr.equals(fieldResourceName, resourceID);
  1259.                 expr.in(this.getIFieldForResourceValue(fieldResourceName),collectionString);
  1260.                 this.expression.and(expr);
  1261.             }
  1262.             else{
  1263.                 IExpression exprEsterna = this.newIExpression();
  1264.                 exprEsterna.or();
  1265.                 for (IField fieldResourceName : fieldsResourceName) {
  1266.                     IExpression expr = this.newIExpression();
  1267.                     expr.and();
  1268.                     expr.equals(fieldResourceName, resourceID);
  1269.                     expr.in(this.getIFieldForResourceValue(fieldResourceName),collectionString);
  1270.                     exprEsterna.or(expr);
  1271.                 }
  1272.                 this.expression.and(exprEsterna);
  1273.             }
  1274.             return this;
  1275.         }catch(Exception e){
  1276.             throw new SearchException(e.getMessage(),e);
  1277.         }
  1278.     }
  1279.    
  1280.    
  1281.    
  1282.    
  1283.    
  1284.     /* ************ CONJUNCTION *********** */
  1285.    
  1286.     /**
  1287.      *  Adds to the expression in the conjunction "AND" of the espressions given as a parameters
  1288.      *  Example: ( exp1 AND exp2  )
  1289.      *  
  1290.      * @param exp1 Filter combined in AND with <var>exp1</var>
  1291.      * @param exp2 Filter combined in AND with <var>exp2</var>
  1292.      * @return the instance of itself enriched with expression that represents the constraint
  1293.      * @throws SearchException
  1294.      */
  1295.     @Override
  1296.     public IStatisticFilter and(IFilter exp1, IFilter exp2) throws SearchException{
  1297.         try{
  1298.             FilterImpl f1 = (FilterImpl) exp1;
  1299.             FilterImpl f2 = (FilterImpl) exp2;
  1300.             this.expression.and(f1.expression,f2.expression);
  1301.             return this;
  1302.         }catch(Exception e){
  1303.             throw new SearchException(e.getMessage(),e);
  1304.         }
  1305.     }
  1306.    
  1307.     /**
  1308.      *  Adds to the expression in the conjunction "AND" of the espressions given as a parameters
  1309.      *  Example: ( expressions[1] AND expressions[2] AND ... expressions[N] )
  1310.      *  
  1311.      * @param expressions Expressions combined in AND
  1312.      * @return the instance of itself enriched with expression that represents the constraint
  1313.      * @throws SearchException
  1314.      */
  1315.     @Override
  1316.     public IStatisticFilter and(IFilter... expressions) throws SearchException{
  1317.         try{
  1318.             if(expressions!=null && expressions.length>0){
  1319.                 IExpression [] fs  = new IExpression[expressions.length];
  1320.                 for (int i = 0; i < expressions.length; i++) {
  1321.                     fs[i] = ((FilterImpl) expressions[i]).expression;
  1322.                 }
  1323.                 this.expression.and(fs);
  1324.             }
  1325.             return this;
  1326.         }catch(Exception e){
  1327.             throw new SearchException(e.getMessage(),e);
  1328.         }
  1329.     }
  1330.    
  1331.     /**
  1332.      *  Adds to the expression in the conjunction "OR" of the espressions given as a parameters
  1333.      *  Example: ( exp1 OR exp2  )
  1334.      *  
  1335.      * @param exp1 Filter combined in OR with <var>exp1</var>
  1336.      * @param exp2 Filter combined in OR with <var>exp2</var>
  1337.      * @return the instance of itself enriched with expression that represents the constraint
  1338.      * @throws SearchException
  1339.      */
  1340.     @Override
  1341.     public IStatisticFilter or(IFilter exp1, IFilter exp2) throws SearchException{
  1342.         try{
  1343.             FilterImpl f1 = (FilterImpl) exp1;
  1344.             FilterImpl f2 = (FilterImpl) exp2;
  1345.             this.expression.or(f1.expression,f2.expression);
  1346.             return this;
  1347.         }catch(Exception e){
  1348.             throw new SearchException(e.getMessage(),e);
  1349.         }
  1350.     }
  1351.    
  1352.     /**
  1353.      *  Adds to the expression in the conjunction "OR" of the espressions given as a parameters
  1354.      *  Example: ( expressions[1] OR expressions[2] OR ... expressions[N] )
  1355.      *  
  1356.      * @param expressions Expressions combined in OR
  1357.      * @return the instance of itself enriched with expression that represents the constraint
  1358.      * @throws SearchException
  1359.      */
  1360.     @Override
  1361.     public IStatisticFilter or(IFilter... expressions) throws SearchException{
  1362.         try{
  1363.             if(expressions!=null && expressions.length>0){
  1364.                 IExpression [] fs  = new IExpression[expressions.length];
  1365.                 for (int i = 0; i < expressions.length; i++) {
  1366.                     fs[i] = ((FilterImpl) expressions[i]).expression;
  1367.                 }
  1368.                 this.expression.or(fs);
  1369.             }
  1370.             return this;
  1371.         }catch(Exception e){
  1372.             throw new SearchException(e.getMessage(),e);
  1373.         }
  1374.     }
  1375.    
  1376.    
  1377.    
  1378.    
  1379.    
  1380.    
  1381.    
  1382.    
  1383.     /* ************ NEGATION *********** */
  1384.    
  1385.     /**
  1386.      * Adding to the negation of the expression passed as parameter
  1387.      * Example: ( NOT expression )
  1388.      *
  1389.      * @param expression Expression
  1390.      * @return the instance of itself enriched with expression that represents the constraint
  1391.      * @throws SearchException
  1392.      */
  1393.     @Override
  1394.     public IStatisticFilter not(IFilter expression) throws SearchException{
  1395.         try{
  1396.             FilterImpl f = (FilterImpl) expression;
  1397.             this.expression.not(f.expression);
  1398.             return this;
  1399.         }catch(Exception e){
  1400.             throw new SearchException(e.getMessage(),e);
  1401.         }
  1402.     }

  1403.    
  1404.    
  1405.    
  1406.    
  1407.    
  1408.    
  1409.     /* ************ MESSAGE TYPE *********** */

  1410.     @Override
  1411.     public IStatisticFilter setMessageType(MessageType messageType) throws SearchException{
  1412.         try{
  1413.             IField f = this.getIFieldForMessageType();
  1414.             if(f!=null){
  1415.                 // Le statistiche non classificano il messaggio rispetto al tipo
  1416.                 this.expression.equals(f, messageType.name());
  1417.             }
  1418.             return this;
  1419.         }catch(Exception e){
  1420.             throw new SearchException(e.getMessage(),e);
  1421.         }
  1422.     }
  1423.    
  1424.    
  1425.    
  1426.    
  1427.     /* ************ NEW FILTER *********** */
  1428.    
  1429.     @Override
  1430.     public IStatisticFilter newFilter() throws SearchException{
  1431.         return this.newIFilter();
  1432.     }
  1433.    

  1434.    
  1435. }