From aa63b5f592bd167141aa280c34330ea81374855f Mon Sep 17 00:00:00 2001 From: geethkokila Date: Tue, 29 Mar 2016 17:48:36 +0530 Subject: [PATCH 1/2] Fixing the application memory usage and adding location based search --- .../mgt/common/app/mgt/Application.java | 10 +++++ .../mgt/core/dao/impl/ApplicationDAOImpl.java | 17 ++++--- .../mgt/dao/impl/DeviceDetailsDAOImpl.java | 2 +- .../impl/DeviceInformationManagerImpl.java | 9 ---- .../device/mgt/core/search/mgt/Constants.java | 1 + .../mgt/core/search/mgt/QueryBuilder.java | 2 + .../core/search/mgt/impl/ProcessorImpl.java | 7 +++ .../search/mgt/impl/QueryBuilderImpl.java | 44 ++++++++++++------- .../mgt/impl/ResultSetAggregatorImpl.java | 17 ++++++- .../src/test/resources/sql/h2.sql | 1 + .../src/main/resources/dbscripts/cdm/h2.sql | 1 + .../main/resources/dbscripts/cdm/mssql.sql | 1 + .../main/resources/dbscripts/cdm/mysql.sql | 1 + .../main/resources/dbscripts/cdm/oracle.sql | 1 + .../resources/dbscripts/cdm/postgresql.sql | 1 + 15 files changed, 81 insertions(+), 34 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/Application.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/Application.java index cdcba75a72..0d45f903bd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/Application.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/app/mgt/Application.java @@ -36,6 +36,8 @@ public class Application implements Serializable { private Properties appProperties; private String applicationIdentifier; + private int memoryUsage; + public String getType() { return type; } @@ -111,6 +113,14 @@ public class Application implements Serializable { this.applicationIdentifier = applicationIdentifier; } + public int getMemoryUsage() { + return memoryUsage; + } + + public void setMemoryUsage(int memoryUsage) { + this.memoryUsage = memoryUsage; + } + public boolean equals(Object o) { if (this == o) { return true; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java index e20f152933..f6b320682b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/ApplicationDAOImpl.java @@ -47,8 +47,8 @@ public class ApplicationDAOImpl implements ApplicationDAO { try { conn = this.getConnection(); stmt = conn.prepareStatement("INSERT INTO DM_APPLICATION (NAME, PLATFORM, CATEGORY, " + - "VERSION, TYPE, LOCATION_URL, IMAGE_URL, TENANT_ID,APP_PROPERTIES,APP_IDENTIFIER) " + - "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,?)"); + "VERSION, TYPE, LOCATION_URL, IMAGE_URL, TENANT_ID, APP_PROPERTIES, APP_IDENTIFIER, MEMORY_USAGE) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, application.getName()); stmt.setString(2, application.getPlatform()); @@ -65,6 +65,7 @@ public class ApplicationDAOImpl implements ApplicationDAO { stmt.setBytes(9, bao.toByteArray()); stmt.setString(10, application.getApplicationIdentifier()); + stmt.setInt(11, application.getMemoryUsage()); stmt.execute(); rs = stmt.getGeneratedKeys(); @@ -108,8 +109,8 @@ public class ApplicationDAOImpl implements ApplicationDAO { try { conn = this.getConnection(); stmt = conn.prepareStatement("INSERT INTO DM_APPLICATION (NAME, PLATFORM, CATEGORY, " + - "VERSION, TYPE, LOCATION_URL, IMAGE_URL, TENANT_ID,APP_PROPERTIES,APP_IDENTIFIER) " + - "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?,?)", new String[] {"id"}); + "VERSION, TYPE, LOCATION_URL, IMAGE_URL, TENANT_ID,APP_PROPERTIES, APP_IDENTIFIER, MEMORY_USAGE) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new String[]{"id"}); for (Application application : applications) { @@ -129,6 +130,7 @@ public class ApplicationDAOImpl implements ApplicationDAO { stmt.setBytes(9, bao.toByteArray()); stmt.setString(10, application.getApplicationIdentifier()); + stmt.setInt(11, application.getMemoryUsage()); stmt.executeUpdate(); rs = stmt.getGeneratedKeys(); @@ -170,7 +172,7 @@ public class ApplicationDAOImpl implements ApplicationDAO { conn = this.getConnection(); conn.setAutoCommit(false); stmt = conn.prepareStatement("DELETE DM_APPLICATION WHERE APP_IDENTIFIER = ? AND TENANT_ID = ?", - new String[] {"id"}); + new String[]{"id"}); for (Application app : apps) { stmt.setString(1, app.getApplicationIdentifier()); @@ -206,7 +208,7 @@ public class ApplicationDAOImpl implements ApplicationDAO { try { conn = this.getConnection(); stmt = conn.prepareStatement("SELECT ID, NAME, APP_IDENTIFIER, PLATFORM, CATEGORY, VERSION, TYPE, " + - "LOCATION_URL, IMAGE_URL, APP_PROPERTIES, TENANT_ID FROM DM_APPLICATION WHERE APP_IDENTIFIER = ? " + + "LOCATION_URL, IMAGE_URL, APP_PROPERTIES, MEMORY_USAGE, TENANT_ID FROM DM_APPLICATION WHERE APP_IDENTIFIER = ? " + "AND TENANT_ID = ?"); stmt.setString(1, identifier); stmt.setInt(2, tenantId); @@ -238,7 +240,7 @@ public class ApplicationDAOImpl implements ApplicationDAO { try { conn = this.getConnection(); stmt = conn.prepareStatement("Select ID, NAME, APP_IDENTIFIER, PLATFORM, CATEGORY, VERSION, TYPE, " + - "LOCATION_URL, IMAGE_URL, APP_PROPERTIES, TENANT_ID From DM_APPLICATION app " + + "LOCATION_URL, IMAGE_URL, APP_PROPERTIES, MEMORY_USAGE, TENANT_ID From DM_APPLICATION app " + "INNER JOIN " + "(Select APPLICATION_ID From DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID=?) APPMAP " + "ON " + @@ -284,6 +286,7 @@ public class ApplicationDAOImpl implements ApplicationDAO { application.setLocationUrl(rs.getString("LOCATION_URL")); application.setPlatform(rs.getString("PLATFORM")); application.setVersion(rs.getString("VERSION")); + application.setMemoryUsage(rs.getInt("MEMORY_USAGE")); application.setApplicationIdentifier(rs.getString("APP_IDENTIFIER")); } catch (IOException e) { 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 6ca1735035..a6822ce5ae 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 @@ -86,7 +86,7 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { @Override public void addDeviceProperties(Map propertyMap, int deviceId) throws DeviceDetailsMgtDAOException { - if(propertyMap.isEmpty()){ + if (propertyMap.isEmpty()) { log.warn("Property map of device id :" + deviceId + " is empty."); return; } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java index cfd55a1b01..d5111df20d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java @@ -136,14 +136,5 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { } } -// @Override -// public void addDeviceApplications(DeviceApplication deviceApplication) throws DeviceDetailsMgtException { -// -// } -// -// @Override -// public DeviceApplication getDeviceApplication(DeviceIdentifier deviceIdentifier) throws DeviceDetailsMgtException { -// return null; -// } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/Constants.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/Constants.java index 873dfa82ed..d8b7ada7b4 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/Constants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/Constants.java @@ -24,4 +24,5 @@ public class Constants { public static String GENERAL = "GENERAL"; public static String PROP_AND = "PROP_AND"; public static String PROP_OR = "PROP_OR"; + public static String LOCATION = "LOCATION"; } 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 a6850ed1fc..db028edc19 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 @@ -32,6 +32,8 @@ public interface QueryBuilder { String processOR(List conditions) throws InvalidOperatorException; + List processLocation(Condition condition) throws InvalidOperatorException; + List processANDProperties(List conditions) throws InvalidOperatorException; List processORProperties(List conditions) 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/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 9dc4e85059..4a97f1fdbe 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 @@ -47,6 +47,7 @@ public class ProcessorImpl implements Processor { List generalDevices = new ArrayList<>(); List> allANDDevices = new ArrayList<>(); List> allORDevices = new ArrayList<>(); + List locationDevices = new ArrayList<>(); try { Map> queries = queryBuilder.buildQueries(searchContext.getConditions()); DeviceManagementDAOFactory.openConnection(); @@ -66,6 +67,10 @@ public class ProcessorImpl implements Processor { allORDevices.add(orDevices); } } + if (queries.containsKey(Constants.LOCATION)) { + locationDevices = searchDAO.searchDevicePropertyTable( + queries.get(Constants.LOCATION).get(0)); + } } catch (InvalidOperatorException e) { throw new SearchMgtException("Invalid operator was provided, so cannot execute the search.", e); } catch (SQLException e) { @@ -84,6 +89,7 @@ public class ProcessorImpl implements Processor { deviceWrappers.put(Constants.GENERAL, generalDevices); deviceWrappers.put(Constants.PROP_AND, this.processANDSearch(allANDDevices)); deviceWrappers.put(Constants.PROP_OR, this.processORSearch(allORDevices)); + deviceWrappers.put(Constants.LOCATION, locationDevices); return aggregator.aggregate(deviceWrappers); } @@ -157,5 +163,6 @@ public class ProcessorImpl implements Processor { } return maps; } + } 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 98ecc2d8fd..fcc2e26372 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 @@ -44,9 +44,13 @@ public class QueryBuilderImpl implements QueryBuilder { List orColumns = new ArrayList<>(); List otherANDColumns = new ArrayList<>(); List otherORColumns = new ArrayList<>(); + Condition locConditon = new Condition(); if (conditions.size() == 1) { - if (Utils.getDeviceDetailsColumnNames().containsKey(conditions.get(0)) || + + if (conditions.get(0).getKey().equalsIgnoreCase(Constants.LOCATION)) { + locConditon = conditions.get(0); + } else if (Utils.getDeviceDetailsColumnNames().containsKey(conditions.get(0)) || Utils.getDeviceLocationColumnNames().containsKey(conditions.get(0))) { andColumns.add(conditions.get(0)); } else { @@ -54,7 +58,9 @@ public class QueryBuilderImpl implements QueryBuilder { } } else { for (Condition con : conditions) { - if (Utils.getDeviceDetailsColumnNames().containsKey(con.getKey()) || + if (con.getKey().equalsIgnoreCase(Constants.LOCATION)) { + locConditon = con; + } else if (Utils.getDeviceDetailsColumnNames().containsKey(con.getKey()) || Utils.getDeviceLocationColumnNames().containsKey(con.getKey())) { if (con.getState().equals(Condition.State.AND)) { andColumns.add(con); @@ -80,11 +86,13 @@ public class QueryBuilderImpl implements QueryBuilder { this.processOR(orColumns))); queries.put(Constants.PROP_AND, this.processANDProperties(otherANDColumns)); queries.put(Constants.PROP_OR, this.processORProperties(otherORColumns)); + queries.put(Constants.LOCATION, this.processLocation(locConditon)); if (log.isDebugEnabled()) { log.debug("General Query : " + queries.get(Constants.GENERAL)); log.debug("Property with AND Query : " + queries.get(Constants.PROP_AND)); log.debug("Property with OR Query : " + queries.get(Constants.PROP_OR)); + log.debug("Location related Query : " + queries.get(Constants.LOCATION)); } return queries; @@ -125,6 +133,13 @@ public class QueryBuilderImpl implements QueryBuilder { return querySuffix; } + @Override + public List processLocation(Condition condition) throws InvalidOperatorException { + List queryList = new ArrayList<>(); + queryList.add(this.buildLocationQuery(condition.getValue())); + return queryList; + } + @Override public List processANDProperties(List conditions) throws InvalidOperatorException { return this.getQueryList(conditions); @@ -146,6 +161,18 @@ public class QueryBuilderImpl implements QueryBuilder { return queryList; } + private String buildLocationQuery(String location) { + + String query = this.getGenericQueryPart(); + query = query + " OR STREET1 LIKE \'%" + location + "%\'"; + query = query + " OR STREET2 LIKE \'%" + location + "%\'"; + query = query + " OR CITY LIKE \'%" + location + "%\'"; + query = query + " OR STATE LIKE \'%" + location + "%\'"; + query = query + " OR COUNTRY LIKE \'%" + location + "%\'"; + query = query + " OR ZIP LIKE \'%" + location + "%\'"; + return query; + } + private String getGenericQueryPart() { return "SELECT D.ID, D.DESCRIPTION, D.NAME, \n" + @@ -159,18 +186,6 @@ public class QueryBuilderImpl implements QueryBuilder { "DM_DEVICE_TYPE AS DT WHERE D.TENANT_ID = " + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); -// CREATE TABLE IF NOT EXISTS DM_DEVICE ( -// ID INTEGER auto_increment NOT NULL, -// DESCRIPTION TEXT DEFAULT NULL, -// NAME VARCHAR(100) DEFAULT NULL, -// DEVICE_TYPE_ID INT(11) DEFAULT NULL, -// DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL, -// TENANT_ID INTEGER DEFAULT 0, -// PRIMARY KEY (ID), -// CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID ) -// REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION -// ); - } @@ -190,4 +205,3 @@ public class QueryBuilderImpl implements QueryBuilder { } } - diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ResultSetAggregatorImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ResultSetAggregatorImpl.java index 468a9cba80..069b1630ac 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ResultSetAggregatorImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/search/mgt/impl/ResultSetAggregatorImpl.java @@ -36,15 +36,28 @@ public class ResultSetAggregatorImpl implements ResultSetAggregator { Map generalQueryMap = this.convertToMap(deviceWrappers.get(Constants.GENERAL)); Map andMap = this.convertToMap(deviceWrappers.get(Constants.PROP_AND)); Map orMap = this.convertToMap(deviceWrappers.get(Constants.PROP_OR)); + Map locationMap = this.convertToMap(deviceWrappers.get(Constants.LOCATION)); + List finalResult = new ArrayList<>(); for (Integer a : andMap.keySet()) { if (generalQueryMap.containsKey(a)) { - finalResult.add(andMap.get(a)); + if (!finalResult.contains(a)) { + finalResult.add(andMap.get(a)); + } } } for (Integer a : orMap.keySet()) { - finalResult.add(orMap.get(a)); + if (!finalResult.contains(a)) { + finalResult.add(orMap.get(a)); + } + } + + for (Integer a : locationMap.keySet()) { + if (!finalResult.contains(a)) { + finalResult.add(locationMap.get(a)); + } } + return finalResult; } 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 d172e2f5d2..09a41be82f 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 @@ -360,6 +360,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( LOCATION_URL VARCHAR(100) DEFAULT NULL, IMAGE_URL VARCHAR(100) DEFAULT NULL, APP_PROPERTIES BLOB NULL, + MEMORY_USAGE DECIMAL(5) NULL, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (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 3a268960d1..196b08158d 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 @@ -361,6 +361,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( LOCATION_URL VARCHAR(100) DEFAULT NULL, IMAGE_URL VARCHAR(100) DEFAULT NULL, APP_PROPERTIES BLOB NULL, + MEMORY_USAGE INTEGER(10) NULL, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (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 bb55d05862..91104f4641 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 @@ -349,6 +349,7 @@ CREATE TABLE DM_APPLICATION ( LOCATION_URL VARCHAR(100) DEFAULT NULL, IMAGE_URL VARCHAR(100) DEFAULT NULL, APP_PROPERTIES VARBINARY(max) NULL, + MEMORY_USAGE INTEGER(10) NULL, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ID) ); 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 545f939108..22494de244 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 @@ -356,6 +356,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( LOCATION_URL VARCHAR(100) DEFAULT NULL, IMAGE_URL VARCHAR(100) DEFAULT NULL, APP_PROPERTIES BLOB NULL, + MEMORY_USAGE INTEGER(10) NULL, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (ID) )ENGINE = InnoDB; 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 728233d24b..b781fb0311 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 @@ -576,6 +576,7 @@ CREATE TABLE DM_APPLICATION ( LOCATION_URL VARCHAR2(100) DEFAULT NULL, IMAGE_URL VARCHAR2(100) DEFAULT NULL, APP_PROPERTIES BLOB NULL, + MEMORY_USAGE NUMBER(10) NULL, TENANT_ID NUMBER(10) NOT NULL, CONSTRAINT PK_DM_APPLICATION PRIMARY KEY (ID) ) 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 a1581e19d3..607a19c461 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 @@ -313,6 +313,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( LOCATION_URL VARCHAR(100) DEFAULT NULL, IMAGE_URL VARCHAR(100) DEFAULT NULL, APP_PROPERTIES BYTEA NULL, + MEMORY_USAGE INTEGER NULL, TENANT_ID INTEGER NOT NULL ); From 888971ae390773919ae00acd236cc0cabaf0ddb5 Mon Sep 17 00:00:00 2001 From: geethkokila Date: Tue, 29 Mar 2016 22:46:09 +0530 Subject: [PATCH 2/2] Fixing the oracl and postgres sql datasources and removing the start and end from the search context --- .../mgt/common/search/SearchContext.java | 34 ++--- .../org.wso2.carbon.device.mgt.core/pom.xml | 7 + .../device/mgt/core/Search/SearchDevice.java | 24 +++- .../src/main/resources/conf/cdm-config.xml | 2 +- .../main/resources/dbscripts/cdm/oracle.sql | 129 ++++++++++++++++++ .../resources/dbscripts/cdm/postgresql.sql | 72 ++++++++++ 6 files changed, 249 insertions(+), 19 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/SearchContext.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/SearchContext.java index 9f4a8bb7da..c7c4be65ca 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/SearchContext.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/search/SearchContext.java @@ -24,8 +24,8 @@ import java.util.List; public class SearchContext { private List conditions; - private int start; - private int end; +// private int start; +// private int end; public List getConditions() { return conditions; @@ -35,20 +35,20 @@ public class SearchContext { this.conditions = conditions; } - public int getStart() { - return start; - } - - public void setStart(int start) { - this.start = start; - } - - public int getEnd() { - return end; - } - - public void setEnd(int end) { - this.end = end; - } +// public int getStart() { +// return start; +// } +// +// public void setStart(int start) { +// this.start = start; +// } +// +// public int getEnd() { +// return end; +// } +// +// public void setEnd(int end) { +// this.end = end; +// } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index 00640f76d4..d6de8899f0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -237,6 +237,13 @@ test + + + + + + + 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 63932998ff..c6904ea66c 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 @@ -48,15 +48,37 @@ public class SearchDevice extends BaseDeviceManagementTest { SearchContext context = new SearchContext(); List conditions = new ArrayList<>(); - Condition cond = new Condition(); + + Condition cond = new Condition(); cond.setKey("BATTERY_VOLTAGE"); cond.setOperator("="); cond.setValue("40"); cond.setState(Condition.State.AND); conditions.add(cond); + + Condition cond2 = new Condition(); + cond2.setKey("CPU_USAGE"); + cond2.setOperator(">"); + cond2.setValue("40"); + cond2.setState(Condition.State.OR); + conditions.add(cond2); + + Condition cond3 = new Condition(); + cond3.setKey("LOCATION"); + cond3.setOperator("="); + cond3.setValue("Colombo"); + cond3.setState(Condition.State.AND); + conditions.add(cond3); + context.setConditions(conditions); +// Gson gson = new Gson(); +// +// String aaa = gson.toJson(context); +// +// log.info(aaa); + SearchManagerService service = new SearchManagerServiceImpl(); List deviceWrappers = service.search(context); diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml index 8bee53c0bb..4e07bab65b 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml @@ -51,7 +51,7 @@ 5 - LOCATION + DEVICE_LOCATION 1 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 b781fb0311..bb88c94ac6 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 @@ -655,3 +655,132 @@ WHEN (NEW.NOTIFICATION_ID IS NULL) / -- NOTIFICATION TABLE END -- + +-- Device Info and Search Table -- + +BEGIN + EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_INFO'; +EXCEPTION + WHEN OTHERS THEN NULL; +END; +/ + +CREATE TABLE DM_DEVICE_INFO ( + ID NUMBER(10) NOT NULL, + DEVICE_ID NUMBER(10) NULL, + KEY_FIELD VARCHAR2(45) NULL, + VALUE_FIELD VARCHAR2(100) NULL, + PRIMARY KEY (ID) + , + CONSTRAINT DM_DEVICE_INFO_DEVICE + FOREIGN KEY (DEVICE_ID) + REFERENCES DM_DEVICE (ID) +) +; + +-- Generate ID using sequence and trigger +CREATE SEQUENCE DM_DEVICE_INFO_seq START WITH 1 INCREMENT BY 1; + +CREATE OR REPLACE TRIGGER DM_DEVICE_INFO_seq_tr + BEFORE INSERT ON DM_DEVICE_INFO FOR EACH ROW + WHEN (NEW.ID IS NULL) +BEGIN + SELECT DM_DEVICE_INFO_seq.NEXTVAL INTO :NEW.ID FROM DUAL; +END; +/ + +CREATE INDEX DM_DEVICE_INFO_DEVICE_idx ON DM_DEVICE_INFO (DEVICE_ID ASC); + + + +BEGIN + EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_LOCATION'; +EXCEPTION + WHEN OTHERS THEN NULL; +END; +/ + +CREATE TABLE DM_DEVICE_LOCATION ( + ID NUMBER(10) NOT NULL, + DEVICE_ID NUMBER(10) NULL, + LATITUDE BINARY_DOUBLE NULL, + LONGITUDE BINARY_DOUBLE NULL, + STREET1 VARCHAR2(45) NULL, + STREET2 VARCHAR2(45) NULL, + CITY VARCHAR2(45) NULL, + ZIP VARCHAR2(10) NULL, + STATE VARCHAR2(45) NULL, + COUNTRY VARCHAR2(45) NULL, + PRIMARY KEY (ID) + , + CONSTRAINT DM_DEVICE_LOCATION_DEVICE + FOREIGN KEY (DEVICE_ID) + REFERENCES DM_DEVICE (ID) +) +; + +-- Generate ID using sequence and trigger +CREATE SEQUENCE DM_DEVICE_LOCATION_seq START WITH 1 INCREMENT BY 1; + +CREATE OR REPLACE TRIGGER DM_DEVICE_LOCATION_seq_tr + BEFORE INSERT ON DM_DEVICE_LOCATION FOR EACH ROW + WHEN (NEW.ID IS NULL) +BEGIN + SELECT DM_DEVICE_LOCATION_seq.NEXTVAL INTO :NEW.ID FROM DUAL; +END; +/ + +CREATE INDEX DM_DEVICE_LOCATION_DEVICE_idx ON DM_DEVICE_LOCATION (DEVICE_ID ASC); + + + +BEGIN + EXECUTE IMMEDIATE 'DROP TABLE DM_DEVICE_DETAIL'; +EXCEPTION + WHEN OTHERS THEN NULL; +END; +/ + +CREATE TABLE DM_DEVICE_DETAIL ( + ID NUMBER(10) NOT NULL, + DEVICE_ID NUMBER(10) NOT NULL, + IMEI VARCHAR2(100) NULL, + IMSI VARCHAR2(100) NULL, + DEVICE_MODEL VARCHAR2(45) NULL, + VENDOR VARCHAR2(45) NULL, + OS_VERSION VARCHAR2(45) NULL, + BATTERY_LEVEL NUMBER(4) NULL, + INTERNAL_TOTAL_MEMORY NUMBER(5) NULL, + INTERNAL_AVAILABLE_MEMORY NUMBER(5) NULL, + EXTERNAL_TOTAL_MEMORY NUMBER(5) NULL, + EXTERNAL_AVAILABLE_MEMORY NUMBER(5) NULL, + OPERATOR VARCHAR2(45) NULL, + CONNECTION_TYPE VARCHAR2(10) NULL, + MOBILE_SIGNAL_STRENGTH NUMBER(5) NULL, + SSID VARCHAR2(45) NULL, + CPU_USAGE NUMBER(5) NULL, + TOTAL_RAM_MEMORY NUMBER(5) NULL, + AVAILABLE_RAM_MEMORY NUMBER(5) NULL, + PLUGGED_IN NUMBER(10) 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; + +CREATE OR REPLACE TRIGGER DM_DEVICE_DETAIL_seq_tr + BEFORE INSERT ON DM_DEVICE_DETAIL FOR EACH ROW + WHEN (NEW.ID IS NULL) +BEGIN + SELECT DM_DEVICE_DETAIL_seq.NEXTVAL INTO :NEW.ID FROM DUAL; +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 607a19c461..0364345d47 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 @@ -346,3 +346,75 @@ CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( -- NOTIFICATION TABLE END -- +-- Device Info and Search Table -- + + +CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO ( + ID INTEGER DEFAULT NEXTVAL ('DM_DEVICE_INFO_seq') NOT NULL, + DEVICE_ID INT NULL, + KEY_FIELD VARCHAR(45) NULL, + VALUE_FIELD VARCHAR(100) NULL, + PRIMARY KEY (ID) , + CONSTRAINT DM_DEVICE_INFO_DEVICE + FOREIGN KEY (DEVICE_ID) + REFERENCES DM_DEVICE (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + +CREATE INDEX DM_DEVICE_INFO_DEVICE_idx ON DM_DEVICE_INFO (DEVICE_ID ASC); + + +CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( + ID INTEGER DEFAULT NEXTVAL ('DM_DEVICE_LOCATION_seq') NOT NULL, + DEVICE_ID INT NULL, + LATITUDE DOUBLE PRECISION NULL, + LONGITUDE DOUBLE PRECISION 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, + PRIMARY KEY (ID) , + CONSTRAINT DM_DEVICE_LOCATION_DEVICE + FOREIGN KEY (DEVICE_ID) + REFERENCES DM_DEVICE (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + +CREATE INDEX DM_DEVICE_LOCATION_DEVICE_idx ON DM_DEVICE_LOCATION (DEVICE_ID ASC); + + +CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( + ID INT NOT NULL DEFAULT NEXTVAL ('DM_DEVICE_DETAIL_seq'), + DEVICE_ID INT NOT NULL, + IMEI VARCHAR(100) NULL, + IMSI VARCHAR(100) NULL, + DEVICE_MODEL VARCHAR(45) NULL, + VENDOR VARCHAR(45) NULL, + OS_VERSION VARCHAR(45) NULL, + BATTERY_LEVEL DECIMAL(4) NULL, + INTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, + INTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, + EXTERNAL_TOTAL_MEMORY DECIMAL(5) NULL, + EXTERNAL_AVAILABLE_MEMORY DECIMAL(5) NULL, + OPERATOR VARCHAR(45) NULL, + CONNECTION_TYPE VARCHAR(10) NULL, + MOBILE_SIGNAL_STRENGTH DECIMAL(5) NULL, + SSID VARCHAR(45) NULL, + CPU_USAGE DECIMAL(5) NULL, + TOTAL_RAM_MEMORY DECIMAL(5) NULL, + AVAILABLE_RAM_MEMORY DECIMAL(5) NULL, + PLUGGED_IN INT NULL, + PRIMARY KEY (ID) , + CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE + FOREIGN KEY (DEVICE_ID) + REFERENCES DM_DEVICE (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + +CREATE INDEX FK_DM_DEVICE_DETAILS_DEVICE_idx ON DM_DEVICE_DETAIL (DEVICE_ID ASC); +