Adding temporary development code bits for dashboard analytics feature

revert-70aa11f8
dilanua 9 years ago
parent 2f2e8f391a
commit 7027a3553a

@ -46,4 +46,10 @@ public interface GadgetDataService {
@SuppressWarnings("unused") @SuppressWarnings("unused")
Map<String, Integer> getNonCompliantDeviceCountsByFeatures(); Map<String, Integer> getNonCompliantDeviceCountsByFeatures();
@SuppressWarnings("unused")
Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters);
@SuppressWarnings("unused")
Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters);
} }

@ -175,7 +175,7 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
} }
} }
stmt = con.prepareStatement(sql); stmt = con.prepareStatement(sql);
// [2] appending filter column values // [2] appending filter column values, if exist
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
if (filters != null && filters.values().size() > 0) { if (filters != null && filters.values().size() > 0) {
int i = 2; int i = 2;
@ -212,8 +212,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
con = this.getConnection(); con = this.getConnection();
String sql, advancedSqlFiltering = ""; String sql, advancedSqlFiltering = "";
// appending filters if exist, to support advanced filtering options // appending filters if exist, to support advanced filtering options
// [1] appending filter columns // [1] appending filter columns, if exist
if (filters.size() > 0) { if (filters != null && filters.size() > 0) {
for (String column : filters.keySet()) { for (String column : filters.keySet()) {
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? "; advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
} }
@ -227,16 +227,18 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
advancedSqlFiltering + "GROUP BY PLATFORM"; advancedSqlFiltering + "GROUP BY PLATFORM";
} }
stmt = con.prepareStatement(sql); stmt = con.prepareStatement(sql);
// [2] appending filter column values // [2] appending filter column values, if exist
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
int i = 2; if (filters != null && filters.values().size() > 0) {
for (Object value : filters.values()) { int i = 2;
if (value instanceof Integer) { for (Object value : filters.values()) {
stmt.setInt(i, (Integer) value); if (value instanceof Integer) {
} else if (value instanceof String) { stmt.setInt(i, (Integer) value);
stmt.setString(i, (String) value); } else if (value instanceof String) {
stmt.setString(i, (String) value);
}
i++;
} }
i++;
} }
// executing query // executing query
rs = stmt.executeQuery(); rs = stmt.executeQuery();
@ -262,37 +264,39 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
con = this.getConnection(); con = this.getConnection();
String sql, advancedSqlFiltering = ""; String sql, advancedSqlFiltering = "";
// appending filters if exist, to support advanced filtering options // appending filters if exist, to support advanced filtering options
// [1] appending filter columns // [1] appending filter columns, if exist
if (filters.size() > 0) { if (filters != null && filters.size() > 0) {
for (String column : filters.keySet()) { for (String column : filters.keySet()) {
advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? "; advancedSqlFiltering = advancedSqlFiltering + "AND " + column + " = ? ";
} }
} }
if (filteringViewID == 1) { if (filteringViewID == 1) {
sql = "SELECT PLATFORM, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ? " + sql = "SELECT OWNERSHIP, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_1 WHERE TENANT_ID = ? " +
advancedSqlFiltering + "GROUP BY OWNERSHIP"; advancedSqlFiltering + "GROUP BY OWNERSHIP";
} else { } else {
// if filteringViewID == 2 // if filteringViewID == 2
sql = "SELECT PLATFORM, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 WHERE TENANT_ID = ? " + sql = "SELECT OWNERSHIP, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 WHERE TENANT_ID = ? " +
advancedSqlFiltering + "GROUP BY OWNERSHIP"; advancedSqlFiltering + "GROUP BY OWNERSHIP";
} }
stmt = con.prepareStatement(sql); stmt = con.prepareStatement(sql);
// [2] appending filter column values // [2] appending filter column values, if exist
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
int i = 2; if (filters != null && filters.values().size() > 0) {
for (Object value : filters.values()) { int i = 2;
if (value instanceof Integer) { for (Object value : filters.values()) {
stmt.setInt(i, (Integer) value); if (value instanceof Integer) {
} else if (value instanceof String) { stmt.setInt(i, (Integer) value);
stmt.setString(i, (String) value); } else if (value instanceof String) {
stmt.setString(i, (String) value);
}
i++;
} }
i++;
} }
// executing query // executing query
rs = stmt.executeQuery(); rs = stmt.executeQuery();
// fetching query results // fetching query results
while (rs.next()) { while (rs.next()) {
filteredDeviceCountsByOwnershipTypes.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT")); filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT"));
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e);
@ -319,32 +323,34 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO {
sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_2 WHERE TENANT_ID = ?"; sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_2 WHERE TENANT_ID = ?";
} }
// appending filters to support advanced filtering options // appending filters to support advanced filtering options
// [1] appending filter columns // [1] appending filter columns, if exist
if (filters.size() > 0) { if (filters != null && filters.size() > 0) {
for (String column : filters.keySet()) { for (String column : filters.keySet()) {
sql = sql + " AND " + column + " = ?"; sql = sql + " AND " + column + " = ?";
} }
} }
stmt = con.prepareStatement(sql); stmt = con.prepareStatement(sql);
// [2] appending filter column values // [2] appending filter column values, if exist
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
int i = 2; if (filters != null && filters.values().size() > 0) {
for (Object value : filters.values()) { int i = 2;
if (value instanceof Integer) { for (Object value : filters.values()) {
stmt.setInt(i, (Integer) value); if (value instanceof Integer) {
} else if (value instanceof String) { stmt.setInt(i, (Integer) value);
stmt.setString(i, (String) value); } else if (value instanceof String) {
stmt.setString(i, (String) value);
}
i++;
} }
i++;
} }
// executing query // executing query
rs = stmt.executeQuery(); rs = stmt.executeQuery();
// fetching query results // fetching query results
while (rs.next()) { while (rs.next()) {
filteredDeviceWithDetails.put("Device-ID", rs.getInt("DEVICE_ID")); filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID"));
filteredDeviceWithDetails.put("Platform", rs.getString("PLATFORM")); filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM"));
filteredDeviceWithDetails.put("Ownership", rs.getString("OWNERSHIP")); filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP"));
filteredDeviceWithDetails.put("Connectivity-Details", rs.getString("CONNECTIVITY_STATUS")); filteredDeviceWithDetails.put("connectivity-details", rs.getString("CONNECTIVITY_STATUS"));
filteredDevicesWithDetails.add(filteredDeviceWithDetails); filteredDevicesWithDetails.add(filteredDeviceWithDetails);
} }
} catch (SQLException e) { } catch (SQLException e) {

@ -146,4 +146,34 @@ class GadgetDataServiceImpl implements GadgetDataService {
return nonCompliantDeviceCountsByFeatures; return nonCompliantDeviceCountsByFeatures;
} }
@Override
public Map<String, Integer> getDeviceCountsByPlatforms(Map<String, Object> filters) {
Map<String, Integer> deviceCountsByPlatforms = null;
try {
GadgetDataServiceDAOFactory.openConnection();
deviceCountsByPlatforms = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getDeviceCountsByPlatforms(filters);
} catch (GadgetDataServiceDAOException | SQLException e) {
return null;
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return deviceCountsByPlatforms;
}
@Override
public Map<String, Integer> getDeviceCountsByOwnershipTypes(Map<String, Object> filters) {
Map<String, Integer> deviceCountsByOwnershipTypes = null;
try {
GadgetDataServiceDAOFactory.openConnection();
deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.
getGadgetDataServiceDAO().getDeviceCountsByOwnershipTypes(filters);
} catch (GadgetDataServiceDAOException | SQLException e) {
return null;
} finally {
GadgetDataServiceDAOFactory.closeConnection();
}
return deviceCountsByOwnershipTypes;
}
} }

Loading…
Cancel
Save