mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'application-mgt-new' into 'application-mgt-new'
Add MsSQL and Oracle support for APPM See merge request entgra/carbon-device-mgt!314
This commit is contained in:
commit
8505d65b55
@ -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,24 +169,10 @@ public class ApplicationManagementDAOFactory {
|
||||
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
|
||||
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
|
||||
return new GenericSubscriptionDAOImpl();
|
||||
default:
|
||||
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
|
||||
}
|
||||
}
|
||||
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();
|
||||
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);
|
||||
}
|
||||
@ -179,43 +186,15 @@ public class ApplicationManagementDAOFactory {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
|
||||
|
||||
@ -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<ApplicationDTO> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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<ApplicationDTO> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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 {
|
||||
}
|
||||
@ -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 {
|
||||
}
|
||||
@ -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{
|
||||
}
|
||||
@ -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{
|
||||
}
|
||||
@ -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
|
||||
@ -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<ReviewDTO> 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<ReviewDTO> getAllActiveAppReviews(List<Integer> 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<ReviewDTO> getAllActiveAppReviewsOfUser(List<Integer> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<ReviewDTO> 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<ReviewDTO> getAllActiveAppReviews(List<Integer> 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<ReviewDTO> getAllActiveAppReviewsOfUser(List<Integer> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -850,6 +850,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> 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<String> 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"));
|
||||
|
||||
@ -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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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<String> 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<String> 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<String> 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<String> 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<String> 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<String> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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 {
|
||||
}
|
||||
@ -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 {
|
||||
}
|
||||
@ -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;
|
||||
|
||||
@ -317,7 +317,7 @@
|
||||
</RatingConfig>
|
||||
|
||||
<MDMConfig>
|
||||
<ArtifactDownloadProtocol>https</ArtifactDownloadProtocol>
|
||||
<ArtifactDownloadProtocol>http</ArtifactDownloadProtocol>
|
||||
<ArtifactDownloadEndpoint>/api/application-mgt/v1.0/artifact</ArtifactDownloadEndpoint>
|
||||
</MDMConfig>
|
||||
</ApplicationManagementConfiguration>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user