From 27303cf12bec1c142df883216e288e856fdf4f7d Mon Sep 17 00:00:00 2001 From: Pahansith Gunathilake Date: Fri, 4 Mar 2022 16:11:10 +0530 Subject: [PATCH] Fix invalid DAO factory handling & invalid event revoke payload --- .../mgt/core/dao/impl/event/H2EventConfigDAOImpl.java | 3 ++- .../mgt/core/event/config/EventOperationExecutor.java | 5 ++++- .../core/geo/service/GeoLocationProviderServiceImpl.java | 7 ++----- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/event/H2EventConfigDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/event/H2EventConfigDAOImpl.java index fef946649f..ab59d5fc83 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/event/H2EventConfigDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/event/H2EventConfigDAOImpl.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.event.config.EventConfig; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.EventManagementDAOException; +import org.wso2.carbon.device.mgt.core.dao.EventManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.impl.AbstractEventConfigDAO; import java.sql.Connection; @@ -75,6 +76,6 @@ public class H2EventConfigDAOImpl extends AbstractEventConfigDAO { } private Connection getConnection() throws SQLException { - return DeviceManagementDAOFactory.getConnection(); + return EventManagementDAOFactory.getConnection(); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/event/config/EventOperationExecutor.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/event/config/EventOperationExecutor.java index 937706c219..9c2a043923 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/event/config/EventOperationExecutor.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/event/config/EventOperationExecutor.java @@ -132,7 +132,10 @@ public class EventOperationExecutor implements Runnable { EventRevokeOperation eventRevokeOperation = new EventRevokeOperation(); eventRevokeOperation.setEventSource(eventSource); eventRevokeOperation.setId(geoFenceMeta.getId()); - operation.setPayLoad(new Gson().toJson(eventRevokeOperation)); + + List eventOperationsRevoke = new ArrayList<>(); + eventOperationsRevoke.add(eventRevokeOperation); + operation.setPayLoad(new Gson().toJson(eventOperationsRevoke)); } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java index 2377954f95..5f2c6c7916 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/geo/service/GeoLocationProviderServiceImpl.java @@ -1507,7 +1507,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic geofenceDAO.deleteGeofenceGroupMapping(groupIdsOfGeoFence, fenceId); } geofenceDAO.deleteGeofenceById(fenceId); - DeviceManagementDAOFactory.commitTransaction(); + EventManagementDAOFactory.commitTransaction(); GeoCacheManagerImpl.getInstance().removeFenceFromCache(fenceId, tenantId); } catch (DeviceManagementDAOException e) { EventManagementDAOFactory.rollbackTransaction(); @@ -1571,7 +1571,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); } finally { - DeviceManagementDAOFactory.closeConnection(); + EventManagementDAOFactory.closeConnection(); } return true; } @@ -1772,12 +1772,9 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic DeviceManagementConstants.EventServices.GEOFENCE, new GeoFenceEventMeta(geofenceData), tenantId, geofenceData.getGroupIds()); } catch (EventConfigurationException e) { - DeviceManagementDAOFactory.rollbackTransaction(); String msg = "Failed to delete Geofence event configurations"; log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); - } finally { - DeviceManagementDAOFactory.closeConnection(); } } }