001/*
002 * Copyright 2018-2020 Ping Identity Corporation
003 * All Rights Reserved.
004 */
005/*
006 * Copyright 2018-2020 Ping Identity Corporation
007 *
008 * Licensed under the Apache License, Version 2.0 (the "License");
009 * you may not use this file except in compliance with the License.
010 * You may obtain a copy of the License at
011 *
012 *    http://www.apache.org/licenses/LICENSE-2.0
013 *
014 * Unless required by applicable law or agreed to in writing, software
015 * distributed under the License is distributed on an "AS IS" BASIS,
016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017 * See the License for the specific language governing permissions and
018 * limitations under the License.
019 */
020/*
021 * Copyright (C) 2018-2020 Ping Identity Corporation
022 *
023 * This program is free software; you can redistribute it and/or modify
024 * it under the terms of the GNU General Public License (GPLv2 only)
025 * or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
026 * as published by the Free Software Foundation.
027 *
028 * This program is distributed in the hope that it will be useful,
029 * but WITHOUT ANY WARRANTY; without even the implied warranty of
030 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
031 * GNU General Public License for more details.
032 *
033 * You should have received a copy of the GNU General Public License
034 * along with this program; if not, see <http://www.gnu.org/licenses>.
035 */
036package com.unboundid.ldap.sdk.unboundidds.tasks;
037
038
039
040import com.unboundid.util.StaticUtils;
041import com.unboundid.util.ThreadSafety;
042import com.unboundid.util.ThreadSafetyLevel;
043
044
045
046/**
047 * This enum defines the set of allowed timestamp formats for use in conjunction
048 * with the file retention task.
049 * <BR>
050 * <BLOCKQUOTE>
051 *   <B>NOTE:</B>  This class, and other classes within the
052 *   {@code com.unboundid.ldap.sdk.unboundidds} package structure, are only
053 *   supported for use against Ping Identity, UnboundID, and
054 *   Nokia/Alcatel-Lucent 8661 server products.  These classes provide support
055 *   for proprietary functionality or for external specifications that are not
056 *   considered stable or mature enough to be guaranteed to work in an
057 *   interoperable way with other types of LDAP servers.
058 * </BLOCKQUOTE>
059 */
060@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
061public enum FileRetentionTaskTimestampFormat
062{
063  /**
064   * The timestamp format that uses the generalized time format in the UTC time
065   * zone (with the 'Z' time zone indicator) with millisecond-level precision
066   * (e.g., "20180102123456.789Z").
067   */
068  GENERALIZED_TIME_UTC_WITH_MILLISECONDS(true, "yyyyMMddHHmmss.SSS'Z'",
069       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_BEGIN_CAPTURE_GROUP +
070       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_YEAR +
071       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MONTH +
072       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_DAY +
073       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_HOUR +
074       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MINUTE +
075       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_SECOND +
076       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MILLISECOND +
077       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_LITERAL_Z +
078       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_END_CAPTURE_GROUP),
079
080
081
082  /**
083   * The timestamp format that uses the generalized time format in the UTC time
084   * zone (with the 'Z' time zone indicator) with second-level precision (e.g.,
085   * "20180102123456Z").
086   */
087  GENERALIZED_TIME_UTC_WITH_SECONDS(true, "yyyyMMddHHmmss'Z'",
088       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_BEGIN_CAPTURE_GROUP +
089       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_YEAR +
090       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MONTH +
091       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_DAY +
092       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_HOUR +
093       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MINUTE +
094       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_SECOND +
095       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_LITERAL_Z +
096       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_END_CAPTURE_GROUP),
097
098
099
100  /**
101   * The timestamp format that uses the generalized time format in the UTC time
102   * zone (with the 'Z' time zone indicator) with minute-level precision (e.g.,
103   * "201801021234Z").
104   */
105  GENERALIZED_TIME_UTC_WITH_MINUTES(true, "yyyyMMddHHmm'Z'",
106       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_BEGIN_CAPTURE_GROUP +
107       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_YEAR +
108       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MONTH +
109       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_DAY +
110       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_HOUR +
111       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MINUTE +
112       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_LITERAL_Z +
113       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_END_CAPTURE_GROUP),
114
115
116
117  /**
118   * The timestamp format that uses a numeric form at in the local time zone
119   * (with no time zone indicator) with millisecond-level precision (e.g.,
120   * "20180102123456.789").
121   */
122  LOCAL_TIME_WITH_MILLISECONDS(false, "yyyyMMddHHmmss.SSS",
123       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_BEGIN_CAPTURE_GROUP +
124       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_YEAR +
125       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MONTH +
126       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_DAY +
127       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_HOUR +
128       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MINUTE +
129       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_SECOND +
130       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MILLISECOND +
131       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_END_CAPTURE_GROUP),
132
133
134
135  /**
136   * The timestamp format that uses a numeric form at in the local time zone
137   * (with no time zone indicator) with second-level precision (e.g.,
138   * "20180102123456").
139   */
140  LOCAL_TIME_WITH_SECONDS(false, "yyyyMMddHHmmss",
141       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_BEGIN_CAPTURE_GROUP +
142       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_YEAR +
143       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MONTH +
144       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_DAY +
145       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_HOUR +
146       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MINUTE +
147       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_SECOND +
148       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_END_CAPTURE_GROUP),
149
150
151
152  /**
153   * The timestamp format that uses a numeric form at in the local time zone
154   * (with no time zone indicator) with minute-level precision (e.g.,
155   * "201801021234").
156   */
157  LOCAL_TIME_WITH_MINUTES(false, "yyyyMMddHHmm",
158       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_BEGIN_CAPTURE_GROUP +
159       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_YEAR +
160       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MONTH +
161       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_DAY +
162       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_HOUR +
163       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MINUTE +
164       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_END_CAPTURE_GROUP),
165
166
167
168  /**
169   * The timestamp format that uses a numeric form at in the local time zone
170   * (with no time zone indicator) with day-level precision (e.g., "20180102").
171   */
172  LOCAL_DATE(false, "yyyyMMdd",
173       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_BEGIN_CAPTURE_GROUP +
174       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_YEAR +
175       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_MONTH +
176       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_DAY +
177       FileRetentionTaskTimestampFormat.REGEX_FRAGMENT_END_CAPTURE_GROUP);
178
179
180
181  /**
182   * A regular expression fragment that begins a capture group.
183   */
184  private static final String REGEX_FRAGMENT_BEGIN_CAPTURE_GROUP = "(";
185
186
187
188  /**
189   * A regular expression fragment that matches a year between 1900 and 2199.
190   */
191  private static final String REGEX_FRAGMENT_YEAR = "(19|20|21)[0-9][0-9]";
192
193
194
195  /**
196   * A regular expression fragment that matches a month between 01 and 12.
197   */
198  private static final String REGEX_FRAGMENT_MONTH = "(0[1-9]|1[0-2])";
199
200
201
202  /**
203   * A regular expression fragment that matches a day between 01 and 31.
204   */
205  private static final String REGEX_FRAGMENT_DAY = "(0[1-9]|[1-2][0-9]|3[0-1])";
206
207
208
209  /**
210   * A regular expression fragment that matches an hour between 00 and 23.
211   */
212  private static final String REGEX_FRAGMENT_HOUR = "([0-1][0-9]|2[0-3])";
213
214
215
216  /**
217   * A regular expression fragment that matches a minute between 00 and 59.
218   */
219  private static final String REGEX_FRAGMENT_MINUTE = "[0-5][0-9]";
220
221
222
223  /**
224   * A regular expression fragment that matches a second between 00 and 59.
225   */
226  private static final String REGEX_FRAGMENT_SECOND = "[0-5][0-9]";
227
228
229
230  /**
231   * A regular expression fragment that matches a millisecond between 000 and
232   * 999, preceded by a literal period character.
233   */
234  private static final String REGEX_FRAGMENT_MILLISECOND = "\\.[0-9][0-9][0-9]";
235
236
237
238  /**
239   * A regular expression fragment that matches a literal 'Z' character (to
240   * serve as a time zone indicator).
241   */
242  private static final String REGEX_FRAGMENT_LITERAL_Z = "Z";
243
244
245
246  /**
247   * A regular expression fragment that ends a capture group.
248   */
249  private static final String REGEX_FRAGMENT_END_CAPTURE_GROUP = ")";
250
251
252
253  // Indicates whether this timestamp format should use the UTC time zone rather
254  // than the JVM's default time zone.
255  private final boolean isInUTCTimeZone;
256
257  // A format string that can be used to create a SimpleDateFormat object
258  // capable of parsing timestamps in this format.
259  private final String simpleDateFormatString;
260
261  // A regular expression string that can be used to match timestamps in this
262  // format.
263  private final String regexString;
264
265
266
267  /**
268   * Creates a new timestamp format value with the provided information.
269   *
270   * @param  isInUTCTimeZone         Indicates whether the timestamp format
271   *                                 should use the UTC time zone rather than
272   *                                 the JVM's default time zone.
273   * @param  simpleDateFormatString  A format string that can be used to create
274   *                                 a {@code SimpleDateFormat] object capable
275   *                                 of parsing timestamps in this format.  It
276   *                                 must not be {@code null}.
277   * @param  regexString             A regular expression string that can be
278   *                                 used to match timestamps in this format.
279   *                                 It must not be {@code null}.
280   */
281  FileRetentionTaskTimestampFormat(final boolean isInUTCTimeZone,
282                                   final String simpleDateFormatString,
283                                   final String regexString)
284  {
285    this.isInUTCTimeZone = isInUTCTimeZone;
286    this.simpleDateFormatString = simpleDateFormatString;
287    this.regexString = regexString;
288  }
289
290
291
292  /**
293   * Indicates whether the timestamp format should use the UTC time zone rather
294   * than the JVM's default time zone.
295   *
296   * @return  {@code true} if the timestamp format should use the UTC time zone,
297   *          or {@code false} if it should use the JVM's default time zone
298   *          (which itself may or may not be the UTC time zone).
299   */
300  public boolean isInUTCTimeZone()
301  {
302    return isInUTCTimeZone;
303  }
304
305
306
307  /**
308   * Retrieves a format string that can be used to create a
309   * {@code SimpleDateFormat} object capable of parsing timestamps in this
310   * format.
311   *
312   * @return  A format string that can be used to create a
313   *          {@code SimpleDateFormat} object capable of parsing timestamps in
314   *          this format.
315   */
316  public String getSimpleDateFormatString()
317  {
318    return simpleDateFormatString;
319  }
320
321
322
323  /**
324   * Retrieves a regular expression string that can be used to match timestamps
325   * in this format.  The returned string will be surrounded by parentheses so
326   * that it can act as a capture group.
327   *
328   * @return  A regular expression string that can be used to match timestamps
329   *          in this format.
330   */
331  public String getRegexString()
332  {
333    return regexString;
334  }
335
336
337
338  /**
339   * Retrieves the timestamp format value with the specified name.
340   *
341   * @param  name  The name of the timestamp format value to retrieve.
342   *
343   * @return  The timestamp format value with the specified name, or
344   *          {@code null} if there is no value with that name.
345   */
346  public static FileRetentionTaskTimestampFormat forName(final String name)
347  {
348    final String upperName = StaticUtils.toUpperCase(name).replace('-', '_');
349    for (final FileRetentionTaskTimestampFormat f : values())
350    {
351      if (f.name().equals(upperName))
352      {
353        return f;
354      }
355    }
356
357    return null;
358  }
359}