Modify get Geofence API to get total count

master
Pramila Niroshan 1 year ago
parent a620cffb31
commit 77823e2839

@ -870,6 +870,14 @@ public class GeoLocationBasedServiceImpl implements GeoLocationBasedService {
PaginationResult paginationResult = new PaginationResult();
paginationResult.setData(geofenceList);
paginationResult.setRecordsTotal(geofenceList.size());
try {
GeoLocationProviderService geoService = DeviceMgtAPIUtils.getGeoService();
paginationResult.setTotalDeviceCount(geoService.getGeoFenceCount());
} catch (GeoLocationBasedServiceException e) {
String msg = "Failed to retrieve geofence data";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity(paginationResult).build();
}

@ -171,4 +171,11 @@ public interface GeoLocationProviderService {
* @throws GeoLocationBasedServiceException any errors occurred while reading event records to geofence
*/
List<EventConfig> getEventsOfGeoFence(int geoFenceId) throws GeoLocationBasedServiceException;
/**
* Get geo fence count by tenant id
* @return returns the geofence count of tenant.
* @throws GeoLocationBasedServiceException any errors occurred while reading event records to geofence
*/
int getGeoFenceCount() throws GeoLocationBasedServiceException;
}

@ -174,4 +174,12 @@ public interface GeofenceDAO {
* @throws DeviceManagementDAOException
*/
GeofenceData getGeofence(int fenceId, boolean requireGroupData) throws DeviceManagementDAOException;
/**
* This method is used to get the geofence count by tenant id.
* @param tenantId tenant id.
* @return returns the geofence count of tenant.
* @throws DeviceManagementDAOException
*/
int getGeofenceCount(int tenantId) throws DeviceManagementDAOException;
}

@ -644,4 +644,28 @@ public abstract class AbstractGeofenceDAOImpl implements GeofenceDAO {
throw new DeviceManagementDAOException(msg, e);
}
}
@Override
public int getGeofenceCount(int tenantId) throws DeviceManagementDAOException {
try {
Connection conn = this.getConnection();
String sql = "SELECT COUNT(*) AS geofence_count " +
"FROM DM_GEOFENCE " +
"WHERE TENANT_ID = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
try (ResultSet rst = stmt.executeQuery()) {
if (rst.next()) {
return rst.getInt("geofence_count");
}
}
}
return 0; // Return 0 if no records found for the given tenantId.
} catch (SQLException e) {
String msg = "Error occurred while retrieving Geofence count of the tenant " + tenantId;
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
}
}

@ -1747,6 +1747,32 @@ public class GeoLocationProviderServiceImpl implements GeoLocationProviderServic
}
}
@Override
public int getGeoFenceCount() throws GeoLocationBasedServiceException {
int tenantId;
try {
tenantId = DeviceManagementDAOUtil.getTenantId();
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while retrieving tenant id while get geofence data";
log.error(msg, e);
throw new GeoLocationBasedServiceException(msg, e);
}
try {
EventManagementDAOFactory.openConnection();
return geofenceDAO.getGeofenceCount(tenantId);
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while retrieving geofence data for the tenant " + tenantId;
log.error(msg, e);
throw new GeoLocationBasedServiceException(msg, e);
} catch (SQLException e) {
String msg = "Failed to open the DB connection to retrieve Geofence";
log.error(msg, e);
throw new GeoLocationBasedServiceException(msg, e);
} finally {
EventManagementDAOFactory.closeConnection();
}
}
/**
* Delete events of geofence
*

Loading…
Cancel
Save