Initial source code
[oam/tr069-adapter.git] / common / src / main / java / org / commscope / tr069adapter / common / scheduler / TriggerInfo.java
diff --git a/common/src/main/java/org/commscope/tr069adapter/common/scheduler/TriggerInfo.java b/common/src/main/java/org/commscope/tr069adapter/common/scheduler/TriggerInfo.java
new file mode 100644 (file)
index 0000000..75358da
--- /dev/null
@@ -0,0 +1,153 @@
+/*\r
+ * ============LICENSE_START========================================================================\r
+ * ONAP : tr-069-adapter\r
+ * =================================================================================================\r
+ * Copyright (C) 2020 CommScope Inc Intellectual Property.\r
+ * =================================================================================================\r
+ * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,\r
+ * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You\r
+ * may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\r
+ * either express or implied. See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ * ===============LICENSE_END=======================================================================\r
+ */\r
+\r
+package org.commscope.tr069adapter.common.scheduler;\r
+\r
+import java.io.Serializable;\r
+import java.util.Date;\r
+\r
+import org.apache.logging.log4j.core.util.CronExpression;\r
+\r
+public class TriggerInfo implements Serializable {\r
+\r
+  /**\r
+   * \r
+   */\r
+  private static final long serialVersionUID = 6020368636888997385L;\r
+\r
+  /**\r
+   * Date representing the start of the job that is to be scheduled. If not provided it assumes the\r
+   * current time as the start time.\r
+   */\r
+  private Date startDate = null;\r
+\r
+  /**\r
+   * Object which represent the time unit in which the interval to be calculated for periodic jobs.\r
+   * default is days.\r
+   */\r
+  private TimeUnit timeUnit = TimeUnit.DAYS;\r
+\r
+  /**\r
+   * long represents the interval.Which scheduling the jobs this property along with timeUnit is\r
+   * used to calculate the interval in between job executions for periodic jobs.\r
+   */\r
+  private long interval = -1;\r
+\r
+  /**\r
+   * Date representing the end date of the scheduled periodic jobs. If there is not end date is\r
+   * provided then scheduling will be executed forever for every periodic interval.Periodic interval\r
+   * is calculated using interval and Timeunit properties of this object.\r
+   */\r
+  private Date endDate = null;\r
+\r
+  /**\r
+   * This string representing valid cron expression to run Cron Triggger type of jobs. If the string\r
+   * which is set is not a valid cron expression it will throw an scheduler exception indicating\r
+   * invalid cron expression..\r
+   */\r
+  private String cronExpr = null;\r
+\r
+  private Date nextFireTime = null;\r
+\r
+  public Date getNextFireTime() {\r
+    return nextFireTime;\r
+  }\r
+\r
+  public void setNextFireTime(Date nextFireTime) {\r
+    this.nextFireTime = nextFireTime;\r
+  }\r
+\r
+  public Date getEndDate() {\r
+    return endDate;\r
+  }\r
+\r
+  public void setEndDate(Date endDate) {\r
+    this.endDate = endDate;\r
+  }\r
+\r
+  public String getCronExpr() {\r
+    return cronExpr;\r
+  }\r
+\r
+  public void setCronExpr(String cronExpr) throws SchedulerException {\r
+    try {\r
+      new CronExpression(cronExpr);\r
+    } catch (Exception excep) {\r
+      throw new SchedulerException(SchedulerError.INVALID_CRON_EXPRESSION);\r
+    }\r
+    this.cronExpr = cronExpr;\r
+  }\r
+\r
+  public Date getStartDate() {\r
+\r
+    return startDate;\r
+  }\r
+\r
+  public void setStartDate(Date startDate) {\r
+    this.startDate = startDate;\r
+  }\r
+\r
+  public TimeUnit getTimeUnit() {\r
+    return timeUnit;\r
+  }\r
+\r
+  public void setTimeUnit(TimeUnit timeUnit) {\r
+    this.timeUnit = timeUnit;\r
+  }\r
+\r
+  public long getInterval() {\r
+    return interval;\r
+  }\r
+\r
+  public void setInterval(long interval) throws SchedulerException {\r
+    if (interval < -1)\r
+      throw new SchedulerException(SchedulerError.INVALID_TIME_INTERVAL);\r
+    this.interval = interval;\r
+  }\r
+\r
+  public TriggerInfo() {}\r
+\r
+  public TriggerInfo(Date startDate) {\r
+    this.startDate = startDate;\r
+  }\r
+\r
+  public TriggerInfo(Date startDate, long interval) throws SchedulerException {\r
+    this(startDate);\r
+    if (interval < -1)\r
+      throw new SchedulerException(SchedulerError.INVALID_TIME_INTERVAL);\r
+    this.interval = interval;\r
+  }\r
+\r
+  public TriggerInfo(Date startDate, Date endDate, long interval) throws SchedulerException {\r
+    this(startDate, interval);\r
+\r
+    if (endDate.getTime() < startDate.getTime())\r
+      throw new SchedulerException(SchedulerError.INVALID_ENDDATE);\r
+    this.endDate = endDate;\r
+\r
+  }\r
+\r
+  public TriggerInfo(String cronExpression) throws SchedulerException {\r
+    try {\r
+      new CronExpression(cronExpression);\r
+    } catch (Exception excep) {\r
+      throw new SchedulerException(SchedulerError.INVALID_CRON_EXPRESSION);\r
+    }\r
+    this.cronExpr = cronExpression;\r
+  }\r
+}\r