PddSinglePdDAdd.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.registry.PortaDominio;
  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.dao.PdDControlStation;
  35. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  36. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  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.  * PddSinglePdDAdd
  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 PddSinglePdDAdd 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.        
  63.         String userLogin = ServletUtils.getUserLoginFromSession(session);

  64.         try {
  65.             PddHelper pddHelper = new PddHelper(request, pd, session);
  66.             String nome = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_NOME);
  67.             String descr = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_DESCRIZIONE);
  68.             String implementazione = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_IMPLEMENTAZIONE);
  69.             String subject = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_SUBJECT);
  70.             String clientAuth = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_CLIENT_AUTH);
  71.            
  72.             PddCore pddCore = new PddCore();
  73.    
  74.             // Preparo il menu
  75.             pddHelper.makeMenu();
  76.    
  77.             // Se nomehid = null, devo visualizzare la pagina per l'inserimento dati
  78.             if(pddHelper.isEditModeInProgress()){
  79.            
  80.                 // setto la barra del titolo
  81.                 ServletUtils.setPageDataTitle_ServletAdd(pd, PddCostanti.LABEL_PORTE_DI_DOMINIO, PddCostanti.SERVLET_NAME_PDD_SINGLEPDD_LIST);
  82.    
  83.                 // preparo i campi
  84.                 List<DataElement> dati = new ArrayList<>();
  85.    
  86.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  87.    
  88.                 if (implementazione == null || "".equals(implementazione))
  89.                     implementazione = PddCostanti.DEFAULT_PDD_IMPLEMENTAZIONE;
  90.                
  91.                 dati = pddHelper.addPddToDati(dati, nome, null, "", subject, "", "", PddTipologia.ESTERNO, TipoOperazione.ADD,
  92.                         null, "", "",  0, descr, "", 0, implementazione, clientAuth, true);
  93.    
  94.                 pd.setDati(dati);
  95.    
  96.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  97.    
  98.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PddCostanti.OBJECT_NAME_PDD_SINGLEPDD, ForwardParams.ADD());
  99.             }
  100.    
  101.             // Controlli sui campi immessi
  102.             boolean isOk = pddHelper.pddCheckData(TipoOperazione.ADD, true);
  103.             if (!isOk) {
  104.                 // setto la barra del titolo
  105.                 ServletUtils.setPageDataTitle_ServletAdd(pd, PddCostanti.LABEL_PORTE_DI_DOMINIO, PddCostanti.SERVLET_NAME_PDD_SINGLEPDD_LIST);
  106.                    
  107.                 // preparo i campi
  108.                 List<DataElement> dati = new ArrayList<>();
  109.    
  110.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  111.    
  112.                 dati = pddHelper.addPddToDati(dati, nome, null, "", subject, "", "", PddTipologia.ESTERNO, TipoOperazione.ADD,
  113.                         null, "", "", 0, descr, "", 0, implementazione, clientAuth, true);
  114.    
  115.                 pd.setDati(dati);
  116.    
  117.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  118.    
  119.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PddCostanti.OBJECT_NAME_PDD_SINGLEPDD, ForwardParams.ADD());
  120.             }
  121.    
  122.             // Inserisco il pdd nel db
  123.             PdDControlStation pdd = new PdDControlStation();
  124.             pdd.setNome(nome);
  125.            
  126.             List<PortaDominio> listaPddOperative = null;
  127.             if(pddCore.isVisioneOggettiGlobale(userLogin)){
  128.                 listaPddOperative = pddCore.pddListSinglePdd(null,PddTipologia.OPERATIVO.toString(), new ConsoleSearch(true));
  129.             }else{
  130.                 listaPddOperative = pddCore.pddListSinglePdd(userLogin,PddTipologia.OPERATIVO.toString(), new ConsoleSearch(true));
  131.             }
  132.             if(!listaPddOperative.isEmpty())
  133.                 pdd.setTipo(PddTipologia.ESTERNO.toString());
  134.             else
  135.                 pdd.setTipo(PddTipologia.OPERATIVO.toString());
  136.             if(subject!=null && !"".equals(subject))
  137.                 pdd.setSubject(subject);
  138.             else
  139.                 pdd.setSubject(null);
  140.             pdd.setDescrizione(descr);
  141.             pdd.setImplementazione(implementazione);
  142.             pdd.setClientAuth(StatoFunzionalita.toEnumConstant(clientAuth));
  143.             pdd.setSuperUser(userLogin);

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

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

  146.             List<PdDControlStation> lista = null;
  147.             if(pddCore.isVisioneOggettiGlobale(userLogin)){
  148.                 lista = pddCore.pddList(null, ricerca);
  149.             }else{
  150.                 lista = pddCore.pddList(userLogin, ricerca);
  151.             }

  152.             pddHelper.preparePddSinglePddList(lista, ricerca);

  153.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  154.             // Forward control to the specified success URI
  155.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PddCostanti.OBJECT_NAME_PDD_SINGLEPDD, ForwardParams.ADD());

  156.         } catch (Exception e) {
  157.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  158.                     PddCostanti.OBJECT_NAME_PDD_SINGLEPDD, ForwardParams.ADD());
  159.         }
  160.     }
  161. }