ConfigurazioneAuditingFiltriChange.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.lib.audit.dao.Filtro;
  36. import org.openspcoop2.web.lib.audit.log.constants.Stato;
  37. import org.openspcoop2.web.lib.audit.log.constants.Tipologia;
  38. import org.openspcoop2.web.lib.audit.web.AuditCostanti;
  39. import org.openspcoop2.web.lib.audit.web.AuditHelper;
  40. import org.openspcoop2.web.lib.mvc.Costanti;
  41. import org.openspcoop2.web.lib.mvc.DataElement;
  42. import org.openspcoop2.web.lib.mvc.ForwardParams;
  43. import org.openspcoop2.web.lib.mvc.GeneralData;
  44. import org.openspcoop2.web.lib.mvc.PageData;
  45. import org.openspcoop2.web.lib.mvc.Parameter;
  46. import org.openspcoop2.web.lib.mvc.ServletUtils;

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

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

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

  61.         // Inizializzo PageData
  62.         PageData pd = new PageData();

  63.         GeneralHelper generalHelper = new GeneralHelper(session);

  64.         // Inizializzo GeneralData
  65.         GeneralData gd = generalHelper.initGeneralData(request);

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

  67.         try {
  68.             ConfigurazioneHelper confHelper = new ConfigurazioneHelper(request, pd, session);

  69.             String id = confHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_ID);
  70.             int idFiltro = Integer.parseInt(id);

  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.             AuditHelper ah = new AuditHelper(request, pd, session);

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

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

  90.             // Prendo il filtro
  91.             Filtro f = confCore.getFiltro((Long.valueOf(idFiltro)).longValue());

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

  97.                 lstParam.add(new Parameter(AuditCostanti.LABEL_AUDIT,
  98.                         AuditCostanti.SERVLET_NAME_AUDIT));
  99.                 lstParam.add(new Parameter(AuditCostanti.LABEL_AUDIT_FILTRI,
  100.                         AuditCostanti.SERVLET_NAME_AUDIT_FILTRI_LIST));
  101.                 lstParam.add(new Parameter(Costanti.PAGE_DATA_TITLE_LABEL_MODIFICA, null));

  102.                 ServletUtils.setPageDataTitle(pd, lstParam);

  103.                 if (utente == null) {
  104.                     utente = f.getUsername();
  105.                     tipooperazione = f.getTipoOperazione() != null ?
  106.                             f.getTipoOperazione().toString() : "-";
  107.                             tipooggetto = f.getTipoOggettoInModifica();
  108.                             statooperazione = f.getStatoOperazione() != null ?
  109.                                     f.getStatoOperazione().toString() : "-";
  110.                                     stato = f.getDump() != null ? AuditCostanti.DEFAULT_VALUE_ABILITATO : AuditCostanti.DEFAULT_VALUE_DISABILITATO;
  111.                                     tipofiltro = f.isDumpExprRegular() ?
  112.                                             AuditCostanti.DEFAULT_VALUE_PARAMETRO_AUDIT_TIPO_FILTRO_ESPRESSIONE_REGOLARE
  113.                                             : AuditCostanti.DEFAULT_VALUE_PARAMETRO_AUDIT_TIPO_FILTRO_NORMALE;
  114.                                     dump = f.getDump();
  115.                                     statoazione = f.isAuditEnabled() ? AuditCostanti.DEFAULT_VALUE_ABILITATO : AuditCostanti.DEFAULT_VALUE_DISABILITATO;
  116.                                     dumpazione = f.isDumpEnabled() ? AuditCostanti.DEFAULT_VALUE_ABILITATO : AuditCostanti.DEFAULT_VALUE_DISABILITATO;
  117.                 }

  118.                 // preparo i campi
  119.                 List<DataElement> dati = ah.addFiltroToDati(
  120.                         Tipologia.CHANGE, utente, tipooperazione, tipiOgg,
  121.                         tipooggetto, statooperazione, stato, tipofiltro,
  122.                         dump, statoazione, dumpazione, id);

  123.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  124.                 pd.setDati(dati);

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

  126.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  127.                         AuditCostanti.OBJECT_NAME_CONFIGURAZIONE_AUDITING_FILTRI,
  128.                         ForwardParams.CHANGE());
  129.             }

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

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

  140.                 lstParam.add(new Parameter(AuditCostanti.LABEL_AUDIT,
  141.                         AuditCostanti.SERVLET_NAME_AUDIT));
  142.                 lstParam.add(new Parameter(AuditCostanti.LABEL_AUDIT_FILTRI,
  143.                         AuditCostanti.SERVLET_NAME_AUDIT_FILTRI_LIST));
  144.                 lstParam.add(new Parameter(Costanti.PAGE_DATA_TITLE_LABEL_MODIFICA, null));

  145.                 ServletUtils.setPageDataTitle(pd, lstParam);

  146.                 // preparo i campi
  147.                 List<DataElement> dati = ah.addFiltroToDati(
  148.                         Tipologia.CHANGE, utente, tipooperazione, tipiOgg,
  149.                         tipooggetto, statooperazione, stato, tipofiltro,
  150.                         dump, statoazione, dumpazione, id);

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

  152.                 pd.setDati(dati);

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

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

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

  184.             confCore.performUpdateOperation(userLogin, confHelper.smista(), f);

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

  187.             List<Filtro> lista = null;
  188.             lista = confCore.filtriList(ricerca);

  189.             ah.prepareFiltriList(ricerca, lista, Liste.FILTRI);
  190.             pd.setMessage(AuditCostanti.LABEL_AUDIT_CONFIGURAZIONE_MODIFICATA, Costanti.MESSAGE_TYPE_INFO);

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

  192.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  193.                     AuditCostanti.OBJECT_NAME_CONFIGURAZIONE_AUDITING_FILTRI,
  194.                     ForwardParams.CHANGE());
  195.         } catch (Exception e) {
  196.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  197.                     AuditCostanti.OBJECT_NAME_CONFIGURAZIONE_AUDITING_FILTRI, ForwardParams.CHANGE());
  198.         }  
  199.     }
  200. }