PolicyDateUtils.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.controllo_traffico.policy;

  21. import java.text.SimpleDateFormat;
  22. import java.util.Date;

  23. import org.openspcoop2.core.controllo_traffico.constants.TipoFinestra;
  24. import org.openspcoop2.generic_project.exception.NotFoundException;
  25. import org.openspcoop2.utils.Map;
  26. import org.openspcoop2.utils.MapKey;
  27. import org.openspcoop2.utils.date.DateUtils;

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

  36.     public static String toStringIntervalloTemporale(TipoFinestra tipoFinestra, Date leftDate,Date rightDate,Date checkDate, boolean statistic) throws NotFoundException{
  37.         StringBuilder bf = new StringBuilder("");
  38.        
  39.         SimpleDateFormat dateFormat = DateUtils.getSimpleDateFormatMs();
  40.        
  41.         if(statistic){
  42.             bf.append("[campionamento statistico, finestra osservazione ");
  43.         }
  44.         else{
  45.             bf.append("[campionamento realtime, finestra osservazione ");
  46.         }
  47.         bf.append(tipoFinestra.getValue());
  48.         bf.append(" ");
  49.         if(leftDate!=null && rightDate!=null){
  50.             bf.append(dateFormat.format(leftDate));
  51.             bf.append(" - ");
  52.             bf.append(dateFormat.format(rightDate));
  53.         }
  54.         else{
  55.             bf.append("non disponibile");
  56.         }
  57.         if(statistic){
  58.             bf.append(" (ultimo aggiornamento:").
  59.             append(dateFormat.format(checkDate)).
  60.             append(")");
  61.         }
  62.         bf.append("]");

  63.         return bf.toString();
  64.     }  
  65.    
  66.     private static final MapKey<String> RATE_LIMITING_GESTORE_POLICY_CONFIG_DATE = Map.newMapKey("RATE_LIMITING_GESTORE_POLICY_CONFIG_DATE");
  67.     public static void setGestorePolicyConfigDateIntoContext(Map<Object> ctx, Long gestorePolicyConfigDate) {
  68.         if(ctx!=null && gestorePolicyConfigDate!=null && gestorePolicyConfigDate>0) {
  69.             ctx.put(RATE_LIMITING_GESTORE_POLICY_CONFIG_DATE, gestorePolicyConfigDate);
  70.         }
  71.     }
  72.     public static void removeGestorePolicyConfigDateIntoContext(Map<Object> ctx) {
  73.         if(ctx!=null ) {
  74.             ctx.remove(RATE_LIMITING_GESTORE_POLICY_CONFIG_DATE);
  75.         }
  76.     }
  77.     public static Date readGestorePolicyConfigDateIntoContext(Map<Object> ctx) {
  78.         if(ctx!=null ) {
  79.             Object o = ctx.get(RATE_LIMITING_GESTORE_POLICY_CONFIG_DATE);
  80.             if(o!=null && o instanceof Long) {
  81.                 long l = (Long) o;
  82.                 return new Date(l);
  83.             }
  84.         }
  85.         return null;
  86.     }
  87.    
  88. }