AuditingDel.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.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.ControlStationCore;
  32. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  33. import org.openspcoop2.web.ctrlstat.core.Utilities;
  34. import org.openspcoop2.web.ctrlstat.servlet.ConsoleHelper;
  35. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  36. import org.openspcoop2.web.lib.audit.log.Operation;
  37. import org.openspcoop2.web.lib.audit.web.AuditCostanti;
  38. import org.openspcoop2.web.lib.mvc.Costanti;
  39. import org.openspcoop2.web.lib.mvc.ForwardParams;
  40. import org.openspcoop2.web.lib.mvc.GeneralData;
  41. import org.openspcoop2.web.lib.mvc.PageData;
  42. import org.openspcoop2.web.lib.mvc.ServletUtils;

  43. /**
  44.  * auditReportDel
  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 AuditingDel 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.         String userLogin = ServletUtils.getUserLoginFromSession(session);  

  63.         try {
  64.             AuditingCore auditingCore = new AuditingCore();
  65.             ConsoleHelper auditingHelper = new ConsoleHelper(request, pd, session);

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

  75.             String objToRemove =  auditingHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);

  76.             // Elimino le operazioni dal db
  77.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);

  78.             for (int i = 0; i < idsToRemove.size(); i++) {

  79.                 Operation singleOp = auditingCore.getAuditOperation(Long.parseLong(idsToRemove.get(i)));

  80.                 // Elimino l'operazione
  81.                 auditingCore.performDeleteOperation(userLogin, auditingHelper.smista(), singleOp);
  82.             }

  83.             // Preparo il menu
  84.             auditingHelper.makeMenu();

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

  87.             List<Operation> lista = auditingCore.auditOperationList(ricerca,
  88.                     datainizio, datafine, tipooperazione,
  89.                     tipooggetto, id, oldid, utente,
  90.                     statooperazione, contoggetto);

  91.             auditingHelper.getAuditHelper().prepareAuditReportList(ricerca, lista, Liste.AUDIT_REPORT,
  92.                     datainizio, datafine,
  93.                     tipooperazione, tipooggetto,
  94.                     id, oldid,
  95.                     utente, statooperazione,
  96.                     contoggetto);
  97.  
  98.             ServletUtils.setGeneralAndPageDataIntoSession(request, session, gd, pd);
  99.             // Forward control to the specified success URI
  100.             return ServletUtils.getStrutsForward (mapping, AuditCostanti.OBJECT_NAME_AUDITING,
  101.                     ForwardParams.DEL());
  102.         } catch (Exception e) {
  103.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  104.                     AuditCostanti.OBJECT_NAME_AUDITING, ForwardParams.DEL());
  105.         }
  106.     }
  107. }