OperazioniDel.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.operazioni;

  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.web.ctrlstat.core.ControlStationCore;
  31. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  32. import org.openspcoop2.web.ctrlstat.core.Utilities;
  33. import org.openspcoop2.web.ctrlstat.servlet.GeneralHelper;
  34. import org.openspcoop2.web.lib.mvc.Costanti;
  35. import org.openspcoop2.web.lib.mvc.ForwardParams;
  36. import org.openspcoop2.web.lib.mvc.GeneralData;
  37. import org.openspcoop2.web.lib.mvc.PageData;
  38. import org.openspcoop2.web.lib.mvc.ServletUtils;
  39. import org.openspcoop2.web.lib.queue.costanti.OperationStatus;
  40. import org.openspcoop2.web.lib.queue.dao.Operation;

  41. /**
  42.  * OperazioniDel
  43.  *
  44.  * @author Pintori Giuliano (pintori@link.it)
  45.  * @author $Author$
  46.  * @version $Rev$, $Date$
  47.  */
  48. public class OperazioniDel  extends Action {

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

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

  52.         // Inizializzo PageData
  53.         PageData pd = new PageData();

  54.         GeneralHelper generalHelper = new GeneralHelper(session);

  55.         // Inizializzo GeneralData
  56.         GeneralData gd = generalHelper.initGeneralData(request);

  57.         try {
  58.             OperazioniHelper opHelper = new OperazioniHelper(request, pd, session);
  59.            
  60.             ArrayList<String> errors = new ArrayList<>();
  61.             OperazioniFormBean formBean = opHelper.getBeanForm(errors );
  62.            
  63.             OperazioniCore opCore = new OperazioniCore();

  64.             String objToRemove =  opHelper.getParameter(Costanti.PARAMETER_NAME_OBJECTS_FOR_REMOVE);
  65.            
  66.             ArrayList<String> idsToRemove = Utilities.parseIdsToRemove(objToRemove);
  67.             for (int i = 0; i < idsToRemove.size(); i++) {

  68.                 // Elimino l'operazione
  69.                 Operation operation = opCore.getOperation(Long.parseLong(idsToRemove.get(i)));

  70.                 // Rimozione operazione
  71.                 operation.setStatus(OperationStatus.SUCCESS);
  72.                 operation.setDeleted(true);

  73.                 opCore.updateOperation(operation);
  74.  
  75.             }
  76.            
  77.             opHelper.makeMenu();

  78.             // Eseguo la ricerca
  79.             int idLista = opCore.getIdLista(formBean);
  80.            
  81.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

  82.             ricerca = opHelper.checkSearchParameters(idLista, ricerca);
  83.             List<Operation> lista = opCore.operationsList(ricerca,formBean,ServletUtils.getUserLoginFromSession(session));

  84.             opHelper.prepareOperazioniList(ricerca, lista);

  85.             // salvo l'oggetto ricerca nella sessione
  86.             ServletUtils.setSearchObjectIntoSession(request, session, ricerca);
  87.    
  88.             ServletUtils.setObjectIntoSession(request, session, formBean, OperazioniCostanti.SESSION_ATTRIBUTE_FORM_BEAN);

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

  90.             return ServletUtils.getStrutsForward (mapping, OperazioniCostanti.OBJECT_NAME_OPERAZIONI,ForwardParams.DEL());
  91.         } catch (Exception e) {
  92.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  93.                     OperazioniCostanti.OBJECT_NAME_OPERAZIONI, ForwardParams.DEL());
  94.         }
  95.     }
  96. }
  97.