VES Heartbeat and Software Management Feature
[oam/tr069-adapter.git] / common / src / main / java / org / commscope / tr069adapter / common / scheduler / ExecutionContext.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 \r
20 package org.commscope.tr069adapter.common.scheduler;\r
21 \r
22 import static org.commscope.tr069adapter.common.scheduler.impl.QuartzSchedulerConstants.JOB_APPENDER;\r
23 \r
24 import java.io.Serializable;\r
25 import java.util.HashMap;\r
26 import java.util.Map;\r
27 import java.util.Set;\r
28 \r
29 public class ExecutionContext implements Serializable {\r
30 \r
31   /**\r
32    * \r
33    */\r
34   private static final long serialVersionUID = 8182423848241219082L;\r
35 \r
36   /**\r
37    * String representing the bean id which by which is job is configured in the spring container.\r
38    */\r
39   private String subSystemName;\r
40 \r
41   private String jobName;\r
42 \r
43   private String jobId;\r
44 \r
45   private String jobGroup;\r
46 \r
47   /**\r
48    * Constructor for getting the execution context object. Need to pass a string which represents\r
49    * the bean id that is configured in spring container.\r
50    * \r
51    * @param subSystemName - String object which is bean id of the job that is to be executed.\r
52    */\r
53   public ExecutionContext(String subSystemName, String jobName) {\r
54     if (null == subSystemName || "".equals(subSystemName))\r
55       throw new InstantiationError("Subsystem name Can not be null or empty");\r
56     this.subSystemName = subSystemName;\r
57     if (null == jobName || "".equals(jobName))\r
58       throw new InstantiationError("Job name Can not be null or empty");\r
59     this.jobName = jobName;\r
60   }\r
61 \r
62   /**\r
63    * Constructor for getting the execution context object. Need to pass a string which represents\r
64    * the bean id that is configured in spring container.\r
65    * \r
66    * @param subSystemName - String object which is bean id of the job that is to be executed.\r
67    */\r
68   public ExecutionContext(String jobId, String subSystemName, String jobName) {\r
69     if (null == subSystemName || "".equals(subSystemName))\r
70       throw new InstantiationError("Subsystem name Can not be null or empty");\r
71     this.subSystemName = subSystemName;\r
72     if (null == jobName || "".equals(jobName))\r
73       throw new InstantiationError("Job name Can not be null or empty");\r
74     this.jobName = jobName;\r
75     this.jobId = jobId;\r
76   }\r
77 \r
78   public String getJobName() {\r
79     return jobName;\r
80   }\r
81 \r
82   public String getSubSystemName() {\r
83     return subSystemName;\r
84   }\r
85 \r
86   private transient Map<String, Object> context = new HashMap<>();\r
87 \r
88   /**\r
89    * Can be used to get some job related data, at the time of job execution.\r
90    * \r
91    * @param key\r
92    * @return\r
93    */\r
94   public Object getJobData(String key) {\r
95     return context.get(key);\r
96   }\r
97 \r
98   /**\r
99    * Can be used add some job related data at the time of scheduling the job. Note: This data can be\r
100    * retrieved later at the time of execution by the Job implementation.\r
101    * \r
102    * @param key\r
103    * @param value\r
104    */\r
105   public void addJobData(String key, Object value) {\r
106     context.put(key, value);\r
107   }\r
108 \r
109   /**\r
110    * This method can be used to get the all the job data parameter names which can be used to\r
111    * iterate through the all job data parameters.\r
112    * \r
113    * @return - String set.\r
114    */\r
115   public Set<String> getJobDatakeySet() {\r
116     return context.keySet();\r
117   }\r
118 \r
119   public String getJobId() {\r
120     int index = jobId.lastIndexOf(JOB_APPENDER);\r
121     if (index > -1) {\r
122       jobId = jobId.substring(0, index);\r
123     }\r
124     return jobId; // remove appender\r
125   }\r
126 \r
127   public String getJobGroup() {\r
128     return jobGroup;\r
129   }\r
130 \r
131   public void setJobGroup(String jobGroup) {\r
132     this.jobGroup = jobGroup;\r
133   }\r
134 \r
135 }\r