Auditing.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.audit;

  21. import java.util.List;

  22. import javax.servlet.http.HttpServletRequest;
  23. import javax.servlet.http.HttpServletResponse;
  24. import javax.servlet.http.HttpSession;

  25. import org.apache.struts.action.Action;
  26. import org.apache.struts.action.ActionForm;
  27. import org.apache.struts.action.ActionForward;
  28. import org.apache.struts.action.ActionMapping;
  29. import org.openspcoop2.core.commons.Liste;
  30. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  31. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  32. import org.openspcoop2.web.ctrlstat.driver.IDBuilder;
  33. import org.openspcoop2.web.ctrlstat.servlet.ConsoleHelper;
  34. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  35. import org.openspcoop2.web.lib.audit.log.Operation;
  36. import org.openspcoop2.web.lib.audit.web.AuditCostanti;
  37. import org.openspcoop2.web.lib.mvc.Costanti;
  38. import org.openspcoop2.web.lib.mvc.DataElement;
  39. import org.openspcoop2.web.lib.mvc.GeneralData;
  40. import org.openspcoop2.web.lib.mvc.PageData;
  41. import org.openspcoop2.web.lib.mvc.ServletUtils;

  42. /**
  43.  * auditReport
  44.  *
  45.  * @author Andrea Poli (apoli@link.it)
  46.  * @author Stefano Corallo (corallo@link.it)
  47.  * @author Sandra Giangrandi (sandra@link.it)
  48.  * @author $Author$
  49.  * @version $Rev$, $Date$
  50.  *
  51.  */
  52. public   class Auditing extends Action {

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

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

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

  58.         GeneralHelper generalHelper = new GeneralHelper(session);

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


  61.         try {
  62.             ConsoleHelper auditingHelper = new ConsoleHelper(request, pd, session);

  63.             String datainizio = auditingHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_DATA_INIZIO);
  64.             String datafine = auditingHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_DATA_FINE);
  65.             String tipooperazione = auditingHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_TIPO_OPERAZIONE);
  66.             String tipooggetto = auditingHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_TIPO_OGGETTO);
  67.             String id = auditingHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_ID);
  68.             String oldid = auditingHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_OLD_ID);
  69.             String utente = auditingHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_UTENTE);
  70.             String statooperazione = auditingHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_STATO_OPERAZIONE);
  71.             String contoggetto = auditingHelper.getParameter(AuditCostanti.PARAMETRO_AUDIT_CONTENUTO_OGGETTO);

  72.             AuditingCore auditingCore = new AuditingCore();
  73.            

  74.             // Preparo il menu
  75.             auditingHelper.makeMenu();
  76.            
  77.             IDBuilder idb = new IDBuilder();
  78.             String[] tipiOggTmp = idb.getManagedObjects(true);
  79.             String[] tipiOgg = new String[tipiOggTmp.length+1];
  80.             tipiOgg[0] = "-";
  81.             for (int i = 0; i < tipiOggTmp.length; i++)
  82.                 tipiOgg[i+1] = tipiOggTmp[i];

  83.             // Se datainizio == null, devo visualizzare la pagina con il pulsante
  84.             if (auditingHelper.isEditModeInProgress()) {
  85.                 // setto la barra del titolo
  86.                 ServletUtils.setPageDataTitle_ServletFirst(pd, AuditCostanti.LABEL_AUDIT, AuditCostanti.SERVLET_NAME_AUDITING);

  87.                 // preparo i campi
  88.                 List<DataElement> dati = auditingHelper.getAuditHelper().addAuditReportToDati(
  89.                         "", "", "-", tipiOgg, "-", "", "", "", "-", "");

  90.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  91.                 pd.setDati(dati);

  92.                 pd.setLabelBottoneInvia(Costanti.LABEL_MONITOR_BUTTON_FILTRA);
  93.                
  94.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  95.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  96.                         AuditCostanti.OBJECT_NAME_AUDITING, AuditCostanti.TIPO_OPERAZIONE_AUDITING);
  97.             }

  98.             // Controlli sui campi immessi
  99.             String msg = auditingHelper.getAuditHelper().auditReportCheckData(datainizio, datafine,
  100.                     tipooperazione, tipooggetto,
  101.                     id, oldid,
  102.                     statooperazione, tipiOgg);
  103.             if (!msg.equals("")) {
  104.                 pd.setMessage(msg);

  105.                 // setto la barra del titolo
  106.                 ServletUtils.setPageDataTitle_ServletFirst(pd, AuditCostanti.LABEL_AUDIT, AuditCostanti.SERVLET_NAME_AUDITING);

  107.                 // preparo i campi
  108.                 List<DataElement> dati = auditingHelper.getAuditHelper().addAuditReportToDati(
  109.                         datainizio, datafine, tipooperazione, tipiOgg,
  110.                         tipooggetto, id, oldid, utente, statooperazione,
  111.                         contoggetto);

  112.                 dati.add(ServletUtils.getDataElementForEditModeFinished());
  113.                
  114.                 pd.setDati(dati);

  115.                 pd.setLabelBottoneInvia(Costanti.LABEL_MONITOR_BUTTON_FILTRA);
  116.                
  117.                 ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);

  118.                 return ServletUtils.getStrutsForwardEditModeCheckError(mapping,
  119.                         AuditCostanti.OBJECT_NAME_AUDITING, AuditCostanti.TIPO_OPERAZIONE_AUDITING);
  120.             }

  121.             // ritorno pagina a lista
  122.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  123.             int idLista = Liste.AUDIT_REPORT;

  124.             ricerca = auditingHelper.checkSearchParameters(idLista, ricerca);

  125.             List<Operation> lista = auditingCore.auditOperationList(ricerca,
  126.                     datainizio, datafine, tipooperazione,
  127.                     tipooggetto, id, oldid, utente,
  128.                     statooperazione, contoggetto);

  129.             auditingHelper.getAuditHelper().prepareAuditReportList(ricerca, lista, idLista,
  130.                     datainizio, datafine,
  131.                     tipooperazione, tipooggetto,
  132.                     id, oldid,
  133.                     utente, statooperazione,
  134.                     contoggetto);

  135.             // salvo l'oggetto ricerca nella sessione
  136.             ServletUtils.setSearchObjectIntoSession(request, session, ricerca);

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

  138.             pd.setLabelBottoneInvia(Costanti.LABEL_MONITOR_BUTTON_FILTRA);
  139.            
  140.             return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  141.                     AuditCostanti.OBJECT_NAME_AUDITING, AuditCostanti.TIPO_OPERAZIONE_AUDITING);

  142.         } catch (Exception e) {
  143.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  144.                     AuditCostanti.OBJECT_NAME_AUDITING, AuditCostanti.TIPO_OPERAZIONE_AUDITING);
  145.         }  
  146.     }
  147. }