ModiSoggettiApiHelper.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.soggetti;

  21. import java.util.Map;

  22. import org.apache.commons.lang.StringUtils;
  23. import org.openspcoop2.core.commons.CoreException;
  24. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  25. import org.openspcoop2.core.config.rs.server.api.impl.ProtocolPropertiesHelper;
  26. import org.openspcoop2.core.config.rs.server.model.DominioEnum;
  27. import org.openspcoop2.core.config.rs.server.model.ModISoggetto;
  28. import org.openspcoop2.core.config.rs.server.model.ModISoggettoPDND;
  29. import org.openspcoop2.core.config.rs.server.model.TracciamentoPDNDSoggettoEnum;
  30. import org.openspcoop2.core.constants.CostantiDB;
  31. import org.openspcoop2.core.registry.Soggetto;
  32. import org.openspcoop2.protocol.sdk.ProtocolException;
  33. import org.openspcoop2.protocol.sdk.properties.AbstractProperty;
  34. import org.openspcoop2.protocol.sdk.properties.ProtocolProperties;
  35. import org.openspcoop2.utils.UtilsException;

  36. /**
  37.  * ModiApplicativiApiHelper
  38.  *
  39.  * @author $Author$
  40.  * @version $Rev$, $Date$
  41.  *
  42.  */
  43. public class ModiSoggettiApiHelper {
  44.    
  45.     private ModiSoggettiApiHelper() {}

  46.     public static ProtocolProperties getProtocolProperties(org.openspcoop2.core.config.rs.server.model.Soggetto body) throws ProtocolException {
  47.         /**     if(body.getModi() == null) {
  48.         //          throw FaultCode.RICHIESTA_NON_VALIDA.toException("Specificare la configurazione 'ModI'");
  49.         //      }*/

  50.         ProtocolProperties p = new ProtocolProperties();

  51.         if(body.getModi() != null && body.getModi().getPdnd()!=null ) {
  52.             if(body.getModi().getPdnd().getIdEnte()!=null && StringUtils.isNotEmpty(body.getModi().getPdnd().getIdEnte())) {
  53.                 p.addProperty(CostantiDB.MODIPA_SOGGETTI_ID_ENTE_ID, body.getModi().getPdnd().getIdEnte());
  54.             }
  55.            
  56.             TracciamentoPDNDSoggettoEnum tracciamentoPdnd = body.getModi().getPdnd().getTracciamentoPdnd();
  57.             if (tracciamentoPdnd != null) {
  58.                
  59.                 if (DominioEnum.INTERNO.equals(body.getDominio())) {
  60.                     p.addProperty(CostantiDB.MODIPA_SOGGETTI_PDND_TRACING_ID, toTracciamentoPDNDSoggettoId(tracciamentoPdnd));
  61.                 } else {
  62.                     throw new ProtocolException("Il campo tracing_pdnd รจ valido solo per soggetti con dominio interno");
  63.                 }
  64.            
  65.             }
  66.         }
  67.        

  68.         return p;

  69.     }
  70.    


  71.     public static void initializePdnd(org.openspcoop2.core.config.rs.server.model.Soggetto ret) {
  72.         if(ret.getModi()==null) {
  73.             ret.setModi(new ModISoggetto());
  74.         }
  75.         if(ret.getModi().getPdnd()==null) {
  76.             ret.getModi().setPdnd(new  ModISoggettoPDND());
  77.         }
  78.     }
  79.    
  80.     public static void populateProtocolInfo(Soggetto soggetto, SoggettiEnv env, org.openspcoop2.core.config.rs.server.model.Soggetto ret) throws CoreException, UtilsException, ProtocolException, DriverConfigurazioneException {

  81.         Map<String, AbstractProperty<?>> p = SoggettiApiHelper.getProtocolPropertiesMap(soggetto, env);
  82.         String idEnte = ProtocolPropertiesHelper.getStringProperty(p, CostantiDB.MODIPA_SOGGETTI_ID_ENTE_ID, false);
  83.         if(idEnte != null && StringUtils.isNotEmpty(idEnte)) {
  84.             initializePdnd(ret);
  85.             ret.getModi().getPdnd().setIdEnte(idEnte);
  86.         }
  87.        
  88.         String tracciamentoPdnd = ProtocolPropertiesHelper.getStringProperty(p, CostantiDB.MODIPA_SOGGETTI_PDND_TRACING_ID, false);
  89.         if (tracciamentoPdnd != null && DominioEnum.INTERNO.equals(ret.getDominio())) {
  90.             initializePdnd(ret);
  91.             ret.getModi().getPdnd().setTracciamentoPdnd(toTracciamentoPDNDSoggettoEnum(tracciamentoPdnd));
  92.         }
  93.        
  94.     }
  95.    
  96.     private static TracciamentoPDNDSoggettoEnum toTracciamentoPDNDSoggettoEnum(String idValue) {
  97.         if (CostantiDB.MODIPA_SOGGETTI_PDND_TRACING_DISABLE_ID.equals(idValue))
  98.             return TracciamentoPDNDSoggettoEnum.DISABILITATO;
  99.         if (CostantiDB.MODIPA_SOGGETTI_PDND_TRACING_ENABLE_ID.equals(idValue))
  100.             return TracciamentoPDNDSoggettoEnum.ABILITATO;
  101.         return TracciamentoPDNDSoggettoEnum.DEFAULT;
  102.     }
  103.    
  104.     private static String toTracciamentoPDNDSoggettoId(TracciamentoPDNDSoggettoEnum enumValue) {
  105.         if (enumValue == null)
  106.             return  CostantiDB.MODIPA_SOGGETTI_PDND_TRACING_DEFAULT_ID;
  107.        
  108.         switch (enumValue) {
  109.         case ABILITATO: return CostantiDB.MODIPA_SOGGETTI_PDND_TRACING_ENABLE_ID;
  110.         case DEFAULT: return CostantiDB.MODIPA_SOGGETTI_PDND_TRACING_DEFAULT_ID;
  111.         case DISABILITATO: return CostantiDB.MODIPA_SOGGETTI_PDND_TRACING_DISABLE_ID;
  112.         }
  113.        
  114.         return CostantiDB.MODIPA_SOGGETTI_PDND_TRACING_DEFAULT_ID;
  115.     }

  116. }