AbstractConnettoreApiHelper.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 static org.openspcoop2.utils.service.beans.utils.BaseHelper.evalnull;

  22. import java.util.Map;

  23. import org.apache.commons.lang3.StringUtils;
  24. import org.openspcoop2.core.config.ServizioApplicativo;
  25. import org.openspcoop2.core.config.rs.server.model.ConnettoreConfigurazioneHttpBasic;
  26. import org.openspcoop2.core.config.rs.server.model.ConnettoreHttp;
  27. import org.openspcoop2.core.config.rs.server.model.OneOfApplicativoServerConnettore;
  28. import org.openspcoop2.core.config.rs.server.model.OneOfConnettoreErogazioneConnettore;
  29. import org.openspcoop2.core.config.rs.server.model.OneOfConnettoreFruizioneConnettore;

  30. /**
  31.  * AbstractConnettoreApiHelper
  32.  *
  33.  * @author $Author$
  34.  * @version $Rev$, $Date$
  35.  *
  36.  */
  37. public abstract class AbstractConnettoreApiHelper<T> implements IConnettoreApiHelper {

  38.     protected abstract T getConnettore(OneOfConnettoreErogazioneConnettore conn) throws Exception;
  39.     protected abstract T getConnettore(OneOfConnettoreFruizioneConnettore conn) throws Exception;
  40.     protected abstract T getConnettore(OneOfApplicativoServerConnettore conn) throws Exception;

  41.     protected abstract org.openspcoop2.core.registry.Connettore fillConnettoreRegistro(org.openspcoop2.core.registry.Connettore regConnettore, ErogazioniEnv env, T connettore, String oldConnT) throws Exception;
  42.     protected abstract org.openspcoop2.core.config.Connettore buildConnettoreConfigurazione(org.openspcoop2.core.config.Connettore regConnettore, ErogazioniEnv env, T connettore, String oldConnT) throws Exception;

  43.     protected org.openspcoop2.core.config.Connettore buildConnettoreConfigurazione(ServizioApplicativo sa, ErogazioniEnv env, T connettore, String oldConnT) throws Exception {
  44.         return buildConnettoreConfigurazione(sa.getInvocazioneServizio().getConnettore(), env, connettore, oldConnT);
  45.     }
  46.    
  47.     protected abstract boolean connettoreCheckData(T conn, ErogazioniEnv env, boolean erogazione) throws Exception;
  48.    
  49.     protected abstract T buildConnettore(Map<String, String> props, String tipo) throws Exception;
  50.     protected T buildConnettore(ServizioApplicativo sa) throws Exception {
  51.         T connettore = buildConnettore(sa.getInvocazioneServizio().getConnettore().getProperties(),sa.getInvocazioneServizio().getConnettore().getTipo());
  52.         if(sa.getInvocazioneServizio().getCredenziali()!=null &&
  53.                 sa.getInvocazioneServizio().getCredenziali().getUser()!=null &&
  54.                 sa.getInvocazioneServizio().getCredenziali().getPassword()!=null &&
  55.                 connettore instanceof ConnettoreHttp) {
  56.             ConnettoreHttp c = (ConnettoreHttp) connettore;
  57.        
  58.             ConnettoreConfigurazioneHttpBasic http = new ConnettoreConfigurazioneHttpBasic();
  59.             http.setPassword(evalnull( () -> sa.getInvocazioneServizio().getCredenziali().getPassword()));
  60.             http.setUsername(evalnull( () -> sa.getInvocazioneServizio().getCredenziali().getUser()));
  61.             if ( !StringUtils.isAllEmpty(http.getPassword(), http.getUsername()) ) {
  62.                 c.setAutenticazioneHttp(http);
  63.             }
  64.         }
  65.         return connettore;
  66.     }

  67.     @Override
  68.     public OneOfConnettoreErogazioneConnettore buildConnettoreErogazione(ServizioApplicativo sa) throws Exception {
  69.         return (OneOfConnettoreErogazioneConnettore) buildConnettore(sa);
  70.     }

  71.     @Override
  72.     public OneOfConnettoreFruizioneConnettore buildConnettoreFruizione(Map<String, String> props, String tipo) throws Exception {
  73.         return (OneOfConnettoreFruizioneConnettore) buildConnettore(props, tipo);
  74.     }
  75.    
  76.     @Override
  77.     public OneOfApplicativoServerConnettore buildConnettoreApplicativoServer(ServizioApplicativo sa) throws Exception {
  78.         return (OneOfApplicativoServerConnettore) buildConnettore(sa);
  79.     }

  80.     @Override
  81.     public boolean connettoreCheckData(OneOfConnettoreFruizioneConnettore conn, ErogazioniEnv env, boolean isErogazione) throws Exception {
  82.         return connettoreCheckData(getConnettore(conn), env, isErogazione);
  83.     }

  84.     @Override
  85.     public boolean connettoreCheckData(OneOfConnettoreErogazioneConnettore conn, ErogazioniEnv env, boolean isErogazione) throws Exception {
  86.         return connettoreCheckData(getConnettore(conn), env, isErogazione);
  87.     }

  88.     @Override
  89.     public boolean connettoreCheckData(OneOfApplicativoServerConnettore conn, ErogazioniEnv env, boolean isErogazione) throws Exception {
  90.         return connettoreCheckData(getConnettore(conn), env, isErogazione);
  91.     }

  92.     @Override
  93.     public org.openspcoop2.core.registry.Connettore buildConnettoreRegistro(ErogazioniEnv env,
  94.             OneOfConnettoreFruizioneConnettore conn) throws Exception {
  95.         org.openspcoop2.core.registry.Connettore regConnettore = new org.openspcoop2.core.registry.Connettore();
  96.         return fillConnettoreRegistro(regConnettore, env, getConnettore(conn), "");
  97.     }

  98.     @Override
  99.     public org.openspcoop2.core.registry.Connettore buildConnettoreRegistro(ErogazioniEnv env,
  100.             OneOfConnettoreErogazioneConnettore conn) throws Exception {
  101.         org.openspcoop2.core.registry.Connettore regConnettore = new org.openspcoop2.core.registry.Connettore();
  102.         return fillConnettoreRegistro(regConnettore, env, getConnettore(conn), "");
  103.     }

  104.     @Override
  105.     public org.openspcoop2.core.registry.Connettore buildConnettoreRegistro(ErogazioniEnv env,
  106.             OneOfApplicativoServerConnettore conn) throws Exception {
  107.         org.openspcoop2.core.registry.Connettore regConnettore = new org.openspcoop2.core.registry.Connettore();
  108.         return fillConnettoreRegistro(regConnettore, env, getConnettore(conn), "");
  109.     }

  110.     @Override
  111.     public org.openspcoop2.core.config.Connettore buildConnettoreConfigurazione(
  112.             org.openspcoop2.core.config.Connettore regConnettore, ErogazioniEnv env, OneOfConnettoreFruizioneConnettore conn,
  113.             String oldConnT) throws Exception {
  114.         return buildConnettoreConfigurazione(regConnettore, env, getConnettore(conn), oldConnT);

  115.     }

  116.     @Override
  117.     public org.openspcoop2.core.config.Connettore buildConnettoreConfigurazione(
  118.             ServizioApplicativo sa, ErogazioniEnv env, OneOfConnettoreErogazioneConnettore conn,
  119.             String oldConnT) throws Exception {
  120.         return buildConnettoreConfigurazione(sa, env, getConnettore(conn), oldConnT);

  121.     }

  122.     @Override
  123.     public org.openspcoop2.core.config.Connettore buildConnettoreConfigurazione(
  124.             ServizioApplicativo sa, ErogazioniEnv env, OneOfApplicativoServerConnettore conn,
  125.             String oldConnT) throws Exception {
  126.         return buildConnettoreConfigurazione(sa, env, getConnettore(conn), oldConnT);

  127.     }

  128.     @Override
  129.     public org.openspcoop2.core.registry.Connettore fillConnettoreRegistro(
  130.             org.openspcoop2.core.registry.Connettore regConnettore, ErogazioniEnv env, OneOfConnettoreFruizioneConnettore conn,
  131.             String oldConnT) throws Exception {
  132.         return fillConnettoreRegistro(regConnettore, env, getConnettore(conn), oldConnT);

  133.     }

  134.     @Override
  135.     public org.openspcoop2.core.registry.Connettore fillConnettoreRegistro(
  136.             org.openspcoop2.core.registry.Connettore regConnettore, ErogazioniEnv env, OneOfConnettoreErogazioneConnettore conn,
  137.             String oldConnT) throws Exception {
  138.         return fillConnettoreRegistro(regConnettore, env, getConnettore(conn), oldConnT);

  139.     }

  140.     @Override
  141.     public org.openspcoop2.core.registry.Connettore fillConnettoreRegistro(
  142.             org.openspcoop2.core.registry.Connettore regConnettore, ErogazioniEnv env, OneOfApplicativoServerConnettore conn,
  143.             String oldConnT) throws Exception {
  144.         return fillConnettoreRegistro(regConnettore, env, getConnettore(conn), oldConnT);

  145.     }


  146. }