PorteDelegateScopeAdd.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.pd;

  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.commons.Liste;
  31. import org.openspcoop2.core.config.AutorizzazioneScope;
  32. import org.openspcoop2.core.config.PortaDelegata;
  33. import org.openspcoop2.core.config.Scope;
  34. import org.openspcoop2.core.registry.constants.ScopeContesto;
  35. import org.openspcoop2.core.registry.driver.FiltroRicercaScope;
  36. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  37. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  38. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  39. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  40. import org.openspcoop2.web.lib.mvc.DataElement;
  41. import org.openspcoop2.web.lib.mvc.ForwardParams;
  42. import org.openspcoop2.web.lib.mvc.GeneralData;
  43. import org.openspcoop2.web.lib.mvc.PageData;
  44. import org.openspcoop2.web.lib.mvc.Parameter;
  45. import org.openspcoop2.web.lib.mvc.ServletUtils;
  46. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  47. /**
  48.  * PorteDelegateScopeAdd
  49.  *
  50.  * @author Andrea Poli (apoli@link.it)
  51.  * @author Giuliano Pintori (pintori@link.it)
  52.  * @author $Author$
  53.  * @version $Rev$, $Date$
  54.  *
  55.  */
  56. public final class PorteDelegateScopeAdd extends Action {

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

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

  60.         // Inizializzo PageData
  61.         PageData pd = new PageData();

  62.         GeneralHelper generalHelper = new GeneralHelper(session);

  63.         // Inizializzo GeneralData
  64.         GeneralData gd = generalHelper.initGeneralData(request);

  65.         try {
  66.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  67.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  68.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  69.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  70.             String id = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  71.             int idInt = Integer.parseInt(id);
  72.             String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  73.             String nome = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_SCOPE);

  74.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  75.             if(idAsps == null)
  76.                 idAsps = "";
  77.            
  78.             String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  79.             if(idFruizione == null)
  80.                 idFruizione = "";
  81.            
  82.             // Preparo il menu
  83.             porteDelegateHelper.makeMenu();

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

  85.            
  86.             // Prendo nome, tipo e pdd del soggetto
  87.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  88.                        
  89.             // Prendo nome della porta delegata
  90.             PortaDelegata pde = porteDelegateCore.getPortaDelegata(idInt);
  91.             String idporta = pde.getNome();

  92.             // Cerco Scope
  93.             FiltroRicercaScope filtroScope = new FiltroRicercaScope();
  94.             filtroScope.setContesto(ScopeContesto.PORTA_DELEGATA);
  95.             filtroScope.setTipologia("");
  96.                        
  97.             List<String> scopes = new ArrayList<>();
  98.             if(pde.getScope()!=null && pde.getScope().getScopeList()!=null && !pde.getScope().getScopeList().isEmpty()){
  99.                 for (Scope scope : pde.getScope().getScopeList()) {
  100.                     scopes.add(scope.getNome());    
  101.                 }
  102.             }
  103.            
  104.             Parameter pId = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, id);
  105.             Parameter pIdSoggetto = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idsogg);
  106.             Parameter pIdAsps = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps);
  107.             Parameter pIdFrizione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione);
  108.             Parameter[] urlParms = { pId,pIdSoggetto,pIdAsps,pIdFrizione };
  109.            
  110.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idsogg, idAsps, idFruizione);
  111.            
  112.             String labelPerPorta = null;
  113.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  114.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  115.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CONTROLLO_ACCESSI_CONFIG_DI,
  116.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CONTROLLO_ACCESSI,
  117.                         pde);
  118.             }
  119.             else {
  120.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CONTROLLO_ACCESSI_CONFIG_DI+idporta;
  121.             }
  122.            
  123.             lstParam.add(new Parameter(labelPerPorta, PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_CONTROLLO_ACCESSI,
  124.                     new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, "" + pde.getId()),
  125.                     new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME_PORTA, pde.getNome()),
  126.                     new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, pde.getIdSoggetto() + ""),
  127.                     pIdAsps, new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione+ "")));
  128.            
  129.             String labelPagLista = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_SCOPE_CONFIG;
  130.            
  131.             lstParam.add(new Parameter(labelPagLista,
  132.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_SCOPE_LIST,urlParms));
  133.             lstParam.add(ServletUtils.getParameterAggiungi());
  134.            
  135.             // Se servizioApplicativohid = null, devo visualizzare la pagina per
  136.             // l'inserimento dati
  137.             if( porteDelegateHelper.isEditModeInProgress()){
  138.                 // setto la barra del titolo
  139.                 ServletUtils.setPageDataTitle(pd, lstParam);

  140.                 // preparo i campi
  141.                 List<DataElement> dati = new ArrayList<>();
  142.                
  143.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  144.                 dati = porteDelegateHelper.addScopeToDati(TipoOperazione.ADD, dati, false, filtroScope, nome, scopes, false, true, true);

  145.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.ADD, id, idsogg, null, idAsps,
  146.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  147.                 pd.setDati(dati);

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

  149.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  150.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_SCOPE, ForwardParams.ADD());

  151.             }

  152.             // Controlli sui campi immessi
  153.             boolean isOk = porteDelegateHelper.scopeCheckData(TipoOperazione.ADD, nome, scopes);
  154.             if (!isOk) {
  155.                 // setto la barra del titolo
  156.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  159.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  160.                
  161.                 dati = porteDelegateHelper.addScopeToDati(TipoOperazione.ADD, dati, false, filtroScope, nome, scopes, false, true, true);

  162.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.ADD, id, idsogg, null, idAsps,
  163.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);
  164.  
  165.                 pd.setDati(dati);

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

  167.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  168.                         PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_SCOPE,
  169.                         ForwardParams.ADD());
  170.             }

  171.             // Inserisco il scope nel db
  172.             Scope scope = new Scope();
  173.             scope.setNome(nome);
  174.             if(pde.getScope()==null){
  175.                 pde.setScope(new AutorizzazioneScope());
  176.             }
  177.             pde.getScope().addScope(scope);

  178.             porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), pde);

  179.             // Preparo la lista
  180.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  181.            
  182.             int idLista = Liste.PORTE_DELEGATE_SCOPE;

  183.             ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);

  184.             List<String> lista = porteDelegateCore.portaDelegataScopeList(Integer.parseInt(id), ricerca);

  185.             porteDelegateHelper.preparePorteDelegateScopeList(idporta, ricerca, lista);

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

  187.             // Forward control to the specified success URI
  188.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_SCOPE,
  189.                     ForwardParams.ADD());
  190.         } catch (Exception e) {
  191.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  192.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_SCOPE,
  193.                     ForwardParams.ADD());
  194.         }  
  195.     }


  196. }