|
|
|
@ -52,7 +52,7 @@ public class PlatformManagerImpl implements PlatformManager {
|
|
|
|
|
@Override
|
|
|
|
|
public void initialize(int tenantId) throws PlatformManagementException {
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
List<Platform> platforms = DAOFactory.getPlatformDAO().getPlatforms(tenantId);
|
|
|
|
|
List<String> platformIdentifiers = new ArrayList<>();
|
|
|
|
|
for (Platform platform : platforms) {
|
|
|
|
@ -61,19 +61,22 @@ public class PlatformManagerImpl implements PlatformManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
DAOFactory.getPlatformDAO().addMapping(tenantId, platformIdentifiers);
|
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Transaction Management Exception while initializing the " + "platforms for the tenant : "
|
|
|
|
|
+ tenantId, e);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Database Connection Exception while initializing the " + "platforms for the tenant : " + tenantId,
|
|
|
|
|
e);
|
|
|
|
|
} catch (PlatformManagementDAOException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw e;
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -86,13 +89,18 @@ public class PlatformManagerImpl implements PlatformManager {
|
|
|
|
|
+ "PlatformManager level");
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.openConnection();
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
platforms = DAOFactory.getPlatformDAO().getPlatforms(tenantId);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
} catch (DBConnectionException | TransactionManagementException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Database Connection Exception while getting the platforms for the tenant : " + tenantId, e);
|
|
|
|
|
} catch (PlatformManagementDAOException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw e;
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Number of platforms received from DAO layer is " + platforms.size() + " for the tenant "
|
|
|
|
@ -128,23 +136,27 @@ public class PlatformManagerImpl implements PlatformManager {
|
|
|
|
|
Platform platform = getPlatformFromInMemory(tenantId, identifier);
|
|
|
|
|
if (platform == null) {
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.openConnection();
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
platform = DAOFactory.getPlatformDAO().getPlatform(tenantId, identifier);
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
if (platform != null) {
|
|
|
|
|
return platform;
|
|
|
|
|
}
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
} catch (DBConnectionException | TransactionManagementException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Database Connection Exception while trying to get the " + "platform with the id :" + identifier
|
|
|
|
|
+ " for the tenant : " + tenantId, e);
|
|
|
|
|
} catch (PlatformManagementDAOException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw e;
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return new Platform(platform);
|
|
|
|
|
}
|
|
|
|
|
throw new PlatformManagementException(
|
|
|
|
|
"No platform was found for tenant - " + tenantId + " with platform identifier - " + identifier);
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Platform getPlatformFromInMemory(int tenantId, String identifier) {
|
|
|
|
@ -169,13 +181,9 @@ public class PlatformManagerImpl implements PlatformManager {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public synchronized void register(int tenantId, Platform platform) throws PlatformManagementException {
|
|
|
|
|
if (platform.isShared() && tenantId != MultitenantConstants.SUPER_TENANT_ID) {
|
|
|
|
|
throw new PlatformManagementException(
|
|
|
|
|
"Platform sharing is a restricted operation, therefore Platform - " + platform.getIdentifier()
|
|
|
|
|
+ " cannot be shared by the tenant domain - " + tenantId);
|
|
|
|
|
}
|
|
|
|
|
validateBeforeRegister(tenantId, platform);
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
int platformId = DAOFactory.getPlatformDAO().register(tenantId, platform);
|
|
|
|
|
if (platform.isFileBased()) {
|
|
|
|
|
platform.setId(platformId);
|
|
|
|
@ -187,7 +195,7 @@ public class PlatformManagerImpl implements PlatformManager {
|
|
|
|
|
if (tenantPlatforms.get(platform.getIdentifier()) == null) {
|
|
|
|
|
tenantPlatforms.put(platform.getIdentifier(), platform);
|
|
|
|
|
} else {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementException(
|
|
|
|
|
"Platform - " + platform.getIdentifier() + " is already registered!");
|
|
|
|
|
}
|
|
|
|
@ -195,136 +203,96 @@ public class PlatformManagerImpl implements PlatformManager {
|
|
|
|
|
if (platform.isDefaultTenantMapping()) {
|
|
|
|
|
try {
|
|
|
|
|
if (platform.isShared()) {
|
|
|
|
|
TenantManager tenantManager = DataHolder.getInstance().getRealmService().getTenantManager();
|
|
|
|
|
Tenant[] tenants = tenantManager.getAllTenants();
|
|
|
|
|
for (Tenant tenant : tenants) {
|
|
|
|
|
DAOFactory.getPlatformDAO()
|
|
|
|
|
.addMapping(tenant.getId(), getListOfString(platform.getIdentifier()));
|
|
|
|
|
}
|
|
|
|
|
sharePlatformWithOtherTenants(platform.getIdentifier());
|
|
|
|
|
}
|
|
|
|
|
DAOFactory.getPlatformDAO().addMapping(tenantId, getListOfString(platform.getIdentifier()));
|
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementException("Error occurred while assigning the platforms for tenants!",
|
|
|
|
|
e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Transaction Management Exception while trying to register a " + "platform with id " + platform
|
|
|
|
|
.getIdentifier() + " for tenant " + tenantId);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Database Connection Exception while trying to register a " + "platform with id " + platform
|
|
|
|
|
.getIdentifier() + " for tenant " + tenantId);
|
|
|
|
|
} catch (PlatformManagementDAOException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw e;
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void update(int tenantId, String oldPlatformIdentifier, Platform platform) throws
|
|
|
|
|
PlatformManagementException {
|
|
|
|
|
if (platform.isShared() && tenantId != MultitenantConstants.SUPER_TENANT_ID) {
|
|
|
|
|
throw new PlatformManagementException(
|
|
|
|
|
"Platform sharing is a restricted operation, therefore Platform - " + platform.getIdentifier()
|
|
|
|
|
+ " cannot be shared by the tenant domain - " + tenantId);
|
|
|
|
|
}
|
|
|
|
|
Platform oldPlatform;
|
|
|
|
|
|
|
|
|
|
if (platform.getIdentifier() != null && !platform.getIdentifier().equals(oldPlatformIdentifier)) {
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.openConnection();
|
|
|
|
|
Platform existingPlatform = DAOFactory.getPlatformDAO().getPlatform(tenantId, platform.getIdentifier());
|
|
|
|
|
|
|
|
|
|
if (existingPlatform != null) {
|
|
|
|
|
throw new PlatformManagementException(
|
|
|
|
|
"Cannot update the identifier of the platform from '" + oldPlatformIdentifier + "' to '"
|
|
|
|
|
+ platform.getIdentifier() + "'. Another platform exists "
|
|
|
|
|
+ "already with the identifier '" + platform.getIdentifier() + "' for the tenant : "
|
|
|
|
|
+ tenantId);
|
|
|
|
|
}
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
throw new PlatformManagementException(
|
|
|
|
|
"Database Connection Exception while trying to update the " + "platform for the tenant : "
|
|
|
|
|
+ tenantId, e);
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Platform oldPlatform = validateBeforeUpdate(tenantId, oldPlatformIdentifier, platform);
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
if (platform.isFileBased()) {
|
|
|
|
|
Map<String, Platform> tenantPlatforms = this.inMemoryStore.get(tenantId);
|
|
|
|
|
if (tenantPlatforms == null) {
|
|
|
|
|
// File based configurations will be updated in the server start-up as well.So in that case, cache,
|
|
|
|
|
// will be empty.
|
|
|
|
|
if (tenantPlatforms != null) {
|
|
|
|
|
if (tenantPlatforms.get(oldPlatformIdentifier) == null) {
|
|
|
|
|
throw new PlatformManagementException(
|
|
|
|
|
"No platforms registered for the tenant - " + tenantId + " with platform identifier - "
|
|
|
|
|
+ platform.getIdentifier());
|
|
|
|
|
"Cannot update platform with identifier " + oldPlatformIdentifier + " as it is not "
|
|
|
|
|
+ " existing already for the tenant " + tenantId);
|
|
|
|
|
}
|
|
|
|
|
oldPlatform = tenantPlatforms.get(oldPlatformIdentifier);
|
|
|
|
|
if (oldPlatform == null) {
|
|
|
|
|
throw new PlatformManagementException(
|
|
|
|
|
"No platforms registered for the tenant - " + tenantId + " with platform identifier - "
|
|
|
|
|
+ platform.getIdentifier());
|
|
|
|
|
} else {
|
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
|
tenantPlatforms = new HashMap<>();
|
|
|
|
|
this.inMemoryStore.put(tenantId, tenantPlatforms);
|
|
|
|
|
}
|
|
|
|
|
DAOFactory.getPlatformDAO().update(tenantId, oldPlatformIdentifier, platform);
|
|
|
|
|
platform.setId(oldPlatform.getId());
|
|
|
|
|
tenantPlatforms.put(platform.getIdentifier(), platform);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
|
oldPlatform = DAOFactory.getPlatformDAO().getPlatform(tenantId, oldPlatformIdentifier);
|
|
|
|
|
DAOFactory.getPlatformDAO().update(tenantId, oldPlatformIdentifier, platform);
|
|
|
|
|
}
|
|
|
|
|
if (platform.isDefaultTenantMapping() && !oldPlatform.isDefaultTenantMapping()) {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
if (platform.isShared() && !oldPlatform.isShared()) {
|
|
|
|
|
TenantManager tenantManager = DataHolder.getInstance().getRealmService().getTenantManager();
|
|
|
|
|
Tenant[] tenants = tenantManager.getAllTenants();
|
|
|
|
|
for (Tenant tenant : tenants) {
|
|
|
|
|
DAOFactory.getPlatformDAO()
|
|
|
|
|
.addMapping(tenant.getId(), getListOfString(platform.getIdentifier()));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
sharePlatformWithOtherTenants(platform.getIdentifier());
|
|
|
|
|
}
|
|
|
|
|
DAOFactory.getPlatformDAO().addMapping(tenantId, getListOfString(platform.getIdentifier()));
|
|
|
|
|
} catch (UserStoreException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementException("Error occurred while assigning the platforms for tenants!",
|
|
|
|
|
e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!platform.isShared() && oldPlatform.isShared()) {
|
|
|
|
|
DAOFactory.getPlatformDAO().removeMappingTenants(platform.getIdentifier());
|
|
|
|
|
}
|
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Transaction Management Exception while trying to update " + "platform : " + oldPlatformIdentifier
|
|
|
|
|
+ " of tenant :" + tenantId);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Database Connection Exception while trying to update " + "platform : " + oldPlatformIdentifier
|
|
|
|
|
+ " of tenant :" + tenantId);
|
|
|
|
|
} catch (PlatformManagementDAOException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw e;
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<String> getListOfString(String platformIdentifier) {
|
|
|
|
|
List<String> identifiers = new ArrayList<>();
|
|
|
|
|
identifiers.add(platformIdentifier);
|
|
|
|
|
return identifiers;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void unregister(int tenantId, String identifier, boolean isFileBased) throws PlatformManagementException {
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginTransaction();
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
DAOFactory.getPlatformDAO().unregister(tenantId, identifier, isFileBased);
|
|
|
|
|
|
|
|
|
|
if (isFileBased) {
|
|
|
|
@ -333,33 +301,41 @@ public class PlatformManagerImpl implements PlatformManager {
|
|
|
|
|
tenantPlatforms.remove(identifier);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ConnectionManagerUtil.commitTransaction();
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Transaction Management Exception while trying to un-register " + "the platform with identifier : "
|
|
|
|
|
+ identifier + " tenant :" + tenantId, e);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackTransaction();
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Database Connection Exception while trying to un-register " + "the platform with identifier : "
|
|
|
|
|
+ identifier + " tenant :" + tenantId, e);
|
|
|
|
|
} catch (PlatformManagementDAOException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw e;
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void addMapping(int tenantId, List<String> platformIdentifiers) throws PlatformManagementException {
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.openConnection();
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
DAOFactory.getPlatformDAO().addMapping(tenantId, platformIdentifiers);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
} catch (DBConnectionException | TransactionManagementException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Database Connection Exception while trying to add tenant " + "mapping for tenant ID : "
|
|
|
|
|
+ tenantId);
|
|
|
|
|
} catch (PlatformManagementDAOException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw e;
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -373,13 +349,217 @@ public class PlatformManagerImpl implements PlatformManager {
|
|
|
|
|
@Override
|
|
|
|
|
public void removeMapping(int tenantId, String platformIdentifier) throws PlatformManagementException {
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.openConnection();
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
DAOFactory.getPlatformDAO().removeMapping(tenantId, platformIdentifier);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
} catch (DBConnectionException | TransactionManagementException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException(
|
|
|
|
|
"Database Connection Exception while trying to remove tenant mapping for tenant ID : " + tenantId);
|
|
|
|
|
} catch (PlatformManagementDAOException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw e;
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void updatePlatformStatus(int tenantId, String platformIdentifier, String status)
|
|
|
|
|
throws PlatformManagementException {
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
Platform platform = DAOFactory.getPlatformDAO().getPlatform(tenantId, platformIdentifier);
|
|
|
|
|
|
|
|
|
|
if (platform == null) {
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
throw new PlatformManagementException("Platform with identifier : " + platformIdentifier + " does not"
|
|
|
|
|
+ " exist for the tenant with id " + tenantId);
|
|
|
|
|
} else {
|
|
|
|
|
boolean isEnabledNewStatus = status.equalsIgnoreCase("ENABLED");
|
|
|
|
|
|
|
|
|
|
// If the platform is already in the same status. No need to enable the platform again
|
|
|
|
|
if (isEnabledNewStatus == platform.isEnabled()) {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Platform with identifier : " + platformIdentifier + " is already in " +
|
|
|
|
|
(isEnabledNewStatus ? "Enabled" : "Disabled") + " status. No need to update.");
|
|
|
|
|
}
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
return;
|
|
|
|
|
} else {
|
|
|
|
|
if (isEnabledNewStatus) {
|
|
|
|
|
DAOFactory.getPlatformDAO().addMapping(tenantId, getListOfString(platform.getIdentifier()));
|
|
|
|
|
} else {
|
|
|
|
|
DAOFactory.getPlatformDAO().removeMapping(tenantId, platform.getIdentifier());
|
|
|
|
|
}
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Platform with identifier : " + platformIdentifier + " successfully " +
|
|
|
|
|
(isEnabledNewStatus ? "Enabled" : "Disabled"));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
} catch (TransactionManagementException | DBConnectionException ex) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException("Database exception while trying to update the status of platform "
|
|
|
|
|
+ "with identifier '" + platformIdentifier + "' for the tenant" + tenantId);
|
|
|
|
|
} catch (PlatformManagementDAOException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw e;
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void removePlatforms(int tenantId) throws PlatformManagementException {
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
DAOFactory.getPlatformDAO().removePlatforms(tenantId);
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
} catch (TransactionManagementException | DBConnectionException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementDAOException("Database exception while trying to remove all the platforms for"
|
|
|
|
|
+ " the tenant " + tenantId);
|
|
|
|
|
} catch (PlatformManagementDAOException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw e;
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* To share the super-tenant platform with other tenants
|
|
|
|
|
* @param platformIdentifier Identifier of the platform
|
|
|
|
|
* @throws UserStoreException User Store Exception
|
|
|
|
|
* @throws PlatformManagementDAOException Platform Management DAO Exception
|
|
|
|
|
*/
|
|
|
|
|
private void sharePlatformWithOtherTenants(String platformIdentifier)
|
|
|
|
|
throws UserStoreException, PlatformManagementDAOException {
|
|
|
|
|
TenantManager tenantManager = DataHolder.getInstance().getRealmService().getTenantManager();
|
|
|
|
|
Tenant[] tenants = tenantManager.getAllTenants();
|
|
|
|
|
for (Tenant tenant : tenants) {
|
|
|
|
|
DAOFactory.getPlatformDAO()
|
|
|
|
|
.addMapping(tenant.getId(), getListOfString(platformIdentifier));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Validation need to be done before registering the platform
|
|
|
|
|
*
|
|
|
|
|
* @param tenantId ID of the tenant which the platform need to registered to
|
|
|
|
|
* @param platform Platform that need to be registered
|
|
|
|
|
* @throws PlatformManagementException Platform Management Exception
|
|
|
|
|
*/
|
|
|
|
|
private void validateBeforeRegister(int tenantId, Platform platform) throws PlatformManagementException {
|
|
|
|
|
validatePlatformSharing(tenantId, platform);
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
int existingPlatformId = DAOFactory.getPlatformDAO()
|
|
|
|
|
.getSuperTenantAndOwnPlatforms(platform.getIdentifier(), tenantId);
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
if (existingPlatformId != -1) {
|
|
|
|
|
throw new PlatformManagementException(
|
|
|
|
|
"Another platform exists with the identifier " + platform.getIdentifier() + " in the tenant "
|
|
|
|
|
+ tenantId + " or super-tenant. Please choose a "
|
|
|
|
|
+ "different identifier for your platform");
|
|
|
|
|
}
|
|
|
|
|
} catch (TransactionManagementException | DBConnectionException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementException(
|
|
|
|
|
"Error while checking pre-conditions before registering" + " platform identifier '" + platform
|
|
|
|
|
.getIdentifier() + "' for the tenant :" + tenantId);
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Validations that need to be done before updating the platform
|
|
|
|
|
*
|
|
|
|
|
* @param tenantId ID of the tenant
|
|
|
|
|
* @param oldPlatformIdentifier Identifier of the old platform
|
|
|
|
|
* @param platform Updated platform
|
|
|
|
|
* @return Old platform if all the validation succeeds
|
|
|
|
|
* @throws PlatformManagementException Platform ManagementException
|
|
|
|
|
*/
|
|
|
|
|
private Platform validateBeforeUpdate(int tenantId, String oldPlatformIdentifier, Platform platform) throws
|
|
|
|
|
PlatformManagementException {
|
|
|
|
|
validatePlatformSharing(tenantId, platform);
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
Platform oldPlatform = DAOFactory.getPlatformDAO().getTenantOwnedPlatform(tenantId, oldPlatformIdentifier);
|
|
|
|
|
if (oldPlatform == null) {
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
throw new PlatformManagementException(
|
|
|
|
|
"Cannot update platform. Platform with identifier : " + oldPlatformIdentifier
|
|
|
|
|
+ " does not exist for the tenant : " + tenantId);
|
|
|
|
|
}
|
|
|
|
|
if (platform.getIdentifier() != null && !platform.getIdentifier().equals(oldPlatformIdentifier)) {
|
|
|
|
|
int existingPlatformID = DAOFactory.getPlatformDAO()
|
|
|
|
|
.getSuperTenantAndOwnPlatforms(platform.getIdentifier(), tenantId);
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
if (existingPlatformID == -1) {
|
|
|
|
|
throw new PlatformManagementException(
|
|
|
|
|
"Cannot update the identifier of the platform from '" + oldPlatformIdentifier + "' to '"
|
|
|
|
|
+ platform.getIdentifier() + "'. Another platform exists "
|
|
|
|
|
+ "already with the identifier '" + platform.getIdentifier() + "' for the tenant : "
|
|
|
|
|
+ tenantId + " or in super-tenant");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return oldPlatform;
|
|
|
|
|
} catch (TransactionManagementException | DBConnectionException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementException(
|
|
|
|
|
"Database error while validating the platform update with the " + "platform identifier: "
|
|
|
|
|
+ oldPlatformIdentifier + " for the tenant :" + tenantId);
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* To validate whether this platform can be shared or not before registering and updating the platform
|
|
|
|
|
*
|
|
|
|
|
* @param tenantId ID of the tenant
|
|
|
|
|
* @param platform Platform to be validated for sharing
|
|
|
|
|
*/
|
|
|
|
|
private void validatePlatformSharing(int tenantId, Platform platform) throws PlatformManagementException {
|
|
|
|
|
if (platform.isShared() && tenantId != MultitenantConstants.SUPER_TENANT_ID) {
|
|
|
|
|
throw new PlatformManagementException(
|
|
|
|
|
"Platform sharing is a restricted operation, therefore Platform - " + platform.getIdentifier()
|
|
|
|
|
+ " cannot be shared by the tenant domain - " + tenantId);
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
ConnectionManagerUtil.beginDBTransaction();
|
|
|
|
|
if (platform.isShared()) {
|
|
|
|
|
int sharedPlatform = DAOFactory.getPlatformDAO().getMultiTenantPlatforms(platform.getIdentifier());
|
|
|
|
|
ConnectionManagerUtil.commitDBTransaction();
|
|
|
|
|
if (sharedPlatform != -1) {
|
|
|
|
|
throw new PlatformManagementException(
|
|
|
|
|
"Platform '" + platform.getIdentifier() + "' cannot be shared as some other tenants have "
|
|
|
|
|
+ "platforms with the same identifier.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (TransactionManagementException | DBConnectionException e) {
|
|
|
|
|
ConnectionManagerUtil.rollbackDBTransaction();
|
|
|
|
|
throw new PlatformManagementException(
|
|
|
|
|
"Error while checking platform sharing conditions for " + " platform identifier '" + platform
|
|
|
|
|
.getIdentifier() + "' for the tenant :" + tenantId);
|
|
|
|
|
} finally {
|
|
|
|
|
ConnectionManagerUtil.closeConnection();
|
|
|
|
|
ConnectionManagerUtil.closeDBConnection();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* To get the list of the given platform Identifier
|
|
|
|
|
* @param platformIdentifier Identifier of the Platform
|
|
|
|
|
* @return Platform Identifier as a list
|
|
|
|
|
*/
|
|
|
|
|
private List<String> getListOfString(String platformIdentifier) {
|
|
|
|
|
List<String> identifiers = new ArrayList<>();
|
|
|
|
|
identifiers.add(platformIdentifier);
|
|
|
|
|
return identifiers;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|