Search.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;

  21. import java.io.Serializable;
  22. import java.util.HashMap;
  23. import java.util.Map;

  24. import org.openspcoop2.utils.sql.ISQLQueryObject;

  25. /**
  26.  * Oggetto che si occupa di memorizzare i valori di ricerca per le liste
  27.  *
  28.  *
  29.  * @author Andrea Poli (apoli@link.it)
  30.  * @author Stefano Corallo (corallo@link.it)
  31.  * @author Sandra Giangrandi (sandra@link.it)
  32.  * @author $Author$
  33.  * @version $Rev$, $Date$
  34.  *
  35.  */
  36. public class Search implements Serializable, ISearch {
  37.     private static final long serialVersionUID = 1L;

  38.     private Map<Integer, Integer> pageSize = null;
  39.     private Map<Integer, Integer> indexIniziale = null;
  40.     private Map<Integer, String> searchString = null;
  41.     private Map<Integer, Integer> numEntries = null;
  42.     private Map<Integer, HashMap<String,String>> filter = null;

  43.     private static Integer PAGE_SIZE_DEFAULT = org.openspcoop2.core.constants.Costanti.PAGE_SIZE_DEFAULT;
  44.     private static Integer INDEX_DEFAULT = org.openspcoop2.core.constants.Costanti.INDEX_DEFAULT;
  45.     private static String SEARCH_DEFAULT = org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED;
  46.     private static Integer NUM_ENTRIES_DEFAULT = org.openspcoop2.core.constants.Costanti.NUM_ENTRIES_DEFAULT;
  47.     //private String FILTER_DEFAULT = org.openspcoop2.core.constants.Costanti.SESSION_ATTRIBUTE_VALUE_RICERCA_UNDEFINED;

  48.     public Search() {
  49.         this.reset();
  50.     }
  51.    
  52.     public void reset() {
  53.         this.pageSize = new HashMap<Integer, Integer>();
  54.         this.indexIniziale = new HashMap<Integer, Integer>();
  55.         this.searchString = new HashMap<Integer, String>();
  56.         this.numEntries = new HashMap<Integer, Integer>();
  57.         this.filter = new HashMap<Integer, HashMap<String,String>>();

  58.         for (int i = 0; i < Liste.getTotaleListe(); i++) {
  59.             this.pageSize.put(i, Search.PAGE_SIZE_DEFAULT);
  60.             this.indexIniziale.put(i, Search.INDEX_DEFAULT);
  61.             this.searchString.put(i, Search.SEARCH_DEFAULT);
  62.             this.numEntries.put(i, Search.NUM_ENTRIES_DEFAULT);
  63.             this.filter.put(i, new HashMap<>());
  64.         }

  65.     }

  66.     public Search(boolean showAllResult) {
  67.         this(showAllResult, ISQLQueryObject.LIMIT_DEFAULT_VALUE);
  68.     }
  69.     public Search(boolean showAllResult, int initialLimit) {
  70.         this.pageSize = new HashMap<Integer, Integer>();
  71.         this.indexIniziale = new HashMap<Integer, Integer>();
  72.         this.searchString = new HashMap<Integer, String>();
  73.         this.numEntries = new HashMap<Integer, Integer>();
  74.         this.filter = new HashMap<Integer, HashMap<String,String>>();

  75.         for (int i = 0; i < Liste.getTotaleListe(); i++) {
  76.             this.pageSize.put(i, initialLimit);// prendo
  77.             // il
  78.             // valore
  79.             // massimo
  80.             // di
  81.             // default
  82.             this.indexIniziale.put(i, Search.INDEX_DEFAULT);
  83.             this.searchString.put(i, Search.SEARCH_DEFAULT);
  84.             this.numEntries.put(i, Search.NUM_ENTRIES_DEFAULT);
  85.             this.filter.put(i, new HashMap<>());
  86.         }

  87.     }

  88.     @Override
  89.     public int getNumEntries(int indexLista) {
  90.         return this.numEntries.get(indexLista);
  91.     }

  92.     @Override
  93.     public void setNumEntries(int indexLista, int numEntries) {
  94.         this.numEntries.put(indexLista, numEntries);
  95.     }

  96.     @Override
  97.     public int getPageSize(int indexLista) {
  98.         return this.pageSize.get(indexLista);
  99.     }

  100.     @Override
  101.     public void setPageSize(int indexLista, int valore) {
  102.         this.pageSize.put(indexLista, valore);
  103.     }

  104.     @Override
  105.     public int getIndexIniziale(int indexLista) {
  106.         return this.indexIniziale.get(indexLista);
  107.     }

  108.     @Override
  109.     public void setIndexIniziale(int indexLista, int valore) {
  110.         this.indexIniziale.put(indexLista, valore);
  111.     }

  112.     @Override
  113.     public String getSearchString(int indexLista) {
  114.         return this.searchString.get(indexLista);
  115.     }

  116.     @Override
  117.     public void setSearchString(int indexLista, String valore) {
  118.         this.searchString.put(indexLista, valore);
  119.     }

  120.     @Override
  121.     public void clearFilters(int indexLista) {
  122.         HashMap<String,String> map = this.filter.get(indexLista);
  123.         if(map!=null) {
  124.             map.clear();
  125.         }
  126.     }
  127.    
  128.     @Override
  129.     public void clearFilter(int indexLista, String filterName) {
  130.         HashMap<String,String> map = this.filter.get(indexLista);
  131.         if(map!=null) {
  132.             map.remove(filterName);
  133.         }
  134.     }
  135.    
  136.     @Override
  137.     public boolean existsFilter(int indexLista, String filterName) {
  138.         HashMap<String,String> map = this.filter.get(indexLista);
  139.         if(map==null || map.size()<=0) {
  140.             return false;
  141.         }
  142.         return map.containsKey(filterName);
  143.     }
  144.    
  145.     @Override
  146.     public String getFilter(int indexLista, String filterName) {
  147.         HashMap<String,String> map = this.filter.get(indexLista);
  148.         if(map==null || map.size()<=0) {
  149.             return null;
  150.         }
  151.         return map.get(filterName);
  152.     }
  153.    
  154.     @Override
  155.     public void addFilter(int indexLista, String filterName, String filterValue) {
  156.         HashMap<String,String> map = this.filter.get(indexLista);
  157.         if(map==null) {
  158.             map = new HashMap<>();
  159.             this.filter.put(indexLista, map);
  160.         }
  161.         if(map.containsKey(filterName)) {
  162.             map.remove(filterName);
  163.         }
  164.         map.put(filterName, filterValue);
  165.     }

  166.     @Deprecated
  167.     public Map<Integer, Integer> getPageSize() {
  168.         return this.pageSize;
  169.     }

  170.     @Deprecated
  171.     public void setPageSize(Map<Integer, Integer> pageSize) {
  172.         this.pageSize = pageSize;
  173.     }

  174.     @Deprecated
  175.     public Map<Integer, Integer> getIndexIniziale() {
  176.         return this.indexIniziale;
  177.     }

  178.     @Deprecated
  179.     public void setIndexIniziale(Map<Integer, Integer> indexIniziale) {
  180.         this.indexIniziale = indexIniziale;
  181.     }

  182.     @Deprecated
  183.     public Map<Integer, String> getSearchString() {
  184.         return this.searchString;
  185.     }

  186.     @Deprecated
  187.     public void setSearchString(Map<Integer, String> searchString) {
  188.         this.searchString = searchString;
  189.     }

  190.     @Deprecated
  191.     public Map<Integer, Integer> getNumEntries() {
  192.         return this.numEntries;
  193.     }

  194.     @Deprecated
  195.     public void setNumEntries(Map<Integer, Integer> numEntries) {
  196.         this.numEntries = numEntries;
  197.     }

  198.     @Deprecated
  199.     public Map<Integer, HashMap<String, String>> getFilter() {
  200.         return this.filter;
  201.     }

  202.     @Deprecated
  203.     public void setFilter(Map<Integer, HashMap<String, String>> filter) {
  204.         this.filter = filter;
  205.     }

  206. }