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 9f4a8bb7daa..c7c4be65ca4 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 00640f76d4d..d6de8899f05 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 63932998ff2..c6904ea66cf 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 8bee53c0bb0..4e07bab65b1 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 b781fb0311f..bb88c94ac60 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 607a19c4610..0364345d472 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); +