Fix review managing issues

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent 54cee927f2
commit 1e4d14d837

@ -55,8 +55,8 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
} }
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet rs = null; ResultSet rs = null;
sql = "INSERT INTO AP_APP_REVIEW (TENANT_ID, COMMENT, PARENT_ID, USERNAME,CREATED_AT, MODIFIED_AT," sql = "INSERT INTO AP_APP_REVIEW (TENANT_ID, COMMENT, PARENT_ID, RATING, USERNAME,CREATED_AT, MODIFIED_AT, "
+ " AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?,?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?)," + "AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?,?,?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?),"
+ "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));"; + "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));";
try { try {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
@ -67,11 +67,12 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
statement.setInt(1, tenantId); statement.setInt(1, tenantId);
statement.setString(2, review.getComment()); statement.setString(2, review.getComment());
statement.setInt(3, review.getParentId()); statement.setInt(3, review.getParentId());
statement.setString(4, review.getUsername()); statement.setInt(4, review.getRating());
statement.setTimestamp(5,timestamp); statement.setString(5, review.getUsername());
statement.setTimestamp(6,timestamp); statement.setTimestamp(6, timestamp);
statement.setString(7,uuid); statement.setTimestamp(7,timestamp);
statement.setString(8,uuid); statement.setString(8,uuid);
statement.setString(9,uuid);
statement.executeUpdate(); statement.executeUpdate();
rs = statement.getGeneratedKeys(); rs = statement.getGeneratedKeys();
return rs.next(); return rs.next();
@ -173,18 +174,18 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
Connection conn; Connection conn;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet rs = null; ResultSet rs = null;
Review review = new Review(); Review review = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql = "SELECT ID, COMMENT, CREATED_AT, MODIFIED_AT, RATING, USERNAME FROM AP_APP_REVIEWE WHERE ID=?;"; sql = "SELECT ID, COMMENT, CREATED_AT, MODIFIED_AT, RATING, USERNAME FROM AP_APP_REVIEW WHERE ID=?;";
statement = conn.prepareStatement(sql); statement = conn.prepareStatement(sql);
statement.setInt(1, reviewId); statement.setInt(1, reviewId);
rs = statement.executeQuery(); rs = statement.executeQuery();
if (rs.next()) { if (rs.next()) {
review = new Review();
review.setId(rs.getInt("ID")); review.setId(rs.getInt("ID"));
review.setComment(rs.getString("COMMENT")); review.setComment(rs.getString("COMMENT"));
review.setCreatedAt(rs.getTimestamp("CREATED_AT")); review.setCreatedAt(rs.getTimestamp("CREATED_AT"));
review.setUsername(rs.getString("CREATED_BY"));
review.setModifiedAt(rs.getTimestamp("MODIFIED_AT")); review.setModifiedAt(rs.getTimestamp("MODIFIED_AT"));
review.setRating(rs.getInt("RATING")); review.setRating(rs.getInt("RATING"));
review.setUsername(rs.getString("USERNAME")); review.setUsername(rs.getString("USERNAME"));
@ -262,9 +263,9 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
List<Integer> reviews = new ArrayList<>(); List<Integer> reviews = new ArrayList<>();
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql = "SELECT AP_APP_COMMENT.RATING AS RATING FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE " 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.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_RELEASE.UUID =? AND "
+ "AP_APP_COMMENT.TENANT_ID = AP_APP_RELEASE.TENANT_ID AND AP_APP_COMMENT.TENANT_ID = ?;"; + "AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID AND AP_APP_REVIEW.TENANT_ID = ?;";
statement = conn.prepareStatement(sql); statement = conn.prepareStatement(sql);
statement.setString(1, uuid); statement.setString(1, uuid);
statement.setInt(2, tenantId); statement.setInt(2, tenantId);
@ -355,7 +356,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
PreparedStatement statement = null; PreparedStatement statement = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql = "DELETE FROM AP_APP_REVIEW WHERE ID=? AND USERNAME = ?);"; sql = "DELETE FROM AP_APP_REVIEW WHERE ID=? AND USERNAME = ?;";
statement = conn.prepareStatement(sql); statement = conn.prepareStatement(sql);
statement.setInt(1, reviewId); statement.setInt(1, reviewId);
statement.setString(2, username); statement.setString(2, username);

@ -240,7 +240,7 @@ public class ReviewManagerImpl implements ReviewManager {
} }
List<Integer> ratingValues = this.reviewDAO.getAllRatingValues(appReleaseUuuid, tenantId); List<Integer> ratingValues = this.reviewDAO.getAllRatingValues(appReleaseUuuid, tenantId);
TreeMap<Integer, Integer> ratingVariety = rating.getRatingVariety(); TreeMap<Integer, Integer> ratingVariety = new TreeMap<>();
for (Integer ratingVal : ratingValues) { for (Integer ratingVal : ratingValues) {
if (ratingVariety.containsKey(ratingVal)) { if (ratingVariety.containsKey(ratingVal)) {
ratingVariety.replace(ratingVal, ratingVariety.get(ratingVal) + 1); ratingVariety.replace(ratingVal, ratingVariety.get(ratingVal) + 1);
@ -277,18 +277,26 @@ public class ReviewManagerImpl implements ReviewManager {
log.error("Couldn't find rating for application release uuid: " + uuid); log.error("Couldn't find rating for application release uuid: " + uuid);
} else { } else {
double updatedRating; double updatedRating;
double newTotalRating;
int numOfUsers = rating.getNoOfUsers(); int numOfUsers = rating.getNoOfUsers();
double currentRating = rating.getRatingValue() * numOfUsers; double currentRating = rating.getRatingValue() * numOfUsers;
if (oldRatingVal == -12345) { if (oldRatingVal == -12345) {
newTotalRating = currentRating + newRatingVal;
numOfUsers++; numOfUsers++;
updatedRating = (currentRating + newRatingVal) / numOfUsers;
} else if (newRatingVal == 0) { } else if (newRatingVal == 0) {
newTotalRating = currentRating - newRatingVal;
numOfUsers--; numOfUsers--;
updatedRating = (currentRating - newRatingVal) / numOfUsers;
} else { } else {
double tmpVal; double tmpVal;
tmpVal = currentRating - oldRatingVal; tmpVal = currentRating - oldRatingVal;
updatedRating = (tmpVal + newRatingVal) / numOfUsers; newTotalRating = tmpVal + newRatingVal;
}
if (numOfUsers == 0) {
updatedRating = 0;
} else {
updatedRating = newTotalRating / numOfUsers;
} }
this.applicationReleaseDAO.updateRatingValue(uuid, updatedRating, numOfUsers); this.applicationReleaseDAO.updateRatingValue(uuid, updatedRating, numOfUsers);
} }

Loading…
Cancel
Save