PorteApplicativeProprietaAutorizzazioneContenutoAdd.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.List;
  22. import java.util.ArrayList;

  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.PortaApplicativa;
  32. import org.openspcoop2.core.config.Proprieta;
  33. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  34. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  35. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  36. import org.openspcoop2.web.lib.mvc.DataElement;
  37. import org.openspcoop2.web.lib.mvc.ForwardParams;
  38. import org.openspcoop2.web.lib.mvc.GeneralData;
  39. import org.openspcoop2.web.lib.mvc.PageData;
  40. import org.openspcoop2.web.lib.mvc.Parameter;
  41. import org.openspcoop2.web.lib.mvc.ServletUtils;
  42. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  43. /**
  44.  * PorteApplicativeProprietaAutorizzazioneContenutoAdd
  45.  *
  46.  * @author Andrea Poli (apoli@link.it)
  47.  * @author Giuliano Pintori (pintori@link.it)
  48.  * @author $Author$
  49.  * @version $Rev$, $Date$
  50.  *
  51.  */
  52. public final class PorteApplicativeProprietaAutorizzazioneContenutoAdd extends Action {

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

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

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

  58.         GeneralHelper generalHelper = new GeneralHelper(session);

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

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

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

  82.             // Prendo nome della porta applicativa
  83.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  84.             String nomePorta = pa.getNome();
  85.            
  86.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);
  87.            
  88.             String labelPerPorta = null;
  89.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  90.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  91.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONTROLLO_ACCESSI_CONFIG_DI,
  92.                         PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONTROLLO_ACCESSI,
  93.                         pa);
  94.             }
  95.             else {
  96.                 labelPerPorta = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_CONTROLLO_ACCESSI_CONFIG_DI+nomePorta;
  97.             }
  98.            
  99.             lstParam.add(new Parameter(labelPerPorta, PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_CONTROLLO_ACCESSI,
  100.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  101.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  102.                     new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)));
  103.            
  104.             String labelPagLista = PorteApplicativeCostanti.LABEL_PARAMETRO_PORTE_APPLICATIVE_AUTORIZZAZIONE_CONTENUTO_PROPRIETA;
  105.            
  106.             lstParam.add(new Parameter(labelPagLista,
  107.                     PorteApplicativeCostanti.SERVLET_NAME_PORTE_APPLICATIVE_AUTORIZZAZIONE_CONTENUTI_CUSTOM_PROPERTIES_LIST,
  108.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta),
  109.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg),
  110.                     new Parameter( PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps)
  111.                     ));
  112.             lstParam.add(ServletUtils.getParameterAggiungi());

  113.             // Se servizioApplicativohid = null, devo visualizzare la pagina per
  114.             // l'inserimento dati
  115.             if (porteApplicativeHelper.isEditModeInProgress()) {
  116.                 // setto la barra del titolo
  117.                 ServletUtils.setPageDataTitle(pd, lstParam);

  118.                 // preparo i campi
  119.                 List<DataElement> dati = new ArrayList<>();
  120.                 dati.add(ServletUtils.getDataElementForEditModeFinished());

  121.                 dati = porteApplicativeHelper.addProprietaAutorizzazioneCustomToDati(dati, TipoOperazione.ADD, nome, valore);
  122.                
  123.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta,idAsps,  dati);

  124.                 pd.setDati(dati);

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

  126.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_AUTORIZZAZIONE_CONTENUTI_CUSTOM_PROPERTIES,
  127.                         ForwardParams.ADD());
  128.             }

  129.             // Controlli sui campi immessi
  130.             boolean isOk = porteApplicativeHelper.proprietaAutorizzazioneContenutoCheckData(TipoOperazione.ADD, idPorta, nome, valore);
  131.             if (!isOk) {
  132.                
  133.                 // setto la barra del titolo
  134.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  137.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  138.                
  139.                 dati = porteApplicativeHelper.addProprietaAutorizzazioneCustomToDati(dati, TipoOperazione.ADD, nome, valore);
  140.                
  141.                 dati = porteApplicativeHelper.addHiddenFieldsToDati(TipoOperazione.ADD, idPorta, idsogg, idPorta, idAsps, dati);

  142.                 pd.setDati(dati);

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

  144.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_AUTORIZZAZIONE_CONTENUTI_CUSTOM_PROPERTIES,
  145.                         ForwardParams.ADD());
  146.             }

  147.             // Inserisco il ruolo nel db
  148.            
  149.            
  150.             Proprieta prop = new Proprieta();
  151.             prop.setNome(nome);
  152.             prop.setValore(valore);
  153.             pa.addProprietaAutorizzazioneContenuto(prop);

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

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

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

  158.             int idLista = Liste.PORTE_APPLICATIVE_PROPRIETA_AUTORIZZAZIONE_CONTENUTO;

  159.             ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
  160.            
  161.             List<Proprieta> lista = porteApplicativeCore.porteApplicativeAutorizzazioneContenutoCustomPropList(idInt, ricerca);

  162.             porteApplicativeHelper.preparePorteApplicativeAutorizzazioneContenutoCustomPropList(nomePorta, ricerca, lista);

  163.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  164.             // Forward control to the specified success URI
  165.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_AUTORIZZAZIONE_CONTENUTI_CUSTOM_PROPERTIES,
  166.                     ForwardParams.ADD());
  167.         } catch (Exception e) {
  168.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  169.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_AUTORIZZAZIONE_CONTENUTI_CUSTOM_PROPERTIES,
  170.                     ForwardParams.ADD());
  171.         }
  172.     }
  173.    
  174. }