Connettori.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.web.ctrlstat.core;

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

  24. import org.slf4j.Logger;
  25. import org.openspcoop2.core.constants.TipiConnettore;
  26. import org.openspcoop2.web.ctrlstat.servlet.connettori.ConnettoriCore;

  27. /**
  28.  * Connettori
  29.  *
  30.  * @author Andrea Poli (apoli@link.it)
  31.  * @author Stefano Corallo (corallo@link.it)
  32.  * @author Sandra Giangrandi (sandra@link.it)
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  *
  36.  */
  37. public class Connettori {
  38.     private static final List<String> lista = new ArrayList<>();

  39.     public static void initialize(Logger log) throws Exception {
  40.         initialize(log, false, null, null);
  41.     }
  42.     public static void initialize(Logger log, boolean initForApi, String confDir, String protocolloDefault) throws Exception {
  43.         /**
  44.          * Aggiungo i connettori di default e quelli che leggo nel db
  45.          */
  46.         for (TipiConnettore t : TipiConnettore.values()) {
  47.             if(!TipiConnettore.CUSTOM.equals(t)){
  48.                 Connettori.lista.add(t.getNome());
  49.             }
  50.         }

  51.         // aggiungo i connettori presenti nel db
  52.         try{
  53.             Connettori.readConnettoriFromDB(initForApi, confDir, protocolloDefault);
  54.         }catch(Exception e){
  55.             log.error("Caricamento connettori non riuscito",e);
  56.             throw new Exception(e.getMessage(),e);
  57.         }
  58.     }

  59.     /**
  60.      * Controlla se il parametro passato e' un connettore
  61.      *
  62.      * @param nome
  63.      * @return true se e' un connettore
  64.      */
  65.     public static boolean contains(String nome) {
  66.         return Connettori.lista.contains(nome);
  67.     }

  68.     private static boolean readConnettoriFromDB(boolean initForApi, String confDir, String protocolloDefault) throws Exception {
  69.         try {
  70.             ConnettoriCore core = null;
  71.             if(initForApi) {
  72.                 core = new ConnettoriCore(initForApi, confDir, protocolloDefault);
  73.             }else {
  74.                 core = new ConnettoriCore();
  75.             }
  76.             List<String> tmpConnettori = core.connettoriList();
  77.             Iterator<String> it = tmpConnettori.iterator();
  78.             while (it.hasNext())
  79.                 Connettori.lista.add(it.next());

  80.             ControlStationLogger.getPddConsoleCoreLogger().info("Connettori: caricati " + Connettori.lista.size() + " connettori.");
  81.         } catch (Exception e) {
  82.             ControlStationLogger.getPddConsoleCoreLogger().error("Connettori: " + e.getMessage());
  83.         }

  84.         return true;
  85.     }

  86.     public static List<String> getList() {
  87.         return new ArrayList<>(Connettori.lista);
  88.     }
  89. }