Operazioni.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.servlet.GeneralHelper;
  33. import org.openspcoop2.web.lib.mvc.ForwardParams;
  34. import org.openspcoop2.web.lib.mvc.GeneralData;
  35. import org.openspcoop2.web.lib.mvc.PageData;
  36. import org.openspcoop2.web.lib.mvc.ServletUtils;
  37. import org.openspcoop2.web.lib.queue.dao.Operation;

  38. /**
  39.  * Operazioni
  40.  *
  41.  * @author Pintori Giuliano (pintori@link.it)
  42.  * @author $Author$
  43.  * @version $Rev$, $Date$
  44.  */
  45. public class Operazioni extends Action{

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

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

  49.         // Salvo il vecchio PageData
  50.     //  PageData pdold = ServletUtils.getPageDataFromSession(session);

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

  53.         GeneralHelper generalHelper = new GeneralHelper(session);

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

  56.         try {
  57.             OperazioniCore opCore = new OperazioniCore();

  58.             OperazioniHelper opHelper = new OperazioniHelper(request, pd, session);

  59.             ArrayList<String> errors = new ArrayList<>();

  60.             OperazioniFormBean formBean = opHelper.getBeanForm(errors);
  61.            
  62.             String metodo = opHelper.getParameter(OperazioniCostanti.PARAMETRO_OPERAZIONI_METHOD);

  63.             // prima volta che accedo quindi show form
  64.             if (opHelper.isEditModeInProgress() && (metodo == null || metodo.equals(OperazioniCostanti.DEFAULT_VALUE_FORM_BEAN_METHOD_FORM))){
  65.                 opHelper.makeMenu();

  66.                 opHelper.showForm("", "", formBean);

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

  68.                 return ServletUtils.getStrutsForwardEditModeInProgress(mapping,
  69.                         OperazioniCostanti.OBJECT_NAME_OPERAZIONI,OperazioniCostanti.TIPO_OPERAZIONE_OPERAZIONI);
  70.             }

  71.             // controllo se visualizzazione dettaglio operazione
  72.             if (formBean.getMethod().equals(OperazioniCostanti.DEFAULT_VALUE_FORM_BEAN_METHOD_DETAILS)) {

  73.                 OperazioniFormBean oldFormBeanRicerca = ServletUtils.getObjectFromSession(request, session, OperazioniFormBean.class, OperazioniCostanti.SESSION_ATTRIBUTE_FORM_BEAN);

  74.                 String idOperazione = formBean.getIdOperazione();

  75.                 long idOp = -1;

  76.                 try{
  77.                     idOp = Long.parseLong(idOperazione);
  78.                 }catch (Exception e){
  79.                    
  80.                 }

  81.                 Operation operazione = opCore.getOperation(idOp);

  82.                 opHelper.makeMenu();

  83.                 if (operazione  != null) {
  84.                     // visualizzo dettagli Operazione
  85.                     opHelper.showDettagliMessaggio(operazione, oldFormBeanRicerca);

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

  87.                     return ServletUtils.getStrutsForwardEditModeFinished(mapping,
  88.                             OperazioniCostanti.OBJECT_NAME_OPERAZIONI,
  89.                             OperazioniCostanti.TIPO_OPERAZIONE_DETAIL);
  90.                 } else {
  91.                     // non ho l'operazione
  92.                     pd.setMessage("L'operazione [" + formBean.getIdOperazione() + "] non e' piu presente. "
  93.                             + "Impossibile visualizzare il dettaglio.");
  94.                     // rinvio alla visulizzazione del form in quanto il
  95.                     // messaggio non e' piu presente


  96.                     opHelper.showForm("", "", formBean);

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

  98.                     return ServletUtils.getStrutsForwardEditModeInProgress(mapping, OperazioniCostanti.OBJECT_NAME_OPERAZIONI,
  99.                             OperazioniCostanti.TIPO_OPERAZIONE_DETAIL);
  100.                 }
  101.             }  

  102.             opHelper.makeMenu();

  103.             // Eseguo la ricerca
  104.             int idLista = opCore.getIdLista(formBean);
  105.            
  106.             ConsoleSearch ricerca = (ConsoleSearch) ServletUtils.getSearchObjectFromSession(request, session, ConsoleSearch.class);

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

  109.             opHelper.prepareOperazioniList(ricerca, lista);

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

  112.             ServletUtils.setObjectIntoSession(request, session, formBean, OperazioniCostanti.SESSION_ATTRIBUTE_FORM_BEAN);

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

  114.             return ServletUtils.getStrutsForward(mapping, OperazioniCostanti.OBJECT_NAME_OPERAZIONI,
  115.                     ForwardParams.LIST());

  116.         } catch (Exception e) {
  117.             return ServletUtils.getStrutsForwardError(ControlStationCore.getLog(), e, pd, request, session, gd, mapping,
  118.                     OperazioniCostanti.OBJECT_NAME_OPERAZIONI,
  119.                     OperazioniCostanti.TIPO_OPERAZIONE_OPERAZIONI);
  120.         }  

  121.     }
  122. }