diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java index 5a12769beac..cfef55c428d 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/CommandOperationDAOImpl.java @@ -20,6 +20,7 @@ package io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUtil; import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.CommandOperation; import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation; @@ -46,7 +47,7 @@ public class CommandOperationDAOImpl extends GenericOperationDAOImpl { try { Connection connection = OperationManagementDAOFactory.getConnection(); String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " + - "INITIATED_BY, ENABLED) VALUES (?, ?, ?, ?, ?, ?)"; + "INITIATED_BY, ENABLED, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?, ?)"; stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt.setString(1, operation.getType().toString()); stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime()); @@ -54,6 +55,7 @@ public class CommandOperationDAOImpl extends GenericOperationDAOImpl { stmt.setString(4, operation.getCode()); stmt.setString(5, operation.getInitiatedBy()); stmt.setBoolean(6, operation.isEnabled()); + stmt.setInt(7, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); stmt.executeUpdate(); rs = stmt.getGeneratedKeys(); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java index 9e19b5b5d88..3d7ceeaa18a 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java @@ -20,6 +20,7 @@ package io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUtil; import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.ConfigOperation; import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation; @@ -49,7 +50,7 @@ public class ConfigOperationDAOImpl extends GenericOperationDAOImpl { operation.setCreatedTimeStamp(new Timestamp(new Date().getTime()).toString()); Connection connection = OperationManagementDAOFactory.getConnection(); String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " + - "INITIATED_BY, OPERATION_DETAILS) VALUES (?, ?, ?, ?, ?, ?)"; + "INITIATED_BY, OPERATION_DETAILS, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?, ?)"; stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt.setString(1, operation.getType().toString()); stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime()); @@ -57,6 +58,7 @@ public class ConfigOperationDAOImpl extends GenericOperationDAOImpl { stmt.setString(4, operation.getCode()); stmt.setString(5, operation.getInitiatedBy()); stmt.setObject(6, operation); + stmt.setInt(7, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); stmt.executeUpdate(); rs = stmt.getGeneratedKeys(); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index fa831c317a8..5d964d4a53f 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -74,7 +74,7 @@ public class GenericOperationDAOImpl implements OperationDAO { try { Connection connection = OperationManagementDAOFactory.getConnection(); String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " + - "INITIATED_BY, OPERATION_DETAILS) VALUES (?, ?, ?, ?, ?, ?)"; + "INITIATED_BY, OPERATION_DETAILS, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?, ?)"; stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt.setString(1, operation.getType().toString()); stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime()); @@ -82,6 +82,7 @@ public class GenericOperationDAOImpl implements OperationDAO { stmt.setString(4, operation.getCode()); stmt.setString(5, operation.getInitiatedBy()); stmt.setObject(6, operation); + stmt.setInt(7, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); stmt.executeUpdate(); rs = stmt.getGeneratedKeys(); @@ -2281,7 +2282,7 @@ public class GenericOperationDAOImpl implements OperationDAO { sql.append("AND INITIATED_BY = ? "); } - sql.append("ORDER BY ID ASC ) dm_ordered " + + sql.append("ORDER BY ID ASC limit ? , ? ) dm_ordered " + "ON dm_ordered.OPERATION_ID = eom.OPERATION_ID WHERE eom.TENANT_ID = ? "); } @@ -2384,7 +2385,8 @@ public class GenericOperationDAOImpl implements OperationDAO { if (activityPaginationRequest.getInitiatedBy() != null) { stmt.setString(index++, activityPaginationRequest.getInitiatedBy()); } - + stmt.setInt(index++, activityPaginationRequest.getOffset()); + stmt.setInt(index++, activityPaginationRequest.getLimit()); stmt.setInt(index++, tenantId); if (activityPaginationRequest.getDeviceType() != null) { diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java index b8a1b135a39..bd4d74386ad 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/PolicyOperationDAOImpl.java @@ -19,6 +19,7 @@ package io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUtil; import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation; import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.PolicyOperation; @@ -49,7 +50,7 @@ public class PolicyOperationDAOImpl extends GenericOperationDAOImpl { operation.setEnabled(true); Connection connection = OperationManagementDAOFactory.getConnection(); String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " + - "INITIATED_BY, OPERATION_DETAILS, ENABLED) VALUES (?, ?, ?, ?, ?, ?, ?)"; + "INITIATED_BY, OPERATION_DETAILS, ENABLED, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt.setString(1, operation.getType().toString()); stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime()); @@ -63,6 +64,7 @@ public class PolicyOperationDAOImpl extends GenericOperationDAOImpl { stmt.setBytes(6, bao.toByteArray()); stmt.setBoolean(7, operation.isEnabled()); + stmt.setInt(8, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); stmt.executeUpdate(); rs = stmt.getGeneratedKeys(); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java index e972afba65c..93b25f47dcb 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/ProfileOperationDAOImpl.java @@ -19,6 +19,7 @@ package io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUtil; import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation; import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.ProfileOperation; @@ -46,7 +47,7 @@ public class ProfileOperationDAOImpl extends GenericOperationDAOImpl { operation.setEnabled(true); Connection connection = OperationManagementDAOFactory.getConnection(); String sql = "INSERT INTO DM_OPERATION(TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, " + - "INITIATED_BY, OPERATION_DETAILS, ENABLED) VALUES (?, ?, ?, ?, ?, ?, ?)"; + "INITIATED_BY, OPERATION_DETAILS, ENABLED, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; stmt = connection.prepareStatement(sql, new String[]{"id"}); stmt.setString(1, operation.getType().toString()); stmt.setLong(2, DeviceManagementDAOUtil.getCurrentUTCTime()); @@ -60,6 +61,7 @@ public class ProfileOperationDAOImpl extends GenericOperationDAOImpl { stmt.setBytes(6, bao.toByteArray()); stmt.setBoolean(7, operation.isEnabled()); + stmt.setInt(8, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); stmt.executeUpdate(); rs = stmt.getGeneratedKeys(); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/resources/sql/h2.sql index 4f83fa5b5ed..664eb333d13 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/resources/sql/h2.sql +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/resources/sql/h2.sql @@ -82,6 +82,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION ( INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS BLOB DEFAULT NULL, ENABLED BOOLEAN NOT NULL DEFAULT FALSE, + TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ID) ); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.extensions/src/test/resources/sql-files/h2.sql b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.extensions/src/test/resources/sql-files/h2.sql index 2b2200bb2bd..b282aa59ce0 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.extensions/src/test/resources/sql-files/h2.sql +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.extensions/src/test/resources/sql-files/h2.sql @@ -68,6 +68,10 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION ( CREATED_TIMESTAMP BIGINT NOT NULL, RECEIVED_TIMESTAMP BIGINT NULL, OPERATION_CODE VARCHAR(1000) NOT NULL, + INITIATED_BY VARCHAR(100) NULL, + OPERATION_DETAILS BLOB DEFAULT NULL, + ENABLED BOOLEAN NOT NULL DEFAULT FALSE, + TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ID) ); diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql index 60521565889..c2f33227b7f 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql @@ -90,6 +90,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION ( INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS BLOB DEFAULT NULL, ENABLED BOOLEAN NOT NULL DEFAULT FALSE, + TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ID) ); diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql index f5a25e36a21..2570e7dd7fb 100644 --- a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql +++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql @@ -90,6 +90,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION ( INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS BLOB DEFAULT NULL, ENABLED BOOLEAN NOT NULL DEFAULT FALSE, + TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ID) ); diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql index 40ad63072f6..295433b55c1 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql @@ -90,6 +90,7 @@ CREATE TABLE IF NOT EXISTS DM_OPERATION ( INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS BLOB DEFAULT NULL, ENABLED BOOLEAN NOT NULL DEFAULT FALSE, + TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ID) );