Fixing minor issues with database queries

feature/appm-store/pbac
megala21 7 years ago
parent b1fc0fcfdb
commit e79c9b4919

@ -249,7 +249,7 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
try {
ConnectionManagerUtil.beginTransaction();
for (String platformIdentifier : platformIdentifiers) {
if (getTenantPlatformMapping(tenantId, platformIdentifier) != -1) {
if (getTenantPlatformMapping(tenantId, platformIdentifier) == -1) {
int platformId = getPlatformId(tenantId, platformIdentifier);
Connection connection = ConnectionManagerUtil.getConnection();
PreparedStatement preparedStatement = connection.prepareStatement(insertMapping);
@ -285,8 +285,8 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
private int getTenantPlatformMapping(int tenantId, String platformIdentifier) throws
PlatformManagementDAOException {
String getMapping = "SELECT MAPPING.ID as ID FROM (SELECT ID FROM APPM_PLATFORM_TENANT_MAPPING WHERE "
+ "TENANT_ID=?) MAPPING JOIN (SELECT ID FROM APPM_PLATFORM WHERE APPM_PLATFORM.IDENTIFIER=?) "
String getMapping = "SELECT MAPPING.ID as ID FROM (SELECT ID, PLATFORM_ID FROM APPM_PLATFORM_TENANT_MAPPING "
+ "WHERE TENANT_ID=?) MAPPING JOIN (SELECT ID FROM APPM_PLATFORM WHERE APPM_PLATFORM.IDENTIFIER=?) "
+ "PLATFORM ON MAPPING.PLATFORM_ID=PLATFORM.ID";
try {
Connection connection = ConnectionManagerUtil.getConnection();
@ -300,7 +300,7 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
return -1;
} catch (DBConnectionException e) {
throw new PlatformManagementDAOException(
"Error occured while obtaining the connection to get the existing " + "Tenant - Platform Mapping.",
"Error occurred while obtaining the connection to get the existing " + "Tenant - Platform Mapping.",
e);
} catch (SQLException e) {
throw new PlatformManagementDAOException("Error occured while executing the SQL query - " + getMapping, e);
@ -462,21 +462,27 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
try {
conn = this.getConnection();
sql += "SELECT * ";
sql += "FROM APPM_PLATFORM ";
sql += "WHERE IDENTIFIER = ? ";
sql += "SELECT * FROM APPM_PLATFORM WHERE IDENTIFIER = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, identifier);
stmt.setInt(2, tenantId);
rs = stmt.executeQuery();
Platform platform = null;
if (rs.next()) {
platform = new Platform();
platform.setId(rs.getInt("ID"));
platform.setName(rs.getString("NAME"));
platform.setFileBased(rs.getBoolean("FILE_BASED"));
platform.setIdentifier(rs.getString("IDENTIFIER"));
if (!platform.isFileBased()) {
platform.setId(rs.getInt("ID"));
platform.setName(rs.getString("NAME"));
platform.setDescription(rs.getString("DESCRIPTION"));
platform.setIconName(rs.getString("ICON_NAME"));
platform.setShared(rs.getBoolean("IS_SHARED"));
}
}
return platform;

@ -59,7 +59,7 @@ public class PlatformDeployer extends AbstractDeployer {
JAXBContext jaxbContext = JAXBContext.newInstance(Platform.class);
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
Platform platformConf = (Platform) unmarshaller.unmarshal(deploymentFile);
if (platformConf.getName().contentEquals(getPlatformID(deploymentFile.getName()))) {
if (platformConf.getId().contentEquals(getPlatformID(deploymentFile.getName()))) {
org.wso2.carbon.device.application.mgt.common.Platform platform = convert(platformConf);
DataHolder.getInstance().getPlatformManager()
.register(CarbonContext.getThreadLocalCarbonContext().getTenantId(), platform);
@ -105,13 +105,16 @@ public class PlatformDeployer extends AbstractDeployer {
platform.setDefaultTenantMapping(platformConfig.isTenantMapping());
platform.setEnabled(false);
List<org.wso2.carbon.device.application.mgt.common.Platform.Property> properties = new ArrayList<>();
for (Property propertyConfig : platformConfig.getProperties()) {
org.wso2.carbon.device.application.mgt.common.Platform.Property property =
new org.wso2.carbon.device.application.mgt.common.Platform.Property();
property.setName(propertyConfig.getName());
property.setDefaultValue(propertyConfig.getDefaultValue());
property.setOptional(propertyConfig.isOptional());
properties.add(property);
if (platformConfig.getProperties() != null) {
for (Property propertyConfig : platformConfig.getProperties()) {
org.wso2.carbon.device.application.mgt.common.Platform.Property property =
new org.wso2.carbon.device.application.mgt.common.Platform.Property();
property.setName(propertyConfig.getName());
property.setDefaultValue(propertyConfig.getDefaultValue());
property.setOptional(propertyConfig.isOptional());
properties.add(property);
}
}
platform.setProperties(properties);
return platform;

@ -6,18 +6,37 @@
-- Table APPM_PLATFORM
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS APPM_PLATFORM (
ID INT NOT NULL,
NAME VARCHAR(100) NOT NULL,
DESCRIPTION TEXT NULL,
IDENTIFIER VARCHAR(100) NOT NULL,
ICON_NAME VARCHAR(100) NULL,
DESCRIPTOR LONGTEXT NOT NULL,
PUBLISHED TINYINT NULL,
IS_SHARED BOOLEAN DEFAULT FALSE,
FILE_BASED BOOLEAN DEFAULT FALSE,
TENANT_ID INT,
PRIMARY KEY (ID),
UNIQUE INDEX IDENTIFIER_UNIQUE (IDENTIFIER ASC));
ID INT NOT NULL AUTO_INCREMENT UNIQUE,
IDENTIFIER VARCHAR (100) NOT NULL,
TENANT_ID INT NOT NULL ,
NAME VARCHAR (255),
FILE_BASED BOOLEAN,
DESCRIPTION LONGVARCHAR,
IS_SHARED BOOLEAN,
ICON_NAME VARCHAR (100),
PRIMARY KEY (IDENTIFIER, TENANT_ID)
);
CREATE TABLE IF NOT EXISTS APPM_PLATFORM_PROPERTIES (
ID INT NOT NULL AUTO_INCREMENT,
PLATFORM_ID VARCHAR (100) NOT NULL,
PROP_NAME VARCHAR (100) NOT NULL,
OPTIONAL BOOLEAN,
DEFAUL_VALUE VARCHAR (255),
TENANT_ID INT NOT NULL ,
FOREIGN KEY(PLATFORM_ID, TENANT_ID) REFERENCES APPM_PLATFORM(IDENTIFIER, TENANT_ID) ON DELETE CASCADE,
PRIMARY KEY (ID, PLATFORM_ID, PROP_NAME, TENANT_ID)
);
CREATE TABLE IF NOT EXISTS APPM_PLATFORM_TENANT_MAPPING (
ID INT NOT NULL AUTO_INCREMENT,
TENANT_ID INT NOT NULL ,
PLATFORM_ID VARCHAR (100) NOT NULL,
FOREIGN KEY(PLATFORM_ID) REFERENCES APPM_PLATFORM(IDENTIFIER) ON DELETE CASCADE,
PRIMARY KEY (ID, TENANT_ID, PLATFORM_ID)
);
CREATE INDEX FK_PLATFROM_TENANT_MAPPING_PLATFORM ON APPM_PLATFORM_TENANT_MAPPING(PLATFORM_ID ASC);
-- -----------------------------------------------------
-- Table APPM_APPLICATION_CATEGORY
@ -29,21 +48,6 @@ CREATE TABLE IF NOT EXISTS APPM_APPLICATION_CATEGORY (
PUBLISHED TINYINT NULL,
PRIMARY KEY (ID));
-- -----------------------------------------------------
-- Table APPM_PLATFORM_TENANT_MAPPING
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS APPM_PLATFORM_TENANT_MAPPING (
ID INT NOT NULL AUTO_INCREMENT,
PLATFORM_ID INT NOT NULL,
TENANT_ID INT NOT NULL,
PRIMARY KEY (ID, PLATFORM_ID),
CONSTRAINT fk_APPM_PLATFORM_TENANT_MAPPING_APPM_SUPPORTED_PLATFORM1
FOREIGN KEY (PLATFORM_ID)
REFERENCES APPM_PLATFORM (ID)
ON DELETE NO ACTION
ON UPDATE NO ACTION);
CREATE INDEX FK_PLATFROM_TENANT_MAPPING_PLATFORM ON APPM_PLATFORM_TENANT_MAPPING(PLATFORM_ID ASC);
-- -----------------------------------------------------

@ -14,18 +14,28 @@ SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
-- -----------------------------------------------------
-- Table `APPM_PLATFORM`
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `APPM_PLATFORM` (
`ID` INT NOT NULL,
`NAME` VARCHAR(100) NOT NULL,
`DESCRIPTION` TEXT NULL,
`IDENTIFIER` VARCHAR(100) NOT NULL,
`DESCRIPTOR` LONGTEXT NOT NULL,
IS_SHARED BOOLEAN DEFAULT FALSE,
FILE_BASED BOOLEAN DEFAULT FALSE,
PRIMARY KEY (`ID`),
UNIQUE INDEX `IDENTIFIER_UNIQUE` (`IDENTIFIER` ASC))
ENGINE = InnoDB
COMMENT = 'This table contains the data related to the application platform';
CREATE TABLE IF NOT EXISTS APPM_PLATFORM (
ID INT NOT NULL AUTO_INCREMENT UNIQUE,
IDENTIFIER VARCHAR (100) NOT NULL,
TENANT_ID INT NOT NULL ,
NAME VARCHAR (255),
FILE_BASED BOOLEAN,
DESCRIPTION VARCHAR(2048),
IS_SHARED BOOLEAN,
ICON_NAME VARCHAR (100),
PRIMARY KEY (IDENTIFIER, TENANT_ID)
);
CREATE TABLE IF NOT EXISTS APPM_PLATFORM_PROPERTIES (
ID INT NOT NULL AUTO_INCREMENT UNIQUE,
PLATFORM_ID VARCHAR (100) NOT NULL,
TENANT_ID INT NOT NULL ,
PROP_NAME VARCHAR (100) NOT NULL,
OPTIONAL BOOLEAN,
DEFAUL_VALUE VARCHAR (255),
PRIMARY KEY (ID, PLATFORM_ID, PROP_NAME, TENANT_ID),
FOREIGN KEY(PLATFORM_ID, TENANT_ID) REFERENCES APPM_PLATFORM(IDENTIFIER, TENANT_ID) ON DELETE CASCADE
);
-- -----------------------------------------------------

Loading…
Cancel
Save