From 6f9851413ef64ba2d49a52aeee107f3af7810d27 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Thu, 28 Apr 2016 19:53:42 +0530 Subject: [PATCH 01/13] Adding the changes for operation activity id --- .../device/mgt/common/operation/mgt/Operation.java | 9 +++++++++ .../mgt/common/operation/mgt/OperationManager.java | 2 ++ .../device/mgt/core/DeviceManagementConstants.java | 5 +++++ .../mgt/core/operation/mgt/OperationManagerImpl.java | 11 +++++++++++ .../core/operation/mgt/dao/util/OperationDAOUtil.java | 2 ++ .../service/DeviceManagementProviderServiceImpl.java | 5 +++++ 6 files changed, 34 insertions(+) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java index 5f141c44d5..e5022670b3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java @@ -44,6 +44,7 @@ public class Operation implements Serializable { private boolean isEnabled; private Object payLoad; private String operationResponse; + private String activityId; @Override public boolean equals(Object o) { @@ -191,6 +192,14 @@ public class Operation implements Serializable { this.operationResponse = operationResponse; } + public String getActivityId() { + return activityId; + } + + public void setActivityId(String activityId) { + this.activityId = activityId; + } + @Override public String toString() { return "Operation{" + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java index 1d86b618f8..26ed93bddb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/OperationManager.java @@ -85,4 +85,6 @@ public interface OperationManager { Operation getOperation(int operationId) throws OperationManagementException; + Operation getOperationByActivityId(String activity) throws OperationManagementException; + } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java index ad4a8e64ee..379ca8c3d6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java @@ -75,4 +75,9 @@ public final class DeviceManagementConstants { public static final String DOWNLOAD_URL = "download-url"; } + public static final class OperationAttributes { + private OperationAttributes() {throw new AssertionError(); } + public static final String ACTIVITY = "ACTIVITY_"; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 265dd02f8c..5281bed162 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -648,6 +648,17 @@ public class OperationManagerImpl implements OperationManager { return operation; } + @Override + public Operation getOperationByActivityId(String activity) throws OperationManagementException { + // This parses the operation id from activity id (ex : ACTIVITY_23) and converts to the integer. + int operationId = Integer.parseInt( + activity.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, "")); + if(operationId == 0){ + throw new IllegalArgumentException("Operation ID cannot be null or zero (0)."); + } + return this.getOperation(operationId); + } + private OperationDAO lookupOperationDAO(Operation operation) { if (operation instanceof CommandOperation) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java index 44a93761a7..20485921bb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java @@ -18,6 +18,7 @@ */ package org.wso2.carbon.device.mgt.core.operation.mgt.dao.util; +import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.*; public class OperationDAOUtil { @@ -94,6 +95,7 @@ public class OperationDAOUtil { operation.setReceivedTimeStamp(dtoOperation.getReceivedTimeStamp()); operation.setEnabled(dtoOperation.isEnabled()); operation.setProperties(dtoOperation.getProperties()); + operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + dtoOperation.getId()); return operation; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 88bd74cdaa..9d5e6b46d5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -867,6 +867,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv return DeviceManagementDataHolder.getInstance().getOperationManager().getOperation(operationId); } + @Override + public Operation getOperationByActivityId(String activity) throws OperationManagementException { + return DeviceManagementDataHolder.getInstance().getOperationManager().getOperationByActivityId(activity); + } + @Override public List getDevicesOfUser(String username) throws DeviceManagementException { List devices = new ArrayList<>(); From 3396a5066d0204bf871c48f4f95905a738166194 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Fri, 29 Apr 2016 22:30:07 +0530 Subject: [PATCH 02/13] Adding changes for the updated time of device info and device location --- .../mgt/common/device/details/DeviceInfo.java | 13 +++++ .../common/device/details/DeviceLocation.java | 13 +++++ .../mgt/dao/impl/DeviceDetailsDAOImpl.java | 10 ++-- .../operation/mgt/OperationManagerImpl.java | 2 +- .../device/mgt/core/search/mgt/Processor.java | 2 + .../mgt/core/search/mgt/QueryBuilder.java | 2 + .../core/search/mgt/SearchManagerService.java | 2 + .../search/mgt/dao/impl/SearchDAOImpl.java | 12 ++--- .../core/search/mgt/impl/ProcessorImpl.java | 22 ++++++++ .../search/mgt/impl/QueryBuilderImpl.java | 16 ++++-- .../mgt/impl/SearchManagerServiceImpl.java | 5 ++ .../src/test/resources/sql/h2.sql | 2 + .../src/test/resources/sql/CreateH2TestDB.sql | 2 + .../src/main/resources/dbscripts/cdm/h2.sql | 2 + .../main/resources/dbscripts/cdm/mssql.sql | 52 +++++++++++++------ .../main/resources/dbscripts/cdm/mysql.sql | 2 + .../main/resources/dbscripts/cdm/oracle.sql | 49 +++++++++++++---- .../resources/dbscripts/cdm/postgresql.sql | 26 +++++++++- 18 files changed, 190 insertions(+), 44 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java index dc6bcd886a..92af0d4544 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceInfo.java @@ -22,6 +22,7 @@ package org.wso2.carbon.device.mgt.common.device.details; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import java.io.Serializable; +import java.util.Date; import java.util.HashMap; import java.util.Map; @@ -51,6 +52,7 @@ public class DeviceInfo implements Serializable { private Double totalRAMMemory; private Double availableRAMMemory; private boolean pluggedIn; + private Date updatedTime; private Map deviceDetailsMap = new HashMap<>(); @@ -290,6 +292,17 @@ public class DeviceInfo implements Serializable { this.pluggedIn = pluggedIn; } + public Date getUpdatedTime() { + if(updatedTime.equals(null)){ + updatedTime = new Date(); + } + return updatedTime; + } + + public void setUpdatedTime(Date updatedTime) { + this.updatedTime = updatedTime; + } + public void setDeviceDetailsMap(Map deviceDetailsMap) { this.deviceDetailsMap = deviceDetailsMap; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java index 0b05406522..1368b92806 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/device/details/DeviceLocation.java @@ -22,6 +22,7 @@ package org.wso2.carbon.device.mgt.common.device.details; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import java.io.Serializable; +import java.util.Date; public class DeviceLocation implements Serializable { @@ -39,6 +40,7 @@ public class DeviceLocation implements Serializable { private String state; private String zip; private String country; + private Date updatedTime; public int getDeviceId() { return deviceId; @@ -119,5 +121,16 @@ public class DeviceLocation implements Serializable { public void setCountry(String country) { this.country = country; } + + public Date getUpdatedTime() { + if(updatedTime.equals(null)){ + updatedTime = new Date(); + } + return updatedTime; + } + + public void setUpdatedTime(Date updatedTime) { + this.updatedTime = updatedTime; + } } 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 cd901b2238..3b392cc820 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 @@ -50,8 +50,8 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_DETAIL (DEVICE_ID, DEVICE_MODEL, " + "VENDOR, OS_VERSION, BATTERY_LEVEL, INTERNAL_TOTAL_MEMORY, INTERNAL_AVAILABLE_MEMORY, " + "EXTERNAL_TOTAL_MEMORY, EXTERNAL_AVAILABLE_MEMORY, CONNECTION_TYPE, " + - "SSID, CPU_USAGE, TOTAL_RAM_MEMORY, AVAILABLE_RAM_MEMORY, PLUGGED_IN) " + - "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + "SSID, CPU_USAGE, TOTAL_RAM_MEMORY, AVAILABLE_RAM_MEMORY, PLUGGED_IN, UPDATE_TIMESTAMP) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); stmt.setInt(1, deviceInfo.getDeviceId()); stmt.setString(2, deviceInfo.getDeviceModel()); @@ -68,6 +68,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { stmt.setDouble(13, deviceInfo.getTotalRAMMemory()); stmt.setDouble(14, deviceInfo.getAvailableRAMMemory()); stmt.setBoolean(15, deviceInfo.isPluggedIn()); + stmt.setLong(16, System.currentTimeMillis()); stmt.execute(); @@ -144,6 +145,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY")); deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); + deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP"))); } deviceInfo.setDeviceId(deviceId); @@ -226,7 +228,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { try { conn = this.getConnection(); stmt = conn.prepareStatement("INSERT INTO DM_DEVICE_LOCATION (DEVICE_ID, LATITUDE, LONGITUDE, STREET1, " + - "STREET2, CITY, ZIP, STATE, COUNTRY) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"); + "STREET2, CITY, ZIP, STATE, COUNTRY, UPDATE_TIMESTAMP) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); stmt.setInt(1, deviceLocation.getDeviceId()); stmt.setDouble(2, deviceLocation.getLatitude()); stmt.setDouble(3, deviceLocation.getLongitude()); @@ -236,6 +238,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { stmt.setString(7, deviceLocation.getZip()); stmt.setString(8, deviceLocation.getState()); stmt.setString(9, deviceLocation.getCountry()); + stmt.setLong(10, System.currentTimeMillis()); stmt.execute(); } catch (SQLException e) { throw new DeviceDetailsMgtDAOException("Error occurred while adding the device location to database.", e); @@ -268,6 +271,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { location.setZip(rs.getString("ZIP")); location.setState(rs.getString("STATE")); location.setCountry(rs.getString("COUNTRY")); + location.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP"))); } location.setDeviceId(deviceId); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 5281bed162..6ea7adbf59 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -613,7 +613,7 @@ public class OperationManagerImpl implements OperationManager { public Operation getOperation(int operationId) throws OperationManagementException { Operation operation; try { - OperationManagementDAOFactory.getConnection(); + OperationManagementDAOFactory.openConnection(); org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO. getOperation(operationId); if (dtoOperation == null) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/Processor.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/Processor.java index 88affab477..4c7058be02 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/Processor.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/Processor.java @@ -28,4 +28,6 @@ import java.util.List; public interface Processor { List execute(SearchContext searchContext) throws SearchMgtException; + + List getUpdatedDevices(long epochTime) throws SearchMgtException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/QueryBuilder.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/QueryBuilder.java index db028edc19..c3e912fcb8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/QueryBuilder.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/QueryBuilder.java @@ -38,4 +38,6 @@ public interface QueryBuilder { List processORProperties(List conditions) throws InvalidOperatorException; + String processUpdatedDevices(long epochTime) throws InvalidOperatorException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/SearchManagerService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/SearchManagerService.java index ad78ca171f..554ecfc0f9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/SearchManagerService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/SearchManagerService.java @@ -27,5 +27,7 @@ import java.util.List; public interface SearchManagerService { List search(SearchContext searchContext) throws SearchMgtException; + + List getUpdated(long epochTime) throws SearchMgtException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/dao/impl/SearchDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/dao/impl/SearchDAOImpl.java index e80da38167..caf6f1929a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/dao/impl/SearchDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/dao/impl/SearchDAOImpl.java @@ -78,17 +78,14 @@ public class SearchDAOImpl implements SearchDAO { deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY")); deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); -// deviceInfo.setIMEI(rs.getString("IMEI")); -// deviceInfo.setIMSI(rs.getString("IMSI")); deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); -// deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH")); -// deviceInfo.setOperator(rs.getString("OPERATOR")); deviceInfo.setOsVersion(rs.getString("OS_VERSION")); deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); deviceInfo.setSsid(rs.getString("SSID")); deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); deviceInfo.setVendor(rs.getString("VENDOR")); + deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP"))); DeviceLocation deviceLocation = new DeviceLocation(); deviceLocation.setLatitude(rs.getDouble("LATITUDE")); @@ -100,6 +97,7 @@ public class SearchDAOImpl implements SearchDAO { deviceLocation.setZip(rs.getString("ZIP")); deviceLocation.setCountry(rs.getString("COUNTRY")); deviceLocation.setDeviceId(rs.getInt("ID")); + deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP"))); DeviceWrapper wrapper = new DeviceWrapper(); wrapper.setDevice(device); @@ -160,17 +158,14 @@ public class SearchDAOImpl implements SearchDAO { deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY")); deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); -// deviceInfo.setIMEI(rs.getString("IMEI")); -// deviceInfo.setIMSI(rs.getString("IMSI")); deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); -// deviceInfo.setMobileSignalStrength(rs.getDouble("MOBILE_SIGNAL_STRENGTH")); -// deviceInfo.setOperator(rs.getString("OPERATOR")); deviceInfo.setOsVersion(rs.getString("OS_VERSION")); deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); deviceInfo.setSsid(rs.getString("SSID")); deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); deviceInfo.setVendor(rs.getString("VENDOR")); + deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP"))); DeviceLocation deviceLocation = new DeviceLocation(); deviceLocation.setLatitude(rs.getDouble("LATITUDE")); @@ -182,6 +177,7 @@ public class SearchDAOImpl implements SearchDAO { deviceLocation.setZip(rs.getString("ZIP")); deviceLocation.setCountry(rs.getString("COUNTRY")); deviceLocation.setDeviceId(rs.getInt("ID")); + deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP"))); DeviceWrapper wrapper = new DeviceWrapper(); wrapper.setDevice(device); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ProcessorImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ProcessorImpl.java index 4a97f1fdbe..55b377d4f5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ProcessorImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ProcessorImpl.java @@ -94,6 +94,28 @@ public class ProcessorImpl implements Processor { return aggregator.aggregate(deviceWrappers); } + @Override + public List getUpdatedDevices(long epochTime) throws SearchMgtException { + + if((1 + (int)Math.floor(Math.log10(epochTime))) <=10 ) { + epochTime = epochTime * 1000; + } + QueryBuilder queryBuilder = new QueryBuilderImpl(); + try { + String query = queryBuilder.processUpdatedDevices(epochTime); + DeviceManagementDAOFactory.openConnection(); + return searchDAO.searchDeviceDetailsTable(query); + } catch (InvalidOperatorException e) { + throw new SearchMgtException("Invalid operator was provided, so cannot execute the search.", e); + } catch (SQLException e) { + throw new SearchMgtException("Error occurred while managing database transactions.", e); + } catch (SearchDAOException e) { + throw new SearchMgtException("Error occurred while running the search operations for given time.", e); + } finally { + DeviceManagementDAOFactory.closeConnection(); + } + } + private List processANDSearch(List> deLists) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java index eaca48451f..60b46271c2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java @@ -158,6 +158,12 @@ public class QueryBuilderImpl implements QueryBuilder { return this.getQueryList(conditions); } + @Override + public String processUpdatedDevices(long epochTime) throws InvalidOperatorException { + return this.getGenericQueryPart() + " AND ( DD.UPDATE_TIMESTAMP > " + epochTime + + " OR DL.UPDATE_TIMESTAMP > " + epochTime + " )"; + } + private List getQueryList(List conditions) { List queryList = new ArrayList<>(); for (Condition con : conditions) { @@ -189,8 +195,9 @@ public class QueryBuilderImpl implements QueryBuilder { "DD.OS_VERSION, DD.BATTERY_LEVEL, DD.INTERNAL_TOTAL_MEMORY, DD.INTERNAL_AVAILABLE_MEMORY,\n" + "DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" + "DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" + - "DD.PLUGGED_IN, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" + - "DL.STATE, DL.COUNTRY FROM DM_DEVICE_DETAIL AS DD, DM_DEVICE AS D, DM_DEVICE_LOCATION AS DL, " + + "DD.PLUGGED_IN, DD.UPDATE_TIMESTAMP, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" + + "DL.STATE, DL.COUNTRY, DL.UPDATE_TIMESTAMP AS DL_UPDATED_TIMESTAMP " + + "FROM DM_DEVICE_DETAIL AS DD, DM_DEVICE AS D, DM_DEVICE_LOCATION AS DL, " + "DM_DEVICE_TYPE AS DT WHERE DEVICE_TYPE_ID=D.DEVICE_TYPE_ID AND D.TENANT_ID = " + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); @@ -205,8 +212,9 @@ public class QueryBuilderImpl implements QueryBuilder { "DD.OS_VERSION, DD.BATTERY_LEVEL, DD.INTERNAL_TOTAL_MEMORY, DD.INTERNAL_AVAILABLE_MEMORY,\n" + "DD.EXTERNAL_TOTAL_MEMORY, DD.EXTERNAL_AVAILABLE_MEMORY, DD.CONNECTION_TYPE, \n" + "DD.SSID, DD.CPU_USAGE, DD.TOTAL_RAM_MEMORY, DD.AVAILABLE_RAM_MEMORY, \n" + - "DD.PLUGGED_IN, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" + - "DL.STATE, DL.COUNTRY, DI.KEY_FIELD, DI.VALUE_FIELD FROM DM_DEVICE_DETAIL AS DD, " + + "DD.PLUGGED_IN, DD.UPDATE_TIMESTAMP, DL.LATITUDE, DL.LONGITUDE, DL.STREET1, DL.STREET2, DL.CITY, DL.ZIP, \n" + + "DL.STATE, DL.COUNTRY, DL.UPDATE_TIMESTAMP AS DL_UPDATED_TIMESTAMP, " + + "DI.KEY_FIELD, DI.VALUE_FIELD FROM DM_DEVICE_DETAIL AS DD, " + "DM_DEVICE AS D, DM_DEVICE_LOCATION AS DL, \n" + "DM_DEVICE_INFO AS DI, DM_DEVICE_TYPE AS DT WHERE DEVICE_TYPE_ID=D.DEVICE_TYPE_ID AND D.TENANT_ID = " + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/SearchManagerServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/SearchManagerServiceImpl.java index 888f3edc36..cc9a51d919 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/SearchManagerServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/SearchManagerServiceImpl.java @@ -40,5 +40,10 @@ public class SearchManagerServiceImpl implements SearchManagerService { public List search(SearchContext searchContext) throws SearchMgtException { return processor.execute(searchContext); } + + @Override + public List getUpdated(long epochTime) throws SearchMgtException { + return processor.getUpdatedDevices(epochTime); + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql index 23a88af804..7d6159a87f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/sql/h2.sql @@ -451,6 +451,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( ZIP VARCHAR(10) NULL, STATE VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL, + UPDATE_TIMESTAMP BIGINT(15) NOT NULL, PRIMARY KEY (ID), CONSTRAINT DM_DEVICE_LOCATION_DEVICE FOREIGN KEY (DEVICE_ID) @@ -477,6 +478,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, PLUGGED_IN INT(1) NULL, + UPDATE_TIMESTAMP BIGINT(15) NOT NULL, PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE FOREIGN KEY (DEVICE_ID) diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql index 23a88af804..7d6159a87f 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql @@ -451,6 +451,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( ZIP VARCHAR(10) NULL, STATE VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL, + UPDATE_TIMESTAMP BIGINT(15) NOT NULL, PRIMARY KEY (ID), CONSTRAINT DM_DEVICE_LOCATION_DEVICE FOREIGN KEY (DEVICE_ID) @@ -477,6 +478,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, PLUGGED_IN INT(1) NULL, + UPDATE_TIMESTAMP BIGINT(15) NOT NULL, PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE FOREIGN KEY (DEVICE_ID) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql index 3067b30030..deabce4756 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -451,6 +451,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( ZIP VARCHAR(10) NULL, STATE VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL, + UPDATE_TIMESTAMP BIGINT(15) NOT NULL, PRIMARY KEY (ID), CONSTRAINT DM_DEVICE_LOCATION_DEVICE FOREIGN KEY (DEVICE_ID) @@ -477,6 +478,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, PLUGGED_IN INT(1) NULL, + UPDATE_TIMESTAMP BIGINT(15) NOT NULL, PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE FOREIGN KEY (DEVICE_ID) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql index 69989f5168..6101c9e5a8 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -341,6 +341,24 @@ CREATE TABLE DM_POLICY_COMPLIANCE_FEATURES ( ON UPDATE NO ACTION ); +CREATE TABLE DM_DEVICE_GROUP_POLICY ( + ID INT NOT NULL IDENTITY, + DEVICE_GROUP_ID INT NOT NULL, + POLICY_ID INT NOT NULL, + TENANT_ID INT NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT FK_DM_DEVICE_GROUP_POLICY + FOREIGN KEY (DEVICE_GROUP_ID) + REFERENCES DM_GROUP (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY + FOREIGN KEY (POLICY_ID , DEVICE_GROUP_ID) + REFERENCES DM_POLICY (ID , ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + CREATE TABLE DM_APPLICATION ( ID INTEGER IDENTITY NOT NULL, NAME VARCHAR(150) NOT NULL, @@ -390,13 +408,12 @@ CREATE TABLE DM_NOTIFICATION ( DROP TABLE IF EXISTS DM_DEVICE_INFO; -CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO ( - ID INTEGER AUTO_INCREMENT NOT NULL, - DEVICE_ID INTEGER NULL, +CREATE TABLE DM_DEVICE_INFO ( + ID INTEGER IDENTITY NOT NULL, + DEVICE_ID INT NULL, KEY_FIELD VARCHAR(45) NULL, VALUE_FIELD VARCHAR(100) NULL, PRIMARY KEY (ID), - INDEX DM_DEVICE_INFO_DEVICE_idx (DEVICE_ID ASC), CONSTRAINT DM_DEVICE_INFO_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID) @@ -404,23 +421,23 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO ( ON UPDATE NO ACTION ); - +CREATE INDEX DM_DEVICE_INFO_DEVICE_idx ON DM_DEVICE_INFO (DEVICE_ID ASC); DROP TABLE IF EXISTS DM_DEVICE_LOCATION; -CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( - ID INTEGER AUTO_INCREMENT NOT NULL, - DEVICE_ID INTEGER NULL, - LATITUDE DOUBLE NULL, - LONGITUDE DOUBLE NULL, +CREATE TABLE DM_DEVICE_LOCATION ( + ID INTEGER IDENTITY NOT NULL, + DEVICE_ID INT NULL, + LATITUDE FLOAT NULL, + LONGITUDE FLOAT NULL, STREET1 VARCHAR(45) NULL, STREET2 VARCHAR(45) NULL, CITY VARCHAR(45) NULL, ZIP VARCHAR(10) NULL, STATE VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL, + UPDATE_TIMESTAMP BIGINT NOT NULL, PRIMARY KEY (ID), - INDEX DM_DEVICE_LOCATION_DEVICE_idx (DEVICE_ID ASC), CONSTRAINT DM_DEVICE_LOCATION_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID) @@ -428,11 +445,12 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( ON UPDATE NO ACTION ); +CREATE INDEX DM_DEVICE_LOCATION_DEVICE_idx ON DM_DEVICE_LOCATION (DEVICE_ID ASC); -DROP TABLE IF EXISTS DM_DEVICE_DETAIL ; +DROP TABLE IF EXISTS DM_DEVICE_DETAIL; -CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( - ID INT NOT NULL AUTO_INCREMENT, +CREATE TABLE DM_DEVICE_DETAIL ( + ID INT NOT NULL IDENTITY, DEVICE_ID INT NOT NULL, DEVICE_MODEL VARCHAR(45) NULL, VENDOR VARCHAR(45) NULL, @@ -447,9 +465,9 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( CPU_USAGE DECIMAL(5) NULL, TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, - PLUGGED_IN INT(1) NULL, + PLUGGED_IN INT NULL, + UPDATE_TIMESTAMP BIGINT NOT NULL, PRIMARY KEY (ID), - INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx (DEVICE_ID ASC), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID) @@ -457,3 +475,5 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( ON UPDATE NO ACTION ); +CREATE INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx ON DM_DEVICE_DETAIL (DEVICE_ID ASC); + diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql index 066e59c8c2..7d3eada22e 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -482,6 +482,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( ZIP VARCHAR(10) NULL, STATE VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL, + UPDATE_TIMESTAMP BIGINT(15) NOT NULL, PRIMARY KEY (ID), INDEX DM_DEVICE_LOCATION_DEVICE_idx (DEVICE_ID ASC), CONSTRAINT DM_DEVICE_LOCATION_DEVICE @@ -513,6 +514,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, PLUGGED_IN INT(1) NULL, + UPDATE_TIMESTAMP BIGINT(15) NOT NULL, PRIMARY KEY (ID), INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx (DEVICE_ID ASC), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql index e47cd11440..fa9ac2e783 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -568,6 +568,34 @@ WHEN (NEW.ID IS NULL) END; / + +CREATE TABLE DM_DEVICE_GROUP_POLICY ( + ID NUMBER(10) NOT NULL, + DEVICE_GROUP_ID NUMBER(10) NOT NULL, + POLICY_ID NUMBER(10) NOT NULL, + TENANT_ID NUMBER(10) NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT FK_DM_DEVICE_GROUP_POLICY + FOREIGN KEY (DEVICE_GROUP_ID) + REFERENCES DM_GROUP (ID) + , + CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY + FOREIGN KEY (POLICY_ID , DEVICE_GROUP_ID) + REFERENCES DM_POLICY (ID , ID) +) ; + +-- Generate ID using sequence and trigger +CREATE SEQUENCE DM_DEVICE_GROUP_POLICY_seq START WITH 1 INCREMENT BY 1; + +CREATE OR REPLACE TRIGGER DM_DEVICE_GROUP_POLICY_seq_tr + BEFORE INSERT ON DM_DEVICE_GROUP_POLICY FOR EACH ROW + WHEN (NEW.ID IS NULL) +BEGIN + SELECT DM_DEVICE_GROUP_POLICY_seq.NEXTVAL INTO :NEW.ID FROM DUAL; +END; +/ + + CREATE TABLE DM_APPLICATION ( ID NUMBER(10) NOT NULL, NAME VARCHAR2(150) NOT NULL, @@ -714,6 +742,7 @@ CREATE TABLE DM_DEVICE_LOCATION ( ZIP VARCHAR2(10) NULL, STATE VARCHAR2(45) NULL, COUNTRY VARCHAR2(45) NULL, + UPDATE_TIMESTAMP NUMBER(19) NOT NULL, PRIMARY KEY (ID) , CONSTRAINT DM_DEVICE_LOCATION_DEVICE @@ -751,23 +780,22 @@ CREATE TABLE DM_DEVICE_DETAIL ( VENDOR VARCHAR2(45) NULL, OS_VERSION VARCHAR2(45) NULL, BATTERY_LEVEL NUMBER(4) NULL, - INTERNAL_TOTAL_MEMORY NUMBER(30) NULL, - INTERNAL_AVAILABLE_MEMORY NUMBER(30) NULL, - EXTERNAL_TOTAL_MEMORY NUMBER(30) NULL, - EXTERNAL_AVAILABLE_MEMORY NUMBER(30) NULL, + INTERNAL_TOTAL_MEMORY NUMBER(30,3) NULL, + INTERNAL_AVAILABLE_MEMORY NUMBER(30,3) NULL, + EXTERNAL_TOTAL_MEMORY NUMBER(30,3) NULL, + EXTERNAL_AVAILABLE_MEMORY NUMBER(30,3) NULL, CONNECTION_TYPE VARCHAR2(10) NULL, SSID VARCHAR2(45) NULL, CPU_USAGE NUMBER(5) NULL, - TOTAL_RAM_MEMORY NUMBER(30) NULL, - AVAILABLE_RAM_MEMORY NUMBER(30) NULL, + TOTAL_RAM_MEMORY NUMBER(30,3) NULL, + AVAILABLE_RAM_MEMORY NUMBER(30,3) NULL, PLUGGED_IN NUMBER(10) NULL, - PRIMARY KEY (ID) - , + UPDATE_TIMESTAMP NUMBER(19) NOT NULL, + PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID) - ) - ; +); -- Generate ID using sequence and trigger CREATE SEQUENCE DM_DEVICE_DETAIL_seq START WITH 1 INCREMENT BY 1; @@ -782,4 +810,3 @@ END; CREATE INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx ON DM_DEVICE_DETAIL (DEVICE_ID ASC); - diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 431fe0e40a..5fcf3f99ac 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -292,6 +292,26 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES ( ON UPDATE NO ACTION ); +CREATE SEQUENCE DM_DEVICE_GROUP_POLICY_seq; + +CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY ( + ID INT NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_GROUP_POLICY_seq'), + DEVICE_GROUP_ID INT NOT NULL, + POLICY_ID INT NOT NULL, + TENANT_ID INT NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT FK_DM_DEVICE_GROUP_POLICY + FOREIGN KEY (DEVICE_GROUP_ID) + REFERENCES DM_GROUP (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY + FOREIGN KEY (POLICY_ID , DEVICE_GROUP_ID) + REFERENCES DM_POLICY (ID , ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( ID BIGSERIAL NOT NULL PRIMARY KEY, DEVICE_ID INTEGER NOT NULL, @@ -379,6 +399,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( ZIP VARCHAR(10) NULL, STATE VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL, + UPDATE_TIMESTAMP BIGINT NOT NULL, PRIMARY KEY (ID) , CONSTRAINT DM_DEVICE_LOCATION_DEVICE FOREIGN KEY (DEVICE_ID) @@ -390,6 +411,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( CREATE INDEX DM_DEVICE_LOCATION_DEVICE_idx ON DM_DEVICE_LOCATION (DEVICE_ID ASC); +CREATE SEQUENCE DM_DEVICE_DETAIL_seq; + CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( ID INT NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_DETAIL_seq'), DEVICE_ID INT NOT NULL, @@ -407,7 +430,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, PLUGGED_IN INT NULL, - PRIMARY KEY (ID) , + UPDATE_TIMESTAMP BIGINT NOT NULL, + PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID) From c0dd2c423efd86a9af18d515db4ba2fa9cf69d70 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Fri, 29 Apr 2016 22:44:01 +0530 Subject: [PATCH 03/13] Fixing the build failure on java 8 --- .../org.wso2.carbon.device.mgt.oauth.extensions/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml index a40e30b63f..c08f127404 100644 --- a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml @@ -88,6 +88,7 @@ org.wso2.carbon.device.mgt.* org.wso2.carbon.identity.application.common.model, org.wso2.carbon.identity.oauth.callback, + org.wso2.carbon.identity.oauth.common, org.wso2.carbon.identity.oauth2, org.wso2.carbon.identity.oauth2.model, org.wso2.carbon.identity.oauth2.validators, From 486190f1829b1fa56ec1b4bedc22279e70500788 Mon Sep 17 00:00:00 2001 From: inosh-perera Date: Sat, 30 Apr 2016 14:44:22 +0530 Subject: [PATCH 04/13] adding more error logs for client certificate not present scenario --- .../framework/authenticator/CertificateAuthenticator.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java index 879efecd80..6b40e2022b 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/src/main/java/org/wso2/carbon/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java @@ -60,7 +60,7 @@ public class CertificateAuthenticator implements WebappAuthenticator { if (request.getHeader(MUTUAL_AUTH_HEADER) != null) { X509Certificate[] clientCertificate = (X509Certificate[]) request. getAttribute(CLIENT_CERTIFICATE_ATTRIBUTE); - if (clientCertificate[0] != null) { + if (clientCertificate != null && clientCertificate[0] != null) { CertificateResponse certificateResponse = AuthenticatorFrameworkDataHolder.getInstance(). getCertificateManagementService().verifyPEMSignature(clientCertificate[0]); if (certificateResponse == null) { @@ -86,6 +86,9 @@ public class CertificateAuthenticator implements WebappAuthenticator { "but the serial number is missing in the database."); } + } else { + authenticationInfo.setStatus(Status.FAILURE); + authenticationInfo.setMessage("No client certificate is present"); } } else if (request.getHeader(CERTIFICATE_VERIFICATION_HEADER) != null) { From f2128762f03945c77e88c1a06baef4384d5be56c Mon Sep 17 00:00:00 2001 From: geethkokila Date: Sat, 30 Apr 2016 19:37:23 +0530 Subject: [PATCH 05/13] Adding the changes for removing repeated operations from pending operations, if same operation is added twice, are making them repeated, Device will not recieve them --- .../mgt/common/operation/mgt/Operation.java | 21 ++++++++++- .../dto/operation/mgt/CommandOperation.java | 4 +++ .../dto/operation/mgt/ConfigOperation.java | 5 +++ .../mgt/core/dto/operation/mgt/Operation.java | 17 +++++++-- .../dto/operation/mgt/PolicyOperation.java | 4 +++ .../dto/operation/mgt/ProfileOperation.java | 5 +++ .../core/operation/mgt/CommandOperation.java | 3 ++ .../core/operation/mgt/ConfigOperation.java | 4 +++ .../operation/mgt/OperationManagerImpl.java | 6 ++++ .../core/operation/mgt/PolicyOperation.java | 4 +++ .../core/operation/mgt/ProfileOperation.java | 4 +++ .../core/operation/mgt/dao/OperationDAO.java | 3 ++ .../mgt/dao/impl/GenericOperationDAOImpl.java | 35 +++++++++++++++++++ .../mgt/dao/util/OperationDAOUtil.java | 1 + 14 files changed, 112 insertions(+), 4 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java index e5022670b3..3496bacb8c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/operation/mgt/Operation.java @@ -31,7 +31,11 @@ public class Operation implements Serializable { } public enum Status { - IN_PROGRESS, PENDING, COMPLETED, ERROR + IN_PROGRESS, PENDING, COMPLETED, ERROR, REPEATED + } + + public enum Control { + REPEAT, NO_REPEAT, PAUSE_SEQUENCE, STOP_SEQUENCE } private String code; @@ -39,6 +43,7 @@ public class Operation implements Serializable { private Type type; private int id; private Status status; + private Control control; private String receivedTimeStamp; private String createdTimeStamp; private boolean isEnabled; @@ -88,6 +93,11 @@ public class Operation implements Serializable { if (status != operation.status) { return false; } + + if(control != operation.control){ + return false; + } + if (type != operation.type) { return false; } @@ -152,6 +162,14 @@ public class Operation implements Serializable { this.status = status; } + public Control getControl() { + return control; + } + + public void setControl(Control control) { + this.control = control; + } + public String getReceivedTimeStamp() { return receivedTimeStamp; } @@ -207,6 +225,7 @@ public class Operation implements Serializable { ", type=" + type + ", id=" + id + ", status=" + status + + ", control=" + control + ", receivedTimeStamp='" + receivedTimeStamp + '\'' + ", createdTimeStamp='" + createdTimeStamp + '\'' + ", isEnabled=" + isEnabled + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/CommandOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/CommandOperation.java index 28c43cd6bd..bc132a9b20 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/CommandOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/CommandOperation.java @@ -34,4 +34,8 @@ public class CommandOperation extends Operation { return Type.COMMAND; } + public Control getControl(){ + return Control.NO_REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ConfigOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ConfigOperation.java index bd4fc50ae6..c2be65a372 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ConfigOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ConfigOperation.java @@ -77,4 +77,9 @@ public class ConfigOperation extends Operation { return Type.CONFIG; } + + public Control getControl(){ + return Control.REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java index 37e0736eb5..360deb868a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/Operation.java @@ -18,8 +18,6 @@ */ package org.wso2.carbon.device.mgt.core.dto.operation.mgt; -import javax.xml.bind.annotation.XmlElement; -import javax.xml.bind.annotation.XmlRootElement; import java.io.Serializable; import java.util.Properties; @@ -30,7 +28,11 @@ public class Operation implements Serializable { } public enum Status { - IN_PROGRESS, PENDING, COMPLETED, ERROR + IN_PROGRESS, PENDING, COMPLETED, ERROR, REPEATED + } + + public enum Control { + REPEAT, NO_REPEAT, PAUSE_SEQUENCE, STOP_SEQUENCE } private String code; @@ -38,6 +40,7 @@ public class Operation implements Serializable { private Type type; private int id; private Status status; + private Control control; private String receivedTimeStamp; private String createdTimeStamp; private boolean isEnabled; @@ -84,6 +87,14 @@ public class Operation implements Serializable { this.status = status; } + public Control getControl() { + return control; + } + + public void setControl(Control control) { + this.control = control; + } + public String getReceivedTimeStamp() { return receivedTimeStamp; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/PolicyOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/PolicyOperation.java index f1d97a0dd0..dc6ae4dd78 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/PolicyOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/PolicyOperation.java @@ -31,4 +31,8 @@ public class PolicyOperation extends Operation{ private List profileOperations; + public Control getControl(){ + return Control.REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ProfileOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ProfileOperation.java index 61bb18d698..107cf091d7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ProfileOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dto/operation/mgt/ProfileOperation.java @@ -26,4 +26,9 @@ public class ProfileOperation extends ConfigOperation implements Serializable { return Type.PROFILE; } + + public Control getControl(){ + return Control.REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java index 852142c1b8..3a9ecefca3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/CommandOperation.java @@ -35,5 +35,8 @@ public class CommandOperation extends Operation { public Type getType() { return Type.COMMAND; } + public Control getControl(){ + return Control.NO_REPEAT; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java index 83cfd0e612..69d8aafc4a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ConfigOperation.java @@ -78,4 +78,8 @@ public class ConfigOperation extends Operation { return Type.CONFIG; } + public Control getControl(){ + return Control.REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java index 6ea7adbf59..9e156618b6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -109,6 +109,12 @@ public class OperationManagerImpl implements OperationManager { OperationDAOUtil.convertOperation(operation); int operationId = this.lookupOperationDAO(operation).addOperation(operationDto); for (EnrolmentInfo enrolmentInfo : enrolments) { + if(operationDto.getControl() == + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT){ + operationDAO.updateEnrollmentOperationsStatus(enrolmentInfo.getId(), operationDto.getCode(), + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING, + org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.REPEATED); + } operationMappingDAO.addOperationMapping(operationId, enrolmentInfo.getId()); } OperationManagementDAOFactory.commitTransaction(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/PolicyOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/PolicyOperation.java index 0740728be0..6b36492a83 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/PolicyOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/PolicyOperation.java @@ -33,4 +33,8 @@ public class PolicyOperation extends Operation { this.profileOperations = profileOperations; } + public Control getControl(){ + return Control.REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java index 6c9abbed4c..f984fdfb0c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/ProfileOperation.java @@ -26,4 +26,8 @@ public class ProfileOperation extends ConfigOperation implements Serializable { return Type.PROFILE; } + public Control getControl(){ + return Control.REPEAT; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java index c24887d1bf..9234953829 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/OperationDAO.java @@ -52,6 +52,9 @@ public interface OperationDAO { void updateOperationStatus(int enrolmentId, int operationId,Operation.Status status) throws OperationManagementDAOException; + void updateEnrollmentOperationsStatus(int enrolmentId, String operationCode, Operation.Status existingStatus, + Operation.Status newStatus) throws OperationManagementDAOException; + void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) throws OperationManagementDAOException; 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 b866285ff0..592be91c71 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 @@ -105,6 +105,41 @@ public class GenericOperationDAOImpl implements OperationDAO { } } + @Override + public void updateEnrollmentOperationsStatus(int enrolmentId, String operationCode, Operation.Status existingStatus, + Operation.Status newStatus) throws OperationManagementDAOException { + PreparedStatement stmt = null; + ResultSet rs = null; + try { + Connection connection = OperationManagementDAOFactory.getConnection(); + String query = "SELECT EOM.ID FROM DM_ENROLMENT_OP_MAPPING AS EOM INNER JOIN DM_OPERATION DM " + + "ON DM.ID = EOM.OPERATION_ID WHERE EOM.ENROLMENT_ID = ? AND DM.OPERATION_CODE = ? " + + "AND EOM.STATUS = ?;"; + stmt = connection.prepareStatement(query); + stmt.setInt(1, enrolmentId); + stmt.setString(2, operationCode); + stmt.setString(3, existingStatus.toString()); + // This will return only one result always. + rs = stmt.executeQuery(); + int id = 0; + while (rs.next()){ + id = rs.getInt("ID"); + } + if (id != 0){ + stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OP_MAPPING SET STATUS = ? WHERE ID = ?"); + stmt.setString(1, newStatus.toString()); + stmt.setInt(2, id); + stmt.executeUpdate(); + } + + } catch (SQLException e) { + throw new OperationManagementDAOException("Error occurred while update device mapping operation status " + + "metadata", e); + } finally { + OperationManagementDAOUtil.cleanupResources(stmt); + } + } + @Override public void addOperationResponse(int enrolmentId, int operationId, Object operationResponse) throws OperationManagementDAOException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java index 20485921bb..6625ceab89 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java @@ -97,6 +97,7 @@ public class OperationDAOUtil { operation.setProperties(dtoOperation.getProperties()); operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + dtoOperation.getId()); + return operation; } } From f2f153a2b4849f37d3ec9216b119307f47c70a10 Mon Sep 17 00:00:00 2001 From: dilanua Date: Sun, 1 May 2016 09:51:09 +0530 Subject: [PATCH 06/13] Adding temporary development code bits for dashboard analytics feature --- .../dashboard/dao/GadgetDataServiceDAOImpl.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOImpl.java index fabd43ec8e..e8f2e19a94 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOImpl.java @@ -485,7 +485,6 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { PreparedStatement stmt = null; ResultSet rs = null; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - Map filteredDeviceWithDetails = new HashMap<>(); List> filteredDevicesWithDetails = new ArrayList<>(); int totalRecordsCount = 0; try { @@ -499,7 +498,7 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } } sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_2 " + - "WHERE TENANT_ID = ? AND FEATURE_CODE = ? " + advancedSqlFiltering + "ORDER BY DEVICE_ID ASC LIMIT ?, ?"; + "WHERE TENANT_ID = ? AND FEATURE_CODE = ? " + advancedSqlFiltering + "ORDER BY DEVICE_ID ASC LIMIT ?, ?"; stmt = con.prepareStatement(sql); // [2] appending filter column values, if exist stmt.setInt(1, tenantId); @@ -523,7 +522,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { // executing query rs = stmt.executeQuery(); // fetching query results + Map filteredDeviceWithDetails; while (rs.next()) { + filteredDeviceWithDetails = new HashMap<>(); filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID")); filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM")); filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP")); @@ -612,13 +613,12 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { PreparedStatement stmt = null; ResultSet rs = null; int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - Map filteredDeviceWithDetails = new HashMap<>(); List> filteredDevicesWithDetails = new ArrayList<>(); try { con = this.getConnection(); String sql; sql = "SELECT DEVICE_ID, PLATFORM, OWNERSHIP, CONNECTIVITY_STATUS FROM DEVICES_VIEW_2 " + - "WHERE TENANT_ID = ? AND FEATURE_CODE = ?"; + "WHERE TENANT_ID = ? AND FEATURE_CODE = ?"; // appending filters to support advanced filtering options // [1] appending filter columns, if exist if (filters != null && filters.size() > 0) { @@ -644,7 +644,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { // executing query rs = stmt.executeQuery(); // fetching query results + Map filteredDeviceWithDetails; while (rs.next()) { + filteredDeviceWithDetails = new HashMap<>(); filteredDeviceWithDetails.put("device-id", rs.getInt("DEVICE_ID")); filteredDeviceWithDetails.put("platform", rs.getString("PLATFORM")); filteredDeviceWithDetails.put("ownership", rs.getString("OWNERSHIP")); From e4b400a5e749cb6df96100adabe8f80a6b820a11 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Mon, 2 May 2016 10:45:10 +0530 Subject: [PATCH 07/13] Disabling device analytics publishing by default --- .../src/main/resources/conf/device-analytics-config.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher.feature/src/main/resources/conf/device-analytics-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher.feature/src/main/resources/conf/device-analytics-config.xml index 5baa363c69..d32ff3e50a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher.feature/src/main/resources/conf/device-analytics-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.analytics.data.publisher.feature/src/main/resources/conf/device-analytics-config.xml @@ -29,7 +29,7 @@ Ex - Multiple Receiver Groups with two receivers each {tcp://localhost:7612/,tcp://localhost:7613},{tcp://localhost:7712/,tcp://localhost:7713/} --> - true + false tcp://localhost:7611 admin admin From d1def26602bfbd8aec5ac270977d5501daf6869e Mon Sep 17 00:00:00 2001 From: Kasun Delgolla Date: Mon, 2 May 2016 12:56:22 +0530 Subject: [PATCH 08/13] Committing group listing back end pagination UI --- .../jaggeryapps/devicemgt/api/group-api.jag | 4 + .../app/pages/cdmf.page.groups/groups.hbs | 5 +- .../cdmf.page.groups/public/js/listing.js | 125 ++++++++++++------ 3 files changed, 92 insertions(+), 42 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag index e64ad14d16..4d5bd9973f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/api/group-api.jag @@ -80,4 +80,8 @@ if (!user) { } } +if (result) { + print(result); +} + %> \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs index 2e9690071b..259daf255f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/groups.hbs @@ -37,7 +37,7 @@
{{#if groupCount}} -
+
@@ -270,9 +270,6 @@ {{/zone}} {{#zone "bottomJs"}} - {{#if groupCount}} {{js "js/listing.js"}} {{/if}} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js index a2d95a3c4e..9d4b89a8f0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.groups/public/js/listing.js @@ -97,48 +97,97 @@ function toTitleCase(str) { function loadGroups() { var groupListing = $("#group-listing"); - var groupListingSrc = groupListing.attr("src"); var currentUser = groupListing.data("currentUser"); - $.template("group-listing", groupListingSrc, function (template) { - - var successCallback = function (data) { - data = JSON.parse(data); - var viewModel = {}; - viewModel.groups = data.data; - $('#group-grid').removeClass('hidden'); - var content = template(viewModel); - $("#ast-container").html(content); - - /* - * On group checkbox select add parent selected style class - */ - $(groupCheckbox).click(function () { - addGroupSelectedClass(this); - }); - attachEvents(); + var serviceURL; + if ($.hasPermission("LIST_ALL_GROUPS")) { + serviceURL = "/devicemgt_admin/groups?start=0&rowCount=1000"; + } else if ($.hasPermission("LIST_GROUPS")) { + //Get authenticated users groups + serviceURL = "/devicemgt_admin/groups/user/" + currentUser + "?start=0&rowCount=1000"; + } else { + $("#loading-content").remove(); + $('#device-table').addClass('hidden'); + $('#device-listing-status-msg').text('Permission denied.'); + $("#device-listing-status").removeClass(' hidden'); + return; + } - $('#group-grid').datatables_extended(); + $('#group-grid').datatables_extended ({ + serverSide: true, + processing: false, + searching: true, + ordering: false, + filter: false, + pageLength : 16, + ajax: { url : '/devicemgt/api/groups', data : {url : serviceURL}, + dataSrc: function ( json ) { + $('#group-grid').removeClass('hidden'); + var $list = $("#group-listing :input[type='search']"); + $list.each(function(){ + $(this).addClass("hidden"); + }); + return json.data; + } + }, + columnDefs: [ + { targets: 0, data: 'id', className: 'remove-padding icon-only content-fill' , render: function ( data, type, row, meta ) { + return '
'; + }}, + { targets: 1, data: 'name', className: 'fade-edge' , render: function ( name, type, row, meta ) { + return '

' + name + '

'; + }}, + { targets: 2, data: 'owner', className: 'fade-edge remove-padding-top'}, + { targets: 3, data: 'id', className: 'text-right content-fill text-left-on-grid-view no-wrap' , + render: function ( id, type, row, meta ) { + var html; + html = '' + + '' + + ''; + + html += '' + + '' + + ''; + + html += ''; + + html += '' + + ''; + + html += '' + + ''; + + return html; + }} + ], + "createdRow": function( row, data, dataIndex ) { + $(row).attr('data-type', 'selectable'); + $(row).attr('data-groupid', data.id); + $.each($('td', row), function (colIndex) { + switch(colIndex) { + case 1: + $(this).attr('data-grid-label', "Name"); + $(this).attr('data-search', data.name); + $(this).attr('data-display', data.name); + break; + case 2: + $(this).attr('data-grid-label', "Owner"); + $(this).attr('data-search', data.owner); + $(this).attr('data-display', data.owner); + break; + } + }); + }, + "fnDrawCallback": function( oSettings ) { $(".icon .text").res_text(0.2); - }; - - var serviceURL; - if ($.hasPermission("LIST_ALL_GROUPS")) { - serviceURL = "/devicemgt_admin/groups?start=0&rowCount=1000"; - } else if ($.hasPermission("LIST_GROUPS")) { - //Get authenticated users groups - serviceURL = "/devicemgt_admin/groups/user/" + currentUser + "?start=0&rowCount=1000"; - } else { - $("#loading-content").remove(); - $('#device-table').addClass('hidden'); - $('#device-listing-status-msg').text('Permission denied.'); - $("#device-listing-status").removeClass(' hidden'); - return; + attachEvents(); } - - invokerUtil.get(serviceURL, successCallback, function (message) { - displayErrors(message.content); - }); - + }); + $(groupCheckbox).click(function () { + addGroupSelectedClass(this); }); } From e2d67fc92c8036dce11e4e9d7c560d1b8d15f8b0 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Mon, 2 May 2016 14:36:14 +0530 Subject: [PATCH 09/13] Adding the changes for device search --- .../search/mgt/dao/impl/SearchDAOImpl.java | 201 +++++++++--------- .../search/mgt/impl/QueryBuilderImpl.java | 4 +- .../mgt/core/search/mgt/impl/Utils.java | 35 +++ .../device/mgt/core/Search/SearchDevice.java | 143 ++++++++----- 4 files changed, 228 insertions(+), 155 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/dao/impl/SearchDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/dao/impl/SearchDAOImpl.java index caf6f1929a..ac8f670b7a 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/dao/impl/SearchDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/dao/impl/SearchDAOImpl.java @@ -34,7 +34,9 @@ import org.wso2.carbon.device.mgt.core.search.mgt.impl.Utils; import java.sql.*; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; public class SearchDAOImpl implements SearchDAO { @@ -52,59 +54,62 @@ public class SearchDAOImpl implements SearchDAO { PreparedStatement stmt = null; ResultSet rs; List devices = new ArrayList<>(); + Map devs = new HashMap<>(); try { conn = this.getConnection(); stmt = conn.prepareStatement(query); rs = stmt.executeQuery(); while (rs.next()) { - - Device device = new Device(); - device.setId(rs.getInt("ID")); - device.setDescription(rs.getString("DESCRIPTION")); - device.setName("NAME"); - device.setType(rs.getString("DEVICE_TYPE_NAME")); - device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION")); - - DeviceIdentifier identifier = new DeviceIdentifier(); - identifier.setType(rs.getString("DEVICE_TYPE_NAME")); - identifier.setId(rs.getString("DEVICE_IDENTIFICATION")); - - DeviceInfo deviceInfo = new DeviceInfo(); - deviceInfo.setDeviceId(rs.getInt("ID")); - deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY")); - deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL")); - deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE")); - deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE")); - deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); - deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY")); - deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); - deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); - deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); - deviceInfo.setOsVersion(rs.getString("OS_VERSION")); - deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); - deviceInfo.setSsid(rs.getString("SSID")); - deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); - deviceInfo.setVendor(rs.getString("VENDOR")); - deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP"))); - - DeviceLocation deviceLocation = new DeviceLocation(); - deviceLocation.setLatitude(rs.getDouble("LATITUDE")); - deviceLocation.setLongitude(rs.getDouble("LONGITUDE")); - deviceLocation.setStreet1(rs.getString("STREET1")); - deviceLocation.setStreet2(rs.getString("STREET2")); - deviceLocation.setCity(rs.getString("CITY")); - deviceLocation.setState(rs.getString("STATE")); - deviceLocation.setZip(rs.getString("ZIP")); - deviceLocation.setCountry(rs.getString("COUNTRY")); - deviceLocation.setDeviceId(rs.getInt("ID")); - deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP"))); - - DeviceWrapper wrapper = new DeviceWrapper(); - wrapper.setDevice(device); - wrapper.setDeviceInfo(deviceInfo); - wrapper.setDeviceLocation(deviceLocation); - wrapper.setDeviceIdentifier(identifier); - devices.add(wrapper); + if(!devs.containsKey(rs.getInt("ID"))) { + Device device = new Device(); + device.setId(rs.getInt("ID")); + device.setDescription(rs.getString("DESCRIPTION")); + device.setName("NAME"); + device.setType(rs.getString("DEVICE_TYPE_NAME")); + device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION")); + + DeviceIdentifier identifier = new DeviceIdentifier(); + identifier.setType(rs.getString("DEVICE_TYPE_NAME")); + identifier.setId(rs.getString("DEVICE_IDENTIFICATION")); + + DeviceInfo deviceInfo = new DeviceInfo(); + deviceInfo.setDeviceId(rs.getInt("ID")); + deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY")); + deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL")); + deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE")); + deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE")); + deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); + deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY")); + deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); + deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); + deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); + deviceInfo.setOsVersion(rs.getString("OS_VERSION")); + deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); + deviceInfo.setSsid(rs.getString("SSID")); + deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); + deviceInfo.setVendor(rs.getString("VENDOR")); + deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP"))); + + DeviceLocation deviceLocation = new DeviceLocation(); + deviceLocation.setLatitude(rs.getDouble("LATITUDE")); + deviceLocation.setLongitude(rs.getDouble("LONGITUDE")); + deviceLocation.setStreet1(rs.getString("STREET1")); + deviceLocation.setStreet2(rs.getString("STREET2")); + deviceLocation.setCity(rs.getString("CITY")); + deviceLocation.setState(rs.getString("STATE")); + deviceLocation.setZip(rs.getString("ZIP")); + deviceLocation.setCountry(rs.getString("COUNTRY")); + deviceLocation.setDeviceId(rs.getInt("ID")); + deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP"))); + + DeviceWrapper wrapper = new DeviceWrapper(); + wrapper.setDevice(device); + wrapper.setDeviceInfo(deviceInfo); + wrapper.setDeviceLocation(deviceLocation); + wrapper.setDeviceIdentifier(identifier); + devices.add(wrapper); + devs.put(device.getId(), device.getId()); + } } } catch (SQLException e) { @@ -132,59 +137,63 @@ public class SearchDAOImpl implements SearchDAO { PreparedStatement stmt = null; ResultSet rs; List devices = new ArrayList<>(); + Map devs = new HashMap<>(); try { conn = this.getConnection(); stmt = conn.prepareStatement(query); rs = stmt.executeQuery(); while (rs.next()) { - - Device device = new Device(); - device.setId(rs.getInt("ID")); - device.setDescription(rs.getString("DESCRIPTION")); - device.setName(rs.getString("NAME")); - device.setType(rs.getString("DEVICE_TYPE_NAME")); - device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION")); - - DeviceIdentifier identifier = new DeviceIdentifier(); - identifier.setType(rs.getString("DEVICE_TYPE_NAME")); - identifier.setId(rs.getString("DEVICE_IDENTIFICATION")); - - DeviceInfo deviceInfo = new DeviceInfo(); - deviceInfo.setDeviceId(rs.getInt("ID")); - deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY")); - deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL")); - deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE")); - deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE")); - deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); - deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY")); - deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); - deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); - deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); - deviceInfo.setOsVersion(rs.getString("OS_VERSION")); - deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); - deviceInfo.setSsid(rs.getString("SSID")); - deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); - deviceInfo.setVendor(rs.getString("VENDOR")); - deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP"))); - - DeviceLocation deviceLocation = new DeviceLocation(); - deviceLocation.setLatitude(rs.getDouble("LATITUDE")); - deviceLocation.setLongitude(rs.getDouble("LONGITUDE")); - deviceLocation.setStreet1(rs.getString("STREET1")); - deviceLocation.setStreet2(rs.getString("STREET2")); - deviceLocation.setCity(rs.getString("CITY")); - deviceLocation.setState(rs.getString("STATE")); - deviceLocation.setZip(rs.getString("ZIP")); - deviceLocation.setCountry(rs.getString("COUNTRY")); - deviceLocation.setDeviceId(rs.getInt("ID")); - deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP"))); - - DeviceWrapper wrapper = new DeviceWrapper(); - wrapper.setDevice(device); - wrapper.setDeviceInfo(deviceInfo); - wrapper.setDeviceLocation(deviceLocation); - wrapper.setDeviceIdentifier(identifier); - devices.add(wrapper); + if(!devs.containsKey(rs.getInt("ID"))) { + Device device = new Device(); + device.setId(rs.getInt("ID")); + device.setDescription(rs.getString("DESCRIPTION")); + device.setName(rs.getString("NAME")); + device.setType(rs.getString("DEVICE_TYPE_NAME")); + device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION")); + + DeviceIdentifier identifier = new DeviceIdentifier(); + identifier.setType(rs.getString("DEVICE_TYPE_NAME")); + identifier.setId(rs.getString("DEVICE_IDENTIFICATION")); + + DeviceInfo deviceInfo = new DeviceInfo(); + deviceInfo.setDeviceId(rs.getInt("ID")); + deviceInfo.setAvailableRAMMemory(rs.getDouble("AVAILABLE_RAM_MEMORY")); + deviceInfo.setBatteryLevel(rs.getDouble("BATTERY_LEVEL")); + deviceInfo.setConnectionType(rs.getString("CONNECTION_TYPE")); + deviceInfo.setCpuUsage(rs.getDouble("CPU_USAGE")); + deviceInfo.setDeviceModel(rs.getString("DEVICE_MODEL")); + deviceInfo.setExternalAvailableMemory(rs.getDouble("EXTERNAL_AVAILABLE_MEMORY")); + deviceInfo.setExternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); + deviceInfo.setInternalAvailableMemory(rs.getDouble("INTERNAL_AVAILABLE_MEMORY")); + deviceInfo.setInternalTotalMemory(rs.getDouble("EXTERNAL_TOTAL_MEMORY")); + deviceInfo.setOsVersion(rs.getString("OS_VERSION")); + deviceInfo.setPluggedIn(rs.getBoolean("PLUGGED_IN")); + deviceInfo.setSsid(rs.getString("SSID")); + deviceInfo.setTotalRAMMemory(rs.getDouble("TOTAL_RAM_MEMORY")); + deviceInfo.setVendor(rs.getString("VENDOR")); + deviceInfo.setUpdatedTime(new java.util.Date(rs.getLong("UPDATE_TIMESTAMP"))); + + DeviceLocation deviceLocation = new DeviceLocation(); + deviceLocation.setLatitude(rs.getDouble("LATITUDE")); + deviceLocation.setLongitude(rs.getDouble("LONGITUDE")); + deviceLocation.setStreet1(rs.getString("STREET1")); + deviceLocation.setStreet2(rs.getString("STREET2")); + deviceLocation.setCity(rs.getString("CITY")); + deviceLocation.setState(rs.getString("STATE")); + deviceLocation.setZip(rs.getString("ZIP")); + deviceLocation.setCountry(rs.getString("COUNTRY")); + deviceLocation.setDeviceId(rs.getInt("ID")); + deviceLocation.setUpdatedTime(new java.util.Date(rs.getLong("DL_UPDATED_TIMESTAMP"))); + + DeviceWrapper wrapper = new DeviceWrapper(); + wrapper.setDevice(device); + wrapper.setDeviceInfo(deviceInfo); + wrapper.setDeviceLocation(deviceLocation); + wrapper.setDeviceIdentifier(identifier); + + devices.add(wrapper); + devs.put(device.getId(), device.getId()); + } } } catch (SQLException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java index 60b46271c2..5864966f0c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/QueryBuilderImpl.java @@ -114,7 +114,7 @@ public class QueryBuilderImpl implements QueryBuilder { for (Condition con : conditions) { if (Utils.checkDeviceDetailsColumns(con.getKey())) { querySuffix = querySuffix + " AND DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) + - con.getOperator() + con.getValue(); + con.getOperator() + Utils.getConvertedValue(con.getKey(), con.getValue()); } else if (Utils.checkDeviceLocationColumns(con.getKey())) { querySuffix = querySuffix + " AND DL." + Utils.getDeviceLocationColumnNames().get(con.getKey()) + con.getOperator() + con.getValue(); @@ -132,7 +132,7 @@ public class QueryBuilderImpl implements QueryBuilder { for (Condition con : conditions) { if (Utils.checkDeviceDetailsColumns(con.getKey())) { querySuffix = querySuffix + " OR DD." + Utils.getDeviceDetailsColumnNames().get(con.getKey()) + - con.getOperator() + con.getValue(); + con.getOperator() + Utils.getConvertedValue(con.getKey(), con.getValue()); } else if (Utils.checkDeviceLocationColumns(con.getKey())) { querySuffix = querySuffix + " OR DL." + Utils.getDeviceLocationColumnNames().get(con.getKey()) + con.getOperator() + con.getValue(); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/Utils.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/Utils.java index bc69e76033..3522228511 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/Utils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/Utils.java @@ -60,6 +60,41 @@ public class Utils { } + public static boolean checkColumnType(String column) { + + boolean bool = false; + + switch (column) { + case "deviceModel": + bool = true; + break; + case "vendor": + bool = true; + break; + case "osVersion": + bool = true; + break; + case "connectionType": + bool = true; + break; + case "ssid": + bool = true; + break; + default: bool =false; + break; + } + + return bool; + } + + public static String getConvertedValue(String column, String value) { + + if(checkColumnType(column)){ + return "\'" + value + "\'"; + } else return value; + + } + public static Map getDeviceDetailsColumnNames() { return genericColumnsMap; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/Search/SearchDevice.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/Search/SearchDevice.java index 88acffe514..93c15914ad 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/Search/SearchDevice.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/java/org/wso2/carbon/device/mgt/core/Search/SearchDevice.java @@ -93,62 +93,91 @@ public class SearchDevice extends BaseDeviceManagementTest { } -// @Test -// public void doValidLocationSearch() throws Exception{ -// -// SearchContext context = new SearchContext(); -// List conditions = new ArrayList<>(); -// -// Condition cond = new Condition(); -// cond.setKey("LOCATION"); -// cond.setOperator("="); -// cond.setValue("Karan"); -// cond.setState(Condition.State.AND); -// conditions.add(cond); -// -// context.setConditions(conditions); -// -// SearchManagerService service = new SearchManagerServiceImpl(); -// List deviceWrappers = service.search(context); -// -// Gson gson = new Gson(); -// String bbbb = gson.toJson(deviceWrappers); -// log.info("Valid Search " + bbbb); -// -// -// for (DeviceWrapper dw : deviceWrappers) { -// log.debug(dw.getDevice().getDescription()); -// log.debug(dw.getDevice().getDeviceIdentifier()); -// } -// } -// -// @Test -// public void doInvalidLocationSearch() throws Exception{ -// -// SearchContext context = new SearchContext(); -// List conditions = new ArrayList<>(); -// -// Condition cond = new Condition(); -// cond.setKey("LOCATION"); -// cond.setOperator("="); -// cond.setValue("Colombo"); -// cond.setState(Condition.State.AND); -// conditions.add(cond); -// -// context.setConditions(conditions); -// -// SearchManagerService service = new SearchManagerServiceImpl(); -// List deviceWrappers = service.search(context); -// -// Gson gson = new Gson(); -// String bbbb = gson.toJson(deviceWrappers); -// log.info("Invalid Search " + bbbb); -// -// -// for (DeviceWrapper dw : deviceWrappers) { -// log.debug(dw.getDevice().getDescription()); -// log.debug(dw.getDevice().getDeviceIdentifier()); -// } -// } + @Test + public void doValidLocationSearch() throws Exception{ + + SearchContext context = new SearchContext(); + List conditions = new ArrayList<>(); + + Condition cond = new Condition(); + cond.setKey("LOCATION"); + cond.setOperator("="); + cond.setValue("Karan"); + cond.setState(Condition.State.AND); + conditions.add(cond); + + context.setConditions(conditions); + + SearchManagerService service = new SearchManagerServiceImpl(); + List deviceWrappers = service.search(context); + + Gson gson = new Gson(); + String bbbb = gson.toJson(deviceWrappers); + log.info("Valid Search " + bbbb); + + + for (DeviceWrapper dw : deviceWrappers) { + log.debug(dw.getDevice().getDescription()); + log.debug(dw.getDevice().getDeviceIdentifier()); + } + } + + @Test + public void doInvalidLocationSearch() throws Exception{ + + SearchContext context = new SearchContext(); + List conditions = new ArrayList<>(); + + Condition cond = new Condition(); + cond.setKey("LOCATION"); + cond.setOperator("="); + cond.setValue("Colombo"); + cond.setState(Condition.State.AND); + conditions.add(cond); + + context.setConditions(conditions); + + SearchManagerService service = new SearchManagerServiceImpl(); + List deviceWrappers = service.search(context); + + Gson gson = new Gson(); + String bbbb = gson.toJson(deviceWrappers); + log.info("Invalid Search " + bbbb); + + + for (DeviceWrapper dw : deviceWrappers) { + log.debug(dw.getDevice().getDescription()); + log.debug(dw.getDevice().getDeviceIdentifier()); + } + } + + @Test + public void doStringSearch() throws Exception{ + + SearchContext context = new SearchContext(); + List conditions = new ArrayList<>(); + + Condition cond = new Condition(); + cond.setKey("deviceModel"); + cond.setOperator("="); + cond.setValue("SM-T520"); + cond.setState(Condition.State.AND); + conditions.add(cond); + + context.setConditions(conditions); + + SearchManagerService service = new SearchManagerServiceImpl(); + List deviceWrappers = service.search(context); + + Gson gson = new Gson(); + String bbbb = gson.toJson(deviceWrappers); + log.info("Invalid Search " + bbbb); + + + for (DeviceWrapper dw : deviceWrappers) { + log.debug(dw.getDevice().getDescription()); + log.debug(dw.getDevice().getDeviceIdentifier()); + } + } } From c828a5264bb37636330c0b19ea478be7301ad39d Mon Sep 17 00:00:00 2001 From: dilanua Date: Mon, 2 May 2016 15:15:45 +0530 Subject: [PATCH 10/13] Adding temporary development code bits for dashboard analytics feature --- .../dashboard/GadgetDataService.java | 37 ++-- .../dao/GadgetDataServiceDAOException.java | 9 +- .../dao/GadgetDataServiceDAOFactory.java | 32 +-- .../dao/GadgetDataServiceDAOImpl.java | 60 +++-- .../internal/GadgetDataServiceComponent.java | 20 +- .../internal/GadgetDataServiceImpl.java | 208 ++++++++++++------ 6 files changed, 228 insertions(+), 138 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java index d34bd4c2e5..7c5b2038e6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataService.java @@ -30,58 +30,61 @@ import java.util.Map; public interface GadgetDataService { @SuppressWarnings("unused") - int getTotalDeviceCount(); + int getTotalDeviceCount() throws GadgetDataServiceException; @SuppressWarnings("unused") - int getActiveDeviceCount(); + int getActiveDeviceCount() throws GadgetDataServiceException; @SuppressWarnings("unused") - int getInactiveDeviceCount(); + int getInactiveDeviceCount() throws GadgetDataServiceException; @SuppressWarnings("unused") - int getRemovedDeviceCount(); + int getRemovedDeviceCount() throws GadgetDataServiceException; @SuppressWarnings("unused") - int getNonCompliantDeviceCount(); + int getNonCompliantDeviceCount() throws GadgetDataServiceException; @SuppressWarnings("unused") - int getUnmonitoredDeviceCount(); + int getUnmonitoredDeviceCount() throws GadgetDataServiceException; @SuppressWarnings("unused") - PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest); + PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) + throws GadgetDataServiceException; @SuppressWarnings("unused") - int getDeviceCount(Map filters); + int getDeviceCount(Map filters) throws GadgetDataServiceException; @SuppressWarnings("unused") - int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map filters); + int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, + Map filters) throws GadgetDataServiceException; @SuppressWarnings("unused") - Map getDeviceCountsByPlatforms(Map filters); + Map getDeviceCountsByPlatforms(Map filters) throws GadgetDataServiceException; @SuppressWarnings("unused") Map getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - Map filters); + Map filters) throws GadgetDataServiceException; @SuppressWarnings("unused") - Map getDeviceCountsByOwnershipTypes(Map filters); + Map getDeviceCountsByOwnershipTypes(Map filters) throws GadgetDataServiceException; @SuppressWarnings("unused") Map getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - Map filters); + Map filters) throws GadgetDataServiceException; @SuppressWarnings("unused") - PaginationResult getDevicesWithDetails(Map filters, PaginationRequest paginationRequest); + PaginationResult getDevicesWithDetails(Map filters, + PaginationRequest paginationRequest) throws GadgetDataServiceException; @SuppressWarnings("unused") PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, PaginationRequest paginationRequest); + Map filters, PaginationRequest paginationRequest) throws GadgetDataServiceException; @SuppressWarnings("unused") - List> getDevicesWithDetails(Map filters); + List> getDevicesWithDetails(Map filters) throws GadgetDataServiceException; @SuppressWarnings("unused") List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters); + Map filters) throws GadgetDataServiceException; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOException.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOException.java index 3ebf841f13..adb1917c1e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOException.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOException.java @@ -18,11 +18,11 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao; -@SuppressWarnings("unused") /** - * Custom exception class for data access related exceptions. + * Custom exception class for GadgetDataServiceDAO layer. */ public class GadgetDataServiceDAOException extends Exception { + private String errorMessage; private static final long serialVersionUID = 2021891706072918864L; @@ -43,6 +43,7 @@ public class GadgetDataServiceDAOException extends Exception { * @param errorMessage Specific error message. * @param cause Cause of this exception. */ + @SuppressWarnings("unused") public GadgetDataServiceDAOException(String errorMessage, Throwable cause) { super(errorMessage, cause); setErrorMessage(errorMessage); @@ -53,6 +54,7 @@ public class GadgetDataServiceDAOException extends Exception { * * @param errorMessage Specific error message. */ + @SuppressWarnings("unused") public GadgetDataServiceDAOException(String errorMessage) { super(errorMessage); setErrorMessage(errorMessage); @@ -63,10 +65,12 @@ public class GadgetDataServiceDAOException extends Exception { * * @param cause Cause of this exception. */ + @SuppressWarnings("unused") public GadgetDataServiceDAOException(Throwable cause) { super(cause); } + @SuppressWarnings("unused") public String getErrorMessage() { return errorMessage; } @@ -74,4 +78,5 @@ public class GadgetDataServiceDAOException extends Exception { public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOFactory.java index bb2d44ac63..75555690cc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOFactory.java @@ -33,6 +33,7 @@ import java.util.List; @SuppressWarnings("unused") public class GadgetDataServiceDAOFactory { + private static final Log log = LogFactory.getLog(GadgetDataServiceDAOFactory.class); private static DataSource dataSource; private static String databaseEngine; @@ -47,7 +48,7 @@ public class GadgetDataServiceDAOFactory { try { databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName(); } catch (SQLException e) { - log.error("Error occurred while retrieving config.datasource connection", e); + log.error("Error occurred while retrieving config.datasource connection.", e); } } @@ -56,7 +57,7 @@ public class GadgetDataServiceDAOFactory { try { databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName(); } catch (SQLException e) { - log.error("Error occurred while retrieving config.datasource connection", e); + log.error("Error occurred while retrieving config.datasource connection.", e); } } @@ -64,8 +65,8 @@ public class GadgetDataServiceDAOFactory { 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"); + "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); @@ -75,8 +76,8 @@ public class GadgetDataServiceDAOFactory { 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"); + "This might have ideally been caused by not properly initiating the transaction via " + + "'beginTransaction'/'openConnection' methods."); } return conn; } @@ -85,36 +86,35 @@ public class GadgetDataServiceDAOFactory { 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"); + "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"); + log.warn("Error occurred while close the connection."); } currentConnection.remove(); } /** - * Resolve data source from the data source definition + * Resolve data source from the data source definition. * - * @param config data source configuration - * @return data source resolved 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"); + "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"); + log.debug("Initializing Device Management Repository data source using the JNDI Lookup Definition."); } List jndiPropertyList = jndiConfig.getJndiProperties(); if (jndiPropertyList != null) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOImpl.java index e8f2e19a94..e4c4286ba1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOImpl.java @@ -18,8 +18,6 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; @@ -35,8 +33,6 @@ import java.util.List; import java.util.Map; class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { - @SuppressWarnings("unused") - private static final Log log = LogFactory.getLog(GadgetDataServiceDAOImpl.class); @Override public int getTotalDeviceCount() throws GadgetDataServiceDAOException { @@ -72,7 +68,15 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { } @Override - public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) throws GadgetDataServiceDAOException { + public int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException { + Map filters = new HashMap<>(); + filters.put("POLICY_ID", -1); + return this.getDeviceCount(filters); + } + + @Override + public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) + throws GadgetDataServiceDAOException { Connection con; PreparedStatement stmt = null; ResultSet rs = null; @@ -82,7 +86,7 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { try { con = this.getConnection(); String sql = "SELECT FEATURE_CODE, COUNT(DEVICE_ID) AS DEVICE_COUNT FROM DEVICES_VIEW_2 " + - "WHERE TENANT_ID = ? GROUP BY FEATURE_CODE ORDER BY DEVICE_COUNT DESC LIMIT ?, ?"; + "WHERE TENANT_ID = ? GROUP BY FEATURE_CODE ORDER BY DEVICE_COUNT DESC LIMIT ?, ?"; stmt = con.prepareStatement(sql); stmt.setInt(1, tenantId); stmt.setInt(2, paginationRequest.getStartIndex()); @@ -112,7 +116,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { totalRecordsCount = rs.getInt("NON_COMPLIANT_FEATURE_COUNT"); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting non compliant device counts by features.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -122,13 +127,6 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { return paginationResult; } - @Override - public int getUnmonitoredDeviceCount() throws GadgetDataServiceDAOException { - Map filters = new HashMap<>(); - filters.put("POLICY_ID", -1); - return this.getDeviceCount(filters); - } - public int getDeviceCount(Map filters) throws GadgetDataServiceDAOException { Connection con; PreparedStatement stmt = null; @@ -166,7 +164,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { filteredDeviceCount = rs.getInt("DEVICE_COUNT"); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting a filtered device count.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -211,7 +210,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { filteredDeviceCount = rs.getInt("DEVICE_COUNT"); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting a filtered device count, " + + "non compliant by a particular feature.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -257,7 +258,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { filteredDeviceCountsByPlatforms.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT")); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting a filtered set of device counts by platforms.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -304,7 +306,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { filteredDeviceCountsByPlatforms.put(rs.getString("PLATFORM"), rs.getInt("DEVICE_COUNT")); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting a set of feature non-compliant device counts by platforms.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -350,7 +353,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT")); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting a filtered set of device counts by ownership types.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -398,7 +402,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { filteredDeviceCountsByOwnershipTypes.put(rs.getString("OWNERSHIP"), rs.getInt("DEVICE_COUNT")); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting a filtered set of feature " + + "non-compliant device counts by ownership types.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -469,7 +475,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { totalRecordsCount = rs.getInt("DEVICE_COUNT"); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting a filtered set of devices " + + "with details when pagination is enabled.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -546,7 +554,9 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { totalRecordsCount = rs.getInt("DEVICE_COUNT"); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting a filtered set of feature non-compliant devices " + + "with details when pagination is enabled.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -600,7 +610,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { filteredDevicesWithDetails.add(filteredDeviceWithDetails); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting a filtered set of devices with details.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } @@ -654,7 +665,8 @@ class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { filteredDevicesWithDetails.add(filteredDeviceWithDetails); } } catch (SQLException e) { - throw new GadgetDataServiceDAOException("Error occurred while executing a selection query to the database", e); + throw new GadgetDataServiceDAOException("Error occurred @ GadgetDataServiceDAO layer while trying to " + + "execute relevant SQL queries for getting filtered set of feature non-compliant devices with details.", e); } finally { DeviceManagementDAOUtil.cleanupResources(stmt, rs); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceComponent.java index 193afc92da..a506665f6f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceComponent.java @@ -39,6 +39,7 @@ import org.wso2.carbon.ndatasource.core.DataSourceService; * unbind="unsetDataSourceService" */ public class GadgetDataServiceComponent { + private static final Log log = LogFactory.getLog(GadgetDataServiceComponent.class); protected void activate(ComponentContext componentContext) { @@ -56,10 +57,10 @@ public class GadgetDataServiceComponent { componentContext.getBundleContext(). registerService(GadgetDataService.class.getName(), new GadgetDataServiceImpl(), null); if (log.isDebugEnabled()) { - log.debug("Device Management Dashboard Analytics Bundle has been started successfully"); + log.debug("Device Management Dashboard Analytics Bundle has been started successfully."); } } catch (Throwable e) { - log.error("Error occurred while initializing the bundle", e); + log.error("Error occurred while initializing the bundle.", e); } } @@ -70,11 +71,18 @@ public class GadgetDataServiceComponent { //do nothing } - public void setDataSourceService(DataSourceService dataSourceService){ - + public void setDataSourceService(DataSourceService dataSourceService) { + if (log.isDebugEnabled()) { + log.debug("Binding org.wso2.carbon.ndatasource.core.DataSourceService..."); + } + //do nothing } - public void unsetDataSourceService(DataSourceService dataSourceService){ - + public void unsetDataSourceService(DataSourceService dataSourceService) { + if (log.isDebugEnabled()) { + log.debug("Unbinding org.wso2.carbon.ndatasource.core.DataSourceService..."); + } + //do nothing } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceImpl.java index 2f31b84f40..b948d63aaa 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceImpl.java @@ -18,9 +18,8 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.internal; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService; +import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataServiceException; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOException; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory; import org.wso2.carbon.device.mgt.common.PaginationRequest; @@ -35,18 +34,18 @@ import java.util.Map; */ class GadgetDataServiceImpl implements GadgetDataService { - @SuppressWarnings("unused") - private static final Log log = LogFactory.getLog(GadgetDataServiceImpl.class); - @Override - public int getTotalDeviceCount() { + public int getTotalDeviceCount() throws GadgetDataServiceException { int totalDeviceCount; try { GadgetDataServiceDAOFactory.openConnection(); totalDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getTotalDeviceCount(); - } catch (GadgetDataServiceDAOException | SQLException e) { - totalDeviceCount = -1; - return totalDeviceCount; + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in calling DAO function for total device count.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -54,14 +53,17 @@ class GadgetDataServiceImpl implements GadgetDataService { } @Override - public int getActiveDeviceCount() { + public int getActiveDeviceCount() throws GadgetDataServiceException { int activeDeviceCount; try { GadgetDataServiceDAOFactory.openConnection(); activeDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getActiveDeviceCount(); - } catch (GadgetDataServiceDAOException | SQLException e) { - activeDeviceCount = -1; - return activeDeviceCount; + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in calling DAO function for active device count.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -69,14 +71,17 @@ class GadgetDataServiceImpl implements GadgetDataService { } @Override - public int getInactiveDeviceCount() { + public int getInactiveDeviceCount() throws GadgetDataServiceException { int inactiveDeviceCount; try { GadgetDataServiceDAOFactory.openConnection(); inactiveDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getInactiveDeviceCount(); - } catch (GadgetDataServiceDAOException | SQLException e) { - inactiveDeviceCount = -1; - return inactiveDeviceCount; + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in calling DAO function for inactive device count.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -84,14 +89,17 @@ class GadgetDataServiceImpl implements GadgetDataService { } @Override - public int getRemovedDeviceCount() { + public int getRemovedDeviceCount() throws GadgetDataServiceException { int removedDeviceCount; try { GadgetDataServiceDAOFactory.openConnection(); removedDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getRemovedDeviceCount(); - } catch (GadgetDataServiceDAOException | SQLException e) { - removedDeviceCount = -1; - return removedDeviceCount; + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in calling DAO function for removed device count.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -99,14 +107,17 @@ class GadgetDataServiceImpl implements GadgetDataService { } @Override - public int getNonCompliantDeviceCount() { + public int getNonCompliantDeviceCount() throws GadgetDataServiceException { int nonCompliantDeviceCount; try { GadgetDataServiceDAOFactory.openConnection(); nonCompliantDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getNonCompliantDeviceCount(); - } catch (GadgetDataServiceDAOException | SQLException e) { - nonCompliantDeviceCount = -1; - return nonCompliantDeviceCount; + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in calling DAO function for non-compliant device count.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -114,14 +125,17 @@ class GadgetDataServiceImpl implements GadgetDataService { } @Override - public int getUnmonitoredDeviceCount() { + public int getUnmonitoredDeviceCount() throws GadgetDataServiceException { int unmonitoredDeviceCount; try { GadgetDataServiceDAOFactory.openConnection(); unmonitoredDeviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getUnmonitoredDeviceCount(); - } catch (GadgetDataServiceDAOException | SQLException e) { - unmonitoredDeviceCount = -1; - return unmonitoredDeviceCount; + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in calling DAO function for unmonitored device count.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -129,14 +143,19 @@ class GadgetDataServiceImpl implements GadgetDataService { } @Override - public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) { - PaginationResult paginationResult = null; + public PaginationResult getNonCompliantDeviceCountsByFeatures(PaginationRequest paginationRequest) + throws GadgetDataServiceException { + PaginationResult paginationResult; try { GadgetDataServiceDAOFactory.openConnection(); paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getNonCompliantDeviceCountsByFeatures(paginationRequest); - } catch (GadgetDataServiceDAOException | SQLException e) { - return null; + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for non-compliant device counts by features.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -144,14 +163,17 @@ class GadgetDataServiceImpl implements GadgetDataService { } @Override - public int getDeviceCount(Map filters) { + public int getDeviceCount(Map filters) throws GadgetDataServiceException { int deviceCount; try { GadgetDataServiceDAOFactory.openConnection(); deviceCount = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDeviceCount(filters); - } catch (GadgetDataServiceDAOException | SQLException e) { - deviceCount = -1; - return deviceCount; + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in calling DAO function for getting a filtered device count.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -159,15 +181,19 @@ class GadgetDataServiceImpl implements GadgetDataService { } @Override - public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map filters) { + public int getFeatureNonCompliantDeviceCount(String nonCompliantFeatureCode, Map filters) + throws GadgetDataServiceException { int featureNonCompliantDeviceCount; try { GadgetDataServiceDAOFactory.openConnection(); featureNonCompliantDeviceCount = GadgetDataServiceDAOFactory. getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCount(nonCompliantFeatureCode, filters); - } catch (GadgetDataServiceDAOException | SQLException e) { - featureNonCompliantDeviceCount = -1; - return featureNonCompliantDeviceCount; + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for getting a filtered device count, non compliant by a particular feature.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -175,14 +201,19 @@ class GadgetDataServiceImpl implements GadgetDataService { } @Override - public Map getDeviceCountsByPlatforms(Map filters) { - Map deviceCountsByPlatforms = null; + public Map getDeviceCountsByPlatforms(Map filters) + throws GadgetDataServiceException { + Map deviceCountsByPlatforms; try { GadgetDataServiceDAOFactory.openConnection(); deviceCountsByPlatforms = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getDeviceCountsByPlatforms(filters); - } catch (GadgetDataServiceDAOException | SQLException e) { - return null; + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for getting filtered device counts by platforms.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -191,14 +222,18 @@ class GadgetDataServiceImpl implements GadgetDataService { @Override public Map getFeatureNonCompliantDeviceCountsByPlatforms(String nonCompliantFeatureCode, - Map filters) { - Map featureNonCompliantDeviceCountsByPlatforms = null; + Map filters) throws GadgetDataServiceException { + Map featureNonCompliantDeviceCountsByPlatforms; try { GadgetDataServiceDAOFactory.openConnection(); featureNonCompliantDeviceCountsByPlatforms = GadgetDataServiceDAOFactory. getGadgetDataServiceDAO().getFeatureNonCompliantDeviceCountsByPlatforms(nonCompliantFeatureCode, filters); - } catch (GadgetDataServiceDAOException | SQLException e) { - return null; + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for getting filtered device counts by platforms, non compliant by a particular feature.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -206,14 +241,19 @@ class GadgetDataServiceImpl implements GadgetDataService { } @Override - public Map getDeviceCountsByOwnershipTypes(Map filters) { - Map deviceCountsByOwnershipTypes = null; + public Map getDeviceCountsByOwnershipTypes(Map filters) + throws GadgetDataServiceException { + Map deviceCountsByOwnershipTypes; try { GadgetDataServiceDAOFactory.openConnection(); deviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getDeviceCountsByOwnershipTypes(filters); - } catch (GadgetDataServiceDAOException | SQLException e) { - return null; + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for getting filtered device counts by ownership types.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -222,15 +262,19 @@ class GadgetDataServiceImpl implements GadgetDataService { @Override public Map getFeatureNonCompliantDeviceCountsByOwnershipTypes(String nonCompliantFeatureCode, - Map filters) { - Map featureNonCompliantDeviceCountsByOwnershipTypes = null; + Map filters) throws GadgetDataServiceException { + Map featureNonCompliantDeviceCountsByOwnershipTypes; try { GadgetDataServiceDAOFactory.openConnection(); featureNonCompliantDeviceCountsByOwnershipTypes = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getFeatureNonCompliantDeviceCountsByOwnershipTypes(nonCompliantFeatureCode, filters); - } catch (GadgetDataServiceDAOException | SQLException e) { - return null; + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection.", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for getting filtered device counts by ownership types, non compliant by a particular feature.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -238,14 +282,19 @@ class GadgetDataServiceImpl implements GadgetDataService { } @Override - public PaginationResult getDevicesWithDetails(Map filters, PaginationRequest paginationRequest) { - PaginationResult paginationResult = null; + public PaginationResult getDevicesWithDetails(Map filters, + PaginationRequest paginationRequest) throws GadgetDataServiceException { + PaginationResult paginationResult; try { GadgetDataServiceDAOFactory.openConnection(); paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getDevicesWithDetails(filters, paginationRequest); - } catch (GadgetDataServiceDAOException | SQLException e) { - return null; + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for getting filtered devices with details when pagination is enabled.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -254,14 +303,18 @@ class GadgetDataServiceImpl implements GadgetDataService { @Override public PaginationResult getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters, PaginationRequest paginationRequest) { - PaginationResult paginationResult = null; + Map filters, PaginationRequest paginationRequest) throws GadgetDataServiceException { + PaginationResult paginationResult; try { GadgetDataServiceDAOFactory.openConnection(); paginationResult = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters, paginationRequest); - } catch (GadgetDataServiceDAOException | SQLException e) { - return null; + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for getting filtered devices with details, non compliant by feature when pagination is enabled.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -269,13 +322,18 @@ class GadgetDataServiceImpl implements GadgetDataService { } @Override - public List> getDevicesWithDetails(Map filters) { - List> devicesWithDetails = null; + public List> getDevicesWithDetails(Map filters) + throws GadgetDataServiceException { + List> devicesWithDetails; try { GadgetDataServiceDAOFactory.openConnection(); devicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO().getDevicesWithDetails(filters); - } catch (GadgetDataServiceDAOException | SQLException e) { - return null; + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for getting filtered devices with details.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } @@ -284,14 +342,18 @@ class GadgetDataServiceImpl implements GadgetDataService { @Override public List> getFeatureNonCompliantDevicesWithDetails(String nonCompliantFeatureCode, - Map filters) { - List> featureNonCompliantDevicesWithDetails = null; + Map filters) throws GadgetDataServiceException { + List> featureNonCompliantDevicesWithDetails; try { GadgetDataServiceDAOFactory.openConnection(); featureNonCompliantDevicesWithDetails = GadgetDataServiceDAOFactory.getGadgetDataServiceDAO(). getFeatureNonCompliantDevicesWithDetails(nonCompliantFeatureCode, filters); - } catch (GadgetDataServiceDAOException | SQLException e) { - return null; + } catch (SQLException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer " + + "in opening database connection", e); + } catch (GadgetDataServiceDAOException e) { + throw new GadgetDataServiceException("Error occurred @ GadgetDataService layer in calling DAO function " + + "for getting filtered devices with details, non compliant by feature.", e); } finally { GadgetDataServiceDAOFactory.closeConnection(); } From d9015b92a0c993300fd4be7bd9850e467ee30f49 Mon Sep 17 00:00:00 2001 From: dilanua Date: Mon, 2 May 2016 15:27:32 +0530 Subject: [PATCH 11/13] Adding temporary development code bits for dashboard analytics feature --- .../dashboard/GadgetDataServiceException.java | 82 +++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataServiceException.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataServiceException.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataServiceException.java new file mode 100644 index 0000000000..32ebef29f0 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/GadgetDataServiceException.java @@ -0,0 +1,82 @@ +/* + * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. 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.analytics.dashboard; + +/** + * Custom exception class for GadgetDataService layer. + */ +public class GadgetDataServiceException extends Exception { + + private String errorMessage; + private static final long serialVersionUID = 2021891706072918864L; + + /** + * Constructs a new exception with the specific error message and nested exception. + * + * @param errorMessage specific error message. + * @param nestedException Nested exception. + */ + public GadgetDataServiceException(String errorMessage, Exception nestedException) { + super(errorMessage, nestedException); + setErrorMessage(errorMessage); + } + + /** + * Constructs a new exception with the specific error message and cause. + * + * @param errorMessage Specific error message. + * @param cause Cause of this exception. + */ + @SuppressWarnings("unused") + public GadgetDataServiceException(String errorMessage, Throwable cause) { + super(errorMessage, cause); + setErrorMessage(errorMessage); + } + + /** + * Constructs a new exception with the specific error message. + * + * @param errorMessage Specific error message. + */ + @SuppressWarnings("unused") + public GadgetDataServiceException(String errorMessage) { + super(errorMessage); + setErrorMessage(errorMessage); + } + + /** + * Constructs a new exception with the specific error message and cause. + * + * @param cause Cause of this exception. + */ + @SuppressWarnings("unused") + public GadgetDataServiceException(Throwable cause) { + super(cause); + } + + @SuppressWarnings("unused") + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + +} From af973dacc6f5869d9a24664806adea3acf635536 Mon Sep 17 00:00:00 2001 From: dilanua Date: Mon, 2 May 2016 18:45:23 +0530 Subject: [PATCH 12/13] Adding temporary development code bits for dashboard analytics feature --- .../org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml | 2 ++ .../dashboard/dao/GadgetDataServiceDAOFactory.java | 1 + .../dashboard/dao/{ => impl}/GadgetDataServiceDAOImpl.java | 7 +++++-- .../{internal => impl}/GadgetDataServiceImpl.java | 4 ++-- .../dashboard/internal/GadgetDataServiceComponent.java | 1 + 5 files changed, 11 insertions(+), 4 deletions(-) rename components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/{ => impl}/GadgetDataServiceDAOImpl.java (98%) rename components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/{internal => impl}/GadgetDataServiceImpl.java (99%) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml index 3272165588..cbc22f06c9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/pom.xml @@ -58,6 +58,8 @@ Device Management Dashboard Analytics Bundle org.wso2.carbon.device.mgt.analytics.dashboard.dao, + org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl, + org.wso2.carbon.device.mgt.analytics.dashboard.impl, org.wso2.carbon.device.mgt.analytics.dashboard.internal diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOFactory.java index 75555690cc..c5a6097f3f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOFactory.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOFactory.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.analytics.dashboard.dao; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl.GadgetDataServiceDAOImpl; import org.wso2.carbon.device.mgt.common.IllegalTransactionStateException; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java similarity index 98% rename from components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOImpl.java rename to components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java index e4c4286ba1..9f2250d3cf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/GadgetDataServiceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/dao/impl/GadgetDataServiceDAOImpl.java @@ -16,9 +16,12 @@ * under the License. */ -package org.wso2.carbon.device.mgt.analytics.dashboard.dao; +package org.wso2.carbon.device.mgt.analytics.dashboard.dao.impl; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAO; +import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOException; +import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.common.PaginationResult; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; @@ -32,7 +35,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { +public class GadgetDataServiceDAOImpl implements GadgetDataServiceDAO { @Override public int getTotalDeviceCount() throws GadgetDataServiceDAOException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java similarity index 99% rename from components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceImpl.java rename to components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java index b948d63aaa..eb01fa3ae2 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/impl/GadgetDataServiceImpl.java @@ -16,7 +16,7 @@ * under the License. */ -package org.wso2.carbon.device.mgt.analytics.dashboard.internal; +package org.wso2.carbon.device.mgt.analytics.dashboard.impl; import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService; import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataServiceException; @@ -32,7 +32,7 @@ import java.util.Map; /** * To be updated... */ -class GadgetDataServiceImpl implements GadgetDataService { +public class GadgetDataServiceImpl implements GadgetDataService { @Override public int getTotalDeviceCount() throws GadgetDataServiceException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceComponent.java index a506665f6f..7d1bc08c19 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.analytics.dashboard/src/main/java/org/wso2/carbon/device/mgt/analytics/dashboard/internal/GadgetDataServiceComponent.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.osgi.service.component.ComponentContext; import org.wso2.carbon.device.mgt.analytics.dashboard.GadgetDataService; import org.wso2.carbon.device.mgt.analytics.dashboard.dao.GadgetDataServiceDAOFactory; +import org.wso2.carbon.device.mgt.analytics.dashboard.impl.GadgetDataServiceImpl; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; From d32e822055292e9def69624bddb804d9ab9260f9 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Tue, 3 May 2016 14:10:30 +0530 Subject: [PATCH 13/13] Fixing the shutdown errors --- .../mgt/core/internal/DeviceTaskManagerServiceComponent.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceTaskManagerServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceTaskManagerServiceComponent.java index 28a0a2345d..7051d72f51 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceTaskManagerServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceTaskManagerServiceComponent.java @@ -72,8 +72,8 @@ public class DeviceTaskManagerServiceComponent { @SuppressWarnings("unused") protected void deactivate(ComponentContext componentContext) { try { - DeviceTaskManagerService taskManagerService = new DeviceTaskManagerServiceImpl(); - taskManagerService.stopTask(); +// DeviceTaskManagerService taskManagerService = new DeviceTaskManagerServiceImpl(); +// taskManagerService.stopTask(); } catch (Throwable e) { log.error("Error occurred while destroying the device details retrieving task manager service.", e); }