About.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.about;

  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.commons.lang.StringEscapeUtils;
  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.web.ctrlstat.core.ControlStationCore;
  33. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  34. import org.openspcoop2.web.lib.mvc.BinaryParameter;
  35. import org.openspcoop2.web.lib.mvc.DataElement;
  36. import org.openspcoop2.web.lib.mvc.GeneralData;
  37. import org.openspcoop2.web.lib.mvc.MessageType;
  38. import org.openspcoop2.web.lib.mvc.PageData;
  39. import org.openspcoop2.web.lib.mvc.Parameter;
  40. import org.openspcoop2.web.lib.mvc.ServletUtils;
  41. import org.openspcoop2.web.lib.mvc.TipoOperazione;

  42. /**
  43.  * About
  44.  *
  45.  * @author Poli Andrea (apoli@link.it)
  46.  * @author Pintori Giuliano (pintori@link.it)
  47.  * @author $Author$
  48.  * @version $Rev$, $Date$
  49.  */
  50. public class About extends Action{


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

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

  54.         // Inizializzo PageData
  55.         PageData pd = new PageData();

  56.         GeneralHelper generalHelper = new GeneralHelper(session);

  57.         // Inizializzo GeneralData
  58.         GeneralData gd = generalHelper.initGeneralData(request);

  59.         String userLogin = ServletUtils.getUserLoginFromSession(session);

  60.         try {

  61.             AboutHelper aHelper = new AboutHelper(request, pd, session);

  62.             // Preparo il menu
  63.             aHelper.makeMenu();

  64.             // setto la barra del titolo
  65.             List<Parameter> lstParam = new ArrayList<>();
  66.             lstParam.add(new Parameter(AboutCostanti.LABEL_ABOUT, null));

  67.             ServletUtils.setPageDataTitle(pd, lstParam);
  68.            
  69.             // preparo i campi
  70.             List<DataElement> dati = new ArrayList<>();

  71.             BinaryParameter infoP = aHelper.getBinaryParameter(AboutCostanti.PARAMETRO_ABOUT_INFO);
  72.            
  73.             String infoDone = aHelper.getParameter(AboutCostanti.PARAMETRO_ABOUT_INFO_FINISH);
  74.             boolean doUpdate = ServletUtils.isCheckBoxEnabled(infoDone);
  75.            
  76.             String aggiornamentoNonRiuscito = null;
  77.             String aggiornamentoEffettuato = null;
  78.             if(doUpdate) {
  79.                 if(infoP.getValue()!=null) {
  80.                     try {
  81.                         aHelper.getCore().updateInfoVersion(request, session, new String(infoP.getValue()));
  82.                         aggiornamentoEffettuato = "Aggiornamento completato con successo";
  83.                         gd.setTitle(StringEscapeUtils.escapeHtml(aHelper.getCore().getConsoleNomeEsteso(request, session)));
  84.                     }catch(Exception e) {
  85.                         aggiornamentoNonRiuscito = "Aggiornamento fallito: "+e.getMessage();
  86.                     }
  87.                 }
  88.                 else {
  89.                     aggiornamentoNonRiuscito = "Licenza non fornita";
  90.                 }
  91.             }
  92.            
  93.             dati = aHelper.addAboutToDati(dati,TipoOperazione.OTHER,userLogin,infoP);
  94.            
  95.             if(!StringUtils.isEmpty(aggiornamentoNonRiuscito)) {
  96.                 pd.setMessage(aggiornamentoNonRiuscito, MessageType.ERROR);
  97.             }
  98.             else if(!StringUtils.isEmpty(aggiornamentoEffettuato)) {
  99.                 pd.setMessage(aggiornamentoEffettuato, MessageType.INFO);
  100.             }
  101.            
  102.             pd.setDati(dati);
  103.            
  104.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  105.             return ServletUtils.getStrutsForwardEditModeFinished(mapping, AboutCostanti.OBJECT_NAME_ABOUT,
  106.                     AboutCostanti.TIPO_OPERAZIONE_ABOUT);
  107.         } catch (Exception e) {
  108.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  109.                     AboutCostanti.OBJECT_NAME_ABOUT, AboutCostanti.TIPO_OPERAZIONE_ABOUT);
  110.         }  
  111.     }
  112. }