From 25c2320956ed1c6744ea7789f7d88bd65f40f1a8 Mon Sep 17 00:00:00 2001 From: inoshperera Date: Wed, 24 Mar 2021 19:08:39 +0530 Subject: [PATCH] Fix wrong zip codes from agents persisting --- .../mgt/dao/impl/DeviceDetailsDAOImpl.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java index a37d7ba588..04eda09d86 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java @@ -19,10 +19,10 @@ package org.wso2.carbon.device.mgt.core.device.details.mgt.dao.impl; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; @@ -266,6 +266,12 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { Connection conn; PreparedStatement stmt = null; try { + if (StringUtils.isNotBlank(deviceLocation.getZip()) + && deviceLocation.getZip().length() > 10) { + log.error("Adding unusually long zip " + deviceLocation.getZip() + ", deviceId:" + + deviceLocation.getDeviceId() + ", enrollmentId:" + enrollmentId); + deviceLocation.setZip(null); + } conn = this.getConnection(); stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_LOCATION (DEVICE_ID, LATITUDE, LONGITUDE, STREET1, " + "STREET2, CITY, ZIP, STATE, COUNTRY, GEO_HASH, UPDATE_TIMESTAMP, ENROLMENT_ID, ALTITUDE, SPEED, BEARING, " + @@ -300,6 +306,13 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { Connection conn; PreparedStatement stmt = null; try { + if (StringUtils.isNotBlank(deviceLocation.getZip()) + && deviceLocation.getZip().length() > 10) { + log.error("Updating unusually long zip " + deviceLocation.getZip() + ", deviceId:" + + deviceLocation.getDeviceId() + ", enrollmentId:" + enrollmentId); + deviceLocation.setZip(null); + } + conn = this.getConnection(); stmt = conn.prepareStatement("UPDATE DM_DEVICE_LOCATION SET LATITUDE = ?, LONGITUDE = ?, " + "STREET1 = ?, STREET2 = ?, CITY = ?, ZIP = ?, STATE = ?, COUNTRY = ?, GEO_HASH = ?, " +