MisurazioniTransazione.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.core.controllo_traffico.beans;

  21. import java.io.Serializable;
  22. import java.util.Date;

  23. import org.openspcoop2.core.constants.TipoPdD;

  24. /**
  25.  * MisurazioniTransazione
  26.  *
  27.  * @author Andrea Poli (poli@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */
  31. public class MisurazioniTransazione implements Serializable , Cloneable {

  32.     /**
  33.      *
  34.      */
  35.     private static final long serialVersionUID = 1L;

  36.     private TipoPdD tipoPdD;
  37.     private String protocollo;
  38.    
  39.     private java.util.Date dataIngressoRichiesta;
  40.     private java.util.Date dataUscitaRichiesta;
  41.     private java.util.Date dataIngressoRisposta;
  42.     private java.util.Date dataUscitaRisposta;

  43.     private java.lang.Long richiestaIngressoBytes;
  44.     private java.lang.Long richiestaUscitaBytes;
  45.     private java.lang.Long rispostaIngressoBytes;
  46.     private java.lang.Long rispostaUscitaBytes;
  47.    
  48.     private int esitoTransazione;

  49.     public String getProtocollo() {
  50.         return this.protocollo;
  51.     }
  52.     public void setProtocollo(String protocollo) {
  53.         this.protocollo = protocollo;
  54.     }
  55.     public int getEsitoTransazione() {
  56.         return this.esitoTransazione;
  57.     }
  58.     public void setEsitoTransazione(int esitoTransazione) {
  59.         this.esitoTransazione = esitoTransazione;
  60.     }
  61.     public TipoPdD getTipoPdD() {
  62.         return this.tipoPdD;
  63.     }
  64.     public void setTipoPdD(TipoPdD tipoPdD) {
  65.         this.tipoPdD = tipoPdD;
  66.     }
  67.    
  68.     public java.util.Date getDataIngressoRichiesta() {
  69.         return this.dataIngressoRichiesta;
  70.     }
  71.     public void setDataIngressoRichiesta(java.util.Date dataIngressoRichiesta) {
  72.         this.dataIngressoRichiesta = dataIngressoRichiesta;
  73.     }
  74.     public java.util.Date getDataUscitaRichiesta() {
  75.         return this.dataUscitaRichiesta;
  76.     }
  77.     public void setDataUscitaRichiesta(java.util.Date dataUscitaRichiesta) {
  78.         this.dataUscitaRichiesta = dataUscitaRichiesta;
  79.     }
  80.     public java.util.Date getDataIngressoRisposta() {
  81.         return this.dataIngressoRisposta;
  82.     }
  83.     public void setDataIngressoRisposta(java.util.Date dataIngressoRisposta) {
  84.         this.dataIngressoRisposta = dataIngressoRisposta;
  85.     }
  86.     public java.util.Date getDataUscitaRisposta() {
  87.         return this.dataUscitaRisposta;
  88.     }
  89.     public void setDataUscitaRisposta(java.util.Date dataUscitaRisposta) {
  90.         this.dataUscitaRisposta = dataUscitaRisposta;
  91.     }
  92.     public java.lang.Long getRichiestaIngressoBytes() {
  93.         return this.richiestaIngressoBytes;
  94.     }
  95.     public void setRichiestaIngressoBytes(java.lang.Long richiestaIngressoBytes) {
  96.         this.richiestaIngressoBytes = richiestaIngressoBytes;
  97.     }
  98.     public java.lang.Long getRichiestaUscitaBytes() {
  99.         return this.richiestaUscitaBytes;
  100.     }
  101.     public void setRichiestaUscitaBytes(java.lang.Long richiestaUscitaBytes) {
  102.         this.richiestaUscitaBytes = richiestaUscitaBytes;
  103.     }
  104.     public java.lang.Long getRispostaIngressoBytes() {
  105.         return this.rispostaIngressoBytes;
  106.     }
  107.     public void setRispostaIngressoBytes(java.lang.Long rispostaIngressoBytes) {
  108.         this.rispostaIngressoBytes = rispostaIngressoBytes;
  109.     }
  110.     public java.lang.Long getRispostaUscitaBytes() {
  111.         return this.rispostaUscitaBytes;
  112.     }
  113.     public void setRispostaUscitaBytes(java.lang.Long rispostaUscitaBytes) {
  114.         this.rispostaUscitaBytes = rispostaUscitaBytes;
  115.     }
  116.    
  117.    
  118.    
  119.     // **** UTILITIES ****
  120.    
  121.     public static String serialize(MisurazioniTransazione misurazione){
  122.         StringBuilder bf = new StringBuilder();
  123.        
  124.        
  125.         if(misurazione.tipoPdD!=null){
  126.             bf.append(misurazione.tipoPdD.getTipo());
  127.         }
  128.         else{
  129.             bf.append("-");
  130.         }
  131.         bf.append("\n");
  132.        
  133.         if(misurazione.protocollo!=null){
  134.             bf.append(misurazione.protocollo);
  135.         }
  136.         else{
  137.             bf.append("-");
  138.         }
  139.         bf.append("\n");
  140.        
  141.         if(misurazione.dataIngressoRichiesta!=null){
  142.             bf.append(misurazione.dataIngressoRichiesta.getTime());
  143.         }
  144.         else{
  145.             bf.append("-");
  146.         }
  147.         bf.append("\n");
  148.        
  149.         if(misurazione.dataUscitaRichiesta!=null){
  150.             bf.append(misurazione.dataUscitaRichiesta.getTime());
  151.         }
  152.         else{
  153.             bf.append("-");
  154.         }
  155.         bf.append("\n");
  156.        
  157.         if(misurazione.dataIngressoRisposta!=null){
  158.             bf.append(misurazione.dataIngressoRisposta.getTime());
  159.         }
  160.         else{
  161.             bf.append("-");
  162.         }
  163.         bf.append("\n");
  164.        
  165.         if(misurazione.dataUscitaRisposta!=null){
  166.             bf.append(misurazione.dataUscitaRisposta.getTime());
  167.         }
  168.         else{
  169.             bf.append("-");
  170.         }
  171.         bf.append("\n");
  172.        
  173.         if(misurazione.richiestaIngressoBytes!=null){
  174.             bf.append(misurazione.richiestaIngressoBytes);
  175.         }
  176.         else{
  177.             bf.append("-");
  178.         }
  179.         bf.append("\n");
  180.        
  181.         if(misurazione.richiestaUscitaBytes!=null){
  182.             bf.append(misurazione.richiestaUscitaBytes);
  183.         }
  184.         else{
  185.             bf.append("-");
  186.         }
  187.         bf.append("\n");
  188.        
  189.         if(misurazione.rispostaIngressoBytes!=null){
  190.             bf.append(misurazione.rispostaIngressoBytes);
  191.         }
  192.         else{
  193.             bf.append("-");
  194.         }
  195.         bf.append("\n");
  196.        
  197.         if(misurazione.rispostaUscitaBytes!=null){
  198.             bf.append(misurazione.rispostaUscitaBytes);
  199.         }
  200.         else{
  201.             bf.append("-");
  202.         }
  203.         bf.append("\n");
  204.        
  205.         bf.append(misurazione.esitoTransazione);
  206.        
  207.         return bf.toString();
  208.     }
  209.    
  210.     public static MisurazioniTransazione deserialize(String s) throws Exception{
  211.         MisurazioniTransazione misurazioni = new MisurazioniTransazione();
  212.         String [] tmp = s.split("\n");
  213.         if(tmp==null){
  214.             throw new Exception("Wrong Format");
  215.         }
  216.         if(tmp.length!=11){
  217.             throw new Exception("Wrong Format (size: "+tmp.length+")");
  218.         }
  219.         for (int i = 0; i < tmp.length; i++) {
  220.             if(i==0){
  221.                 String tmpValue = tmp[i].trim();
  222.                 if(tmpValue!=null && !"-".equals(tmpValue)){
  223.                     misurazioni.tipoPdD = TipoPdD.toTipoPdD(tmpValue);
  224.                 }
  225.             }
  226.             else if(i==1){
  227.                 String tmpValue = tmp[i].trim();
  228.                 if(tmpValue!=null && !"-".equals(tmpValue)){
  229.                     misurazioni.protocollo = tmpValue;
  230.                 }
  231.             }
  232.             else if(i==2){
  233.                 String tmpValue = tmp[i].trim();
  234.                 if(tmpValue!=null && !"-".equals(tmpValue)){
  235.                     misurazioni.dataIngressoRichiesta = new Date(Long.parseLong(tmpValue));
  236.                 }
  237.             }
  238.             else if(i==3){
  239.                 String tmpValue = tmp[i].trim();
  240.                 if(tmpValue!=null && !"-".equals(tmpValue)){
  241.                     misurazioni.dataUscitaRichiesta = new Date(Long.parseLong(tmpValue));
  242.                 }
  243.             }
  244.             else if(i==4){
  245.                 String tmpValue = tmp[i].trim();
  246.                 if(tmpValue!=null && !"-".equals(tmpValue)){
  247.                     misurazioni.dataIngressoRisposta = new Date(Long.parseLong(tmpValue));
  248.                 }
  249.             }
  250.             else if(i==5){
  251.                 String tmpValue = tmp[i].trim();
  252.                 if(tmpValue!=null && !"-".equals(tmpValue)){
  253.                     misurazioni.dataUscitaRisposta = new Date(Long.parseLong(tmpValue));
  254.                 }
  255.             }
  256.             else if(i==6){
  257.                 String tmpValue = tmp[i].trim();
  258.                 if(tmpValue!=null && !"-".equals(tmpValue)){
  259.                     misurazioni.richiestaIngressoBytes = Long.parseLong(tmpValue);
  260.                 }
  261.             }
  262.             else if(i==7){
  263.                 String tmpValue = tmp[i].trim();
  264.                 if(tmpValue!=null && !"-".equals(tmpValue)){
  265.                     misurazioni.richiestaUscitaBytes = Long.parseLong(tmpValue);
  266.                 }
  267.             }
  268.             else if(i==8){
  269.                 String tmpValue = tmp[i].trim();
  270.                 if(tmpValue!=null && !"-".equals(tmpValue)){
  271.                     misurazioni.rispostaIngressoBytes = Long.parseLong(tmpValue);
  272.                 }
  273.             }
  274.             else if(i==9){
  275.                 String tmpValue = tmp[i].trim();
  276.                 if(tmpValue!=null && !"-".equals(tmpValue)){
  277.                     misurazioni.rispostaUscitaBytes = Long.parseLong(tmpValue);
  278.                 }
  279.             }
  280.             else if(i==10){
  281.                 String tmpValue = tmp[i].trim();
  282.                 if(tmpValue!=null && !"-".equals(tmpValue)){
  283.                     misurazioni.esitoTransazione = Integer.parseInt(tmpValue);
  284.                 }
  285.             }
  286.         }
  287.        
  288.         return misurazioni;
  289.     }
  290. }