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/ApplicationManagementDAOFactory.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOFactory.java index b800a4fd5a..dff16cb59f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOFactory.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOFactory.java @@ -21,22 +21,32 @@ package org.wso2.carbon.device.application.mgt.core.dao.common; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; 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.*; -import org.wso2.carbon.device.application.mgt.core.dao.impl.review.ReviewDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; +import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; +import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO; +import org.wso2.carbon.device.application.mgt.core.dao.ReviewDAO; +import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO; +import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO; +import org.wso2.carbon.device.application.mgt.core.dao.impl.application.SQLServerApplicationDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.OracleApplicationReleaseDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.SQLServerApplicationReleaseDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.OracleLifecycleStateDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.SQLServerLifecycleStateDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.review.GenericReviewDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.GenericApplicationReleaseDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.OracleApplicationDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.review.OracleReviewDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.review.SQLServerReviewDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.subscription.GenericSubscriptionDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.subscription.OracleSubscriptionDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.subscription.SQLServerSubscriptionDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.visibility.GenericVisibilityDAOImpl; -import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; -import org.wso2.carbon.device.application.mgt.core.util.ApplicationMgtDatabaseCreator; +import org.wso2.carbon.device.application.mgt.core.dao.impl.visibility.OracleVisibilityDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.visibility.SQLServerVisibilityDAOImpl; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.Constants; -import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; -import org.wso2.carbon.device.mgt.core.dao.impl.DeviceTypeDAOImpl; -import org.wso2.carbon.utils.dbcreator.DatabaseCreator; import javax.sql.DataSource; import java.sql.SQLException; @@ -74,6 +84,8 @@ public class ApplicationManagementDAOFactory { case Constants.DataBaseTypes.DB_TYPE_MYSQL: case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL: return new GenericApplicationDAOImpl(); + case Constants.DataBaseTypes.DB_TYPE_MSSQL: + return new SQLServerApplicationDAOImpl(); case Constants.DataBaseTypes.DB_TYPE_ORACLE: return new OracleApplicationDAOImpl(); default: @@ -89,8 +101,11 @@ public class ApplicationManagementDAOFactory { case Constants.DataBaseTypes.DB_TYPE_H2: case Constants.DataBaseTypes.DB_TYPE_MYSQL: case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL: - case Constants.DataBaseTypes.DB_TYPE_ORACLE: return new GenericLifecycleStateDAOImpl(); + case Constants.DataBaseTypes.DB_TYPE_MSSQL: + return new SQLServerLifecycleStateDAOImpl(); + case Constants.DataBaseTypes.DB_TYPE_ORACLE: + return new OracleLifecycleStateDAOImpl(); default: throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); } @@ -109,8 +124,11 @@ public class ApplicationManagementDAOFactory { case Constants.DataBaseTypes.DB_TYPE_H2: case Constants.DataBaseTypes.DB_TYPE_MYSQL: case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL: - case Constants.DataBaseTypes.DB_TYPE_ORACLE: return new GenericApplicationReleaseDAOImpl(); + case Constants.DataBaseTypes.DB_TYPE_ORACLE: + return new OracleApplicationReleaseDAOImpl(); + case Constants.DataBaseTypes.DB_TYPE_MSSQL: + return new SQLServerApplicationReleaseDAOImpl(); default: throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); } @@ -128,8 +146,11 @@ public class ApplicationManagementDAOFactory { case Constants.DataBaseTypes.DB_TYPE_H2: case Constants.DataBaseTypes.DB_TYPE_MYSQL: case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL: - case Constants.DataBaseTypes.DB_TYPE_ORACLE: return new GenericVisibilityDAOImpl(); + case Constants.DataBaseTypes.DB_TYPE_ORACLE: + return new OracleVisibilityDAOImpl(); + case Constants.DataBaseTypes.DB_TYPE_MSSQL: + return new SQLServerVisibilityDAOImpl(); default: throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); } @@ -148,6 +169,10 @@ public class ApplicationManagementDAOFactory { case Constants.DataBaseTypes.DB_TYPE_MYSQL: case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL: return new GenericSubscriptionDAOImpl(); + case Constants.DataBaseTypes.DB_TYPE_ORACLE: + return new OracleSubscriptionDAOImpl(); + case Constants.DataBaseTypes.DB_TYPE_MSSQL: + return new SQLServerSubscriptionDAOImpl(); default: throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); } @@ -155,67 +180,21 @@ public class ApplicationManagementDAOFactory { throw new IllegalStateException("Database engine has not initialized properly."); } - /** - * To get the instance of DeviceTypeDAOImpl of the particular database engine. - * @return DeviceTypeDAOImpl - */ - public static DeviceTypeDAO getDeviceTypeDAO() { - if (databaseEngine != null) { - switch (databaseEngine) { - case Constants.DataBaseTypes.DB_TYPE_H2: - case Constants.DataBaseTypes.DB_TYPE_MYSQL: - case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL: - return new DeviceTypeDAOImpl(); - default: - throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); - } - } - throw new IllegalStateException("Database engine has not initialized properly."); - } - public static ReviewDAO getCommentDAO() { if (databaseEngine != null) { switch (databaseEngine) { case Constants.DataBaseTypes.DB_TYPE_H2: case Constants.DataBaseTypes.DB_TYPE_MYSQL: case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL: - return new ReviewDAOImpl(); + return new GenericReviewDAOImpl(); + case Constants.DataBaseTypes.DB_TYPE_ORACLE: + return new OracleReviewDAOImpl(); + case Constants.DataBaseTypes.DB_TYPE_MSSQL: + return new SQLServerReviewDAOImpl(); default: throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); } } throw new IllegalStateException("Database engine has not initialized properly."); } - - /** - * 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 { - String dataSourceName = ConfigurationManager.getInstance().getConfiguration().getDatasourceName(); - String validationQuery = "SELECT * from APPM_PLATFORM"; - try { - 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(dataSourceName); - if (!databaseCreator.isDatabaseStructureCreated(validationQuery)) { - databaseCreator.createRegistryDatabase(); - log.info("Application Management tables are created in the database"); - } else { - log.info("Application Management Database structure already exists. Not creating the database."); - } - } - } catch (SQLException 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); - } - } } 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/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index ed75820d7d..44416cb397 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -43,7 +43,7 @@ import java.util.List; import java.util.StringJoiner; /** - * This handles ApplicationDAO related operations. + * This handles Application related operations. */ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements ApplicationDAO { 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/application/OracleApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java index 56432d8db0..f78caaf7d3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java @@ -19,15 +19,173 @@ package org.wso2.carbon.device.application.mgt.core.dao.impl.application; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.application.mgt.common.Filter; +import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; +import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; +import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; +import org.wso2.carbon.device.application.mgt.core.util.DAOUtil; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; /** - * This is a ApplicationDAO Implementation specific to Oracle. + * This handles Application operations which are specific to Oracle. */ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl { private static final Log log = LogFactory.getLog(OracleApplicationDAOImpl.class); + @Override + public List getApplications(Filter filter,int deviceTypeId, int tenantId) throws + ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Getting application data from the database"); + log.debug(String.format("Filter: limit=%s, offset=%s", filter.getLimit(), filter.getOffset())); + } + int paramIndex = 1; + String sql = "SELECT " + + "AP_APP.ID AS APP_ID, " + + "AP_APP.NAME AS APP_NAME, " + + "AP_APP.DESCRIPTION AS APP_DESCRIPTION, " + + "AP_APP.TYPE AS APP_TYPE, " + + "AP_APP.STATUS AS APP_STATUS, " + + "AP_APP.SUB_TYPE AS APP_SUB_TYPE, " + + "AP_APP.CURRENCY AS APP_CURRENCY, " + + "AP_APP.RATING AS APP_RATING, " + + "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, " + + "AP_APP_RELEASE.ID AS RELEASE_ID, " + + "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, " + + "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, " + + "AP_APP_RELEASE.UUID AS RELEASE_UUID, " + + "AP_APP_RELEASE.RELEASE_TYPE AS RELEASE_TYPE, " + + "AP_APP_RELEASE.INSTALLER_LOCATION AS AP_RELEASE_STORED_LOC, " + + "AP_APP_RELEASE.ICON_LOCATION AS AP_RELEASE_ICON_LOC, " + + "AP_APP_RELEASE.BANNER_LOCATION AS AP_RELEASE_BANNER_LOC, " + + "AP_APP_RELEASE.SC_1_LOCATION AS AP_RELEASE_SC1, " + + "AP_APP_RELEASE.SC_2_LOCATION AS AP_RELEASE_SC2, " + + "AP_APP_RELEASE.SC_3_LOCATION AS AP_RELEASE_SC3, " + + "AP_APP_RELEASE.APP_HASH_VALUE AS RELEASE_HASH_VALUE, " + + "AP_APP_RELEASE.APP_PRICE AS RELEASE_PRICE, " + + "AP_APP_RELEASE.APP_META_INFO AS RELEASE_META_INFO, " + + "AP_APP_RELEASE.PACKAGE_NAME AS PACKAGE_NAME, " + + "AP_APP_RELEASE.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, " + + "AP_APP_RELEASE.RATING AS RELEASE_RATING, " + + "AP_APP_RELEASE.CURRENT_STATE AS RELEASE_CURRENT_STATE, " + + "AP_APP_RELEASE.RATED_USERS AS RATED_USER_COUNT " + + "FROM AP_APP " + + "INNER JOIN AP_APP_RELEASE ON " + + "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID " + + "INNER JOIN (SELECT ID FROM AP_APP OFFSET ? ROWS FETCH NEXT ? ROWS ONLY) AS app_data ON app_data.ID = AP_APP.ID " + + "WHERE AP_APP.TENANT_ID = ?"; + + if (filter == null) { + String msg = "Filter is not instantiated."; + log.error(msg); + throw new ApplicationManagementDAOException(msg); + } + + if (!StringUtils.isEmpty(filter.getAppType())) { + sql += " AND AP_APP.TYPE = ?"; + } + if (!StringUtils.isEmpty(filter.getAppName())) { + sql += " AND LOWER (AP_APP.NAME) "; + if (filter.isFullMatch()) { + sql += "= ?"; + } else { + sql += "LIKE ?"; + } + } + if (!StringUtils.isEmpty(filter.getSubscriptionType())) { + sql += " AND AP_APP.SUB_TYPE = ?"; + } + if (filter.getMinimumRating() > 0) { + sql += " AND AP_APP.RATING >= ?"; + } + if (!StringUtils.isEmpty(filter.getVersion())) { + sql += " AND AP_APP_RELEASE.VERSION = ?"; + } + if (!StringUtils.isEmpty(filter.getAppReleaseType())) { + sql += " AND AP_APP_RELEASE.RELEASE_TYPE = ?"; + } + if (!StringUtils.isEmpty(filter.getAppReleaseState())) { + sql += " AND AP_APP_RELEASE.CURRENT_STATE = ?"; + } + if (deviceTypeId != -1) { + sql += " AND AP_APP.DEVICE_TYPE_ID = ?"; + } + + if (filter.getLimit() == -1) { + sql = sql.replace("OFFSET ? ROWS FETCH NEXT ? ROWS ONLY", ""); + } + + String sortingOrder = "ASC"; + if (!StringUtils.isEmpty(filter.getSortBy() )) { + sortingOrder = filter.getSortBy(); + } + sql += " ORDER BY APP_ID " + sortingOrder; + + try { + Connection conn = this.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql); + ){ + if (filter.getLimit() != -1) { + if (filter.getLimit() == 0) { + stmt.setInt(paramIndex++, 100); + } else { + stmt.setInt(paramIndex++, filter.getLimit()); + } + stmt.setInt(paramIndex++, filter.getOffset()); + } + stmt.setInt(paramIndex++, tenantId); + if (filter.getAppType() != null && !filter.getAppType().isEmpty()) { + stmt.setString(paramIndex++, filter.getAppType()); + } + if (filter.getAppName() != null && !filter.getAppName().isEmpty()) { + if (filter.isFullMatch()) { + stmt.setString(paramIndex++, filter.getAppName().toLowerCase()); + } else { + stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%"); + } + } + if (!StringUtils.isEmpty(filter.getSubscriptionType())) { + stmt.setString(paramIndex++, filter.getSubscriptionType()); + } + if (filter.getMinimumRating() > 0) { + stmt.setInt(paramIndex++, filter.getMinimumRating()); + } + if (!StringUtils.isEmpty(filter.getVersion())) { + stmt.setString(paramIndex++, filter.getVersion()); + } + if (!StringUtils.isEmpty(filter.getAppReleaseType())) { + stmt.setString(paramIndex++, filter.getAppReleaseType()); + } + if (!StringUtils.isEmpty(filter.getAppReleaseState())) { + stmt.setString(paramIndex++, filter.getAppReleaseState()); + } + if (deviceTypeId > 0 ) { + stmt.setInt(paramIndex, deviceTypeId); + } + try (ResultSet rs = stmt.executeQuery() ) { + return DAOUtil.loadApplications(rs); + } + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection while getting application list for the " + + "tenant " + tenantId; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while getting application list for the tenant " + tenantId + ". While " + + "executing " + sql; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } + } } 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/application/SQLServerApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java new file mode 100644 index 0000000000..8cfe1ea71f --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java @@ -0,0 +1,189 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.application.mgt.core.dao.impl.application; + +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.application.mgt.common.Filter; +import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; +import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; +import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; +import org.wso2.carbon.device.application.mgt.core.util.DAOUtil; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + +/** + * This handles Application operations which are specific to MSSQL. + */ +public class SQLServerApplicationDAOImpl extends GenericApplicationDAOImpl { + + private static final Log log = LogFactory.getLog(SQLServerApplicationDAOImpl.class); + + @Override + public List getApplications(Filter filter,int deviceTypeId, int tenantId) throws + ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Getting application data from the database"); + log.debug(String.format("Filter: limit=%s, offset=%s", filter.getLimit(), filter.getOffset())); + } + int paramIndex = 1; + String sql = "SELECT " + + "AP_APP.ID AS APP_ID, " + + "AP_APP.NAME AS APP_NAME, " + + "AP_APP.DESCRIPTION AS APP_DESCRIPTION, " + + "AP_APP.TYPE AS APP_TYPE, " + + "AP_APP.STATUS AS APP_STATUS, " + + "AP_APP.SUB_TYPE AS APP_SUB_TYPE, " + + "AP_APP.CURRENCY AS APP_CURRENCY, " + + "AP_APP.RATING AS APP_RATING, " + + "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, " + + "AP_APP_RELEASE.ID AS RELEASE_ID, " + + "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, " + + "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, " + + "AP_APP_RELEASE.UUID AS RELEASE_UUID, " + + "AP_APP_RELEASE.RELEASE_TYPE AS RELEASE_TYPE, " + + "AP_APP_RELEASE.INSTALLER_LOCATION AS AP_RELEASE_STORED_LOC, " + + "AP_APP_RELEASE.ICON_LOCATION AS AP_RELEASE_ICON_LOC, " + + "AP_APP_RELEASE.BANNER_LOCATION AS AP_RELEASE_BANNER_LOC, " + + "AP_APP_RELEASE.SC_1_LOCATION AS AP_RELEASE_SC1, " + + "AP_APP_RELEASE.SC_2_LOCATION AS AP_RELEASE_SC2, " + + "AP_APP_RELEASE.SC_3_LOCATION AS AP_RELEASE_SC3, " + + "AP_APP_RELEASE.APP_HASH_VALUE AS RELEASE_HASH_VALUE, " + + "AP_APP_RELEASE.APP_PRICE AS RELEASE_PRICE, " + + "AP_APP_RELEASE.APP_META_INFO AS RELEASE_META_INFO, " + + "AP_APP_RELEASE.PACKAGE_NAME AS PACKAGE_NAME, " + + "AP_APP_RELEASE.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, " + + "AP_APP_RELEASE.RATING AS RELEASE_RATING, " + + "AP_APP_RELEASE.CURRENT_STATE AS RELEASE_CURRENT_STATE, " + + "AP_APP_RELEASE.RATED_USERS AS RATED_USER_COUNT " + + "FROM AP_APP " + + "INNER JOIN AP_APP_RELEASE ON " + + "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID " + + "INNER JOIN (SELECT ID FROM AP_APP OFFSET ? ROWS FETCH NEXT ? ROWS ONLY) AS app_data ON app_data.ID = AP_APP.ID " + + "WHERE AP_APP.TENANT_ID = ?"; + + if (filter == null) { + String msg = "Filter is not instantiated."; + log.error(msg); + throw new ApplicationManagementDAOException(msg); + } + + if (!StringUtils.isEmpty(filter.getAppType())) { + sql += " AND AP_APP.TYPE = ?"; + } + if (!StringUtils.isEmpty(filter.getAppName())) { + sql += " AND LOWER (AP_APP.NAME) "; + if (filter.isFullMatch()) { + sql += "= ?"; + } else { + sql += "LIKE ?"; + } + } + if (!StringUtils.isEmpty(filter.getSubscriptionType())) { + sql += " AND AP_APP.SUB_TYPE = ?"; + } + if (filter.getMinimumRating() > 0) { + sql += " AND AP_APP.RATING >= ?"; + } + if (!StringUtils.isEmpty(filter.getVersion())) { + sql += " AND AP_APP_RELEASE.VERSION = ?"; + } + if (!StringUtils.isEmpty(filter.getAppReleaseType())) { + sql += " AND AP_APP_RELEASE.RELEASE_TYPE = ?"; + } + if (!StringUtils.isEmpty(filter.getAppReleaseState())) { + sql += " AND AP_APP_RELEASE.CURRENT_STATE = ?"; + } + if (deviceTypeId != -1) { + sql += " AND AP_APP.DEVICE_TYPE_ID = ?"; + } + + if (filter.getLimit() == -1) { + sql = sql.replace("OFFSET ? ROWS FETCH NEXT ? ROWS ONLY", ""); + } + + String sortingOrder = "ASC"; + if (!StringUtils.isEmpty(filter.getSortBy() )) { + sortingOrder = filter.getSortBy(); + } + sql += " ORDER BY APP_ID " + sortingOrder; + + try { + Connection conn = this.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql); + ){ + if (filter.getLimit() != -1) { + if (filter.getLimit() == 0) { + stmt.setInt(paramIndex++, 100); + } else { + stmt.setInt(paramIndex++, filter.getLimit()); + } + stmt.setInt(paramIndex++, filter.getOffset()); + } + stmt.setInt(paramIndex++, tenantId); + + if (filter.getAppType() != null && !filter.getAppType().isEmpty()) { + stmt.setString(paramIndex++, filter.getAppType()); + } + if (filter.getAppName() != null && !filter.getAppName().isEmpty()) { + if (filter.isFullMatch()) { + stmt.setString(paramIndex++, filter.getAppName().toLowerCase()); + } else { + stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%"); + } + } + if (!StringUtils.isEmpty(filter.getSubscriptionType())) { + stmt.setString(paramIndex++, filter.getSubscriptionType()); + } + if (filter.getMinimumRating() > 0) { + stmt.setInt(paramIndex++, filter.getMinimumRating()); + } + if (!StringUtils.isEmpty(filter.getVersion())) { + stmt.setString(paramIndex++, filter.getVersion()); + } + if (!StringUtils.isEmpty(filter.getAppReleaseType())) { + stmt.setString(paramIndex++, filter.getAppReleaseType()); + } + if (!StringUtils.isEmpty(filter.getAppReleaseState())) { + stmt.setString(paramIndex++, filter.getAppReleaseState()); + } + if (deviceTypeId > 0 ) { + stmt.setInt(paramIndex, deviceTypeId); + } + try (ResultSet rs = stmt.executeQuery() ) { + return DAOUtil.loadApplications(rs); + } + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection while getting application list for the " + + "tenant " + tenantId; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while getting application list for the tenant " + tenantId + ". While " + + "executing " + sql; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } + } +} 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/application/release/GenericApplicationReleaseDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java index 979a28c2f0..f05d0a66c1 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/GenericApplicationReleaseDAOImpl.java @@ -312,7 +312,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements statement.setString(x++, applicationReleaseDTO.getCurrentState().toUpperCase()); } statement.setInt(x++, applicationReleaseDTO.getId()); - statement.setInt(x++, tenantId); + statement.setInt(x, tenantId); if (statement.executeUpdate() == 0) { return null; } 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/application/release/OracleApplicationReleaseDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/OracleApplicationReleaseDAOImpl.java new file mode 100644 index 0000000000..07fc421771 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/OracleApplicationReleaseDAOImpl.java @@ -0,0 +1,24 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.application.mgt.core.dao.impl.application.release; + +/** + * This handles Application Release operations which are specific to MSSQL. + */ +public class OracleApplicationReleaseDAOImpl extends GenericApplicationReleaseDAOImpl { +} 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/application/release/SQLServerApplicationReleaseDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/SQLServerApplicationReleaseDAOImpl.java new file mode 100644 index 0000000000..a19cab152c --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/release/SQLServerApplicationReleaseDAOImpl.java @@ -0,0 +1,24 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.application.mgt.core.dao.impl.application.release; + +/** + * This handles Application Release operations which are specific to MSSQL. + */ +public class SQLServerApplicationReleaseDAOImpl extends GenericApplicationReleaseDAOImpl { +} 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/lifecyclestate/OracleLifecycleStateDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/OracleLifecycleStateDAOImpl.java new file mode 100644 index 0000000000..e278574c39 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/OracleLifecycleStateDAOImpl.java @@ -0,0 +1,24 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate; + +/** + * This handles App Lifecycle operations which are specific to MSSQL. + */ +public class OracleLifecycleStateDAOImpl extends GenericLifecycleStateDAOImpl{ +} 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/lifecyclestate/SQLServerLifecycleStateDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/SQLServerLifecycleStateDAOImpl.java new file mode 100644 index 0000000000..063e3ccd56 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/SQLServerLifecycleStateDAOImpl.java @@ -0,0 +1,24 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate; + +/** + * This handles App Lifecycle operations which are specific to MSSQL. + */ +public class SQLServerLifecycleStateDAOImpl extends GenericLifecycleStateDAOImpl{ +} 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/review/ReviewDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/GenericReviewDAOImpl.java similarity index 99% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/ReviewDAOImpl.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/GenericReviewDAOImpl.java index bdd14ee2ae..768f96ca58 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/ReviewDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/GenericReviewDAOImpl.java @@ -45,9 +45,9 @@ import java.util.StringJoiner; * This handles ReviewDAO related operations. */ -public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { +public class GenericReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO { - private static final Log log = LogFactory.getLog(ReviewDAOImpl.class); + private static final Log log = LogFactory.getLog(GenericReviewDAOImpl.class); private String sql; @Override 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/review/OracleReviewDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/OracleReviewDAOImpl.java new file mode 100644 index 0000000000..b05391d306 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/OracleReviewDAOImpl.java @@ -0,0 +1,200 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.application.mgt.core.dao.impl.review; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.application.mgt.common.PaginationRequest; +import org.wso2.carbon.device.application.mgt.common.dto.ReviewDTO; +import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; +import org.wso2.carbon.device.application.mgt.core.exception.ReviewManagementDAOException; +import org.wso2.carbon.device.application.mgt.core.util.Constants; +import org.wso2.carbon.device.application.mgt.core.util.DAOUtil; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; +import java.util.StringJoiner; + +/** + * This handles Application Review handling operations which are specific to Oracle. + */ +public class OracleReviewDAOImpl extends GenericReviewDAOImpl { + + private static final Log log = LogFactory.getLog(OracleReviewDAOImpl.class); + private String sql; + + @Override + public List getAllReleaseReviews(int releaseId, PaginationRequest request, int tenantId) + throws ReviewManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Getting all application release reviews for the application release ID: " + releaseId); + } + sql = "SELECT " + + "AP_APP_REVIEW.ID AS ID, " + + "AP_APP_REVIEW.COMMENT AS COMMENT, " + + "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, " + + "AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, " + + "AP_APP_REVIEW.USERNAME AS USERNAME, " + + "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, " + + "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, " + + "AP_APP_REVIEW.RATING AS RATING, " + + "AP_APP_RELEASE.UUID AS UUID, " + + "AP_APP_RELEASE.VERSION AS VERSION " + + "FROM AP_APP_REVIEW INNER JOIN AP_APP_RELEASE ON " + + "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID " + + "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID = ? AND " + + "AP_APP_REVIEW.ROOT_PARENT_ID = ? AND " + + "AP_APP_REVIEW.TENANT_ID = ? " + + "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + try { + Connection conn = this.getDBConnection(); + try (PreparedStatement statement = conn.prepareStatement(sql)) { + statement.setInt(1, releaseId); + statement.setInt(2, Constants.REVIEW_PARENT_ID); + statement.setInt(3, tenantId); + statement.setInt(4, request.getLimit()); + statement.setInt(5, request.getOffSet()); + try (ResultSet rs = statement.executeQuery()) { + return DAOUtil.loadReviews(rs); + } + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection to get all app release reviews for " + + "application release ID: " + releaseId; + log.error(msg, e); + throw new ReviewManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while executing the SQL statement to get all app release reviews for " + + "application release ID: " + releaseId; + log.error(msg, e); + throw new ReviewManagementDAOException(msg, e); + } + } + + @Override + public List getAllActiveAppReviews(List releaseIds, PaginationRequest request, int tenantId) + throws ReviewManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("DAO request is received to Get all active application reviews."); + } + try { + Connection conn = this.getDBConnection(); + StringJoiner joiner = new StringJoiner(",", + "SELECT " + "AP_APP_REVIEW.ID AS ID, " + + "AP_APP_REVIEW.COMMENT AS COMMENT, " + + "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, " + + "AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, " + + "AP_APP_REVIEW.USERNAME AS USERNAME, " + + "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, " + + "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, " + + "AP_APP_REVIEW.RATING AS RATING, " + + "AP_APP_RELEASE.UUID AS UUID, " + + "AP_APP_RELEASE.VERSION AS VERSION " + + "FROM AP_APP_REVIEW INNER JOIN AP_APP_RELEASE ON " + + "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID " + + "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID IN (", + ") AND AP_APP_REVIEW.ROOT_PARENT_ID = ? AND " + + "AP_APP_REVIEW.ACTIVE_REVIEW = true AND " + + "AP_APP_REVIEW.TENANT_ID = ? " + + "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"); + releaseIds.stream().map(ignored -> "?").forEach(joiner::add); + String query = joiner.toString(); + try (PreparedStatement ps = conn.prepareStatement(query)) { + int index = 1; + for (Integer releaseId : releaseIds) { + ps.setObject(index++, releaseId); + } + ps.setInt(index++, Constants.REVIEW_PARENT_ID); + ps.setInt(index++, tenantId); + ps.setInt(index++, request.getLimit()); + ps.setInt(index, request.getOffSet()); + try (ResultSet rs = ps.executeQuery()) { + return DAOUtil.loadReviews(rs); + } + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection to get all active app reviews."; + log.error(msg, e); + throw new ReviewManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while executing SQL to get all active app reviews."; + log.error(msg, e); + throw new ReviewManagementDAOException(msg, e); + } + } + + @Override + public List getAllActiveAppReviewsOfUser(List releaseIds, PaginationRequest request, + String username, int tenantId) + throws ReviewManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("DAO request is received to Get all active application reviews of user " + username); + } + try { + Connection conn = this.getDBConnection(); + StringJoiner joiner = new StringJoiner(",", + "SELECT " + + "AP_APP_REVIEW.ID AS ID, " + + "AP_APP_REVIEW.COMMENT AS COMMENT, " + + "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, " + + "AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, " + + "AP_APP_REVIEW.USERNAME AS USERNAME, " + + "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, " + + "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, " + + "AP_APP_REVIEW.RATING AS RATING, " + + "AP_APP_RELEASE.UUID AS UUID, " + + "AP_APP_RELEASE.VERSION AS VERSION " + + "FROM AP_APP_REVIEW INNER JOIN AP_APP_RELEASE ON " + + "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID " + + "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID IN (", + ") AND AP_APP_REVIEW.ROOT_PARENT_ID = ? AND " + + "AP_APP_REVIEW.ACTIVE_REVIEW = true AND " + + "AP_APP_REVIEW.USERNAME = ? AND " + + "AP_APP_REVIEW.TENANT_ID = ? " + + "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"); + releaseIds.stream().map(ignored -> "?").forEach(joiner::add); + String query = joiner.toString(); + try (PreparedStatement ps = conn.prepareStatement(query)) { + int index = 1; + for (Integer releaseId : releaseIds) { + ps.setObject(index++, releaseId); + } + ps.setInt(index++, Constants.REVIEW_PARENT_ID); + ps.setString(index++, username); + ps.setInt(index++, tenantId); + ps.setInt(index++, request.getLimit()); + ps.setInt(index, request.getOffSet()); + try (ResultSet rs = ps.executeQuery()) { + return DAOUtil.loadReviews(rs); + } + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection to get all active app reviews of user " + + username; + log.error(msg, e); + throw new ReviewManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while executing SQL to get all active app reviews of user " + username; + log.error(msg, e); + throw new ReviewManagementDAOException(msg, e); + } + } +} 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/review/SQLServerReviewDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/SQLServerReviewDAOImpl.java new file mode 100644 index 0000000000..91182b9e28 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/review/SQLServerReviewDAOImpl.java @@ -0,0 +1,200 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.application.mgt.core.dao.impl.review; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.application.mgt.common.PaginationRequest; +import org.wso2.carbon.device.application.mgt.common.dto.ReviewDTO; +import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; +import org.wso2.carbon.device.application.mgt.core.exception.ReviewManagementDAOException; +import org.wso2.carbon.device.application.mgt.core.util.Constants; +import org.wso2.carbon.device.application.mgt.core.util.DAOUtil; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; +import java.util.StringJoiner; + +/** + * This handles Application Review handling operations which are specific to MsSQL. + */ +public class SQLServerReviewDAOImpl extends GenericReviewDAOImpl { + + private static final Log log = LogFactory.getLog(SQLServerReviewDAOImpl.class); + private String sql; + + @Override + public List getAllReleaseReviews(int releaseId, PaginationRequest request, int tenantId) + throws ReviewManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Getting all application release reviews for the application release ID: " + releaseId); + } + sql = "SELECT " + + "AP_APP_REVIEW.ID AS ID, " + + "AP_APP_REVIEW.COMMENT AS COMMENT, " + + "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, " + + "AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, " + + "AP_APP_REVIEW.USERNAME AS USERNAME, " + + "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, " + + "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, " + + "AP_APP_REVIEW.RATING AS RATING, " + + "AP_APP_RELEASE.UUID AS UUID, " + + "AP_APP_RELEASE.VERSION AS VERSION " + + "FROM AP_APP_REVIEW INNER JOIN AP_APP_RELEASE ON " + + "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID " + + "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID = ? AND " + + "AP_APP_REVIEW.ROOT_PARENT_ID = ? AND " + + "AP_APP_REVIEW.TENANT_ID = ? " + + "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + try { + Connection conn = this.getDBConnection(); + try (PreparedStatement statement = conn.prepareStatement(sql)) { + statement.setInt(1, releaseId); + statement.setInt(2, Constants.REVIEW_PARENT_ID); + statement.setInt(3, tenantId); + statement.setInt(4, request.getLimit()); + statement.setInt(5, request.getOffSet()); + try (ResultSet rs = statement.executeQuery()) { + return DAOUtil.loadReviews(rs); + } + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection to get all app release reviews for " + + "application release ID: " + releaseId; + log.error(msg, e); + throw new ReviewManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while executing the SQL statement to get all app release reviews for " + + "application release ID: " + releaseId; + log.error(msg, e); + throw new ReviewManagementDAOException(msg, e); + } + } + + @Override + public List getAllActiveAppReviews(List releaseIds, PaginationRequest request, int tenantId) + throws ReviewManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("DAO request is received to Get all active application reviews."); + } + try { + Connection conn = this.getDBConnection(); + StringJoiner joiner = new StringJoiner(",", + "SELECT " + "AP_APP_REVIEW.ID AS ID, " + + "AP_APP_REVIEW.COMMENT AS COMMENT, " + + "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, " + + "AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, " + + "AP_APP_REVIEW.USERNAME AS USERNAME, " + + "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, " + + "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, " + + "AP_APP_REVIEW.RATING AS RATING, " + + "AP_APP_RELEASE.UUID AS UUID, " + + "AP_APP_RELEASE.VERSION AS VERSION " + + "FROM AP_APP_REVIEW INNER JOIN AP_APP_RELEASE ON " + + "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID " + + "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID IN (", + ") AND AP_APP_REVIEW.ROOT_PARENT_ID = ? AND " + + "AP_APP_REVIEW.ACTIVE_REVIEW = true AND " + + "AP_APP_REVIEW.TENANT_ID = ? " + + "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"); + releaseIds.stream().map(ignored -> "?").forEach(joiner::add); + String query = joiner.toString(); + try (PreparedStatement ps = conn.prepareStatement(query)) { + int index = 1; + for (Integer releaseId : releaseIds) { + ps.setObject(index++, releaseId); + } + ps.setInt(index++, Constants.REVIEW_PARENT_ID); + ps.setInt(index++, tenantId); + ps.setInt(index++, request.getLimit()); + ps.setInt(index, request.getOffSet()); + try (ResultSet rs = ps.executeQuery()) { + return DAOUtil.loadReviews(rs); + } + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection to get all active app reviews."; + log.error(msg, e); + throw new ReviewManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while executing SQL to get all active app reviews."; + log.error(msg, e); + throw new ReviewManagementDAOException(msg, e); + } + } + + @Override + public List getAllActiveAppReviewsOfUser(List releaseIds, PaginationRequest request, + String username, int tenantId) + throws ReviewManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("DAO request is received to Get all active application reviews of user " + username); + } + try { + Connection conn = this.getDBConnection(); + StringJoiner joiner = new StringJoiner(",", + "SELECT " + + "AP_APP_REVIEW.ID AS ID, " + + "AP_APP_REVIEW.COMMENT AS COMMENT, " + + "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, " + + "AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, " + + "AP_APP_REVIEW.USERNAME AS USERNAME, " + + "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, " + + "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, " + + "AP_APP_REVIEW.RATING AS RATING, " + + "AP_APP_RELEASE.UUID AS UUID, " + + "AP_APP_RELEASE.VERSION AS VERSION " + + "FROM AP_APP_REVIEW INNER JOIN AP_APP_RELEASE ON " + + "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID " + + "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID IN (", + ") AND AP_APP_REVIEW.ROOT_PARENT_ID = ? AND " + + "AP_APP_REVIEW.ACTIVE_REVIEW = true AND " + + "AP_APP_REVIEW.USERNAME = ? AND " + + "AP_APP_REVIEW.TENANT_ID = ? " + + "OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"); + releaseIds.stream().map(ignored -> "?").forEach(joiner::add); + String query = joiner.toString(); + try (PreparedStatement ps = conn.prepareStatement(query)) { + int index = 1; + for (Integer releaseId : releaseIds) { + ps.setObject(index++, releaseId); + } + ps.setInt(index++, Constants.REVIEW_PARENT_ID); + ps.setString(index++, username); + ps.setInt(index++, tenantId); + ps.setInt(index++, request.getLimit()); + ps.setInt(index, request.getOffSet()); + try (ResultSet rs = ps.executeQuery()) { + return DAOUtil.loadReviews(rs); + } + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection to get all active app reviews of user " + + username; + log.error(msg, e); + throw new ReviewManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while executing SQL to get all active app reviews of user " + username; + log.error(msg, e); + throw new ReviewManagementDAOException(msg, e); + } + } +} 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/subscription/GenericSubscriptionDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java index 53c44e73a7..5b137b6253 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java @@ -850,6 +850,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } } + @Override public List getAppSubscribedUsers(int offsetValue, int limitValue, int appReleaseId, int tenantId) throws ApplicationManagementDAOException { @@ -864,12 +865,12 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc + "US.USER_NAME AS USER " + "FROM AP_USER_SUBSCRIPTION US " + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? LIMIT ?,?"; + + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? LIMIT ? OFFSET ?"; try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setInt(1, appReleaseId); stmt.setInt(2, tenantId); - stmt.setInt(3, offsetValue); - stmt.setInt(4, limitValue); + stmt.setInt(3, limitValue); + stmt.setInt(4, offsetValue); try (ResultSet rs = stmt.executeQuery()) { while (rs.next()) { subscribedUsers.add(rs.getString("USER")); @@ -958,6 +959,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } } + @Override public List getAppSubscribedRoles(int offsetValue, int limitValue, int appReleaseId, int tenantId) throws ApplicationManagementDAOException { @@ -972,12 +974,12 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc + "US.ROLE_NAME AS ROLE " + "FROM AP_ROLE_SUBSCRIPTION US " + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? LIMIT ?,?"; + + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? LIMIT ? OFFSET ?"; try (PreparedStatement ps = conn.prepareStatement(sql)) { ps.setInt(1, appReleaseId); ps.setInt(2, tenantId); - ps.setInt(3, offsetValue); - ps.setInt(4, limitValue); + ps.setInt(3, limitValue); + ps.setInt(4, offsetValue); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { subscribedRoles.add(rs.getString("ROLE")); @@ -1052,12 +1054,12 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc + "GS.GROUP_NAME AS GROUPS " + "FROM AP_GROUP_SUBSCRIPTION GS " + "WHERE " - + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? LIMIT ?,?"; + + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? LIMIT ? OFFSET ?"; try (PreparedStatement ps = conn.prepareStatement(sql)) { ps.setInt(1, appReleaseId); ps.setInt(2, tenantId); - ps.setInt(3, offsetValue); - ps.setInt(4, limitValue); + ps.setInt(3, limitValue); + ps.setInt(4, offsetValue); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { subscribedGroups.add(rs.getString("GROUPS")); 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/subscription/OracleSubscriptionDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/OracleSubscriptionDAOImpl.java new file mode 100644 index 0000000000..ffda6ed4c8 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/OracleSubscriptionDAOImpl.java @@ -0,0 +1,159 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.application.mgt.core.dao.impl.subscription; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; +import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +/** + * This handles Application subscribing operations which are specific to Oracle. + */ +public class OracleSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { + + private static Log log = LogFactory.getLog(OracleSubscriptionDAOImpl.class); + + @Override + public List getAppSubscribedUsers(int offsetValue, int limitValue, int appReleaseId, + int tenantId) + throws ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to get already subscribed users for " + + "given app release id."); + } + try { + Connection conn = this.getDBConnection(); + List subscribedUsers = new ArrayList<>(); + String sql = "SELECT " + + "US.USER_NAME AS USER " + + "FROM AP_USER_SUBSCRIPTION US " + + "WHERE " + + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setInt(1, appReleaseId); + stmt.setInt(2, tenantId); + stmt.setInt(3, limitValue); + stmt.setInt(4, offsetValue); + try (ResultSet rs = stmt.executeQuery()) { + while (rs.next()) { + subscribedUsers.add(rs.getString("USER")); + } + } + return subscribedUsers; + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection to get already " + + "subscribed users for given app release id."; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "SQL Error occurred while getting subscribed users for given app release id."; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } + } + + @Override + public List getAppSubscribedRoles(int offsetValue, int limitValue, int appReleaseId, + int tenantId) + throws ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to get already subscribed roles for " + + "given app release id."); + } + try { + Connection conn = this.getDBConnection(); + List subscribedRoles = new ArrayList<>(); + String sql = "SELECT " + + "US.ROLE_NAME AS ROLE " + + "FROM AP_ROLE_SUBSCRIPTION US " + + "WHERE " + + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + try (PreparedStatement ps = conn.prepareStatement(sql)) { + ps.setInt(1, appReleaseId); + ps.setInt(2, tenantId); + ps.setInt(3, limitValue); + ps.setInt(4, offsetValue); + try (ResultSet rs = ps.executeQuery()) { + while (rs.next()) { + subscribedRoles.add(rs.getString("ROLE")); + } + } + return subscribedRoles; + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection to get already " + + "subscribed roles for given app release id."; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "SQL Error occurred while getting subscribed roles for given app release id."; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } + } + + @Override + public List getAppSubscribedGroups(int offsetValue, int limitValue, int appReleaseId, + int tenantId) + throws ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to get already subscribed groups for " + + "given app release id."); + } + try { + Connection conn = this.getDBConnection(); + List subscribedGroups = new ArrayList<>(); + String sql = "SELECT " + + "GS.GROUP_NAME AS GROUPS " + + "FROM AP_GROUP_SUBSCRIPTION GS " + + "WHERE " + + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + try (PreparedStatement ps = conn.prepareStatement(sql)) { + ps.setInt(1, appReleaseId); + ps.setInt(2, tenantId); + ps.setInt(3, limitValue); + ps.setInt(4, offsetValue); + try (ResultSet rs = ps.executeQuery()) { + while (rs.next()) { + subscribedGroups.add(rs.getString("GROUPS")); + } + } + return subscribedGroups; + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection to get already " + + "subscribed groups for given app release id."; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "SQL Error occurred while getting subscribed groups for given " + + "app release id."; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } + } +} 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/subscription/SQLServerSubscriptionDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/SQLServerSubscriptionDAOImpl.java new file mode 100644 index 0000000000..eefa4832ea --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/subscription/SQLServerSubscriptionDAOImpl.java @@ -0,0 +1,159 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.application.mgt.core.dao.impl.subscription; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; +import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +/** + * This handles Application subscribing operations which are specific to MsSQL. + */ +public class SQLServerSubscriptionDAOImpl extends GenericSubscriptionDAOImpl { + + private static Log log = LogFactory.getLog(SQLServerSubscriptionDAOImpl.class); + + @Override + public List getAppSubscribedUsers(int offsetValue, int limitValue, int appReleaseId, + int tenantId) + throws ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to get already subscribed users for " + + "given app release id."); + } + try { + Connection conn = this.getDBConnection(); + List subscribedUsers = new ArrayList<>(); + String sql = "SELECT " + + "US.USER_NAME AS USER " + + "FROM AP_USER_SUBSCRIPTION US " + + "WHERE " + + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setInt(1, appReleaseId); + stmt.setInt(2, tenantId); + stmt.setInt(3, limitValue); + stmt.setInt(4, offsetValue); + try (ResultSet rs = stmt.executeQuery()) { + while (rs.next()) { + subscribedUsers.add(rs.getString("USER")); + } + } + return subscribedUsers; + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection to get already " + + "subscribed users for given app release id."; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "SQL Error occurred while getting subscribed users for given app release id."; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } + } + + @Override + public List getAppSubscribedRoles(int offsetValue, int limitValue, int appReleaseId, + int tenantId) + throws ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to get already subscribed roles for " + + "given app release id."); + } + try { + Connection conn = this.getDBConnection(); + List subscribedRoles = new ArrayList<>(); + String sql = "SELECT " + + "US.ROLE_NAME AS ROLE " + + "FROM AP_ROLE_SUBSCRIPTION US " + + "WHERE " + + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + try (PreparedStatement ps = conn.prepareStatement(sql)) { + ps.setInt(1, appReleaseId); + ps.setInt(2, tenantId); + ps.setInt(3, limitValue); + ps.setInt(4, offsetValue); + try (ResultSet rs = ps.executeQuery()) { + while (rs.next()) { + subscribedRoles.add(rs.getString("ROLE")); + } + } + return subscribedRoles; + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection to get already " + + "subscribed roles for given app release id."; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "SQL Error occurred while getting subscribed roles for given app release id."; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } + } + + @Override + public List getAppSubscribedGroups(int offsetValue, int limitValue, int appReleaseId, + int tenantId) + throws ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to get already subscribed groups for " + + "given app release id."); + } + try { + Connection conn = this.getDBConnection(); + List subscribedGroups = new ArrayList<>(); + String sql = "SELECT " + + "GS.GROUP_NAME AS GROUPS " + + "FROM AP_GROUP_SUBSCRIPTION GS " + + "WHERE " + + "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? OFFSET ? ROWS FETCH NEXT ? ROWS ONLY"; + try (PreparedStatement ps = conn.prepareStatement(sql)) { + ps.setInt(1, appReleaseId); + ps.setInt(2, tenantId); + ps.setInt(3, limitValue); + ps.setInt(4, offsetValue); + try (ResultSet rs = ps.executeQuery()) { + while (rs.next()) { + subscribedGroups.add(rs.getString("GROUPS")); + } + } + return subscribedGroups; + } + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the DB connection to get already " + + "subscribed groups for given app release id."; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "SQL Error occurred while getting subscribed groups for given " + + "app release id."; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } + } +} 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/visibility/OracleVisibilityDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/OracleVisibilityDAOImpl.java new file mode 100644 index 0000000000..8234879598 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/OracleVisibilityDAOImpl.java @@ -0,0 +1,24 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.application.mgt.core.dao.impl.visibility; + +/** + * This handles Application visibility handling operations which are specific to Oracle.. + */ +public class OracleVisibilityDAOImpl extends GenericVisibilityDAOImpl { +} 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/visibility/SQLServerVisibilityDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/SQLServerVisibilityDAOImpl.java new file mode 100644 index 0000000000..3243f24116 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/SQLServerVisibilityDAOImpl.java @@ -0,0 +1,24 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.application.mgt.core.dao.impl.visibility; + +/** + * This handles Application visibility handling operations which are specific to MsSQL. + */ +public class SQLServerVisibilityDAOImpl extends GenericVisibilityDAOImpl { +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java index c52f8a11b0..e467fac0cf 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/device/OracleDeviceDAOImpl.java @@ -21,8 +21,6 @@ package org.wso2.carbon.device.mgt.core.dao.impl.device; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.PaginationRequest; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml index 6a6cfead86..44aa0ed051 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml @@ -317,7 +317,7 @@ - https + http /api/application-mgt/v1.0/artifact