From 866686c6ead6abd3e0a742d834d4bcbb092f0127 Mon Sep 17 00:00:00 2001 From: Mohamed Rashd Date: Tue, 22 Feb 2022 16:50:51 +0530 Subject: [PATCH 1/5] Fix post api failing when trying the with refresh token due to non repeatable http entity --- .../io/entgra/ui/request/interceptor/util/HandlerUtil.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java index 64f8a3e221f..ece5d92d9b6 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java @@ -39,6 +39,7 @@ import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.cookie.SM; +import org.apache.http.entity.BufferedHttpEntity; import org.apache.http.entity.ContentType; import org.apache.http.entity.InputStreamEntity; import org.apache.http.entity.StringEntity; @@ -413,14 +414,14 @@ public class HandlerUtil { entityBuilder.addTextBody(item.getFieldName(), item.getString()); } } - proxyRequest.setEntity(entityBuilder.build()); + proxyRequest.setEntity(new BufferedHttpEntity(entityBuilder.build())); HandlerUtil.copyRequestHeaders(req, proxyRequest, false); } else { if (StringUtils.isNotEmpty(req.getHeader(HttpHeaders.CONTENT_LENGTH)) || StringUtils.isNotEmpty(req.getHeader(HttpHeaders.TRANSFER_ENCODING))) { InputStreamEntity entity = new InputStreamEntity(req.getInputStream(), Long.parseLong(req.getHeader(HttpHeaders.CONTENT_LENGTH))); - proxyRequest.setEntity(entity); + proxyRequest.setEntity(new BufferedHttpEntity(entity)); } HandlerUtil.copyRequestHeaders(req, proxyRequest, true); } From 5b5257301a2129e1f963db29243208cff503169a Mon Sep 17 00:00:00 2001 From: Chamindu Senanayake Date: Tue, 1 Mar 2022 10:27:59 +0530 Subject: [PATCH 2/5] Fix remove certificate API --- .../mgt/cert/jaxrs/api/CertificateManagementAdminService.java | 4 +--- .../jaxrs/api/impl/CertificateManagementAdminServiceImpl.java | 4 +--- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java index 5204205dc1a..80dd79617db 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java @@ -310,8 +310,6 @@ public interface CertificateManagementAdminService { @HeaderParam("If-Modified-Since") String ifModifiedSince); @DELETE - @Path("/{serialNumber}") - @Consumes(MediaType.WILDCARD) @ApiOperation( consumes = MediaType.WILDCARD, produces = MediaType.APPLICATION_JSON, @@ -348,7 +346,7 @@ public interface CertificateManagementAdminService { "NOTE: Make sure that a certificate with the serial number you provide exists in the server. If not, first add a certificate.", required = true, defaultValue = "12438035315552875930") - @PathParam("serialNumber") String serialNumber); + @QueryParam("serialNumber") String serialNumber); /** * Verify Certificate for the API security filter diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/impl/CertificateManagementAdminServiceImpl.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/impl/CertificateManagementAdminServiceImpl.java index d898e632ae1..be0539c9462 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/impl/CertificateManagementAdminServiceImpl.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/impl/CertificateManagementAdminServiceImpl.java @@ -151,9 +151,7 @@ public class CertificateManagementAdminServiceImpl implements CertificateManagem } @DELETE - @Path("/{serialNumber}") - @Consumes(MediaType.WILDCARD) - public Response removeCertificate(@PathParam("serialNumber") String serialNumber) { + public Response removeCertificate(@QueryParam("serialNumber") String serialNumber) { RequestValidationUtil.validateSerialNumber(serialNumber); CertificateManagementService certificateService = CertificateMgtAPIUtils.getCertificateManagementService(); From 12c48540d8fa592efe003b8868c82d66776817e0 Mon Sep 17 00:00:00 2001 From: Pahansith Gunathilake Date: Tue, 1 Mar 2022 10:46:36 +0530 Subject: [PATCH 3/5] Fix device enrollment failure --- .../GroupManagementProviderServiceImpl.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java index 6a678c1fca0..bccec017076 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -994,16 +994,19 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid if (log.isDebugEnabled()) { log.debug("Group devices to the group: " + groupId); } - Device device; + try { int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + List deviceIdentifierList = deviceIdentifiers.stream() + .map(DeviceIdentifier::getId) + .collect(Collectors.toCollection(ArrayList::new)); + List devicesList = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() + .getDeviceByIdList(deviceIdentifierList); + if (devicesList == null || devicesList.isEmpty()) { + throw new DeviceNotFoundException("Couldn't find any devices for the given deviceIdentifiers '" + deviceIdentifiers + "'"); + } GroupManagementDAOFactory.beginTransaction(); - for (DeviceIdentifier deviceIdentifier : deviceIdentifiers) { - device = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider(). - getDevice(deviceIdentifier, false); - if (device == null) { - throw new DeviceNotFoundException("Device not found for id '" + deviceIdentifier.getId() + "'"); - } + for (Device device : devicesList) { if (!this.groupDAO.isDeviceMappedToGroup(groupId, device.getId(), tenantId)) { this.groupDAO.addDevice(groupId, device.getId(), tenantId); } From 35e0b9189ed094bee3d98bc095612f1c9716838d Mon Sep 17 00:00:00 2001 From: Pahansith Gunathilake Date: Wed, 2 Mar 2022 00:54:33 +0000 Subject: [PATCH 4/5] Add separate DAO factory for event management --- .../core/dao/DeviceManagementDAOFactory.java | 21 -- .../core/dao/EventManagementDAOFactory.java | 200 ++++++++++++++++++ .../core/dao/impl/AbstractEventConfigDAO.java | 3 +- .../mgt/core/dao/impl/GeofenceDAOImpl.java | 3 +- ...EventConfigurationProviderServiceImpl.java | 37 ++-- .../GeoLocationProviderServiceImpl.java | 74 +++---- .../DeviceManagementServiceComponent.java | 2 + .../GroupManagementProviderServiceImpl.java | 22 +- 8 files changed, 276 insertions(+), 86 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/EventManagementDAOFactory.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java index 348f256016e..a07989e3385 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/DeviceManagementDAOFactory.java @@ -151,27 +151,6 @@ public class DeviceManagementDAOFactory { return new PrivacyComplianceDAOImpl(); } - public static GeofenceDAO getGeofenceDAO() { - return new GeofenceDAOImpl(); - } - - public static EventConfigDAO getEventConfigDAO() { - if (databaseEngine != null) { - switch (databaseEngine) { - case DeviceManagementConstants.DataBaseTypes.DB_TYPE_POSTGRESQL: - case DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE: - case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MSSQL: - case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL: - return new GenericEventConfigDAOImpl(); - case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2: - return new H2EventConfigDAOImpl(); - default: - throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); - } - } - throw new IllegalStateException("Database engine has not initialized properly."); - } - public static void init(DataSourceConfig config) { dataSource = resolveDataSource(config); try { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/EventManagementDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/EventManagementDAOFactory.java new file mode 100644 index 00000000000..754b5190041 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/EventManagementDAOFactory.java @@ -0,0 +1,200 @@ +/* + * Copyright (c) 2022, 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.core.dao; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.common.exceptions.IllegalTransactionStateException; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.UnsupportedDatabaseEngineException; +import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; +import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; +import org.wso2.carbon.device.mgt.core.dao.impl.*; +import org.wso2.carbon.device.mgt.core.dao.impl.event.GenericEventConfigDAOImpl; +import org.wso2.carbon.device.mgt.core.dao.impl.event.H2EventConfigDAOImpl; +import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; + +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Hashtable; +import java.util.List; + +public class EventManagementDAOFactory { + private static DataSource dataSource; + private static String databaseEngine; + private static final Log log = LogFactory.getLog(EventManagementDAOFactory.class); + private static ThreadLocal currentConnection = new ThreadLocal<>(); + + + public static GeofenceDAO getGeofenceDAO() { + return new GeofenceDAOImpl(); + } + + public static EventConfigDAO getEventConfigDAO() { + if (databaseEngine != null) { + switch (databaseEngine) { + case DeviceManagementConstants.DataBaseTypes.DB_TYPE_POSTGRESQL: + case DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE: + case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MSSQL: + case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL: + return new GenericEventConfigDAOImpl(); + case DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2: + return new H2EventConfigDAOImpl(); + default: + throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); + } + } + throw new IllegalStateException("Database engine has not initialized properly."); + } + + public static void init(DataSourceConfig config) { + dataSource = resolveDataSource(config); + try { + databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName(); + } catch (SQLException e) { + log.error("Error occurred while retrieving config.datasource connection", e); + } + } + + public static void init(DataSource dtSource) { + dataSource = dtSource; + try { + databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName(); + } catch (SQLException e) { + log.error("Error occurred while retrieving config.datasource connection", e); + } + } + + public static void beginTransaction() throws TransactionManagementException { + Connection conn = currentConnection.get(); + if (conn != null) { + throw new IllegalTransactionStateException("A transaction is already active within the context of " + + "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " + + "transaction is already active is a sign of improper transaction handling"); + } + try { + conn = dataSource.getConnection(); + conn.setAutoCommit(false); + currentConnection.set(conn); + } catch (SQLException e) { + throw new TransactionManagementException("Error occurred while retrieving config.datasource connection", e); + } + } + + public static void openConnection() throws SQLException { + Connection conn = currentConnection.get(); + if (conn != null) { + throw new IllegalTransactionStateException("A transaction is already active within the context of " + + "this particular thread. Therefore, calling 'beginTransaction/openConnection' while another " + + "transaction is already active is a sign of improper transaction handling"); + } + conn = dataSource.getConnection(); + currentConnection.set(conn); + } + + public static Connection getConnection() throws SQLException { + Connection conn = currentConnection.get(); + if (conn == null) { + throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + + "This might have ideally been caused by not properly initiating the transaction via " + + "'beginTransaction'/'openConnection' methods"); + } + return conn; + } + + public static void commitTransaction() { + Connection conn = currentConnection.get(); + if (conn == null) { + throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + + "This might have ideally been caused by not properly initiating the transaction via " + + "'beginTransaction'/'openConnection' methods"); + } + try { + conn.commit(); + } catch (SQLException e) { + log.error("Error occurred while committing the transaction", e); + } + } + + public static void rollbackTransaction() { + Connection conn = currentConnection.get(); + if (conn == null) { + throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + + "This might have ideally been caused by not properly initiating the transaction via " + + "'beginTransaction'/'openConnection' methods"); + } + try { + conn.rollback(); + } catch (SQLException e) { + log.warn("Error occurred while roll-backing the transaction", e); + } + } + + public static void closeConnection() { + Connection conn = currentConnection.get(); + if (conn == null) { + throw new IllegalTransactionStateException("No connection is associated with the current transaction. " + + "This might have ideally been caused by not properly initiating the transaction via " + + "'beginTransaction'/'openConnection' methods"); + } + try { + conn.close(); + } catch (SQLException e) { + log.warn("Error occurred while close the connection"); + } + currentConnection.remove(); + } + + + /** + * Resolve data source from the data source definition + * + * @param config data source configuration + * @return data source resolved from the data source definition + */ + private static DataSource resolveDataSource(DataSourceConfig config) { + DataSource dataSource = null; + if (config == null) { + throw new RuntimeException( + "Device Management Repository data source configuration " + "is null and " + + "thus, is not initialized"); + } + JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition(); + if (jndiConfig != null) { + if (log.isDebugEnabled()) { + log.debug("Initializing Device Management Repository data source using the JNDI " + + "Lookup Definition"); + } + List jndiPropertyList = + jndiConfig.getJndiProperties(); + if (jndiPropertyList != null) { + Hashtable jndiProperties = new Hashtable(); + for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { + jndiProperties.put(prop.getName(), prop.getValue()); + } + dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties); + } else { + dataSource = DeviceManagementDAOUtil.lookupDataSource(jndiConfig.getJndiName(), null); + } + } + return dataSource; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractEventConfigDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractEventConfigDAO.java index a0cc3889a09..0e5194a4a4f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractEventConfigDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/AbstractEventConfigDAO.java @@ -24,6 +24,7 @@ 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.EventConfigDAO; import org.wso2.carbon.device.mgt.core.dao.EventManagementDAOException; +import org.wso2.carbon.device.mgt.core.dao.EventManagementDAOFactory; import java.sql.Connection; import java.sql.PreparedStatement; @@ -342,6 +343,6 @@ public abstract class AbstractEventConfigDAO implements EventConfigDAO { } 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/dao/impl/GeofenceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GeofenceDAOImpl.java index e0d1efa4d1b..e845a43da92 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GeofenceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/GeofenceDAOImpl.java @@ -26,6 +26,7 @@ import org.wso2.carbon.device.mgt.common.event.config.EventConfig; import org.wso2.carbon.device.mgt.common.geo.service.GeofenceData; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.dao.EventManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.GeofenceDAO; import org.wso2.carbon.device.mgt.core.dto.event.config.GeoFenceGroupMap; @@ -308,7 +309,7 @@ public class GeofenceDAOImpl implements GeofenceDAO { } private Connection getConnection() throws SQLException { - return DeviceManagementDAOFactory.getConnection(); + return EventManagementDAOFactory.getConnection(); } private List extractGeofenceData(ResultSet rst) throws SQLException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/event/config/EventConfigurationProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/event/config/EventConfigurationProviderServiceImpl.java index b2fe4ede22a..7a6a362e411 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/event/config/EventConfigurationProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/event/config/EventConfigurationProviderServiceImpl.java @@ -27,10 +27,7 @@ import org.wso2.carbon.device.mgt.common.event.config.EventConfigurationProvider import org.wso2.carbon.device.mgt.common.event.config.EventMetaData; import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; -import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; -import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; -import org.wso2.carbon.device.mgt.core.dao.EventConfigDAO; -import org.wso2.carbon.device.mgt.core.dao.EventManagementDAOException; +import org.wso2.carbon.device.mgt.core.dao.*; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.geo.task.GeoFenceEventOperationManager; import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder; @@ -49,7 +46,7 @@ public class EventConfigurationProviderServiceImpl implements EventConfiguration private final EventConfigDAO eventConfigDAO; public EventConfigurationProviderServiceImpl() { - eventConfigDAO = DeviceManagementDAOFactory.getEventConfigDAO(); + eventConfigDAO = EventManagementDAOFactory.getEventConfigDAO(); } @Override @@ -65,7 +62,7 @@ public class EventConfigurationProviderServiceImpl implements EventConfiguration } try { - DeviceManagementDAOFactory.beginTransaction(); + EventManagementDAOFactory.beginTransaction(); if (log.isDebugEnabled()) { log.debug("Creating event records of tenant " + tenantId); } @@ -75,7 +72,7 @@ public class EventConfigurationProviderServiceImpl implements EventConfiguration log.debug("Creating event group mapping for created events with group ids : " + groupIds.toString()); } eventConfigDAO.addEventGroupMappingRecords(generatedEventIds, groupIds); - DeviceManagementDAOFactory.commitTransaction(); + EventManagementDAOFactory.commitTransaction(); if (log.isDebugEnabled()) { log.debug("Event configuration added successfully for the tenant " + tenantId); } @@ -86,10 +83,10 @@ public class EventConfigurationProviderServiceImpl implements EventConfiguration } catch (EventManagementDAOException e) { String msg = "Error occurred while saving event records"; log.error(msg, e); - DeviceManagementDAOFactory.rollbackTransaction(); + EventManagementDAOFactory.rollbackTransaction(); throw new EventConfigurationException(msg, e); } finally { - DeviceManagementDAOFactory.closeConnection(); + EventManagementDAOFactory.closeConnection(); } } @@ -103,7 +100,7 @@ public class EventConfigurationProviderServiceImpl implements EventConfiguration } List eventsToAdd; try { - DeviceManagementDAOFactory.beginTransaction(); + EventManagementDAOFactory.beginTransaction(); eventsToAdd = new ArrayList<>(); List eventsToUpdate = new ArrayList<>(); List updateEventIdList = new ArrayList<>(); @@ -162,7 +159,7 @@ public class EventConfigurationProviderServiceImpl implements EventConfiguration } eventConfigDAO.deleteEventRecords(removedEventIdList); } - DeviceManagementDAOFactory.commitTransaction(); + EventManagementDAOFactory.commitTransaction(); } catch (TransactionManagementException e) { String msg = "Failed to start/open transaction to store device event configurations"; log.error(msg, e); @@ -170,10 +167,10 @@ public class EventConfigurationProviderServiceImpl implements EventConfiguration } catch (EventManagementDAOException e) { String msg = "Error occurred while saving event records"; log.error(msg, e); - DeviceManagementDAOFactory.rollbackTransaction(); + EventManagementDAOFactory.rollbackTransaction(); throw new EventConfigurationException(msg, e); } finally { - DeviceManagementDAOFactory.closeConnection(); + EventManagementDAOFactory.closeConnection(); } if (log.isDebugEnabled()) { @@ -185,7 +182,7 @@ public class EventConfigurationProviderServiceImpl implements EventConfiguration @Override public List getEvents(List createdEventIds) throws EventConfigurationException { try { - DeviceManagementDAOFactory.openConnection(); + EventManagementDAOFactory.openConnection(); return eventConfigDAO.getEventsById(createdEventIds); } catch (EventManagementDAOException e) { String msg = "Error occurred while retrieving event by IDs : " + Arrays.toString(createdEventIds.toArray()); @@ -196,14 +193,14 @@ public class EventConfigurationProviderServiceImpl implements EventConfiguration log.error(msg, e); throw new EventConfigurationException(msg, e); } finally { - DeviceManagementDAOFactory.closeConnection(); + EventManagementDAOFactory.closeConnection(); } } @Override public List getEventsSourcesOfGroup(int groupId, int tenantId) throws EventConfigurationException { try { - DeviceManagementDAOFactory.openConnection(); + EventManagementDAOFactory.openConnection(); return eventConfigDAO.getEventSourcesOfGroups(groupId, tenantId); } catch (EventManagementDAOException e) { String msg = "Error occurred while retrieving events of group " + groupId + " and tenant " + tenantId; @@ -214,14 +211,14 @@ public class EventConfigurationProviderServiceImpl implements EventConfiguration log.error(msg, e); throw new EventConfigurationException(msg, e); } finally { - DeviceManagementDAOFactory.closeConnection(); + EventManagementDAOFactory.closeConnection(); } } @Override public void deleteEvents(List events) throws EventConfigurationException { try { - DeviceManagementDAOFactory.beginTransaction(); + EventManagementDAOFactory.beginTransaction(); Set eventIdSet = new HashSet<>(); for (EventConfig eventConfig : events) { eventIdSet.add(eventConfig.getEventId()); @@ -230,13 +227,13 @@ public class EventConfigurationProviderServiceImpl implements EventConfiguration eventConfigDAO.deleteEventGroupMappingRecordsByEventIds(Lists.newArrayList(eventIdSet)); eventConfigDAO.deleteEventRecords(Lists.newArrayList(eventIdSet)); } - DeviceManagementDAOFactory.commitTransaction(); + EventManagementDAOFactory.commitTransaction(); } catch (TransactionManagementException e) { String msg = "Failed to start/open transaction to delete device event configurations"; log.error(msg, e); throw new EventConfigurationException(msg, e); } catch (EventManagementDAOException e) { - DeviceManagementDAOFactory.rollbackTransaction(); + EventManagementDAOFactory.rollbackTransaction(); String msg = "Error occurred while deleting event records"; log.error(msg, e); throw new EventConfigurationException(msg, e); 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 fad3138d446..2377954f95e 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 @@ -53,6 +53,7 @@ import org.wso2.carbon.device.mgt.common.geo.service.GeofenceData; import org.wso2.carbon.device.mgt.core.cache.impl.GeoCacheManagerImpl; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.dao.EventManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.GeofenceDAO; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dto.event.config.GeoFenceGroupMap; @@ -133,7 +134,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic private final GeofenceDAO geofenceDAO; public GeoLocationProviderServiceImpl() { - this.geofenceDAO = DeviceManagementDAOFactory.getGeofenceDAO(); + this.geofenceDAO = EventManagementDAOFactory.getGeofenceDAO(); } public static JWTClientManagerService getJWTClientManagerService() { @@ -1269,32 +1270,32 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic } try { - DeviceManagementDAOFactory.beginTransaction(); + EventManagementDAOFactory.beginTransaction(); geofenceData = geofenceDAO.saveGeofence(geofenceData); GeoCacheManagerImpl.getInstance() .addFenceToCache(geofenceData, geofenceData.getId(), tenantId); geofenceDAO.createGeofenceGroupMapping(geofenceData, geofenceData.getGroupIds()); - DeviceManagementDAOFactory.commitTransaction(); + EventManagementDAOFactory.commitTransaction(); } catch (TransactionManagementException e) { String msg = "Failed to begin transaction for saving geofence"; log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); } catch (DeviceManagementDAOException e) { - DeviceManagementDAOFactory.rollbackTransaction(); + EventManagementDAOFactory.rollbackTransaction(); String msg = "Error occurred while saving geofence"; log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); } finally { - DeviceManagementDAOFactory.closeConnection(); + EventManagementDAOFactory.closeConnection(); } List createdEventIds; try { setEventSource(geofenceData.getEventConfig()); eventConfigService = DeviceManagementDataHolder.getInstance().getEventConfigurationService(); createdEventIds = eventConfigService.createEventsOfDeviceGroup(geofenceData.getEventConfig(), geofenceData.getGroupIds()); - DeviceManagementDAOFactory.beginTransaction(); + EventManagementDAOFactory.beginTransaction(); geofenceDAO.createGeofenceEventMapping(geofenceData.getId(), createdEventIds); - DeviceManagementDAOFactory.commitTransaction(); + EventManagementDAOFactory.commitTransaction(); } catch (EventConfigurationException e) { String msg = "Failed to store Geofence event configurations"; log.error(msg, e); @@ -1309,12 +1310,12 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); } catch (DeviceManagementDAOException e) { - DeviceManagementDAOFactory.rollbackTransaction(); + EventManagementDAOFactory.rollbackTransaction(); String msg = "Error occurred while creating geofence event mapping records"; log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); } finally { - DeviceManagementDAOFactory.closeConnection(); + EventManagementDAOFactory.closeConnection(); } try { @@ -1358,7 +1359,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic } try { - DeviceManagementDAOFactory.openConnection(); + EventManagementDAOFactory.openConnection(); GeofenceData geofence = geofenceDAO.getGeofence(fenceId, true); if (geofence != null) { GeoCacheManagerImpl.getInstance().addFenceToCache(geofence, fenceId, tenantId); @@ -1373,7 +1374,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); } finally { - DeviceManagementDAOFactory.closeConnection(); + EventManagementDAOFactory.closeConnection(); } } @@ -1392,7 +1393,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic if (log.isDebugEnabled()) { log.debug("Retrieving geofence data for the tenant " + tenantId); } - DeviceManagementDAOFactory.openConnection(); + EventManagementDAOFactory.openConnection(); return geofenceDAO.getGeoFencesOfTenant(request, tenantId); } catch (DeviceManagementDAOException e) { String msg = "Error occurred while retrieving geofence data for the tenant " + tenantId; @@ -1403,7 +1404,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); } finally { - DeviceManagementDAOFactory.closeConnection(); + EventManagementDAOFactory.closeConnection(); } } @@ -1422,7 +1423,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic if (log.isDebugEnabled()) { log.debug("Retrieving geofence data for the tenant " + tenantId); } - DeviceManagementDAOFactory.openConnection(); + EventManagementDAOFactory.openConnection(); return geofenceDAO.getGeoFencesOfTenant(fenceName, tenantId); } catch (DeviceManagementDAOException e) { String msg = "Error occurred while retrieving geofence data for the tenant " + tenantId; @@ -1433,7 +1434,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); } finally { - DeviceManagementDAOFactory.closeConnection(); + EventManagementDAOFactory.closeConnection(); } } @@ -1452,7 +1453,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic if (log.isDebugEnabled()) { log.debug("Retrieving all fence data for the tenant " + tenantId); } - DeviceManagementDAOFactory.openConnection(); + EventManagementDAOFactory.openConnection(); List geoFencesOfTenant = geofenceDAO.getGeoFencesOfTenant(tenantId); for (GeofenceData geofenceData : geoFencesOfTenant) { GeoCacheManagerImpl.getInstance() @@ -1469,7 +1470,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); } finally { - DeviceManagementDAOFactory.closeConnection(); + EventManagementDAOFactory.closeConnection(); } } @@ -1488,7 +1489,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic } try { - DeviceManagementDAOFactory.beginTransaction(); + EventManagementDAOFactory.beginTransaction(); geofence = geofenceDAO.getGeofence(fenceId, true); if (geofence == null) { return false; @@ -1509,7 +1510,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic DeviceManagementDAOFactory.commitTransaction(); GeoCacheManagerImpl.getInstance().removeFenceFromCache(fenceId, tenantId); } catch (DeviceManagementDAOException e) { - DeviceManagementDAOFactory.rollbackTransaction(); + EventManagementDAOFactory.rollbackTransaction(); String msg = "Error occurred while deleting geofence"; log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); @@ -1518,7 +1519,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); } finally { - DeviceManagementDAOFactory.closeConnection(); + EventManagementDAOFactory.closeConnection(); } this.deleteGeoFenceEvents(geofence, eventsOfGeoFence); return true; @@ -1538,7 +1539,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic List savedGroupIds; try { - DeviceManagementDAOFactory.beginTransaction(); + EventManagementDAOFactory.beginTransaction(); int updatedRowCount = geofenceDAO.updateGeofence(geofenceData, fenceId); savedGroupIds = geofenceDAO.getGroupIdsOfGeoFence(fenceId); geofenceData.setId(fenceId); @@ -1556,7 +1557,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic } geofenceDAO.deleteGeofenceGroupMapping(groupIdsToDelete, fenceId); geofenceDAO.createGeofenceGroupMapping(geofenceData, groupIdsToAdd); - DeviceManagementDAOFactory.commitTransaction(); + EventManagementDAOFactory.commitTransaction(); if (updatedRowCount > 0) { GeoCacheManagerImpl.getInstance().updateGeoFenceInCache(geofenceData, fenceId, tenantId); } @@ -1587,11 +1588,11 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic if (log.isDebugEnabled()) { log.debug("Deleting geofence event mapping records of geofence " + fenceId); } - DeviceManagementDAOFactory.beginTransaction(); + EventManagementDAOFactory.beginTransaction(); geofenceDAO.deleteGeofenceEventMapping(removedEventIdList); - DeviceManagementDAOFactory.commitTransaction(); + EventManagementDAOFactory.commitTransaction(); } catch (DeviceManagementDAOException e) { - DeviceManagementDAOFactory.rollbackTransaction(); + EventManagementDAOFactory.rollbackTransaction(); String msg = "Error occurred while deleting geofence event mapping of fence " + fenceId; log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); @@ -1600,7 +1601,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); } finally { - DeviceManagementDAOFactory.closeConnection(); + EventManagementDAOFactory.closeConnection(); } List createdEventIds; @@ -1630,11 +1631,11 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic + fenceId + ". created events " + createdEventIds.toString()); } try { - DeviceManagementDAOFactory.beginTransaction(); + EventManagementDAOFactory.beginTransaction(); geofenceDAO.createGeofenceEventMapping(fenceId, createdEventIds); - DeviceManagementDAOFactory.commitTransaction(); + EventManagementDAOFactory.commitTransaction(); } catch (DeviceManagementDAOException e) { - DeviceManagementDAOFactory.rollbackTransaction(); + EventManagementDAOFactory.rollbackTransaction(); String msg = "Error occurred while creating geofence event mapping records of geofence " + fenceId; log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); @@ -1643,7 +1644,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); } finally { - DeviceManagementDAOFactory.closeConnection(); + EventManagementDAOFactory.closeConnection(); } if (log.isDebugEnabled()) { log.debug("Update geofence event completed."); @@ -1664,7 +1665,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic @Override public List attachEventObjects(List geoFences) throws GeoLocationBasedServiceException { try { - DeviceManagementDAOFactory.openConnection(); + EventManagementDAOFactory.openConnection(); List fenceIds = new ArrayList<>(); for (GeofenceData geoFence : geoFences) { fenceIds.add(geoFence.getId()); @@ -1696,14 +1697,14 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); } finally { - DeviceManagementDAOFactory.closeConnection(); + EventManagementDAOFactory.closeConnection(); } } @Override public List getGeoFencesOfGroup(int groupId, int tenantId, boolean requireEventData) throws GeoLocationBasedServiceException { try { - DeviceManagementDAOFactory.openConnection(); + EventManagementDAOFactory.openConnection(); List geofenceDataList = geofenceDAO.getGeoFences(groupId, tenantId); if (requireEventData) { for (GeofenceData geoFenceData : geofenceDataList) { @@ -1711,7 +1712,6 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic geoFenceData.setEventConfig(eventsOfGeoFence); } } - DeviceManagementDAOFactory.closeConnection(); return geofenceDataList; } catch (DeviceManagementDAOException e) { String msg = "Error occurred while retrieving geo fences of group " + groupId @@ -1723,13 +1723,15 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic + groupId + " and tenant " + tenantId; log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); + } finally { + EventManagementDAOFactory.closeConnection(); } } @Override public List getEventsOfGeoFence(int geoFenceId) throws GeoLocationBasedServiceException { try { - DeviceManagementDAOFactory.openConnection(); + EventManagementDAOFactory.openConnection(); return geofenceDAO.getEventsOfGeoFence(geoFenceId); } catch (SQLException e) { String msg = "Failed to obtain connection while retrieving event data of geo fence " @@ -1741,7 +1743,7 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic log.error(msg, e); throw new GeoLocationBasedServiceException(msg, e); } finally { - DeviceManagementDAOFactory.closeConnection(); + EventManagementDAOFactory.closeConnection(); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java index 859659bdf5f..4c031163aa7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceManagementServiceComponent.java @@ -51,6 +51,7 @@ import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.tenant.PlatformConfigurationManagementServiceImpl; import org.wso2.carbon.device.mgt.core.config.ui.UIConfigurationManager; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.dao.EventManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.GroupManagementDAOFactory; import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; import org.wso2.carbon.device.mgt.core.device.details.mgt.impl.DeviceInformationManagerImpl; @@ -192,6 +193,7 @@ public class DeviceManagementServiceComponent { NotificationManagementDAOFactory.init(dsConfig); OperationManagementDAOFactory.init(dsConfig); MetadataManagementDAOFactory.init(dsConfig); + EventManagementDAOFactory.init(dsConfig); OTPManagementDAOFactory.init(dsConfig.getJndiLookupDefinition().getJndiName()); /*Initialize the device cache*/ DeviceManagerUtil.initializeDeviceCache(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java index bccec017076..2db3bd5f584 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -994,17 +994,29 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid if (log.isDebugEnabled()) { log.debug("Group devices to the group: " + groupId); } - + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + List devicesList = null; try { - int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + List deviceIdentifierList = deviceIdentifiers.stream() .map(DeviceIdentifier::getId) .collect(Collectors.toCollection(ArrayList::new)); - List devicesList = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() + devicesList = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider() .getDeviceByIdList(deviceIdentifierList); if (devicesList == null || devicesList.isEmpty()) { throw new DeviceNotFoundException("Couldn't find any devices for the given deviceIdentifiers '" + deviceIdentifiers + "'"); } + } catch (DeviceManagementException e) { + String msg = "Error occurred while retrieving devices using device identifiers"; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (Exception e) { + String msg = "Error occurred in addDevices for groupId " + groupId; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } + + try { GroupManagementDAOFactory.beginTransaction(); for (Device device : devicesList) { if (!this.groupDAO.isDeviceMappedToGroup(groupId, device.getId(), tenantId)) { @@ -1013,10 +1025,6 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid } GroupManagementDAOFactory.commitTransaction(); createEventTask(OperationMgtConstants.OperationCodes.EVENT_CONFIG, groupId, deviceIdentifiers, tenantId); - } catch (DeviceManagementException e) { - String msg = "Error occurred while retrieving device."; - log.error(msg, e); - throw new GroupManagementException(msg, e); } catch (GroupManagementDAOException e) { GroupManagementDAOFactory.rollbackTransaction(); String msg = "Error occurred while adding device to group."; From cb2e5e9c66db2f8f9b58bf5443dbdd3ba3daa910 Mon Sep 17 00:00:00 2001 From: Pahansith Gunathilake Date: Wed, 2 Mar 2022 09:10:39 +0530 Subject: [PATCH 5/5] Fix test failure --- .../core/operation/mgt/dao/impl/GenericOperationDAOImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index f6f7e4b0cca..24e565f2d7e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -425,7 +425,8 @@ public class GenericOperationDAOImpl implements OperationDAO { " LEFT JOIN " + " DM_DEVICE_OPERATION_RESPONSE opr ON opr.EN_OP_MAP_ID = eom.ID " + "WHERE " + - " eom.OPERATION_ID = ? AND eom.TENANT_ID = ?"; + " eom.OPERATION_ID = ? AND eom.TENANT_ID = ? " + + "ORDER BY eom.UPDATED_TIMESTAMP DESC"; stmt = conn.prepareStatement(sql); stmt.setInt(1, operationId);