From f3aefcca77520111e985ae545f99938408030b4f Mon Sep 17 00:00:00 2001 From: harshanl Date: Tue, 23 Aug 2016 17:57:08 +0530 Subject: [PATCH 1/7] Fixed EMM-1450 --- .../mgt/jaxrs/service/impl/UserManagementServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java index 0be452585f..6df497f8c1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java @@ -268,7 +268,7 @@ public class UserManagementServiceImpl implements UserManagementService { RequestValidationUtil.validatePaginationParameters(offset, limit); List userList, offsetList; - String appliedFilter = ((filter == null) || filter.isEmpty() ? "*" : filter); + String appliedFilter = ((filter == null) || filter.isEmpty() ? "*" : filter + "*"); // to get whole set of users, appliedLimit is set to -1 // by default, this whole set is limited to 100 - MaxUserNameListLength of user-mgt.xml int appliedLimit = -1; @@ -277,7 +277,7 @@ public class UserManagementServiceImpl implements UserManagementService { UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); //As the listUsers function accepts limit only to accommodate offset we are passing offset + limit - String[] users = userStoreManager.listUsers(appliedFilter + "*", appliedLimit); + String[] users = userStoreManager.listUsers(appliedFilter, appliedLimit); userList = new ArrayList<>(users.length); BasicUserInfo user; for (String username : users) { From 556c82b2e8f45af6faa79fe7a81f404e6562e965 Mon Sep 17 00:00:00 2001 From: harshanl Date: Tue, 23 Aug 2016 17:59:52 +0530 Subject: [PATCH 2/7] Fixed ORACLE DB script issue --- .../src/main/resources/dbscripts/cdm/oracle.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index 0b1256d5ee..8c98587ffe 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -7,16 +7,16 @@ CREATE TABLE DM_DEVICE_TYPE ( ) / -- Generate ID using sequence and trigger -CREATE SEQUENCE DM_DEVICE_TYPE_seq START WITH 1 INCREMENT BY 1 NOCACHE +CREATE SEQUENCE DM_DEVICE_TYPE_id_seq START WITH 1 INCREMENT BY 1 NOCACHE / -CREATE OR REPLACE TRIGGER DM_DEVICE_TYPE_seq_tr +CREATE OR REPLACE TRIGGER DM_DEVICE_TYPE_id_seq_tr BEFORE INSERT ON DM_DEVICE_TYPE REFERENCING NEW AS NEW FOR EACH ROW WHEN (NEW.ID IS NULL) BEGIN - SELECT DM_DEVICE_TYPE_seq.NEXTVAL INTO :NEW.ID FROM DUAL; + SELECT DM_DEVICE_TYPE_id_seq.NEXTVAL INTO :NEW.ID FROM DUAL; END; / From a72b47f6f7df81182c64937ba7378e64bb620b81 Mon Sep 17 00:00:00 2001 From: Saad Sahibjan Date: Wed, 24 Aug 2016 19:18:35 +0530 Subject: [PATCH 3/7] Fixing incorrect response for remove policy --- .../impl/PolicyManagementServiceImpl.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java index f2aeae680d..109bb189d4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/PolicyManagementServiceImpl.java @@ -221,14 +221,22 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { RequestValidationUtil.validatePolicyIds(policyIds); PolicyManagerService policyManagementService = DeviceMgtAPIUtils.getPolicyManagementService(); boolean policyDeleted = true; + String invalidPolicyIds = ""; try { PolicyAdministratorPoint pap = policyManagementService.getPAP(); for (int i : policyIds) { Policy policy = pap.getPolicy(i); - if (policy == null || !pap.deletePolicy(policy)) { + if (policy == null) { + invalidPolicyIds += i + ","; policyDeleted = false; } } + if(policyDeleted) { + for(int i : policyIds) { + Policy policy = pap.getPolicy(i); + pap.deletePolicy(policy); + } + } } catch (PolicyManagementException e) { String msg = "ErrorResponse occurred while removing policies"; log.error(msg, e); @@ -239,8 +247,10 @@ public class PolicyManagementServiceImpl implements PolicyManagementService { return Response.status(Response.Status.OK).entity("Policies have been successfully deleted").build(); } else { //TODO:Check of this logic is correct - return Response.status(Response.Status.NOT_FOUND).entity( - new ErrorResponse.ErrorResponseBuilder().setMessage("Policy doesn't exist").build()).build(); + String ModifiedInvalidPolicyIds = invalidPolicyIds.substring(0, invalidPolicyIds.length()-1); + return Response.status(Response.Status.BAD_REQUEST).entity( + new ErrorResponse.ErrorResponseBuilder().setMessage("Policies with the policy ID " + + ModifiedInvalidPolicyIds + " doesn't exist").build()).build(); } } From 16e6e124369ebd05ed9aee224bfe86c57fc8b1a5 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Perera Date: Thu, 25 Aug 2016 11:53:29 +0530 Subject: [PATCH 4/7] Fixed issue in Activity API returning one activity --- .../core/operation/mgt/dao/impl/GenericOperationDAOImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index 36bdfd738a..afd6c774b0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -420,7 +420,8 @@ public class GenericOperationDAOImpl implements OperationDAO { "ON feom.OPERATION_ID = o.ID LEFT OUTER JOIN (SELECT ID, ENROLMENT_ID, OPERATION_ID, " + "OPERATION_RESPONSE, MAX(RECEIVED_TIMESTAMP) LATEST_RECEIVED_TIMESTAMP " + "FROM DM_DEVICE_OPERATION_RESPONSE GROUP BY ENROLMENT_ID , OPERATION_ID) orsp " + - "ON o.ID = orsp.OPERATION_ID AND feom.ENROLMENT_ID = orsp.ENROLMENT_ID GROUP BY feom.ENROLMENT_ID"; + "ON o.ID = orsp.OPERATION_ID AND feom.ENROLMENT_ID = orsp.ENROLMENT_ID GROUP BY feom.ENROLMENT_ID, " + + "feom.OPERATION_ID"; stmt = conn.prepareStatement(sql); From 9246cdcf30839359a9e15625a9ceee9c226b7d07 Mon Sep 17 00:00:00 2001 From: charitha Date: Thu, 25 Aug 2016 12:28:55 +0530 Subject: [PATCH 5/7] Return empty array when results not found with since parameter --- .../mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 9cd1bda1ca..705328d96a 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); From 579d91bd79f3e305adb0d774c3bd48f858a7cb06 Mon Sep 17 00:00:00 2001 From: charitha Date: Thu, 25 Aug 2016 13:10:23 +0530 Subject: [PATCH 6/7] Fix issue in get devices with since parameter. --- .../mgt/core/dao/impl/AbstractDeviceDAOImpl.java | 15 +++++++++++++-- .../dao/impl/device/GenericDeviceDAOImpl.java | 9 +++++---- 2 files changed, 18 insertions(+), 6 deletions(-) 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 44bdd5ba45..6ca4378806 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,11 +416,13 @@ 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, DM_DEVICE_DETAIL dt WHERE DEVICE_TYPE_ID = t.ID " + + "AND d.TENANT_ID = ? AND dt.DEVICE_ID = d.ID"; if (deviceType != null && !deviceType.isEmpty()) { sql = sql + " AND t.NAME = ?"; @@ -432,6 +434,12 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { isDeviceNameProvided = true; } + //Add query for last updated timestamp + if (since != null) { + sql = sql + " AND dt.UPDATE_TIMESTAMP > ?"; + isSinceProvided = true; + } + sql = sql + ") d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?"; if (ownership != null && !ownership.isEmpty()) { @@ -458,6 +466,9 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { if (isDeviceNameProvided) { stmt.setString(paramIdx++, request.getDeviceName() + "%"); } + if (isSinceProvided) { + stmt.setLong(paramIdx++, 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/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 246a1bc1f3..2c47c600d5 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,9 @@ 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, DM_DEVICE_DETAIL dt " + + "WHERE DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ? AND dt.DEVICE_ID = d.ID"; //Add the query for device-type if (deviceType != null && !deviceType.isEmpty()) { @@ -75,7 +76,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { //Add query for last updated timestamp if (since != null) { - sql = sql + " AND d.LAST_UPDATED_TIMESTAMP > ?"; + sql = sql + " AND dt.UPDATE_TIMESTAMP > ?"; isSinceProvided = true; } @@ -109,7 +110,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { stmt.setString(paramIdx++, request.getDeviceName() + "%"); } if (isSinceProvided) { - stmt.setTimestamp(paramIdx++, new Timestamp(since.getTime())); + stmt.setLong(paramIdx++, since.getTime()); } stmt.setInt(paramIdx++, tenantId); if (isOwnershipProvided) { From 811d225bc3c0295b5aaf610be0ddd4af6e04a78c Mon Sep 17 00:00:00 2001 From: harshanl Date: Thu, 25 Aug 2016 13:58:38 +0530 Subject: [PATCH 7/7] Fixed adding operations to invalid devices --- .../device/mgt/core/operation/mgt/OperationManagerImpl.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 4cebea7195..04a7d71322 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