|
|
|
@ -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.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.core.dao.ReviewDAO;
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
|
|
|
|
@ -52,7 +51,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
|
private String sql;
|
|
|
|
|
|
|
|
|
|
@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()) {
|
|
|
|
|
log.debug("Request received in DAO Layer to add review for application release. Application Release UUID: "
|
|
|
|
|
+ appReleaseId);
|
|
|
|
@ -69,11 +68,11 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
|
+ "AP_APP_RELEASE_ID) "
|
|
|
|
|
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ? )";
|
|
|
|
|
try {
|
|
|
|
|
int reviewId = -1;
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
|
|
|
|
|
|
|
|
|
|
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.setString(2, reviewDTO.getContent());
|
|
|
|
|
statement.setInt(3, reviewDTO.getRootParentId());
|
|
|
|
@ -85,16 +84,22 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
|
statement.setInt(9, appReleaseId);
|
|
|
|
|
statement.executeUpdate();
|
|
|
|
|
try (ResultSet rs = statement.getGeneratedKeys()) {
|
|
|
|
|
return rs.next();
|
|
|
|
|
if (rs.next()) {
|
|
|
|
|
reviewId = rs.getInt(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return reviewId;
|
|
|
|
|
}
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
throw new ReviewManagementDAOException("Error occurred while obtaining the DB connection while "
|
|
|
|
|
+ "adding review for application release which has ID: "+ appReleaseId + "Tenant Id: " + tenantId, e);
|
|
|
|
|
String msg = "Error occurred while obtaining the DB connection to add a review for application release which"
|
|
|
|
|
+ " has ID: "+ appReleaseId + " and Tenant Id: " + tenantId;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
|
"Error occurred while executing SQL statement to add application review. Application ID: "
|
|
|
|
|
+ appReleaseId + " tenant " + tenantId, e);
|
|
|
|
|
String msg = "Error occurred while executing SQL statement to add application review. Application ID: "
|
|
|
|
|
+ appReleaseId + " and tenant " + tenantId;
|
|
|
|
|
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)
|
|
|
|
|
throws ReviewManagementDAOException {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
Connection conn;
|
|
|
|
|
int index = 1;
|
|
|
|
|
try {
|
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
|
StringJoiner joiner = new StringJoiner(",",
|
|
|
|
|
"SELECT rv.ID FROM AP_APP_REVIEW rv WHERE rv.AP_APP_RELEASE_ID IN (",
|
|
|
|
|
") AND rv.USERNAME = ? AND rv.TENANT_ID = ?");
|
|
|
|
|
appReleaseIds.stream().map(ignored -> "?").forEach(joiner::add);
|
|
|
|
|
String query = joiner.toString();
|
|
|
|
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
|
|
|
|
int index = 1;
|
|
|
|
|
for (Integer deviceId : appReleaseIds) {
|
|
|
|
|
ps.setObject(index++, deviceId);
|
|
|
|
|
}
|
|
|
|
@ -124,25 +128,25 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
|
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) {
|
|
|
|
|
throw new ReviewManagementDAOException("Error occured while getting the database connection when checking "
|
|
|
|
|
+ "whether user has already commented for the application ro not", e);
|
|
|
|
|
String msg = "Error occured while getting the database connection when checking whether user has already "
|
|
|
|
|
+ "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
|
|
|
|
|
public int updateReview(ReviewDTO reviewDTO, int reviewId, boolean isActiveReview, int tenantId)
|
|
|
|
|
throws ReviewManagementDAOException {
|
|
|
|
|
|
|
|
|
|
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 "
|
|
|
|
|
+ "AP_APP_REVIEW "
|
|
|
|
|
+ "SET "
|
|
|
|
@ -150,109 +154,73 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
|
+ "RATING = ?, "
|
|
|
|
|
+ "MODIFIED_AT = ?, "
|
|
|
|
|
+ "ACTIVE_REVIEW = ? "
|
|
|
|
|
+ "WHERE ID = ? AND "
|
|
|
|
|
+ "TENANT_ID = ?";
|
|
|
|
|
+ "WHERE ID = ? AND TENANT_ID = ?";
|
|
|
|
|
try {
|
|
|
|
|
Calendar calendar = Calendar.getInstance();
|
|
|
|
|
Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
|
|
|
|
|
|
|
|
|
|
connection = this.getDBConnection();
|
|
|
|
|
statement = connection.prepareStatement(sql);
|
|
|
|
|
statement.setString(1, reviewDTO.getContent());
|
|
|
|
|
statement.setInt(2, reviewDTO.getRating());
|
|
|
|
|
statement.setTimestamp(3, timestamp);
|
|
|
|
|
statement.setBoolean(4, isActiveReview);
|
|
|
|
|
statement.setInt(5, reviewId);
|
|
|
|
|
statement.setInt(6, tenantId);
|
|
|
|
|
return statement.executeUpdate();
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new ReviewManagementDAOException("Error occurred while executing reviewTmp updating query");
|
|
|
|
|
Connection connection = this.getDBConnection();
|
|
|
|
|
try (PreparedStatement statement = connection.prepareStatement(sql)){
|
|
|
|
|
statement.setString(1, reviewDTO.getContent());
|
|
|
|
|
statement.setInt(2, reviewDTO.getRating());
|
|
|
|
|
statement.setTimestamp(3, timestamp);
|
|
|
|
|
statement.setBoolean(4, isActiveReview);
|
|
|
|
|
statement.setInt(5, reviewId);
|
|
|
|
|
statement.setInt(6, tenantId);
|
|
|
|
|
return statement.executeUpdate();
|
|
|
|
|
}
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
throw new ReviewManagementDAOException("Error occured while getting the db connection to update reviewTmp");
|
|
|
|
|
} finally {
|
|
|
|
|
DAOUtil.cleanupResources(statement, rs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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);
|
|
|
|
|
String msg = "Error occured while getting the db connection to update review for review ID: " + reviewId;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
|
"SQL Error occurred while retrieving information of the reviewTmp " + reviewId, e);
|
|
|
|
|
} catch (DBConnectionException 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);
|
|
|
|
|
String msg = "Error occurred while executing review updating query for review ID: " + reviewId;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public ReviewDTO getReview(int appReleaseId, int reviewId) throws ReviewManagementDAOException {
|
|
|
|
|
public ReviewDTO getReview(int reviewId, int tenantId) throws ReviewManagementDAOException {
|
|
|
|
|
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;
|
|
|
|
|
PreparedStatement statement = null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
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 = ? AND AP_APP_REVIEW.TENANT_ID = ?";
|
|
|
|
|
try {
|
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
|
sql = "SELECT "
|
|
|
|
|
+ "ID, "
|
|
|
|
|
+ "COMMENT,"
|
|
|
|
|
+ "ROOT_PARENT_ID,"
|
|
|
|
|
+ "IMMEDIATE_PARENT_ID, "
|
|
|
|
|
+ "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);
|
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
|
try (PreparedStatement statement = conn.prepareStatement(sql)) {
|
|
|
|
|
statement.setInt(1, reviewId);
|
|
|
|
|
statement.setInt(2, tenantId);
|
|
|
|
|
try (ResultSet rs = statement.executeQuery()) {
|
|
|
|
|
return DAOUtil.loadReview(rs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
|
"DB Connection Exception occurred while retrieving information of the reviewTmp " + reviewId, e);
|
|
|
|
|
String msg = "DB Connection Exception occurred while retrieving information of the review for review ID: "
|
|
|
|
|
+ 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) {
|
|
|
|
|
throw new ReviewManagementDAOException("Found more than one review for review ID: " + reviewId, e);
|
|
|
|
|
} finally {
|
|
|
|
|
DAOUtil.cleanupResources(statement, rs);
|
|
|
|
|
String msg = "Found more than one review for review ID: " + reviewId;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -260,31 +228,28 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
|
@Override
|
|
|
|
|
public List<ReviewDTO> getAllReleaseReviews(int releaseId, PaginationRequest request, int tenantId)
|
|
|
|
|
throws ReviewManagementDAOException {
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
List<ReviewDTO> reviewDTOs;
|
|
|
|
|
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 {
|
|
|
|
|
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 ?";
|
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
|
try (PreparedStatement statement = conn.prepareStatement(sql)) {
|
|
|
|
|
statement.setInt(1, releaseId);
|
|
|
|
|
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(5, request.getOffSet());
|
|
|
|
|
try (ResultSet rs = statement.executeQuery()) {
|
|
|
|
|
reviewDTOs = DAOUtil.loadReviews(rs);
|
|
|
|
|
return DAOUtil.loadReviews(rs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
|
"Error occurred while obtaining the DB connection when verifying application existence", e);
|
|
|
|
|
String msg = "Error occurred while obtaining the DB connection to get all app release reviews for "
|
|
|
|
|
+ "application release ID: " + releaseId;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new ReviewManagementDAOException("DB connection error occurred while getting all reviewTmps", e);
|
|
|
|
|
} return reviewDTOs;
|
|
|
|
|
String msg = "Error occurred while executing the SQL statement to get all app release reviews for "
|
|
|
|
|
+ "application release ID: " + releaseId;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<ReviewDTO> getAllActiveAppReviews(List<Integer> releaseIds, PaginationRequest request, int tenantId)
|
|
|
|
|
throws ReviewManagementDAOException {
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
List<ReviewDTO> reviewDTOs;
|
|
|
|
|
int index = 1;
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
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 = ? "
|
|
|
|
|
+ "LIMIT ? OFFSET ?");
|
|
|
|
|
releaseIds.stream().map(ignored -> "?").forEach(joiner::add);
|
|
|
|
|
String query = joiner.toString();
|
|
|
|
|
try (PreparedStatement ps = conn.prepareStatement(query)) {
|
|
|
|
|
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()) {
|
|
|
|
|
reviewDTOs = DAOUtil.loadReviews(rs);
|
|
|
|
|
}
|
|
|
|
|
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 = ? "
|
|
|
|
|
+ "LIMIT ? OFFSET ?");
|
|
|
|
|
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) {
|
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
|
"Error occurred while obtaining the DB connection when verifying application existence.", e);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
String msg = "Error occurred while obtaining the DB connection to get all active app reviews.";
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new ReviewManagementDAOException("DB connection error occurred while getting all reviews.", e);
|
|
|
|
|
} return reviewDTOs;
|
|
|
|
|
String msg = "Error occurred while executing SQL to get all active app reviews.";
|
|
|
|
|
log.error(msg);
|
|
|
|
|
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("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 {
|
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
|
StringJoiner joiner = new StringJoiner(",",
|
|
|
|
|
"SELECT "
|
|
|
|
|
+ "AP_APP_REVIEW.ID AS ID, "
|
|
|
|
@ -395,6 +357,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
@ -404,29 +367,28 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
|
ps.setInt(index++, request.getLimit());
|
|
|
|
|
ps.setInt(index, request.getOffSet());
|
|
|
|
|
try (ResultSet rs = ps.executeQuery()) {
|
|
|
|
|
reviewDTOs = DAOUtil.loadReviews(rs);
|
|
|
|
|
return DAOUtil.loadReviews(rs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (DBConnectionException e) {
|
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
|
"Error occurred while obtaining the DB connection when application review of user: " + username , e);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
String msg = "Error occurred while obtaining the DB connection to get all active app reviews of user "
|
|
|
|
|
+ username;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new ReviewManagementDAOException("DB connection error occurred while getting application reviews of "
|
|
|
|
|
+ "user:" + username, e);
|
|
|
|
|
} return reviewDTOs;
|
|
|
|
|
String msg = "Error occurred while executing SQL to get all active app reviews of user " + username;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<ReviewDTO> getReplyComments(int parentId, int tenantId) throws ReviewManagementDAOException {
|
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
|
sql = "SELECT "
|
|
|
|
|
+ "AP_APP_REVIEW.ID AS ID, "
|
|
|
|
|
+ "AP_APP_REVIEW.COMMENT AS COMMENT, "
|
|
|
|
@ -446,66 +408,70 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
|
try (PreparedStatement statement = conn.prepareStatement(sql)) {
|
|
|
|
|
statement.setInt(1, parentId);
|
|
|
|
|
statement.setInt(2, tenantId);
|
|
|
|
|
try (ResultSet rs = statement.executeQuery();) {
|
|
|
|
|
reviewDTOs = DAOUtil.loadReviews(rs);
|
|
|
|
|
try (ResultSet rs = statement.executeQuery()) {
|
|
|
|
|
return DAOUtil.loadReviews(rs);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
|
"Error occurred while obtaining the DB connection when getting reply comments for a review.", e);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
String msg = "Error occurred while obtaining the DB connection when getting reply comments for a review "
|
|
|
|
|
+ "which has reviw ID: " + parentId;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ReviewManagementDAOException(msg, 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
|
|
|
|
|
public List<Integer> getAllAppReleaseRatingValues(String uuid, int tenantId) throws ReviewManagementDAOException {
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
PreparedStatement statement = null;
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
List<Integer> reviews = new ArrayList<>();
|
|
|
|
|
sql = "SELECT "
|
|
|
|
|
+ "AP_APP_REVIEW.RATING AS RATING "
|
|
|
|
|
+ "FROM AP_APP_REVIEW, AP_APP_RELEASE "
|
|
|
|
|
+ "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 {
|
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
|
sql = "SELECT AP_APP_REVIEW.RATING AS RATING FROM AP_APP_REVIEW, AP_APP_RELEASE 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 = ?";
|
|
|
|
|
statement = conn.prepareStatement(sql);
|
|
|
|
|
statement.setString(1, uuid);
|
|
|
|
|
statement.setInt(2, tenantId);
|
|
|
|
|
rs = statement.executeQuery();
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
reviews.add(rs.getInt("RATING"));
|
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
|
try (PreparedStatement statement = conn.prepareStatement(sql)) {
|
|
|
|
|
statement.setString(1, uuid);
|
|
|
|
|
statement.setInt(2, tenantId);
|
|
|
|
|
try (ResultSet rs = statement.executeQuery()) {
|
|
|
|
|
List<Integer> reviews = new ArrayList<>();
|
|
|
|
|
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) {
|
|
|
|
|
throw new ReviewManagementDAOException(
|
|
|
|
|
"Error occured while getting DB connection to retrieve all rating values for the application release. App release UUID: "
|
|
|
|
|
+ uuid, e);
|
|
|
|
|
} finally {
|
|
|
|
|
DAOUtil.cleanupResources(statement, rs);
|
|
|
|
|
String msg = "Error occured while getting DB connection to retrieve all rating values for the application "
|
|
|
|
|
+ "release which has UUID:" + uuid;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
} 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
|
|
|
|
|
public List<Integer> getAllAppRatingValues(List<String> uuids, int tenantId) throws ReviewManagementDAOException {
|
|
|
|
|
|
|
|
|
|
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 {
|
|
|
|
|
int index = 1;
|
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
|
StringJoiner joiner = new StringJoiner(",",
|
|
|
|
|
"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 (",
|
|
|
|
@ -518,88 +484,31 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
|
}
|
|
|
|
|
ps.setInt(index, tenantId);
|
|
|
|
|
try (ResultSet rs = ps.executeQuery()) {
|
|
|
|
|
List<Integer> reviews = new ArrayList<>();
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
reviews.add(rs.getInt("RATING"));
|
|
|
|
|
} }
|
|
|
|
|
}
|
|
|
|
|
} 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");
|
|
|
|
|
}
|
|
|
|
|
return reviews;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new ReviewManagementDAOException("SQL Error occurred while retrieving review counts", e);
|
|
|
|
|
} catch (DBConnectionException e) {
|
|
|
|
|
throw new ReviewManagementDAOException("DB Connection Exception occurred while retrieving review counts", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DAOUtil.cleanupResources(statement, rs);
|
|
|
|
|
}
|
|
|
|
|
return commentCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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);
|
|
|
|
|
String msg = "Error occured while getting DB connection to retrieve all rating values for an application.";
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
String msg = "Error occured while executing SQL to get all rating values for the application.";
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
}
|
|
|
|
|
return commentCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
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 {
|
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
|
sql = "DELETE "
|
|
|
|
|
+ "FROM AP_APP_REVIEW "
|
|
|
|
|
+ "WHERE "
|
|
|
|
@ -610,19 +519,25 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
|
statement.setInt(2, tenantId);
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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 {
|
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
|
sql = "DELETE "
|
|
|
|
|
+ "FROM AP_APP_REVIEW "
|
|
|
|
|
+ "WHERE "
|
|
|
|
@ -636,19 +551,24 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
|
}
|
|
|
|
|
stmt.executeBatch();
|
|
|
|
|
}
|
|
|
|
|
} 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);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
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 {
|
|
|
|
|
conn = this.getDBConnection();
|
|
|
|
|
Connection conn = this.getDBConnection();
|
|
|
|
|
sql = "DELETE "
|
|
|
|
|
+ "FROM AP_APP_REVIEW "
|
|
|
|
|
+ "WHERE "
|
|
|
|
@ -659,39 +579,16 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
|
|
|
|
|
statement.setInt(2, tenantId);
|
|
|
|
|
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) {
|
|
|
|
|
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) {
|
|
|
|
|
throw new ReviewManagementException("SQL Error occurred while deleting comments", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DAOUtil.cleanupResources(statement, null);
|
|
|
|
|
String msg = "Error occured while executing SQL to delete all child comments of a review which has ID: "
|
|
|
|
|
+ rootParentId;
|
|
|
|
|
log.error(msg);
|
|
|
|
|
throw new ReviewManagementDAOException(msg, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|