ConnettoreStatusApiHelper.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.config.rs.server.api.impl.erogazioni;

  21. import java.util.Map;
  22. import java.util.Objects;

  23. import org.openspcoop2.core.config.rs.server.model.ConnettoreEnum;
  24. import org.openspcoop2.core.config.rs.server.model.ConnettoreStatus;
  25. import org.openspcoop2.core.config.rs.server.model.ConnettoreStatusVerificaStatistica;
  26. import org.openspcoop2.core.config.rs.server.model.OneOfApplicativoServerConnettore;
  27. import org.openspcoop2.core.config.rs.server.model.OneOfConnettoreErogazioneConnettore;
  28. import org.openspcoop2.core.config.rs.server.model.OneOfConnettoreFruizioneConnettore;
  29. import org.openspcoop2.core.config.rs.server.model.TipoPeriodoStatisticoEnum;
  30. import org.openspcoop2.core.config.rs.server.model.TipoRispostaStatusEnum;
  31. import org.openspcoop2.core.constants.CostantiDB;
  32. import org.openspcoop2.core.constants.TipiConnettore;
  33. import org.openspcoop2.core.registry.Connettore;
  34. import org.openspcoop2.web.ctrlstat.servlet.connettori.ConnettoreStatusParams;
  35. import org.openspcoop2.web.ctrlstat.servlet.connettori.ConnettoriCostanti;
  36. import org.openspcoop2.web.lib.mvc.ServletUtils;

  37. /**
  38.  * ConnettoreStatusApiHelper
  39.  *
  40.  * @author Tommaso Burlon (tommaso.burlon@link.it)
  41.  * @author $Author$
  42.  * @version $Rev$, $Date$
  43.  */
  44. public class ConnettoreStatusApiHelper extends AbstractConnettoreApiHelper<ConnettoreStatus> {

  45.     @Override
  46.     protected boolean connettoreCheckData(ConnettoreStatus conn, ErogazioniEnv env, boolean erogazione) throws Exception {
  47.         return !ConnettoreStatusParams.check(env.apsHelper, null, null).getParsingErrors();
  48.     }

  49.     @Override
  50.     public Connettore fillConnettoreRegistro(org.openspcoop2.core.registry.Connettore regConnettore,
  51.             ErogazioniEnv env,
  52.             ConnettoreStatus conn,
  53.             String oldConnT) throws Exception {
  54.        
  55.         ConnettoreStatusParams params = new ConnettoreStatusParams()
  56.                 .statusResponseType(conn.getRisposta().toString())
  57.                 .testConnectivity(conn.isVerificaConnettivita())
  58.                 .testStatistics(false);
  59.        
  60.         if (conn.getVerificaStatistica() != null) {
  61.             params.testStatistics(true);
  62.             params.periodValue(conn.getVerificaStatistica().getIntervallo());
  63.             params.period(conn.getVerificaStatistica().getFrequenza().toString());
  64.             params.statLifetime(conn.getVerificaStatistica().getCacheLifeTime());
  65.         }
  66.        
  67.         env.apsHelper.fillConnettore(
  68.                 regConnettore,
  69.                 conn.isDebug() == Boolean.TRUE ? "true" : "false",              // this.connettoreDebug,
  70.                 TipiConnettore.STATUS.getNome(),            // endpointtype
  71.                 oldConnT,                       // oldConnT
  72.                 "",                     // tipoConn Personalizzato
  73.                 null, // this.url,
  74.                 null,   // this.nome,
  75.                 null,   // this.tipo,
  76.                 null,
  77.                 null,
  78.                 null,   // this.initcont,
  79.                 null,   // this.urlpgk,
  80.                 null, // this.url,
  81.                 null,   // this.connfact,
  82.                 null,   // this.sendas,
  83.                 null, // this.httpsurl,
  84.                 null,               // this.httpstipologia
  85.                 false,  // this.httpshostverify,
  86.                 ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS, // httpsTrustVerifyCert
  87.                 null,               // this.httpspath
  88.                 null,   // this.httpstipo,
  89.                 null,           // this.httpspwd,
  90.                 null,                   // this.httpsalgoritmo
  91.                 false,
  92.                 null,           // this.httpskeystore,
  93.                 "",                                                                 //  this.httpspwdprivatekeytrust
  94.                 null,               // pathkey
  95.                 null,       // this.httpstipokey
  96.                 null,           // this.httpspwdkey
  97.                 null,               // this.httpspwdprivatekey,  
  98.                 null,               // this.httpsalgoritmokey,
  99.                 null,                   // httpsKeyAlias
  100.                 null,                   // httpsTrustStoreCRLs
  101.                 null,                   // httpsTrustStoreOCSPPolicy
  102.                 null,                   // httpsKeyStoreBYOKPolicy
  103.            
  104.                 ServletUtils.boolToCheckBoxStatus( false ),
  105.                 null,
  106.                 null,
  107.                 null,
  108.                 null,
  109.                
  110.                 ServletUtils.boolToCheckBoxStatus( false ),
  111.                 null,   // this.tempiRisposta_connectionTimeout,
  112.                 null, //null,   // this.tempiRisposta_readTimeout,
  113.                 null,   // this.tempiRisposta_tempoMedioRisposta,
  114.                 "no",   // this.opzioniAvanzate,
  115.                 "",     // this.transfer_mode,
  116.                 "",     // this.transfer_mode_chunk_size,
  117.                 "",     // this.redirect_mode,
  118.                 "",     // this.redirect_max_hop,
  119.                 null,   // this.requestOutputFileName,
  120.                 null,   // this.requestOutputFileName_permissions
  121.                 null,   // this.requestOutputFileNameHeaders,
  122.                 null,   // this.requestOutputFileNameHeaders_permissions
  123.                 null,   // this.requestOutputParentDirCreateIfNotExists,
  124.                 null,   // this.requestOutputOverwriteIfExists,
  125.                 null,   // this.responseInputMode,
  126.                 null,   // this.responseInputFileName,
  127.                 null,   // this.responseInputFileNameHeaders,
  128.                 null,   // this.responseInputDeleteAfterRead,
  129.                 null,   // this.responseInputWaitTime,
  130.                 null,   // tokenPolicy
  131.                 null, null, // apiKeyHeader,  apiKeyValue
  132.                 null, null, // appIdHeader, appIdValue
  133.                 params, // connettoreStatusParams
  134.                 null // listExtendedConnettore
  135.                 );
  136.        
  137.         return regConnettore;
  138.     }

  139.     @Override
  140.     public org.openspcoop2.core.config.Connettore buildConnettoreConfigurazione(
  141.             org.openspcoop2.core.config.Connettore regConnettore, ErogazioniEnv env, ConnettoreStatus conn,
  142.             String oldConnType) throws Exception {

  143.         ConnettoreStatusParams params = new ConnettoreStatusParams()
  144.                 .statusResponseType(conn.getRisposta().toString())
  145.                 .testConnectivity(conn.isVerificaConnettivita())
  146.                 .testStatistics(false);
  147.        
  148.         if (conn.getVerificaStatistica() != null) {
  149.             params.testStatistics(true);
  150.             params.periodValue(conn.getVerificaStatistica().getIntervallo());
  151.             params.period(conn.getVerificaStatistica().getFrequenza().toString());
  152.             params.statLifetime(conn.getVerificaStatistica().getCacheLifeTime());
  153.         }
  154.        
  155.         env.apsHelper.fillConnettore(
  156.                 regConnettore,
  157.                 conn.isDebug() == Boolean.TRUE ? "true" : "false",              // this.connettoreDebug,
  158.                 TipiConnettore.STATUS.getNome(),            // endpointtype
  159.                 oldConnType,                        // oldConnT
  160.                 "",                     // tipoConn Personalizzato
  161.                 null, // this.url,
  162.                 null,   // this.nome,
  163.                 null,   // this.tipo,
  164.                 null,
  165.                 null,
  166.                 null,   // this.initcont,
  167.                 null,   // this.urlpgk,
  168.                 null, // this.url,
  169.                 null,   // this.connfact,
  170.                 null,   // this.sendas,
  171.                 null, // this.httpsurl,
  172.                 null,               // this.httpstipologia
  173.                 false,  // this.httpshostverify,
  174.                 ConnettoriCostanti.DEFAULT_CONNETTORE_HTTPS_TRUST_VERIFY_CERTS, // httpsTrustVerifyCert
  175.                 null,               // this.httpspath
  176.                 null,   // this.httpstipo,
  177.                 null,           // this.httpspwd,
  178.                 null,                   // this.httpsalgoritmo
  179.                 false,
  180.                 null,           // this.httpskeystore,
  181.                 "",                                                                 //  this.httpspwdprivatekeytrust
  182.                 null,               // pathkey
  183.                 null,       // this.httpstipokey
  184.                 null,           // this.httpspwdkey
  185.                 null,               // this.httpspwdprivatekey,  
  186.                 null,               // this.httpsalgoritmokey,
  187.                 null,                   // httpsKeyAlias
  188.                 null,                   // httpsTrustStoreCRLs
  189.                 null,                   // httpsTrustStoreOCSPPolicy
  190.                 null,                   // httpsKeyStoreBYOKPolicy
  191.            
  192.                 ServletUtils.boolToCheckBoxStatus( false ),
  193.                 null,
  194.                 null,
  195.                 null,
  196.                 null,
  197.                
  198.                 ServletUtils.boolToCheckBoxStatus( false ),
  199.                 null,   // this.tempiRisposta_connectionTimeout,
  200.                 null, //null,   // this.tempiRisposta_readTimeout,
  201.                 null,   // this.tempiRisposta_tempoMedioRisposta,
  202.                 "no",   // this.opzioniAvanzate,
  203.                 "",     // this.transfer_mode,
  204.                 "",     // this.transfer_mode_chunk_size,
  205.                 "",     // this.redirect_mode,
  206.                 "",     // this.redirect_max_hop,
  207.                 null,   // this.requestOutputFileName,
  208.                 null,   // this.requestOutputFileName_permissions
  209.                 null,   // this.requestOutputFileNameHeaders,
  210.                 null,   // this.requestOutputFileNameHeaders_permissions
  211.                 null,   // this.requestOutputParentDirCreateIfNotExists,
  212.                 null,   // this.requestOutputOverwriteIfExists,
  213.                 null,   // this.responseInputMode,
  214.                 null,   // this.responseInputFileName,
  215.                 null,   // this.responseInputFileNameHeaders,
  216.                 null,   // this.responseInputDeleteAfterRead,
  217.                 null,   // this.responseInputWaitTime,
  218.                 null,   // tokenPolicy
  219.                 null, null, // apiKeyHeader,  apiKeyValue
  220.                 null, null, // appIdHeader, appIdValue
  221.                 params, // connettoreStatusParams
  222.                 null // listExtendedConnettore
  223.                 );      
  224.         return regConnettore;
  225.     }

  226.     @Override
  227.     public ConnettoreStatus buildConnettore(Map<String, String> props, String tipo) {
  228.         String verificaConnettivita = props.get(CostantiDB.CONNETTORE_STATUS_TEST_CONNECTIVITY);
  229.         String statusResponseType = props.get(CostantiDB.CONNETTORE_STATUS_RESPONSE_TYPE);
  230.         String period = props.get(CostantiDB.CONNETTORE_STATUS_STATISTICAL_PERIOD);
  231.         String periodValue = props.get(CostantiDB.CONNETTORE_STATUS_STATISTICAL_PERIOD_VALUE);
  232.         String cacheLifetime = props.get(CostantiDB.CONNETTORE_STATUS_STAT_LIFETIME);
  233.         String debug = props.get(CostantiDB.CONNETTORE_DEBUG);
  234.        
  235.         ConnettoreStatusVerificaStatistica verificaStatistica = null;
  236.        
  237.         if (period != null) {
  238.             verificaStatistica = new ConnettoreStatusVerificaStatistica()
  239.                     .intervallo(Integer.valueOf(periodValue))
  240.                     .frequenza(TipoPeriodoStatisticoEnum.fromValue(period))
  241.                     .cacheLifeTime(cacheLifetime == null ? null : Integer.valueOf(cacheLifetime));
  242.         }
  243.        
  244.         return new ConnettoreStatus()
  245.                 .tipo(ConnettoreEnum.STATUS)
  246.                 .risposta(TipoRispostaStatusEnum.fromValue(statusResponseType))
  247.                 .debug(Objects.requireNonNullElse(debug, Boolean.FALSE).equals(Boolean.TRUE))
  248.                 .verificaConnettivita(Objects.requireNonNullElse(verificaConnettivita, Boolean.FALSE).equals(Boolean.TRUE))
  249.                 .verificaStatistica(verificaStatistica);
  250.     }

  251.     @Override
  252.     public String getUrlConnettore(Map<String, String> props, String tipoConnettore) throws Exception {
  253.         return "[status] govway://status";
  254.     }

  255.     @Override
  256.     protected ConnettoreStatus getConnettore(OneOfConnettoreErogazioneConnettore conn) throws Exception {
  257.         return (ConnettoreStatus) conn;
  258.     }

  259.     @Override
  260.     protected ConnettoreStatus getConnettore(OneOfConnettoreFruizioneConnettore conn) throws Exception {
  261.         return (ConnettoreStatus) conn;
  262.     }

  263.     @Override
  264.     protected ConnettoreStatus getConnettore(OneOfApplicativoServerConnettore conn) throws Exception {
  265.         return (ConnettoreStatus) conn;
  266.     }

  267. }