PorteDelegateProprietaAutorizzazioneChange.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.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.PortaDelegata;
  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.  * PorteDelegateProprietaAutorizzazioneAdd
  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 PorteDelegateProprietaAutorizzazioneChange 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.  
  62.         try {
  63.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  64.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  65.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  66.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  67.             String idPorta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  68.             int idInt = Integer.parseInt(idPorta);
  69.             String nome = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME);
  70.             String valore = porteDelegateHelper.getLockedParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_VALORE, false);
  71.             String idSoggFruitore = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  72.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  73.             if(idAsps == null)
  74.                 idAsps = "";
  75.             String idFruizione= porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  76.             if(idFruizione == null)
  77.                 idFruizione = "";
  78.            
  79.             // Wrap value
  80.             valore = porteDelegateHelper.wrapValoreProprieta(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_VALORE, valore);
  81.            
  82.             // Preparo il menu
  83.             porteDelegateHelper.makeMenu();

  84.             // Prendo nome, tipo e pdd del soggetto
  85.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();

  86.             // Prendo nome della porta applicativa
  87.             PortaDelegata pde = porteDelegateCore.getPortaDelegata(idInt);
  88.             String idporta = pde.getNome();
  89.            
  90.             Parameter pId = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, "" + pde.getId());
  91.             Parameter pIdSoggetto = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, pde.getIdSoggetto() + "");
  92.             Parameter pIdAsps = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps);
  93.             Parameter pIdFrizione = new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione);
  94.             Parameter[] urlParms = { pId,pIdSoggetto,pIdAsps,pIdFrizione };
  95.            
  96.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idSoggFruitore, idAsps, idFruizione);
  97.            
  98.             String labelPerPorta = null;
  99.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  100.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  101.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CONTROLLO_ACCESSI_CONFIG_DI,
  102.                         PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CONTROLLO_ACCESSI,
  103.                         pde);
  104.             }
  105.             else {
  106.                 labelPerPorta = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_CONTROLLO_ACCESSI_CONFIG_DI+idporta;
  107.             }
  108.            
  109.             lstParam.add(new Parameter(labelPerPorta, PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_CONTROLLO_ACCESSI,
  110.                     new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, "" + pde.getId()),
  111.                     new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_NOME_PORTA, pde.getNome()),
  112.                     new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, pde.getIdSoggetto() + ""),
  113.                     pIdAsps, new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione+ "")));
  114.            
  115.             String labelPagLista = PorteDelegateCostanti.LABEL_PARAMETRO_PORTE_DELEGATE_AUTORIZZAZIONE_PROPRIETA;
  116.            
  117.             lstParam.add(new Parameter(labelPagLista,
  118.                     PorteDelegateCostanti.SERVLET_NAME_PORTE_DELEGATE_AUTORIZZAZIONE_CUSTOM_PROPERTIES_LIST,urlParms));
  119.             lstParam.add(new Parameter(nome, null));
  120.            
  121.             // Se nome = null, devo visualizzare la pagina per l'inserimento
  122.             // dati
  123.             if (porteDelegateHelper.isEditModeInProgress()) {
  124.                 // setto la barra del titolo
  125.                 ServletUtils.setPageDataTitle(pd, lstParam);
  126.                
  127.                 if(valore==null){
  128.                     for (int i = 0; i < pde.sizeProprietaAutorizzazioneList(); i++) {
  129.                         Proprieta ssp = pde.getProprietaAutorizzazione(i);
  130.                         if (nome.equals(ssp.getNome())) {
  131.                             if(ssp.getValore()!=null){
  132.                                 valore = ssp.getValore();
  133.                             }
  134.                             break;
  135.                         }
  136.                     }
  137.                 }

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

  141.                 dati = porteDelegateHelper.addProprietaAutorizzazioneCustomToDati(dati, TipoOperazione.CHANGE, nome ,valore);

  142.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, idPorta, idSoggFruitore,  null,idAsps,
  143.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  144.                 pd.setDati(dati);

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

  146.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_AUTORIZZAZIONE_CUSTOM_PROPERTIES,
  147.                         ForwardParams.CHANGE());
  148.             }

  149.             // Controlli sui campi immessi
  150.             boolean isOk = porteDelegateHelper.proprietaAutorizzazioneCheckData(TipoOperazione.CHANGE, idPorta, nome, valore);
  151.             if (!isOk) {
  152.                 // setto la barra del titolo
  153.                 ServletUtils.setPageDataTitle(pd, lstParam);

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

  156.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  157.                
  158.                 dati = porteDelegateHelper.addProprietaAutorizzazioneCustomToDati(dati, TipoOperazione.CHANGE, nome ,valore);

  159.                 dati = porteDelegateHelper.addHiddenFieldsToDati(TipoOperazione.CHANGE, idPorta, idSoggFruitore,  null,idAsps,
  160.                         idFruizione, pde.getTipoSoggettoProprietario(), pde.getNomeSoggettoProprietario(), dati);

  161.                 pd.setDati(dati);

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

  163.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_AUTORIZZAZIONE_CUSTOM_PROPERTIES,
  164.                         ForwardParams.CHANGE());
  165.             }

  166.             // rimuovo la vecchia proprieta'
  167.             for (int i = 0; i < pde.sizeProprietaAutorizzazioneList(); i++) {
  168.                 Proprieta ssp = pde.getProprietaAutorizzazione(i);
  169.                 if (nome.equals(ssp.getNome())) {
  170.                     pde.removeProprietaAutorizzazione(i);
  171.                     break;
  172.                 }
  173.             }
  174.            
  175.             // inserisco la nuova proprieta
  176.             Proprieta ssp = new Proprieta();
  177.             ssp.setNome(nome);
  178.             ssp.setValore(valore);
  179.             pde.addProprietaAutorizzazione(ssp);

  180.             String userLogin = ServletUtils.getUserLoginFromSession(session);
  181.            
  182.             porteDelegateCore.performUpdateOperation(userLogin, porteDelegateHelper.smista(), pde);

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

  185.             int idLista = Liste.PORTE_DELEGATE_PROPRIETA_AUTORIZZAZIONE;

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

  187.             List<Proprieta> lista = porteDelegateCore.porteDelegateAutorizzazioneCustomPropList(Integer.parseInt(idPorta), ricerca);

  188.             porteDelegateHelper.preparePorteDelegateAutorizzazioneCustomPropList(idporta, ricerca, lista);

  189.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  190.             // Forward control to the specified success URI
  191.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_AUTORIZZAZIONE_CUSTOM_PROPERTIES,
  192.                     ForwardParams.CHANGE());
  193.         } catch (Exception e) {
  194.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  195.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_AUTORIZZAZIONE_CUSTOM_PROPERTIES,
  196.                     ForwardParams.CHANGE());
  197.         }  
  198.     }

  199.    
  200. }