UniqueIdentifierUtilities.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.text.ParseException;
  22. import java.text.SimpleDateFormat;
  23. import java.util.Date;

  24. import org.openspcoop2.core.controllo_traffico.AttivazionePolicy;
  25. import org.openspcoop2.core.controllo_traffico.IdActivePolicy;
  26. import org.openspcoop2.utils.date.DateUtils;

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

  35.     private static final String separator = "#";
  36.    
  37.     public static String getUniqueId(AttivazionePolicy attivazionePolicy){
  38.         String idActivePolicy = attivazionePolicy.getIdActivePolicy();
  39.        
  40.         SimpleDateFormat dateFormat = DateUtils.getSimpleDateFormatMs();
  41.         String time = dateFormat.format(attivazionePolicy.getUpdateTime());
  42.        
  43.         return idActivePolicy + separator + time;
  44.     }
  45.    
  46.     public static String getUniqueId(IdActivePolicy idActivePolicy){
  47.        
  48.         SimpleDateFormat dateFormat = DateUtils.getSimpleDateFormatMs();
  49.         return idActivePolicy.getNome()+separator+dateFormat.format(idActivePolicy.getUpdateTime());
  50.        
  51.     }
  52.    
  53.     public static String extractIdActivePolicy(String id){
  54.         return id.split(separator)[0];
  55.     }
  56.    
  57.     public static Date extractUpdateTimeActivePolicy(String id) throws ParseException{
  58.         SimpleDateFormat dateFormat = DateUtils.getSimpleDateFormatMs();
  59.         return dateFormat.parse(id.split(separator)[1]);
  60.     }
  61. }