diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 9cd1bda1ca6..705328d96a4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -18,6 +18,7 @@ */ package org.wso2.carbon.device.mgt.jaxrs.service.impl; +import com.google.gson.JsonArray; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.CarbonContext; @@ -127,8 +128,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { request.setSince(sinceDate); result = dms.getAllDevices(request); if (result == null || result.getData() == null || result.getData().size() <= 0) { - return Response.status(Response.Status.OK).entity("No device is modified " + - "after the timestamp provided in 'since' filter").build(); + return Response.status(Response.Status.OK).entity(new JsonArray()).build(); } } else { result = dms.getAllDevices(request); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index 44bdd5ba454..1ecdb88459b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -416,12 +416,23 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { boolean isOwnershipProvided = false; String status = request.getStatus(); boolean isStatusProvided = false; + Date since = request.getSince(); + boolean isSinceProvided = false; try { conn = this.getConnection(); String sql = "SELECT COUNT(d1.ID) AS DEVICE_COUNT FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, d.DEVICE_IDENTIFICATION, " + - "t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID " + - "AND d.TENANT_ID = ?"; + "t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t"; + //Add query for last updated timestamp + if (since != null) { + sql = sql + " , DM_DEVICE_DETAIL dt"; + isSinceProvided = true; + } + sql = sql + " WHERE DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?"; + //Add query for last updated timestamp + if (isSinceProvided) { + sql = sql + " AND dt.DEVICE_ID = d.ID AND dt.UPDATE_TIMESTAMP > ?"; + } if (deviceType != null && !deviceType.isEmpty()) { sql = sql + " AND t.NAME = ?"; isDeviceTypeProvided = true; @@ -452,12 +463,16 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); int paramIdx = 2; + if (isSinceProvided) { + stmt.setLong(paramIdx++, since.getTime()); + } if (isDeviceTypeProvided) { stmt.setString(paramIdx++, request.getDeviceType()); } if (isDeviceNameProvided) { stmt.setString(paramIdx++, request.getDeviceName() + "%"); } + stmt.setInt(paramIdx++, tenantId); if (isOwnershipProvided) { stmt.setString(paramIdx++, request.getOwnership()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java index 246a1bc1f38..b60072be2ac 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java @@ -59,8 +59,21 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " + "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, " + - "d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t " + - "WHERE DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?"; + "d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE " + + "FROM DM_DEVICE d, DM_DEVICE_TYPE t "; + + //Add the query to filter active devices on timestamp + if (since != null) { + sql = sql + ", DM_DEVICE_DETAIL dt"; + isSinceProvided = true; + } + + sql = sql + " WHERE DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?"; + + //Add query for last updated timestamp + if (isSinceProvided) { + sql = sql + " AND dt.DEVICE_ID = d.ID AND dt.UPDATE_TIMESTAMP > ?"; + } //Add the query for device-type if (deviceType != null && !deviceType.isEmpty()) { @@ -73,12 +86,6 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { isDeviceNameProvided = true; } - //Add query for last updated timestamp - if (since != null) { - sql = sql + " AND d.LAST_UPDATED_TIMESTAMP > ?"; - isSinceProvided = true; - } - sql = sql + ") d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?"; //Add the query for ownership @@ -102,15 +109,16 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); int paramIdx = 2; + if (isSinceProvided) { + stmt.setLong(paramIdx++, since.getTime()); + } if (isDeviceTypeProvided) { stmt.setString(paramIdx++, request.getDeviceType()); } if (isDeviceNameProvided) { stmt.setString(paramIdx++, request.getDeviceName() + "%"); } - if (isSinceProvided) { - stmt.setTimestamp(paramIdx++, new Timestamp(since.getTime())); - } + stmt.setInt(paramIdx++, tenantId); if (isOwnershipProvided) { stmt.setString(paramIdx++, request.getOwnership()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 4cebea71953..04a7d71322a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -102,7 +102,7 @@ public class OperationManagerImpl implements OperationManager { DeviceIDHolder deviceIDHolder = DeviceManagerUtil.validateDeviceIdentifiers(deviceIds); List validDeviceIds = deviceIDHolder.getValidDeviceIDList(); if (validDeviceIds.size() > 0) { - List authorizedDeviceList = this.getAuthorizedDevices(operation, deviceIds); + List authorizedDeviceList = this.getAuthorizedDevices(operation, validDeviceIds); if (authorizedDeviceList.size() <= 0) { log.info("User : " + getUser() + " is not authorized to perform operations on given device-list."); return null; @@ -123,7 +123,7 @@ public class OperationManagerImpl implements OperationManager { //TODO have to create a sql to load device details from deviceDAO using single query. String operationCode = operationDto.getCode(); - for (DeviceIdentifier deviceId : deviceIds) { + for (DeviceIdentifier deviceId : authorizedDeviceList) { Device device = getDevice(deviceId); enrolmentId = device.getEnrolmentInfo().getId(); //Do not repeat the task operations diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/layouts/cdmf.layout.default.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/layouts/cdmf.layout.default.hbs index e4e75b3bd0b..57f7736618e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/layouts/cdmf.layout.default.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/layouts/cdmf.layout.default.hbs @@ -58,8 +58,10 @@ under the License. --}}
{{defineZone "contentTitle"}} -
- {{defineZone "content"}} +
+
+ {{defineZone "content"}} +
diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in/sign-in.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in/sign-in.hbs index 1b839d3cdb6..7961b2b65bd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in/sign-in.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.sign-in/sign-in.hbs @@ -19,38 +19,40 @@ {{unit "cdmf.unit.ui.title" pageTitle="Login"}} {{#zone "content"}} -