OperazioniCore.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.sql.Connection;
  22. import java.util.List;

  23. import org.openspcoop2.core.commons.Filtri;
  24. import org.openspcoop2.core.commons.Liste;
  25. import org.openspcoop2.web.ctrlstat.core.ControlStationCore;
  26. import org.openspcoop2.web.ctrlstat.core.ConsoleSearch;
  27. import org.openspcoop2.web.lib.queue.ClassQueue;
  28. import org.openspcoop2.web.lib.queue.ClassQueueException;
  29. import org.openspcoop2.web.lib.queue.costanti.OperationStatus;
  30. import org.openspcoop2.web.lib.queue.dao.Operation;

  31. /**
  32.  * OperazioniCore
  33.  *
  34.  * @author Pintori Giuliano (pintori@link.it)
  35.  * @author $Author$
  36.  * @version $Rev$, $Date$
  37.  */
  38. public class OperazioniCore extends ControlStationCore {

  39.     public OperazioniCore() throws Exception {
  40.         super();
  41.     }
  42.     public OperazioniCore(ControlStationCore core) throws Exception {
  43.         super(core);
  44.     }

  45.     public Operation getOperation(long idOperation) throws ClassQueueException {
  46.         Connection con = null;
  47.         String nomeMetodo = "getOperation";
  48.         ClassQueue driver = null;

  49.         try {
  50.             // prendo una connessione
  51.             con = ControlStationCore.dbM.getConnection();
  52.             // istanzio il driver
  53.             driver = new ClassQueue(con, this.tipoDB);
  54.             return driver.getOperation(idOperation);
  55.         } catch (Exception e) {
  56.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  57.             throw new ClassQueueException(getPrefixError(nomeMetodo,  e));
  58.         } finally {
  59.             ControlStationCore.dbM.releaseConnection(con);
  60.         }
  61.     }

  62.     public int updateOperation(Operation operation) throws ClassQueueException {
  63.         Connection con = null;
  64.         String nomeMetodo = "updateOperation";
  65.         ClassQueue driver = null;

  66.         try {
  67.             // prendo una connessione
  68.             con = ControlStationCore.dbM.getConnection();
  69.             // istanzio il driver
  70.             driver = new ClassQueue(con, this.tipoDB);
  71.             return driver.updateOperation(operation);
  72.         } catch (Exception e) {
  73.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  74.             throw new ClassQueueException(getPrefixError(nomeMetodo,  e));
  75.         } finally {
  76.             ControlStationCore.dbM.releaseConnection(con);
  77.         }
  78.     }

  79.     public List<Operation> operationsList(ConsoleSearch ricerca,
  80.             OperazioniFormBean formBean, String logAdm
  81.             ) throws ClassQueueException {
  82.         Connection con = null;
  83.         String nomeMetodo = "operationsList";
  84.         ClassQueue driver = null;

  85.         OperationStatus os = formBean.getTipoOperationStatus();
  86.         List<String> utenti = formBean.getUtenti();
  87.         ricerca.addFilter(this.getIdLista(formBean),Filtri.FILTRO_UTENTE, formBean.getUtente());
  88.         String hostname = formBean.getHostname() != null ? formBean.getHostname() : "";
  89.         String pezzoAny = formBean.getPezzoAny()!= null ? formBean.getPezzoAny() : "";
  90.         String daSql = formBean.getDataInizio()!= null ? formBean.getDataInizio() : "";
  91.         String aSql = formBean.getDataFine()!= null ? formBean.getDataFine() : "";
  92.        
  93.         try {
  94.             // prendo una connessione
  95.             con = ControlStationCore.dbM.getConnection();
  96.             // istanzio il driver
  97.             driver = new ClassQueue(con, this.tipoDB);
  98.             return driver.operationsList(ricerca, os, utenti, logAdm, hostname, pezzoAny, daSql, aSql);
  99.         } catch (Exception e) {
  100.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  101.             throw new ClassQueueException(getPrefixError(nomeMetodo,  e));
  102.         } finally {
  103.             ControlStationCore.dbM.releaseConnection(con);
  104.         }
  105.     }  
  106.     public List<String> hostnameList() throws ClassQueueException {
  107.         Connection con = null;
  108.         String nomeMetodo = "hostnameList";
  109.         ClassQueue driver = null;

  110.         try {
  111.             // prendo una connessione
  112.             con = ControlStationCore.dbM.getConnection();
  113.             // istanzio il driver
  114.             driver = new ClassQueue(con, this.tipoDB);
  115.             return driver.hostnameList();
  116.         } catch (Exception e) {
  117.             ControlStationCore.logError(getPrefixError(nomeMetodo,  e), e);
  118.             throw new ClassQueueException(getPrefixError(nomeMetodo,  e),e);
  119.         } finally {
  120.             ControlStationCore.dbM.releaseConnection(con);
  121.         }
  122.     }
  123.    
  124.     public int getIdLista(OperazioniFormBean formBean){
  125.         return getIdLista(formBean.getTipoOperationStatus());
  126.     }
  127.    
  128.     public int getIdLista(OperationStatus os){
  129.         int idLista = -1;
  130.        
  131.         if(os == null)
  132.             return idLista;
  133.        
  134.         if (os.toString().equals("SUCCESS"))
  135.             idLista = Liste.OPERATIONS_ESEGUITE;
  136.         if (os.toString().equals("ERROR"))
  137.             idLista = Liste.OPERATIONS_FALLITE;
  138.         if (os.toString().equals("INVALID"))
  139.             idLista = Liste.OPERATIONS_INVALIDE;
  140.         if (os.toString().equals("NOT_SET"))
  141.             idLista = Liste.OPERATIONS_CODA;
  142.         if (os.toString().equals("WAIT"))
  143.             idLista = Liste.OPERATIONS_WAITING;
  144.        
  145.         return idLista;
  146.     }
  147. }