|
|
@ -24,6 +24,7 @@ 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.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.device.application.mgt.core.util.ConnectionManagerUtil;
|
|
|
@ -36,22 +37,25 @@ 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.getConnection();
|
|
|
|
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)" + " 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());
|
|
|
@ -59,9 +63,12 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
preparedStatement.setString(7, platform.getIconName());
|
|
|
|
preparedStatement.setString(7, platform.getIconName());
|
|
|
|
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, "
|
|
|
|
|
|
|
|
+ "DEFAULT_VALUE) VALUES ( ? , ?, ? , ?)";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (platform.getProperties() != null) {
|
|
|
|
for (Platform.Property property : platform.getProperties()) {
|
|
|
|
for (Platform.Property property : platform.getProperties()) {
|
|
|
|
preparedStatement = connection.prepareStatement(insertPlatformProps);
|
|
|
|
preparedStatement = connection.prepareStatement(insertPlatformProps);
|
|
|
|
preparedStatement.setInt(1, platformId);
|
|
|
|
preparedStatement.setInt(1, platformId);
|
|
|
@ -70,74 +77,91 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
preparedStatement.setString(4, property.getDefaultValue());
|
|
|
|
preparedStatement.setString(4, property.getDefaultValue());
|
|
|
|
preparedStatement.execute();
|
|
|
|
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)" + " 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.setBoolean(3, true);
|
|
|
|
preparedStatement.setBoolean(3, true);
|
|
|
|
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.getConnection();
|
|
|
|
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 = ?";
|
|
|
|
if (!isIdentifierNull) {
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(insertToPlatform);
|
|
|
|
insertToPlatform += ",IDENTIFIER = ? ";
|
|
|
|
preparedStatement.setString(1, platform.getIdentifier());
|
|
|
|
}
|
|
|
|
preparedStatement.setString(2, platform.getName());
|
|
|
|
if (!isNameNull) {
|
|
|
|
preparedStatement.setString(3, platform.getDescription());
|
|
|
|
insertToPlatform += ", NAME =?";
|
|
|
|
preparedStatement.setBoolean(4, platform.isShared());
|
|
|
|
}
|
|
|
|
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());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!isIdentifierNull && !isNameNull) {
|
|
|
|
|
|
|
|
preparedStatement.setString(4, platform.getIdentifier());
|
|
|
|
|
|
|
|
preparedStatement.setString(5, platform.getName());
|
|
|
|
|
|
|
|
preparedStatement.setInt(6, platformId);
|
|
|
|
|
|
|
|
} else if (isIdentifierNull && !isNameNull) {
|
|
|
|
|
|
|
|
preparedStatement.setString(4, platform.getName());
|
|
|
|
|
|
|
|
preparedStatement.setInt(5, platformId);
|
|
|
|
|
|
|
|
} else if (!isIdentifierNull) {
|
|
|
|
|
|
|
|
preparedStatement.setString(4, platform.getIdentifier());
|
|
|
|
|
|
|
|
preparedStatement.setInt(5, platformId);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
preparedStatement.setInt(4, 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,"
|
|
|
|
|
|
|
|
+ " DEFAULT_VALUE) VALUES ( ? , ?, ? , ?)";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (platform.getProperties() != null) {
|
|
|
|
for (Platform.Property property : platform.getProperties()) {
|
|
|
|
for (Platform.Property property : platform.getProperties()) {
|
|
|
|
preparedStatement = connection.prepareStatement(insertPlatformProps);
|
|
|
|
preparedStatement = connection.prepareStatement(insertPlatformProps);
|
|
|
|
preparedStatement.setInt(1, platformId);
|
|
|
|
preparedStatement.setInt(1, platformId);
|
|
|
@ -146,45 +170,41 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
preparedStatement.setString(4, property.getDefaultValue());
|
|
|
|
preparedStatement.setString(4, property.getDefaultValue());
|
|
|
|
preparedStatement.execute();
|
|
|
|
preparedStatement.execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
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.setInt(1, 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 = "SELECT ID FROM APPM_PLATFORM WHERE (TENANT_ID=? AND IDENTIFIER=?) OR (IS_SHARED = TRUE AND "
|
|
|
|
|
|
|
|
+ "IDENTIFIER=?)";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
Connection connection = this.getConnection();
|
|
|
|
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 +213,180 @@ 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()) {
|
|
|
|
|
|
|
|
Connection connection = this.getConnection();
|
|
|
|
String deletePlatform = "DELETE FROM APPM_PLATFORM WHERE ID = ?";
|
|
|
|
String deletePlatform = "DELETE FROM APPM_PLATFORM WHERE ID = ?";
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(deletePlatform);
|
|
|
|
preparedStatement = connection.prepareStatement(deletePlatform);
|
|
|
|
preparedStatement.setInt(1, platformId);
|
|
|
|
preparedStatement.setInt(1, platform.getId());
|
|
|
|
preparedStatement.execute();
|
|
|
|
preparedStatement.execute();
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new PlatformManagementDAOException("Platform identifier - " + platformIdenfier
|
|
|
|
if (isFileBased) {
|
|
|
|
+ " is already unregistered registered for tenant - " + tenantDomain);
|
|
|
|
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 {
|
|
|
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
|
|
|
"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.getConnection();
|
|
|
|
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) throws
|
|
|
|
String getMapping = "SELECT MAPPING.ID as ID FROM (SELECT ID FROM APPM_PLATFORM_TENANT_MAPPING WHERE TENANT_DOMAIN=?) MAPPING JOIN " +
|
|
|
|
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.getConnection();
|
|
|
|
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.getConnection();
|
|
|
|
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.getConnection();
|
|
|
|
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 =
|
|
|
|
"SELECT MAPPING.ID, PLATFORM.IDENTIFIER FROM (SELECT * FROM APPM_PLATFORM WHERE TENANT_DOMAIN=? OR "
|
|
|
|
"SELECT MAPPING.ID, PLATFORM.IDENTIFIER FROM (SELECT * FROM APPM_PLATFORM WHERE TENANT_ID=? OR "
|
|
|
|
+ "IS_SHARED = TRUE AND FILE_BASED = FALSE) PLATFORM LEFT JOIN APPM_PLATFORM_TENANT_MAPPING "
|
|
|
|
+ "IS_SHARED = TRUE AND FILE_BASED = FALSE) PLATFORM LEFT JOIN APPM_PLATFORM_TENANT_MAPPING "
|
|
|
|
+ "MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID";
|
|
|
|
+ "MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection connection = ConnectionManagerUtil.openConnection();
|
|
|
|
Connection connection = this.getConnection();
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(selectQuery);
|
|
|
|
preparedStatement = connection.prepareStatement(selectQuery);
|
|
|
|
preparedStatement.setString(1, tenantDomain);
|
|
|
|
preparedStatement.setInt(1, tenantId);
|
|
|
|
ResultSet resultSet = preparedStatement.executeQuery();
|
|
|
|
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");
|
|
|
|
String identifier = resultSet.getString("PLATFORM.IDENTIFIER");
|
|
|
|
int mappingID = resultSet.getInt("MAPPING.ID");
|
|
|
|
int mappingID = resultSet.getInt("MAPPING.ID");
|
|
|
|
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 +398,37 @@ 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 {
|
|
|
|
|
|
|
|
PreparedStatement preparedStatement = null;
|
|
|
|
|
|
|
|
ResultSet resultSet = null;
|
|
|
|
String platformQuery = "SELECT * FROM (SELECT * FROM APPM_PLATFORM WHERE (TENANT_DOMAIN=? AND IDENTIFIER=?) " +
|
|
|
|
String platformQuery = "SELECT * FROM (SELECT * FROM APPM_PLATFORM WHERE (TENANT_DOMAIN=? AND IDENTIFIER=?) " +
|
|
|
|
"OR (IS_SHARED = TRUE AND IDENTIFIER=?) AND FILE_BASED = FALSE ) PLATFORM " +
|
|
|
|
"OR (IS_SHARED = TRUE AND IDENTIFIER=?) AND FILE_BASED = FALSE ) PLATFORM " +
|
|
|
|
"LEFT JOIN APPM_PLATFORM_PROPERTIES PROPS ON PLATFORM.ID = PROPS.PLATFORM_ID";
|
|
|
|
"LEFT JOIN APPM_PLATFORM_PROPERTIES PROPS ON PLATFORM.ID = PROPS.PLATFORM_ID";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openConnection();
|
|
|
|
Connection connection = this.getConnection();
|
|
|
|
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,57 @@ 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 {
|
|
|
|
public Platform getPlatform(int tenantId, String identifier) throws PlatformManagementDAOException {
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
Connection conn = null;
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
String sql = "";
|
|
|
|
String sql = "";
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
sql += "SELECT * ";
|
|
|
|
sql = "SELECT * FROM APPM_PLATFORM WHERE IDENTIFIER = ? AND TENANT_ID = ?";
|
|
|
|
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);
|
|
|
|
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.setFileBased(rs.getBoolean("FILE_BASED"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
platform.setIdentifier(rs.getString("IDENTIFIER"));
|
|
|
|
|
|
|
|
if (!platform.isFileBased()) {
|
|
|
|
platform.setId(rs.getInt("ID"));
|
|
|
|
platform.setId(rs.getInt("ID"));
|
|
|
|
platform.setName(rs.getString("NAME"));
|
|
|
|
platform.setName(rs.getString("NAME"));
|
|
|
|
platform.setIdentifier(rs.getString("IDENTIFIER"));
|
|
|
|
platform.setDescription(rs.getString("DESCRIPTION"));
|
|
|
|
|
|
|
|
platform.setIconName(rs.getString("ICON_NAME"));
|
|
|
|
|
|
|
|
platform.setShared(rs.getBoolean("IS_SHARED"));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return platform;
|
|
|
|
return platform;
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while getting application List", e);
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while getting platform with the identifier " +
|
|
|
|
|
|
|
|
identifier + ", for the tenant : " + tenantId, e);
|
|
|
|
} catch (DBConnectionException 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|