|
|
@ -36,22 +36,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 {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
int platformId = getPlatformId(tenantDomain, platform.getIdentifier());
|
|
|
|
int platformId = getPlatformId(tenantId, platform.getIdentifier());
|
|
|
|
if (platformId == -1) {
|
|
|
|
if (platformId == -1) {
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
Connection connection = ConnectionManagerUtil.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 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 +62,10 @@ 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 ( ? , ?, ? , ?)";
|
|
|
|
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);
|
|
|
@ -71,16 +75,16 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
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 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();
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
return platformId;
|
|
|
|
return platformId;
|
|
|
@ -88,7 +92,7 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
if (!platform.isFileBased()) {
|
|
|
|
if (!platform.isFileBased()) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException("Platform - " + platform.getIdentifier()
|
|
|
|
throw new PlatformManagementDAOException("Platform - " + platform.getIdentifier()
|
|
|
|
+ " is already registered for tenant - " + tenantDomain);
|
|
|
|
+ " is already registered for tenant - " + tenantId);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return platformId;
|
|
|
|
return platformId;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -102,26 +106,27 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException("Unable to obtain the connection while trying to register the platform - "
|
|
|
|
throw new PlatformManagementDAOException("Unable to obtain the connection while trying to register the platform - "
|
|
|
|
+ platform.getIdentifier() + " for tenant - " + tenantDomain, e);
|
|
|
|
+ platform.getIdentifier() + " for tenant - " + tenantId, e);
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while performing the transaction on the database " +
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while performing the transaction on the database " +
|
|
|
|
"for adding the platform - " + platform.getIdentifier() + " , tenant domain - " + tenantDomain);
|
|
|
|
"for adding the platform - " + platform.getIdentifier() + " , tenant domain - " + tenantId);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void update(String tenantDomain, String oldPlatformIdentifier, Platform platform) throws PlatformManagementDAOException {
|
|
|
|
public void update(int tenantId, String oldPlatformIdentifier, Platform platform) throws
|
|
|
|
|
|
|
|
PlatformManagementDAOException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
int platformId = getPlatformId(tenantDomain, oldPlatformIdentifier);
|
|
|
|
int platformId = getPlatformId(tenantId, oldPlatformIdentifier);
|
|
|
|
if (platformId != -1) {
|
|
|
|
if (platformId != -1) {
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
if (!platform.isFileBased()) {
|
|
|
|
if (!platform.isFileBased()) {
|
|
|
|
String insertToPlatform = "UPDATE APPM_PLATFORM SET IDENTIFIER = ?, NAME =?, DESCRIPTION=?, " +
|
|
|
|
String insertToPlatform = "UPDATE APPM_PLATFORM SET IDENTIFIER = ?, NAME =?, DESCRIPTION=?, "
|
|
|
|
"IS_SHARED=?, ICON_NAME=? WHERE ID = ?";
|
|
|
|
+ "IS_SHARED=?, ICON_NAME=? WHERE ID = ?";
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(insertToPlatform);
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(insertToPlatform);
|
|
|
|
preparedStatement.setString(1, platform.getIdentifier());
|
|
|
|
preparedStatement.setString(1, platform.getIdentifier());
|
|
|
|
preparedStatement.setString(2, platform.getName());
|
|
|
|
preparedStatement.setString(2, platform.getName());
|
|
|
@ -130,14 +135,15 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
preparedStatement.setString(5, platform.getIconName());
|
|
|
|
preparedStatement.setString(5, platform.getIconName());
|
|
|
|
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 ( ? , ?, ? , ?)";
|
|
|
|
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);
|
|
|
@ -154,8 +160,9 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
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();
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
@ -165,23 +172,26 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
throw ex;
|
|
|
|
throw ex;
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException("Unable to obtain the connection while trying to register the platform - "
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
+ platform.getIdentifier() + " for tenant - " + tenantDomain, e);
|
|
|
|
"Unable to obtain the connection while trying to register the platform - " + platform
|
|
|
|
|
|
|
|
.getIdentifier() + " for tenant - " + tenantId, e);
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while performing the transaction on the database " +
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
"for adding the platform - " + platform.getIdentifier() + " , tenant domain - " + tenantDomain);
|
|
|
|
"Error occurred while performing the transaction on the database " + "for adding the platform - "
|
|
|
|
|
|
|
|
+ platform.getIdentifier() + " , tenant domain - " + tenantId);
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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=?)";
|
|
|
|
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 = ConnectionManagerUtil.getConnection();
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(query);
|
|
|
|
PreparedStatement 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 resultSet = preparedStatement.executeQuery();
|
|
|
@ -198,10 +208,10 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void unregister(String tenantDomain, String platformIdenfier) throws PlatformManagementDAOException {
|
|
|
|
public void unregister(int tenantId, String platformIdenfier) throws PlatformManagementDAOException {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
int platformId = getPlatformId(tenantDomain, platformIdenfier);
|
|
|
|
int platformId = getPlatformId(tenantId, platformIdenfier);
|
|
|
|
if (platformId != -1) {
|
|
|
|
if (platformId != -1) {
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
String deletePlatform = "DELETE FROM APPM_PLATFORM WHERE ID = ?";
|
|
|
|
String deletePlatform = "DELETE FROM APPM_PLATFORM WHERE ID = ?";
|
|
|
@ -211,16 +221,18 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
throw new PlatformManagementDAOException("Platform identifier - " + platformIdenfier
|
|
|
|
throw new PlatformManagementDAOException("Platform identifier - " + platformIdenfier
|
|
|
|
+ " is already unregistered registered for tenant - " + tenantDomain);
|
|
|
|
+ " is already unregistered registered for tenant - " + tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException("Unable to start the transaction while trying to register the platform - "
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
+ platformIdenfier + " for tenant - " + tenantDomain, e);
|
|
|
|
"Unable to start the transaction while trying to register the platform - " + platformIdenfier
|
|
|
|
|
|
|
|
+ " for tenant - " + tenantId, e);
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException("Unable to obtain the connection while trying to register the platform - "
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
+ platformIdenfier + " for tenant - " + tenantDomain, e);
|
|
|
|
"Unable to obtain the connection while trying to register the platform - " + platformIdenfier
|
|
|
|
|
|
|
|
+ " for tenant - " + tenantId, e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException("Error while executing the SQL query. ", e);
|
|
|
|
throw new PlatformManagementDAOException("Error while executing the SQL query. ", e);
|
|
|
@ -232,33 +244,37 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 (?, ?)";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
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 = ConnectionManagerUtil.getConnection();
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(insertMapping);
|
|
|
|
PreparedStatement 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);
|
|
|
|
throw new PlatformManagementDAOException("Platform identifier - " + platformIdentifier + " is "
|
|
|
|
|
|
|
|
+ "already assigned to tenant domain - " + tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException("Error occured while trying to add the mapping of platform - "
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
+ platformIdentifiers.toString() + " for tenant - " + tenantDomain, e);
|
|
|
|
"Error occured while trying to add the mapping of platform - " + platformIdentifiers.toString()
|
|
|
|
|
|
|
|
+ " for tenant - " + tenantId, e);
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException("Error occurred when getting the connection for the database. ", e);
|
|
|
|
throw new PlatformManagementDAOException("Error occurred when getting the connection for the database. ",
|
|
|
|
|
|
|
|
e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException("Error occured while executing the SQL query - " + insertMapping, e);
|
|
|
|
throw new PlatformManagementDAOException("Error occured while executing the SQL query - " + insertMapping,
|
|
|
|
|
|
|
|
e);
|
|
|
|
} catch (PlatformManagementDAOException ex) {
|
|
|
|
} catch (PlatformManagementDAOException ex) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw ex;
|
|
|
|
throw ex;
|
|
|
@ -267,13 +283,15 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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";
|
|
|
|
String getMapping = "SELECT MAPPING.ID as ID FROM (SELECT ID FROM APPM_PLATFORM_TENANT_MAPPING WHERE "
|
|
|
|
|
|
|
|
+ "TENANT_ID=?) MAPPING JOIN (SELECT ID FROM APPM_PLATFORM WHERE APPM_PLATFORM.IDENTIFIER=?) "
|
|
|
|
|
|
|
|
+ "PLATFORM ON MAPPING.PLATFORM_ID=PLATFORM.ID";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(getMapping);
|
|
|
|
PreparedStatement 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 resultSet = preparedStatement.executeQuery();
|
|
|
|
if (resultSet.next()) {
|
|
|
|
if (resultSet.next()) {
|
|
|
@ -281,18 +299,20 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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 occured 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
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 = ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
int mappingId = getTenantPlatformMapping(tenantDomain, platformIdentifier);
|
|
|
|
int mappingId = getTenantPlatformMapping(tenantId, platformIdentifier);
|
|
|
|
if (mappingId != -1) {
|
|
|
|
if (mappingId != -1) {
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(deleteMapping);
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(deleteMapping);
|
|
|
@ -300,13 +320,14 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
preparedStatement.execute();
|
|
|
|
preparedStatement.execute();
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
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 (TransactionManagementException | DBConnectionException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while unassigning the platform - " + platformIdentifier
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
+ " for tenant - " + tenantDomain);
|
|
|
|
"Error occurred while unassigning the platform - " + platformIdentifier + " for tenant - "
|
|
|
|
|
|
|
|
+ tenantId);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while executing the query - " + deleteMapping);
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while executing the query - " + deleteMapping);
|
|
|
@ -320,18 +341,19 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
|
|
|
|
|
|
|
|
@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);
|
|
|
|
int platformId = getPlatformId(MultitenantConstants.SUPER_TENANT_ID, platformIdentifier);
|
|
|
|
String getMapping = "DELETE FROM APPM_PLATFORM_TENANT_MAPPING WHERE TENANT_DOMAIN != ? AND PLATFORM_ID=?";
|
|
|
|
String getMapping = "DELETE FROM APPM_PLATFORM_TENANT_MAPPING WHERE TENANT_ID != ? AND PLATFORM_ID=?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ConnectionManagerUtil.openConnection();
|
|
|
|
ConnectionManagerUtil.openConnection();
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(getMapping);
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(getMapping);
|
|
|
|
preparedStatement.setString(1, MultitenantConstants.SUPER_TENANT_DOMAIN_NAME);
|
|
|
|
preparedStatement.setInt(1, MultitenantConstants.SUPER_TENANT_ID);
|
|
|
|
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 occured 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 {
|
|
|
|
} finally {
|
|
|
@ -341,27 +363,27 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Platform> getPlatforms(String tenantDomain) throws PlatformManagementDAOException {
|
|
|
|
public List<Platform> getPlatforms(int tenantId) throws PlatformManagementDAOException {
|
|
|
|
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 = ConnectionManagerUtil.openConnection();
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(selectQuery);
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(selectQuery);
|
|
|
|
preparedStatement.setString(1, tenantDomain);
|
|
|
|
preparedStatement.setInt(1, tenantId);
|
|
|
|
ResultSet resultSet = preparedStatement.executeQuery();
|
|
|
|
ResultSet 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,13 +395,13 @@ 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 occured 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 {
|
|
|
|