From 24b462f4f4dee1633597bac0cf77f5015b31d078 Mon Sep 17 00:00:00 2001 From: Chatura Dilan Date: Wed, 29 Jun 2016 17:41:45 +0530 Subject: [PATCH] Added is-active field to the Application --- .../device/mgt/common/app/mgt/Application.java | 12 +++++++++++- .../mgt/core/dao/impl/ApplicationDAOImpl.java | 15 +++++++++------ .../src/test/resources/sql/h2.sql | 1 + .../src/test/resources/sql/CreateH2TestDB.sql | 1 + .../src/main/resources/dbscripts/cdm/h2.sql | 1 + .../src/main/resources/dbscripts/cdm/mssql.sql | 1 + .../src/main/resources/dbscripts/cdm/mysql.sql | 1 + .../src/main/resources/dbscripts/cdm/oracle.sql | 1 + .../main/resources/dbscripts/cdm/postgresql.sql | 1 + 9 files changed, 27 insertions(+), 7 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 1b17534dcf..82e3108149 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 @@ -49,8 +49,10 @@ public class Application implements Serializable { private Properties appProperties; @ApiModelProperty(name = "applicationIdentifier", value = "The application identifier", required = true) private String applicationIdentifier; - @ApiModelProperty(name = "memoryUsage", value = "AMount of memory used by the application", required = true) + @ApiModelProperty(name = "memoryUsage", value = "Amount of memory used by the application", required = true) private int memoryUsage; + @ApiModelProperty(name = "isActive", value = "Is the application actively running", required = true) + private boolean isActive; public String getType() { @@ -166,4 +168,12 @@ public class Application implements Serializable { this.appProperties = appProperties; } + + public boolean isActive() { + return isActive; + } + + public void setActive(boolean active) { + isActive = active; + } } 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 f6b320682b..a9312623ae 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, MEMORY_USAGE) " + - "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); + "VERSION, TYPE, LOCATION_URL, IMAGE_URL, TENANT_ID, APP_PROPERTIES, APP_IDENTIFIER, MEMORY_USAGE, IS_ACTIVE) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); stmt.setString(1, application.getName()); stmt.setString(2, application.getPlatform()); @@ -66,6 +66,7 @@ public class ApplicationDAOImpl implements ApplicationDAO { stmt.setString(10, application.getApplicationIdentifier()); stmt.setInt(11, application.getMemoryUsage()); + stmt.setBoolean(12, application.isActive()); stmt.execute(); rs = stmt.getGeneratedKeys(); @@ -109,8 +110,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, MEMORY_USAGE) " + - "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new String[]{"id"}); + "VERSION, TYPE, LOCATION_URL, IMAGE_URL, TENANT_ID,APP_PROPERTIES, APP_IDENTIFIER, MEMORY_USAGE, IS_ACTIVE) " + + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", new String[]{"id"}); for (Application application : applications) { @@ -131,6 +132,7 @@ public class ApplicationDAOImpl implements ApplicationDAO { stmt.setString(10, application.getApplicationIdentifier()); stmt.setInt(11, application.getMemoryUsage()); + stmt.setBoolean(12, application.isActive()); stmt.executeUpdate(); rs = stmt.getGeneratedKeys(); @@ -208,7 +210,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, MEMORY_USAGE, TENANT_ID FROM DM_APPLICATION WHERE APP_IDENTIFIER = ? " + + "LOCATION_URL, IMAGE_URL, APP_PROPERTIES, MEMORY_USAGE, IS_ACTIVE, TENANT_ID FROM DM_APPLICATION WHERE APP_IDENTIFIER = ? " + "AND TENANT_ID = ?"); stmt.setString(1, identifier); stmt.setInt(2, tenantId); @@ -240,7 +242,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, MEMORY_USAGE, TENANT_ID From DM_APPLICATION app " + + "LOCATION_URL, IMAGE_URL, APP_PROPERTIES, MEMORY_USAGE, IS_ACTIVE, TENANT_ID From DM_APPLICATION app " + "INNER JOIN " + "(Select APPLICATION_ID From DM_DEVICE_APPLICATION_MAPPING WHERE DEVICE_ID=?) APPMAP " + "ON " + @@ -287,6 +289,7 @@ public class ApplicationDAOImpl implements ApplicationDAO { application.setPlatform(rs.getString("PLATFORM")); application.setVersion(rs.getString("VERSION")); application.setMemoryUsage(rs.getInt("MEMORY_USAGE")); + application.setActive(rs.getBoolean("IS_ACTIVE")); application.setApplicationIdentifier(rs.getString("APP_IDENTIFIER")); } catch (IOException e) { 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 f9062684ae..a370c70ca1 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 @@ -388,6 +388,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( IMAGE_URL VARCHAR(100) DEFAULT NULL, APP_PROPERTIES BLOB NULL, MEMORY_USAGE INTEGER(10) NULL, + IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE, TENANT_ID INTEGER NOT NULL, PRIMARY KEY (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 fe3d2de042..d7ab39170b 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 @@ -392,6 +392,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( IMAGE_URL VARCHAR(100) DEFAULT NULL, APP_PROPERTIES BLOB NULL, MEMORY_USAGE INTEGER(10) NULL, + IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE, 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 fe3d2de042..d7ab39170b 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 @@ -392,6 +392,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( IMAGE_URL VARCHAR(100) DEFAULT NULL, APP_PROPERTIES BLOB NULL, MEMORY_USAGE INTEGER(10) NULL, + IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE, 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 b810963921..68345b343b 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 @@ -399,6 +399,7 @@ CREATE TABLE DM_APPLICATION ( IMAGE_URL VARCHAR(100) DEFAULT NULL, APP_PROPERTIES VARBINARY(max) NULL, MEMORY_USAGE INTEGER NULL, + IS_ACTIVE BIT NOT NULL DEFAULT 'FALSE', 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 651bb734e9..d7f4efab06 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 @@ -365,6 +365,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( IMAGE_URL VARCHAR(100) DEFAULT NULL, APP_PROPERTIES BLOB NULL, MEMORY_USAGE INTEGER(10) NULL, + IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE, 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 de8645df1f..57f55c5d17 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 @@ -661,6 +661,7 @@ CREATE TABLE DM_APPLICATION ( IMAGE_URL VARCHAR2(100) DEFAULT NULL, APP_PROPERTIES BLOB NULL, MEMORY_USAGE NUMBER(10) NULL, + IS_ACTIVE NUMBER(10) DEFAULT 0 NOT 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 407c2cc155..bfc4a7f062 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 @@ -341,6 +341,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( IMAGE_URL VARCHAR(100) DEFAULT NULL, APP_PROPERTIES BYTEA NULL, MEMORY_USAGE INTEGER NULL, + IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE, TENANT_ID INTEGER NOT NULL );