AbstractIntegrationConfiguration.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.protocol.basic.config;

  21. import java.util.List;

  22. import org.openspcoop2.core.id.IDServizio;
  23. import org.openspcoop2.core.id.IDSoggetto;
  24. import org.openspcoop2.protocol.manifest.IntegrationConfiguration;
  25. import org.openspcoop2.protocol.manifest.IntegrationConfigurationElementName;
  26. import org.openspcoop2.protocol.sdk.ProtocolException;

  27. /**
  28.  * AbstractIntegrationConfiguration
  29.  *
  30.  *
  31.  * @author Poli Andrea (apoli@link.it)
  32.  * @author $Author$
  33.  * @version $Rev$, $Date$
  34.  */

  35. public abstract class AbstractIntegrationConfiguration implements java.io.Serializable {

  36.     /**
  37.      *
  38.      */
  39.     private static final long serialVersionUID = 1L;
  40.    
  41.     protected IntegrationConfiguration integrationConfiguration;
  42.    
  43.     protected AbstractIntegrationConfiguration(IntegrationConfiguration integrationConfiguration) {
  44.         this.integrationConfiguration = integrationConfiguration;
  45.     }
  46.    
  47.     protected boolean useInterfaceNameInInvocationURL() {
  48.         return this.integrationConfiguration.getName().isUseInUrl();
  49.     }
  50.    
  51.     protected String getNome(IDServizio idServizio, IDSoggetto idSoggetto, String name, String ruleName,
  52.             List<IntegrationConfigurationElementName> list) throws ProtocolException {
  53.         StringBuilder bf = new StringBuilder();
  54.         for (IntegrationConfigurationElementName integrationConfigurationElementName : list) {
  55.             if(integrationConfigurationElementName.getPrefix()!=null && !"".equals(integrationConfigurationElementName.getPrefix())) {
  56.                 bf.append(integrationConfigurationElementName.getPrefix());
  57.             }
  58.             if(integrationConfigurationElementName.getActor()!=null) {
  59.                 switch (integrationConfigurationElementName.getActor()) {
  60.                 case SUBSCRIBER_TYPE:
  61.                     if(idSoggetto==null || idSoggetto.getTipo()==null) {
  62.                         throw new ProtocolException("Subscriber type undefined");
  63.                     }
  64.                     bf.append(idSoggetto.getTipo());
  65.                     break;
  66.                 case SUBSCRIBER_NAME:
  67.                     if(idSoggetto==null || idSoggetto.getNome()==null) {
  68.                         throw new ProtocolException("Subscriber name undefined");
  69.                     }
  70.                     bf.append(idSoggetto.getNome());
  71.                     break;
  72.                 case PROVIDER_TYPE:
  73.                     if(idServizio==null || idServizio.getSoggettoErogatore()==null || idServizio.getSoggettoErogatore().getTipo()==null) {
  74.                         throw new ProtocolException("Provider type undefined");
  75.                     }
  76.                     bf.append(idServizio.getSoggettoErogatore().getTipo());
  77.                     break;
  78.                 case PROVIDER_NAME:
  79.                     if(idServizio==null || idServizio.getSoggettoErogatore()==null || idServizio.getSoggettoErogatore().getNome()==null) {
  80.                         throw new ProtocolException("Provider name undefined");
  81.                     }
  82.                     bf.append(idServizio.getSoggettoErogatore().getNome());
  83.                     break;
  84.                 case SERVICE_TYPE:
  85.                     if(idServizio==null || idServizio.getTipo()==null) {
  86.                         throw new ProtocolException("Service type undefined");
  87.                     }
  88.                     bf.append(idServizio.getTipo());
  89.                     break;
  90.                 case SERVICE_NAME:
  91.                     if(idServizio==null || idServizio.getNome()==null) {
  92.                         throw new ProtocolException("Service name undefined");
  93.                     }
  94.                     bf.append(idServizio.getNome());
  95.                     break;
  96.                 case SERVICE_VERSION:
  97.                     if(idServizio==null || idServizio.getVersione()==null) {
  98.                         throw new ProtocolException("Service version undefined");
  99.                     }
  100.                     bf.append(idServizio.getVersione().intValue()+"");
  101.                     break;
  102.                 case NAME:
  103.                     if(name==null) {
  104.                         throw new ProtocolException("Name undefined");
  105.                     }
  106.                     bf.append(name);
  107.                     break;
  108.                 case RULE_NAME:
  109.                     if(ruleName==null) {
  110.                         throw new ProtocolException("Rule name undefined");
  111.                     }
  112.                     bf.append(ruleName);
  113.                     break;
  114.                 }
  115.             }
  116.             if(integrationConfigurationElementName.getSuffix()!=null && !"".equals(integrationConfigurationElementName.getSuffix())) {
  117.                 bf.append(integrationConfigurationElementName.getSuffix());
  118.             }
  119.         }
  120.         return bf.toString();
  121.     }

  122. }