From 539e814e2d7e7e3438cadab07899b0b585c6ae2e Mon Sep 17 00:00:00 2001 From: shamalka Date: Thu, 7 May 2020 22:13:52 +0530 Subject: [PATCH 1/8] Change getEnrollmentQRCode method return type --- .../mgt/common/QREnrollmentPayload.java | 39 +++++++++++++++++++ .../common/spi/DeviceTypeCommonService.java | 3 +- 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/QREnrollmentPayload.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/QREnrollmentPayload.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/QREnrollmentPayload.java new file mode 100644 index 00000000000..ce6b725920a --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/QREnrollmentPayload.java @@ -0,0 +1,39 @@ +package org.wso2.carbon.device.mgt.common; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +/** + * This class represents the information of QR enrollment payload. + */ +@ApiModel(value = "QREnrollmentPayload", + description = "Details related to QR enrollment to generate QR code.") +public class QREnrollmentPayload implements Serializable { + + @ApiModelProperty(name = "payload", value = "Platform configuration payload to generate QR code.", required = true) + private Map payload; + + @ApiModelProperty(name = "invalidPlatformConfigs", value = "Invalid platform configs to show when an " + + "invalidation occurs.", required = true) + private List invalidPlatformConfigs; + + public Map getPayload() { + return payload; + } + + public void setPayload(Map payload) { + this.payload = payload; + } + + public List getInvalidPlatformConfigs() { + return invalidPlatformConfigs; + } + + public void setInvalidPlatformConfigs(List invalidPlatformConfigs) { + this.invalidPlatformConfigs = invalidPlatformConfigs; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceTypeCommonService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceTypeCommonService.java index 7b324a565f8..5ab616ffcd6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceTypeCommonService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceTypeCommonService.java @@ -17,6 +17,7 @@ package org.wso2.carbon.device.mgt.common.spi; +import org.wso2.carbon.device.mgt.common.QREnrollmentPayload; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import java.util.Map; @@ -32,5 +33,5 @@ public interface DeviceTypeCommonService { * @return QR code Map which contains key value pairs to have for the QR String. * @throws DeviceManagementException if error occurred while generating the QR String for Ownership */ - Map getEnrollmentQRCode(String ownershipType) throws DeviceManagementException; + QREnrollmentPayload getEnrollmentQRCode(String ownershipType) throws DeviceManagementException; } From dcb1602752d11ef9e73680db15ff7a63d95c8e9b Mon Sep 17 00:00:00 2001 From: shamalka Date: Thu, 7 May 2020 22:21:38 +0530 Subject: [PATCH 2/8] Add license --- .../device/mgt/common/QREnrollmentPayload.java | 18 ++++++++++++++++++ .../common/spi/DeviceTypeCommonService.java | 2 -- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/QREnrollmentPayload.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/QREnrollmentPayload.java index ce6b725920a..831e4ad836d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/QREnrollmentPayload.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/QREnrollmentPayload.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2020, Entgra (Pvt) Ltd. (http://www.entgra.io) 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 org.wso2.carbon.device.mgt.common; import io.swagger.annotations.ApiModel; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceTypeCommonService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceTypeCommonService.java index 5ab616ffcd6..377c9b91e7f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceTypeCommonService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceTypeCommonService.java @@ -20,8 +20,6 @@ package org.wso2.carbon.device.mgt.common.spi; import org.wso2.carbon.device.mgt.common.QREnrollmentPayload; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; -import java.util.Map; - /** * This implementation populates device type plugin management service. */ From 756d73d2cf06426ee0268a28ca4909a6eba3f613 Mon Sep 17 00:00:00 2001 From: shamalka Date: Mon, 11 May 2020 13:35:39 +0530 Subject: [PATCH 3/8] Add optional platform configs --- .../device/mgt/common/QREnrollmentPayload.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/QREnrollmentPayload.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/QREnrollmentPayload.java index 831e4ad836d..600493ba8de 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/QREnrollmentPayload.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/QREnrollmentPayload.java @@ -39,6 +39,10 @@ public class QREnrollmentPayload implements Serializable { "invalidation occurs.", required = true) private List invalidPlatformConfigs; + @ApiModelProperty(name = "optionalPlatformConfigs", value = "Optional platform configs to show when an " + + "values are not set.") + private List optionalPlatformConfigs; + public Map getPayload() { return payload; } @@ -54,4 +58,12 @@ public class QREnrollmentPayload implements Serializable { public void setInvalidPlatformConfigs(List invalidPlatformConfigs) { this.invalidPlatformConfigs = invalidPlatformConfigs; } + + public List getOptionalPlatformConfigs() { + return optionalPlatformConfigs; + } + + public void setOptionalPlatformConfigs(List optionalPlatformConfigs) { + this.optionalPlatformConfigs = optionalPlatformConfigs; + } } From 240f157565366c2687a1d7283bb0261769a40790 Mon Sep 17 00:00:00 2001 From: shamalka Date: Mon, 11 May 2020 13:48:13 +0530 Subject: [PATCH 4/8] Improve comments --- .../carbon/device/mgt/common/spi/DeviceTypeCommonService.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceTypeCommonService.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceTypeCommonService.java index 377c9b91e7f..798d4ee58da 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceTypeCommonService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/spi/DeviceTypeCommonService.java @@ -28,7 +28,8 @@ public interface DeviceTypeCommonService { /** * To get Enrollment QR code against Ownership type * - * @return QR code Map which contains key value pairs to have for the QR String. + * @return {@link QREnrollmentPayload} object with payload to generate QR, invalidPlatformConfigs + * and optionalPlatformConfigs. * @throws DeviceManagementException if error occurred while generating the QR String for Ownership */ QREnrollmentPayload getEnrollmentQRCode(String ownershipType) throws DeviceManagementException; From 552015e6f0d3293bcd278925f1fce504c2d71892 Mon Sep 17 00:00:00 2001 From: Pahansith Date: Tue, 12 May 2020 15:24:58 +0530 Subject: [PATCH 5/8] Fix device delete issue --- .../core/dao/impl/AbstractDeviceDAOImpl.java | 26 ++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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 d9b7d495423..d8e32ee2947 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 @@ -2397,8 +2397,9 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { */ private void removeDeviceOperationResponse(Connection conn, List enrollmentIds) throws DeviceManagementDAOException { - String sql = "DELETE FROM DM_DEVICE_OPERATION_RESPONSE WHERE ENROLMENT_ID = ?"; try { + deleteLargePayloadRecords(conn, enrollmentIds); + String sql = "DELETE FROM DM_DEVICE_OPERATION_RESPONSE WHERE ENROLMENT_ID = ?"; if (!executeBatchOperation(conn, sql, enrollmentIds)) { String msg = "Failed to remove device operation response of devices with enrollmentIds : " + enrollmentIds + " while executing batch operation"; @@ -2413,6 +2414,29 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } } + private void deleteLargePayloadRecords(Connection conn, List enrollmentIds) + throws DeviceManagementDAOException { + String sql = "DELETE DM_DEVICE_OPERATION_RESPONSE_LARGE " + + "FROM DM_DEVICE_OPERATION_RESPONSE_LARGE " + + "INNER JOIN DM_DEVICE_OPERATION_RESPONSE ON DM_DEVICE_OPERATION_RESPONSE_LARGE.ID = " + + "DM_DEVICE_OPERATION_RESPONSE.ID " + + "WHERE ENROLMENT_ID = ?"; + try { + if (!executeBatchOperation(conn, sql, enrollmentIds)) { + String msg = "Failed to remove device large operation response of devices with " + + "enrollmentIds : " + + enrollmentIds + " while executing batch operation"; + log.error(msg); + throw new DeviceManagementDAOException(msg); + } + } catch (SQLException e) { + String msg = "SQL error occurred while removing large device operation response of " + + "devices with enrollmentIds : " + enrollmentIds; + log.error(msg, e); + throw new DeviceManagementDAOException(msg, e); + } + } + /*** * This method removes records of a given list of enrollments from the DM_ENROLMENT_OP_MAPPING table * @param conn Connection object From e1a5ae11641a68ffa824d334c478d2d7d6739093 Mon Sep 17 00:00:00 2001 From: shamalka Date: Tue, 12 May 2020 17:16:24 +0530 Subject: [PATCH 6/8] Fix app name validation issue for webclip --- .../mgt/core/impl/ApplicationManagerImpl.java | 21 ++++++++++++------- .../application/mgt/core/util/Constants.java | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index 0fde607bbab..55ddd7d3f36 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -1894,16 +1894,23 @@ public class ApplicationManagerImpl implements ApplicationManager { DeviceManagementProviderService deviceManagementProviderService = DataHolder.getInstance() .getDeviceManagementService(); try { - DeviceType deviceType = deviceManagementProviderService.getDeviceType(deviceTypeName); - if (deviceType == null) { - String msg = "Device type doesn't exist. Hence check the application name existence with valid " - + "device type name."; - log.error(msg); - throw new BadRequestException(msg); + int deviceTypeId; + if (!deviceTypeName.equals(Constants.ALL)) { + DeviceType deviceType = deviceManagementProviderService.getDeviceType(deviceTypeName); + deviceTypeId = deviceType.getId(); + if (deviceType == null) { + String msg = "Device type doesn't exist. Hence check the application name existence with valid " + + "device type name."; + log.error(msg); + throw new BadRequestException(msg); + } + } else { + //For web-clips device type = 'ALL' + deviceTypeId = 0; } try { ConnectionManagerUtil.openDBConnection(); - if (applicationDAO.isExistingAppName(appName, deviceType.getId(), tenantId)) { + if (applicationDAO.isExistingAppName(appName, deviceTypeId, tenantId)) { return true; } } catch (DBConnectionException e) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java index e29959b427b..11ca234e1a9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/Constants.java @@ -48,6 +48,7 @@ public class Constants { public static final String FORWARD_SLASH = "/"; public static final String ANY = "ANY"; public static final String DEFAULT_PCK_NAME = "default.app.com"; + public static final String ALL = "ALL"; public static final String GOOGLE_PLAY_STORE_URL = "https://play.google.com/store/apps/details?id="; public static final String APPLE_STORE_URL = "https://itunes.apple.com/country/app/app-name/id"; From 60d67c9fea99f79abafe528610dcfe3186a261ce Mon Sep 17 00:00:00 2001 From: Pahansith Date: Tue, 12 May 2020 17:57:40 +0530 Subject: [PATCH 7/8] Change method calling order --- .../carbon/device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d8e32ee2947..786ee0b58aa 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 @@ -1912,6 +1912,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { removeEnrollmentDeviceDetail(conn, enrollmentIds); removeEnrollmentDeviceLocation(conn, enrollmentIds); removeEnrollmentDeviceInfo(conn, enrollmentIds); + deleteLargePayloadRecords(conn, enrollmentIds); removeDeviceOperationResponse(conn, enrollmentIds); removeEnrollmentOperationMapping(conn, enrollmentIds); if (log.isDebugEnabled()) { @@ -2398,7 +2399,6 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { private void removeDeviceOperationResponse(Connection conn, List enrollmentIds) throws DeviceManagementDAOException { try { - deleteLargePayloadRecords(conn, enrollmentIds); String sql = "DELETE FROM DM_DEVICE_OPERATION_RESPONSE WHERE ENROLMENT_ID = ?"; if (!executeBatchOperation(conn, sql, enrollmentIds)) { String msg = "Failed to remove device operation response of devices with enrollmentIds : " From 35baf7ca9591094dfaf399cd9e6ae1ccd3e1f26e Mon Sep 17 00:00:00 2001 From: Pahansith Date: Tue, 12 May 2020 18:14:16 +0530 Subject: [PATCH 8/8] Add log records for large response delete --- .../device/mgt/core/dao/impl/AbstractDeviceDAOImpl.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 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 786ee0b58aa..1c6ebebae33 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 @@ -1912,13 +1912,14 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { removeEnrollmentDeviceDetail(conn, enrollmentIds); removeEnrollmentDeviceLocation(conn, enrollmentIds); removeEnrollmentDeviceInfo(conn, enrollmentIds); - deleteLargePayloadRecords(conn, enrollmentIds); + removeDeviceLargeOperationResponse(conn, enrollmentIds); removeDeviceOperationResponse(conn, enrollmentIds); removeEnrollmentOperationMapping(conn, enrollmentIds); if (log.isDebugEnabled()) { log.debug("Successfully removed enrollment device details, enrollment device location," + "enrollment device info, enrollment device application mapping, " + - "enrollment device operation response, enrollment operation mapping data of " + + "enrollment device operation large response, enrollment device " + + "operation response, enrollment operation mapping data of " + "devices with identifiers: " + deviceIdentifiers); } removeDeviceEnrollment(conn, deviceIds); @@ -2414,7 +2415,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { } } - private void deleteLargePayloadRecords(Connection conn, List enrollmentIds) + private void removeDeviceLargeOperationResponse(Connection conn, List enrollmentIds) throws DeviceManagementDAOException { String sql = "DELETE DM_DEVICE_OPERATION_RESPONSE_LARGE " + "FROM DM_DEVICE_OPERATION_RESPONSE_LARGE " +