From b9e0b099a15c015f70fbed6ae4f0de957954140a Mon Sep 17 00:00:00 2001 From: Hasunie Date: Wed, 7 Dec 2016 08:37:00 +0530 Subject: [PATCH 1/3] fixing device update issue --- .../mgt/core/dao/impl/AbstractDeviceDAOImpl.java | 15 ++++++++------- .../DeviceManagementProviderServiceImpl.java | 2 +- 2 files changed, 9 insertions(+), 8 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 3c08f863398..d5b6128daf0 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 @@ -82,16 +82,17 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO { int rows; try { conn = this.getConnection(); - String sql = "UPDATE DM_DEVICE SET DESCRIPTION = ?, LAST_UPDATED_TIMESTAMP = ? " + + String sql = "UPDATE DM_DEVICE SET NAME = ?, DESCRIPTION = ?, LAST_UPDATED_TIMESTAMP = ? " + "WHERE DEVICE_TYPE_ID = (SELECT ID FROM DM_DEVICE_TYPE WHERE NAME = ? AND PROVIDER_TENANT_ID = ?) " + "AND DEVICE_IDENTIFICATION = ? AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql, new String[] {"id"}); - stmt.setString(1, device.getDescription()); - stmt.setTimestamp(2, new Timestamp(new Date().getTime())); - stmt.setString(3, device.getType()); - stmt.setInt(4, tenantId); - stmt.setString(5, device.getDeviceIdentifier()); - stmt.setInt(6, tenantId); + stmt.setString(1, device.getName()); + stmt.setString(2, device.getDescription()); + stmt.setTimestamp(3, new Timestamp(new Date().getTime())); + stmt.setString(4, device.getType()); + stmt.setInt(5, tenantId); + stmt.setString(6, device.getDeviceIdentifier()); + stmt.setInt(7, tenantId); rows = stmt.executeUpdate(); return (rows > 0); } catch (SQLException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index aa6a9ba0803..88a2705bb46 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -274,7 +274,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv Device currentDevice = deviceDAO.getDevice(deviceIdentifier, tenantId); device.setId(currentDevice.getId()); device.getEnrolmentInfo().setId(currentDevice.getEnrolmentInfo().getId()); - + device.setName(currentDevice.getName()); deviceDAO.updateDevice(device, tenantId); enrollmentDAO.updateEnrollment(device.getEnrolmentInfo()); DeviceManagementDAOFactory.commitTransaction(); From 60d1281949440dc1d3f914fdbc457ffc8e6f390b Mon Sep 17 00:00:00 2001 From: Hasunie Date: Thu, 8 Dec 2016 15:58:32 +0530 Subject: [PATCH 2/3] fixing windows device name issue --- .../DeviceManagementProviderServiceImpl.java | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 88a2705bb46..3f60cc89e08 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -274,7 +274,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv Device currentDevice = deviceDAO.getDevice(deviceIdentifier, tenantId); device.setId(currentDevice.getId()); device.getEnrolmentInfo().setId(currentDevice.getEnrolmentInfo().getId()); - device.setName(currentDevice.getName()); + if (device.getName() == null) { + device.setName(currentDevice.getName()); + } deviceDAO.updateDevice(device, tenantId); enrollmentDAO.updateEnrollment(device.getEnrolmentInfo()); DeviceManagementDAOFactory.commitTransaction(); @@ -365,7 +367,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } } catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while obtaining the enrollment information device for" + - "id '" + deviceId.getId() + "'", e); + "id '" + deviceId.getId() + "'", e); } catch (SQLException e) { throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); } finally { @@ -875,7 +877,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv if (device == null) { if (log.isDebugEnabled()) { log.debug("No device is found upon the type '" + deviceId.getType() + "' and id '" + - deviceId.getId() + "'"); + deviceId.getId() + "'"); } return null; } @@ -888,7 +890,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv device.setApplications(applications); } catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while obtaining the device for id " + - "'" + deviceId.getId() + "'", e); + "'" + deviceId.getId() + "'", e); } catch (SQLException e) { throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); } catch (DeviceDetailsMgtDAOException e) { @@ -902,7 +904,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv if (deviceManager == null) { if (log.isDebugEnabled()) { log.debug("Device Manager associated with the device type '" + deviceId.getType() + "' is null. " + - "Therefore, not attempting method 'getDevice'"); + "Therefore, not attempting method 'getDevice'"); } return device; } @@ -1225,7 +1227,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv List taskOperations; Map> deviceTypeSpecificTasks = new HashMap<>(); - for(DeviceTypeIdentifier dti : deviceManagementServiceMap.keySet()){ + for (DeviceTypeIdentifier dti : deviceManagementServiceMap.keySet()) { dms = deviceManagementServiceMap.get(dti); taskOperations = dms.getTasksForPlatform(); if (taskOperations != null) { @@ -1846,7 +1848,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } } catch (DeviceManagementDAOException e) { throw new DeviceManagementException("Error occurred while obtaining the enrollment information device for" + - "id '" + deviceId.getId() + "' and user : " + user, e); + "id '" + deviceId.getId() + "' and user : " + user, e); } catch (SQLException e) { throw new DeviceManagementException("Error occurred while opening a connection to the data source", e); } finally { @@ -1914,8 +1916,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv /** * Checks for the default group existence and create group based on device ownership * - * @param service {@link GroupManagementProviderService} instance. - * @param groupName of the group to create. + * @param service {@link GroupManagementProviderService} instance. + * @param groupName of the group to create. * @return Group with details. * @throws GroupManagementException */ From 312098b1de85f7e70266ac80946e43cad736bc40 Mon Sep 17 00:00:00 2001 From: charitha Date: Thu, 8 Dec 2016 17:19:12 +0530 Subject: [PATCH 3/3] Fix issues in generic policy editor --- .../public/js/editor.js | 13 +++- .../public/js/policy-create.js | 62 ++++++++++++------- 2 files changed, 50 insertions(+), 25 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/editor.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/editor.js index aca1bf0a7ce..1b3035cf621 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/editor.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.generic.policy-wizard/public/js/editor.js @@ -34,4 +34,15 @@ window.queryEditor = CodeMirror.fromTextArea(document.getElementById('policy-def var validatePolicyProfile = function () { return true; -}; \ No newline at end of file +}; + +/** + * Generates policy profile feature list which will be saved with the profile. + * + * This function will be invoked from the relevant cdmf unit at the time of policy creation. + * + * @returns {Array} profile payloads + */ +var generateGenericPayload = function () { + return window.queryEditor.getValue(); +}; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/public/js/policy-create.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/public/js/policy-create.js index 63807df7d91..14d08a99697 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/public/js/policy-create.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.policy.create/public/js/policy-create.js @@ -21,6 +21,7 @@ var policy = {}; var validateInline = {}; var clearInline = {}; var validateStep = {}; +var hasPolicyProfileScript = false; var enableInlineError = function (inputField, errorMsg, errorSign) { var fieldIdentifier = "#" + inputField; @@ -157,6 +158,9 @@ stepForwardFrom["policy-platform"] = function (actionButton) { script.type = 'text/javascript'; script.src = context + policyOperationsScriptSrc; $(".wr-advance-operations").prepend(script); + hasPolicyProfileScript = true; + } else { + hasPolicyProfileScript = false; } if (policyOperationsStylesSrc) { var style = document.createElement('link'); @@ -172,11 +176,14 @@ stepForwardFrom["policy-platform"] = function (actionButton) { * Forward action of policy profile page. Generates policy profile payload. */ stepForwardFrom["policy-profile"] = function () { - /* - generatePolicyProfile() function should be implemented in plugin side and should include the logic to build the - policy profile object. - */ - policy["profile"] = generatePolicyProfile(); + policy["profile"] = []; + if (hasPolicyProfileScript) { + /* + generatePolicyProfile() function should be implemented in plugin side and should include the logic to build the + policy profile object. + */ + policy["profile"] = generatePolicyProfile(); + } // updating next-page wizard title with selected platform $("#policy-criteria-page-wizard-title").text("ADD " + policy["platform"] + " POLICY"); }; @@ -185,11 +192,13 @@ stepForwardFrom["policy-profile"] = function () { * Backward action of policy profile page. Moves back to platform selection step. */ stepBackFrom["policy-profile"] = function () { - /* - resetPolicyProfile() function should be implemented in plugin side and should include the logic to reset the policy - profile object. - */ - resetPolicyProfile(); + if (hasPolicyProfileScript) { + /* + resetPolicyProfile() function should be implemented in plugin side and should include the logic to reset the policy + profile object. + */ + resetPolicyProfile(); + } }; /** @@ -365,21 +374,26 @@ stepForwardFrom["policy-naming"] = function () { }; var savePolicy = function (policy, isActive, serviceURL) { - /* - generateProfileFeaturesList() should be implemented in the plugin side and should include logic to build the - profilePayloads array which contains objects, {featureCode:"value", deviceType:"value", content:"value"}. - policy["profile"] object will be available for the method which returns from the generatePolicyProfile() function. - */ - var profilePayloads = generateProfileFeaturesList(); - - $.each(profilePayloads, function (i, item) { - $.each(item.content, function (key, value) { - //cannot add a true check since it will catch value = false as well - if (value === null || value === undefined || value === "") { - item.content[key] = null; - } + var profilePayloads; + if (hasPolicyProfileScript) { + /* + generateProfileFeaturesList() should be implemented in the plugin side and should include logic to build the + profilePayloads array which contains objects, {featureCode:"value", deviceType:"value", content:"value"}. + policy["profile"] object will be available for the method which returns from the generatePolicyProfile() function. + */ + profilePayloads = generateProfileFeaturesList(); + + $.each(profilePayloads, function (i, item) { + $.each(item.content, function (key, value) { + //cannot add a true check since it will catch value = false as well + if (value === null || value === undefined || value === "") { + item.content[key] = null; + } + }); }); - }); + } else { + profilePayloads = generateGenericPayload(); + } var payload = { "policyName": policy["policyName"],