IdentificativoIM.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.services.skeleton;

  21. import java.util.Date;

  22. import org.openspcoop2.utils.date.DateUtils;
  23. import org.slf4j.Logger;

  24. /**
  25.  * IdentificativoIM
  26.  *
  27.  * @author apoli@link.it
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */
  31. public class IdentificativoIM {

  32.     public static final String DATE_PREFIX_SEPARATOR = "@";
  33.     public static final String FORMAT = "yyyyMMddHHmmssSSS";
  34.    
  35.     private String id;
  36.     private Date data;
  37.    
  38.     public IdentificativoIM(String id, Date data) {
  39.         this.id = id;
  40.         this.data = data;
  41.     }
  42.    
  43.     public String getId() {
  44.         return this.id;
  45.     }
  46.     public String getIdWithDate() {
  47.         if(this.data!=null) {
  48.             return DateUtils.getSimpleDateFormat(FORMAT).format(this.data)+DATE_PREFIX_SEPARATOR+this.id;
  49.         }
  50.         else {
  51.             return this.id;
  52.         }
  53.     }

  54.     public Date getData() {
  55.         return this.data;
  56.     }
  57.    
  58.     public static IdentificativoIM getIdentificativoIM(String identificativo, Logger log) {
  59.         //System.out.println("IM indexOf["+identificativo.indexOf(DATE_PREFIX_SEPARATOR)+"]");
  60.         if(identificativo.length()>(FORMAT.length()+1) &&
  61.                 identificativo.contains(DATE_PREFIX_SEPARATOR) &&
  62.                 !identificativo.endsWith(DATE_PREFIX_SEPARATOR) &&
  63.                 !identificativo.startsWith(DATE_PREFIX_SEPARATOR) &&
  64.                 identificativo.indexOf(DATE_PREFIX_SEPARATOR)==FORMAT.length()) {
  65.             String dataString = identificativo.substring(0,identificativo.indexOf(DATE_PREFIX_SEPARATOR));
  66.             String id = identificativo.substring(identificativo.indexOf(DATE_PREFIX_SEPARATOR)+1);
  67.             try {
  68.                 Date data = DateUtils.getSimpleDateFormat(FORMAT).parse(dataString);
  69.                 IdentificativoIM idIM = new IdentificativoIM(id, data);
  70.                 return idIM;
  71.             }
  72.             catch(Exception e) {
  73.                 log.error("Conversione data '"+dataString+"' non riuscita: "+e.getMessage(),e);
  74.             }
  75.         }
  76.         return new IdentificativoIM(identificativo, null);
  77.     }
  78. }