PorteDelegateAzioneList.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 java.util.Map;

  24. import javax.servlet.http.HttpServletRequest;
  25. import javax.servlet.http.HttpServletResponse;
  26. import javax.servlet.http.HttpSession;

  27. import org.apache.commons.lang.StringUtils;
  28. import org.apache.struts.action.Action;
  29. import org.apache.struts.action.ActionForm;
  30. import org.apache.struts.action.ActionForward;
  31. import org.apache.struts.action.ActionMapping;
  32. import org.openspcoop2.core.commons.Liste;
  33. import org.openspcoop2.core.config.PortaDelegata;
  34. import org.openspcoop2.core.id.IDServizio;
  35. import org.openspcoop2.core.mapping.MappingFruizionePortaDelegata;
  36. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  37. import org.openspcoop2.core.registry.beans.AccordoServizioParteComuneSintetico;
  38. import org.openspcoop2.core.registry.driver.IDAccordoFactory;
  39. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  40. import org.openspcoop2.message.constants.ServiceBinding;
  41. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  42. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  43. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  44. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  45. import org.openspcoop2.web.ctrlstat.servlet.apc.AccordiServizioParteComuneCore;
  46. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
  47. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaHelper;
  48. import org.openspcoop2.web.lib.mvc.ForwardParams;
  49. import org.openspcoop2.web.lib.mvc.GeneralData;
  50. import org.openspcoop2.web.lib.mvc.PageData;
  51. import org.openspcoop2.web.lib.mvc.Parameter;
  52. import org.openspcoop2.web.lib.mvc.ServletUtils;

  53. /**
  54.  * PorteDelegateAzioneList
  55.  *
  56.  * @author Andrea Poli (apoli@link.it)
  57.  * @author Giuliano Pintori (pintori@link.it)
  58.  * @author $Author$
  59.  * @version $Rev$, $Date$
  60.  *
  61.  */
  62. public final class PorteDelegateAzioneList extends Action {

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

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

  66.         // Inizializzo PageData
  67.         PageData pd = new PageData();

  68.         GeneralHelper generalHelper = new GeneralHelper(session);

  69.         // Inizializzo GeneralData
  70.         GeneralData gd = generalHelper.initGeneralData(request);
  71.  
  72.         try {
  73.             PorteDelegateHelper porteDelegateHelper = new PorteDelegateHelper(request, pd, session);
  74.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte delegate
  75.             Integer parentPD = ServletUtils.getIntegerAttributeFromSession(PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT, session, request);
  76.             if(parentPD == null) parentPD = PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_NONE;
  77.             String idPorta = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID);
  78.             int idInt = Integer.parseInt(idPorta);
  79.             String idsogg = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO);
  80.             String idAsps = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS);
  81.             if(idAsps == null)
  82.                 idAsps = "";
  83.             String idFruizione = porteDelegateHelper.getParameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE);
  84.            
  85.             String idTab = porteDelegateHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
  86.             if(!porteDelegateHelper.isModalitaCompleta() && StringUtils.isNotEmpty(idTab)) {
  87.                 ServletUtils.setObjectIntoSession(request, session, idTab, CostantiControlStation.PARAMETRO_ID_TAB);
  88.             }
  89.            
  90.             // Preparo il menu
  91.             porteDelegateHelper.makeMenu();
  92.            
  93.             // Prendo la porta applicativa
  94.             PorteDelegateCore porteDelegateCore = new PorteDelegateCore();
  95.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteDelegateCore);
  96.             AccordiServizioParteSpecificaCore aspsCore = new AccordiServizioParteSpecificaCore(porteDelegateCore);
  97.            
  98.             PortaDelegata portaDelegata = porteDelegateCore.getPortaDelegata(idInt);
  99.             String nomePorta = portaDelegata.getNome();
  100.            
  101.             Long idAspsLong = Long.parseLong(idAsps);
  102.             AccordoServizioParteSpecifica asps = aspsCore.getAccordoServizioParteSpecifica(idAspsLong);
  103.             AccordoServizioParteComuneSintetico aspc = apcCore.getAccordoServizioSintetico(IDAccordoFactory.getInstance().getIDAccordoFromUri(asps.getAccordoServizioParteComune()));
  104.             ServiceBinding serviceBinding = apcCore.toMessageServiceBinding(aspc.getServiceBinding());
  105.    
  106.             String labelPerPorta = null;
  107.             if(parentPD!=null && (parentPD.intValue() == PorteDelegateCostanti.ATTRIBUTO_PORTE_DELEGATE_PARENT_CONFIGURAZIONE)) {
  108.                 labelPerPorta = porteDelegateCore.getLabelRegolaMappingFruizionePortaDelegata(
  109.                         porteDelegateHelper.getLabelAzioniDi(serviceBinding),
  110.                         porteDelegateHelper.getLabelAzioni(serviceBinding),
  111.                         portaDelegata);
  112.             }
  113.             else {
  114.                 labelPerPorta = porteDelegateHelper.getLabelAzioniDi(serviceBinding)+nomePorta;
  115.             }
  116.            
  117.             MappingFruizionePortaDelegata mappingFruizione = porteDelegateCore.getMappingFruizionePortaDelegata(portaDelegata);
  118.             List<String> listaAzioni = null;
  119.             if(mappingFruizione!=null && mappingFruizione.isDefault()) {
  120.                 // calcolo azioni rimaste
  121.                 List<IDServizio> listId = new ArrayList<>();
  122.                 listId.add(IDServizioFactory.getInstance().getIDServizioFromAccordo(asps));
  123.                 List<MappingFruizionePortaDelegata> lista = porteDelegateCore.getMapping(listId, false, true);
  124.                 if(lista!=null && !lista.isEmpty()) {
  125.                     AccordiServizioParteSpecificaHelper aspsHelper = new AccordiServizioParteSpecificaHelper(request, pd, session);
  126.                     Map<String,String> azioni = porteDelegateCore.getAzioniConLabel(asps, aspc, false, true, new ArrayList<>());
  127.                     List<String> azioniL = new ArrayList<>();
  128.                     if(azioni != null && azioni.size() > 0)
  129.                         azioniL.addAll(azioni.keySet());
  130.                     listaAzioni = aspsHelper.getAllActionsNotRedefinedMappingFruizione(azioniL, lista);
  131.                 }
  132.             }
  133.             else {
  134.                 listaAzioni = portaDelegata.getAzione().getAzioneDelegataList();
  135.             }
  136.            
  137.             // Preparo la lista
  138.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  139.             int idLista = Liste.PORTE_DELEGATE_AZIONI;
  140.             ricerca = porteDelegateHelper.checkSearchParameters(idLista, ricerca);
  141.            
  142.             List<Parameter> listaParametriSessione = new ArrayList<>();
  143.             listaParametriSessione.add(new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID, idPorta));
  144.             listaParametriSessione.add(new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_SOGGETTO, idsogg));
  145.             listaParametriSessione.add(new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_ASPS, idAsps));
  146.             listaParametriSessione.add(new Parameter(PorteDelegateCostanti.PARAMETRO_PORTE_DELEGATE_ID_FRUIZIONE, idFruizione));
  147.            
  148.             List<Parameter> lstParam = porteDelegateHelper.getTitoloPD(parentPD, idsogg, idAsps, idFruizione);
  149.            
  150.             // imposto menu' contestuale
  151.             porteDelegateHelper.impostaComandiMenuContestualePD(idsogg, idAsps, idFruizione);
  152.            
  153.             porteDelegateHelper.preparePorteAzioneList(ricerca,
  154.                     listaAzioni, idPorta, parentPD, lstParam, nomePorta, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_AZIONE,
  155.                     listaParametriSessione, labelPerPorta, serviceBinding, aspc);
  156.    
  157.             if(mappingFruizione!=null && mappingFruizione.isDefault()) {
  158.                 pd.setAddButton(false);
  159.                 pd.setRemoveButton(false);
  160.                 pd.setSelect(false);
  161.             }
  162.            
  163.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  164.            
  165.             // Forward control to the specified success URI
  166.             return ServletUtils.getStrutsForward (mapping, PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_AZIONE,
  167.                     ForwardParams.LIST());
  168.         } catch (Exception e) {
  169.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  170.                     PorteDelegateCostanti.OBJECT_NAME_PORTE_DELEGATE_AZIONE,
  171.                     ForwardParams.LIST());
  172.         }  
  173.     }
  174. }