|
|
@ -22,11 +22,10 @@ import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.Platform;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.Platform;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.TransactionManagementException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.PlatformDAO;
|
|
|
|
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.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;
|
|
|
@ -36,155 +35,181 @@ import java.sql.SQLException;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* Generic Implementation for handling Platform management related database operations.
|
|
|
|
|
|
|
|
*/
|
|
|
|
public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformDAO {
|
|
|
|
public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformDAO {
|
|
|
|
private static Log log = LogFactory.getLog(GenericPlatformDAOImpl.class);
|
|
|
|
private static Log log = LogFactory.getLog(GenericPlatformDAOImpl.class);
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int register(String tenantDomain, Platform platform) throws PlatformManagementDAOException {
|
|
|
|
public int register(int tenantId, Platform platform) throws PlatformManagementDAOException {
|
|
|
|
|
|
|
|
PreparedStatement preparedStatement = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
int platformId = getPlatformId(tenantId, platform.getIdentifier());
|
|
|
|
int platformId = getPlatformId(tenantDomain, platform.getIdentifier());
|
|
|
|
|
|
|
|
if (platformId == -1) {
|
|
|
|
if (platformId == -1) {
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
Connection connection = this.getDBConnection();
|
|
|
|
if (!platform.isFileBased()) {
|
|
|
|
if (!platform.isFileBased()) {
|
|
|
|
String insertToPlatform = "INSERT INTO APPM_PLATFORM (IDENTIFIER, TENANT_DOMAIN, NAME, FILE_BASED, DESCRIPTION, IS_SHARED, ICON_NAME)" +
|
|
|
|
String insertToPlatform = "INSERT INTO APPM_PLATFORM (IDENTIFIER, TENANT_ID, NAME, FILE_BASED, "
|
|
|
|
" VALUES (?, ?, ?, ?, ?, ?, ?)";
|
|
|
|
+ "DESCRIPTION, IS_SHARED, ICON_NAME, IS_DEFAULT_TENANT_MAPPING)" + " VALUES (?, ?, ?, ?, "
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(insertToPlatform);
|
|
|
|
+ "?, ?, ?, ?)";
|
|
|
|
|
|
|
|
preparedStatement = connection.prepareStatement(insertToPlatform);
|
|
|
|
preparedStatement.setString(1, platform.getIdentifier());
|
|
|
|
preparedStatement.setString(1, platform.getIdentifier());
|
|
|
|
preparedStatement.setString(2, tenantDomain);
|
|
|
|
preparedStatement.setInt(2, tenantId);
|
|
|
|
preparedStatement.setString(3, platform.getName());
|
|
|
|
preparedStatement.setString(3, platform.getName());
|
|
|
|
preparedStatement.setBoolean(4, false);
|
|
|
|
preparedStatement.setBoolean(4, false);
|
|
|
|
preparedStatement.setString(5, platform.getDescription());
|
|
|
|
preparedStatement.setString(5, platform.getDescription());
|
|
|
|
preparedStatement.setBoolean(6, platform.isShared());
|
|
|
|
preparedStatement.setBoolean(6, platform.isShared());
|
|
|
|
preparedStatement.setString(7, platform.getIconName());
|
|
|
|
preparedStatement.setString(7, platform.getIconName());
|
|
|
|
|
|
|
|
preparedStatement.setBoolean(8, platform.isDefaultTenantMapping());
|
|
|
|
preparedStatement.execute();
|
|
|
|
preparedStatement.execute();
|
|
|
|
|
|
|
|
|
|
|
|
platformId = getPlatformId(tenantDomain, platform.getIdentifier());
|
|
|
|
platformId = getPlatformId(tenantId, platform.getIdentifier());
|
|
|
|
String insertPlatformProps = "INSERT INTO APPM_PLATFORM_PROPERTIES (PLATFORM_ID, PROP_NAME, OPTIONAL, DEFAULT_VALUE) VALUES " +
|
|
|
|
String insertPlatformProps =
|
|
|
|
"( ? , ?, ? , ?)";
|
|
|
|
"INSERT INTO APPM_PLATFORM_PROPERTIES (PLATFORM_ID, PROP_NAME, OPTIONAL, "
|
|
|
|
for (Platform.Property property : platform.getProperties()) {
|
|
|
|
+ "DEFAULT_VALUE) VALUES ( ? , ?, ? , ?)";
|
|
|
|
preparedStatement = connection.prepareStatement(insertPlatformProps);
|
|
|
|
|
|
|
|
preparedStatement.setInt(1, platformId);
|
|
|
|
if (platform.getProperties() != null) {
|
|
|
|
preparedStatement.setString(2, property.getName());
|
|
|
|
for (Platform.Property property : platform.getProperties()) {
|
|
|
|
preparedStatement.setBoolean(3, property.isOptional());
|
|
|
|
preparedStatement = connection.prepareStatement(insertPlatformProps);
|
|
|
|
preparedStatement.setString(4, property.getDefaultValue());
|
|
|
|
preparedStatement.setInt(1, platformId);
|
|
|
|
preparedStatement.execute();
|
|
|
|
preparedStatement.setString(2, property.getName());
|
|
|
|
|
|
|
|
preparedStatement.setBoolean(3, property.isOptional());
|
|
|
|
|
|
|
|
preparedStatement.setString(4, property.getDefaultValue());
|
|
|
|
|
|
|
|
preparedStatement.execute();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
String insertToPlatform = "INSERT INTO APPM_PLATFORM (IDENTIFIER, TENANT_DOMAIN, FILE_BASED)" +
|
|
|
|
String insertToPlatform =
|
|
|
|
" VALUES (?, ?, ?)";
|
|
|
|
"INSERT INTO APPM_PLATFORM (IDENTIFIER, TENANT_ID, FILE_BASED, IS_SHARED, "
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(insertToPlatform);
|
|
|
|
+ "IS_DEFAULT_TENANT_MAPPING) VALUES (?, ?, ?, ?, ?)";
|
|
|
|
|
|
|
|
preparedStatement = connection.prepareStatement(insertToPlatform);
|
|
|
|
preparedStatement.setString(1, platform.getIdentifier());
|
|
|
|
preparedStatement.setString(1, platform.getIdentifier());
|
|
|
|
preparedStatement.setString(2, tenantDomain);
|
|
|
|
preparedStatement.setInt(2, tenantId);
|
|
|
|
preparedStatement.setBoolean(3, true);
|
|
|
|
preparedStatement.setBoolean(3, true);
|
|
|
|
|
|
|
|
preparedStatement.setBoolean(4, platform.isShared());
|
|
|
|
|
|
|
|
preparedStatement.setBoolean(5, platform.isDefaultTenantMapping());
|
|
|
|
preparedStatement.execute();
|
|
|
|
preparedStatement.execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (platformId == -1) {
|
|
|
|
if (platformId == -1) {
|
|
|
|
platformId = getPlatformId(tenantDomain, platform.getIdentifier());
|
|
|
|
platformId = getPlatformId(tenantId, platform.getIdentifier());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
|
|
|
|
return platformId;
|
|
|
|
return platformId;
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
if (!platform.isFileBased()) {
|
|
|
|
if (!platform.isFileBased()) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
throw new PlatformManagementDAOException("Platform - " + platform.getIdentifier()
|
|
|
|
"Platform - " + platform.getIdentifier() + " is already registered for tenant - "
|
|
|
|
+ " is already registered for tenant - " + tenantDomain);
|
|
|
|
+ tenantId);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return platformId;
|
|
|
|
return platformId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException("Error while executing the SQL query. ", e);
|
|
|
|
throw new PlatformManagementDAOException("Error while executing the SQL query. ", e);
|
|
|
|
} catch (PlatformManagementDAOException ex) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
|
|
|
throw ex;
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
throw new PlatformManagementDAOException("Unable to obtain the connection while trying to register the platform - "
|
|
|
|
"Unable to obtain the connection while trying to register the platform - " + platform
|
|
|
|
+ platform.getIdentifier() + " for tenant - " + tenantDomain, e);
|
|
|
|
.getIdentifier() + " for tenant - " + tenantId, e);
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while performing the transaction on the database " +
|
|
|
|
|
|
|
|
"for adding the platform - " + platform.getIdentifier() + " , tenant domain - " + tenantDomain);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
Util.cleanupResources(preparedStatement, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void update(String tenantDomain, String oldPlatformIdentifier, Platform platform) throws PlatformManagementDAOException {
|
|
|
|
public void update(int tenantId, String oldPlatformIdentifier, Platform platform)
|
|
|
|
|
|
|
|
throws PlatformManagementDAOException {
|
|
|
|
|
|
|
|
PreparedStatement preparedStatement = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
int platformId = getPlatformId(tenantId, oldPlatformIdentifier);
|
|
|
|
int platformId = getPlatformId(tenantDomain, oldPlatformIdentifier);
|
|
|
|
boolean isIdentifierNull = platform.getIdentifier() == null;
|
|
|
|
|
|
|
|
boolean isNameNull = platform.getName() == null;
|
|
|
|
|
|
|
|
|
|
|
|
if (platformId != -1) {
|
|
|
|
if (platformId != -1) {
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
Connection connection = this.getDBConnection();
|
|
|
|
if (!platform.isFileBased()) {
|
|
|
|
if (!platform.isFileBased()) {
|
|
|
|
String insertToPlatform = "UPDATE APPM_PLATFORM SET IDENTIFIER = ?, NAME =?, DESCRIPTION=?, " +
|
|
|
|
String insertToPlatform = "UPDATE APPM_PLATFORM SET DESCRIPTION=?, IS_SHARED=?, ICON_NAME=?, "
|
|
|
|
"IS_SHARED=?, ICON_NAME=? WHERE ID = ?";
|
|
|
|
+ "IS_DEFAULT_TENANT_MAPPING=?";
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(insertToPlatform);
|
|
|
|
if (!isIdentifierNull) {
|
|
|
|
preparedStatement.setString(1, platform.getIdentifier());
|
|
|
|
insertToPlatform += ",IDENTIFIER = ? ";
|
|
|
|
preparedStatement.setString(2, platform.getName());
|
|
|
|
}
|
|
|
|
preparedStatement.setString(3, platform.getDescription());
|
|
|
|
if (!isNameNull) {
|
|
|
|
preparedStatement.setBoolean(4, platform.isShared());
|
|
|
|
insertToPlatform += ", NAME =?";
|
|
|
|
preparedStatement.setString(5, platform.getIconName());
|
|
|
|
}
|
|
|
|
|
|
|
|
insertToPlatform += " WHERE ID = ?";
|
|
|
|
|
|
|
|
preparedStatement = connection.prepareStatement(insertToPlatform);
|
|
|
|
|
|
|
|
preparedStatement.setString(1, platform.getDescription());
|
|
|
|
|
|
|
|
preparedStatement.setBoolean(2, platform.isShared());
|
|
|
|
|
|
|
|
preparedStatement.setString(3, platform.getIconName());
|
|
|
|
|
|
|
|
preparedStatement.setBoolean(4, platform.isDefaultTenantMapping());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isIdentifierNull && !isNameNull) {
|
|
|
|
|
|
|
|
preparedStatement.setString(5, platform.getIdentifier());
|
|
|
|
|
|
|
|
preparedStatement.setString(6, platform.getName());
|
|
|
|
|
|
|
|
preparedStatement.setInt(7, platformId);
|
|
|
|
|
|
|
|
} else if (isIdentifierNull && !isNameNull) {
|
|
|
|
|
|
|
|
preparedStatement.setString(5, platform.getName());
|
|
|
|
|
|
|
|
preparedStatement.setInt(6, platformId);
|
|
|
|
|
|
|
|
} else if (!isIdentifierNull) {
|
|
|
|
|
|
|
|
preparedStatement.setString(5, platform.getIdentifier());
|
|
|
|
|
|
|
|
preparedStatement.setInt(6, platformId);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
preparedStatement.setInt(5, platformId);
|
|
|
|
|
|
|
|
}
|
|
|
|
preparedStatement.execute();
|
|
|
|
preparedStatement.execute();
|
|
|
|
|
|
|
|
|
|
|
|
platformId = getPlatformId(tenantDomain, platform.getIdentifier());
|
|
|
|
platformId = getPlatformId(tenantId, platform.getIdentifier());
|
|
|
|
String deletePlatformProps = "DELETE FROM APPM_PLATFORM_PROPERTIES WHERE PLATFORM_ID=?";
|
|
|
|
String deletePlatformProps = "DELETE FROM APPM_PLATFORM_PROPERTIES WHERE PLATFORM_ID=?";
|
|
|
|
preparedStatement = connection.prepareStatement(deletePlatformProps);
|
|
|
|
preparedStatement = connection.prepareStatement(deletePlatformProps);
|
|
|
|
preparedStatement.setInt(1, platformId);
|
|
|
|
preparedStatement.setInt(1, platformId);
|
|
|
|
preparedStatement.execute();
|
|
|
|
preparedStatement.execute();
|
|
|
|
|
|
|
|
|
|
|
|
String insertPlatformProps = "INSERT INTO APPM_PLATFORM_PROPERTIES (PLATFORM_ID, PROP_NAME, OPTIONAL," +
|
|
|
|
String insertPlatformProps =
|
|
|
|
" DEFAULT_VALUE) VALUES ( ? , ?, ? , ?)";
|
|
|
|
"INSERT INTO APPM_PLATFORM_PROPERTIES (PLATFORM_ID, PROP_NAME, OPTIONAL,"
|
|
|
|
for (Platform.Property property : platform.getProperties()) {
|
|
|
|
+ " DEFAULT_VALUE) VALUES ( ? , ?, ? , ?)";
|
|
|
|
preparedStatement = connection.prepareStatement(insertPlatformProps);
|
|
|
|
|
|
|
|
preparedStatement.setInt(1, platformId);
|
|
|
|
if (platform.getProperties() != null) {
|
|
|
|
preparedStatement.setString(2, property.getName());
|
|
|
|
for (Platform.Property property : platform.getProperties()) {
|
|
|
|
preparedStatement.setBoolean(3, property.isOptional());
|
|
|
|
preparedStatement = connection.prepareStatement(insertPlatformProps);
|
|
|
|
preparedStatement.setString(4, property.getDefaultValue());
|
|
|
|
preparedStatement.setInt(1, platformId);
|
|
|
|
preparedStatement.execute();
|
|
|
|
preparedStatement.setString(2, property.getName());
|
|
|
|
|
|
|
|
preparedStatement.setBoolean(3, property.isOptional());
|
|
|
|
|
|
|
|
preparedStatement.setString(4, property.getDefaultValue());
|
|
|
|
|
|
|
|
preparedStatement.execute();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else if (!isIdentifierNull) {
|
|
|
|
String insertToPlatform = "UPDATE APPM_PLATFORM SET IDENTIFIER = ? WHERE ID = ?";
|
|
|
|
String insertToPlatform = "UPDATE APPM_PLATFORM SET IDENTIFIER = ? WHERE ID = ?";
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(insertToPlatform);
|
|
|
|
preparedStatement = connection.prepareStatement(insertToPlatform);
|
|
|
|
preparedStatement.setInt(1, platformId);
|
|
|
|
preparedStatement.setString(1, platform.getIdentifier());
|
|
|
|
|
|
|
|
preparedStatement.setInt(2, platformId);
|
|
|
|
preparedStatement.execute();
|
|
|
|
preparedStatement.execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new PlatformManagementDAOException("Cannot find any platform that was registered with identifier - "
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
+ platform.getIdentifier() + " for tenant - " + tenantDomain);
|
|
|
|
"Cannot find any platform that was registered with identifier - " + platform.getIdentifier()
|
|
|
|
|
|
|
|
+ " for tenant - " + tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException("Error while executing the SQL query. ", e);
|
|
|
|
throw new PlatformManagementDAOException("Error while executing the SQL query. ", e);
|
|
|
|
} catch (PlatformManagementDAOException ex) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
|
|
|
throw ex;
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
throw new PlatformManagementDAOException("Unable to obtain the connection while trying to register the platform - "
|
|
|
|
"Unable to obtain the connection while trying to register the platform - " + platform
|
|
|
|
+ platform.getIdentifier() + " for tenant - " + tenantDomain, e);
|
|
|
|
.getIdentifier() + " for tenant - " + tenantId, e);
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while performing the transaction on the database " +
|
|
|
|
|
|
|
|
"for adding the platform - " + platform.getIdentifier() + " , tenant domain - " + tenantDomain);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
Util.cleanupResources(preparedStatement, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int getPlatformId(String tenantDomain, String platformIdentifier) throws PlatformManagementDAOException {
|
|
|
|
private int getPlatformId(int tenantId, String platformIdentifier) throws PlatformManagementDAOException {
|
|
|
|
String query = "SELECT ID FROM APPM_PLATFORM WHERE (TENANT_DOMAIN=? AND IDENTIFIER=?) OR (IS_SHARED = TRUE AND IDENTIFIER=?)";
|
|
|
|
PreparedStatement preparedStatement = null;
|
|
|
|
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
|
|
|
|
String query = SQLQueries.queryToGetPlatformId;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
Connection connection = this.getDBConnection();
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(query);
|
|
|
|
preparedStatement = connection.prepareStatement(query);
|
|
|
|
preparedStatement.setString(1, tenantDomain);
|
|
|
|
preparedStatement.setInt(1, tenantId);
|
|
|
|
preparedStatement.setString(2, platformIdentifier);
|
|
|
|
preparedStatement.setString(2, platformIdentifier);
|
|
|
|
preparedStatement.setString(3, platformIdentifier);
|
|
|
|
preparedStatement.setString(3, platformIdentifier);
|
|
|
|
ResultSet resultSet = preparedStatement.executeQuery();
|
|
|
|
resultSet = preparedStatement.executeQuery();
|
|
|
|
if (resultSet.next()) {
|
|
|
|
if (resultSet.next()) {
|
|
|
|
return resultSet.getInt("ID");
|
|
|
|
return resultSet.getInt("ID");
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -193,175 +218,176 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
throw new PlatformManagementDAOException("Error when trying to obtaining the database connection.", e);
|
|
|
|
throw new PlatformManagementDAOException("Error when trying to obtaining the database connection.", e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new PlatformManagementDAOException("Error in executing the query - " + query, e);
|
|
|
|
throw new PlatformManagementDAOException("Error in executing the query - " + query, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
Util.cleanupResources(preparedStatement, resultSet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void unregister(String tenantDomain, String platformIdenfier) throws PlatformManagementDAOException {
|
|
|
|
public void unregister(int tenantId, String platformIdenfier, boolean isFileBased)
|
|
|
|
|
|
|
|
throws PlatformManagementDAOException {
|
|
|
|
|
|
|
|
PreparedStatement preparedStatement = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
Platform platform = getPlatform(tenantId, platformIdenfier);
|
|
|
|
int platformId = getPlatformId(tenantDomain, platformIdenfier);
|
|
|
|
|
|
|
|
if (platformId != -1) {
|
|
|
|
if (platform != null) {
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
if (isFileBased == platform.isFileBased()) {
|
|
|
|
String deletePlatform = "DELETE FROM APPM_PLATFORM WHERE ID = ?";
|
|
|
|
Connection connection = this.getDBConnection();
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(deletePlatform);
|
|
|
|
String deletePlatform = "DELETE FROM APPM_PLATFORM WHERE ID = ?";
|
|
|
|
preparedStatement.setInt(1, platformId);
|
|
|
|
preparedStatement = connection.prepareStatement(deletePlatform);
|
|
|
|
preparedStatement.execute();
|
|
|
|
preparedStatement.setInt(1, platform.getId());
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
preparedStatement.execute();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (isFileBased) {
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException("Platform with identifier - " + platformIdenfier
|
|
|
|
|
|
|
|
+ " is not a file based platform. Try to remove that using PlatformManagement APIs");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException("Platform with identifier - " + platformIdenfier
|
|
|
|
|
|
|
|
+ " is a file based platform. Try to remove that by un-deploying the relevant file.");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new PlatformManagementDAOException("Platform identifier - " + platformIdenfier
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
+ " is already unregistered registered for tenant - " + tenantDomain);
|
|
|
|
"Platform identifier - " + platformIdenfier + " is not registered for tenant - " + tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException("Unable to start the transaction while trying to register the platform - "
|
|
|
|
|
|
|
|
+ platformIdenfier + " for tenant - " + tenantDomain, e);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
throw new PlatformManagementDAOException("Unable to obtain the connection while trying to register the platform - "
|
|
|
|
"Unable to obtain the connection while trying to register the platform - " + platformIdenfier
|
|
|
|
+ platformIdenfier + " for tenant - " + tenantDomain, e);
|
|
|
|
+ " for tenant - " + tenantId, e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException("Error while executing the SQL query. ", e);
|
|
|
|
throw new PlatformManagementDAOException("Error while executing the SQL query. ", e);
|
|
|
|
} catch (PlatformManagementDAOException ex) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
|
|
|
throw ex;
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
Util.cleanupResources(preparedStatement, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void addMapping(String tenantDomain, List<String> platformIdentifiers) throws PlatformManagementDAOException {
|
|
|
|
public void addMapping(int tenantId, List<String> platformIdentifiers) throws PlatformManagementDAOException {
|
|
|
|
String insertMapping = "INSERT INTO APPM_PLATFORM_TENANT_MAPPING(TENANT_DOMAIN, PLATFORM_ID) VALUES (?, ?)";
|
|
|
|
String insertMapping = "INSERT INTO APPM_PLATFORM_TENANT_MAPPING(TENANT_ID, PLATFORM_ID) VALUES (?, ?)";
|
|
|
|
|
|
|
|
PreparedStatement preparedStatement = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
|
|
|
|
for (String platformIdentifier : platformIdentifiers) {
|
|
|
|
for (String platformIdentifier : platformIdentifiers) {
|
|
|
|
if (getTenantPlatformMapping(tenantDomain, platformIdentifier) != -1) {
|
|
|
|
if (getTenantPlatformMapping(tenantId, platformIdentifier) == -1) {
|
|
|
|
int platformId = getPlatformId(tenantDomain, platformIdentifier);
|
|
|
|
int platformId = getPlatformId(tenantId, platformIdentifier);
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
Connection connection = this.getDBConnection();
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(insertMapping);
|
|
|
|
preparedStatement = connection.prepareStatement(insertMapping);
|
|
|
|
preparedStatement.setString(1, tenantDomain);
|
|
|
|
preparedStatement.setInt(1, tenantId);
|
|
|
|
preparedStatement.setInt(2, platformId);
|
|
|
|
preparedStatement.setInt(2, platformId);
|
|
|
|
preparedStatement.execute();
|
|
|
|
preparedStatement.execute();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new PlatformManagementDAOException("Platform identifier - " + platformIdentifier + " is already assigned to tenant domain - " + tenantDomain);
|
|
|
|
log.error("Platform identifier - " + platformIdentifier + " is already assigned to tenant domain"
|
|
|
|
|
|
|
|
+ " - " + tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException("Error occured while trying to add the mapping of platform - "
|
|
|
|
|
|
|
|
+ platformIdentifiers.toString() + " for tenant - " + tenantDomain, e);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException("Error occurred when getting the connection for the database. ",
|
|
|
|
throw new PlatformManagementDAOException("Error occurred when getting the connection for the database. ", e);
|
|
|
|
e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException("Error occured while executing the SQL query - " + insertMapping,
|
|
|
|
throw new PlatformManagementDAOException("Error occured while executing the SQL query - " + insertMapping, e);
|
|
|
|
e);
|
|
|
|
} catch (PlatformManagementDAOException ex) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
|
|
|
throw ex;
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
Util.cleanupResources(preparedStatement, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private int getTenantPlatformMapping(String tenantDomain, String platformIdentifier) throws PlatformManagementDAOException {
|
|
|
|
private int getTenantPlatformMapping(int tenantId, String platformIdentifier)
|
|
|
|
String getMapping = "SELECT MAPPING.ID as ID FROM (SELECT ID FROM APPM_PLATFORM_TENANT_MAPPING WHERE TENANT_DOMAIN=?) MAPPING JOIN " +
|
|
|
|
throws PlatformManagementDAOException {
|
|
|
|
"(SELECT ID FROM APPM_PLATFORM WHERE APPM_PLATFORM.IDENTIFIER=?) PLATFORM ON MAPPING.PLATFORM_ID=PLATFORM.ID";
|
|
|
|
PreparedStatement preparedStatement = null;
|
|
|
|
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
|
|
|
|
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 {
|
|
|
|
try {
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
Connection connection = this.getDBConnection();
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(getMapping);
|
|
|
|
preparedStatement = connection.prepareStatement(getMapping);
|
|
|
|
preparedStatement.setString(1, tenantDomain);
|
|
|
|
preparedStatement.setInt(1, tenantId);
|
|
|
|
preparedStatement.setString(2, platformIdentifier);
|
|
|
|
preparedStatement.setString(2, platformIdentifier);
|
|
|
|
ResultSet resultSet = preparedStatement.executeQuery();
|
|
|
|
resultSet = preparedStatement.executeQuery();
|
|
|
|
if (resultSet.next()) {
|
|
|
|
if (resultSet.next()) {
|
|
|
|
return resultSet.getInt("ID");
|
|
|
|
return resultSet.getInt("ID");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
return -1;
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new PlatformManagementDAOException("Error occured while obtaining the connection to get the existing " +
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
"Tenant - Platform Mapping.", e);
|
|
|
|
"Error occurred while obtaining the connection to get the existing " + "Tenant - Platform Mapping.",
|
|
|
|
|
|
|
|
e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new PlatformManagementDAOException("Error occured while executing the SQL query - " + getMapping, e);
|
|
|
|
throw new PlatformManagementDAOException("Error occured while executing the SQL query - " + getMapping, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
Util.cleanupResources(preparedStatement, resultSet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void removeMapping(String tenantDomain, String platformIdentifier) throws PlatformManagementDAOException {
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void removeMapping(int tenantId, String platformIdentifier) throws PlatformManagementDAOException {
|
|
|
|
String deleteMapping = "DELETE FROM APPM_PLATFORM_TENANT_MAPPING WHERE ID = ?";
|
|
|
|
String deleteMapping = "DELETE FROM APPM_PLATFORM_TENANT_MAPPING WHERE ID = ?";
|
|
|
|
|
|
|
|
PreparedStatement preparedStatement = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
int mappingId = getTenantPlatformMapping(tenantId, platformIdentifier);
|
|
|
|
int mappingId = getTenantPlatformMapping(tenantDomain, platformIdentifier);
|
|
|
|
|
|
|
|
if (mappingId != -1) {
|
|
|
|
if (mappingId != -1) {
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
Connection connection = this.getDBConnection();
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(deleteMapping);
|
|
|
|
preparedStatement = connection.prepareStatement(deleteMapping);
|
|
|
|
preparedStatement.setInt(1, mappingId);
|
|
|
|
preparedStatement.setInt(1, mappingId);
|
|
|
|
preparedStatement.execute();
|
|
|
|
preparedStatement.execute();
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new PlatformManagementDAOException("Platform - " + platformIdentifier
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
+ " is already unassigned for tenant - " + tenantDomain);
|
|
|
|
"Platform - " + platformIdentifier + " is already unassigned for tenant - " + tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (TransactionManagementException | DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while unassigning the platform - " + platformIdentifier
|
|
|
|
"Error occurred while unassigning the platform - " + platformIdentifier + " for tenant - "
|
|
|
|
+ " for tenant - " + tenantDomain);
|
|
|
|
+ tenantId);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while executing the query - " + deleteMapping);
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while executing the query - " + deleteMapping);
|
|
|
|
} catch (PlatformManagementDAOException ex) {
|
|
|
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
|
|
|
throw ex;
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
Util.cleanupResources(preparedStatement, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void removeMappingTenants(String platformIdentifier) throws PlatformManagementDAOException {
|
|
|
|
public void removeMappingTenants(String platformIdentifier) throws PlatformManagementDAOException {
|
|
|
|
int platformId = getPlatformId(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, platformIdentifier);
|
|
|
|
PreparedStatement preparedStatement = null;
|
|
|
|
String getMapping = "DELETE FROM APPM_PLATFORM_TENANT_MAPPING WHERE TENANT_DOMAIN != ? AND PLATFORM_ID=?";
|
|
|
|
int platformId = getPlatformId(MultitenantConstants.SUPER_TENANT_ID, platformIdentifier);
|
|
|
|
|
|
|
|
String getMapping = "DELETE FROM APPM_PLATFORM_TENANT_MAPPING WHERE TENANT_ID != ? AND PLATFORM_ID=?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openConnection();
|
|
|
|
Connection connection = this.getDBConnection();
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
preparedStatement = connection.prepareStatement(getMapping);
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(getMapping);
|
|
|
|
preparedStatement.setInt(1, MultitenantConstants.SUPER_TENANT_ID);
|
|
|
|
preparedStatement.setString(1, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
|
|
|
|
|
|
|
preparedStatement.setInt(2, platformId);
|
|
|
|
preparedStatement.setInt(2, platformId);
|
|
|
|
preparedStatement.execute();
|
|
|
|
preparedStatement.execute();
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new PlatformManagementDAOException("Error occured while obtaining the connection to get the existing " +
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
"Tenant - Platform Mapping.", e);
|
|
|
|
"Error occurred while obtaining the connection to remove existing " + "Tenant - Platform Mapping"
|
|
|
|
|
|
|
|
+ " for the platform : " + platformIdentifier, e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new PlatformManagementDAOException("Error occured while executing the SQL query - " + getMapping, e);
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while executing the SQL query - " + getMapping, e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
Util.cleanupResources(preparedStatement, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Platform> getPlatforms(String tenantDomain) throws PlatformManagementDAOException {
|
|
|
|
public List<Platform> getPlatforms(int tenantId) throws PlatformManagementDAOException {
|
|
|
|
|
|
|
|
PreparedStatement preparedStatement = null;
|
|
|
|
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("GetPlaforms request received for the tenantDomain " + tenantDomain);
|
|
|
|
log.debug("GetPlaforms request received for the tenant ID " + tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
String selectQuery =
|
|
|
|
String selectQuery = SQLQueries.queryToGetPlatforms;
|
|
|
|
"SELECT MAPPING.ID, PLATFORM.IDENTIFIER FROM (SELECT * FROM APPM_PLATFORM WHERE TENANT_DOMAIN=? OR "
|
|
|
|
|
|
|
|
+ "IS_SHARED = TRUE AND FILE_BASED = FALSE) PLATFORM LEFT JOIN APPM_PLATFORM_TENANT_MAPPING "
|
|
|
|
|
|
|
|
+ "MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID";
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection connection = ConnectionManagerUtil.openConnection();
|
|
|
|
Connection connection = this.getDBConnection();
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(selectQuery);
|
|
|
|
preparedStatement = connection.prepareStatement(selectQuery);
|
|
|
|
preparedStatement.setString(1, tenantDomain);
|
|
|
|
preparedStatement.setInt(1, tenantId);
|
|
|
|
ResultSet resultSet = preparedStatement.executeQuery();
|
|
|
|
preparedStatement.setInt(2, tenantId);
|
|
|
|
|
|
|
|
resultSet = preparedStatement.executeQuery();
|
|
|
|
List<Platform> platforms = new ArrayList<>();
|
|
|
|
List<Platform> platforms = new ArrayList<>();
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Platform retrieved for the tenant domain " + tenantDomain);
|
|
|
|
log.debug("Platform retrieved for the tenant Id " + tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (resultSet.next()) {
|
|
|
|
while (resultSet.next()) {
|
|
|
|
String identifier = resultSet.getString("PLATFORM.IDENTIFIER");
|
|
|
|
int mappingID = resultSet.getInt(1);
|
|
|
|
int mappingID = resultSet.getInt("MAPPING.ID");
|
|
|
|
String identifier = resultSet.getString(2);
|
|
|
|
Platform platform = getPlatform(tenantDomain, identifier);
|
|
|
|
Platform platform = getPlatform(tenantId, identifier);
|
|
|
|
if (mappingID != 0) {
|
|
|
|
if (mappingID != 0) {
|
|
|
|
platform.setEnabled(true);
|
|
|
|
platform.setEnabled(true);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -373,36 +399,36 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Number of platforms available for the tenant domain - " + tenantDomain + " :" + platforms
|
|
|
|
log.debug("Number of platforms available for the tenant ID - " + tenantId + " :" + platforms.size());
|
|
|
|
.size());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return platforms;
|
|
|
|
return platforms;
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
"Error occured when loading the platforms for tenant - " + tenantDomain, e);
|
|
|
|
"Error occurred when loading the platforms for tenant - " + tenantId, e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new PlatformManagementDAOException("Error occurred when executing query - " + selectQuery, e);
|
|
|
|
throw new PlatformManagementDAOException("Error occurred when executing query - " + selectQuery, e);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
Util.cleanupResources(preparedStatement, resultSet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Platform getPlatform(String tenantDomain, String platformIdenfier) throws PlatformManagementDAOException {
|
|
|
|
public Platform getPlatform(String tenantDomain, String platformIdentifier) throws PlatformManagementDAOException {
|
|
|
|
String platformQuery = "SELECT * FROM (SELECT * FROM APPM_PLATFORM WHERE (TENANT_DOMAIN=? AND IDENTIFIER=?) " +
|
|
|
|
PreparedStatement preparedStatement = null;
|
|
|
|
"OR (IS_SHARED = TRUE AND IDENTIFIER=?) AND FILE_BASED = FALSE ) PLATFORM " +
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
"LEFT JOIN APPM_PLATFORM_PROPERTIES PROPS ON PLATFORM.ID = PROPS.PLATFORM_ID";
|
|
|
|
String platformQuery = "SELECT * FROM (SELECT * FROM APPM_PLATFORM WHERE (TENANT_DOMAIN=? AND IDENTIFIER=?) "
|
|
|
|
|
|
|
|
+ "OR (IS_SHARED = TRUE AND IDENTIFIER=?) AND FILE_BASED = FALSE ) PLATFORM "
|
|
|
|
|
|
|
|
+ "LEFT JOIN APPM_PLATFORM_PROPERTIES PROPS ON PLATFORM.ID = PROPS.PLATFORM_ID";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openConnection();
|
|
|
|
Connection connection = this.getDBConnection();
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
preparedStatement = connection.prepareStatement(platformQuery);
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(platformQuery);
|
|
|
|
|
|
|
|
preparedStatement.setString(1, tenantDomain);
|
|
|
|
preparedStatement.setString(1, tenantDomain);
|
|
|
|
preparedStatement.setString(2, platformIdenfier);
|
|
|
|
preparedStatement.setString(2, platformIdentifier);
|
|
|
|
preparedStatement.setString(3, platformIdenfier);
|
|
|
|
preparedStatement.setString(3, platformIdentifier);
|
|
|
|
ResultSet resultSet = preparedStatement.executeQuery();
|
|
|
|
resultSet = preparedStatement.executeQuery();
|
|
|
|
Platform platform = new Platform();
|
|
|
|
Platform platform = new Platform();
|
|
|
|
if (resultSet.next()) {
|
|
|
|
if (resultSet.next()) {
|
|
|
|
platform.setId(resultSet.getInt("PLATFORM.ID"));
|
|
|
|
platform.setId(resultSet.getInt("PLATFORM.ID"));
|
|
|
|
platform.setIdentifier(platformIdenfier);
|
|
|
|
platform.setIdentifier(platformIdentifier);
|
|
|
|
platform.setName(resultSet.getString("PLATFORM.NAME"));
|
|
|
|
platform.setName(resultSet.getString("PLATFORM.NAME"));
|
|
|
|
platform.setIconName(resultSet.getString("PLATFORM.DESCRIPTION"));
|
|
|
|
platform.setIconName(resultSet.getString("PLATFORM.DESCRIPTION"));
|
|
|
|
platform.setIconName(resultSet.getString("PLATFORM.ICON_NAME"));
|
|
|
|
platform.setIconName(resultSet.getString("PLATFORM.ICON_NAME"));
|
|
|
@ -420,50 +446,191 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
} while (resultSet.next());
|
|
|
|
} while (resultSet.next());
|
|
|
|
platform.setProperties(properties);
|
|
|
|
platform.setProperties(properties);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
platform.setIdentifier(platformIdenfier);
|
|
|
|
platform.setIdentifier(platformIdentifier);
|
|
|
|
platform.setFileBased(true);
|
|
|
|
platform.setFileBased(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return platform;
|
|
|
|
return platform;
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new PlatformManagementDAOException("Error when loading the platform - " + platformIdenfier, e);
|
|
|
|
throw new PlatformManagementDAOException("Error when loading the platform - " + platformIdentifier, e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new PlatformManagementDAOException("Error in executing the query - " + platformQuery, e);
|
|
|
|
throw new PlatformManagementDAOException("Error in executing the query - " + platformQuery, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
Util.cleanupResources(preparedStatement, resultSet);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Platform getPlatform(int tenantId, String identifier) throws PlatformManagementDAOException {
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Platform getPlatform(int tenantId, String identifier) throws PlatformManagementDAOException {
|
|
|
|
Connection conn = null;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
String sql = "";
|
|
|
|
String sql = "";
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
sql += "SELECT * ";
|
|
|
|
sql = SQLQueries.queryToGetPlatform;
|
|
|
|
sql += "FROM APPM_PLATFORM ";
|
|
|
|
|
|
|
|
sql += "WHERE IDENTIFIER = ? ";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setString(1, identifier);
|
|
|
|
stmt.setString(1, identifier);
|
|
|
|
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
|
|
|
|
stmt.setInt(3, tenantId);
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
Platform platform = null;
|
|
|
|
Platform platform = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (rs.next()) {
|
|
|
|
if (rs.next()) {
|
|
|
|
platform = new Platform();
|
|
|
|
platform = new Platform();
|
|
|
|
platform.setId(rs.getInt("ID"));
|
|
|
|
platform.setFileBased(rs.getBoolean(3));
|
|
|
|
platform.setName(rs.getString("NAME"));
|
|
|
|
platform.setIdentifier(rs.getString(2));
|
|
|
|
platform.setIdentifier(rs.getString("IDENTIFIER"));
|
|
|
|
platform.setShared(rs.getBoolean(8));
|
|
|
|
}
|
|
|
|
platform.setDefaultTenantMapping(rs.getBoolean(9));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!platform.isFileBased()) {
|
|
|
|
|
|
|
|
platform.setId(rs.getInt(4));
|
|
|
|
|
|
|
|
platform.setName(rs.getString(5));
|
|
|
|
|
|
|
|
platform.setDescription(rs.getString(6));
|
|
|
|
|
|
|
|
platform.setIconName(rs.getString(7));
|
|
|
|
|
|
|
|
if (rs.getInt(1) != 0) {
|
|
|
|
|
|
|
|
platform.setEnabled(true);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
platform.setEnabled(false);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
return platform;
|
|
|
|
return platform;
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while getting application List", e);
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
"Error occurred while getting platform with the identifier " + identifier + ", for the tenant : "
|
|
|
|
|
|
|
|
+ tenantId, e);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while obtaining the DB connection.", e);
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while obtaining the DB connection.", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
Util.cleanupResources(stmt, rs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void removePlatforms(int tenantId) throws PlatformManagementDAOException {
|
|
|
|
|
|
|
|
PreparedStatement preparedStatement = null;
|
|
|
|
|
|
|
|
String sql = "DELETE FROM APPM_PLATFORM WHERE TENANT_ID = ?";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Connection connection = this.getDBConnection();
|
|
|
|
|
|
|
|
preparedStatement = connection.prepareStatement(sql);
|
|
|
|
|
|
|
|
preparedStatement.setInt(1, tenantId);
|
|
|
|
|
|
|
|
preparedStatement.executeUpdate();
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
|
|
|
"Database connection error while removing the platforms for the " + "tenant - " + tenantId);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
|
|
|
"SQL exception while executing the query " + sql + " for " + "the tenant : " + tenantId);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
Util.cleanupResources(preparedStatement, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public int getSuperTenantAndOwnPlatforms(String platformIdentifier, int tenantId)
|
|
|
|
|
|
|
|
throws PlatformManagementDAOException {
|
|
|
|
|
|
|
|
PreparedStatement preparedStatement = null;
|
|
|
|
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
|
|
|
|
String sql = SQLQueries.queryToGetSupertenantAndOwnPlatforms;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Connection connection = this.getDBConnection();
|
|
|
|
|
|
|
|
preparedStatement = connection.prepareStatement(sql);
|
|
|
|
|
|
|
|
preparedStatement.setString(1, platformIdentifier);
|
|
|
|
|
|
|
|
preparedStatement.setInt(2, tenantId);
|
|
|
|
|
|
|
|
preparedStatement.setInt(3, MultitenantConstants.SUPER_TENANT_ID);
|
|
|
|
|
|
|
|
resultSet = preparedStatement.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (resultSet.next()) {
|
|
|
|
|
|
|
|
return resultSet.getInt(1);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
|
|
|
"Database connection error while removing the platfor for the " + "tenant - " + tenantId);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
|
|
|
"SQL exception while executing the query " + sql + " for " + "the tenant : " + tenantId);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
Util.cleanupResources(preparedStatement, resultSet);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public Platform getTenantOwnedPlatform(int tenantId, String platformIdentifier)
|
|
|
|
|
|
|
|
throws PlatformManagementDAOException {
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
String sql = "";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
|
|
|
|
sql = "SELECT * from APPM_PLATFORM WHERE TENANT_ID = ? AND IDENTIFIER = ?";
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, tenantId);
|
|
|
|
|
|
|
|
stmt.setString(2, platformIdentifier);
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Platform platform = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
|
|
|
platform = new Platform();
|
|
|
|
|
|
|
|
platform.setFileBased(rs.getBoolean("FILE_BASED"));
|
|
|
|
|
|
|
|
platform.setIdentifier(rs.getString("IDENTIFIER"));
|
|
|
|
|
|
|
|
platform.setShared(rs.getBoolean("IS_SHARED"));
|
|
|
|
|
|
|
|
platform.setDefaultTenantMapping(rs.getBoolean("IS_DEFAULT_TENANT_MAPPING"));
|
|
|
|
|
|
|
|
if (!platform.isFileBased()) {
|
|
|
|
|
|
|
|
platform.setId(rs.getInt("ID"));
|
|
|
|
|
|
|
|
platform.setName(rs.getString("NAME"));
|
|
|
|
|
|
|
|
platform.setDescription(rs.getString("DESCRIPTION"));
|
|
|
|
|
|
|
|
platform.setIconName(rs.getString("ICON_NAME"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return platform;
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while executing the query : " + sql + " for "
|
|
|
|
|
|
|
|
+ "getting platforms owned by tenant : " + tenantId, e);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
|
|
|
"Error occurred while obtaining the DB connection for getting " + "platforms owned by tenant : "
|
|
|
|
|
|
|
|
+ tenantId, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
Util.cleanupResources(stmt, rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public int getMultiTenantPlatforms(String identifier) throws PlatformManagementDAOException {
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
String sql = "";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
|
|
|
|
sql = "SELECT ID from APPM_PLATFORM WHERE TENANT_ID != ? AND IDENTIFIER=?";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, MultitenantConstants.SUPER_TENANT_ID);
|
|
|
|
|
|
|
|
stmt.setString(2, identifier);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
|
|
|
return rs.getInt(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException("Database Connection exception while trying to get the tenants "
|
|
|
|
|
|
|
|
+ "which has the platforms with the platform identifier : " + identifier, e);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException("SQL exception while executing the query " + sql + " to get the"
|
|
|
|
|
|
|
|
+ " tenants which has the platform with the platform identifier : " + identifier, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|