diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/PlatformManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/PlatformManagementAPIImpl.java index fe8ec589ea..b708b388e2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/PlatformManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/PlatformManagementAPIImpl.java @@ -37,6 +37,9 @@ import javax.ws.rs.PathParam; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; +/** + * Implementation of PlatformManagement APIs. + */ @Path("/platforms") public class PlatformManagementAPIImpl implements PlatformManagementAPI { @@ -49,13 +52,13 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI { @GET @Override public Response getPlatforms(@QueryParam("status") String status) { - String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); + int tenantID = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); if (log.isDebugEnabled()) { log.debug("API request received for getting the platforms with the status " + status); } try { - List platforms = APIUtil.getPlatformManager().getPlatforms(tenantDomain); + List platforms = APIUtil.getPlatformManager().getPlatforms(tenantID); List results; if (status != null) { if (status.contentEquals(ALL_STATUS)) { @@ -85,7 +88,7 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI { } return Response.status(Response.Status.OK).entity(results).build(); } catch (PlatformManagementException e) { - log.error("Error while getting the platforms for tenant - " + tenantDomain, e); + log.error("Error while getting the platforms for tenant - " + tenantID, e); return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); } } @@ -94,9 +97,9 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI { @Override @Path("/{identifier}") public Response getPlatform(@PathParam("identifier") String id) { - String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); try { - Platform platform = APIUtil.getPlatformManager().getPlatform(tenantDomain, id); + Platform platform = APIUtil.getPlatformManager().getPlatform(tenantId, id); return Response.status(Response.Status.OK).entity(platform).build(); } catch (PlatformManagementDAOException e) { return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); @@ -108,11 +111,11 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI { @POST @Override public Response addPlatform(Platform platform) { - String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); try { if (platform != null) { if (platform.validate()) { - APIUtil.getPlatformManager().register(tenantDomain, platform); + APIUtil.getPlatformManager().register(tenantId, platform); return Response.status(Response.Status.CREATED).build(); } else { return APIUtil.getResponse("Invxalid payload! Platform ID and names are mandatory fields!", @@ -131,12 +134,12 @@ public class PlatformManagementAPIImpl implements PlatformManagementAPI { @Path("/{identifier}") @Override public Response updatePlatform(Platform platform, @PathParam("identifier") @Size(max = 45) String id) { - String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); try { - APIUtil.getPlatformManager().update(tenantDomain, id, platform); + APIUtil.getPlatformManager().update(tenantId, id, platform); return Response.status(Response.Status.OK).build(); } catch (PlatformManagementException e) { - log.error("Error while updating the platform - " + id + " for tenant domain - " + tenantDomain, e); + log.error("Error while updating the platform - " + id + " for tenant domain - " + tenantId, e); return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 8d238a363d..1347461c54 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -26,6 +26,7 @@ http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> + @@ -33,7 +34,7 @@ http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd"> - + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml index db708d84b9..55fe863d2e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/webapp/WEB-INF/web.xml @@ -37,7 +37,7 @@ doAuthentication - false + true diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/PlatformManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/PlatformManager.java index ca2fc379a9..d1edbef02f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/PlatformManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/PlatformManager.java @@ -29,24 +29,24 @@ import java.util.List; */ public interface PlatformManager { - void initialize(String tenantDomain) throws PlatformManagementException; + void initialize(int tenantId) throws PlatformManagementException; - List getPlatforms(String tenantDomain) throws PlatformManagementException; + List getPlatforms(int tenantId) throws PlatformManagementException; - Platform getPlatform(String tenantDomain, String platformIdentifier) throws PlatformManagementException; + Platform getPlatform(int tenantId, String platformIdentifier) throws PlatformManagementException; - void register(String tenantDomain, Platform platform) throws PlatformManagementException; + void register(int tenantId, Platform platform) throws PlatformManagementException; - void update(String tenantDomain, String oldPlatformIdentifier, Platform platform) + void update(int tenantId, String oldPlatformIdentifier, Platform platform) throws PlatformManagementException; - void unregister(String tenantDomain, String platformIdentifier, boolean isFileBased) + void unregister(int tenantId, String platformIdentifier, boolean isFileBased) throws PlatformManagementException; - void addMapping(String tenantDomain, List platformIdentifiers) throws PlatformManagementException; + void addMapping(int tenantId, List platformIdentifiers) throws PlatformManagementException; - void addMapping(String tenantDomain, String platformIdentifier) throws PlatformManagementException; + void addMapping(int tenantId, String platformIdentifier) throws PlatformManagementException; - void removeMapping(String tenantDomain, String platformIdentifier) throws PlatformManagementException; + void removeMapping(int tenantId, String platformIdentifier) throws PlatformManagementException; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml index 7687d18861..a971d147e6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/pom.xml @@ -74,8 +74,7 @@ org.apache.axis2.*, org.wso2.carbon.user.core.*, org.wso2.carbon.user.api.*, - org.wso2.carbon.ndatasource.core, - org.apache.axiom.om.*; version="${axiom.osgi.version.range}" + org.wso2.carbon.ndatasource.core !org.wso2.carbon.device.application.mgt.core.internal.*, diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ConfigurationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ConfigurationManager.java index cf959cb91d..8ef40bdff0 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ConfigurationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ConfigurationManager.java @@ -22,16 +22,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.InvalidConfigurationException; -import org.wso2.carbon.device.application.mgt.core.deployer.Platform; -import org.wso2.carbon.device.application.mgt.core.deployer.Property; -import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; import org.wso2.carbon.device.application.mgt.core.util.Constants; import javax.xml.bind.JAXBContext; import javax.xml.bind.Unmarshaller; import java.io.File; -import java.util.ArrayList; -import java.util.List; public class ConfigurationManager { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/PlatformDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/PlatformDAO.java index 8aa524f138..55e95ed17e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/PlatformDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/PlatformDAO.java @@ -19,30 +19,31 @@ package org.wso2.carbon.device.application.mgt.core.dao; import org.wso2.carbon.device.application.mgt.common.Platform; -import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.PlatformManagementDAOException; import java.util.List; +/** + * PlatformDAO defines set of DAO operations that are needed for Platform Management. + */ public interface PlatformDAO { - int register(String tenantDomain, Platform platform) throws PlatformManagementDAOException; + int register(int tenantId, Platform platform) throws PlatformManagementDAOException; - void update(String tenantDomain, String oldPlatformIdentifier, Platform platform) throws PlatformManagementDAOException; + void update(int tenantId, String oldPlatformIdentifier, Platform platform) throws PlatformManagementDAOException; - void unregister(String tenantDomain, String platformIdentifier) throws PlatformManagementDAOException; + void unregister(int tenantId, String platformIdentifier) throws PlatformManagementDAOException; - void addMapping(String tenantDomain, List platformIdentifiers) throws PlatformManagementDAOException; + void addMapping(int tenantId, List platformIdentifiers) throws PlatformManagementDAOException; - void removeMapping(String tenantDomain, String platformIdentifier) throws PlatformManagementDAOException; + void removeMapping(int tenantId, String platformIdentifier) throws PlatformManagementDAOException; void removeMappingTenants(String platformIdentifier) throws PlatformManagementDAOException; - List getPlatforms(String tenantDomain) throws PlatformManagementDAOException; + List getPlatforms(int tenantId) throws PlatformManagementDAOException; Platform getPlatform(String tenantDomain, String platformIdentifier) throws PlatformManagementDAOException; Platform getPlatform(int tenantId, String identifier) throws PlatformManagementDAOException; - } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java index 6a63405460..027067a186 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/DAOFactory.java @@ -18,11 +18,8 @@ */ package org.wso2.carbon.device.application.mgt.core.dao.common; -import org.apache.axiom.om.OMElement; -import org.apache.axiom.om.util.AXIOMUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.application.mgt.common.exception.UnsupportedDatabaseEngineException; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; @@ -33,18 +30,11 @@ import org.wso2.carbon.device.application.mgt.core.dao.impl.application.MySQLApp import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.platform.GenericPlatformDAOImpl; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; -import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; import org.wso2.carbon.device.application.mgt.core.util.ApplicationMgtDatabaseCreator; -import org.wso2.carbon.device.application.mgt.core.util.Constants; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; -import org.wso2.carbon.ndatasource.core.CarbonDataSource; -import org.wso2.carbon.ndatasource.core.DataSourceService; +import org.wso2.carbon.device.application.mgt.core.util.Constants; import org.wso2.carbon.utils.dbcreator.DatabaseCreator; -import org.wso2.carbon.utils.multitenancy.MultitenantConstants; -import javax.sql.DataSource; -import javax.xml.namespace.QName; -import javax.xml.stream.XMLStreamException; import java.sql.SQLException; /** @@ -63,41 +53,41 @@ public class DAOFactory { databaseEngine = ConnectionManagerUtil.getDatabaseType(); } - public static ApplicationDAO getApplicationDAO(){ + public static ApplicationDAO getApplicationDAO() { if (databaseEngine != null) { switch (databaseEngine) { - case Constants.DataBaseTypes.DB_TYPE_H2: - return new H2ApplicationDAOImpl(); - case Constants.DataBaseTypes.DB_TYPE_MYSQL: - return new MySQLApplicationDAOImpl(); - default: - throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); + case Constants.DataBaseTypes.DB_TYPE_H2: + return new H2ApplicationDAOImpl(); + case Constants.DataBaseTypes.DB_TYPE_MYSQL: + return new MySQLApplicationDAOImpl(); + default: + throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); } } throw new IllegalStateException("Database engine has not initialized properly."); } - public static PlatformDAO getPlatformDAO(){ + public static PlatformDAO getPlatformDAO() { if (databaseEngine != null) { switch (databaseEngine) { - case Constants.DataBaseTypes.DB_TYPE_H2: - case Constants.DataBaseTypes.DB_TYPE_MYSQL: - return new GenericPlatformDAOImpl(); - default: - throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); + case Constants.DataBaseTypes.DB_TYPE_H2: + case Constants.DataBaseTypes.DB_TYPE_MYSQL: + return new GenericPlatformDAOImpl(); + default: + throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); } } throw new IllegalStateException("Database engine has not initialized properly."); } - public static LifecycleStateDAO getLifecycleStateDAO(){ + public static LifecycleStateDAO getLifecycleStateDAO() { if (databaseEngine != null) { switch (databaseEngine) { - case Constants.DataBaseTypes.DB_TYPE_H2: - case Constants.DataBaseTypes.DB_TYPE_MYSQL: - return new GenericLifecycleStateImpl(); - default: - throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); + case Constants.DataBaseTypes.DB_TYPE_H2: + case Constants.DataBaseTypes.DB_TYPE_MYSQL: + return new GenericLifecycleStateImpl(); + default: + throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); } } throw new IllegalStateException("Database engine has not initialized properly."); @@ -105,29 +95,20 @@ public class DAOFactory { /** * This method initializes the databases by creating the database. + * * @throws ApplicationManagementDAOException Exceptions thrown during the creation of the tables */ public static void initDatabases() throws ApplicationManagementDAOException { - CarbonDataSource carbonDataSource = null; - DataSource dataSource = null; - String dataSourceName = ConfigurationManager.getInstance() - .getConfiguration().getDatasourceName(); - DataSourceService service = DataHolder.getInstance().getDataSourceService(); - PrivilegedCarbonContext.startTenantFlow(); - PrivilegedCarbonContext.getThreadLocalCarbonContext() - .setTenantDomain(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME, true); + String dataSourceName = ConfigurationManager.getInstance().getConfiguration().getDatasourceName(); + String validationQuery = "SELECT * from APPM_PLATFORM"; try { - carbonDataSource = service.getDataSource(dataSourceName); - dataSource = (DataSource) carbonDataSource.getDSObject(); if (System.getProperty("setup") == null) { if (log.isDebugEnabled()) { log.debug("Application Management Database schema initialization check was skipped since " + "\'setup\' variable was not given during startup"); } } else { - DatabaseCreator databaseCreator = new ApplicationMgtDatabaseCreator(dataSource); - String validationQuery = getValidationQuery( - (String) carbonDataSource.getDSMInfo().getDefinition().getDsXMLConfiguration()); + DatabaseCreator databaseCreator = new ApplicationMgtDatabaseCreator(dataSourceName); if (!databaseCreator.isDatabaseStructureCreated(validationQuery)) { databaseCreator.createRegistryDatabase(); if (log.isDebugEnabled()) { @@ -136,34 +117,11 @@ public class DAOFactory { } } } catch (SQLException e) { - throw new ApplicationManagementDAOException("Error while creating application-mgt database during the " - + "startup ", e); + throw new ApplicationManagementDAOException( + "Error while creating application-mgt database during the " + "startup ", e); } catch (Exception e) { - throw new ApplicationManagementDAOException("Error while creating application-mgt database in the " - + "startup ", e); + throw new ApplicationManagementDAOException( + "Error while creating application-mgt database in the " + "startup ", e); } } - - /** - * To get the the validation query to make sure whether the tables exist already in application management databse - * @param dsXMLConfiguration Datasource XML configurations - * @return Validation query - */ - private static String getValidationQuery(String dsXMLConfiguration) { - String DEFAULT_VALIDATION_QUERY = "SELECT 1"; - try { - OMElement omElement = AXIOMUtil.stringToOM(dsXMLConfiguration); - return omElement.getFirstChildWithName(new QName("validationQuery")).getText(); - } catch (XMLStreamException e) { - log.error("Error while reading the validation query from the data source configuration of " - + "application-mgt (application-mgt-datasources.xml", e); - if (log.isDebugEnabled()) { - log.debug("Due to fail to read the validation query from application-mgt datasources, using the " - + "default validation query : " + DEFAULT_VALIDATION_QUERY); - } - return DEFAULT_VALIDATION_QUERY; - } - - } } - diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/GenericPlatformDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/GenericPlatformDAOImpl.java index 2aebb9d32c..ae51b716d2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/GenericPlatformDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/platform/GenericPlatformDAOImpl.java @@ -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 platformIdentifiers) throws PlatformManagementDAOException { - String insertMapping = "INSERT INTO APPM_PLATFORM_TENANT_MAPPING(TENANT_DOMAIN, PLATFORM_ID) VALUES (?, ?)"; + public void addMapping(int tenantId, List 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 getPlatforms(String tenantDomain) throws PlatformManagementDAOException { + public List 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 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 { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/deployer/Platform.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/deployer/Platform.java index a622cf0fe7..104a82ffd8 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/deployer/Platform.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/deployer/Platform.java @@ -17,11 +17,14 @@ */ package org.wso2.carbon.device.application.mgt.core.deployer; +import java.util.List; import javax.xml.bind.annotation.XmlAttribute; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlRootElement; -import java.util.List; +/** + * Platform represents an Application Platform such as Android, IOS, etc. + */ @XmlRootElement(name = "Platform") public class Platform { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/deployer/PlatformDeployer.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/deployer/PlatformDeployer.java index 07659b5dd4..abc043918a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/deployer/PlatformDeployer.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/deployer/PlatformDeployer.java @@ -29,21 +29,23 @@ import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; import org.wso2.carbon.device.application.mgt.core.util.Constants; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; -import javax.xml.bind.JAXBContext; -import javax.xml.bind.JAXBException; -import javax.xml.bind.Unmarshaller; import java.io.File; import java.util.ArrayList; import java.util.List; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; + public class PlatformDeployer extends AbstractDeployer { private static final Log log = LogFactory.getLog(PlatformDeployer.class); @Override public void init(ConfigurationContext configurationContext) { - File deployementDir = new File(MultitenantUtils.getAxis2RepositoryPath(CarbonContext.getThreadLocalCarbonContext(). - getTenantId()) + Constants.PLATFORMS_DEPLOYMENT_DIR_NAME); + File deployementDir = new File( + MultitenantUtils.getAxis2RepositoryPath(CarbonContext.getThreadLocalCarbonContext(). + getTenantId()) + Constants.PLATFORMS_DEPLOYMENT_DIR_NAME); if (!deployementDir.exists()) { if (!deployementDir.mkdir()) { log.warn("Unable to create the deployment dir at: " + deployementDir.getPath()); @@ -59,10 +61,12 @@ public class PlatformDeployer extends AbstractDeployer { Platform platformConf = (Platform) unmarshaller.unmarshal(deploymentFile); if (platformConf.getName().contentEquals(getPlatformID(deploymentFile.getName()))) { org.wso2.carbon.device.application.mgt.common.Platform platform = convert(platformConf); - DataHolder.getInstance().getPlatformManager().register(CarbonContext.getThreadLocalCarbonContext().getTenantDomain(), platform); + DataHolder.getInstance().getPlatformManager() + .register(CarbonContext.getThreadLocalCarbonContext().getTenantId(), platform); } else { - log.error("Unable to deploy the platform - " + deploymentFile.getAbsolutePath() + "!. Platform config file name - " - + deploymentFile.getName() + " should match with the 'id' provided within the platform configuration!"); + log.error("Unable to deploy the platform - " + deploymentFile.getAbsolutePath() + + "!. Platform config file name - " + deploymentFile.getName() + + " should match with the 'id' provided within the platform configuration!"); } } catch (JAXBException e) { log.error("Platform configuration file - " + deploymentFile.getAbsolutePath() + " is invalid!", e); @@ -74,7 +78,8 @@ public class PlatformDeployer extends AbstractDeployer { public void undeploy(String fileName) throws DeploymentException { String platformId = getPlatformID(fileName); try { - DataHolder.getInstance().getPlatformManager().unregister(CarbonContext.getThreadLocalCarbonContext().getTenantDomain(), platformId, true); + DataHolder.getInstance().getPlatformManager() + .unregister(CarbonContext.getThreadLocalCarbonContext().getTenantId(), platformId, true); } catch (PlatformManagementException e) { log.error("Error occurred while undeploying the platform - " + fileName); } @@ -89,7 +94,8 @@ public class PlatformDeployer extends AbstractDeployer { } private org.wso2.carbon.device.application.mgt.common.Platform convert(Platform platformConfig) { - org.wso2.carbon.device.application.mgt.common.Platform platform = new org.wso2.carbon.device.application.mgt.common.Platform(); + org.wso2.carbon.device.application.mgt.common.Platform platform = + new org.wso2.carbon.device.application.mgt.common.Platform(); platform.setIdentifier(platformConfig.getId()); platform.setName(platformConfig.getName()); platform.setDescription(platformConfig.getDescription()); @@ -100,7 +106,8 @@ public class PlatformDeployer extends AbstractDeployer { platform.setEnabled(false); List properties = new ArrayList<>(); for (Property propertyConfig : platformConfig.getProperties()) { - org.wso2.carbon.device.application.mgt.common.Platform.Property property = new org.wso2.carbon.device.application.mgt.common.Platform.Property(); + org.wso2.carbon.device.application.mgt.common.Platform.Property property = + new org.wso2.carbon.device.application.mgt.common.Platform.Property(); property.setName(propertyConfig.getName()); property.setDefaultValue(propertyConfig.getDefaultValue()); property.setOptional(propertyConfig.isOptional()); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/PlatformManagementDAOException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/PlatformManagementDAOException.java index 413efd6626..0cd87944de 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/PlatformManagementDAOException.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/exception/PlatformManagementDAOException.java @@ -19,6 +19,9 @@ package org.wso2.carbon.device.application.mgt.core.exception; import org.wso2.carbon.device.application.mgt.common.exception.PlatformManagementException; +/** + * Exception that will be thrown when there is a issue during Platform level DAO operations. + */ public class PlatformManagementDAOException extends PlatformManagementException { public PlatformManagementDAOException(String message, Throwable ex) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/PlatformManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/PlatformManagerImpl.java index 4d9730c8bf..58cb92355d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/PlatformManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/PlatformManagerImpl.java @@ -34,8 +34,11 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +/** + * Implementation of {@link PlatformManager}, which manages the CRUD operations on Application platforms. + */ public class PlatformManagerImpl implements PlatformManager { - private Map> inMemoryStore; + private Map> inMemoryStore; private static Log log = LogFactory.getLog(PlatformManagerImpl.class); public PlatformManagerImpl() { @@ -43,34 +46,34 @@ public class PlatformManagerImpl implements PlatformManager { } @Override - public void initialize(String tenantDomain) throws PlatformManagementException { - List platforms = DAOFactory.getPlatformDAO().getPlatforms(tenantDomain); + public void initialize(int tenantId) throws PlatformManagementException { + List platforms = DAOFactory.getPlatformDAO().getPlatforms(tenantId); List platformIdentifiers = new ArrayList<>(); for (Platform platform : platforms) { if (!platform.isEnabled() & platform.isDefaultTenantMapping()) { platformIdentifiers.add(platform.getIdentifier()); } } - addMapping(tenantDomain, platformIdentifiers); + addMapping(tenantId, platformIdentifiers); } @Override - public List getPlatforms(String tenantDomain) throws PlatformManagementException { + public List getPlatforms(int tenantId) throws PlatformManagementException { if (log.isDebugEnabled()) { - log.debug("Request for getting platforms received for the tenant domain " + tenantDomain + " at " + log.debug("Request for getting platforms received for the tenant ID " + tenantId + " at " + "PlatformManager level"); } - List platforms = DAOFactory.getPlatformDAO().getPlatforms(tenantDomain); + List platforms = DAOFactory.getPlatformDAO().getPlatforms(tenantId); int platformIndex = 0; if (log.isDebugEnabled()) { log.debug("Number of platforms received from DAO layer is " + platforms.size() + " for the tenant " - + tenantDomain); + + tenantId); } for (Platform platform : platforms) { if (platform.isFileBased()) { Map superTenantPlatforms = this.inMemoryStore - .get(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + .get(MultitenantConstants.SUPER_TENANT_ID); Platform registeredPlatform = superTenantPlatforms.get(platform.getIdentifier()); if (registeredPlatform != null) { platforms.set(platformIndex, new Platform(registeredPlatform)); @@ -87,36 +90,37 @@ public class PlatformManagerImpl implements PlatformManager { platformIndex++; } if (log.isDebugEnabled()) { - log.debug("Number of effective platforms for the tenant " + tenantDomain + " : " + platforms.size()); + log.debug("Number of effective platforms for the tenant " + tenantId + + " : " + platforms.size()); } return platforms; } @Override - public Platform getPlatform(String tenantDomain, String identifier) throws PlatformManagementException { - Platform platform = getPlatformFromInMemory(tenantDomain, identifier); + public Platform getPlatform(int tenantId, String identifier) throws PlatformManagementException { + Platform platform = getPlatformFromInMemory(tenantId, identifier); if (platform == null) { - platform = DAOFactory.getPlatformDAO().getPlatform(tenantDomain, identifier); + platform = DAOFactory.getPlatformDAO().getPlatform(tenantId, identifier); if (platform != null) { return platform; } } else { return new Platform(platform); } - throw new PlatformManagementException("No platform was found for tenant - " + tenantDomain + + throw new PlatformManagementException("No platform was found for tenant - " + tenantId + " with Platform identifier - " + identifier); } - private Platform getPlatformFromInMemory(String tenantDomain, String identifier) { - Map platformMap = this.inMemoryStore.get(tenantDomain); + private Platform getPlatformFromInMemory(int tenantId, String identifier) { + Map platformMap = this.inMemoryStore.get(tenantId); if (platformMap != null) { Platform platform = platformMap.get(identifier); if (platform != null) { return platform; } } - if (!tenantDomain.equalsIgnoreCase(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { - platformMap = this.inMemoryStore.get(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME); + if (tenantId != MultitenantConstants.SUPER_TENANT_ID) { + platformMap = this.inMemoryStore.get(MultitenantConstants.SUPER_TENANT_ID); if (platformMap != null) { Platform platform = platformMap.get(identifier); if (platform != null && platform.isShared()) { @@ -128,23 +132,25 @@ public class PlatformManagerImpl implements PlatformManager { } @Override - public synchronized void register(String tenantDomain, Platform platform) throws PlatformManagementException { - if (platform.isShared() && !tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { - throw new PlatformManagementException("Platform sharing is a restricted operation, therefore Platform - " - + platform.getIdentifier() + " cannot be shared by the tenant domain - " + tenantDomain); + 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); } - int platformId = DAOFactory.getPlatformDAO().register(tenantDomain, platform); + int platformId = DAOFactory.getPlatformDAO().register(tenantId, platform); if (platform.isFileBased()) { platform.setId(platformId); - Map tenantPlatforms = this.inMemoryStore.get(tenantDomain); + Map tenantPlatforms = this.inMemoryStore.get(tenantId); if (tenantPlatforms == null) { tenantPlatforms = new HashMap<>(); - this.inMemoryStore.put(tenantDomain, tenantPlatforms); + this.inMemoryStore.put(tenantId, tenantPlatforms); } if (tenantPlatforms.get(platform.getIdentifier()) == null) { tenantPlatforms.put(platform.getIdentifier(), platform); } else { - throw new PlatformManagementException("Platform - " + platform.getIdentifier() + " is already registered!"); + throw new PlatformManagementException( + "Platform - " + platform.getIdentifier() + " is already registered!"); } } if (platform.isDefaultTenantMapping()) { @@ -153,10 +159,10 @@ public class PlatformManagerImpl implements PlatformManager { TenantManager tenantManager = DataHolder.getInstance().getRealmService().getTenantManager(); Tenant[] tenants = tenantManager.getAllTenants(); for (Tenant tenant : tenants) { - addMapping(tenant.getDomain(), platform.getIdentifier()); + addMapping(tenant.getId(), platform.getIdentifier()); } } - addMapping(tenantDomain, platform.getIdentifier()); + addMapping(tenantId, platform.getIdentifier()); } catch (UserStoreException e) { throw new PlatformManagementException("Error occured while assigning the platforms for tenants!", e); } @@ -164,31 +170,34 @@ public class PlatformManagerImpl implements PlatformManager { } @Override - public void update(String tenantDomain, String oldPlatformIdentifier, Platform platform) + public void update(int tenantId, String oldPlatformIdentifier, Platform platform) throws PlatformManagementException { - if (platform.isShared() && !tenantDomain.equals(MultitenantConstants.SUPER_TENANT_DOMAIN_NAME)) { - throw new PlatformManagementException("Platform sharing is a restricted operation, therefore Platform - " - + platform.getIdentifier() + " cannot be shared by the tenant domain - " + tenantDomain); + 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.isFileBased()) { - Map tenantPlatforms = this.inMemoryStore.get(tenantDomain); + Map tenantPlatforms = this.inMemoryStore.get(tenantId); if (tenantPlatforms == null) { - throw new PlatformManagementException("No platforms registered for the tenant - " + tenantDomain + - " with platform identifier - " + platform.getIdentifier()); + throw new PlatformManagementException( + "No platforms registered for the tenant - " + tenantId + " with platform identifier - " + + platform.getIdentifier()); } oldPlatform = tenantPlatforms.get(oldPlatformIdentifier); if (oldPlatform == null) { - throw new PlatformManagementException("No platforms registered for the tenant - " + tenantDomain + - " with platform identifier - " + platform.getIdentifier()); + throw new PlatformManagementException( + "No platforms registered for the tenant - " + tenantId + " with platform identifier - " + + platform.getIdentifier()); } else { - DAOFactory.getPlatformDAO().update(tenantDomain, oldPlatformIdentifier, platform); + DAOFactory.getPlatformDAO().update(tenantId, oldPlatformIdentifier, platform); platform.setId(oldPlatform.getId()); tenantPlatforms.put(platform.getIdentifier(), platform); } } else { - oldPlatform = DAOFactory.getPlatformDAO().getPlatform(tenantDomain, oldPlatformIdentifier); - DAOFactory.getPlatformDAO().update(tenantDomain, oldPlatformIdentifier, platform); + oldPlatform = DAOFactory.getPlatformDAO().getPlatform(tenantId, oldPlatformIdentifier); + DAOFactory.getPlatformDAO().update(tenantId, oldPlatformIdentifier, platform); } if (platform.isDefaultTenantMapping() && !oldPlatform.isDefaultTenantMapping()) { try { @@ -196,12 +205,12 @@ public class PlatformManagerImpl implements PlatformManager { TenantManager tenantManager = DataHolder.getInstance().getRealmService().getTenantManager(); Tenant[] tenants = tenantManager.getAllTenants(); for (Tenant tenant : tenants) { - addMapping(tenant.getDomain(), platform.getIdentifier()); + addMapping(tenant.getId(), platform.getIdentifier()); } } - addMapping(tenantDomain, platform.getIdentifier()); + addMapping(tenantId, platform.getIdentifier()); } catch (UserStoreException e) { - throw new PlatformManagementException("Error occured while assigning the platforms for tenants!", e); + throw new PlatformManagementException("Error occurred while assigning the platforms for tenants!", e); } } if (!platform.isShared() && oldPlatform.isShared()) { @@ -210,31 +219,32 @@ public class PlatformManagerImpl implements PlatformManager { } @Override - public void unregister(String tenantDomain, String identifier, boolean isFileBased) throws PlatformManagementException { + public void unregister(int tenantId, String identifier, boolean isFileBased) throws + PlatformManagementException { if (isFileBased) { - Map tenantPlatforms = this.inMemoryStore.get(tenantDomain); + Map tenantPlatforms = this.inMemoryStore.get(tenantId); if (tenantPlatforms != null) { this.inMemoryStore.remove(identifier); } } else { - DAOFactory.getPlatformDAO().unregister(tenantDomain, identifier); + DAOFactory.getPlatformDAO().unregister(tenantId, identifier); } } @Override - public void addMapping(String tenantDomain, List platformIdentifiers) throws PlatformManagementException { - DAOFactory.getPlatformDAO().addMapping(tenantDomain, platformIdentifiers); + public void addMapping(int tenantId, List platformIdentifiers) throws PlatformManagementException { + DAOFactory.getPlatformDAO().addMapping(tenantId, platformIdentifiers); } @Override - public void addMapping(String tenantDomain, String platformIdentifier) throws PlatformManagementException { + public void addMapping(int tenantId, String platformIdentifier) throws PlatformManagementException { List identifiers = new ArrayList<>(); identifiers.add(platformIdentifier); - DAOFactory.getPlatformDAO().addMapping(tenantDomain, identifiers); + DAOFactory.getPlatformDAO().addMapping(tenantId, identifiers); } @Override - public void removeMapping(String tenantDomain, String platformIdentifier) throws PlatformManagementException { - DAOFactory.getPlatformDAO().removeMapping(tenantDomain, platformIdentifier); + public void removeMapping(int tenantId, String platformIdentifier) throws PlatformManagementException { + DAOFactory.getPlatformDAO().removeMapping(tenantId, platformIdentifier); } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java index d2719a9d0e..5c4bac0495 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/DataHolder.java @@ -29,7 +29,6 @@ import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManage import org.wso2.carbon.device.application.mgt.common.services.VisibilityManager; import org.wso2.carbon.device.application.mgt.common.services.VisibilityTypeManager; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; -import org.wso2.carbon.ndatasource.core.DataSourceService; import org.wso2.carbon.user.core.service.RealmService; /** @@ -63,8 +62,6 @@ public class DataHolder { private static final DataHolder applicationMgtDataHolder = new DataHolder(); - private DataSourceService dataSourceService; - private DataHolder() { } @@ -169,11 +166,4 @@ public class DataHolder { this.realmService = realmService; } - public void setDataSourceService(DataSourceService dataSourceService) { - this.dataSourceService = dataSourceService; - } - - public DataSourceService getDataSourceService() { - return dataSourceService; - } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java index c1b536a254..e729af9a6a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/internal/ServiceComponent.java @@ -70,8 +70,7 @@ public class ServiceComponent { private static Log log = LogFactory.getLog(ServiceComponent.class); - protected void activate(ComponentContext componentContext) throws NamingException, - ApplicationManagementDAOException { + protected void activate(ComponentContext componentContext) throws NamingException { BundleContext bundleContext = componentContext.getBundleContext(); try { String datasourceName = ConfigurationManager.getInstance().getConfiguration().getDatasourceName(); @@ -119,9 +118,12 @@ public class ServiceComponent { bundleContext.registerService(ApplicationUploadManager.class.getName(), uploadManager, null); DAOFactory.init(datasourceName); + DAOFactory.initDatabases(); log.info("ApplicationManagement core bundle has been successfully initialized"); } catch (InvalidConfigurationException e) { log.error("Error while activating Application Management core component. ", e); + } catch (ApplicationManagementDAOException e) { + log.error("Error while activating Application Management core component.Failed to create the database ", e); } } @@ -152,10 +154,12 @@ public class ServiceComponent { } protected void setDataSourceService(DataSourceService dataSourceService) { - DataHolder.getInstance().setDataSourceService(dataSourceService); + //Not implemented. Not needed but to make sure the datasource service are registered, as it is needed create + // databases. } protected void unsetDataSourceService(DataSourceService dataSourceService) { - DataHolder.getInstance().setDataSourceService(null); + //Not implemented. Not needed but to make sure the datasource service are registered, as it is needed to create + // databases. } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationMgtDatabaseCreator.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationMgtDatabaseCreator.java index ccdcf5e083..197b82921f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationMgtDatabaseCreator.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ApplicationMgtDatabaseCreator.java @@ -35,8 +35,8 @@ public class ApplicationMgtDatabaseCreator extends DatabaseCreator { CarbonUtils.getCarbonHome() + File.separator + "dbscripts" + File.separator + "cdm" + File.separator + "application-mgt" + File.separator; - public ApplicationMgtDatabaseCreator(DataSource dataSource) { - super(dataSource); + public ApplicationMgtDatabaseCreator(String dataSourceName) { + super(ConnectionManagerUtil.resolveDataSource(dataSourceName)); } protected String getDbScriptLocation(String databaseType) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ConnectionManagerUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ConnectionManagerUtil.java index 0a99a14e47..664e637901 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ConnectionManagerUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/ConnectionManagerUtil.java @@ -160,18 +160,19 @@ public class ConnectionManagerUtil { } } - /** - * Resolve data source from the data source definition. + * Resolve the datasource from the datasource definition. * - * @param dataSourceName data source name + * @param dataSourceName Name of the datasource + * @return DataSource resolved by the datasource name */ - public static void resolveDataSource(String dataSourceName) { + public static DataSource resolveDataSource(String dataSourceName) { try { dataSource = InitialContext.doLookup(dataSourceName); } catch (Exception e) { throw new RuntimeException("Error in looking up data source: " + e.getMessage(), e); } + return dataSource; } @@ -183,4 +184,5 @@ public class ConnectionManagerUtil { } return null; } + } diff --git a/components/application-mgt/pom.xml b/components/application-mgt/pom.xml index 41ed7a816a..9770fd0643 100644 --- a/components/application-mgt/pom.xml +++ b/components/application-mgt/pom.xml @@ -41,6 +41,12 @@ + + + org.apache.maven.plugins + maven-checkstyle-plugin + + diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index 32e670c95b..6f19489dec 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -13,6 +13,9 @@ CREATE TABLE IF NOT EXISTS APPM_PLATFORM ( ICON_NAME VARCHAR(100) NULL, DESCRIPTOR LONGTEXT NOT NULL, PUBLISHED TINYINT NULL, + IS_SHARED BOOLEAN DEFAULT FALSE, + FILE_BASED BOOLEAN DEFAULT FALSE, + TENANT_ID INT, PRIMARY KEY (ID), UNIQUE INDEX IDENTIFIER_UNIQUE (IDENTIFIER ASC)); @@ -27,9 +30,9 @@ CREATE TABLE IF NOT EXISTS APPM_APPLICATION_CATEGORY ( PRIMARY KEY (ID)); -- ----------------------------------------------------- --- Table APPM_PLATFORM_APPLICATION_MAPPING +-- Table APPM_PLATFORM_TENANT_MAPPING -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS APPM_PLATFORM_APPLICATION_MAPPING ( +CREATE TABLE IF NOT EXISTS APPM_PLATFORM_TENANT_MAPPING ( ID INT NOT NULL AUTO_INCREMENT, PLATFORM_ID INT NOT NULL, TENANT_ID INT NOT NULL, @@ -40,7 +43,7 @@ CREATE TABLE IF NOT EXISTS APPM_PLATFORM_APPLICATION_MAPPING ( ON DELETE NO ACTION ON UPDATE NO ACTION); -CREATE INDEX FK_PLATFROM_APPLICATION_MAPPING_PLATFORM ON APPM_PLATFORM_APPLICATION_MAPPING(PLATFORM_ID ASC); +CREATE INDEX FK_PLATFROM_TENANT_MAPPING_PLATFORM ON APPM_PLATFORM_TENANT_MAPPING(PLATFORM_ID ASC); -- ----------------------------------------------------- @@ -83,9 +86,9 @@ CREATE TABLE IF NOT EXISTS APPM_APPLICATION ( REFERENCES APPM_APPLICATION_CATEGORY (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT fk_APPM_APPLICATION_APPM_PLATFORM_APPLICATION_MAPPING1 + CONSTRAINT fk_APPM_APPLICATION_APPM_PLATFORM_TENANT_MAPPING1 FOREIGN KEY (PLATFORM_APPLICATION_MAPPING_ID) - REFERENCES APPM_PLATFORM_APPLICATION_MAPPING (ID) + REFERENCES APPM_PLATFORM_TENANT_MAPPING (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT fk_APPM_APPLICATION_APPM_LIFECYCLE_STATE1 @@ -278,8 +281,8 @@ CREATE INDEX FK_VISIBILITY_APPLICATION ON APPM_VISIBILITY(APPLICATION_ID ASC); -- Table APPM_SUBSCRIPTION_PROPERTIES -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS APPM_SUBSCRIPTION_PROPERTIES ( - PROP_KEY TEXT NOT NULL, - PROP_VALUE TEXT NULL, + PROP_KEY VARCHAR(500) NOT NULL, + PROP_VALUE VARCHAR(500) NULL, APPM_SUBSCRIPTION_ID INT NOT NULL, PRIMARY KEY (PROP_KEY, APPM_SUBSCRIPTION_ID), CONSTRAINT fk_APPM_SUBSCRIPTION_PROPERTIES_APPM_SUBSCRIPTION1 diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index 485fb3b2bf..a316f290e6 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -20,6 +20,8 @@ CREATE TABLE IF NOT EXISTS `APPM_PLATFORM` ( `DESCRIPTION` TEXT NULL, `IDENTIFIER` VARCHAR(100) NOT NULL, `DESCRIPTOR` LONGTEXT NOT NULL, + IS_SHARED BOOLEAN DEFAULT FALSE, + FILE_BASED BOOLEAN DEFAULT FALSE, PRIMARY KEY (`ID`), UNIQUE INDEX `IDENTIFIER_UNIQUE` (`IDENTIFIER` ASC)) ENGINE = InnoDB @@ -235,7 +237,7 @@ CREATE TABLE IF NOT EXISTS `APPM_COMMENT` ( -- ----------------------------------------------------- -- Table `APPM_PLATFORM_TENENT_MAPPING` -- ----------------------------------------------------- -CREATE TABLE IF NOT EXISTS `APPM_PLATFORM_TENENT_MAPPING` ( +CREATE TABLE IF NOT EXISTS `APPM_PLATFORM_TENANT_MAPPING` ( `ID` INT NOT NULL AUTO_INCREMENT, `PLATFORM_ID` INT NOT NULL, `TENANT_ID` INT NOT NULL, diff --git a/pom.xml b/pom.xml index 5164788cb9..753b1a5c5d 100644 --- a/pom.xml +++ b/pom.xml @@ -953,11 +953,6 @@ org.wso2.carbon.identity.application.common ${carbon.identity.framework.version} - - org.wso2.carbon.identity - org.wso2.carbon.identity.oauth2.grant.jwt - ${identity.jwt.extension.version} - org.wso2.carbon.identity.framework org.wso2.carbon.user.mgt @@ -1190,16 +1185,6 @@ org.wso2.carbon.application.mgt.stub ${carbon.commons.version} - - org.wso2.carbon.analytics - org.wso2.carbon.analytics.api - ${carbon.analytics.version} - - - org.wso2.carbon.analytics - org.wso2.carbon.analytics.datasource.commons - ${carbon.analytics.version} - org.wso2.carbon.event-processing org.wso2.carbon.event.processor.stub @@ -1430,11 +1415,6 @@ org.wso2.carbon.event.output.adapter.core ${carbon.analytics.common.version} - - org.wso2.carbon.analytics-common - org.wso2.carbon.event.receiver.stub - ${carbon.analytics.common.version} - org.wso2.carbon.analytics org.wso2.carbon.analytics.datasource.commons @@ -1445,11 +1425,6 @@ org.wso2.carbon.analytics.dataservice.commons ${carbon.analytics.version} - - org.wso2.carbon.analytics-common - org.wso2.carbon.event.stream.stub - ${carbon.analytics.common.version} - org.wso2.carbon.analytics-common org.wso2.carbon.event.publisher.stub @@ -1666,10 +1641,6 @@ org.apache.maven.plugins maven-deploy-plugin - - org.apache.maven.plugins - maven-checkstyle-plugin - @@ -2022,7 +1993,6 @@ 2.5 - 1.0.2 2.6.1.wso2v1 2.6.1.wso2v3 2.8.2.wso2v1