From 7616c2255c054e21a10f4f85ced02513f94ab385 Mon Sep 17 00:00:00 2001 From: ashvini Date: Wed, 29 May 2024 12:44:59 +0530 Subject: [PATCH 1/4] Add filter to get Web apps in Enrollment Application Install Add filter file --- .../mgt/core/application/mgt/common/Filter.java | 13 +++++++++++++ .../impl/application/GenericApplicationDAOImpl.java | 12 ++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/Filter.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/Filter.java index 272e9ba8a3..88f7e90a0a 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/Filter.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/Filter.java @@ -118,6 +118,11 @@ public class Filter { */ private boolean isNotRetired; + /** + * To check whether web applications should be returned + */ + private boolean withWebApps; + public int getLimit() { return limit; } @@ -221,4 +226,12 @@ public class Filter { public void setNotRetired(boolean notRetired) { isNotRetired = notRetired; } + + public boolean isWithWebApps() { + return withWebApps; + } + + public void setWithWebApps(boolean withWebApps) { + this.withWebApps = withWebApps; + } } diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index 7c71880fa6..618149cd72 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -178,7 +178,11 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic sql += "AND AP_APP_RELEASE.CURRENT_STATE = ? "; } if (deviceTypeId != -1) { - sql += "AND AP_APP.DEVICE_TYPE_ID = ? "; + sql += "AND (AP_APP.DEVICE_TYPE_ID = ? "; + if (filter.isWithWebApps()) { + sql += "OR AP_APP.DEVICE_TYPE_ID = 0 "; + } + sql += ") "; } if (filter.isNotRetired()) { sql += "AND AP_APP.STATUS != 'RETIRED' "; @@ -309,7 +313,11 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic sql += " AND AP_APP_RELEASE.CURRENT_STATE = ?"; } if (deviceTypeId != -1) { - sql += " AND AP_APP.DEVICE_TYPE_ID = ?"; + sql += "AND (AP_APP.DEVICE_TYPE_ID = ? "; + if (filter.isWithWebApps()) { + sql += "OR AP_APP.DEVICE_TYPE_ID = 0 "; + } + sql += ") "; } if (filter.isNotRetired()) { sql += " AND AP_APP.STATUS != 'RETIRED'"; From 641ddbfb85c8f3b8cdcfeba30d423502c087b80f Mon Sep 17 00:00:00 2001 From: pramilaniroshan Date: Thu, 6 Jun 2024 09:50:27 +0530 Subject: [PATCH 2/4] Fix sql syntax errors --- .../jaxrs/service/impl/GroupManagementServiceImpl.java | 2 +- .../device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java | 7 +++---- .../device/mgt/core/dao/impl/AbstractGroupDAOImpl.java | 8 ++++---- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GroupManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GroupManagementServiceImpl.java index fc8f080b07..e8c56680b1 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GroupManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GroupManagementServiceImpl.java @@ -273,7 +273,7 @@ public class GroupManagementServiceImpl implements GroupManagementService { ); return Response.status(Response.Status.OK).build(); } catch (GroupManagementException e) { - String msg = "Error occurred while adding new group."; + String msg = "Error occurred while updating group. "; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } catch (GroupNotExistException e) { 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/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index 7ab1cdb6e3..e95183d8c3 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -176,7 +176,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { + "d.DESCRIPTION, " + "d.NAME, " + "d.LAST_UPDATED_TIMESTAMP " - + "FROM DM_DEVICE d" + + "FROM DM_DEVICE d WHERE " + "d.DEVICE_IDENTIFICATION = ? AND " + "d.TENANT_ID = ?"; @@ -197,7 +197,6 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { try (PreparedStatement stmt = conn.prepareStatement(sql)) { int paramIndx = 1; - stmt.setString(paramIndx++, deviceData.getDeviceIdentifier().getType()); stmt.setString(paramIndx++, deviceData.getDeviceIdentifier().getId()); stmt.setInt(paramIndx++, tenantId); if (deviceData.getLastModifiedDate() != null) { @@ -964,12 +963,12 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { + "d.NAME AS DEVICE_NAME, " + "d.DEVICE_IDENTIFICATION, " + "d.LAST_UPDATED_TIMESTAMP, " - + "e.DEVICE_TYPE " + + "e1.DEVICE_TYPE " + "FROM " + "DM_DEVICE d, " + "(SELECT " + "e.OWNER, " - + "e.DEVICE_TYPE " + + "e.DEVICE_TYPE, " + "e.OWNERSHIP, " + "e.ID AS ENROLMENT_ID, " + "e.DEVICE_ID, " 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/dao/impl/AbstractGroupDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java index 374c1ca0aa..c65692870d 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java @@ -1282,8 +1282,8 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { StringJoiner joiner = new StringJoiner(",","SELECT " + "d1.DEVICE_ID, " + "d1.DESCRIPTION, " - + "e.DEVICE_NAME, " - + "d1.DEVICE_TYPE, " + + "d1.NAME AS DEVICE_NAME, " + + "e.DEVICE_TYPE, " + "d1.DEVICE_IDENTIFICATION, " + "d1.LAST_UPDATED_TIMESTAMP, " + "e.OWNER, " @@ -1343,8 +1343,8 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { String sql = "SELECT " + "d1.DEVICE_ID, " + "d1.DESCRIPTION, " - + "e.DEVICE_NAME, " - + "d1.DEVICE_TYPE, " + + "d1.NAME AS DEVICE_NAME, " + + "e.DEVICE_TYPE, " + "d1.DEVICE_IDENTIFICATION, " + "d1.LAST_UPDATED_TIMESTAMP, " + "e.OWNER, " From f0c48c585de2311dd71cae55e46164b77645158d Mon Sep 17 00:00:00 2001 From: pramilaniroshan Date: Fri, 7 Jun 2024 13:04:51 +0530 Subject: [PATCH 3/4] Fix sql syntax errors --- .../mgt/core/dao/impl/AbstractDeviceDAOImpl.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) 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/dao/impl/AbstractDeviceDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java index e95183d8c3..58bfed7d4a 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java @@ -1036,12 +1036,12 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { "(SELECT gd.DEVICE_ID, " + "gd.DESCRIPTION, " + "gd.NAME, " + - "gd.DEVICE_IDENTIFICATION, " + + "gd.DEVICE_IDENTIFICATION " + "FROM " + "(SELECT d.ID AS DEVICE_ID, " + "d.DESCRIPTION, " + "d.NAME, " + - "d.DEVICE_IDENTIFICATION, " + + "d.DEVICE_IDENTIFICATION " + "FROM DM_DEVICE d, " + "(SELECT dgm.DEVICE_ID " + "FROM DM_DEVICE_GROUP_MAP dgm " + @@ -2365,7 +2365,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { "e.device_id," + "e.status, " + "e.date_of_last_update, " + - "e.date_of_enrolment " + + "e.date_of_enrolment, " + "e.DEVICE_TYPE " + "FROM dm_enrolment e " + "INNER JOIN " + @@ -2375,7 +2375,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { "KEY_FIELD = 'encryptionEnabled' " + "AND VALUE_FIELD = ?) AS di " + "ON di.DEVICE_ID = e.DEVICE_ID " + - "WHERE e.tenant_id = ?) e1, " + + "WHERE e.tenant_id = ?) e1 " + "WHERE d.id = e1.device_id " + "ORDER BY e1.date_of_last_update DESC " + "LIMIT ? OFFSET ?"; @@ -2409,7 +2409,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { try { Connection conn = getConnection(); String sql = - "SELECT COUNT(DEVICE_ID) " + + "SELECT COUNT(DEVICE_ID) AS DEVICE_COUNT " + "FROM DM_DEVICE_INFO " + "WHERE KEY_FIELD = 'encryptionEnabled' " + "AND VALUE_FIELD = ?"; @@ -2417,7 +2417,6 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { try (PreparedStatement ps = conn.prepareStatement(sql)) { ps.setBoolean(1, isEncrypted); - ps.setInt(2, tenantId); try (ResultSet rs = ps.executeQuery()) { return rs.next() ? rs.getInt("DEVICE_COUNT") : 0; From b0362c58256ed0a3a1c6d8a7d9d456e9190a3c91 Mon Sep 17 00:00:00 2001 From: prathabanKavin Date: Fri, 7 Jun 2024 21:57:21 +0530 Subject: [PATCH 4/4] Fix devices of a group not loading --- .../mgt/core/dao/impl/device/GenericDeviceDAOImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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/dao/impl/device/GenericDeviceDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java index efe07d1335..d1ea236645 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/device/GenericDeviceDAOImpl.java @@ -646,8 +646,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { } @Override - public List searchDevicesInGroup(PaginationRequest request, int tenantId) - throws DeviceManagementDAOException { + public List searchDevicesInGroup(PaginationRequest request, int tenantId) throws DeviceManagementDAOException { List devices = null; int groupId = request.getGroupId(); String deviceType = request.getDeviceType(); @@ -687,6 +686,7 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { "gd.DESCRIPTION, " + "gd.NAME, " + "gd.DEVICE_IDENTIFICATION, " + + "gd.LAST_UPDATED_TIMESTAMP " + "FROM " + "(SELECT d.ID AS DEVICE_ID, " + "d.DESCRIPTION, " + @@ -708,10 +708,10 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl { sql = sql + " WHERE 1 = 1"; //Add query for last updated timestamp if (since != null) { - sql = sql + " AND d.LAST_UPDATED_TIMESTAMP > ?"; + sql = sql + " AND gd.LAST_UPDATED_TIMESTAMP > ?"; isSinceProvided = true; } - sql = sql + " ) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? "; + sql = sql + " ) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND e.TENANT_ID = ? "; //Add the query for device-type if (deviceType != null && !deviceType.isEmpty()) { sql = sql + " AND e.DEVICE_TYPE = ?";