SubscriptionUtils.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.mapping;

  21. import org.openspcoop2.core.config.PortaDelegata;
  22. import org.openspcoop2.core.config.PortaDelegataAzione;
  23. import org.openspcoop2.core.config.PortaDelegataServizio;
  24. import org.openspcoop2.core.config.PortaDelegataSoggettoErogatore;
  25. import org.openspcoop2.core.config.constants.PortaDelegataAzioneIdentificazione;
  26. import org.openspcoop2.core.config.constants.StatoFunzionalita;
  27. import org.openspcoop2.core.constants.Costanti;
  28. import org.openspcoop2.core.id.IDPortaDelegata;
  29. import org.openspcoop2.core.id.IDServizio;
  30. import org.openspcoop2.core.id.IDSoggetto;
  31. import org.openspcoop2.core.id.IdentificativiFruizione;

  32. /**
  33.  * SubscriptionUtils
  34.  *
  35.  *
  36.  * @author Poli Andrea (apoli@link.it)
  37.  * @author $Author$
  38.  * @version $Rev$, $Date$
  39.  */

  40. public class SubscriptionUtils {

  41.     public static IDPortaDelegata setCommonParameter(PortaDelegata portaDelegata,
  42.             IDSoggetto idFruitore, IDServizio idServizio, boolean setDatiServizio, boolean portaClonata) {
  43.        
  44.         portaDelegata.setTipoSoggettoProprietario(idFruitore.getTipo());
  45.         portaDelegata.setNomeSoggettoProprietario(idFruitore.getNome());
  46.        
  47.         if(setDatiServizio) {
  48.             PortaDelegataSoggettoErogatore pdSogg = new PortaDelegataSoggettoErogatore();
  49.             pdSogg.setTipo(idServizio.getSoggettoErogatore().getTipo());
  50.             pdSogg.setNome(idServizio.getSoggettoErogatore().getNome());
  51.             portaDelegata.setSoggettoErogatore(pdSogg);
  52.    
  53.             PortaDelegataServizio pdServizio = new PortaDelegataServizio();
  54.             pdServizio.setTipo(idServizio.getTipo());
  55.             pdServizio.setNome(idServizio.getNome());
  56.             pdServizio.setVersione(idServizio.getVersione());
  57.             portaDelegata.setServizio(pdServizio);
  58.         }
  59.        
  60.         portaDelegata.setStato(StatoFunzionalita.ABILITATO);
  61.        
  62.         if(!portaClonata) {
  63.             portaDelegata.setRicevutaAsincronaAsimmetrica(StatoFunzionalita.ABILITATO);
  64.             portaDelegata.setRicevutaAsincronaSimmetrica(StatoFunzionalita.ABILITATO);
  65.            
  66.             portaDelegata.setAllegaBody(StatoFunzionalita.DISABILITATO);
  67.             portaDelegata.setScartaBody(StatoFunzionalita.DISABILITATO);
  68.            
  69.             portaDelegata.setStatoMessageSecurity(StatoFunzionalita.DISABILITATO.toString());
  70.         }
  71.        
  72.         IDPortaDelegata idPortaDelegata = new IDPortaDelegata();
  73.         idPortaDelegata.setNome(portaDelegata.getNome());
  74.         IdentificativiFruizione identificativiFruizione = new IdentificativiFruizione();
  75.         identificativiFruizione.setIdServizio(idServizio);
  76.         identificativiFruizione.setSoggettoFruitore(idFruitore);
  77.         idPortaDelegata.setIdentificativiFruizione(identificativiFruizione);
  78.        
  79.         return idPortaDelegata;
  80.     }
  81.    
  82.     public static void setAzioneDelegate(PortaDelegata portaDelegata, String nomePortaDelegante, String ... azione) {
  83.         PortaDelegataAzione pda = new PortaDelegataAzione();
  84.         pda.setIdentificazione(PortaDelegataAzioneIdentificazione.DELEGATED_BY);
  85.         pda.setNomePortaDelegante(nomePortaDelegante);
  86.         for (int i = 0; i < azione.length; i++) {
  87.             pda.addAzioneDelegata(azione[i]);
  88.         }
  89.         portaDelegata.setAzione(pda);
  90.        
  91.         portaDelegata.setRicercaPortaAzioneDelegata(StatoFunzionalita.DISABILITATO);
  92.     }
  93.    
  94.     public static MappingFruizionePortaDelegata createMappingDefault(IDSoggetto idFruitore, IDServizio idServizio,IDPortaDelegata idPortaDelegata) {
  95.         MappingFruizionePortaDelegata mappingFruizione = _creteMapping(idFruitore, idServizio, idPortaDelegata);
  96.         mappingFruizione.setDefault(true);
  97.         mappingFruizione.setNome(getDefaultMappingName());
  98.         mappingFruizione.setDescrizione(getDefaultMappingDescription());
  99.         return mappingFruizione;
  100.     }
  101.     public static MappingFruizionePortaDelegata createMapping(IDSoggetto idFruitore, IDServizio idServizio,IDPortaDelegata idPortaDelegata, String ruleName, String description) {
  102.         MappingFruizionePortaDelegata mappingFruizione = _creteMapping(idFruitore, idServizio, idPortaDelegata);
  103.         mappingFruizione.setDefault(false);
  104.         mappingFruizione.setNome(ruleName);
  105.         mappingFruizione.setDescrizione(description);
  106.         return mappingFruizione;
  107.     }
  108.     private static MappingFruizionePortaDelegata _creteMapping(IDSoggetto idFruitore, IDServizio idServizio,IDPortaDelegata idPortaDelegata) {
  109.         MappingFruizionePortaDelegata mappingFruizione = new MappingFruizionePortaDelegata();
  110.         mappingFruizione.setIdFruitore(idFruitore);
  111.         mappingFruizione.setIdServizio(idServizio);
  112.         mappingFruizione.setIdPortaDelegata(idPortaDelegata);
  113.         return mappingFruizione;
  114.     }
  115.    
  116.     public static boolean isPortaDelegataUtilizzabileComeDefault(PortaDelegata pa) {
  117.         if( (pa.getAzione()==null) ||
  118.                 (
  119.                         !PortaDelegataAzioneIdentificazione.DELEGATED_BY.equals(pa.getAzione().getIdentificazione())
  120.                         &&
  121.                         (pa.getAzione().getNome()==null || "".equals(pa.getAzione().getNome()))
  122.                         &&
  123.                         (pa.getRicercaPortaAzioneDelegata()==null || StatoFunzionalita.ABILITATO.equals(pa.getRicercaPortaAzioneDelegata()))
  124.                 )
  125.             ){
  126.             return true;
  127.         }
  128.         return false;
  129.     }
  130.     public static String getDefaultMappingName() {
  131.         return Costanti.MAPPING_FRUIZIONE_PD_NOME_DEFAULT;
  132.     }
  133.     public static String getDefaultMappingDescription() {
  134.         return Costanti.MAPPING_FRUIZIONE_PD_DESCRIZIONE_DEFAULT;
  135.     }
  136.    
  137. }