ConfigurazioneAuditingFiltriAdd.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.config;

  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.web.ctrlstat.core.ConsoleSearch;
  32. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  33. import org.openspcoop2.web.ctrlstat.driver.IDBuilder;
  34. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  35. import org.openspcoop2.web.ctrlstat.servlet.audit.AuditingCore;
  36. import org.openspcoop2.web.lib.audit.dao.Configurazione;
  37. import org.openspcoop2.web.lib.audit.dao.Filtro;
  38. import org.openspcoop2.web.lib.audit.log.constants.Stato;
  39. import org.openspcoop2.web.lib.audit.log.constants.Tipologia;
  40. import org.openspcoop2.web.lib.audit.web.AuditCostanti;
  41. import org.openspcoop2.web.lib.audit.web.AuditHelper;
  42. import org.openspcoop2.web.lib.mvc.Costanti;
  43. import org.openspcoop2.web.lib.mvc.DataElement;
  44. import org.openspcoop2.web.lib.mvc.ForwardParams;
  45. import org.openspcoop2.web.lib.mvc.GeneralData;
  46. import org.openspcoop2.web.lib.mvc.PageData;
  47. import org.openspcoop2.web.lib.mvc.Parameter;
  48. import org.openspcoop2.web.lib.mvc.ServletUtils;

  49. /**
  50.  * filtriAdd
  51.  *
  52.  * @author Andrea Poli (apoli@link.it)
  53.  * @author Stefano Corallo (corallo@link.it)
  54.  * @author Sandra Giangrandi (sandra@link.it)
  55.  * @author $Author$
  56.  * @version $Rev$, $Date$
  57.  *
  58.  */
  59. public final class ConfigurazioneAuditingFiltriAdd extends Action {

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

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

  63.         // Inizializzo PageData
  64.         PageData pd = new PageData();

  65.         GeneralHelper generalHelper = new GeneralHelper(session);

  66.         // Inizializzo GeneralData
  67.         GeneralData gd = generalHelper.initGeneralData(request);

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

  69.         try {
  70.             ConfigurazioneHelper confHelper = new ConfigurazioneHelper(request, pd, session);

  71.             String utente = confHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_UTENTE);
  72.             String tipooperazione = confHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_TIPO_OPERAZIONE);
  73.             String tipooggetto = confHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_TIPO_OGGETTO);
  74.             String statooperazione = confHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_STATO_OPERAZIONE);
  75.             String stato = confHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_STATO);
  76.             String tipofiltro = confHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_TIPO_FILTRO);
  77.             String dump = confHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_DUMP);
  78.             String statoazione = confHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_STATO_AZIONE);
  79.             String dumpazione = confHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_DUMP_AZIONE);

  80.             ConfigurazioneCore confCore = new ConfigurazioneCore();
  81.             AuditingCore auditingCore = new AuditingCore(confCore);
  82.             AuditHelper ah = new AuditHelper(request, pd, session);

  83.             IDBuilder idb = new IDBuilder();
  84.             String[] tipiOggTmp = idb.getManagedObjects(true);
  85.             String[] tipiOgg = new String[tipiOggTmp.length+1];
  86.             tipiOgg[0] = "-";
  87.             for (int i = 0; i < tipiOggTmp.length; i++)
  88.                 tipiOgg[i+1] = tipiOggTmp[i];

  89.             // Preparo il menu
  90.             confHelper.makeMenu();

  91.             // Se idhid = null, devo visualizzare la pagina per l'inserimento
  92.             // dati
  93.             if (confHelper.isEditModeInProgress()) {
  94.                 // setto la barra del titolo
  95.                 List<Parameter> lstParam = new ArrayList<>();

  96.                 lstParam.add(new Parameter(AuditCostanti.LABEL_AUDIT,
  97.                         AuditCostanti.SERVLET_NAME_AUDIT));
  98.                 lstParam.add(new Parameter(AuditCostanti.LABEL_AUDIT_FILTRI,
  99.                         AuditCostanti.SERVLET_NAME_AUDIT_FILTRI_LIST));
  100.                 lstParam.add(ServletUtils.getParameterAggiungi());

  101.                 ServletUtils.setPageDataTitle(pd, lstParam);

  102.                 // preparo i campi
  103.                 if (utente == null) {
  104.                     Configurazione conf = auditingCore.getConfigurazioneAudit();
  105.                     utente = "";
  106.                     tipooperazione = "-";
  107.                     tipooggetto = "-";
  108.                     statooperazione = "-";
  109.                     stato = AuditCostanti.DEFAULT_VALUE_DISABILITATO;
  110.                     tipofiltro = AuditCostanti.DEFAULT_VALUE_PARAMETRO_AUDIT_TIPO_FILTRO_NORMALE;
  111.                     dump = "";
  112.                     statoazione = conf.isAuditEnabled() ?
  113.                             AuditCostanti.DEFAULT_VALUE_ABILITATO : AuditCostanti.DEFAULT_VALUE_DISABILITATO;
  114.                     dumpazione = conf.isDumpEnabled() ?
  115.                             AuditCostanti.DEFAULT_VALUE_ABILITATO : AuditCostanti.DEFAULT_VALUE_DISABILITATO;
  116.                 }
  117.                 List<DataElement> dati = ah.addFiltroToDati(
  118.                         Tipologia.ADD, utente, tipooperazione, tipiOgg,
  119.                         tipooggetto, statooperazione, stato, tipofiltro,
  120.                         dump, statoazione, dumpazione, "0");

  121.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  122.                 pd.setDati(dati);

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

  124.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  125.                         AuditCostanti.OBJECT_NAME_CONFIGURAZIONE_AUDITING_FILTRI,
  126.                         ForwardParams.ADD());
  127.             }

  128.             // Controlli sui campi immessi
  129.             String msg = ah.filtriCheckData(utente, tipooperazione,
  130.                     tipooggetto, statooperazione,
  131.                     stato, tipofiltro,
  132.                     dump, statoazione,
  133.                     dumpazione, tipiOgg);
  134.             if (!msg.equals("")) {
  135.                 pd.setMessage(msg);

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

  138.                 lstParam.add(new Parameter(AuditCostanti.LABEL_AUDIT,
  139.                         AuditCostanti.SERVLET_NAME_AUDIT));
  140.                 lstParam.add(new Parameter(AuditCostanti.LABEL_AUDIT_FILTRI,
  141.                         AuditCostanti.SERVLET_NAME_AUDIT_FILTRI_LIST));
  142.                 lstParam.add(ServletUtils.getParameterAggiungi());

  143.                 ServletUtils.setPageDataTitle(pd, lstParam);

  144.                 // preparo i campi
  145.                 List<DataElement> dati = ah.addFiltroToDati(
  146.                         Tipologia.ADD, utente, tipooperazione, tipiOgg,
  147.                         tipooggetto, statooperazione, stato, tipofiltro,
  148.                         dump, statoazione, dumpazione, "0");

  149.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  150.                
  151.                 pd.setDati(dati);

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

  153.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  154.                         AuditCostanti.OBJECT_NAME_CONFIGURAZIONE_AUDITING_FILTRI,
  155.                         ForwardParams.ADD());
  156.             }

  157.             // Inserisco il filtro nel db
  158.             Filtro f = new Filtro();
  159.             if (utente != null && !utente.equals(""))
  160.                 f.setUsername(utente);
  161.             if (tipooperazione != null && !tipooperazione.equals("-"))
  162.                 f.setTipoOperazione(Tipologia.toEnumConstant(tipooperazione));
  163.             if (tipooggetto != null && !tipooggetto.equals("-"))
  164.                 f.setTipoOggettoInModifica(tipooggetto);
  165.             if (statooperazione != null && !statooperazione.equals("-"))
  166.                 f.setStatoOperazione(Stato.toEnumConstant(statooperazione));
  167.             if (stato.equals(AuditCostanti.DEFAULT_VALUE_ABILITATO)) {
  168.                 f.setDumpExprRegular(!tipofiltro.equals(AuditCostanti.DEFAULT_VALUE_PARAMETRO_AUDIT_TIPO_FILTRO_NORMALE));
  169.                 f.setDump(dump);
  170.             } else
  171.                 f.setDumpExprRegular(false);
  172.             f.setAuditEnabled(statoazione.equals(AuditCostanti.DEFAULT_VALUE_ABILITATO));
  173.             f.setDumpEnabled(dumpazione.equals(AuditCostanti.DEFAULT_VALUE_ABILITATO));

  174.             confCore.performCreateOperation(userLogin, confHelper.smista(), f);

  175.             // Preparo la lista
  176.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  177.             List<Filtro> lista = null;
  178.             lista = confCore.filtriList(ricerca);

  179.             ah.prepareFiltriList(ricerca, lista, Liste.FILTRI);
  180.             pd.setMessage(AuditCostanti.LABEL_AUDIT_CONFIGURAZIONE_MODIFICATA, Costanti.MESSAGE_TYPE_INFO);
  181.            
  182.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  183.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  184.                     AuditCostanti.OBJECT_NAME_CONFIGURAZIONE_AUDITING_FILTRI,
  185.                     ForwardParams.ADD());
  186.         } catch (Exception e) {
  187.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  188.                     AuditCostanti.OBJECT_NAME_CONFIGURAZIONE_AUDITING_FILTRI, ForwardParams.ADD());
  189.         }
  190.     }
  191. }