ConsoleUtilities.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.web.ctrlstat.servlet;

  21. import java.text.MessageFormat;

  22. import org.openspcoop2.core.config.CorrelazioneApplicativa;
  23. import org.openspcoop2.core.config.CorrelazioneApplicativaElemento;
  24. import org.openspcoop2.core.config.CorrelazioneApplicativaRisposta;
  25. import org.openspcoop2.core.config.CorrelazioneApplicativaRispostaElemento;
  26. import org.openspcoop2.core.config.PortaApplicativa;
  27. import org.openspcoop2.core.config.PortaDelegata;
  28. import org.openspcoop2.core.config.driver.DriverConfigurazioneException;
  29. import org.openspcoop2.core.config.driver.DriverConfigurazioneNotFound;
  30. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  31. import org.openspcoop2.web.ctrlstat.servlet.pa.PorteApplicativeCore;
  32. import org.openspcoop2.web.ctrlstat.servlet.pd.PorteDelegateCore;

  33. /**
  34.  * ConsoleUtilities
  35.  *
  36.  * @author Andrea Poli (apoli@link.it)
  37.  * @author $Author$
  38.  * @version $Rev$, $Date$
  39.  *
  40.  */
  41. public class ConsoleUtilities {

  42.     public static boolean alreadyExistsCorrelazioneApplicativaRichiesta(PorteDelegateCore porteDelegateCore,
  43.             long idPorta, String elemento, long idCorrelazione,
  44.             StringBuilder existsMessage) throws DriverConfigurazioneNotFound, DriverConfigurazioneException {
  45.         return _alreadyExistsCorrelazioneApplicativaRichiesta(true, porteDelegateCore, null, idPorta, elemento, idCorrelazione, existsMessage);
  46.     }
  47.     public static boolean alreadyExistsCorrelazioneApplicativaRichiesta(PorteApplicativeCore porteApplicativeCore,
  48.             long idPorta, String elemento, long idCorrelazione,
  49.             StringBuilder existsMessage) throws DriverConfigurazioneNotFound, DriverConfigurazioneException {
  50.         return _alreadyExistsCorrelazioneApplicativaRichiesta(false, null, porteApplicativeCore, idPorta, elemento, idCorrelazione, existsMessage);
  51.     }
  52.     private static boolean _alreadyExistsCorrelazioneApplicativaRichiesta(boolean portaDelegata,
  53.             PorteDelegateCore porteDelegateCore, PorteApplicativeCore porteApplicativeCore,
  54.             long idPorta, String elemento, long idCorrelazione,
  55.             StringBuilder existsMessage) throws DriverConfigurazioneNotFound, DriverConfigurazioneException {
  56.         // Controllo che non esistano altre correlazioni applicative con gli
  57.         // stessi dati
  58.         boolean giaRegistrato = false;

  59.         long idCorrApp = 0;
  60.         CorrelazioneApplicativa ca = null;
  61.         String nomePorta = null;
  62.         if(portaDelegata){
  63.             PortaDelegata pde = null;
  64.             pde = porteDelegateCore.getPortaDelegata(idPorta);
  65.             ca = pde.getCorrelazioneApplicativa();
  66.             nomePorta = pde.getNome();
  67.         }else{
  68.             PortaApplicativa pda = null;
  69.             pda = porteApplicativeCore.getPortaApplicativa(idPorta);
  70.             ca = pda.getCorrelazioneApplicativa();
  71.             nomePorta = pda.getNome();
  72.         }
  73.         if (ca != null) {
  74.             for (int i = 0; i < ca.sizeElementoList(); i++) {
  75.                 CorrelazioneApplicativaElemento cae = ca.getElemento(i);
  76.                 String caeNome = cae.getNome();
  77.                 if (caeNome == null)
  78.                     caeNome = "";
  79.                 if (elemento.equals(caeNome) || ("*".equals(caeNome) && "".equals(elemento))) {
  80.                     idCorrApp = cae.getId().longValue();
  81.                     break;
  82.                 }
  83.             }
  84.         }

  85.         if ((idCorrApp != 0) && (idCorrApp != idCorrelazione)) {
  86.             giaRegistrato = true;
  87.         }

  88.         if (giaRegistrato) {
  89.             String nomeElemento = CostantiControlStation.LABEL_NON_DEFINITO;
  90.             if(elemento!=null && ("".equals(elemento)==false))
  91.                 nomeElemento = elemento;
  92.             String labelPorta = null;
  93.             if(portaDelegata)
  94.                 labelPorta = MessageFormat.format(CostantiControlStation.LABEL_PORTA_DELEGATA_CON_PARAMETRI, nomePorta);
  95.             else
  96.                 labelPorta = MessageFormat.format(CostantiControlStation.LABEL_PORTA_APPLICATIVA_CON_PARAMETRI, nomePorta);
  97.             existsMessage.append(MessageFormat.format(CostantiControlStation.MESSAGGIO_ERRORE_CORRELAZIONE_APPLICATIVA_CON_ELEMENTO_XML_DEFINITA_GIA_ESISTENTE, nomeElemento, labelPorta));
  98.         }
  99.        
  100.         return giaRegistrato;
  101.     }
  102.    
  103.    
  104.    
  105.     public static boolean alreadyExistsCorrelazioneApplicativaRisposta(PorteDelegateCore porteDelegateCore,
  106.             long idPorta, String elemento, long idCorrelazione,
  107.             StringBuilder existsMessage) throws DriverConfigurazioneNotFound, DriverConfigurazioneException {
  108.         return _alreadyExistsCorrelazioneApplicativaRisposta(true, porteDelegateCore, null, idPorta, elemento, idCorrelazione, existsMessage);
  109.     }
  110.     public static boolean alreadyExistsCorrelazioneApplicativaRisposta(PorteApplicativeCore porteApplicativeCore,
  111.             long idPorta, String elemento, long idCorrelazione,
  112.             StringBuilder existsMessage) throws DriverConfigurazioneNotFound, DriverConfigurazioneException {
  113.         return _alreadyExistsCorrelazioneApplicativaRisposta(false, null, porteApplicativeCore, idPorta, elemento, idCorrelazione, existsMessage);
  114.     }
  115.     private static boolean _alreadyExistsCorrelazioneApplicativaRisposta(boolean portaDelegata,
  116.             PorteDelegateCore porteDelegateCore, PorteApplicativeCore porteApplicativeCore,
  117.             long idPorta, String elemento, long idCorrelazione,
  118.             StringBuilder existsMessage) throws DriverConfigurazioneNotFound, DriverConfigurazioneException {
  119.        
  120.         // Controllo che non esistano altre correlazioni applicative con gli
  121.         // stessi dati
  122.         boolean giaRegistrato = false;

  123.         int idCorrApp = 0;
  124.         CorrelazioneApplicativaRisposta ca = null;
  125.         String nomePorta = null;
  126.         if(portaDelegata){
  127.             PortaDelegata pde = null;
  128.             pde = porteDelegateCore.getPortaDelegata(idPorta);
  129.             ca = pde.getCorrelazioneApplicativaRisposta();
  130.             nomePorta = pde.getNome();
  131.         }else{
  132.             PortaApplicativa pda = null;
  133.             pda = porteApplicativeCore.getPortaApplicativa(idPorta);
  134.             ca = pda.getCorrelazioneApplicativaRisposta();
  135.             nomePorta = pda.getNome();
  136.         }
  137.         if (ca != null) {
  138.             for (int i = 0; i < ca.sizeElementoList(); i++) {
  139.                 CorrelazioneApplicativaRispostaElemento cae = ca.getElemento(i);
  140.                 String caeNome = cae.getNome();
  141.                 if (caeNome == null)
  142.                     caeNome = "";
  143.                 if (elemento.equals(caeNome) || ("*".equals(caeNome) && "".equals(elemento))) {
  144.                     idCorrApp = cae.getId().intValue();
  145.                     break;
  146.                 }
  147.             }
  148.         }

  149.         if ((idCorrApp != 0) && (idCorrApp != idCorrelazione)) {
  150.             giaRegistrato = true;
  151.         }

  152.         if (giaRegistrato) {
  153.             String nomeElemento = CostantiControlStation.LABEL_NON_DEFINITO;
  154.             if(elemento!=null && ("".equals(elemento)==false))
  155.                 nomeElemento = elemento;
  156.             String labelPorta = null;
  157.             if(portaDelegata)
  158.                 labelPorta = MessageFormat.format(CostantiControlStation.LABEL_PORTA_DELEGATA_CON_PARAMETRI, nomePorta);
  159.             else
  160.                 labelPorta = MessageFormat.format(CostantiControlStation.LABEL_PORTA_APPLICATIVA_CON_PARAMETRI, nomePorta);
  161.             existsMessage.append(MessageFormat.format(CostantiControlStation.MESSAGGIO_ERRORE_CORRELAZIONE_APPLICATIVA_PER_LA_RISPOSTA_CON_ELEMENTO_DEFINITA_GIA_ESISTENTE, nomeElemento, labelPorta));
  162.         }

  163.         return giaRegistrato;
  164.        
  165.     }
  166. }