DateUtility.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.pdd.core.transazioni;

  21. import java.sql.Timestamp;
  22. import java.text.SimpleDateFormat;
  23. import java.util.Date;

  24. import org.openspcoop2.protocol.sdk.builder.IBustaBuilder;
  25. import org.openspcoop2.utils.date.DateUtils;
  26. import org.slf4j.Logger;

  27. /**    
  28.  * DateUtility
  29.  *
  30.  * @author Poli Andrea (poli@link.it)
  31.  * @author $Author$
  32.  * @version $Rev$, $Date$
  33.  */
  34. public class DateUtility {

  35.     private static final String dateformatPattern = "yyyyMMddHHmm"; // utile per il filtro duplicati

  36.     public static Timestamp getTimestampIntoIdProtocollo(Logger log, IBustaBuilder<?> bustaBuilder, String idMessaggio){
  37.        
  38.         Date dataIdBusta = null;
  39.         try{
  40.             dataIdBusta = bustaBuilder.extractDateFromID(idMessaggio);
  41.         }catch(Exception e){
  42.             log.error("Errore durante l'estrazione della data dall'identificativo di protocollo [id: "+idMessaggio+"]: "+e.getMessage(),e);
  43.             return null;
  44.         }
  45.        
  46.         if(dataIdBusta==null){
  47.             return null;
  48.         }
  49.        
  50.         SimpleDateFormat dateFormat = DateUtils.getDefaultDateTimeFormatter(dateformatPattern);
  51.        
  52.         // Le date presenti in un identificativo di protocollo, possono contenere
  53.         // informazioni fino al millisecondo.
  54.         // Per il filtro duplicati si vuole invece mantenere le informazioni fino al minuto
  55.         // al fine di raggruppare gli identificativi in un insieme minimo che renda efficiente l'indice di ricerca
  56.         String data = dateFormat.format(dataIdBusta);
  57.        
  58.         try{
  59.             return new Timestamp(dateFormat.parse(data).getTime());
  60.         }catch(Exception e){
  61.             log.error("Errore durante la conversione della data estratta dall'identificativo di protocollo [data estratta: "+data+"]: "+e.getMessage(),e);
  62.             return null;
  63.         }
  64.     }
  65.    
  66. }