PddAdd.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.List;

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

  26. import org.apache.struts.action.Action;
  27. import org.apache.struts.action.ActionForm;
  28. import org.apache.struts.action.ActionForward;
  29. import org.apache.struts.action.ActionMapping;
  30. import org.openspcoop2.core.config.constants.CostantiConfigurazione;
  31. import org.openspcoop2.core.registry.constants.PddTipologia;
  32. import org.openspcoop2.core.registry.constants.StatoFunzionalita;
  33. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  34. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  35. import org.openspcoop2.web.ctrlstat.dao.PdDControlStation;
  36. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  37. import org.openspcoop2.web.lib.mvc.DataElement;
  38. import org.openspcoop2.web.lib.mvc.ForwardParams;
  39. import org.openspcoop2.web.lib.mvc.GeneralData;
  40. import org.openspcoop2.web.lib.mvc.PageData;
  41. import org.openspcoop2.web.lib.mvc.ServletUtils;
  42. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  43. /**
  44.  * pddAdd
  45.  *
  46.  * @author Andrea Poli (apoli@link.it)
  47.  * @author Stefano Corallo (corallo@link.it)
  48.  * @author Sandra Giangrandi (sandra@link.it)
  49.  * @author $Author$
  50.  * @version $Rev$, $Date$
  51.  *
  52.  */
  53. public final class PddAdd extends Action {


  54.     @Override
  55.     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

  56.         HttpSession session = request.getSession(true);

  57.         // Inizializzo PageData
  58.         PageData pd = new PageData();

  59.         GeneralHelper generalHelper = new GeneralHelper(session);

  60.         // Inizializzo GeneralData
  61.         GeneralData gd = generalHelper.initGeneralData(request);

  62.         try {
  63.        
  64.             PddHelper pddHelper = new PddHelper(request, pd, session);
  65.             PddCore pddCore = new PddCore();
  66.            
  67.             String nome = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_NOME);
  68.             String tipo = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_TIPOLOGIA);
  69.             String descrizione = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_DESCRIZIONE);
  70.             String ip = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_INDIRIZZO_PUBBLICO);
  71.             String ipGestione = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_INDIRIZZO_GESTIONE);
  72.             String porta = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_PORTA_PUBBLICA);
  73.             String portaGestione = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_PORTA_GESTIONE);
  74.             String implementazione = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_IMPLEMENTAZIONE);
  75.             String subject = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_SUBJECT);
  76.             String clientAuth = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_CLIENT_AUTH);
  77.             String protocollo = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_PROTOCOLLO);
  78.             String protocolloGestione = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_PROTOCOLLO_GESTIONE);
  79.            
  80.             int portaInt = 0;
  81.             int portaGestioneInt = 0;
  82.             try {
  83.                 portaInt = Integer.parseInt(porta);
  84.             } catch (NumberFormatException e) {
  85.                 portaInt = pddCore.getPortaPubblica();// porta default
  86.             }
  87.             try {
  88.                 portaGestioneInt = Integer.parseInt(portaGestione);
  89.             } catch (NumberFormatException e) {
  90.                 portaGestioneInt = pddCore.getPortaGestione();// porta di default
  91.             }

  92.             // Preparo il menu
  93.             pddHelper.makeMenu();
  94.    
  95.             // Se nomehid = null, devo visualizzare la pagina per l'inserimento dati
  96.             if(pddHelper.isEditModeInProgress()){
  97.    
  98.                 // default value
  99.                 if (porta == null || "".equals(porta))
  100.                     porta = pddCore.getPortaPubblica()+"";
  101.                 if (ip == null || "".equals(ip))
  102.                     ip = pddCore.getIndirizzoPubblico();
  103.                 if (portaGestione == null || "".equals(portaGestione))
  104.                     portaGestione = pddCore.getPortaGestione()+"";
  105.                 if (ipGestione == null || "".equals(ipGestione))
  106.                     ipGestione = pddCore.getIndirizzoGestione();
  107.                 if (implementazione == null || "".equals(implementazione))
  108.                     implementazione = PddCostanti.DEFAULT_PDD_IMPLEMENTAZIONE;
  109.    
  110.                 // setto la barra del titolo
  111.                 ServletUtils.setPageDataTitle_ServletAdd(pd, PddCostanti.LABEL_PORTE_DI_DOMINIO, PddCostanti.SERVLET_NAME_PDD_LIST);
  112.    
  113.                 // preparo i campi
  114.                 List<DataElement> dati = new ArrayList<>();
  115.    
  116.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  117.    
  118.                 if (nome == null)
  119.                     dati = pddHelper.addPddToDati(dati, "", null,  ip, "", "", "",
  120.                             PddTipologia.OPERATIVO, TipoOperazione.ADD,
  121.                             PddCostanti.getDefaultPddProtocolli(), PddCostanti.DEFAULT_PDD_PROTOCOLLO, PddCostanti.DEFAULT_PDD_PROTOCOLLO,
  122.                             portaInt, descrizione, ipGestione, portaGestioneInt, implementazione, CostantiConfigurazione.DISABILITATO.toString(), false);
  123.                 else
  124.                     dati = pddHelper.addPddToDati(dati, nome, null,  ip, subject, "", "",
  125.                             PddTipologia.toPddTipologia(tipo), TipoOperazione.ADD,
  126.                             PddCostanti.getDefaultPddProtocolli(), protocollo,  protocolloGestione,
  127.                             portaInt, descrizione, ipGestione, portaGestioneInt, implementazione, clientAuth, false);
  128.    
  129.                 pd.setDati(dati);
  130.    
  131.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  132.    
  133.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PddCostanti.OBJECT_NAME_PDD, ForwardParams.ADD());
  134.                
  135.             }
  136.    
  137.             // Controlli sui campi immessi
  138.             boolean isOk = pddHelper.pddCheckData(TipoOperazione.ADD, false);
  139.             if (!isOk) {
  140.                
  141.                 // setto la barra del titolo
  142.                 ServletUtils.setPageDataTitle_ServletAdd(pd, PddCostanti.LABEL_PORTE_DI_DOMINIO, PddCostanti.SERVLET_NAME_PDD_LIST);
  143.    
  144.                 // preparo i campi
  145.                 List<DataElement> dati = new ArrayList<>();
  146.    
  147.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  148.    
  149.                 dati = pddHelper.addPddToDati(dati, nome, null, ip, subject, "" /* password */, ""/* confpw */,
  150.                         PddTipologia.toPddTipologia(tipo), TipoOperazione.ADD,
  151.                         PddCostanti.getDefaultPddProtocolli(), protocollo,  protocolloGestione,
  152.                         portaInt, descrizione, ipGestione, portaGestioneInt, implementazione, clientAuth, false);
  153.    
  154.                 pd.setDati(dati);
  155.    
  156.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  157.    
  158.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PddCostanti.OBJECT_NAME_PDD, ForwardParams.ADD());
  159.                
  160.             }


  161.             String userLogin = ServletUtils.getUserLoginFromSession(session);

  162.             if ((subject == null) || subject.trim().equals("")) {
  163.                 subject="C=IT,O="+nome;
  164.                 if ((ip != null) && !ip.equals("")) {
  165.                     subject += ",OU=" + ip;
  166.                 }
  167.             }

  168.             PdDControlStation pdd = new PdDControlStation();
  169.             pdd.setNome(nome);
  170.             pdd.setTipo(tipo);
  171.             if(subject!=null && !"".equals(subject))
  172.                 pdd.setSubject(subject);
  173.             else
  174.                 pdd.setSubject(null);
  175.             pdd.setDescrizione(descrizione);
  176.             pdd.setImplementazione(implementazione);
  177.             pdd.setClientAuth(StatoFunzionalita.toEnumConstant(clientAuth));
  178.             if (tipo.equals(PddTipologia.OPERATIVO.toString()) || tipo.equals(PddTipologia.NONOPERATIVO.toString())) {
  179.                 pdd.setIp(ip);
  180.                 pdd.setProtocollo(protocollo);
  181.                 pdd.setPorta(portaInt);
  182.                 pdd.setIpGestione(ipGestione);
  183.                 pdd.setPortaGestione(portaGestioneInt);
  184.                 pdd.setProtocolloGestione(protocolloGestione);
  185.             }
  186.             pdd.setSuperUser(userLogin);

  187.             pddCore.performCreateOperation(userLogin, pddHelper.smista(), pdd);

  188.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session,ConsoleSearch.class);

  189.             List<PdDControlStation> lista = null;
  190.             if(pddCore.isVisioneOggettiGlobale(userLogin)){
  191.                 lista = pddCore.pddList(null, ricerca);
  192.             }else{
  193.                 lista = pddCore.pddList(userLogin, ricerca);
  194.             }

  195.             pddHelper.preparePddList(lista, ricerca);

  196.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  197.            
  198.             // Forward control to the specified success URI
  199.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PddCostanti.OBJECT_NAME_PDD, ForwardParams.ADD());

  200.         } catch (Exception e) {
  201.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  202.                     PddCostanti.OBJECT_NAME_PDD, ForwardParams.ADD());
  203.         }

  204.     }
  205. }