AccordiServizioParteComuneAllegatiView.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.apc;

  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.registry.AccordoServizioParteComune;
  31. import org.openspcoop2.core.registry.Documento;
  32. import org.openspcoop2.core.registry.driver.IDAccordoFactory;
  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.apc.api.ApiCostanti;
  37. import org.openspcoop2.web.ctrlstat.servlet.archivi.ArchiviCore;
  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.  * accordiAllegatiView
  45.  *
  46.  * @author Andrea Poli (apoli@link.it)
  47.  * @author Stefano Corallo (corallo@link.it)
  48.  * @author Sandra Giangrandi (sandra@link.it)
  49.  * @author $Author$
  50.  * @version $Rev$, $Date$
  51.  *
  52.  */
  53. public final class AccordiServizioParteComuneAllegatiView extends Action {

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

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

  57.         // Inizializzo PageData
  58.         PageData pd = new PageData();

  59.         GeneralHelper generalHelper = new GeneralHelper(session);

  60.         // Inizializzo GeneralData
  61.         GeneralData gd = generalHelper.initGeneralData(request);

  62.         try {
  63.                        
  64.             AccordiServizioParteComuneHelper apcHelper = new AccordiServizioParteComuneHelper(request, pd, session);

  65.             String idAllegato = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_ALLEGATI_ID_ALLEGATO);
  66.             String idAccordo = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_ALLEGATI_ID_ACCORDO);
  67.            
  68.             long idAllegatoLong = Long.parseLong(idAllegato);
  69.             long idAccordoLong = Long.parseLong(idAccordo);
  70.            
  71.             String tipoAccordo = apcHelper.getParameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_TIPO_ACCORDO);
  72.             if("".equals(tipoAccordo))
  73.                 tipoAccordo = null;
  74.            
  75.             AccordiServizioParteComuneCore apcCore = new AccordiServizioParteComuneCore();
  76.             ArchiviCore archiviCore = new ArchiviCore(apcCore);

  77.             // Preparo il menu
  78.             apcHelper.makeMenu();

  79.             // Prendo il nome
  80.             AccordoServizioParteComune as = apcCore.getAccordoServizioFull(idAccordoLong);
  81.             String labelASTitle = apcHelper.getLabelIdAccordo(as);
  82.            
  83.             Documento doc = archiviCore.getDocumento(idAllegatoLong,true);

  84.             StringBuilder contenutoAllegato = new StringBuilder();
  85.             String errore = Utilities.getTestoVisualizzabile(doc.getByteContenuto(),contenutoAllegato);
  86.            
  87.             IDAccordoFactory idAccordoFactory = IDAccordoFactory.getInstance();
  88.             String uri = idAccordoFactory.getUriFromAccordo(as);
  89.             Parameter pTipoAccordo = AccordiServizioParteComuneUtilities.getParametroAccordoServizio(tipoAccordo);
  90.             Parameter pIdAccordo = new Parameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_ID, idAccordo);
  91.             Parameter pNomeAccordo = new Parameter(AccordiServizioParteComuneCostanti.PARAMETRO_APC_NOME, uri);
  92.            
  93.             Boolean isModalitaVistaApiCustom = ServletUtils.getBooleanAttributeFromSession(ApiCostanti.SESSION_ATTRIBUTE_VISTA_APC_API, session, request, false).getValue();
  94.             List<Parameter> listaParams = apcHelper.getTitoloApc(TipoOperazione.ADD, as, tipoAccordo, labelASTitle, null, false);
  95.            
  96.             String labelAllegati = (isModalitaVistaApiCustom!=null && isModalitaVistaApiCustom.booleanValue()) ? AccordiServizioParteComuneCostanti.LABEL_ALLEGATI : AccordiServizioParteComuneCostanti.LABEL_ALLEGATI + " di " + labelASTitle;
  97.              
  98.             listaParams.add(new Parameter(labelAllegati, AccordiServizioParteComuneCostanti.SERVLET_NAME_APC_ALLEGATI_LIST, pIdAccordo, pNomeAccordo, pTipoAccordo));
  99.             listaParams.add(new Parameter(doc.getFile(), null));
  100.            
  101.             // setto la barra del titolo
  102.             ServletUtils.setPageDataTitle(pd, listaParams);
  103.            
  104.             // preparo i campi
  105.             List<Object> dati = new ArrayList<>();

  106.             dati.add(ServletUtils.getDataElementForEditModeFinished());

  107.             apcHelper.addAccordiAllegatiToDati(dati,TipoOperazione.OTHER,idAccordo,
  108.                     null,null,null,null,tipoAccordo,null,
  109.                     idAllegato,doc,as,errore,contenutoAllegato,null);
  110.                        
  111.             pd.setDati(dati);

  112.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  113.            
  114.             return ServletUtils.getStrutsForwardEditModeInProgress(mapping, AccordiServizioParteComuneCostanti.OBJECT_NAME_APC_ALLEGATI,
  115.                     AccordiServizioParteComuneCostanti.TIPO_OPERAZIONE_VIEW);
  116.            
  117.         } catch (Exception e) {
  118.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  119.                     AccordiServizioParteComuneCostanti.OBJECT_NAME_APC_ALLEGATI, AccordiServizioParteComuneCostanti.TIPO_OPERAZIONE_VIEW);
  120.         }
  121.     }
  122. }