diff --git a/components/task-mgt/pom.xml b/components/task-mgt/pom.xml
new file mode 100755
index 0000000000..d9ab379c3b
--- /dev/null
+++ b/components/task-mgt/pom.xml
@@ -0,0 +1,41 @@
+
+
+
+
+
+ org.wso2.carbon.devicemgt
+ carbon-devicemgt
+ 5.0.20-SNAPSHOT
+ ../../pom.xml
+
+
+ 4.0.0
+ task-mgt
+ pom
+ Entgra IoT - Task Management Component
+ http://entgra.io
+
+
+ task-manager
+ task-watcher
+
+
+
\ No newline at end of file
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml b/components/task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml
new file mode 100755
index 0000000000..ad7c991872
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml
@@ -0,0 +1,56 @@
+
+
+
+
+ task-manager
+ org.wso2.carbon.devicemgt
+ 5.0.20-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ io.entgra.task.mgt.common
+ bundle
+ Entgra IoT - Task Management Common
+ Entgra IoT - Task Management Common
+ https://entgra.io
+
+
+
+
+ org.apache.felix
+ maven-bundle-plugin
+ true
+
+
+ ${project.artifactId}
+ ${project.artifactId}
+ ${carbon.device.mgt.version}
+ Task Management Common Bundle
+
+ io.entgra.task.mgt.common.*
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/bean/DynamicTask.java b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/bean/DynamicTask.java
new file mode 100755
index 0000000000..ece8d4dc26
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/bean/DynamicTask.java
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Entgra Pvt Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.entgra.task.mgt.common.bean;
+
+import java.util.Map;
+
+public class DynamicTask {
+
+ private int dynamicTaskId;
+ private String name;
+ private String cronExpression;
+ private boolean isEnabled;
+ private int tenantId;
+ private String taskClassName;
+ private Map properties;
+
+ public int getDynamicTaskId() {
+ return dynamicTaskId;
+ }
+
+ public void setDynamicTaskId(int dynamicTaskId) {
+ this.dynamicTaskId = dynamicTaskId;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getCronExpression() {
+ return cronExpression;
+ }
+
+ public void setCronExpression(String cronExpression) {
+ this.cronExpression = cronExpression;
+ }
+
+ public boolean isEnabled() {
+ return isEnabled;
+ }
+
+ public void setEnabled(boolean enable) {
+ isEnabled = enable;
+ }
+
+ public int getTenantId() {
+ return tenantId;
+ }
+
+ public void setTenantId(int tenantId) {
+ this.tenantId = tenantId;
+ }
+
+ public String getTaskClassName() {
+ return taskClassName;
+ }
+
+ public void setTaskClassName(String taskClassName) {
+ this.taskClassName = taskClassName;
+ }
+
+ public Map getProperties() {
+ return properties;
+ }
+
+ public void setProperties(Map properties) {
+ this.properties = properties;
+ }
+
+}
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/constant/TaskMgtConstant.java b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/constant/TaskMgtConstant.java
new file mode 100755
index 0000000000..5dcc03bd1b
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/constant/TaskMgtConstant.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Entgra Pvt Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.entgra.task.mgt.common.constant;
+
+public class TaskMgtConstant {
+ public static final class DataSourceProperties {
+ private DataSourceProperties() {
+ throw new AssertionError();
+ }
+
+ public static final String DB_CHECK_QUERY = "SELECT * FROM DM_DEVICE";
+ public static final String TASK_CONFIG_XML_NAME = "task-mgt-config.xml";
+ }
+
+ public static final class DataBaseTypes {
+ private DataBaseTypes() {
+ throw new AssertionError();
+ }
+
+ public static final String DB_TYPE_MYSQL = "MySQL";
+ public static final String DB_TYPE_ORACLE = "Oracle";
+ public static final String DB_TYPE_MSSQL = "Microsoft SQL Server";
+ public static final String DB_TYPE_DB2 = "DB2";
+ public static final String DB_TYPE_H2 = "H2";
+ public static final String DB_TYPE_POSTGRESQL = "PostgreSQL";
+ }
+
+ public static final class Task {
+
+ public static final String DYNAMIC_TASK_TYPE = "DYNAMIC_TASK";
+ public static final String NAME_SEPARATOR = "_";
+ public static final String PROPERTY_KEY_COLUMN_NAME = "PROPERTY_NAME";
+ public static final String PROPERTY_VALUE_COLUMN_NAME = "PROPERTY_VALUE";
+ public static final String __TENANT_ID_PROP__ = "__TENANT_ID_PROP__";
+
+ }
+}
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/IllegalTransactionStateException.java b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/IllegalTransactionStateException.java
new file mode 100755
index 0000000000..4c4c996c59
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/IllegalTransactionStateException.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Entgra Pvt Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.entgra.task.mgt.common.exception;
+
+public class IllegalTransactionStateException extends RuntimeException {
+
+ private static final long serialVersionUID = -3151279331929070297L;
+
+ public IllegalTransactionStateException(String msg, Exception nestedEx) {
+ super(msg, nestedEx);
+ }
+
+ public IllegalTransactionStateException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public IllegalTransactionStateException(String msg) {
+ super(msg);
+ }
+
+ public IllegalTransactionStateException() {
+ super();
+ }
+
+ public IllegalTransactionStateException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TaskManagementDAOException.java b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TaskManagementDAOException.java
new file mode 100755
index 0000000000..9b683dba20
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TaskManagementDAOException.java
@@ -0,0 +1,31 @@
+/*
+ * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Entgra Pvt Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.entgra.task.mgt.common.exception;
+
+public class TaskManagementDAOException extends Exception {
+
+ public TaskManagementDAOException(String msg) {
+ super(msg);
+ }
+
+ public TaskManagementDAOException(String msg, Exception e) {
+ super(msg, e);
+ }
+
+
+}
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TaskManagementException.java b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TaskManagementException.java
new file mode 100755
index 0000000000..d9705e6438
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TaskManagementException.java
@@ -0,0 +1,29 @@
+/*
+ * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Entgra Pvt Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.entgra.task.mgt.common.exception;
+
+public class TaskManagementException extends Exception {
+
+ public TaskManagementException(String msg) {
+ super(msg);
+ }
+
+ public TaskManagementException(String msg, Exception e) {
+ super(msg, e);
+ }
+}
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TaskNotFoundException.java b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TaskNotFoundException.java
new file mode 100755
index 0000000000..2d2f568fe2
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TaskNotFoundException.java
@@ -0,0 +1,33 @@
+/*
+ * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Entgra Pvt Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.entgra.task.mgt.common.exception;
+
+/**
+ * Represents the exception thrown during validating the request.
+ */
+public class TaskNotFoundException extends Exception {
+
+ public TaskNotFoundException(String message) {
+ super(message);
+ }
+
+ public TaskNotFoundException(String message, Exception ex) {
+ super(message, ex);
+ }
+
+}
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TransactionManagementException.java b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TransactionManagementException.java
new file mode 100755
index 0000000000..5e43237e43
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/TransactionManagementException.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Entgra Pvt Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.entgra.task.mgt.common.exception;
+
+public class TransactionManagementException extends Exception {
+
+ private static final long serialVersionUID = -3151279321929070297L;
+
+ public TransactionManagementException(String msg, Exception nestedEx) {
+ super(msg, nestedEx);
+ }
+
+ public TransactionManagementException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public TransactionManagementException(String msg) {
+ super(msg);
+ }
+
+ public TransactionManagementException() {
+ super();
+ }
+
+ public TransactionManagementException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/UnsupportedDatabaseEngineException.java b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/UnsupportedDatabaseEngineException.java
new file mode 100755
index 0000000000..a29f954e12
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/exception/UnsupportedDatabaseEngineException.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Entgra Pvt Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.entgra.task.mgt.common.exception;
+
+/**
+ * This runtime exception will be thrown if the server has configured with unsupported DB engine.
+ */
+public class UnsupportedDatabaseEngineException extends RuntimeException {
+
+ private static final long serialVersionUID = -3151279311929070297L;
+
+ public UnsupportedDatabaseEngineException(String msg, Exception nestedEx) {
+ super(msg, nestedEx);
+ }
+
+ public UnsupportedDatabaseEngineException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public UnsupportedDatabaseEngineException(String msg) {
+ super(msg);
+ }
+
+ public UnsupportedDatabaseEngineException() {
+ super();
+ }
+
+ public UnsupportedDatabaseEngineException(Throwable cause) {
+ super(cause);
+ }
+
+}
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/spi/TaskManagementService.java b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/spi/TaskManagementService.java
new file mode 100755
index 0000000000..fac557e0bd
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/src/main/java/io/entgra/task/mgt/common/spi/TaskManagementService.java
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Entgra Pvt Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.entgra.task.mgt.common.spi;
+
+import io.entgra.task.mgt.common.exception.TaskNotFoundException;
+import io.entgra.task.mgt.common.exception.TaskManagementException;
+import io.entgra.task.mgt.common.bean.DynamicTask;
+
+import java.util.List;
+
+public interface TaskManagementService {
+
+ void init() throws TaskManagementException;
+
+ void createTask(DynamicTask dynamicTask) throws TaskManagementException;
+
+ void updateTask(int dynamicTaskId, DynamicTask dynamicTask) throws TaskManagementException, TaskNotFoundException;
+
+ void toggleTask(int dynamicTaskId, boolean isEnabled) throws TaskManagementException, TaskNotFoundException;
+
+ void deleteTask(int dynamicTaskId) throws TaskManagementException, TaskNotFoundException;
+
+ List getAllDynamicTasks() throws TaskManagementException;
+
+ DynamicTask getDynamicTaskById(int dynamicTaskId) throws TaskManagementException;
+
+ List getActiveDynamicTasks() throws TaskManagementException;
+}
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml b/components/task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml
new file mode 100755
index 0000000000..5202f25781
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml
@@ -0,0 +1,132 @@
+
+
+
+
+
+ org.wso2.carbon.devicemgt
+ task-manager
+ 5.0.20-SNAPSHOT
+ ../pom.xml
+
+
+ 4.0.0
+ io.entgra.task.mgt.core
+ bundle
+ Entgra IoT - Task manager Core
+ Entgra IoT - Task manager Core
+ http://entgra.io
+
+
+
+
+ org.apache.felix
+ maven-scr-plugin
+
+
+ org.apache.felix
+ maven-bundle-plugin
+ true
+
+
+ ${project.artifactId}
+ ${project.artifactId}
+ ${carbon.device.mgt.version}
+ Task Management Core Bundle
+ io.entgra.task.mgt.core.internal
+
+ org.osgi.framework.*;version="${imp.package.version.osgi.framework}",
+ org.osgi.service.*;version="${imp.package.version.osgi.service}",
+ org.apache.commons.logging,
+ org.wso2.carbon.ndatasource.core,
+ org.w3c.dom,
+ javax.xml.bind.annotation,
+ javax.xml.bind,
+ javax.sql,
+ javax.naming,
+ io.entgra.task.mgt.common.*,
+ org.wso2.carbon.utils.*,
+ org.wso2.carbon.ntask.*,
+ org.wso2.carbon.device.mgt.core.*,
+ org.wso2.carbon.device.mgt.common.*,
+ org.wso2.carbon.context,
+ io.entgra.server.bootup.heartbeat.beacon.dto,
+ io.entgra.server.bootup.heartbeat.beacon.exception,
+ io.entgra.server.bootup.heartbeat.beacon.service,
+
+
+ !io.entgra.task.mgt.core.internal,
+ io.entgra.task.mgt.core.*
+
+
+
+
+
+
+
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi
+ provided
+
+
+ org.eclipse.osgi
+ org.eclipse.osgi.services
+ provided
+
+
+ org.wso2.carbon
+ org.wso2.carbon.ndatasource.core
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ io.entgra.task.mgt.common
+ provided
+
+
+ org.wso2.carbon
+ org.wso2.carbon.logging
+ provided
+
+
+ org.wso2.carbon
+ org.wso2.carbon.utils
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.core
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ org.wso2.carbon.device.mgt.common
+ provided
+
+
+ org.wso2.carbon.devicemgt
+ io.entgra.server.bootup.heartbeat.beacon
+ provided
+
+
+
+
\ No newline at end of file
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/TaskConfigurationManager.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/TaskConfigurationManager.java
new file mode 100755
index 0000000000..9700465a1d
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/TaskConfigurationManager.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Entgra Pvt Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.entgra.task.mgt.core.config;
+
+import io.entgra.task.mgt.common.constant.TaskMgtConstant;
+import io.entgra.task.mgt.common.exception.TaskManagementException;
+import io.entgra.task.mgt.core.util.TaskManagementUtil;
+import org.w3c.dom.Document;
+import org.wso2.carbon.utils.CarbonUtils;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+import java.io.File;
+
+/**
+ * Class responsible for the task mgt configuration initialization.
+ */
+public class TaskConfigurationManager {
+
+ private TaskManagementConfig taskManagementConfig;
+ private static volatile TaskConfigurationManager taskConfigurationManager;
+
+ private static final String TASK_MGT_CONFIG_PATH =
+ CarbonUtils.getCarbonConfigDirPath() + File.separator +
+ TaskMgtConstant.DataSourceProperties.TASK_CONFIG_XML_NAME;
+
+ public static TaskConfigurationManager getInstance() {
+ if (taskConfigurationManager == null) {
+ synchronized (TaskConfigurationManager.class) {
+ if (taskConfigurationManager == null) {
+ taskConfigurationManager = new TaskConfigurationManager();
+ }
+ }
+ }
+ return taskConfigurationManager;
+ }
+
+ public synchronized void initConfig() throws TaskManagementException {
+ try {
+ File taskMgtConfig = new File(TASK_MGT_CONFIG_PATH);
+ Document doc = TaskManagementUtil.convertToDocument(taskMgtConfig);
+
+ /* Un-marshaling Device Management configuration */
+ JAXBContext cdmContext = JAXBContext.newInstance(TaskManagementConfig.class);
+ Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
+ //unmarshaller.setSchema(getSchema());
+ this.taskManagementConfig = (TaskManagementConfig) unmarshaller.unmarshal(doc);
+ } catch (JAXBException e) {
+ throw new TaskManagementException("Error occurred while initializing Data Source config", e);
+ }
+ }
+
+ public TaskManagementConfig getTaskManagementConfig() throws TaskManagementException {
+ if (taskManagementConfig == null) {
+ initConfig();
+ }
+ return taskManagementConfig;
+ }
+
+ public void setTaskManagementConfig(TaskManagementConfig taskManagementConfig) {
+ this.taskManagementConfig = taskManagementConfig;
+ }
+}
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/TaskManagementConfig.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/TaskManagementConfig.java
new file mode 100755
index 0000000000..2b3ae468ac
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/TaskManagementConfig.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Entgra Pvt Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.entgra.task.mgt.core.config;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Represents Task Mgt configuration.
+ */
+@XmlRootElement(name = "TaskMgtConfiguration")
+@SuppressWarnings("unused")
+public final class TaskManagementConfig {
+
+ private TaskManagementConfigRepository taskMgtConfigRepository;
+ private boolean isTaskWatcherEnabled;
+
+ @XmlElement(name = "ManagementRepository", required = true)
+ public TaskManagementConfigRepository getTaskMgtConfigRepository() {
+ return taskMgtConfigRepository;
+ }
+
+ public void setTaskMgtConfigRepository(TaskManagementConfigRepository taskMgtConfigRepository) {
+ this.taskMgtConfigRepository = taskMgtConfigRepository;
+ }
+
+ @XmlElement(name = "TaskWatcherEnable", required = true)
+ public boolean isTaskWatcherEnabled() {
+ return isTaskWatcherEnabled;
+ }
+
+ public void setTaskWatcherEnabled(boolean enabled) {
+ this.isTaskWatcherEnabled = enabled;
+ }
+}
+
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/TaskManagementConfigRepository.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/TaskManagementConfigRepository.java
new file mode 100755
index 0000000000..a81617f738
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/TaskManagementConfigRepository.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Entgra Pvt Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.entgra.task.mgt.core.config;
+
+import io.entgra.task.mgt.core.config.datasource.DataSourceConfig;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Class for holding management repository data.
+ */
+@XmlRootElement(name = "ManagementRepository")
+public class TaskManagementConfigRepository {
+
+ private DataSourceConfig dataSourceConfig;
+
+ @XmlElement(name = "DataSourceConfiguration", required = true)
+ public DataSourceConfig getDataSourceConfig() {
+ return dataSourceConfig;
+ }
+
+ public void setDataSourceConfig(DataSourceConfig dataSourceConfig) {
+ this.dataSourceConfig = dataSourceConfig;
+ }
+
+}
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/datasource/DataSourceConfig.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/datasource/DataSourceConfig.java
new file mode 100755
index 0000000000..b4c4d9fc2d
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/datasource/DataSourceConfig.java
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Entgra Pvt Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.entgra.task.mgt.core.config.datasource;
+
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+/**
+ * Class for holding data source configuration in task-mgt-config.xml at parsing with JAXB.
+ */
+@XmlRootElement(name = "DataSourceConfiguration")
+public class DataSourceConfig {
+
+ private JNDILookupDefinition jndiLookupDefinition;
+
+ @XmlElement(name = "JndiLookupDefinition", required = true)
+ public JNDILookupDefinition getJndiLookupDefinition() {
+ return jndiLookupDefinition;
+ }
+
+ public void setJndiLookupDefinition(JNDILookupDefinition jndiLookupDefinition) {
+ this.jndiLookupDefinition = jndiLookupDefinition;
+ }
+
+}
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/datasource/JNDILookupDefinition.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/datasource/JNDILookupDefinition.java
new file mode 100755
index 0000000000..5101af8d49
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/config/datasource/JNDILookupDefinition.java
@@ -0,0 +1,79 @@
+/*
+ * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Entgra Pvt Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package io.entgra.task.mgt.core.config.datasource;
+
+import javax.xml.bind.annotation.*;
+import java.util.List;
+
+/**
+ * Class for hold JndiLookupDefinition of task-mgt-config.xml at parsing with JAXB.
+ */
+@XmlRootElement(name = "JndiLookupDefinition")
+public class JNDILookupDefinition {
+
+ private String jndiName;
+ private List jndiProperties;
+
+ @XmlElement(name = "Name", required = false)
+ public String getJndiName() {
+ return jndiName;
+ }
+
+ public void setJndiName(String jndiName) {
+ this.jndiName = jndiName;
+ }
+
+ @XmlElementWrapper(name = "Environment", required = false)
+ @XmlElement(name = "Property", nillable = false)
+ public List getJndiProperties() {
+ return jndiProperties;
+ }
+
+ public void setJndiProperties(List jndiProperties) {
+ this.jndiProperties = jndiProperties;
+ }
+
+ @XmlRootElement(name = "Property")
+ public static class JNDIProperty {
+
+ private String name;
+
+ private String value;
+
+ @XmlAttribute(name = "Name")
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @XmlValue
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+ }
+
+}
+
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/DynamicTaskDAO.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/DynamicTaskDAO.java
new file mode 100755
index 0000000000..317870dba1
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/DynamicTaskDAO.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Entgra Pvt Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.entgra.task.mgt.core.dao;
+
+import io.entgra.task.mgt.common.bean.DynamicTask;
+import io.entgra.task.mgt.common.exception.TaskManagementDAOException;
+
+import java.util.List;
+
+/**
+ * This class represents the key operations associated with dynamic tasks.
+ */
+public interface DynamicTaskDAO {
+
+ int addTask(DynamicTask dynamicTask) throws TaskManagementDAOException;
+
+ boolean updateDynamicTask(DynamicTask dynamicTask) throws TaskManagementDAOException;
+
+ void deleteDynamicTask(int dynamicTaskId) throws TaskManagementDAOException;
+
+ DynamicTask getDynamicTaskById(int dynamicTaskId) throws TaskManagementDAOException;
+
+ List getAllDynamicTasks() throws TaskManagementDAOException;
+
+ List getActiveDynamicTasks() throws TaskManagementDAOException;
+
+}
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/DynamicTaskPropDAO.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/DynamicTaskPropDAO.java
new file mode 100755
index 0000000000..b458417298
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/DynamicTaskPropDAO.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Entgra Pvt Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.entgra.task.mgt.core.dao;
+
+import io.entgra.task.mgt.common.exception.TaskManagementDAOException;
+
+import java.util.Map;
+
+/**
+ * This class represents the key operations associated with dynamic task properties.
+ */
+public interface DynamicTaskPropDAO {
+
+ void addTaskProperties(int dynamicTaskId, Map properties) throws TaskManagementDAOException;
+
+ Map getDynamicTaskProps(int dynamicTaskId) throws TaskManagementDAOException;
+
+ void updateDynamicTaskProps(int dynamicTaskId, Map properties)
+ throws TaskManagementDAOException;
+}
diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/common/TaskManagementDAOFactory.java b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/common/TaskManagementDAOFactory.java
new file mode 100755
index 0000000000..c5ef61db2a
--- /dev/null
+++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/src/main/java/io/entgra/task/mgt/core/dao/common/TaskManagementDAOFactory.java
@@ -0,0 +1,206 @@
+/*
+ * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) All Rights Reserved.
+ *
+ * Entgra Pvt Ltd. licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package io.entgra.task.mgt.core.dao.common;
+
+import io.entgra.task.mgt.common.constant.TaskMgtConstant;
+import io.entgra.task.mgt.common.exception.IllegalTransactionStateException;
+import io.entgra.task.mgt.common.exception.TransactionManagementException;
+import io.entgra.task.mgt.common.exception.UnsupportedDatabaseEngineException;
+import io.entgra.task.mgt.core.config.datasource.DataSourceConfig;
+import io.entgra.task.mgt.core.config.datasource.JNDILookupDefinition;
+import io.entgra.task.mgt.core.dao.DynamicTaskDAO;
+import io.entgra.task.mgt.core.dao.DynamicTaskPropDAO;
+import io.entgra.task.mgt.core.dao.util.TaskManagementDAOUtil;
+import io.entgra.task.mgt.core.dao.impl.DynamicTaskDAOImpl;
+import io.entgra.task.mgt.core.dao.impl.DynamicTaskPropDAOImpl;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import javax.sql.DataSource;
+import java.sql.Connection;
+import java.sql.SQLException;
+import java.util.Hashtable;
+import java.util.List;
+
+public class TaskManagementDAOFactory {
+
+ private static DataSource dataSource;
+ private static String databaseEngine;
+ private static final Log log = LogFactory.getLog(TaskManagementDAOFactory.class);
+ private static ThreadLocal currentConnection = new ThreadLocal<>();
+
+
+ public static DynamicTaskDAO getDynamicTaskDAO() {
+ if (databaseEngine != null) {
+ switch (databaseEngine) {
+ case TaskMgtConstant.DataBaseTypes.DB_TYPE_H2:
+ case TaskMgtConstant.DataBaseTypes.DB_TYPE_MYSQL:
+ return new DynamicTaskDAOImpl();
+ default:
+ throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
+ }
+ }
+ throw new IllegalStateException("Database engine has not initialized properly.");
+ }
+
+ public static DynamicTaskPropDAO getDynamicTaskPropDAO() {
+ if (databaseEngine != null) {
+ switch (databaseEngine) {
+ case TaskMgtConstant.DataBaseTypes.DB_TYPE_H2:
+ case TaskMgtConstant.DataBaseTypes.DB_TYPE_MYSQL:
+ return new DynamicTaskPropDAOImpl();
+ default:
+ throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
+ }
+ }
+ throw new IllegalStateException("Database engine has not initialized properly.");
+ }
+
+ public static void init(DataSourceConfig config) {
+ dataSource = resolveDataSource(config);
+ try {
+ databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
+ } catch (SQLException e) {
+ log.error("Error occurred while retrieving config.datasource connection", e);
+ }
+ }
+
+ public static void init(DataSource dtSource) {
+ dataSource = dtSource;
+ try {
+ databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName();
+ } catch (SQLException e) {
+ log.error("Error occurred while retrieving config.datasource connection", e);
+ }
+ }
+
+ public static void beginTransaction() throws TransactionManagementException {
+ Connection conn = currentConnection.get();
+ if (conn != null) {
+ throw new IllegalTransactionStateException("A transaction is already active within the context of " +
+ "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " +
+ "transaction is already active is a sign of improper transaction handling");
+ }
+ try {
+ conn = dataSource.getConnection();
+ conn.setAutoCommit(false);
+ currentConnection.set(conn);
+ } catch (SQLException e) {
+ throw new TransactionManagementException("Error occurred while retrieving config.datasource connection", e);
+ }
+ }
+
+ public static void openConnection() throws SQLException {
+ Connection conn = currentConnection.get();
+ if (conn != null) {
+ throw new IllegalTransactionStateException("A transaction is already active within the context of " +
+ "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " +
+ "transaction is already active is a sign of improper transaction handling");
+ }
+ conn = dataSource.getConnection();
+ currentConnection.set(conn);
+ }
+
+ public static Connection getConnection() throws SQLException {
+ Connection conn = currentConnection.get();
+ if (conn == null) {
+ throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
+ "This might have ideally been caused by not properly initiating the transaction via " +
+ "'beginTransaction'/'openConnection' methods");
+ }
+ return conn;
+ }
+
+ public static void commitTransaction() {
+ Connection conn = currentConnection.get();
+ if (conn == null) {
+ throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
+ "This might have ideally been caused by not properly initiating the transaction via " +
+ "'beginTransaction'/'openConnection' methods");
+ }
+ try {
+ conn.commit();
+ } catch (SQLException e) {
+ log.error("Error occurred while committing the transaction", e);
+ }
+ }
+
+ public static void rollbackTransaction() {
+ Connection conn = currentConnection.get();
+ if (conn == null) {
+ throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
+ "This might have ideally been caused by not properly initiating the transaction via " +
+ "'beginTransaction'/'openConnection' methods");
+ }
+ try {
+ conn.rollback();
+ } catch (SQLException e) {
+ log.warn("Error occurred while roll-backing the transaction", e);
+ }
+ }
+
+ public static void closeConnection() {
+ Connection conn = currentConnection.get();
+ if (conn == null) {
+ throw new IllegalTransactionStateException("No connection is associated with the current transaction. " +
+ "This might have ideally been caused by not properly initiating the transaction via " +
+ "'beginTransaction'/'openConnection' methods");
+ }
+ try {
+ conn.close();
+ } catch (SQLException e) {
+ log.warn("Error occurred while close the connection");
+ }
+ currentConnection.remove();
+ }
+
+
+ /**
+ * Resolve data source from the data source definition
+ *
+ * @param config data source configuration
+ * @return data source resolved from the data source definition
+ */
+ private static DataSource resolveDataSource(DataSourceConfig config) {
+ DataSource dataSource = null;
+ if (config == null) {
+ throw new RuntimeException(
+ "Device Management Repository data source configuration " + "is null and " +
+ "thus, is not initialized");
+ }
+ io.entgra.task.mgt.core.config.datasource.JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition();
+ if (jndiConfig != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("Initializing Device Management Repository data source using the JNDI " +
+ "Lookup Definition");
+ }
+ List jndiPropertyList =
+ jndiConfig.getJndiProperties();
+ if (jndiPropertyList != null) {
+ Hashtable