Adding Platform TAG functionalities

feature/appm-store/pbac
Pasindu 7 years ago
parent c951b2ca1b
commit c9bdceafb5

@ -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.common.Util;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; 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.exception.PlatformManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import java.sql.Connection; import java.sql.Connection;
@ -78,6 +79,27 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
preparedStatement.execute(); 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 { } else {
String insertToPlatform = String insertToPlatform =
"INSERT INTO APPM_PLATFORM (IDENTIFIER, TENANT_ID, FILE_BASED, IS_SHARED, " "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.setShared(rs.getBoolean(8));
platform.setDefaultTenantMapping(rs.getBoolean(9)); platform.setDefaultTenantMapping(rs.getBoolean(9));
platform.setId(rs.getInt(4)); 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<String> tags = new ArrayList<>();
while (rsTags.next()) {
tags.add(rsTags.getString("NAME"));
}
platform.setTags(tags);
if (!platform.isFileBased()) { if (!platform.isFileBased()) {
platform.setName(rs.getString(5)); platform.setName(rs.getString(5));
platform.setDescription(rs.getString(6)); platform.setDescription(rs.getString(6));

@ -37,4 +37,5 @@ public class SQLQueries {
static String queryToGetPlatforms = "SELECT MAPPING.ID, PLATFORM.IDENTIFIER FROM (SELECT * FROM APPM_PLATFORM " 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 " + "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 = ?"; + "MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID AND MAPPING.TENANT_ID = ?";
static String queryToGetPlatformTags = "SELECT * FROM APPM_PLATFORM_TAG WHERE PLATFORM_ID=?";
} }

@ -28,7 +28,6 @@
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>org.wso2.carbon.device.application.mgt.publisher.ui</artifactId> <artifactId>org.wso2.carbon.device.application.mgt.publisher.ui</artifactId>
<version>3.0.46-SNAPSHOT</version> <version>3.0.46-SNAPSHOT</version>
<packaging>pom</packaging>
<name>WSO2 Carbon - Application Management Publisher UI</name> <name>WSO2 Carbon - Application Management Publisher UI</name>
<description>WSO2 Carbon - Application Management Publisher UI React Application</description> <description>WSO2 Carbon - Application Management Publisher UI React Application</description>
<url>http://wso2.org</url> <url>http://wso2.org</url>

@ -292,8 +292,8 @@ CREATE TABLE IF NOT EXISTS APPM_PLATFORM_TAG (
CONSTRAINT fk_APPM_SUPPORTED_PLATFORM_TAGS_APPM_SUPPORTED_PLATFORM1 CONSTRAINT fk_APPM_SUPPORTED_PLATFORM_TAGS_APPM_SUPPORTED_PLATFORM1
FOREIGN KEY (PLATFORM_ID) FOREIGN KEY (PLATFORM_ID)
REFERENCES APPM_PLATFORM (ID) REFERENCES APPM_PLATFORM (ID)
ON DELETE NO ACTION ON DELETE CASCADE
ON UPDATE NO ACTION); ON UPDATE CASCADE);
CREATE INDEX FK_PLATFORM_TAGS_PLATFORM ON APPM_PLATFORM_TAG(PLATFORM_ID ASC); CREATE INDEX FK_PLATFORM_TAGS_PLATFORM ON APPM_PLATFORM_TAG(PLATFORM_ID ASC);

@ -32,4 +32,12 @@ FOREIGN KEY(PLATFORM_ID) REFERENCES APPM_PLATFORM(ID) ON DELETE CASCADE,
PRIMARY KEY (ID, TENANT_ID, PLATFORM_ID) 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); CREATE INDEX FK_PLATFROM_TENANT_MAPPING_PLATFORM ON APPM_PLATFORM_TENANT_MAPPING(PLATFORM_ID ASC);

@ -327,8 +327,8 @@ CREATE TABLE IF NOT EXISTS `APPM_PLATFORM_TAG` (
CONSTRAINT `fk_APPM_SUPPORTED_PLATFORM_TAGS_APPM_SUPPORTED_PLATFORM1` CONSTRAINT `fk_APPM_SUPPORTED_PLATFORM_TAGS_APPM_SUPPORTED_PLATFORM1`
FOREIGN KEY (`PLATFORM_ID`) FOREIGN KEY (`PLATFORM_ID`)
REFERENCES `APPM_PLATFORM` (`ID`) REFERENCES `APPM_PLATFORM` (`ID`)
ON DELETE NO ACTION ON DELETE CASCADE
ON UPDATE NO ACTION) ON UPDATE CASCADE)
ENGINE = InnoDB ENGINE = InnoDB
COMMENT = 'This table contains the data related to the app platform tag'; COMMENT = 'This table contains the data related to the app platform tag';

@ -353,3 +353,18 @@ CREATE TABLE APPM_APPLICATION_TAG (
CREATE INDEX FK_APPM_APP_TAG_APP ON APPM_APPLICATION_TAG(APPLICATION_ID ASC) 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)
/

@ -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 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 TABLE IF EXISTS APPM_APPLICATION_RELEASE;
DROP SEQUENCE IF EXISTS APPM_APPLICATION_RELEASE_PK_SEQ; DROP SEQUENCE IF EXISTS APPM_APPLICATION_RELEASE_PK_SEQ;
CREATE SEQUENCE APPM_APPLICATION_RELEASE_PK_SEQ; CREATE SEQUENCE APPM_APPLICATION_RELEASE_PK_SEQ;

Loading…
Cancel
Save