PddSinglePdDChange.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.constants.PddTipologia;
  31. import org.openspcoop2.core.registry.constants.StatoFunzionalita;
  32. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  33. import org.openspcoop2.web.ctrlstat.dao.PdDControlStation;
  34. import org.openspcoop2.web.ctrlstat.dao.SoggettoCtrlStat;
  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.  * pddSinglePdDChange
  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 PddSinglePdDChange 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.         String userLogin = ServletUtils.getUserLoginFromSession(session);

  63.         try {
  64.             PddHelper pddHelper = new PddHelper(request, pd, session);
  65.             String id = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_ID);
  66.             String descr = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_DESCRIZIONE);
  67.             String implementazione = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_IMPLEMENTAZIONE);
  68.             String subject = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_SUBJECT);
  69.             String clientAuth = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_CLIENT_AUTH);
  70.             String tipo = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_TIPOLOGIA);
  71.             String nome = pddHelper.getParameter(PddCostanti.PARAMETRO_PDD_NOME);
  72.            
  73.             PddCore pddCore = new PddCore();

  74.             // Preparo il menu
  75.             pddHelper.makeMenu();

  76.             // Prendo il nome della pdd

  77.             if ((id == null) || id.equals("")) {
  78.                 pd.setMessage("L'identificativo della porta di dominio &egrave; necessario!");
  79.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  80.                 return ServletUtils.getStrutsForwardGeneralError(mapping, PddCostanti.OBJECT_NAME_PDD_SINGLEPDD, ForwardParams.CHANGE());
  81.             }
  82.             long idPdd = Long.parseLong(id);
  83.             PdDControlStation pdd = pddCore.getPdDControlStation(idPdd);

  84.             // Se nomehid = null, devo visualizzare la pagina per la modifica
  85.             // dati
  86.             if(pddHelper.isEditModeInProgress()){
  87.                
  88.                 // setto la barra del titolo
  89.                 ServletUtils.setPageDataTitle_ServletChange(pd, PddCostanti.LABEL_PORTE_DI_DOMINIO,
  90.                         PddCostanti.SERVLET_NAME_PDD_SINGLEPDD_LIST, pdd.getNome());

  91.                 if(descr==null)
  92.                     descr = pdd.getDescrizione();
  93.                 if(nome==null)
  94.                     nome = pdd.getNome();
  95.                 if(implementazione==null)
  96.                     implementazione = pdd.getImplementazione();
  97.                 if(subject==null)
  98.                     subject = pdd.getSubject();
  99.                 if(clientAuth==null &&
  100.                     pdd.getClientAuth()!=null) {
  101.                     clientAuth = pdd.getClientAuth().toString();
  102.                 }
  103.                 tipo = pdd.getTipo();

  104.                 // preparo i campi
  105.                 List<DataElement> dati = new ArrayList<>();

  106.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  107.                 dati = pddHelper.addPddToDati(dati, nome, id, "", subject, "", "", PddTipologia.toPddTipologia(tipo), TipoOperazione.CHANGE,
  108.                         null, "", "", 0, descr, "", 0, implementazione, clientAuth, true);

  109.                 pd.setDati(dati);

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

  111.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PddCostanti.OBJECT_NAME_PDD_SINGLEPDD, ForwardParams.CHANGE());
  112.             }

  113.             // Controlli sui campi immessi
  114.             boolean isOk = pddHelper.pddCheckData(TipoOperazione.CHANGE, true);
  115.             if (!isOk) {
  116.                
  117.                 // setto la barra del titolo
  118.                 ServletUtils.setPageDataTitle_ServletChange(pd, PddCostanti.LABEL_PORTE_DI_DOMINIO,
  119.                         PddCostanti.SERVLET_NAME_PDD_SINGLEPDD_LIST, pdd.getNome());

  120.                 // preparo i campi
  121.                 List<DataElement> dati = new ArrayList<>();

  122.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  123.                 dati = pddHelper.addPddToDati(dati, nome, id, "", subject, "", "", PddTipologia.toPddTipologia(tipo), TipoOperazione.CHANGE,
  124.                         null, "", "", 0, descr, "", 0, implementazione, clientAuth, true);

  125.                 pd.setDati(dati);

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

  127.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PddCostanti.OBJECT_NAME_PDD_SINGLEPDD, ForwardParams.CHANGE());
  128.             }

  129.             // Modifico i dati del pdd nel db
  130.             pdd.setDescrizione(descr);
  131.             pdd.setImplementazione(implementazione);
  132.             if(subject!=null && !"".equals(subject))
  133.                 pdd.setSubject(subject);
  134.             else
  135.                 pdd.setSubject(null);
  136.             pdd.setClientAuth(StatoFunzionalita.toEnumConstant(clientAuth));
  137.            
  138.             ArrayList<Object> oggettiDaAggiornare = new ArrayList<>();
  139.            
  140.             // Se e' stato modificato il nome della pdd, modifico i soggetti
  141.             if(!pdd.getNome().equals(nome)){
  142.                 List<SoggettoCtrlStat> soggetti = pddCore.soggettiWithServer(pdd.getNome());
  143.                 for (SoggettoCtrlStat soggettoCtrlStat : soggetti) {
  144.                     if(soggettoCtrlStat.getSoggettoReg()!=null)
  145.                         soggettoCtrlStat.getSoggettoReg().setPortaDominio(nome);
  146.                     oggettiDaAggiornare.add(soggettoCtrlStat);
  147.                 }
  148.                 pdd.setOldNomeForUpdate(pdd.getNome());
  149.                 pdd.setNome(nome);
  150.             }
  151.            
  152.             oggettiDaAggiornare.add(pdd);
  153.            
  154.             // effettuo le operazioni
  155.             pddCore.performUpdateOperation(userLogin, pddHelper.smista(), oggettiDaAggiornare.toArray(new Object[1]));

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

  157.             List<PdDControlStation> lista = null;
  158.             if(pddCore.isVisioneOggettiGlobale(userLogin)){
  159.                 lista = pddCore.pddList(null, ricerca);
  160.             }else{
  161.                 lista = pddCore.pddList(userLogin, ricerca);
  162.             }

  163.             pddHelper.preparePddSinglePddList(lista, ricerca);

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

  165.             // Forward control to the specified success URI
  166.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PddCostanti.OBJECT_NAME_PDD_SINGLEPDD, ForwardParams.CHANGE());

  167.         } catch (Exception e) {
  168.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  169.                     PddCostanti.OBJECT_NAME_PDD_SINGLEPDD, ForwardParams.CHANGE());
  170.         }
  171.     }
  172. }