Initial source code
[oam/tr069-adapter.git] / common / src / main / java / org / commscope / tr069adapter / common / scheduler / ExecutionContext.java
diff --git a/common/src/main/java/org/commscope/tr069adapter/common/scheduler/ExecutionContext.java b/common/src/main/java/org/commscope/tr069adapter/common/scheduler/ExecutionContext.java
new file mode 100644 (file)
index 0000000..f3305d2
--- /dev/null
@@ -0,0 +1,135 @@
+/*\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
+\r
+package org.commscope.tr069adapter.common.scheduler;\r
+\r
+import static org.commscope.tr069adapter.common.scheduler.impl.QuartzSchedulerConstants.JOB_APPENDER;\r
+\r
+import java.io.Serializable;\r
+import java.util.HashMap;\r
+import java.util.Map;\r
+import java.util.Set;\r
+\r
+public class ExecutionContext implements Serializable {\r
+\r
+  /**\r
+   * \r
+   */\r
+  private static final long serialVersionUID = 8182423848241219082L;\r
+\r
+  /**\r
+   * String representing the bean id which by which is job is configured in the spring container.\r
+   */\r
+  private String subSystemName;\r
+\r
+  private String jobName;\r
+\r
+  private String jobId;\r
+\r
+  private String jobGroup;\r
+\r
+  /**\r
+   * Constructor for getting the execution context object. Need to pass a string which represents\r
+   * the bean id that is configured in spring container.\r
+   * \r
+   * @param subSystemName - String object which is bean id of the job that is to be executed.\r
+   */\r
+  public ExecutionContext(String subSystemName, String jobName) {\r
+    if (null == subSystemName || "".equals(subSystemName))\r
+      throw new InstantiationError("Subsystem name Can not be null or empty");\r
+    this.subSystemName = subSystemName;\r
+    if (null == jobName || "".equals(jobName))\r
+      throw new InstantiationError("Job name Can not be null or empty");\r
+    this.jobName = jobName;\r
+  }\r
+\r
+  /**\r
+   * Constructor for getting the execution context object. Need to pass a string which represents\r
+   * the bean id that is configured in spring container.\r
+   * \r
+   * @param subSystemName - String object which is bean id of the job that is to be executed.\r
+   */\r
+  public ExecutionContext(String jobId, String subSystemName, String jobName) {\r
+    if (null == subSystemName || "".equals(subSystemName))\r
+      throw new InstantiationError("Subsystem name Can not be null or empty");\r
+    this.subSystemName = subSystemName;\r
+    if (null == jobName || "".equals(jobName))\r
+      throw new InstantiationError("Job name Can not be null or empty");\r
+    this.jobName = jobName;\r
+    this.jobId = jobId;\r
+  }\r
+\r
+  public String getJobName() {\r
+    return jobName;\r
+  }\r
+\r
+  public String getSubSystemName() {\r
+    return subSystemName;\r
+  }\r
+\r
+  private Map<String, Object> context = new HashMap<>();\r
+\r
+  /**\r
+   * Can be used to get some job related data, at the time of job execution.\r
+   * \r
+   * @param key\r
+   * @return\r
+   */\r
+  public Object getJobData(String key) {\r
+    return context.get(key);\r
+  }\r
+\r
+  /**\r
+   * Can be used add some job related data at the time of scheduling the job. Note: This data can be\r
+   * retrieved later at the time of execution by the Job implementation.\r
+   * \r
+   * @param key\r
+   * @param value\r
+   */\r
+  public void addJobData(String key, Object value) {\r
+    context.put(key, value);\r
+  }\r
+\r
+  /**\r
+   * This method can be used to get the all the job data parameter names which can be used to\r
+   * iterate through the all job data parameters.\r
+   * \r
+   * @return - String set.\r
+   */\r
+  public Set<String> getJobDatakeySet() {\r
+    return context.keySet();\r
+  }\r
+\r
+  public String getJobId() {\r
+    int index = jobId.lastIndexOf(JOB_APPENDER);\r
+    if (index > -1) {\r
+      jobId = jobId.substring(0, index);\r
+    }\r
+    return jobId; // remove appender\r
+  }\r
+\r
+  public String getJobGroup() {\r
+    return jobGroup;\r
+  }\r
+\r
+  public void setJobGroup(String jobGroup) {\r
+    this.jobGroup = jobGroup;\r
+  }\r
+\r
+}\r