forked from community/device-mgt-core
Add MsSQL and Oracle support for APPM See merge request entgra/carbon-device-mgt!314feature/appm-store/pbac
commit
8505d65b55
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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{
|
||||||
|
}
|
4
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 → 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
4
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 → 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
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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 {
|
||||||
|
}
|
Loading…
Reference in new issue