|
|
|
@ -36,22 +36,25 @@ import java.sql.SQLException;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Generic Implementation for handling Platform management related database operations.
|
|
|
|
|
*/
|
|
|
|
|
public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformDAO {
|
|
|
|
|
private static Log log = LogFactory.getLog(GenericPlatformDAOImpl.class);
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int register(String tenantDomain, Platform platform) throws PlatformManagementDAOException {
|
|
|
|
|
public int register(int tenantId, Platform platform) throws PlatformManagementDAOException {
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
|
int platformId = getPlatformId(tenantDomain, platform.getIdentifier());
|
|
|
|
|
int platformId = getPlatformId(tenantId, platform.getIdentifier());
|
|
|
|
|
if (platformId == -1) {
|
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
|
if (!platform.isFileBased()) {
|
|
|
|
|
String insertToPlatform = "INSERT INTO APPM_PLATFORM (IDENTIFIER, TENANT_DOMAIN, NAME, FILE_BASED, DESCRIPTION, IS_SHARED, ICON_NAME)" +
|
|
|
|
|
" VALUES (?, ?, ?, ?, ?, ?, ?)";
|
|
|
|
|
String insertToPlatform = "INSERT INTO APPM_PLATFORM (IDENTIFIER, TENANT_ID, NAME, FILE_BASED, "
|
|
|
|
|
+ "DESCRIPTION, IS_SHARED, ICON_NAME)" + " VALUES (?, ?, ?, ?, ?, ?, ?)";
|
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(insertToPlatform);
|
|
|
|
|
preparedStatement.setString(1, platform.getIdentifier());
|
|
|
|
|
preparedStatement.setString(2, tenantDomain);
|
|
|
|
|
preparedStatement.setInt(2, tenantId);
|
|
|
|
|
preparedStatement.setString(3, platform.getName());
|
|
|
|
|
preparedStatement.setBoolean(4, false);
|
|
|
|
|
preparedStatement.setString(5, platform.getDescription());
|
|
|
|
@ -59,9 +62,10 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
|
preparedStatement.setString(7, platform.getIconName());
|
|
|
|
|
preparedStatement.execute();
|
|
|
|
|
|
|
|
|
|
platformId = getPlatformId(tenantDomain, platform.getIdentifier());
|
|
|
|
|
String insertPlatformProps = "INSERT INTO APPM_PLATFORM_PROPERTIES (PLATFORM_ID, PROP_NAME, OPTIONAL, DEFAULT_VALUE) VALUES " +
|
|
|
|
|
"( ? , ?, ? , ?)";
|
|
|
|
|
platformId = getPlatformId(tenantId, platform.getIdentifier());
|
|
|
|
|
String insertPlatformProps =
|
|
|
|
|
"INSERT INTO APPM_PLATFORM_PROPERTIES (PLATFORM_ID, PROP_NAME, OPTIONAL, "
|
|
|
|
|
+ "DEFAULT_VALUE) VALUES ( ? , ?, ? , ?)";
|
|
|
|
|
for (Platform.Property property : platform.getProperties()) {
|
|
|
|
|
preparedStatement = connection.prepareStatement(insertPlatformProps);
|
|
|
|
|
preparedStatement.setInt(1, platformId);
|
|
|
|
@ -71,16 +75,16 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
|
preparedStatement.execute();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
String insertToPlatform = "INSERT INTO APPM_PLATFORM (IDENTIFIER, TENANT_DOMAIN, FILE_BASED)" +
|
|
|
|
|
" VALUES (?, ?, ?)";
|
|
|
|
|
String insertToPlatform =
|
|
|
|
|
"INSERT INTO APPM_PLATFORM (IDENTIFIER, TENANT_ID, FILE_BASED)" + " VALUES (?, ?, ?)";
|
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(insertToPlatform);
|
|
|
|
|
preparedStatement.setString(1, platform.getIdentifier());
|
|
|
|
|
preparedStatement.setString(2, tenantDomain);
|
|
|
|
|
preparedStatement.setInt(2, tenantId);
|
|
|
|
|
preparedStatement.setBoolean(3, true);
|
|
|
|
|
preparedStatement.execute();
|
|
|
|
|
}
|
|
|
|
|
if (platformId == -1) {
|
|
|
|
|
platformId = getPlatformId(tenantDomain, platform.getIdentifier());
|
|
|
|
|
platformId = getPlatformId(tenantId, platform.getIdentifier());
|
|
|
|
|
}
|
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
|
return platformId;
|
|
|
|
@ -88,7 +92,7 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
|
if (!platform.isFileBased()) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException("Platform - " + platform.getIdentifier()
|
|
|
|
|
+ " is already registered for tenant - " + tenantDomain);
|
|
|
|
|
+ " is already registered for tenant - " + tenantId);
|
|
|
|
|
} else {
|
|
|
|
|
return platformId;
|
|
|
|
|
}
|
|
|
|
@ -102,26 +106,27 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
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) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
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 {
|
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void update(String tenantDomain, String oldPlatformIdentifier, Platform platform) throws PlatformManagementDAOException {
|
|
|
|
|
public void update(int tenantId, String oldPlatformIdentifier, Platform platform) throws
|
|
|
|
|
PlatformManagementDAOException {
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
|
int platformId = getPlatformId(tenantDomain, oldPlatformIdentifier);
|
|
|
|
|
int platformId = getPlatformId(tenantId, oldPlatformIdentifier);
|
|
|
|
|
if (platformId != -1) {
|
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
|
if (!platform.isFileBased()) {
|
|
|
|
|
String insertToPlatform = "UPDATE APPM_PLATFORM SET IDENTIFIER = ?, NAME =?, DESCRIPTION=?, " +
|
|
|
|
|
"IS_SHARED=?, ICON_NAME=? WHERE ID = ?";
|
|
|
|
|
String insertToPlatform = "UPDATE APPM_PLATFORM SET IDENTIFIER = ?, NAME =?, DESCRIPTION=?, "
|
|
|
|
|
+ "IS_SHARED=?, ICON_NAME=? WHERE ID = ?";
|
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(insertToPlatform);
|
|
|
|
|
preparedStatement.setString(1, platform.getIdentifier());
|
|
|
|
|
preparedStatement.setString(2, platform.getName());
|
|
|
|
@ -130,14 +135,15 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
|
preparedStatement.setString(5, platform.getIconName());
|
|
|
|
|
preparedStatement.execute();
|
|
|
|
|
|
|
|
|
|
platformId = getPlatformId(tenantDomain, platform.getIdentifier());
|
|
|
|
|
platformId = getPlatformId(tenantId, platform.getIdentifier());
|
|
|
|
|
String deletePlatformProps = "DELETE FROM APPM_PLATFORM_PROPERTIES WHERE PLATFORM_ID=?";
|
|
|
|
|
preparedStatement = connection.prepareStatement(deletePlatformProps);
|
|
|
|
|
preparedStatement.setInt(1, platformId);
|
|
|
|
|
preparedStatement.execute();
|
|
|
|
|
|
|
|
|
|
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()) {
|
|
|
|
|
preparedStatement = connection.prepareStatement(insertPlatformProps);
|
|
|
|
|
preparedStatement.setInt(1, platformId);
|
|
|
|
@ -154,8 +160,9 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
|
}
|
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
|
} else {
|
|
|
|
|
throw new PlatformManagementDAOException("Cannot find any platform that was registered with identifier - "
|
|
|
|
|
+ platform.getIdentifier() + " for tenant - " + tenantDomain);
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Cannot find any platform that was registered with identifier - " + platform.getIdentifier()
|
|
|
|
|
+ " for tenant - " + tenantId);
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
@ -165,23 +172,26 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
|
throw ex;
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException("Unable to obtain the connection while trying to register the platform - "
|
|
|
|
|
+ platform.getIdentifier() + " for tenant - " + tenantDomain, e);
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Unable to obtain the connection while trying to register the platform - " + platform
|
|
|
|
|
.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);
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Error occurred while performing the transaction on the database " + "for adding the platform - "
|
|
|
|
|
+ platform.getIdentifier() + " , tenant domain - " + tenantId);
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int getPlatformId(String tenantDomain, String platformIdentifier) throws PlatformManagementDAOException {
|
|
|
|
|
String query = "SELECT ID FROM APPM_PLATFORM WHERE (TENANT_DOMAIN=? AND IDENTIFIER=?) OR (IS_SHARED = TRUE AND IDENTIFIER=?)";
|
|
|
|
|
private int getPlatformId(int tenantId, String platformIdentifier) throws PlatformManagementDAOException {
|
|
|
|
|
String query = "SELECT ID FROM APPM_PLATFORM WHERE (TENANT_ID=? AND IDENTIFIER=?) OR (IS_SHARED = TRUE AND "
|
|
|
|
|
+ "IDENTIFIER=?)";
|
|
|
|
|
try {
|
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(query);
|
|
|
|
|
preparedStatement.setString(1, tenantDomain);
|
|
|
|
|
preparedStatement.setInt(1, tenantId);
|
|
|
|
|
preparedStatement.setString(2, platformIdentifier);
|
|
|
|
|
preparedStatement.setString(3, platformIdentifier);
|
|
|
|
|
ResultSet resultSet = preparedStatement.executeQuery();
|
|
|
|
@ -198,10 +208,10 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void unregister(String tenantDomain, String platformIdenfier) throws PlatformManagementDAOException {
|
|
|
|
|
public void unregister(int tenantId, String platformIdenfier) throws PlatformManagementDAOException {
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
|
int platformId = getPlatformId(tenantDomain, platformIdenfier);
|
|
|
|
|
int platformId = getPlatformId(tenantId, platformIdenfier);
|
|
|
|
|
if (platformId != -1) {
|
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
|
String deletePlatform = "DELETE FROM APPM_PLATFORM WHERE ID = ?";
|
|
|
|
@ -211,16 +221,18 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
|
} else {
|
|
|
|
|
throw new PlatformManagementDAOException("Platform identifier - " + platformIdenfier
|
|
|
|
|
+ " is already unregistered registered for tenant - " + tenantDomain);
|
|
|
|
|
+ " is already unregistered 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);
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Unable to start the transaction while trying to register the platform - " + platformIdenfier
|
|
|
|
|
+ " for tenant - " + tenantId, e);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException("Unable to obtain the connection while trying to register the platform - "
|
|
|
|
|
+ platformIdenfier + " for tenant - " + tenantDomain, e);
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Unable to obtain the connection while trying to register the platform - " + platformIdenfier
|
|
|
|
|
+ " for tenant - " + tenantId, e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
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 {
|
|
|
|
|
String insertMapping = "INSERT INTO APPM_PLATFORM_TENANT_MAPPING(TENANT_DOMAIN, PLATFORM_ID) VALUES (?, ?)";
|
|
|
|
|
public void addMapping(int tenantId, List<String> platformIdentifiers) throws PlatformManagementDAOException {
|
|
|
|
|
String insertMapping = "INSERT INTO APPM_PLATFORM_TENANT_MAPPING(TENANT_ID, PLATFORM_ID) VALUES (?, ?)";
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
|
for (String platformIdentifier : platformIdentifiers) {
|
|
|
|
|
if (getTenantPlatformMapping(tenantDomain, platformIdentifier) != -1) {
|
|
|
|
|
int platformId = getPlatformId(tenantDomain, platformIdentifier);
|
|
|
|
|
if (getTenantPlatformMapping(tenantId, platformIdentifier) != -1) {
|
|
|
|
|
int platformId = getPlatformId(tenantId, platformIdentifier);
|
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(insertMapping);
|
|
|
|
|
preparedStatement.setString(1, tenantDomain);
|
|
|
|
|
preparedStatement.setInt(1, tenantId);
|
|
|
|
|
preparedStatement.setInt(2, platformId);
|
|
|
|
|
preparedStatement.execute();
|
|
|
|
|
} 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();
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException("Error occured while trying to add the mapping of platform - "
|
|
|
|
|
+ platformIdentifiers.toString() + " for tenant - " + tenantDomain, e);
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Error occured while trying to add the mapping of platform - " + platformIdentifiers.toString()
|
|
|
|
|
+ " for tenant - " + tenantId, e);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
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) {
|
|
|
|
|
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) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
throw ex;
|
|
|
|
@ -267,13 +283,15 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private int getTenantPlatformMapping(String tenantDomain, String platformIdentifier) throws PlatformManagementDAOException {
|
|
|
|
|
String getMapping = "SELECT MAPPING.ID as ID FROM (SELECT ID FROM APPM_PLATFORM_TENANT_MAPPING WHERE TENANT_DOMAIN=?) MAPPING JOIN " +
|
|
|
|
|
"(SELECT ID FROM APPM_PLATFORM WHERE APPM_PLATFORM.IDENTIFIER=?) PLATFORM ON MAPPING.PLATFORM_ID=PLATFORM.ID";
|
|
|
|
|
private int getTenantPlatformMapping(int tenantId, String platformIdentifier) throws
|
|
|
|
|
PlatformManagementDAOException {
|
|
|
|
|
String getMapping = "SELECT MAPPING.ID as ID FROM (SELECT ID FROM APPM_PLATFORM_TENANT_MAPPING WHERE "
|
|
|
|
|
+ "TENANT_ID=?) MAPPING JOIN (SELECT ID FROM APPM_PLATFORM WHERE APPM_PLATFORM.IDENTIFIER=?) "
|
|
|
|
|
+ "PLATFORM ON MAPPING.PLATFORM_ID=PLATFORM.ID";
|
|
|
|
|
try {
|
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(getMapping);
|
|
|
|
|
preparedStatement.setString(1, tenantDomain);
|
|
|
|
|
preparedStatement.setInt(1, tenantId);
|
|
|
|
|
preparedStatement.setString(2, platformIdentifier);
|
|
|
|
|
ResultSet resultSet = preparedStatement.executeQuery();
|
|
|
|
|
if (resultSet.next()) {
|
|
|
|
@ -281,18 +299,20 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
throw new PlatformManagementDAOException("Error occured while obtaining the connection to get the existing " +
|
|
|
|
|
"Tenant - Platform Mapping.", e);
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Error occured while obtaining the connection to get the existing " + "Tenant - Platform Mapping.",
|
|
|
|
|
e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new PlatformManagementDAOException("Error occured while executing the SQL query - " + getMapping, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 = ?";
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
|
int mappingId = getTenantPlatformMapping(tenantDomain, platformIdentifier);
|
|
|
|
|
int mappingId = getTenantPlatformMapping(tenantId, platformIdentifier);
|
|
|
|
|
if (mappingId != -1) {
|
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(deleteMapping);
|
|
|
|
@ -300,13 +320,14 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
|
preparedStatement.execute();
|
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
|
} else {
|
|
|
|
|
throw new PlatformManagementDAOException("Platform - " + platformIdentifier
|
|
|
|
|
+ " is already unassigned for tenant - " + tenantDomain);
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Platform - " + platformIdentifier + " is already unassigned for tenant - " + tenantId);
|
|
|
|
|
}
|
|
|
|
|
} catch (TransactionManagementException | DBConnectionException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while unassigning the platform - " + platformIdentifier
|
|
|
|
|
+ " for tenant - " + tenantDomain);
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Error occurred while unassigning the platform - " + platformIdentifier + " for tenant - "
|
|
|
|
|
+ tenantId);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException("Error occurred while executing the query - " + deleteMapping);
|
|
|
|
@ -320,18 +341,19 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void removeMappingTenants(String platformIdentifier) throws PlatformManagementDAOException {
|
|
|
|
|
int platformId = getPlatformId(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, platformIdentifier);
|
|
|
|
|
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 {
|
|
|
|
|
ConnectionManagerUtil.openConnection();
|
|
|
|
|
Connection connection = ConnectionManagerUtil.getConnection();
|
|
|
|
|
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.execute();
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
throw new PlatformManagementDAOException("Error occured while obtaining the connection to get the existing " +
|
|
|
|
|
"Tenant - Platform Mapping.", e);
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Error occured while obtaining the connection to get the existing " + "Tenant - Platform Mapping.",
|
|
|
|
|
e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new PlatformManagementDAOException("Error occured while executing the SQL query - " + getMapping, e);
|
|
|
|
|
} finally {
|
|
|
|
@ -341,27 +363,27 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<Platform> getPlatforms(String tenantDomain) throws PlatformManagementDAOException {
|
|
|
|
|
public List<Platform> getPlatforms(int tenantId) throws PlatformManagementDAOException {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("GetPlaforms request received for the tenantDomain " + tenantDomain);
|
|
|
|
|
log.debug("GetPlaforms request received for the tenant ID " + tenantId);
|
|
|
|
|
}
|
|
|
|
|
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 "
|
|
|
|
|
+ "MAPPING ON PLATFORM.ID = MAPPING.PLATFORM_ID";
|
|
|
|
|
try {
|
|
|
|
|
Connection connection = ConnectionManagerUtil.openConnection();
|
|
|
|
|
PreparedStatement preparedStatement = connection.prepareStatement(selectQuery);
|
|
|
|
|
preparedStatement.setString(1, tenantDomain);
|
|
|
|
|
preparedStatement.setInt(1, tenantId);
|
|
|
|
|
ResultSet resultSet = preparedStatement.executeQuery();
|
|
|
|
|
List<Platform> platforms = new ArrayList<>();
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Platform retrieved for the tenant domain " + tenantDomain);
|
|
|
|
|
log.debug("Platform retrieved for the tenant Id " + tenantId);
|
|
|
|
|
}
|
|
|
|
|
while (resultSet.next()) {
|
|
|
|
|
String identifier = resultSet.getString("PLATFORM.IDENTIFIER");
|
|
|
|
|
int mappingID = resultSet.getInt("MAPPING.ID");
|
|
|
|
|
Platform platform = getPlatform(tenantDomain, identifier);
|
|
|
|
|
Platform platform = getPlatform(tenantId, identifier);
|
|
|
|
|
if (mappingID != 0) {
|
|
|
|
|
platform.setEnabled(true);
|
|
|
|
|
} else {
|
|
|
|
@ -373,13 +395,13 @@ public class GenericPlatformDAOImpl extends AbstractDAOImpl implements PlatformD
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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());
|
|
|
|
|
}
|
|
|
|
|
return platforms;
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
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) {
|
|
|
|
|
throw new PlatformManagementDAOException("Error occurred when executing query - " + selectQuery, e);
|
|
|
|
|
} finally {
|
|
|
|
|