ErogazioniVerificaCertificati.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.aps.erogazioni;

  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.id.IDServizio;
  32. import org.openspcoop2.core.id.IDSoggetto;
  33. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  34. import org.openspcoop2.core.registry.Fruitore;
  35. import org.openspcoop2.core.registry.driver.IDServizioFactory;
  36. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  37. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  38. import org.openspcoop2.web.ctrlstat.costanti.CostantiControlStation;
  39. import org.openspcoop2.web.ctrlstat.driver.DriverControlStationException;
  40. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  41. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCore;
  42. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaCostanti;
  43. import org.openspcoop2.web.ctrlstat.servlet.aps.AccordiServizioParteSpecificaUtilities;
  44. import org.openspcoop2.web.ctrlstat.servlet.config.ConfigurazioneCostanti;
  45. import org.openspcoop2.web.ctrlstat.servlet.soggetti.SoggettiCore;
  46. import org.openspcoop2.web.lib.mvc.DataElement;
  47. import org.openspcoop2.web.lib.mvc.DataElementType;
  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. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  54. /**
  55.  * ErogazioniVerificaCertificati
  56.  *
  57.  * @author Andrea Poli (poli@link.it)
  58.  * @author Giuliano Pintori (pintori@link.it)
  59.  * @author $Author$
  60.  * @version $Rev$, $Date$
  61.  *
  62.  */
  63. public class ErogazioniVerificaCertificati  extends Action {
  64.    
  65.     @Override
  66.     public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {

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

  68.         // Inizializzo PageData
  69.         PageData pd = new PageData();

  70.         GeneralHelper generalHelper = new GeneralHelper(session);

  71.         // Inizializzo GeneralData
  72.         GeneralData gd = generalHelper.initGeneralData(request);

  73.         // Parametri relativi al tipo operazione
  74.         TipoOperazione tipoOp = TipoOperazione.OTHER;
  75.        
  76.         try {
  77.             ErogazioniHelper apsHelper = new ErogazioniHelper(request, pd, session);
  78.            
  79.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore();
  80.             SoggettiCore soggettiCore = new SoggettiCore(apsCore);
  81.            
  82.             String verificaCertificatiFromLista = apsHelper.getParameter(CostantiControlStation.PARAMETRO_VERIFICA_CERTIFICATI_FROM_LISTA);
  83.             boolean arrivoDaLista = "true".equalsIgnoreCase(verificaCertificatiFromLista);
  84.            
  85.             boolean soloModI = false;
  86.             if(!arrivoDaLista) {
  87.                 String par = apsHelper.getParameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_MODIFICA_PROFILO);
  88.                 soloModI = "true".equalsIgnoreCase(par);
  89.             }
  90.                        
  91.             String id = apsHelper.getParameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_ID);
  92.             long idInt  = Long.parseLong(id);
  93.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(idInt);
  94.             String idsogg = apsHelper.getParameter(CostantiControlStation.PARAMETRO_ID_SOGGETTO);
  95.            
  96.             String tipoSoggettoFruitore = apsHelper.getParameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_TIPO_SOGGETTO_FRUITORE);
  97.             String nomeSoggettoFruitore = apsHelper.getParameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_NOME_SOGGETTO_FRUITORE);
  98.             IDSoggetto idSoggettoFruitore = null;
  99.             if(tipoSoggettoFruitore!=null && !"".equals(tipoSoggettoFruitore) &&
  100.                     nomeSoggettoFruitore!=null && !"".equals(nomeSoggettoFruitore)) {
  101.                 idSoggettoFruitore = new IDSoggetto(tipoSoggettoFruitore, nomeSoggettoFruitore);
  102.             }
  103.            
  104.             String alias = apsHelper.getParameter(ConfigurazioneCostanti.PARAMETRO_CONFIGURAZIONE_SISTEMA_NODO_CLUSTER);
  105.            
  106.             String tipologia = ServletUtils.getObjectFromSession(request, session, String.class, AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_TIPO_EROGAZIONE);
  107.             boolean gestioneFruitori = false;
  108.             boolean gestioneErogatori = false;
  109.             if(tipologia!=null) {
  110.                 if(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_TIPO_EROGAZIONE_VALUE_FRUIZIONE.equals(tipologia)) {
  111.                     gestioneFruitori = true;
  112.                 }
  113.                 else if(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_TIPO_EROGAZIONE_VALUE_EROGAZIONE.equals(tipologia)) {
  114.                     gestioneErogatori = true;
  115.                 }
  116.             }
  117.            
  118.             Fruitore fruitore = null;
  119.             String idFruizione = null;
  120.             if(gestioneFruitori) {
  121.                 // In questa modalità ci deve essere un fruitore indirizzato
  122.                 for (Fruitore check : asps.getFruitoreList()) {
  123.                     if(check.getTipo().equals(idSoggettoFruitore.getTipo()) && check.getNome().equals(idSoggettoFruitore.getNome())) {
  124.                         fruitore = check;
  125.                         break;
  126.                     }
  127.                 }
  128.             }
  129.             if(fruitore!=null) {
  130.                 idFruizione = fruitore.getId()+"";
  131.             }
  132.            
  133.             // Preparo il menu
  134.             apsHelper.makeMenu();
  135.                        
  136.             IDServizio idServizio = IDServizioFactory.getInstance().getIDServizioFromAccordo(asps);
  137.             String tipoProtocollo = soggettiCore.getProtocolloAssociatoTipoSoggetto(asps.getTipoSoggettoErogatore());
  138.            
  139.             // setto la barra del titolo
  140.             ErogazioniVerificaCertificati.impostaBarraDelTitolo(pd, apsHelper, arrivoDaLista, asps, tipoSoggettoFruitore, nomeSoggettoFruitore,
  141.                     idSoggettoFruitore, gestioneFruitori, idServizio, tipoProtocollo);
  142.            
  143.             List<DataElement> dati = new ArrayList<>();
  144.             dati.add(ServletUtils.getDataElementForEditModeFinished());
  145.            
  146.             // Esecuzione delle operazioni di verifica
  147.             boolean verificaCertificatiEffettuata = apsHelper.eseguiVerificaCertificati(soloModI, asps, idSoggettoFruitore, alias, gestioneFruitori,
  148.                     gestioneErogatori, fruitore, idServizio, tipoProtocollo, dati);
  149.            
  150.             pd.setLabelBottoneInvia(CostantiControlStation.LABEL_CONFIGURAZIONE_VERIFICA_CONNETTORE_BOTTONE);
  151.            
  152.            
  153.             if(idSoggettoFruitore != null) {
  154.                 dati = apsHelper.addHiddenFieldsToDati(tipoOp, id, idsogg, id, asps.getId()+"", idFruizione, tipoSoggettoFruitore, nomeSoggettoFruitore, dati);
  155.             }else {
  156.                 dati = apsHelper.addHiddenFieldsToDati(TipoOperazione.OTHER, asps.getId()+"", null, null, dati);
  157.             }

  158.             DataElement de = new DataElement();
  159.             de.setValue(arrivoDaLista+"");
  160.             de.setType(DataElementType.HIDDEN);
  161.             de.setName(CostantiControlStation.PARAMETRO_VERIFICA_CERTIFICATI_FROM_LISTA);
  162.             dati.add(de);
  163.            
  164.             if(soloModI) {
  165.                 de = new DataElement();
  166.                 de.setValue(soloModI+"");
  167.                 de.setType(DataElementType.HIDDEN);
  168.                 de.setName(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_MODIFICA_PROFILO);
  169.                 dati.add(de);
  170.             }
  171.            
  172.             pd.setDati(dati);

  173.             if(verificaCertificatiEffettuata) {
  174.            
  175.                 // verifica richiesta dal link nella lista, torno alla lista
  176.                 if(arrivoDaLista) {
  177.                    
  178.                     String userLogin = ServletUtils.getUserLoginFromSession(session);  
  179.                    
  180.                     ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);
  181.                    
  182.                     int idLista = Liste.SERVIZI;
  183.                    
  184.                     // poiche' esistono filtri che hanno necessita di postback salvo in sessione
  185.                     List<AccordoServizioParteSpecifica> lista = null;
  186.                     if(!ServletUtils.isSearchDone(apsHelper)) {
  187.                         lista = ServletUtils.getRisultatiRicercaFromSession(request, session, idLista,  AccordoServizioParteSpecifica.class);
  188.                     }
  189.                    
  190.                     ricerca = apsHelper.checkSearchParameters(idLista, ricerca);
  191.                    
  192.                     apsHelper.clearFiltroSoggettoByPostBackProtocollo(0, ricerca, idLista);
  193.                                        
  194.                     apsHelper.checkGestione(request, session, ricerca, idLista, tipologia,true);
  195.                    
  196.                     // preparo lista
  197.                     boolean [] permessi = AccordiServizioParteSpecificaUtilities.getPermessiUtente(apsHelper);
  198.                    
  199.                     if(lista==null) {
  200.                         if(apsCore.isVisioneOggettiGlobale(userLogin)){
  201.                             lista = apsCore.soggettiServizioList(null, ricerca,permessi, gestioneFruitori, gestioneErogatori);
  202.                         }else{
  203.                             lista = apsCore.soggettiServizioList(userLogin, ricerca,permessi, gestioneFruitori, gestioneErogatori);
  204.                         }
  205.                     }

  206.                    
  207.                     if(!apsHelper.isPostBackFilterElement()) {
  208.                         ServletUtils.setRisultatiRicercaIntoSession(request, session, idLista, lista); // salvo poiche' esistono filtri che hanno necessita di postback
  209.                     }
  210.                    
  211.                     apsHelper.prepareErogazioniList(ricerca, lista);
  212.                    
  213.                     // salvo l'oggetto ricerca nella sessione
  214.                     ServletUtils.setSearchObjectIntoSession(request, session, ricerca);
  215.                    
  216.                     ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  217.                     return ServletUtils.getStrutsForwardEditModeFinished(mapping, ErogazioniCostanti.OBJECT_NAME_ASPS_EROGAZIONI_VERIFICA_CERTIFICATI, CostantiControlStation.TIPO_OPERAZIONE_VERIFICA_CERTIFICATI);
  218.                 }
  219.                
  220.                 // verifica richiesta dal dettaglio, torno al dettaglio
  221.                 else {
  222.                     apsHelper.prepareErogazioneChange(tipoOp, asps, idSoggettoFruitore);
  223.                     ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  224.                     return ServletUtils.getStrutsForwardEditModeFinished(mapping, ErogazioniCostanti.OBJECT_NAME_ASPS_EROGAZIONI, ForwardParams.CHANGE());
  225.                 }
  226.                
  227.             }
  228.             else {
  229.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  230.                 return ServletUtils.getStrutsForwardEditModeFinished(mapping, ErogazioniCostanti.OBJECT_NAME_ASPS_EROGAZIONI_VERIFICA_CERTIFICATI, ForwardParams.OTHER(""));
  231.                
  232.             }
  233.            
  234.         } catch (Exception e) {
  235.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping, ErogazioniCostanti.OBJECT_NAME_ASPS_EROGAZIONI_VERIFICA_CERTIFICATI, ForwardParams.OTHER(""));
  236.         }  
  237.     }
  238.    
  239.     public static void impostaBarraDelTitolo(PageData pd, ErogazioniHelper apsHelper, boolean arrivoDaLista,
  240.             AccordoServizioParteSpecifica asps, String tipoSoggettoFruitore, String nomeSoggettoFruitore,
  241.             IDSoggetto idSoggettoFruitore, boolean gestioneFruitori, IDServizio idServizio, String tipoProtocollo)
  242.             throws DriverControlStationException {
  243.         String tmpTitle = apsHelper.getLabelServizio(idSoggettoFruitore, gestioneFruitori, idServizio, tipoProtocollo);
  244.        
  245.         // setto la barra del titolo
  246.         List<Parameter> listParameterChange = new ArrayList<>();
  247.         Parameter pIdsoggErogatore = new Parameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_ID_SOGGETTO_EROGATORE, ""+asps.getIdSoggetto());
  248.         Parameter pNomeServizio = new Parameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_NOME_SERVIZIO, asps.getNome());
  249.         Parameter pTipoServizio = new Parameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_TIPO_SERVIZIO, asps.getTipo());
  250.         Parameter pTipoSoggettoFruitore = null;
  251.         Parameter pNomeSoggettoFruitore = null;
  252.         if(gestioneFruitori) {
  253.             pTipoSoggettoFruitore = new Parameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_TIPO_SOGGETTO_FRUITORE, tipoSoggettoFruitore);
  254.             pNomeSoggettoFruitore = new Parameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_NOME_SOGGETTO_FRUITORE, nomeSoggettoFruitore);
  255.         }
  256.        
  257.         listParameterChange.add(new Parameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_ID, asps.getId() + ""));
  258.         listParameterChange.add(pNomeServizio);
  259.         listParameterChange.add(pTipoServizio);
  260.         listParameterChange.add(pIdsoggErogatore);
  261.        
  262.         List<Parameter> lstParm = new ArrayList<>();

  263.         if(gestioneFruitori) {
  264.             lstParm.add(new Parameter(ErogazioniCostanti.LABEL_ASPS_FRUIZIONI, ErogazioniCostanti.SERVLET_NAME_ASPS_EROGAZIONI_LIST));
  265.            
  266.             listParameterChange.add(pTipoSoggettoFruitore);
  267.             listParameterChange.add(pNomeSoggettoFruitore);
  268.         }
  269.         else {
  270.             lstParm.add(new Parameter(ErogazioniCostanti.LABEL_ASPS_EROGAZIONI, ErogazioniCostanti.SERVLET_NAME_ASPS_EROGAZIONI_LIST));
  271.         }
  272.         if(arrivoDaLista) {
  273.             String labelVerifica = ErogazioniCostanti.LABEL_ASPS_VERIFICA_CERTIFICATI_DI  + tmpTitle;
  274.             lstParm.add(new Parameter(labelVerifica, null));
  275.         }
  276.         else {
  277.             lstParm.add(new Parameter(tmpTitle, ErogazioniCostanti.SERVLET_NAME_ASPS_EROGAZIONI_CHANGE, listParameterChange.toArray(new Parameter[listParameterChange.size()])));
  278.             lstParm.add(new Parameter(ErogazioniCostanti.LABEL_ASPS_VERIFICA_CERTIFICATI, null));
  279.         }

  280.         // setto la barra del titolo
  281.         ServletUtils.setPageDataTitle(pd, lstParm );
  282.     }

  283.    

  284. }