|
|
@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory;
|
|
|
|
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
|
|
|
|
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.dto.ReviewDTO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.ReviewDAO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.dao.ReviewDAO;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
|
|
|
@ -52,7 +51,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
private String sql;
|
|
|
|
private String sql;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public boolean addReview(ReviewDTO reviewDTO, int appReleaseId, int tenantId) throws ReviewManagementDAOException {
|
|
|
|
public int addReview(ReviewDTO reviewDTO, int appReleaseId, int tenantId) throws ReviewManagementDAOException {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Request received in DAO Layer to add review for application release. Application Release UUID: "
|
|
|
|
log.debug("Request received in DAO Layer to add review for application release. Application Release UUID: "
|
|
|
|
+ appReleaseId);
|
|
|
|
+ appReleaseId);
|
|
|
@ -69,11 +68,11 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
+ "AP_APP_RELEASE_ID) "
|
|
|
|
+ "AP_APP_RELEASE_ID) "
|
|
|
|
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ? )";
|
|
|
|
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ? )";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
|
|
|
|
int reviewId = -1;
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
|
|
|
|
Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
try (PreparedStatement statement = conn.prepareStatement(sql, new String[] { "id" });) {
|
|
|
|
try (PreparedStatement statement = conn.prepareStatement(sql, new String[] { "id" })) {
|
|
|
|
statement.setInt(1, tenantId);
|
|
|
|
statement.setInt(1, tenantId);
|
|
|
|
statement.setString(2, reviewDTO.getContent());
|
|
|
|
statement.setString(2, reviewDTO.getContent());
|
|
|
|
statement.setInt(3, reviewDTO.getRootParentId());
|
|
|
|
statement.setInt(3, reviewDTO.getRootParentId());
|
|
|
@ -85,16 +84,22 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
statement.setInt(9, appReleaseId);
|
|
|
|
statement.setInt(9, appReleaseId);
|
|
|
|
statement.executeUpdate();
|
|
|
|
statement.executeUpdate();
|
|
|
|
try (ResultSet rs = statement.getGeneratedKeys()) {
|
|
|
|
try (ResultSet rs = statement.getGeneratedKeys()) {
|
|
|
|
return rs.next();
|
|
|
|
if (rs.next()) {
|
|
|
|
|
|
|
|
reviewId = rs.getInt(1);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return reviewId;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new ReviewManagementDAOException("Error occurred while obtaining the DB connection while "
|
|
|
|
String msg = "Error occurred while obtaining the DB connection to add a review for application release which"
|
|
|
|
+ "adding review for application release which has ID: "+ appReleaseId + "Tenant Id: " + tenantId, e);
|
|
|
|
+ " has ID: "+ appReleaseId + " and Tenant Id: " + tenantId;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
String msg = "Error occurred while executing SQL statement to add application review. Application ID: "
|
|
|
|
"Error occurred while executing SQL statement to add application review. Application ID: "
|
|
|
|
+ appReleaseId + " and tenant " + tenantId;
|
|
|
|
+ appReleaseId + " tenant " + tenantId, e);
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -102,19 +107,18 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
public boolean hasUerReviewedApp(List<Integer> appReleaseIds, String username, int tenantId)
|
|
|
|
public boolean hasUerReviewedApp(List<Integer> appReleaseIds, String username, int tenantId)
|
|
|
|
throws ReviewManagementDAOException {
|
|
|
|
throws ReviewManagementDAOException {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Request received in DAO Layer to check whether user have already reviewed or not for the "
|
|
|
|
log.debug("Request received to DAO Layer to check whether user have already reviewed or not for the "
|
|
|
|
+ "application. Commenting user: " + username + " and tenant-id: " + tenantId);
|
|
|
|
+ "application. Commenting user: " + username + " and tenant-id: " + tenantId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
int index = 1;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
StringJoiner joiner = new StringJoiner(",",
|
|
|
|
StringJoiner joiner = new StringJoiner(",",
|
|
|
|
"SELECT rv.ID FROM AP_APP_REVIEW rv WHERE rv.AP_APP_RELEASE_ID IN (",
|
|
|
|
"SELECT rv.ID FROM AP_APP_REVIEW rv WHERE rv.AP_APP_RELEASE_ID IN (",
|
|
|
|
") AND rv.USERNAME = ? AND rv.TENANT_ID = ?");
|
|
|
|
") AND rv.USERNAME = ? AND rv.TENANT_ID = ?");
|
|
|
|
appReleaseIds.stream().map(ignored -> "?").forEach(joiner::add);
|
|
|
|
appReleaseIds.stream().map(ignored -> "?").forEach(joiner::add);
|
|
|
|
String query = joiner.toString();
|
|
|
|
String query = joiner.toString();
|
|
|
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
|
|
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
|
|
|
|
|
|
|
int index = 1;
|
|
|
|
for (Integer deviceId : appReleaseIds) {
|
|
|
|
for (Integer deviceId : appReleaseIds) {
|
|
|
|
ps.setObject(index++, deviceId);
|
|
|
|
ps.setObject(index++, deviceId);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -124,25 +128,25 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
return rs.next();
|
|
|
|
return rs.next();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException("Error occured while accessing the Database when checking whether "
|
|
|
|
|
|
|
|
+ "user has already commented for the application ro not", e);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new ReviewManagementDAOException("Error occured while getting the database connection when checking "
|
|
|
|
String msg = "Error occured while getting the database connection when checking whether user has already "
|
|
|
|
+ "whether user has already commented for the application ro not", e);
|
|
|
|
+ "commented for the application or not";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occured while executing the SQL statement to check whether user has already commented "
|
|
|
|
|
|
|
|
+ "for the application or not";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int updateReview(ReviewDTO reviewDTO, int reviewId, boolean isActiveReview, int tenantId)
|
|
|
|
public int updateReview(ReviewDTO reviewDTO, int reviewId, boolean isActiveReview, int tenantId)
|
|
|
|
throws ReviewManagementDAOException {
|
|
|
|
throws ReviewManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Request received in DAO Layer to update the Review with ID (" + reviewId + ")");
|
|
|
|
log.debug("Request received to DAO Layer to update the Review which has ID " + reviewId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Connection connection;
|
|
|
|
|
|
|
|
PreparedStatement statement = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
sql = "UPDATE "
|
|
|
|
sql = "UPDATE "
|
|
|
|
+ "AP_APP_REVIEW "
|
|
|
|
+ "AP_APP_REVIEW "
|
|
|
|
+ "SET "
|
|
|
|
+ "SET "
|
|
|
@ -150,109 +154,73 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
+ "RATING = ?, "
|
|
|
|
+ "RATING = ?, "
|
|
|
|
+ "MODIFIED_AT = ?, "
|
|
|
|
+ "MODIFIED_AT = ?, "
|
|
|
|
+ "ACTIVE_REVIEW = ? "
|
|
|
|
+ "ACTIVE_REVIEW = ? "
|
|
|
|
+ "WHERE ID = ? AND "
|
|
|
|
+ "WHERE ID = ? AND TENANT_ID = ?";
|
|
|
|
+ "TENANT_ID = ?";
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
|
|
|
|
Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
|
|
|
|
|
|
|
|
|
|
|
|
connection = this.getDBConnection();
|
|
|
|
Connection connection = this.getDBConnection();
|
|
|
|
statement = connection.prepareStatement(sql);
|
|
|
|
try (PreparedStatement statement = connection.prepareStatement(sql)){
|
|
|
|
statement.setString(1, reviewDTO.getContent());
|
|
|
|
statement.setString(1, reviewDTO.getContent());
|
|
|
|
statement.setInt(2, reviewDTO.getRating());
|
|
|
|
statement.setInt(2, reviewDTO.getRating());
|
|
|
|
statement.setTimestamp(3, timestamp);
|
|
|
|
statement.setTimestamp(3, timestamp);
|
|
|
|
statement.setBoolean(4, isActiveReview);
|
|
|
|
statement.setBoolean(4, isActiveReview);
|
|
|
|
statement.setInt(5, reviewId);
|
|
|
|
statement.setInt(5, reviewId);
|
|
|
|
statement.setInt(6, tenantId);
|
|
|
|
statement.setInt(6, tenantId);
|
|
|
|
return statement.executeUpdate();
|
|
|
|
return statement.executeUpdate();
|
|
|
|
} catch (SQLException e) {
|
|
|
|
}
|
|
|
|
throw new ReviewManagementDAOException("Error occurred while executing reviewTmp updating query");
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new ReviewManagementDAOException("Error occured while getting the db connection to update reviewTmp");
|
|
|
|
String msg = "Error occured while getting the db connection to update review for review ID: " + reviewId;
|
|
|
|
} finally {
|
|
|
|
log.error(msg);
|
|
|
|
DAOUtil.cleanupResources(statement, rs);
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public ReviewDTO getReview(int reviewId) throws ReviewManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("Getting reviewDTO with the review id(" + reviewId + ") from the database");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
PreparedStatement statement = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
|
|
|
|
sql = "SELECT "
|
|
|
|
|
|
|
|
+ "AP_APP_REVIEW.ID AS ID, "
|
|
|
|
|
|
|
|
+ "AP_APP_REVIEW.COMMENT AS COMMENT, "
|
|
|
|
|
|
|
|
+ "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, "
|
|
|
|
|
|
|
|
+ "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, "
|
|
|
|
|
|
|
|
+ "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, "
|
|
|
|
|
|
|
|
+ "AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, "
|
|
|
|
|
|
|
|
+ "AP_APP_REVIEW.RATING AS RATING, "
|
|
|
|
|
|
|
|
+ "AP_APP_REVIEW.USERNAME AS USERNAME, "
|
|
|
|
|
|
|
|
+ "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.ID = ?";
|
|
|
|
|
|
|
|
statement = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
statement.setInt(1, reviewId);
|
|
|
|
|
|
|
|
rs = statement.executeQuery();
|
|
|
|
|
|
|
|
return DAOUtil.loadReview(rs);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
String msg = "Error occurred while executing review updating query for review ID: " + reviewId;
|
|
|
|
"SQL Error occurred while retrieving information of the reviewTmp " + reviewId, e);
|
|
|
|
log.error(msg);
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
|
|
|
|
"DB Connection Exception occurred while retrieving information of the reviewTmp " + reviewId, e);
|
|
|
|
|
|
|
|
} catch (UnexpectedServerErrorException e) {
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException("Found more than one review for review ID: " + reviewId, e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
DAOUtil.cleanupResources(statement, rs);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public ReviewDTO getReview(int appReleaseId, int reviewId) throws ReviewManagementDAOException {
|
|
|
|
public ReviewDTO getReview(int reviewId, int tenantId) throws ReviewManagementDAOException {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Getting reviewDTO with the review id(" + reviewId + ") from the database");
|
|
|
|
log.debug("Request received to DAO Layer to get review for review ID: " + reviewId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Connection conn;
|
|
|
|
sql = "SELECT "
|
|
|
|
PreparedStatement statement = null;
|
|
|
|
+ "AP_APP_REVIEW.ID AS ID, "
|
|
|
|
ResultSet rs = null;
|
|
|
|
+ "AP_APP_REVIEW.COMMENT AS COMMENT, "
|
|
|
|
|
|
|
|
+ "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, "
|
|
|
|
|
|
|
|
+ "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, "
|
|
|
|
|
|
|
|
+ "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, "
|
|
|
|
|
|
|
|
+ "AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, "
|
|
|
|
|
|
|
|
+ "AP_APP_REVIEW.RATING AS RATING, "
|
|
|
|
|
|
|
|
+ "AP_APP_REVIEW.USERNAME AS USERNAME, "
|
|
|
|
|
|
|
|
+ "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.ID = ? AND AP_APP_REVIEW.TENANT_ID = ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
sql = "SELECT "
|
|
|
|
try (PreparedStatement statement = conn.prepareStatement(sql)) {
|
|
|
|
+ "ID, "
|
|
|
|
statement.setInt(1, reviewId);
|
|
|
|
+ "COMMENT,"
|
|
|
|
statement.setInt(2, tenantId);
|
|
|
|
+ "ROOT_PARENT_ID,"
|
|
|
|
try (ResultSet rs = statement.executeQuery()) {
|
|
|
|
+ "IMMEDIATE_PARENT_ID, "
|
|
|
|
return DAOUtil.loadReview(rs);
|
|
|
|
+ "CREATED_AT, "
|
|
|
|
}
|
|
|
|
+ "MODIFIED_AT, "
|
|
|
|
}
|
|
|
|
+ "RATING, "
|
|
|
|
|
|
|
|
+ "USERNAME "
|
|
|
|
|
|
|
|
+ "FROM AP_APP_REVIEW "
|
|
|
|
|
|
|
|
+ "WHERE ID = ? AND "
|
|
|
|
|
|
|
|
+ "AP_APP_RELEASE_ID = ?";
|
|
|
|
|
|
|
|
statement = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
statement.setInt(1, reviewId);
|
|
|
|
|
|
|
|
statement.setInt(2, appReleaseId);
|
|
|
|
|
|
|
|
rs = statement.executeQuery();
|
|
|
|
|
|
|
|
return DAOUtil.loadReview(rs);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
|
|
|
|
"SQL Error occurred while retrieving information of the reviewTmp " + reviewId, e);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
String msg = "DB Connection Exception occurred while retrieving information of the review for review ID: "
|
|
|
|
"DB Connection Exception occurred while retrieving information of the reviewTmp " + reviewId, e);
|
|
|
|
+ reviewId;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occured while executing SQL statement to get review data for review ID: " + reviewId;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
} catch (UnexpectedServerErrorException e) {
|
|
|
|
} catch (UnexpectedServerErrorException e) {
|
|
|
|
throw new ReviewManagementDAOException("Found more than one review for review ID: " + reviewId, e);
|
|
|
|
String msg = "Found more than one review for review ID: " + reviewId;
|
|
|
|
} finally {
|
|
|
|
log.error(msg);
|
|
|
|
DAOUtil.cleanupResources(statement, rs);
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -260,31 +228,28 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<ReviewDTO> getAllReleaseReviews(int releaseId, PaginationRequest request, int tenantId)
|
|
|
|
public List<ReviewDTO> getAllReleaseReviews(int releaseId, PaginationRequest request, int tenantId)
|
|
|
|
throws ReviewManagementDAOException {
|
|
|
|
throws ReviewManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Getting comment of the application release (" + releaseId + ") from the database");
|
|
|
|
log.debug("Getting all application release reviews for the application release ID: " + releaseId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Connection conn;
|
|
|
|
sql = "SELECT "
|
|
|
|
List<ReviewDTO> reviewDTOs;
|
|
|
|
+ "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 = ? "
|
|
|
|
|
|
|
|
+ "LIMIT ? OFFSET ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
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 = ? "
|
|
|
|
|
|
|
|
+ "LIMIT ? OFFSET ?";
|
|
|
|
|
|
|
|
try (PreparedStatement statement = conn.prepareStatement(sql)) {
|
|
|
|
try (PreparedStatement statement = conn.prepareStatement(sql)) {
|
|
|
|
statement.setInt(1, releaseId);
|
|
|
|
statement.setInt(1, releaseId);
|
|
|
|
statement.setInt(2, Constants.REVIEW_PARENT_ID);
|
|
|
|
statement.setInt(2, Constants.REVIEW_PARENT_ID);
|
|
|
@ -292,86 +257,83 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
statement.setInt(4, request.getLimit());
|
|
|
|
statement.setInt(4, request.getLimit());
|
|
|
|
statement.setInt(5, request.getOffSet());
|
|
|
|
statement.setInt(5, request.getOffSet());
|
|
|
|
try (ResultSet rs = statement.executeQuery()) {
|
|
|
|
try (ResultSet rs = statement.executeQuery()) {
|
|
|
|
reviewDTOs = DAOUtil.loadReviews(rs);
|
|
|
|
return DAOUtil.loadReviews(rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
String msg = "Error occurred while obtaining the DB connection to get all app release reviews for "
|
|
|
|
"Error occurred while obtaining the DB connection when verifying application existence", e);
|
|
|
|
+ "application release ID: " + releaseId;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new ReviewManagementDAOException("DB connection error occurred while getting all reviewTmps", e);
|
|
|
|
String msg = "Error occurred while executing the SQL statement to get all app release reviews for "
|
|
|
|
} return reviewDTOs;
|
|
|
|
+ "application release ID: " + releaseId;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<ReviewDTO> getAllActiveAppReviews(List<Integer> releaseIds, PaginationRequest request, int tenantId)
|
|
|
|
public List<ReviewDTO> getAllActiveAppReviews(List<Integer> releaseIds, PaginationRequest request, int tenantId)
|
|
|
|
throws ReviewManagementDAOException {
|
|
|
|
throws ReviewManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Getting reviews of the application from the database.");
|
|
|
|
log.debug("DAO request is received to Get all active application reviews.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Connection conn;
|
|
|
|
try {
|
|
|
|
List<ReviewDTO> reviewDTOs;
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
int index = 1;
|
|
|
|
StringJoiner joiner = new StringJoiner(",",
|
|
|
|
|
|
|
|
"SELECT " + "AP_APP_REVIEW.ID AS ID, "
|
|
|
|
try {
|
|
|
|
+ "AP_APP_REVIEW.COMMENT AS COMMENT, "
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
+ "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, "
|
|
|
|
StringJoiner joiner = new StringJoiner(",",
|
|
|
|
+ "AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, "
|
|
|
|
"SELECT "
|
|
|
|
+ "AP_APP_REVIEW.USERNAME AS USERNAME, "
|
|
|
|
+ "AP_APP_REVIEW.ID AS ID, "
|
|
|
|
+ "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, "
|
|
|
|
+ "AP_APP_REVIEW.COMMENT AS COMMENT, "
|
|
|
|
+ "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, "
|
|
|
|
+ "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, "
|
|
|
|
+ "AP_APP_REVIEW.RATING AS RATING, "
|
|
|
|
+ "AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, "
|
|
|
|
+ "AP_APP_RELEASE.UUID AS UUID, "
|
|
|
|
+ "AP_APP_REVIEW.USERNAME AS USERNAME, "
|
|
|
|
+ "AP_APP_RELEASE.VERSION AS VERSION "
|
|
|
|
+ "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, "
|
|
|
|
+ "FROM AP_APP_REVIEW INNER JOIN AP_APP_RELEASE ON "
|
|
|
|
+ "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, "
|
|
|
|
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID "
|
|
|
|
+ "AP_APP_REVIEW.RATING AS RATING, "
|
|
|
|
+ "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID IN (",
|
|
|
|
+ "AP_APP_RELEASE.UUID AS UUID, "
|
|
|
|
") AND AP_APP_REVIEW.ROOT_PARENT_ID = ? AND "
|
|
|
|
+ "AP_APP_RELEASE.VERSION AS VERSION "
|
|
|
|
+ "AP_APP_REVIEW.ACTIVE_REVIEW = true AND "
|
|
|
|
+ "FROM AP_APP_REVIEW INNER JOIN AP_APP_RELEASE ON "
|
|
|
|
+ "AP_APP_REVIEW.TENANT_ID = ? "
|
|
|
|
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID "
|
|
|
|
+ "LIMIT ? OFFSET ?");
|
|
|
|
+ "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID IN (",
|
|
|
|
releaseIds.stream().map(ignored -> "?").forEach(joiner::add);
|
|
|
|
") AND AP_APP_REVIEW.ROOT_PARENT_ID = ? AND "
|
|
|
|
String query = joiner.toString();
|
|
|
|
+ "AP_APP_REVIEW.ACTIVE_REVIEW = true AND "
|
|
|
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
|
|
|
+ "AP_APP_REVIEW.TENANT_ID = ? "
|
|
|
|
int index = 1;
|
|
|
|
+ "LIMIT ? OFFSET ?");
|
|
|
|
for (Integer releaseId : releaseIds) {
|
|
|
|
releaseIds.stream().map(ignored -> "?").forEach(joiner::add);
|
|
|
|
ps.setObject(index++, releaseId);
|
|
|
|
String query = joiner.toString();
|
|
|
|
}
|
|
|
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
|
|
|
ps.setInt(index++, Constants.REVIEW_PARENT_ID);
|
|
|
|
for (Integer releaseId : releaseIds) {
|
|
|
|
ps.setInt(index++, tenantId);
|
|
|
|
ps.setObject(index++, releaseId);
|
|
|
|
ps.setInt(index++, request.getLimit());
|
|
|
|
}
|
|
|
|
ps.setInt(index, request.getOffSet());
|
|
|
|
ps.setInt(index++, Constants.REVIEW_PARENT_ID);
|
|
|
|
try (ResultSet rs = ps.executeQuery()) {
|
|
|
|
ps.setInt(index++, tenantId);
|
|
|
|
return DAOUtil.loadReviews(rs);
|
|
|
|
ps.setInt(index++, request.getLimit());
|
|
|
|
|
|
|
|
ps.setInt(index, request.getOffSet());
|
|
|
|
|
|
|
|
try (ResultSet rs = ps.executeQuery()) {
|
|
|
|
|
|
|
|
reviewDTOs = DAOUtil.loadReviews(rs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
String msg = "Error occurred while obtaining the DB connection to get all active app reviews.";
|
|
|
|
"Error occurred while obtaining the DB connection when verifying application existence.", e);
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new ReviewManagementDAOException("DB connection error occurred while getting all reviews.", e);
|
|
|
|
String msg = "Error occurred while executing SQL to get all active app reviews.";
|
|
|
|
} return reviewDTOs;
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<ReviewDTO> getAllActiveAppReviewsOfUser(List<Integer> releaseIds, PaginationRequest request,
|
|
|
|
public List<ReviewDTO> getAllActiveAppReviewsOfUser(List<Integer> releaseIds, PaginationRequest request,
|
|
|
|
String username, int tenantId)
|
|
|
|
String username, int tenantId)
|
|
|
|
throws ReviewManagementDAOException {
|
|
|
|
throws ReviewManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Getting reviews of the application for given user from the database.");
|
|
|
|
log.debug("DAO request is received to Get all active application reviews of user " + username);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
List<ReviewDTO> reviewDTOs;
|
|
|
|
|
|
|
|
int index = 1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
StringJoiner joiner = new StringJoiner(",",
|
|
|
|
StringJoiner joiner = new StringJoiner(",",
|
|
|
|
"SELECT "
|
|
|
|
"SELECT "
|
|
|
|
+ "AP_APP_REVIEW.ID AS ID, "
|
|
|
|
+ "AP_APP_REVIEW.ID AS ID, "
|
|
|
@ -395,6 +357,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
releaseIds.stream().map(ignored -> "?").forEach(joiner::add);
|
|
|
|
releaseIds.stream().map(ignored -> "?").forEach(joiner::add);
|
|
|
|
String query = joiner.toString();
|
|
|
|
String query = joiner.toString();
|
|
|
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
|
|
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
|
|
|
|
|
|
|
int index = 1;
|
|
|
|
for (Integer releaseId : releaseIds) {
|
|
|
|
for (Integer releaseId : releaseIds) {
|
|
|
|
ps.setObject(index++, releaseId);
|
|
|
|
ps.setObject(index++, releaseId);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -404,29 +367,28 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
ps.setInt(index++, request.getLimit());
|
|
|
|
ps.setInt(index++, request.getLimit());
|
|
|
|
ps.setInt(index, request.getOffSet());
|
|
|
|
ps.setInt(index, request.getOffSet());
|
|
|
|
try (ResultSet rs = ps.executeQuery()) {
|
|
|
|
try (ResultSet rs = ps.executeQuery()) {
|
|
|
|
reviewDTOs = DAOUtil.loadReviews(rs);
|
|
|
|
return DAOUtil.loadReviews(rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
catch (DBConnectionException e) {
|
|
|
|
String msg = "Error occurred while obtaining the DB connection to get all active app reviews of user "
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
+ username;
|
|
|
|
"Error occurred while obtaining the DB connection when application review of user: " + username , e);
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new ReviewManagementDAOException("DB connection error occurred while getting application reviews of "
|
|
|
|
String msg = "Error occurred while executing SQL to get all active app reviews of user " + username;
|
|
|
|
+ "user:" + username, e);
|
|
|
|
log.error(msg);
|
|
|
|
} return reviewDTOs;
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<ReviewDTO> getReplyComments(int parentId, int tenantId) throws ReviewManagementDAOException {
|
|
|
|
public List<ReviewDTO> getReplyComments(int parentId, int tenantId) throws ReviewManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Getting comment of the application release (" + parentId + ") from the database");
|
|
|
|
log.debug("Getting all reply comments for review which has review ID: " + parentId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
List<ReviewDTO> reviewDTOs;
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
sql = "SELECT "
|
|
|
|
sql = "SELECT "
|
|
|
|
+ "AP_APP_REVIEW.ID AS ID, "
|
|
|
|
+ "AP_APP_REVIEW.ID AS ID, "
|
|
|
|
+ "AP_APP_REVIEW.COMMENT AS COMMENT, "
|
|
|
|
+ "AP_APP_REVIEW.COMMENT AS COMMENT, "
|
|
|
@ -446,66 +408,70 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
try (PreparedStatement statement = conn.prepareStatement(sql)) {
|
|
|
|
try (PreparedStatement statement = conn.prepareStatement(sql)) {
|
|
|
|
statement.setInt(1, parentId);
|
|
|
|
statement.setInt(1, parentId);
|
|
|
|
statement.setInt(2, tenantId);
|
|
|
|
statement.setInt(2, tenantId);
|
|
|
|
try (ResultSet rs = statement.executeQuery();) {
|
|
|
|
try (ResultSet rs = statement.executeQuery()) {
|
|
|
|
reviewDTOs = DAOUtil.loadReviews(rs);
|
|
|
|
return DAOUtil.loadReviews(rs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
String msg = "Error occurred while obtaining the DB connection when getting reply comments for a review "
|
|
|
|
"Error occurred while obtaining the DB connection when getting reply comments for a review.", e);
|
|
|
|
+ "which has reviw ID: " + parentId;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new ReviewManagementDAOException("DB connection error occurred while getting reply comments", e);
|
|
|
|
String msg = "Error occurred while executing SQL to ge reply comments for a review which has reviw ID: "
|
|
|
|
|
|
|
|
+ parentId;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reviewDTOs;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Integer> getAllAppReleaseRatingValues(String uuid, int tenantId) throws ReviewManagementDAOException {
|
|
|
|
public List<Integer> getAllAppReleaseRatingValues(String uuid, int tenantId) throws ReviewManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Getting comment of the application release (" + uuid + ") from the database");
|
|
|
|
log.debug("Getting all app release rating values for app release UUID: " + uuid);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Connection conn;
|
|
|
|
sql = "SELECT "
|
|
|
|
PreparedStatement statement = null;
|
|
|
|
+ "AP_APP_REVIEW.RATING AS RATING "
|
|
|
|
ResultSet rs = null;
|
|
|
|
+ "FROM AP_APP_REVIEW, AP_APP_RELEASE "
|
|
|
|
List<Integer> reviews = new ArrayList<>();
|
|
|
|
+ "WHERE "
|
|
|
|
|
|
|
|
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID AND "
|
|
|
|
|
|
|
|
+ "AP_APP_RELEASE.UUID = ? AND "
|
|
|
|
|
|
|
|
+ "AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID AND "
|
|
|
|
|
|
|
|
+ "AP_APP_REVIEW.TENANT_ID = ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
sql = "SELECT AP_APP_REVIEW.RATING AS RATING FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE "
|
|
|
|
try (PreparedStatement statement = conn.prepareStatement(sql)) {
|
|
|
|
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_RELEASE.UUID =? AND "
|
|
|
|
statement.setString(1, uuid);
|
|
|
|
+ "AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID AND AP_APP_REVIEW.TENANT_ID = ?";
|
|
|
|
statement.setInt(2, tenantId);
|
|
|
|
statement = conn.prepareStatement(sql);
|
|
|
|
try (ResultSet rs = statement.executeQuery()) {
|
|
|
|
statement.setString(1, uuid);
|
|
|
|
List<Integer> reviews = new ArrayList<>();
|
|
|
|
statement.setInt(2, tenantId);
|
|
|
|
while (rs.next()) {
|
|
|
|
rs = statement.executeQuery();
|
|
|
|
reviews.add(rs.getInt("RATING"));
|
|
|
|
while (rs.next()) {
|
|
|
|
}
|
|
|
|
reviews.add(rs.getInt("RATING"));
|
|
|
|
return reviews;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
|
|
|
|
"Error occured while getting all rating values for the application release. App release UUID: "
|
|
|
|
|
|
|
|
+ uuid, e);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
String msg = "Error occured while getting DB connection to retrieve all rating values for the application "
|
|
|
|
"Error occured while getting DB connection to retrieve all rating values for the application release. App release UUID: "
|
|
|
|
+ "release which has UUID:" + uuid;
|
|
|
|
+ uuid, e);
|
|
|
|
log.error(msg);
|
|
|
|
} finally {
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
DAOUtil.cleanupResources(statement, rs);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occured while executing SQL to retrieve all rating values for the application release "
|
|
|
|
|
|
|
|
+ "which has UUID:" + uuid;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reviews;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Integer> getAllAppRatingValues(List<String> uuids, int tenantId) throws ReviewManagementDAOException {
|
|
|
|
public List<Integer> getAllAppRatingValues(List<String> uuids, int tenantId) throws ReviewManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Getting rating values of the application from the database");
|
|
|
|
log.debug("DAO request is received to Get all application rating values of an application.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
List<Integer> reviews = new ArrayList<>();
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
int index = 1;
|
|
|
|
int index = 1;
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
StringJoiner joiner = new StringJoiner(",",
|
|
|
|
StringJoiner joiner = new StringJoiner(",",
|
|
|
|
"SELECT AP_APP_REVIEW.RATING AS RATING FROM AP_APP_REVIEW INNER JOIN AP_APP_RELEASE ON "
|
|
|
|
"SELECT AP_APP_REVIEW.RATING AS RATING FROM AP_APP_REVIEW INNER JOIN AP_APP_RELEASE ON "
|
|
|
|
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID WHERE AP_APP_RELEASE.UUID IN (",
|
|
|
|
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID WHERE AP_APP_RELEASE.UUID IN (",
|
|
|
@ -518,88 +484,31 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ps.setInt(index, tenantId);
|
|
|
|
ps.setInt(index, tenantId);
|
|
|
|
try (ResultSet rs = ps.executeQuery()) {
|
|
|
|
try (ResultSet rs = ps.executeQuery()) {
|
|
|
|
|
|
|
|
List<Integer> reviews = new ArrayList<>();
|
|
|
|
while (rs.next()) {
|
|
|
|
while (rs.next()) {
|
|
|
|
reviews.add(rs.getInt("RATING"));
|
|
|
|
reviews.add(rs.getInt("RATING"));
|
|
|
|
} }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return reviews;
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
|
|
|
|
"Error occured while getting all rating values for the application.", e);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
|
|
|
|
"Error occured while getting DB connection to retrieve all rating values for the application.", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return reviews;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public int getReviewCount(String uuid) throws ReviewManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int commentCount = 0;
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
PreparedStatement statement = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
boolean isUuidProvided = false;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
|
|
|
|
if (uuid != null) {
|
|
|
|
|
|
|
|
isUuidProvided = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isUuidProvided) {
|
|
|
|
|
|
|
|
sql = "SELECT COUNT(AP_APP_REVIEW.ID) AS REVIEW_COUNT FROM AP_APP_REVIEW,AP_APP_RELEASE "
|
|
|
|
|
|
|
|
+ "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID= AP_APP_RELEASE.ID AND "
|
|
|
|
|
|
|
|
+ "AP_APP_REVIEW.AP_APP_ID= AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;";
|
|
|
|
|
|
|
|
statement = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
statement.setString(1, uuid);
|
|
|
|
|
|
|
|
rs = statement.executeQuery();
|
|
|
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
|
|
|
commentCount = rs.getInt("REVIEW_COUNT");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException("SQL Error occurred while retrieving review counts", e);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new ReviewManagementDAOException("DB Connection Exception occurred while retrieving review counts", e);
|
|
|
|
String msg = "Error occured while getting DB connection to retrieve all rating values for an application.";
|
|
|
|
} finally {
|
|
|
|
log.error(msg);
|
|
|
|
DAOUtil.cleanupResources(statement, rs);
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
return commentCount;
|
|
|
|
String msg = "Error occured while executing SQL to get all rating values for the application.";
|
|
|
|
}
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public int getReviewCountByApp(String appType, String appName, String version)
|
|
|
|
|
|
|
|
throws ReviewManagementException, DBConnectionException, SQLException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
PreparedStatement statement = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
int commentCount = 0;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
//todo need to reconstruct the query
|
|
|
|
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
|
|
|
|
sql = "SELECT COUNT(ID) AS COMMENT_COUNT FROM AP_APP_COMMENT C, "
|
|
|
|
|
|
|
|
+ "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=? )R,"
|
|
|
|
|
|
|
|
+ "(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? and TYPE=?)P "
|
|
|
|
|
|
|
|
+ "WHERE AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND AP_APP_ID=RELEASE_AP_APP_ID;";
|
|
|
|
|
|
|
|
statement = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
statement.setString(1, version);
|
|
|
|
|
|
|
|
statement.setString(2, appName);
|
|
|
|
|
|
|
|
statement.setString(3, appType);
|
|
|
|
|
|
|
|
rs = statement.executeQuery();
|
|
|
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
|
|
|
commentCount = rs.getInt("COMMENT_COUNT");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
DAOUtil.cleanupResources(statement, rs);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return commentCount;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void deleteReview(int reviewId, int tenantId) throws ReviewManagementDAOException {
|
|
|
|
public void deleteReview(int reviewId, int tenantId) throws ReviewManagementDAOException {
|
|
|
|
Connection conn;
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("DAO request is received to delete review which has review ID: " + reviewId);
|
|
|
|
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
sql = "DELETE "
|
|
|
|
sql = "DELETE "
|
|
|
|
+ "FROM AP_APP_REVIEW "
|
|
|
|
+ "FROM AP_APP_REVIEW "
|
|
|
|
+ "WHERE "
|
|
|
|
+ "WHERE "
|
|
|
@ -610,19 +519,25 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
statement.setInt(2, tenantId);
|
|
|
|
statement.setInt(2, tenantId);
|
|
|
|
statement.executeUpdate();
|
|
|
|
statement.executeUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException("Error occured while accessing the Database", e);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new ReviewManagementDAOException("Error occured while getting the database connection", e);
|
|
|
|
String msg = "Error occured while getting the database connection to delete review which has review ID: "
|
|
|
|
|
|
|
|
+ reviewId;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occured while executing SQL to delete review which has review ID: " + reviewId;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void deleteReviews(List<Integer> reviewIds, int tenantId) throws ReviewManagementDAOException{
|
|
|
|
public void deleteReviews(List<Integer> reviewIds, int tenantId) throws ReviewManagementDAOException{
|
|
|
|
Connection conn;
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("DAO request is received to delete reviews for requesting review Ids.");
|
|
|
|
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
sql = "DELETE "
|
|
|
|
sql = "DELETE "
|
|
|
|
+ "FROM AP_APP_REVIEW "
|
|
|
|
+ "FROM AP_APP_REVIEW "
|
|
|
|
+ "WHERE "
|
|
|
|
+ "WHERE "
|
|
|
@ -636,19 +551,24 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
stmt.executeBatch();
|
|
|
|
stmt.executeBatch();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException("Error occured while accessing the Database", e);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
throw new ReviewManagementDAOException("Error occured while getting the database connection", e);
|
|
|
|
String msg = "Error occurred while getting the database connection to delete reviews for given review Ids.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
String msg = "Error occurred while executing SQL to delete reviews for given review Ids.";
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void deleteAllChildCommentsOfReview(int rootParentId, int tenantId) throws ReviewManagementDAOException {
|
|
|
|
public void deleteAllChildCommentsOfReview(int rootParentId, int tenantId) throws ReviewManagementDAOException {
|
|
|
|
Connection conn;
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
|
|
|
log.debug("DAO request is received to delete child comments of a review.");
|
|
|
|
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
sql = "DELETE "
|
|
|
|
sql = "DELETE "
|
|
|
|
+ "FROM AP_APP_REVIEW "
|
|
|
|
+ "FROM AP_APP_REVIEW "
|
|
|
|
+ "WHERE "
|
|
|
|
+ "WHERE "
|
|
|
@ -659,39 +579,16 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
statement.setInt(2, tenantId);
|
|
|
|
statement.setInt(2, tenantId);
|
|
|
|
statement.executeUpdate();
|
|
|
|
statement.executeUpdate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException("Error occured while accessing the Database", e);
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException("Error occured while getting the database connection", e);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void deleteReviews(String appType, String appName, String version) throws ReviewManagementException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Connection conn;
|
|
|
|
|
|
|
|
PreparedStatement statement = null;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
|
|
|
|
//todo need to reconstruct the query,
|
|
|
|
|
|
|
|
sql = "DELETE FROM AP_APP_COMMENT WHERE "
|
|
|
|
|
|
|
|
+ "(SELECT AP_APP_RELEASE_ID FROM AP_APP_RELEASE WHERE VERSION=? AND "
|
|
|
|
|
|
|
|
+ "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? AND TYPE=?)) AND "
|
|
|
|
|
|
|
|
+ "(SELECT AP_APP_ID FROM AP_APP AND NAME=? AND TYPE=?);";
|
|
|
|
|
|
|
|
statement = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
statement.setString(1, version);
|
|
|
|
|
|
|
|
statement.setString(2, appName);
|
|
|
|
|
|
|
|
statement.setString(3, appType);
|
|
|
|
|
|
|
|
statement.setString(4, appName);
|
|
|
|
|
|
|
|
statement.setString(5, appType);
|
|
|
|
|
|
|
|
statement.executeUpdate();
|
|
|
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
log.error("DB Connection Exception occurred while deleting comments", e);
|
|
|
|
String msg = "Error occured while getting the database connection to delete all child comments of a review "
|
|
|
|
|
|
|
|
+ "which has ID: " + rootParentId;
|
|
|
|
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new ReviewManagementException("SQL Error occurred while deleting comments", e);
|
|
|
|
String msg = "Error occured while executing SQL to delete all child comments of a review which has ID: "
|
|
|
|
} finally {
|
|
|
|
+ rootParentId;
|
|
|
|
DAOUtil.cleanupResources(statement, null);
|
|
|
|
log.error(msg);
|
|
|
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|