PddHelper.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.pdd;

  21. import java.util.ArrayList;
  22. import java.util.Iterator;
  23. import java.util.List;

  24. import javax.servlet.http.HttpServletRequest;
  25. import javax.servlet.http.HttpSession;

  26. import org.apache.commons.lang.StringEscapeUtils;
  27. import org.openspcoop2.core.commons.ISearch;
  28. import org.openspcoop2.core.commons.Liste;
  29. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  30. import org.openspcoop2.core.registry.PortaDominio;
  31. import org.openspcoop2.core.registry.constants.CostantiRegistroServizi;
  32. import org.openspcoop2.core.registry.constants.PddTipologia;
  33. import org.openspcoop2.core.registry.driver.DriverRegistroServiziException;
  34. import org.openspcoop2.utils.certificate.PrincipalType;
  35. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  36. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  37. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  38. import org.openspcoop2.web.ctrlstat.dao.PdDControlStation;
  39. import org.openspcoop2.web.ctrlstat.servlet.ConsoleHelper;
  40. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCostanti;
  41. import org.openspcoop2.web.ctrlstat.servlet.soggetti.SoggettiCostanti;
  42. import org.openspcoop2.web.lib.mvc.Costanti;
  43. import org.openspcoop2.web.lib.mvc.DataElement;
  44. import org.openspcoop2.web.lib.mvc.DataElementType;
  45. import org.openspcoop2.web.lib.mvc.PageData;
  46. import org.openspcoop2.web.lib.mvc.Parameter;
  47. import org.openspcoop2.web.lib.mvc.ServletUtils;
  48. import org.openspcoop2.web.lib.mvc.TipoOperazione;
  49. import org.openspcoop2.web.lib.users.dao.User;

  50. /**
  51.  * PddHelper
  52.  *
  53.  * @author Poli Andrea (apoli@link.it)
  54.  * @author $Author$
  55.  * @version $Rev$, $Date$
  56.  */
  57. public class PddHelper extends ConsoleHelper {

  58.     public PddHelper(HttpServletRequest request, PageData pd,
  59.             HttpSession session) {
  60.         super(request, pd,  session);
  61.     }
  62.     public PddHelper(ControlStationCore core, HttpServletRequest request, PageData pd,
  63.             HttpSession session) {
  64.         super(core, request, pd,  session);
  65.     }

  66.    
  67.     /**
  68.      * Controlla se una Porta di Dominio e' di tipo esterno
  69.      *
  70.      * @param pdd
  71.      * @return indicazione se la pdd รจ esterna
  72.      */
  73.     public boolean isPdDEsterna(PdDControlStation pdd) {

  74.         return PddTipologia.ESTERNO.toString().equals(pdd.getTipo());

  75.     }
  76.     public boolean isPdDOperativa(PdDControlStation pdd) {

  77.         return PddTipologia.OPERATIVO.equals(pdd.getTipo());

  78.     }
  79.     public boolean isPdDNonOperativa(PdDControlStation pdd) {

  80.         return PddTipologia.NONOPERATIVO.equals(pdd.getTipo());

  81.     }
  82.    
  83.     public List<DataElement> addPddToDati(List<DataElement> dati, String nome, String id, String ip, String subject, String password, String confpw, PddTipologia tipo,
  84.             TipoOperazione tipoOp, String[] protocolli, String protocollo, String protocolloGestione, int porta, String descrizione,
  85.             String ipGestione, int portaGestione, String implementazione, String clientAuth, boolean singlePdd) throws DriverRegistroServiziException {
  86.        
  87.         DataElement de = new DataElement();
  88.         de.setLabel(PddCostanti.LABEL_PORTA_DI_DOMINIO);
  89.         de.setType(DataElementType.TITLE);
  90.         dati.add(de);
  91.        
  92.         /** Id della Porta di Dominio */
  93.         if (tipoOp.equals(TipoOperazione.CHANGE)) {
  94.             de = new DataElement();
  95.             de.setLabel(PddCostanti.LABEL_PDD_ID);
  96.             de.setValue(id);
  97.             de.setType(DataElementType.HIDDEN);
  98.             de.setName(PddCostanti.PARAMETRO_PDD_ID);
  99.             dati.add(de);
  100.         }
  101.        
  102.         /** Nome della Porta di Dominio */
  103.         de = new DataElement();
  104.         de.setLabel(PddCostanti.LABEL_PDD_NOME);
  105.         if (tipoOp.equals(TipoOperazione.ADD) || this.core.isSinglePdD()) {
  106.             de.setType(DataElementType.TEXT_EDIT);
  107.             de.setRequired(true);
  108.         } else {
  109.             de.setType(DataElementType.TEXT);
  110.         }
  111.         de.setName(PddCostanti.PARAMETRO_PDD_NOME);
  112.         de.setValue(nome);
  113.         de.setSize(this.getSize());
  114.         dati.add(de);

  115.         /** Descrizione della Porta di Dominio */
  116.         de = new DataElement();
  117.         de.setLabel(PddCostanti.LABEL_PDD_DESCRIZIONE);
  118.         de.setType(DataElementType.TEXT_EDIT);
  119.         de.setName(PddCostanti.PARAMETRO_PDD_DESCRIZIONE);
  120.         de.setValue(descrizione);
  121.         de.setSize(this.getSize());
  122.         dati.add(de);

  123.         if (!singlePdd) {
  124.            
  125.             /** Protocollo (solo in caso di pdd control station) */
  126.             de = new DataElement();
  127.             de.setLabel(PddCostanti.LABEL_PDD_PROTOCOLLO);
  128.             if (tipoOp.equals(TipoOperazione.ADD) && !tipo.equals(PddTipologia.ESTERNO)){
  129.                 de.setType(DataElementType.SELECT);
  130.             }else
  131.                 de.setType(DataElementType.HIDDEN);
  132.             de.setName(PddCostanti.PARAMETRO_PDD_PROTOCOLLO);
  133.             de.setValues(protocolli);
  134.             de.setSelected(protocollo);
  135.             dati.add(de);

  136.             /** Indirizzo Pubblico (solo in caso di pdd control station) */
  137.             de = new DataElement();
  138.             de.setLabel(PddCostanti.LABEL_PDD_INDIRIZZO_PUBBLICO);
  139.             if (tipoOp.equals(TipoOperazione.ADD) && !tipo.equals(PddTipologia.ESTERNO)){
  140.                 de.setType(DataElementType.TEXT_EDIT);
  141.                 de.setRequired(true);
  142.             }else
  143.                 de.setType(DataElementType.HIDDEN);
  144.             de.setName(PddCostanti.PARAMETRO_PDD_INDIRIZZO_PUBBLICO);
  145.             de.setValue(ip);
  146.             de.setSize(this.getSize());
  147.             dati.add(de);

  148.             /** Porta Pubblica (solo in caso di pdd control station) */
  149.             de = new DataElement();
  150.             de.setLabel(PddCostanti.LABEL_PDD_PORTA_PUBBLICA);
  151.             if (tipoOp.equals(TipoOperazione.ADD) && !tipo.equals(PddTipologia.ESTERNO)){
  152.                 de.setType(DataElementType.TEXT_EDIT);
  153.                 de.setRequired(true);
  154.             }else
  155.                 de.setType(DataElementType.HIDDEN);
  156.             de.setName(PddCostanti.PARAMETRO_PDD_PORTA_PUBBLICA);
  157.             de.setValue(porta <= 0 ? PddCostanti.DEFAULT_PDD_PORTA : "" + porta);
  158.             de.setSize(this.getSize());
  159.             dati.add(de);

  160.             /** Protocollo Gestione (solo in caso di pdd control station) */
  161.             de = new DataElement();
  162.             de.setLabel(PddCostanti.LABEL_PDD_PROTOCOLLO_GESTIONE);
  163.             if (tipoOp.equals(TipoOperazione.ADD) && !tipo.equals(PddTipologia.ESTERNO)){
  164.                 de.setType(DataElementType.SELECT);
  165.             }else
  166.                 de.setType(DataElementType.HIDDEN);
  167.             de.setName(PddCostanti.PARAMETRO_PDD_PROTOCOLLO_GESTIONE);
  168.             de.setValues(protocolli);
  169.             de.setSelected(protocolloGestione);
  170.             dati.add(de);
  171.            
  172.             /** Indirizzo Gestione (solo in caso di pdd control station) */
  173.             de = new DataElement();
  174.             de.setLabel(PddCostanti.LABEL_PDD_INDIRIZZO_GESTIONE);
  175.             if (tipoOp.equals(TipoOperazione.ADD) && !tipo.equals(PddTipologia.ESTERNO)){
  176.                 de.setType(DataElementType.TEXT_EDIT);
  177.                 de.setRequired(true);
  178.             }else
  179.                 de.setType(DataElementType.HIDDEN);
  180.             de.setName(PddCostanti.PARAMETRO_PDD_INDIRIZZO_GESTIONE);
  181.             de.setValue(ipGestione);
  182.             de.setSize(this.getSize());
  183.             dati.add(de);

  184.             /** Porta Gestione (solo in caso di pdd control station) */
  185.             de = new DataElement();
  186.             de.setLabel(PddCostanti.LABEL_PDD_PORTA_GESTIONE);
  187.             if (tipoOp.equals(TipoOperazione.ADD) && !tipo.equals(PddTipologia.ESTERNO)){
  188.                 de.setType(DataElementType.TEXT_EDIT);
  189.                 de.setRequired(true);
  190.             }else
  191.                 de.setType(DataElementType.HIDDEN);
  192.             de.setName(PddCostanti.PARAMETRO_PDD_PORTA_GESTIONE);
  193.             de.setValue(portaGestione <= 0 ? PddCostanti.DEFAULT_PDD_PORTA : "" + portaGestione);
  194.             de.setSize(this.getSize());
  195.             dati.add(de);

  196.             /** Tipologia della Pdd (solo in caso di pdd control station) */
  197.             // In caso di creazione posso scegliere il tipo che voglio
  198.             // Se tipo=='esterno' non posso cambiare il tipo
  199.             de = new DataElement();
  200.             de.setLabel(PddCostanti.LABEL_PDD_TIPOLOGIA);
  201.             de.setType(DataElementType.SELECT);
  202.             de.setName(PddCostanti.PARAMETRO_PDD_TIPOLOGIA);
  203.             if (tipoOp.equals(TipoOperazione.ADD)) {
  204.                 de.setLabels(PddCostanti.getLabelTipi());
  205.                 de.setValues(PddTipologia.TIPI);
  206.             } else if (tipoOp.equals(TipoOperazione.CHANGE)) {
  207.                 if (tipo.equals(PddTipologia.ESTERNO)) {
  208.                     de.setLabels(PddCostanti.getLabelTipoSoloEsterno());
  209.                     de.setValues(PddTipologia.TIPO_SOLO_ESTERNO);
  210.                 } else {
  211.                     de.setLabels(PddCostanti.getLabelTipiSoloOperativi());
  212.                     de.setValues(PddTipologia.TIPI_SOLO_OPERATIVI);
  213.                 }
  214.             }
  215.             de.setSelected(tipo.toString());
  216. //          if(this.core.isSinglePdD()){
  217.                 de.setPostBack(true);  
  218. //          }
  219. //          else{
  220. //              de.setOnChangeAlternativePostBack("changePdDType()");
  221. //          }
  222.             dati.add(de);
  223.         }else{
  224.            
  225.             /** Tipologia della Pdd */
  226.             if(TipoOperazione.ADD.equals(tipoOp)==false){
  227.                 // SinglePdD
  228.                 de = new DataElement();
  229.                 de.setLabel(PddCostanti.LABEL_PDD_TIPOLOGIA);
  230.                 de.setType(DataElementType.TEXT);
  231.                 de.setName(PddCostanti.PARAMETRO_PDD_TIPOLOGIA);
  232.                 de.setValue(tipo.toString());
  233.                 dati.add(de);
  234.             }
  235.         }

  236.         /** Implementazione della Pdd */
  237.         de = new DataElement();
  238.         de.setLabel(PddCostanti.LABEL_PDD_IMPLEMENTAZIONE);
  239.         if (this.isModalitaAvanzata()) {
  240.             de.setType(DataElementType.TEXT_EDIT);
  241.             de.setRequired(true);
  242.         }
  243.         else{
  244.             de.setType(DataElementType.HIDDEN);
  245.         }
  246.         de.setName(PddCostanti.PARAMETRO_PDD_IMPLEMENTAZIONE);
  247.         de.setValue(implementazione);
  248.         de.setSize(this.getSize());
  249.         dati.add(de);
  250.        
  251.         /** ClientAuth della Pdd */
  252.         String[] tipiAuth = { CostantiConfigurazione.DISABILITATO.toString(), CostantiConfigurazione.ABILITATO.toString() };
  253.         de = new DataElement();
  254.         de.setLabel(PddCostanti.LABEL_PDD_CLIENT_AUTH);
  255.         de.setType(DataElementType.SELECT);
  256.         de.setName(PddCostanti.PARAMETRO_PDD_CLIENT_AUTH);
  257.         de.setSelected(clientAuth);
  258.         de.setValues(tipiAuth);
  259.         de.setSize(this.getSize());
  260. //      de.setOnChange("CambiaClientAuth('" + tipoOp + "'," + singlePdd + ")");
  261.         de.setPostBack(true);
  262.         dati.add(de);
  263.        
  264.         /** Subject della Pdd */
  265.         de = new DataElement();
  266.         de.setLabel(PddCostanti.LABEL_PDD_SUBJECT);
  267.         //if (clientAuth != null && clientAuth.equals("abilitato")) {
  268.         de.setType(DataElementType.TEXT_EDIT);
  269.         de.setValue(StringEscapeUtils.escapeHtml(subject));
  270.         if (clientAuth != null && clientAuth.equals(CostantiRegistroServizi.ABILITATO.getValue())) {
  271.             de.setRequired(true);
  272.         }
  273.         //}  else {
  274.         //    de.setType(DataElementType.HIDDEN);
  275.         //    de.setValue("");
  276.         //}
  277.         de.setName(PddCostanti.PARAMETRO_PDD_SUBJECT);
  278.         de.setSize(this.getSize());
  279.         dati.add(de);

  280.         return dati;
  281.     }
  282.    
  283.    
  284.     // Controlla i dati dei Pdd
  285.     boolean pddCheckData(TipoOperazione tipoOp, boolean singlePdd)
  286.             throws Exception {

  287.         try{

  288.             String nome = this.getParameter(PddCostanti.PARAMETRO_PDD_NOME);
  289.             String ip = this.getParameter(PddCostanti.PARAMETRO_PDD_INDIRIZZO_PUBBLICO);
  290.             String ipGestione = this.getParameter(PddCostanti.PARAMETRO_PDD_INDIRIZZO_GESTIONE);
  291.             String tipoParam = this.getParameter(PddCostanti.PARAMETRO_PDD_TIPOLOGIA);
  292.             PddTipologia tipo = PddTipologia.toPddTipologia(tipoParam);
  293.             String implementazione = this.getParameter(PddCostanti.PARAMETRO_PDD_IMPLEMENTAZIONE);
  294.             String clientAuth = this.getParameter(PddCostanti.PARAMETRO_PDD_CLIENT_AUTH);
  295.             String subject = this.getParameter(PddCostanti.PARAMETRO_PDD_SUBJECT);
  296.             String porta = this.getParameter(PddCostanti.PARAMETRO_PDD_PORTA_PUBBLICA);
  297.             String portaGestione = this.getParameter(PddCostanti.PARAMETRO_PDD_PORTA_GESTIONE);

  298.             if (implementazione == null || "".equals(implementazione)) {
  299.                 this.pd.setMessage("Il campo Implementazione deve essere specificato.");
  300.                 return false;
  301.             }

  302.             if(subject!=null && !"".equals(subject)){
  303.                 try{
  304.                     org.openspcoop2.utils.certificate.CertificateUtils.validaPrincipal(subject, PrincipalType.SUBJECT);
  305.                 }catch(Exception e){
  306.                     this.pd.setMessage("Il subject fornito non รจ valido: "+e.getMessage());
  307.                     return false;
  308.                 }
  309.             }

  310.             if (CostantiConfigurazione.ABILITATO.toString().equals(clientAuth)){
  311.                 if (subject == null || "".equals(subject)) {
  312.                     this.pd.setMessage("&Egrave; necessario specificare il subject in caso di Client Auth abilitato.");
  313.                     return false;
  314.                 }
  315.             }

  316.             // Controllo che i campi "select" abbiano uno dei valori ammessi
  317.             if (!singlePdd) {
  318.                 if (!tipo.equals(PddTipologia.OPERATIVO) && !tipo.equals(PddTipologia.NONOPERATIVO) && !tipo.equals(PddTipologia.ESTERNO)) {
  319.                     this.pd.setMessage("Tipo dev'essere operativo, non-operativo o esterno");
  320.                     return false;
  321.                 }
  322.             }

  323.             if (
  324.                     singlePdd
  325.                     ||
  326.                     (tipo.equals(PddTipologia.ESTERNO))) {
  327.                 // campi obbligatori

  328.                 // nome
  329.                 if ((nome == null) || nome.equals("")) {
  330.                     this.pd.setMessage("Dati incompleti. &Egrave; necessario indicare il Nome.");
  331.                     return false;
  332.                 }
  333.                
  334.                 // controllo spazi
  335.                 if ((nome.indexOf(" ") != -1)) {
  336.                     this.pd.setMessage("Non inserire spazi nei campi di testo");
  337.                     return false;
  338.                 }
  339.                
  340.                 // Il nome deve contenere solo lettere e numeri e '_' '-' '.'
  341.                 if(singlePdd){
  342.                     if(this.checkNCName(nome, PddCostanti.LABEL_PDD_NOME)==false){
  343.                         return false;
  344.                     }
  345.                 }
  346.                 else{
  347.                     // Le code JMS possono avere vincoli sul nome
  348.                     if(this.checkSimpleName(nome, PddCostanti.LABEL_PDD_NOME)==false){
  349.                         return false;
  350.                     }
  351.                 }

  352.             } else {// in caso di operativo o non-operativo
  353.                 // Campi obbligatori
  354.                 if (nome.equals("") || ip.equals("") || ipGestione.equals("") || porta.equals("") || portaGestione.equals("")) {
  355.                     String tmpElenco = "";
  356.                     if (nome.equals("")) {
  357.                         tmpElenco = "Nome";
  358.                     }
  359.                     if (ip.equals("")) {
  360.                         if (tmpElenco.equals("")) {
  361.                             tmpElenco = "Indirizzo IP";
  362.                         } else {
  363.                             tmpElenco = tmpElenco + ", Indirizzo IP";
  364.                         }
  365.                     }
  366.                     if (ipGestione.equals("")) {
  367.                         if (tmpElenco.equals("")) {
  368.                             tmpElenco = "Indirizzo IP Gestione";
  369.                         } else {
  370.                             tmpElenco = tmpElenco + ", Indirizzo IP Gestione";
  371.                         }
  372.                     }
  373.                     if (porta.equals("")) {
  374.                         if (tmpElenco.equals("")) {
  375.                             tmpElenco = "Porta";
  376.                         } else {
  377.                             tmpElenco = tmpElenco + ", Porta";
  378.                         }
  379.                     }
  380.                     if (portaGestione.equals("")) {
  381.                         if (tmpElenco.equals("")) {
  382.                             tmpElenco = "Porta Gestione";
  383.                         } else {
  384.                             tmpElenco = tmpElenco + ", Porta Gestione";
  385.                         }
  386.                     }
  387.                     this.pd.setMessage("Dati incompleti. &Egrave; necessario indicare: " + tmpElenco);
  388.                     return false;
  389.                 }

  390.                 // Controllo che non ci siano spazi nei campi di testo
  391.                 if ((nome.indexOf(" ") != -1) || (ip.indexOf(" ") != -1) || (ipGestione.indexOf(" ") != -1) || (porta.indexOf(" ") != -1) || (portaGestione.indexOf(" ") != -1)) {
  392.                     this.pd.setMessage("Non inserire spazi nei campi di testo");
  393.                     return false;
  394.                 }

  395.                 // Le code JMS possono avere vincoli sul nome
  396.                 if(this.checkSimpleName(nome, PddCostanti.LABEL_PDD_NOME)==false){
  397.                     return false;
  398.                 }

  399.                 // ip dev'essere un indirizzo ip o un hostname valido
  400.                 if (!org.openspcoop2.utils.regexp.RegExpUtilities.isIPOrHostname(ip)) {
  401.                     this.pd.setMessage("Indirizzo pubblico dev'essere un ip o un hostname valido");
  402.                     return false;
  403.                 }

  404.                 // ip_gestione dev'essere un indirizzo ip o un hostname valido
  405.                 if (!org.openspcoop2.utils.regexp.RegExpUtilities.isIPOrHostname(ipGestione)) {
  406.                     this.pd.setMessage("Indirizzo gestione dev'essere un ip o un hostname valido");
  407.                     return false;
  408.                 }

  409.                 // La porta deve essere un numero
  410.                 if(this.checkNumber(porta, PddCostanti.LABEL_PDD_PORTA_PUBBLICA, false)==false){
  411.                     return false;
  412.                 }

  413.                 // La porta gestione deve essere un numero
  414.                 if(this.checkNumber(portaGestione, PddCostanti.LABEL_PDD_PORTA_GESTIONE, false)==false){
  415.                     return false;
  416.                 }
  417.                
  418.             }

  419.             // Se tipoOp = add, controllo che il pdd non sia gia' stato registrato
  420.             if (tipoOp.equals(TipoOperazione.ADD)) {
  421.                 boolean trovatoPdd = this.pddCore.existPdd(nome) > 0;
  422.                 if (trovatoPdd) {
  423.                     this.pd.setMessage("Esiste gi&agrave; una Porta di Dominio con nome " + nome);
  424.                     return false;
  425.                 }
  426.             }

  427.             // Controllo non esista un altra pdd con stesso subject
  428.             if(subject!=null && !"".equals(subject)){
  429.                 List<PortaDominio> pddList = this.pddCore.porteDominioWithSubject(subject);
  430.                 for (int i = 0; i < pddList.size(); i++) {
  431.                     PortaDominio pdd = pddList.get(i);

  432.                     if ((tipoOp.equals(TipoOperazione.CHANGE)) && (nome.equals(pdd.getNome()))) {
  433.                         continue;
  434.                     }

  435.                     // Messaggio di errore
  436.                     this.pd.setMessage("La Porta di Dominio " + pdd.getNome() + " possiede gia' le credenziali ssl indicate.");
  437.                     return false;
  438.                 }
  439.             }

  440.             return true;
  441.         } catch (Exception e) {
  442.             this.log.error("Exception: " + e.getMessage(), e);
  443.             throw new Exception(e);
  444.         }
  445.     }


  446.     public void preparePddSinglePddList(List<PdDControlStation> lista, ISearch ricerca) throws Exception {
  447.         try {

  448.             ServletUtils.addListElementIntoSession(this.request, this.session, PddCostanti.OBJECT_NAME_PDD_SINGLEPDD);

  449.             Boolean contaListe = ServletUtils.getContaListeFromSession(this.session);

  450.             int idLista = Liste.PDD;
  451.             int limit = ricerca.getPageSize(idLista);
  452.             int offset = ricerca.getIndexIniziale(idLista);
  453.            
  454.             String search = ServletUtils.getSearchFromSession(ricerca, idLista);
  455.            
  456.             this.pd.setIndex(offset);
  457.             this.pd.setPageSize(limit);
  458.             this.pd.setNumEntries(ricerca.getNumEntries(idLista));

  459.             // setto la barra del titolo
  460.             if (search.equals("")) {
  461.                 this.pd.setSearchDescription("");
  462.                 ServletUtils.setPageDataTitle(this.pd,
  463.                         new Parameter(PddCostanti.LABEL_PORTE_DI_DOMINIO,PddCostanti.SERVLET_NAME_PDD_SINGLEPDD_LIST));
  464.             }
  465.             else{
  466.                 ServletUtils.setPageDataTitle(this.pd,
  467.                         new Parameter(PddCostanti.LABEL_PORTE_DI_DOMINIO,PddCostanti.SERVLET_NAME_PDD_SINGLEPDD_LIST),
  468.                         new Parameter(Costanti.PAGE_DATA_TITLE_LABEL_RISULTATI_RICERCA,null));  
  469.             }

  470.             // controllo eventuali risultati ricerca
  471.             if (!search.equals("")) {
  472.                 ServletUtils.enabledPageDataSearch(this.pd, PddCostanti.LABEL_PORTE_DI_DOMINIO, search);
  473.             }

  474.             // setto le label delle colonne
  475.             String[] labels = { PddCostanti.LABEL_PDD_NOME, PddCostanti.LABEL_PDD_TIPOLOGIA, PddCostanti.LABEL_PDD_IMPLEMENTAZIONE, PddCostanti.LABEL_PDD_SOGGETTI };
  476.             this.pd.setLabels(labels);

  477.             // preparo i dati
  478.             List<List<DataElement>> dati = new ArrayList<>();

  479.             Iterator<PdDControlStation> it = lista.iterator();
  480.             PdDControlStation pdd = null;
  481.             while (it.hasNext()) {
  482.                 pdd = it.next();
  483.                 List<DataElement> e = new ArrayList<>();

  484.                 DataElement de = new DataElement();
  485.                 de.setUrl(PddCostanti.SERVLET_NAME_PDD_SINGLEPDD_CHANGE,
  486.                         new Parameter(PddCostanti.PARAMETRO_PDD_ID, pdd.getId().toString()),
  487.                         new Parameter(PddCostanti.PARAMETRO_PDD_NOME, pdd.getNome()));
  488.                 de.setValue(pdd.getNome());
  489.                 de.setIdToRemove(pdd.getNome());
  490.                 e.add(de);

  491.                 de = new DataElement();
  492.                 de.setValue(pdd.getTipo());
  493.                 e.add(de);

  494.                 de = new DataElement();
  495.                 de.setValue(pdd.getImplementazione());
  496.                 e.add(de);

  497.                 de = new DataElement();
  498.                 de.setUrl(PddCostanti.SERVLET_NAME_PDD_SOGGETTI_LIST,
  499.                         new Parameter(PddCostanti.PARAMETRO_PDD_ID, pdd.getId().toString()));
  500.                 if (contaListe) {
  501.                     // BugFix OP-674
  502.                     //List<org.openspcoop2.core.config.Soggetto> lista1 = this.pddCore.pddSoggettiList(pdd.getId().intValue(), new Search(true));
  503.                     ConsoleSearch searchForCount = new ConsoleSearch(true,1);
  504.                     this.pddCore.pddSoggettiList(pdd.getId().intValue(), searchForCount);
  505.                     int numSog = 0;
  506. //                  if (lista1 != null)
  507. //                      numSog = lista1.size();
  508.                     numSog = searchForCount.getNumEntries(Liste.PDD_SOGGETTI);
  509.                     ServletUtils.setDataElementVisualizzaLabel(de,Long.valueOf(numSog));
  510.                 } else
  511.                     ServletUtils.setDataElementVisualizzaLabel(de);
  512.                 e.add(de);

  513.                 dati.add(e);
  514.             }

  515.             this.pd.setDati(dati);
  516.             this.pd.setAddButton(true);

  517.         } catch (Exception e) {
  518.             this.log.error("Exception: " + e.getMessage(), e);
  519.             throw new Exception(e);
  520.         }
  521.     }

  522.     public void preparePddList(List<PdDControlStation> lista, ISearch ricerca) throws Exception {
  523.         try {
  524.             ServletUtils.addListElementIntoSession(this.request, this.session, PddCostanti.OBJECT_NAME_PDD);
  525.            
  526.             Boolean contaListe = ServletUtils.getContaListeFromSession(this.session);

  527.             int idLista = Liste.PDD;
  528.             int limit = ricerca.getPageSize(idLista);
  529.             int offset = ricerca.getIndexIniziale(idLista);
  530.            
  531.             String search = ServletUtils.getSearchFromSession(ricerca, idLista);
  532.            
  533.             this.pd.setIndex(offset);
  534.             this.pd.setPageSize(limit);
  535.             this.pd.setNumEntries(ricerca.getNumEntries(idLista));
  536.            
  537.             // setto la barra del titolo
  538.             if (search.equals("")) {
  539.                 this.pd.setSearchDescription("");
  540.                 ServletUtils.setPageDataTitle(this.pd,
  541.                         new Parameter(PddCostanti.LABEL_PORTE_DI_DOMINIO,PddCostanti.SERVLET_NAME_PDD_LIST));
  542.             }
  543.             else{
  544.                 ServletUtils.setPageDataTitle(this.pd,
  545.                         new Parameter(PddCostanti.LABEL_PORTE_DI_DOMINIO,PddCostanti.SERVLET_NAME_PDD_LIST),
  546.                         new Parameter(Costanti.PAGE_DATA_TITLE_LABEL_RISULTATI_RICERCA,null));  
  547.             }

  548.             // controllo eventuali risultati ricerca
  549.             if (!search.equals("")) {
  550.                 ServletUtils.enabledPageDataSearch(this.pd, PddCostanti.LABEL_PORTE_DI_DOMINIO, search);
  551.             }

  552.             User user = ServletUtils.getUserFromSession(this.request, this.session);
  553.             boolean showConfigurazioneSistema = user!=null && user.getPermessi()!=null && user.getPermessi().isSistema() &&
  554.                     this.pddCore.getJmxPdDAliases()!=null && this.pddCore.getJmxPdDAliases().size()>0;
  555.            
  556.             // setto le label delle colonne
  557.             List<String> listLabels = new ArrayList<>();
  558.             listLabels.add(PddCostanti.LABEL_PDD_NOME);
  559.             listLabels.add(PddCostanti.LABEL_PDD_INDIRIZZO);
  560.             listLabels.add(PddCostanti.LABEL_PDD_TIPOLOGIA);
  561.             listLabels.add(PddCostanti.LABEL_PDD_IMPLEMENTAZIONE);
  562.             if(showConfigurazioneSistema){
  563.                 listLabels.add(PddCostanti.LABEL_PDD_CONFIGURAZIONE_SISTEMA);
  564.             }
  565.             listLabels.add(PddCostanti.LABEL_PDD_SOGGETTI);
  566.             String[] labels = listLabels.toArray(new String[1]);
  567.             this.pd.setLabels(labels);

  568.             // preparo i dati
  569.             List<List<DataElement>> dati = new ArrayList<>();

  570.             Iterator<PdDControlStation> it = lista.iterator();
  571.             PdDControlStation pdd = null;
  572.             while (it.hasNext()) {
  573.                 pdd = it.next();
  574.                 List<DataElement> e = new ArrayList<>();

  575.                 DataElement de = new DataElement();
  576.                 de.setUrl(PddCostanti.SERVLET_NAME_PDD_CHANGE,
  577.                         new Parameter(PddCostanti.PARAMETRO_PDD_ID, pdd.getId().toString()),
  578.                         new Parameter(PddCostanti.PARAMETRO_PDD_NOME, pdd.getNome()));
  579.                 de.setValue(pdd.getNome());
  580.                 de.setIdToRemove(pdd.getId().toString());
  581.                 e.add(de);

  582.                 de = new DataElement();
  583.                 if (PddTipologia.ESTERNO.toString().equals(pdd.getTipo()))
  584.                     de.setValue("");
  585.                 else
  586.                     de.setValue(pdd.getIp());
  587.                 e.add(de);

  588.                 de = new DataElement();
  589.                 de.setValue(pdd.getTipo());
  590.                 e.add(de);

  591.                 de = new DataElement();
  592.                 de.setValue(pdd.getImplementazione());
  593.                 e.add(de);

  594.                 if(showConfigurazioneSistema){
  595.                     de = new DataElement();
  596.                     if(PddTipologia.OPERATIVO.toString().equals(pdd.getTipo())){
  597.                         de.setUrl(ConfigurazioneCostanti.SERVLET_NAME_CONFIGURAZIONE_SISTEMA_ADD,
  598.                                 new Parameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_SISTEMA_NODO_CLUSTER, pdd.getNome()));
  599.                         de.setValue(Costanti.LABEL_VISUALIZZA);
  600.                     }
  601.                     else{
  602.                         de.setType(DataElementType.TEXT);
  603.                         de.setValue("-");
  604.                     }
  605.                     e.add(de);
  606.                 }
  607.                
  608.                 de = new DataElement();
  609.                 de.setUrl(PddCostanti.SERVLET_NAME_PDD_SOGGETTI_LIST,
  610.                         new Parameter(PddCostanti.PARAMETRO_PDD_ID, pdd.getId().toString()));
  611.                 if (contaListe) {
  612.                     // BugFix OP-674
  613.                     //List<org.openspcoop2.core.config.Soggetto> lista1 = this.pddCore.pddSoggettiList(pdd.getId().intValue(), new Search(true));
  614.                     ConsoleSearch searchForCount = new ConsoleSearch(true,1);
  615.                     this.pddCore.pddSoggettiList(pdd.getId().intValue(), searchForCount);
  616.                     int numSog = 0;
  617. //                  if (lista1 != null)
  618. //                      numSog = lista1.size();
  619.                     numSog = searchForCount.getNumEntries(Liste.PDD_SOGGETTI);
  620.                     ServletUtils.setDataElementVisualizzaLabel(de,Long.valueOf(numSog));
  621.                 } else
  622.                     ServletUtils.setDataElementVisualizzaLabel(de);
  623.                 e.add(de);              

  624.                 dati.add(e);
  625.             }

  626.             this.pd.setDati(dati);
  627.             this.pd.setAddButton(true);

  628.         } catch (Exception e) {
  629.             this.log.error("Exception: " + e.getMessage(), e);
  630.             throw new Exception(e);
  631.         }
  632.     }
  633.    
  634.     // Prepara la lista di soggetti associati al pdd
  635.     public void preparePddSoggettiList(String nomePdd, int id, List<org.openspcoop2.core.config.Soggetto> lista, ISearch ricerca)
  636.             throws Exception {
  637.         try {
  638.            
  639.             ServletUtils.addListElementIntoSession(this.request, this.session, PddCostanti.OBJECT_NAME_PDD_SOGGETTI,
  640.                     new Parameter(PddCostanti.PARAMETRO_PDD_ID, id+""));
  641.            
  642.             Boolean singlePdD = ServletUtils.getObjectFromSession(this.request, this.session, Boolean.class, CostantiControlStation.SESSION_PARAMETRO_SINGLE_PDD);
  643.            
  644.             int idLista = Liste.PDD_SOGGETTI;
  645.             int limit = ricerca.getPageSize(idLista);
  646.             int offset = ricerca.getIndexIniziale(idLista);
  647.        
  648.             String search = ServletUtils.getSearchFromSession(ricerca, idLista);
  649.            
  650.             this.pd.setIndex(offset);
  651.             this.pd.setPageSize(limit);
  652.             this.pd.setNumEntries(ricerca.getNumEntries(idLista));
  653.            
  654.             // setto la barra del titolo
  655.             String t2URL = PddCostanti.SERVLET_NAME_PDD_SINGLEPDD_LIST;
  656.             boolean sPdD = singlePdD != null ? singlePdD.booleanValue() : false;
  657.             if (sPdD == false){
  658.                 t2URL = PddCostanti.SERVLET_NAME_PDD_LIST;
  659.             }
  660.             String t3Label = "Soggetti associati alla Porta di Dominio " + nomePdd;
  661.             if (search.equals("")) {
  662.                 this.pd.setSearchDescription("");
  663.                 ServletUtils.setPageDataTitle(this.pd,
  664.                         new Parameter(PddCostanti.LABEL_PORTE_DI_DOMINIO,t2URL),
  665.                         new Parameter(t3Label,null));
  666.             }
  667.             else{
  668.                 ServletUtils.setPageDataTitle(this.pd,
  669.                         new Parameter(PddCostanti.LABEL_PORTE_DI_DOMINIO,t2URL),
  670.                         new Parameter(t3Label, PddCostanti.SERVLET_NAME_PDD_SOGGETTI_LIST+"?"+PddCostanti.PARAMETRO_PDD_ID+"="+id),
  671.                         new Parameter(Costanti.PAGE_DATA_TITLE_LABEL_RISULTATI_RICERCA,null));  
  672.             }
  673.            

  674.             // controllo eventuali risultati ricerca
  675.             if (!search.equals("")) {
  676.                 ServletUtils.enabledPageDataSearch(this.pd, PddCostanti.LABEL_SOGGETTI, search);
  677.             }

  678.             // setto le label delle colonne
  679.             String[] labels = { PddCostanti.LABEL_SOGGETTI };
  680.             this.pd.setLabels(labels);


  681.             List<List<DataElement>> dati = new ArrayList<>();
  682.             // preparo i dati
  683.             if (lista != null) {
  684.                 Iterator<org.openspcoop2.core.config.Soggetto> it = lista.iterator();
  685.                 while (it.hasNext()) {
  686.                     org.openspcoop2.core.config.Soggetto sog = it.next();

  687.                     List<DataElement> e = new ArrayList<>();

  688.                     DataElement de = new DataElement();
  689.                     //if (idsSogg.contains(sog.getId()))
  690.                     de.setUrl(SoggettiCostanti.SERVLET_NAME_SOGGETTI_CHANGE,
  691.                             new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_ID, sog.getId().toString()),
  692.                             new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_NOME, sog.getNome()),
  693.                             new Parameter(SoggettiCostanti.PARAMETRO_SOGGETTO_TIPO, sog.getTipo()));
  694.                     de.setValue(sog.getTipo() + "/" + sog.getNome());
  695.                     e.add(de);

  696.                     dati.add(e);
  697.                 }
  698.             }
  699.            
  700.             this.pd.setDati(dati);
  701.             this.pd.setAddButton(false);
  702.             this.pd.setSelect(false);
  703.            
  704.         } catch (Exception e) {
  705.             this.log.error("Exception: " + e.getMessage(), e);
  706.             throw new Exception(e);
  707.         }
  708.     }
  709. }