PorteApplicativeAzioneList.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 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.PortaApplicativa;
  34. import org.openspcoop2.core.id.IDServizio;
  35. import org.openspcoop2.core.mapping.MappingErogazionePortaApplicativa;
  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.  * PorteApplicativeAzioneList
  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 PorteApplicativeAzioneList 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.             PorteApplicativeHelper porteApplicativeHelper = new PorteApplicativeHelper(request, pd, session);
  74.             // prelevo il flag che mi dice da quale pagina ho acceduto la sezione delle porte applicative
  75.             Integer parentPA = ServletUtils.getIntegerAttributeFromSession(PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT, session, request);
  76.             if(parentPA == null) parentPA = PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_NONE;
  77.            
  78.             String idPorta = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID);
  79.             int idInt = Integer.parseInt(idPorta);
  80.             String idsogg = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO);
  81.             String idAsps = porteApplicativeHelper.getParameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS);
  82.             if(idAsps == null)
  83.                 idAsps = "";
  84.            
  85.             String idTab = porteApplicativeHelper.getParameter(CostantiControlStation.PARAMETRO_ID_TAB);
  86.             if(!porteApplicativeHelper.isModalitaCompleta() && StringUtils.isNotEmpty(idTab)) {
  87.                 ServletUtils.setObjectIntoSession(request, session, idTab, CostantiControlStation.PARAMETRO_ID_TAB);
  88.             }
  89.            
  90.             // Preparo il menu
  91.             porteApplicativeHelper.makeMenu();
  92.    
  93.             // Prendo nome della porta applicativa
  94.             PorteApplicativeCore porteApplicativeCore = new PorteApplicativeCore();
  95.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore(porteApplicativeCore);
  96.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore(porteApplicativeCore);
  97.            
  98.             PortaApplicativa pa = porteApplicativeCore.getPortaApplicativa(idInt);
  99.             String nomePorta = pa.getNome();
  100.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(Integer.parseInt(idAsps));
  101.             AccordoServizioParteComuneSintetico aspc = apcCore.getAccordoServizioSintetico(IDAccordoFactory.getInstance().getIDAccordoFromUri(asps.getAccordoServizioParteComune()));
  102.             ServiceBinding serviceBinding = apcCore.toMessageServiceBinding(aspc.getServiceBinding());
  103.            
  104.             String labelPerPorta = null;
  105.             if(parentPA!=null && (parentPA.intValue() == PorteApplicativeCostanti.ATTRIBUTO_PORTE_APPLICATIVE_PARENT_CONFIGURAZIONE)) {
  106.                 labelPerPorta = porteApplicativeCore.getLabelRegolaMappingErogazionePortaApplicativa(
  107.                         porteApplicativeHelper.getLabelAzioniDi(serviceBinding),
  108.                         porteApplicativeHelper.getLabelAzioni(serviceBinding),
  109.                         pa);
  110.             }
  111.             else {
  112.                 labelPerPorta = porteApplicativeHelper.getLabelAzioniDi(serviceBinding)+pa.getNome();
  113.             }
  114.            
  115.             MappingErogazionePortaApplicativa mappingErogazione = porteApplicativeCore.getMappingErogazionePortaApplicativa(pa);
  116.             List<String> listaAzioni = null;
  117.             if(mappingErogazione!=null && mappingErogazione.isDefault()) {
  118.                 // calcolo azioni rimaste
  119.                 List<IDServizio> listId = new ArrayList<>();
  120.                 listId.add(IDServizioFactory.getInstance().getIDServizioFromAccordo(asps));
  121.                 List<MappingErogazionePortaApplicativa> lista = porteApplicativeCore.getMapping(listId, false, true);
  122.                 if(lista!=null && !lista.isEmpty()) {
  123.                     AccordiServizioParteSpecificaHelper aspsHelper = new AccordiServizioParteSpecificaHelper(request, pd, session);
  124.                     Map<String,String> azioni = porteApplicativeCore.getAzioniConLabel(asps, aspc, false, true, new ArrayList<>());
  125.                     List<String> azioniL = new ArrayList<>();
  126.                     if(azioni != null && azioni.size() > 0)
  127.                         azioniL.addAll(azioni.keySet());
  128.                     listaAzioni = aspsHelper.getAllActionsNotRedefinedMappingErogazione(azioniL, lista);
  129.                 }
  130.             }
  131.             else {
  132.                 listaAzioni = pa.getAzione().getAzioneDelegataList();
  133.             }
  134.            
  135.             // Preparo la lista
  136.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  137.             int idLista = Liste.PORTE_APPLICATIVE_AZIONI;
  138.             ricerca = porteApplicativeHelper.checkSearchParameters(idLista, ricerca);
  139.            
  140.             List<Parameter> lstParam = porteApplicativeHelper.getTitoloPA(parentPA, idsogg, idAsps);
  141.             List<Parameter> listaParametriSessione = new ArrayList<>();
  142.             listaParametriSessione.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID, idPorta));
  143.             listaParametriSessione.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_SOGGETTO, idsogg));
  144.             listaParametriSessione.add(new Parameter(PorteApplicativeCostanti.PARAMETRO_PORTE_APPLICATIVE_ID_ASPS, idAsps));
  145.             porteApplicativeHelper.preparePorteAzioneList(ricerca,
  146.                     listaAzioni, idPorta, parentPA, lstParam, nomePorta, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_AZIONE,
  147.                     listaParametriSessione, labelPerPorta, serviceBinding, aspc);
  148.            
  149.             // imposto menu' contestuale
  150.             porteApplicativeHelper.impostaComandiMenuContestualePA(idsogg, idAsps);
  151.    
  152.             if(mappingErogazione!=null && mappingErogazione.isDefault()) {
  153.                 pd.setAddButton(false);
  154.                 pd.setRemoveButton(false);
  155.                 pd.setSelect(false);
  156.             }
  157.            
  158.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  159.            
  160.             // Forward control to the specified success URI
  161.             return ServletUtils.getStrutsForward (mapping, PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_AZIONE,
  162.                     ForwardParams.LIST());
  163.         } catch (Exception e) {
  164.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  165.                     PorteApplicativeCostanti.OBJECT_NAME_PORTE_APPLICATIVE_AZIONE,
  166.                     ForwardParams.LIST());
  167.         }  
  168.     }
  169. }