PorteApplicativeScopeAdd.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.pa;

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

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

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

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

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

  63.         GeneralHelper generalHelper = new GeneralHelper(session);

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

  66.         try {
  67.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  68.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  69.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  70.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  71.            
  72.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  73.             int idInt = Integer.parseInt(idPorta);
  74.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  75.             String nome = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_SCOPE);
  76.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  77.             if(idAsps == null)
  78.                 idAsps = "";
  79.            
  80.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();

  81.             // Preparo il menu
  82.             porteApplicativeHelper.makeMenu();

  83.             // Prendo nome della porta applicativa
  84.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  85.             String nomePorta = pa.getNome();
  86.            
  87.             // Cerco Scope
  88.             FiltroRicercaScope filtroScope = new FiltroRicercaScope();
  89.             filtroScope.setContesto(ScopeContesto.PORTA_APPLICATIVA);
  90.             filtroScope.setTipologia("");
  91.                        
  92.             List<String> scopes = new ArrayList<>();
  93.             if(pa.getScope()!=null && pa.getScope().getScopeList()!=null && !pa.getScope().getScopeList().isEmpty()){
  94.                 for (Scope scope : pa.getScope().getScopeList()) {
  95.                     scopes.add(scope.getNome());    
  96.                 }
  97.             }
  98.            
  99.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);
  100.            
  101.             String labelPerPorta = null;
  102.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  103.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  104.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONTROLLO_ACCESSI_CONFIG_DI,
  105.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONTROLLO_ACCESSI,
  106.                         pa);
  107.             }
  108.             else {
  109.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONTROLLO_ACCESSI_CONFIG_DI+nomePorta;
  110.             }
  111.            
  112.             lstParam.add(new Parameter(labelPerPorta, PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_CONTROLLO_ACCESSI,
  113.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  114.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  115.                     new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)));
  116.            
  117.             String labelPagLista = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_SCOPE_CONFIG;
  118.            
  119.             lstParam.add(new Parameter(labelPagLista,
  120.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_SCOPE_LIST,
  121.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  122.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  123.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)
  124.                     ));
  125.             lstParam.add(ServletUtils.getParameterAggiungi());

  126.             // Se servizioApplicativohid = null, devo visualizzare la pagina per
  127.             // l'inserimento dati
  128.             if (porteApplicativeHelper.isEditModeInProgress()) {
  129.                 // setto la barra del titolo
  130.                 ServletUtils.setPageDataTitle(pd, lstParam);

  131.                 // preparo i campi
  132.                 List<DataElement> dati = new ArrayList<>();
  133.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  134.                 dati = porteApplicativeHelper.addScopeToDati(TipoOperazione.ADD, dati, false, filtroScope, nome, scopes, false, true, true);
  135.                
  136.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta,idAsps,  dati);

  137.                 pd.setDati(dati);

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

  139.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_SCOPE,
  140.                         ForwardParams.ADD());
  141.             }

  142.             // Controlli sui campi immessi
  143.             boolean isOk = porteApplicativeHelper.scopeCheckData(TipoOperazione.ADD, nome, scopes);
  144.             if (!isOk) {
  145.                
  146.                 // setto la barra del titolo
  147.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  150.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  151.                
  152.                 dati = porteApplicativeHelper.addScopeToDati(TipoOperazione.ADD, dati, false, filtroScope, nome, scopes, false, true, true);
  153.                
  154.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta, idAsps, dati);

  155.                 pd.setDati(dati);

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

  157.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_SCOPE,
  158.                         ForwardParams.ADD());
  159.             }

  160.             // Inserisco il scope nel db
  161.             Scope scope = new Scope();
  162.             scope.setNome(nome);
  163.             if(pa.getScope()==null){
  164.                 pa.setScope(new AutorizzazioneScope());
  165.             }
  166.             pa.getScope().addScope(scope);

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

  168.             porteApplicativeCore.performUpdateOperation(userLogin, porteApplicativeHelper.smista(), pa);

  169.             // Preparo la lista
  170.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  171.             int idLista = Liste.PORTE_APPLICATIVE_SCOPE;

  172.             ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);

  173.             List<String> lista = porteApplicativeCore.portaApplicativaScopeList(idInt, ricerca);

  174.             porteApplicativeHelper.preparePorteApplicativeScopeList(nomePorta, ricerca, lista);

  175.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  176.             // Forward control to the specified success URI
  177.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_SCOPE,
  178.                     ForwardParams.ADD());
  179.         } catch (Exception e) {
  180.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  181.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_SCOPE,
  182.                     ForwardParams.ADD());
  183.         }
  184.     }
  185.    
  186. }