From c9bdceafb559b9cb77470611f5cfc36d66997af6 Mon Sep 17 00:00:00 2001 From: Pasindu Date: Mon, 25 Sep 2017 09:52:47 +0530 Subject: [PATCH] Adding Platform TAG functionalities --- .../impl/platform/GenericPlatformDAOImpl.java | 34 +++++++++++++++++++ .../core/dao/impl/platform/SQLQueries.java | 1 + .../pom.xml | 1 - .../dbscripts/cdm/application-mgt/h2.sql | 4 +-- .../dbscripts/cdm/application-mgt/mssql.sql | 8 +++++ .../dbscripts/cdm/application-mgt/mysql.sql | 4 +-- .../dbscripts/cdm/application-mgt/oracle.sql | 15 ++++++++ .../cdm/application-mgt/postgresql.sql | 10 ++++++ 8 files changed, 72 insertions(+), 5 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/GenericPlatformDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/GenericPlatformDAOImpl.java index de980fd5ed0..360eb49cbaf 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/GenericPlatformDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/GenericPlatformDAOImpl.java @@ -26,6 +26,7 @@ import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO; import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; import org.wso2.carbon.device.application.mgt.core.exception.PlatformManagementDAOException; +import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import java.sql.Connection; @@ -78,6 +79,27 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD preparedStatement.execute(); } } + //Adding tags to the database. + Boolean isBatchExecutionSupported = ConnectionManagerUtil.isBatchQuerySupported(); + String insertTags = "INSERT INTO APPM_PLATFORM_TAG (NAME, PLATFORM_ID) VALUES (?, ?)"; + preparedStatement = connection.prepareStatement(insertTags); + if (platform.getTags() != null) { + for (String tag : platform.getTags()) { + preparedStatement.setString(1, tag); + preparedStatement.setInt(2, platformId); + + if (isBatchExecutionSupported) { + preparedStatement.addBatch(); + } + else { + preparedStatement.execute(); + } + } + if (isBatchExecutionSupported) { + preparedStatement.executeBatch(); + } + } + } else { String insertToPlatform = "INSERT INTO APPM_PLATFORM (IDENTIFIER, TENANT_ID, FILE_BASED, IS_SHARED, " @@ -486,6 +508,18 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD platform.setShared(rs.getBoolean(8)); platform.setDefaultTenantMapping(rs.getBoolean(9)); platform.setId(rs.getInt(4)); + //Getting tags + sql = "SELECT * FROM APPM_PLATFORM_TAG WHERE PLATFORM_ID=?"; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, rs.getInt(4)); + ResultSet rsTags = stmt.executeQuery(); + + List tags = new ArrayList<>(); + while (rsTags.next()) { + tags.add(rsTags.getString("NAME")); + } + platform.setTags(tags); + if (!platform.isFileBased()) { platform.setName(rs.getString(5)); platform.setDescription(rs.getString(6)); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/SQLQueries.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/SQLQueries.java index 73eab98ac4e..91b6315d2d1 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/SQLQueries.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/SQLQueries.java @@ -37,4 +37,5 @@ public class SQLQueries { static String queryToGetPlatforms = "SELECT MAPPING.ID, PLATFORM.IDENTIFIER FROM (SELECT * FROM APPM_PLATFORM " + "WHERE TENANT_ID=? OR IS_SHARED = TRUE ) PLATFORM LEFT JOIN APPM_PLATFORM_TENANT_MAPPING " + "MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID AND MAPPING.TENANT_ID = ?"; + static String queryToGetPlatformTags = "SELECT * FROM APPM_PLATFORM_TAG WHERE PLATFORM_ID=?"; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml index 00548da9879..d1cf9388ada 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/pom.xml @@ -28,7 +28,6 @@ 4.0.0 org.wso2.carbon.device.application.mgt.publisher.ui 3.0.46-SNAPSHOT - pom WSO2 Carbon - Application Management Publisher UI WSO2 Carbon - Application Management Publisher UI React Application http://wso2.org diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index f8596375b34..3d5e3c4fc4e 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -292,8 +292,8 @@ CREATE TABLE IF NOT EXISTS APPM_PLATFORM_TAG ( CONSTRAINT fk_APPM_SUPPORTED_PLATFORM_TAGS_APPM_SUPPORTED_PLATFORM1 FOREIGN KEY (PLATFORM_ID) REFERENCES APPM_PLATFORM (ID) - ON DELETE NO ACTION - ON UPDATE NO ACTION); + ON DELETE CASCADE + ON UPDATE CASCADE); CREATE INDEX FK_PLATFORM_TAGS_PLATFORM ON APPM_PLATFORM_TAG(PLATFORM_ID ASC); diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql index 42fd4cb36b0..8fa1a42b4be 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mssql.sql @@ -32,4 +32,12 @@ FOREIGN KEY(PLATFORM_ID) REFERENCES APPM_PLATFORM(ID) ON DELETE CASCADE, PRIMARY KEY (ID, TENANT_ID, PLATFORM_ID) ); +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[APPM_PLATFORM_TAG]') AND TYPE IN (N'U')) +CREATE TABLE APPM_PLATFORM_TAG ( +NAME VARCHAR (100) NOT NULL , +PLATFORM_ID INT NOT NULL, +FOREIGN KEY(PLATFORM_ID) REFERENCES APPM_PLATFORM(ID) ON DELETE CASCADE, +PRIMARY KEY (PLATFORM_ID, NAME) +); + CREATE INDEX FK_PLATFROM_TENANT_MAPPING_PLATFORM ON APPM_PLATFORM_TENANT_MAPPING(PLATFORM_ID ASC); \ No newline at end of file diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index a5f5bbd5a51..3e378c09e06 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -327,8 +327,8 @@ CREATE TABLE IF NOT EXISTS `APPM_PLATFORM_TAG` ( CONSTRAINT `fk_APPM_SUPPORTED_PLATFORM_TAGS_APPM_SUPPORTED_PLATFORM1` FOREIGN KEY (`PLATFORM_ID`) REFERENCES `APPM_PLATFORM` (`ID`) - ON DELETE NO ACTION - ON UPDATE NO ACTION) + ON DELETE CASCADE + ON UPDATE CASCADE) ENGINE = InnoDB COMMENT = 'This table contains the data related to the app platform tag'; diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql index 174b1d6fc5d..0cb323dbe46 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/oracle.sql @@ -353,3 +353,18 @@ CREATE TABLE APPM_APPLICATION_TAG ( CREATE INDEX FK_APPM_APP_TAG_APP ON APPM_APPLICATION_TAG(APPLICATION_ID ASC) / + + +CREATE TABLE APPM_PLATFORM_TAG ( + NAME VARCHAR(100) NOT NULL, + PLATFORM_ID INT NOT NULL, + PRIMARY KEY (PLATFORM_ID, NAME), + CONSTRAINT FK_APPM_PLATFORM_TAG_APP + FOREIGN KEY (PLATFORM_ID) + REFERENCES APPM_PLATFORM (ID)) +/ + +CREATE INDEX FK_APPM_PLATFORM_TAG_APP ON APPM_PLATFORM_TAG(PLATFORM_ID ASC) +/ + + diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql index 7259c736bf5..5937f68d08e 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/postgresql.sql @@ -203,6 +203,16 @@ CREATE TABLE IF NOT EXISTS APPM_APPLICATION_TAG ( CREATE INDEX IF NOT EXISTS FK_APPLICATION_TAG_APPLICATION ON APPM_APPLICATION_TAG(APPLICATION_ID ASC); +CREATE TABLE IF NOT EXISTS APPM_PLATFORM_TAG ( + NAME VARCHAR(100) NOT NULL, + PLATFORM_ID INT NOT NULL, + PRIMARY KEY (PLATFORM_ID, NAME), + CONSTRAINT fk_APPM_PLATFORM_TAG_APPM_APPLICATION1 + FOREIGN KEY (PLATFORM_ID) + REFERENCES APPM_PLATFORM (ID) + ON DELETE CASCADE + ON UPDATE CASCADE); + DROP TABLE IF EXISTS APPM_APPLICATION_RELEASE; DROP SEQUENCE IF EXISTS APPM_APPLICATION_RELEASE_PK_SEQ; CREATE SEQUENCE APPM_APPLICATION_RELEASE_PK_SEQ;