BasicProtocolIntegrationConfiguration.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.config.PortaApplicativa;
  23. import org.openspcoop2.core.config.PortaDelegata;
  24. import org.openspcoop2.core.config.constants.PortaApplicativaAzioneIdentificazione;
  25. import org.openspcoop2.core.config.constants.PortaDelegataAzioneIdentificazione;
  26. import org.openspcoop2.core.id.IDServizio;
  27. import org.openspcoop2.core.id.IDSoggetto;
  28. import org.openspcoop2.message.constants.ServiceBinding;
  29. import org.openspcoop2.protocol.basic.BasicComponentFactory;
  30. import org.openspcoop2.protocol.sdk.IProtocolFactory;
  31. import org.openspcoop2.protocol.sdk.ProtocolException;
  32. import org.openspcoop2.protocol.sdk.config.ProtocolImplementation;
  33. import org.openspcoop2.protocol.sdk.config.ProtocolSubscription;
  34. import org.openspcoop2.protocol.sdk.constants.ConsoleInterfaceType;
  35. import org.openspcoop2.protocol.sdk.registry.IConfigIntegrationReader;

  36. /**
  37.  * Classe che implementa, l'interfaccia {@link org.openspcoop2.protocol.sdk.config.IProtocolConfiguration}
  38.  *
  39.  * @author Poli Andrea (apoli@link.it)
  40.  * @author $Author$
  41.  * @version $Rev$, $Date$
  42.  */
  43. public class BasicProtocolIntegrationConfiguration extends BasicComponentFactory implements org.openspcoop2.protocol.sdk.config.IProtocolIntegrationConfiguration {

  44.     private ImplementationConfiguration implementationConfigurationRest;
  45.     private ImplementationConfiguration implementationConfigurationSoap;
  46.     private SubscriptionConfiguration subscriptionConfigurationRest;
  47.     private SubscriptionConfiguration subscriptionConfigurationSoap;

  48.     public BasicProtocolIntegrationConfiguration(IProtocolFactory<?> factory) throws ProtocolException {
  49.         super(factory);
  50.         if(this.protocolFactory.getManifest().getBinding().getRest()!=null) {
  51.             this.implementationConfigurationRest = new ImplementationConfiguration(this.protocolFactory.getManifest().getBinding().getRest().getIntegration().getImplementation());
  52.             this.subscriptionConfigurationRest = new SubscriptionConfiguration(this.protocolFactory.getManifest().getBinding().getRest().getIntegration().getSubscription());
  53.         }
  54.         if(this.protocolFactory.getManifest().getBinding().getSoap()!=null) {
  55.             this.implementationConfigurationSoap = new ImplementationConfiguration(this.protocolFactory.getManifest().getBinding().getSoap().getIntegration().getImplementation());
  56.             this.subscriptionConfigurationSoap = new SubscriptionConfiguration(this.protocolFactory.getManifest().getBinding().getSoap().getIntegration().getSubscription());
  57.         }
  58.     }

  59.     // SUBSCRIPTION
  60.    
  61.     @Override
  62.     public ProtocolSubscription createDefaultSubscription(ServiceBinding serviceBinding, IDSoggetto idFruitore, IDServizio idServizio) throws ProtocolException{
  63.         if(serviceBinding==null){
  64.             throw new ProtocolException("Service Binding undefined");
  65.         }
  66.         switch (serviceBinding) {
  67.         case REST:
  68.             if(this.subscriptionConfigurationRest==null) {
  69.                 throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  70.             }
  71.             return this.subscriptionConfigurationRest.createDefaultSubscription(idFruitore, idServizio);
  72.         case SOAP:
  73.             if(this.subscriptionConfigurationSoap==null) {
  74.                 throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  75.             }
  76.             return this.subscriptionConfigurationSoap.createDefaultSubscription(idFruitore, idServizio);
  77.         }
  78.         throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  79.     }
  80.    
  81.     @Override
  82.     public ProtocolSubscription createSubscription(IConfigIntegrationReader configIntegrationReader, ServiceBinding serviceBinding, IDSoggetto idFruitore, IDServizio idServizio,
  83.             PortaDelegata portaDelegataDefault,
  84.             String ruleName, String description, String ... azione ) throws ProtocolException{
  85.         return this.createSubscription(configIntegrationReader, serviceBinding, idFruitore, idServizio,
  86.                 portaDelegataDefault, null,
  87.                 ruleName, description, azione);
  88.     }
  89.     @Override
  90.     public ProtocolSubscription createSubscription(IConfigIntegrationReader confiIntegrationReader, ServiceBinding serviceBinding, IDSoggetto idFruitore, IDServizio idServizio,
  91.             PortaDelegata portaDelegataDefault, PortaDelegata portaDelegataDaCopiare,
  92.             String ruleName, String description, String ... azione ) throws ProtocolException{
  93.         if(serviceBinding==null){
  94.             throw new ProtocolException("Service Binding undefined");
  95.         }
  96.         switch (serviceBinding) {
  97.         case REST:
  98.             if(this.subscriptionConfigurationRest==null) {
  99.                 throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  100.             }
  101.             return this.subscriptionConfigurationRest.createSubscription(confiIntegrationReader, idFruitore, idServizio, portaDelegataDefault, portaDelegataDaCopiare, ruleName, description, azione);
  102.         case SOAP:
  103.             if(this.subscriptionConfigurationSoap==null) {
  104.                 throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  105.             }
  106.             return this.subscriptionConfigurationSoap.createSubscription(confiIntegrationReader,idFruitore, idServizio, portaDelegataDefault, portaDelegataDaCopiare, ruleName, description, azione);
  107.         }
  108.         throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  109.     }
  110.    
  111.     @Override
  112.     public List<PortaDelegataAzioneIdentificazione> getAllSubscriptionIdentificationResourceModes(ServiceBinding serviceBinding, ConsoleInterfaceType consoleType) throws ProtocolException{
  113.         if(serviceBinding==null){
  114.             throw new ProtocolException("Service Binding undefined");
  115.         }
  116.         switch (serviceBinding) {
  117.         case REST:
  118.             if(this.subscriptionConfigurationRest==null) {
  119.                 throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  120.             }
  121.             return this.subscriptionConfigurationRest.supportedIdentificationModes(consoleType);
  122.         case SOAP:
  123.             if(this.subscriptionConfigurationSoap==null) {
  124.                 throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  125.             }
  126.             return this.subscriptionConfigurationSoap.supportedIdentificationModes(consoleType);
  127.         }
  128.         throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  129.     }
  130.    
  131.     @Override
  132.     public boolean useInterfaceNameInSubscriptionInvocationURL(ServiceBinding serviceBinding) throws ProtocolException{
  133.         switch (serviceBinding) {
  134.         case REST:
  135.             if(this.subscriptionConfigurationRest==null) {
  136.                 throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  137.             }
  138.             return this.subscriptionConfigurationRest.useInterfaceNameInInvocationURL();
  139.         case SOAP:
  140.             if(this.subscriptionConfigurationSoap==null) {
  141.                 throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  142.             }
  143.             return this.subscriptionConfigurationSoap.useInterfaceNameInInvocationURL();
  144.         }
  145.         throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  146.     }
  147.    
  148.    
  149.     // IMPLEMENTATION
  150.    
  151.     @Override
  152.     public ProtocolImplementation createDefaultImplementation(ServiceBinding serviceBinding, IDServizio idServizio) throws ProtocolException{
  153.         if(serviceBinding==null){
  154.             throw new ProtocolException("Service Binding undefined");
  155.         }
  156.         switch (serviceBinding) {
  157.         case REST:
  158.             if(this.implementationConfigurationRest==null) {
  159.                 throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  160.             }
  161.             return this.implementationConfigurationRest.createDefaultImplementation(idServizio);
  162.         case SOAP:
  163.             if(this.implementationConfigurationSoap==null) {
  164.                 throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  165.             }
  166.             return this.implementationConfigurationSoap.createDefaultImplementation(idServizio);
  167.         }
  168.         throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  169.     }
  170.    
  171.     @Override
  172.     public ProtocolImplementation createImplementation(IConfigIntegrationReader configIntegrationReader,ServiceBinding serviceBinding, IDServizio idServizio,
  173.             PortaApplicativa portaApplicativaDefault,
  174.             String ruleName, String description, String ... azione ) throws ProtocolException{
  175.         return this.createImplementation(configIntegrationReader,serviceBinding, idServizio,
  176.                 portaApplicativaDefault, null,
  177.                 ruleName, description, azione);
  178.     }
  179.     @Override
  180.     public ProtocolImplementation createImplementation(IConfigIntegrationReader configIntegrationReader,ServiceBinding serviceBinding, IDServizio idServizio,
  181.             PortaApplicativa portaApplicativaDefault, PortaApplicativa portaApplicativaDaCopiare,
  182.             String ruleName, String description, String ... azione ) throws ProtocolException{
  183.         if(serviceBinding==null){
  184.             throw new ProtocolException("Service Binding undefined");
  185.         }
  186.         switch (serviceBinding) {
  187.         case REST:
  188.             if(this.implementationConfigurationRest==null) {
  189.                 throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  190.             }
  191.             return this.implementationConfigurationRest.createImplementation(configIntegrationReader,idServizio, portaApplicativaDefault, portaApplicativaDaCopiare, ruleName, description, azione);
  192.         case SOAP:
  193.             if(this.implementationConfigurationSoap==null) {
  194.                 throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  195.             }
  196.             return this.implementationConfigurationSoap.createImplementation(configIntegrationReader,idServizio, portaApplicativaDefault, portaApplicativaDaCopiare, ruleName, description, azione);
  197.         }
  198.         throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  199.     }
  200.    
  201.     @Override
  202.     public List<PortaApplicativaAzioneIdentificazione> getAllImplementationIdentificationResourceModes(ServiceBinding serviceBinding, ConsoleInterfaceType consoleType) throws ProtocolException{
  203.         if(serviceBinding==null){
  204.             throw new ProtocolException("Service Binding undefined");
  205.         }
  206.         switch (serviceBinding) {
  207.         case REST:
  208.             if(this.implementationConfigurationRest==null) {
  209.                 throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  210.             }
  211.             return this.implementationConfigurationRest.supportedIdentificationModes(consoleType);
  212.         case SOAP:
  213.             if(this.implementationConfigurationSoap==null) {
  214.                 throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  215.             }
  216.             return this.implementationConfigurationSoap.supportedIdentificationModes(consoleType);
  217.         }
  218.         throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  219.     }
  220.    
  221.     @Override
  222.     public boolean useInterfaceNameInImplementationInvocationURL(ServiceBinding serviceBinding) throws ProtocolException{
  223.         switch (serviceBinding) {
  224.         case REST:
  225.             if(this.implementationConfigurationRest==null) {
  226.                 throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  227.             }
  228.             return this.implementationConfigurationRest.useInterfaceNameInInvocationURL();
  229.         case SOAP:
  230.             if(this.implementationConfigurationSoap==null) {
  231.                 throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  232.             }
  233.             return this.implementationConfigurationSoap.useInterfaceNameInInvocationURL();
  234.         }
  235.         throw new ProtocolException("Service Binding '"+serviceBinding+"' unsupported");
  236.     }
  237.    
  238. }