AccordiServizioParteSpecificaAllegatiView.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;

  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.id.IDSoggetto;
  31. import org.openspcoop2.core.registry.AccordoServizioParteSpecifica;
  32. import org.openspcoop2.core.registry.Documento;
  33. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  34. import org.openspcoop2.web.ctrlstat.core.Utilities;
  35. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  36. import org.openspcoop2.web.ctrlstat.servlet.aps.erogazioni.ErogazioniCostanti;
  37. import org.openspcoop2.web.ctrlstat.servlet.archivi.ArchiviCore;
  38. import org.openspcoop2.web.lib.mvc.Costanti;
  39. import org.openspcoop2.web.lib.mvc.DataElement;
  40. import org.openspcoop2.web.lib.mvc.GeneralData;
  41. import org.openspcoop2.web.lib.mvc.PageData;
  42. import org.openspcoop2.web.lib.mvc.Parameter;
  43. import org.openspcoop2.web.lib.mvc.ServletUtils;
  44. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  45. /**
  46.  * serviziAllegatiView
  47.  *
  48.  * @author Andrea Poli (apoli@link.it)
  49.  * @author Stefano Corallo (corallo@link.it)
  50.  * @author Sandra Giangrandi (sandra@link.it)
  51.  * @author $Author$
  52.  * @version $Rev$, $Date$
  53.  *
  54.  */
  55. public final class AccordiServizioParteSpecificaAllegatiView extends Action {

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

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

  59.         // Inizializzo PageData
  60.         PageData pd = new PageData();

  61.         GeneralHelper generalHelper = new GeneralHelper(session);

  62.         // Inizializzo GeneralData
  63.         GeneralData gd = generalHelper.initGeneralData(request);

  64.         try {

  65.             AccordiServizioParteSpecificaHelper apsHelper = new AccordiServizioParteSpecificaHelper(request, pd, session);

  66.             String idAllegato = apsHelper.getParameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_ID_ALLEGATO);
  67.             String idServizio = apsHelper.getParameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_ID);
  68.             String nomeDocumento = apsHelper.getParameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_NOME_DOCUMENTO);
  69.             long idAllegatoLong = Long.parseLong(idAllegato);
  70.             long idServizioLong = Long.parseLong(idServizio);

  71.             String modificaAPI = apsHelper.getParameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_MODIFICA_API);
  72.            
  73.             AccordiServizioParteSpecificaCore apsCore = new AccordiServizioParteSpecificaCore();
  74.             ArchiviCore archiviCore = new ArchiviCore(apsCore);

  75.             String tipologia = ServletUtils.getObjectFromSession(request, session, String.class, AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_TIPO_EROGAZIONE);
  76.             boolean gestioneFruitori = false;
  77.             if(tipologia!=null &&
  78.                 AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_TIPO_EROGAZIONE_VALUE_FRUIZIONE.equals(tipologia)) {
  79.                 gestioneFruitori = true;
  80.             }
  81.            
  82.             // Preparo il menu
  83.             apsHelper.makeMenu();

  84.             // Prendo il nome
  85.             AccordoServizioParteSpecifica asps = apsCore.getAccordoServizioParteSpecifica(idServizioLong);

  86.             String tipoSoggettoFruitore = null;
  87.             String nomeSoggettoFruitore = null;
  88.             IDSoggetto idSoggettoFruitore = null;
  89.             if(gestioneFruitori) {
  90.                 tipoSoggettoFruitore = apsHelper.getParameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_TIPO_SOGGETTO_FRUITORE);
  91.                 nomeSoggettoFruitore = apsHelper.getParameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_NOME_SOGGETTO_FRUITORE);
  92.                 idSoggettoFruitore = new IDSoggetto(tipoSoggettoFruitore, nomeSoggettoFruitore);
  93.             }
  94.            
  95.             String tipoProtocollo = apsCore.getProtocolloAssociatoTipoServizio(asps.getTipo());
  96.            
  97.             String tmpTitle = apsHelper.getLabelServizio(idSoggettoFruitore, gestioneFruitori, asps, tipoProtocollo);

  98.             Documento doc = archiviCore.getDocumento(idAllegatoLong,true);

  99.             StringBuilder contenutoAllegato = new StringBuilder();
  100.             String errore = Utilities.getTestoVisualizzabile(doc.getByteContenuto(),contenutoAllegato);

  101.             // setto la barra del titolo
  102.             List<Parameter> lstParam = new ArrayList<>();

  103.             Boolean vistaErogazioni = ServletUtils.getBooleanAttributeFromSession(ErogazioniCostanti.ASPS_EROGAZIONI_ATTRIBUTO_VISTA_EROGAZIONI, session, request).getValue();
  104.             if(vistaErogazioni != null && vistaErogazioni.booleanValue()) {
  105.                 if(gestioneFruitori) {
  106.                     lstParam.add(new Parameter(ErogazioniCostanti.LABEL_ASPS_FRUIZIONI, ErogazioniCostanti.SERVLET_NAME_ASPS_EROGAZIONI_LIST));
  107.                 } else {
  108.                     lstParam.add(new Parameter(ErogazioniCostanti.LABEL_ASPS_EROGAZIONI, ErogazioniCostanti.SERVLET_NAME_ASPS_EROGAZIONI_LIST));
  109.                 }
  110.                 List<Parameter> listErogazioniChange = new ArrayList<>();
  111.                 Parameter pIdServizio = new Parameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_ID, asps.getId()+ "");
  112.                 Parameter pNomeServizio = new Parameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_NOME_SERVIZIO, asps.getNome());
  113.                 Parameter pTipoServizio = new Parameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_TIPO_SERVIZIO, asps.getTipo());
  114.                 listErogazioniChange.add(pIdServizio);
  115.                 listErogazioniChange.add(pNomeServizio);
  116.                 listErogazioniChange.add(pTipoServizio);
  117.                 if(gestioneFruitori) {
  118.                     Parameter pNomeSoggettoFruitore = new Parameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_NOME_SOGGETTO_FRUITORE, nomeSoggettoFruitore);
  119.                     Parameter pTipoSoggettoFruitore = new Parameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_TIPO_SOGGETTO_FRUITORE, tipoSoggettoFruitore);
  120.                     listErogazioniChange.add(pNomeSoggettoFruitore);
  121.                     listErogazioniChange.add(pTipoSoggettoFruitore);
  122.                 }
  123.                 if(modificaAPI!=null) {
  124.                     Parameter pModificaAPI = new Parameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_MODIFICA_API, modificaAPI);
  125.                     listErogazioniChange.add(pModificaAPI);
  126.                 }
  127.                
  128.                 lstParam.add(new Parameter(tmpTitle, ErogazioniCostanti.SERVLET_NAME_ASPS_EROGAZIONI_CHANGE,
  129.                         listErogazioniChange.toArray(new Parameter[1])));
  130.                
  131.                 lstParam.add(new Parameter(ErogazioniCostanti.LABEL_ASPS_MODIFICA_SERVIZIO_INFO_GENERALI, AccordiServizioParteSpecificaCostanti.SERVLET_NAME_APS_CHANGE,
  132.                         listErogazioniChange.toArray(new Parameter[1])));
  133.                
  134.                 lstParam.add(new Parameter(AccordiServizioParteSpecificaCostanti.LABEL_APS_ALLEGATI,AccordiServizioParteSpecificaCostanti.SERVLET_NAME_APS_ALLEGATI_LIST,
  135.                         listErogazioniChange.toArray(new Parameter[1])));
  136.             } else {
  137.             if(gestioneFruitori) {
  138.                 lstParam.add(new Parameter(AccordiServizioParteSpecificaCostanti.LABEL_APS_FRUITORI, AccordiServizioParteSpecificaCostanti.SERVLET_NAME_APS_LIST));
  139.             }
  140.             else {
  141.                 lstParam.add(new Parameter(AccordiServizioParteSpecificaCostanti.LABEL_APS, AccordiServizioParteSpecificaCostanti.SERVLET_NAME_APS_LIST));
  142.             }
  143.             lstParam.add(new Parameter(AccordiServizioParteSpecificaCostanti.LABEL_APS_ALLEGATI_DI + tmpTitle,
  144.                     AccordiServizioParteSpecificaCostanti.SERVLET_NAME_APS_ALLEGATI_LIST,
  145.                     new Parameter(AccordiServizioParteSpecificaCostanti.PARAMETRO_APS_ID, idServizio)
  146.                     ));
  147.             }
  148.             lstParam.add(new Parameter(nomeDocumento, null));

  149.             // setto la barra del titolo
  150.             ServletUtils.setPageDataTitle(pd, lstParam );


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

  153.             dati = apsHelper.addHiddenFieldsToDati(TipoOperazione.OTHER, idServizio, null, null, null, null, tipoSoggettoFruitore, nomeSoggettoFruitore, dati);

  154.             dati = apsHelper.addViewAllegatiToDati(TipoOperazione.OTHER, idAllegato, idServizio, doc, contenutoAllegato, errore,
  155.                     dati, modificaAPI);

  156.             pd.setMode(Costanti.DATA_ELEMENT_EDIT_MODE_DISABLE_NAME);
  157.             pd.setDati(dati);

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

  159.             return ServletUtils.getStrutsForwardEditModeInProgress(mapping, AccordiServizioParteSpecificaCostanti.OBJECT_NAME_APS_ALLEGATI,
  160.                     AccordiServizioParteSpecificaCostanti.TIPO_OPERAZIONE_VIEW);

  161.         } catch (Exception e) {
  162.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  163.                     AccordiServizioParteSpecificaCostanti.OBJECT_NAME_APS_ALLEGATI,
  164.                     AccordiServizioParteSpecificaCostanti.TIPO_OPERAZIONE_VIEW);
  165.         }  
  166.     }


  167. }