VES Heartbeat and Software Management Feature
[oam/tr069-adapter.git] / common / src / main / java / org / commscope / tr069adapter / common / scheduler / TriggerInfo.java
1 /*\r
2  * ============LICENSE_START========================================================================\r
3  * ONAP : tr-069-adapter\r
4  * =================================================================================================\r
5  * Copyright (C) 2020 CommScope Inc Intellectual Property.\r
6  * =================================================================================================\r
7  * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,\r
8  * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You\r
9  * may obtain a copy of the License at\r
10  *\r
11  * http://www.apache.org/licenses/LICENSE-2.0\r
12  *\r
13  * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,\r
14  * either express or implied. See the License for the specific language governing permissions and\r
15  * limitations under the License.\r
16  * ===============LICENSE_END=======================================================================\r
17  */\r
18 \r
19 package org.commscope.tr069adapter.common.scheduler;\r
20 \r
21 import java.io.Serializable;\r
22 import java.util.Date;\r
23 \r
24 import org.apache.logging.log4j.core.util.CronExpression;\r
25 \r
26 public class TriggerInfo implements Serializable {\r
27 \r
28   /**\r
29    * \r
30    */\r
31   private static final long serialVersionUID = 6020368636888997385L;\r
32 \r
33   /**\r
34    * Date representing the start of the job that is to be scheduled. If not provided it assumes the\r
35    * current time as the start time.\r
36    */\r
37   private Date startDate = null;\r
38 \r
39   /**\r
40    * Object which represent the time unit in which the interval to be calculated for periodic jobs.\r
41    * default is days.\r
42    */\r
43   private TimeUnit timeUnit = TimeUnit.DAYS;\r
44 \r
45   /**\r
46    * long represents the interval.Which scheduling the jobs this property along with timeUnit is\r
47    * used to calculate the interval in between job executions for periodic jobs.\r
48    */\r
49   private long interval = -1;\r
50 \r
51   /**\r
52    * Date representing the end date of the scheduled periodic jobs. If there is not end date is\r
53    * provided then scheduling will be executed forever for every periodic interval.Periodic interval\r
54    * is calculated using interval and Timeunit properties of this object.\r
55    */\r
56   private Date endDate = null;\r
57 \r
58   /**\r
59    * This string representing valid cron expression to run Cron Triggger type of jobs. If the string\r
60    * which is set is not a valid cron expression it will throw an scheduler exception indicating\r
61    * invalid cron expression..\r
62    */\r
63   private String cronExpr = null;\r
64 \r
65   private Date nextFireTime = null;\r
66 \r
67   public Date getNextFireTime() {\r
68     return nextFireTime;\r
69   }\r
70 \r
71   public void setNextFireTime(Date nextFireTime) {\r
72     this.nextFireTime = nextFireTime;\r
73   }\r
74 \r
75   public Date getEndDate() {\r
76     return endDate;\r
77   }\r
78 \r
79   public void setEndDate(Date endDate) {\r
80     this.endDate = endDate;\r
81   }\r
82 \r
83   public String getCronExpr() {\r
84     return cronExpr;\r
85   }\r
86 \r
87   public void setCronExpr(String cronExpr) throws SchedulerException {\r
88     try {\r
89       new CronExpression(cronExpr);\r
90     } catch (Exception excep) {\r
91       throw new SchedulerException(SchedulerError.INVALID_CRON_EXPRESSION);\r
92     }\r
93     this.cronExpr = cronExpr;\r
94   }\r
95 \r
96   public Date getStartDate() {\r
97 \r
98     return startDate;\r
99   }\r
100 \r
101   public void setStartDate(Date startDate) {\r
102     this.startDate = startDate;\r
103   }\r
104 \r
105   public TimeUnit getTimeUnit() {\r
106     return timeUnit;\r
107   }\r
108 \r
109   public void setTimeUnit(TimeUnit timeUnit) {\r
110     this.timeUnit = timeUnit;\r
111   }\r
112 \r
113   public long getInterval() {\r
114     return interval;\r
115   }\r
116 \r
117   public void setInterval(long interval) throws SchedulerException {\r
118     if (interval < -1)\r
119       throw new SchedulerException(SchedulerError.INVALID_TIME_INTERVAL);\r
120     this.interval = interval;\r
121   }\r
122 \r
123   public TriggerInfo() {}\r
124 \r
125   public TriggerInfo(Date startDate) {\r
126     this.startDate = startDate;\r
127   }\r
128 \r
129   public TriggerInfo(Date startDate, long interval) throws SchedulerException {\r
130     this(startDate);\r
131     if (interval < -1)\r
132       throw new SchedulerException(SchedulerError.INVALID_TIME_INTERVAL);\r
133     this.interval = interval;\r
134   }\r
135 \r
136   public TriggerInfo(Date startDate, Date endDate, long interval) throws SchedulerException {\r
137     this(startDate, interval);\r
138 \r
139     if (endDate.getTime() < startDate.getTime())\r
140       throw new SchedulerException(SchedulerError.INVALID_ENDDATE);\r
141     this.endDate = endDate;\r
142 \r
143   }\r
144 \r
145   public TriggerInfo(String cronExpression) throws SchedulerException {\r
146     try {\r
147       new CronExpression(cronExpression);\r
148     } catch (Exception excep) {\r
149       throw new SchedulerException(SchedulerError.INVALID_CRON_EXPRESSION);\r
150     }\r
151     this.cronExpr = cronExpression;\r
152   }\r
153 }\r