Reformatted the code.

feature/appm-store/pbac
nishadi 7 years ago
parent 1bbd0b1aa5
commit 3bfb2addbb

@ -62,17 +62,16 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
List<Comment> comments = new ArrayList<>(); List<Comment> comments = new ArrayList<>();
try { try {
PaginationRequest request=new PaginationRequest(offSet,limit); PaginationRequest request = new PaginationRequest(offSet, limit);
if(request.validatePaginationRequest(offSet,limit)) { if (request.validatePaginationRequest(offSet, limit)) {
commentsManager.getAllComments(request, uuid); commentsManager.getAllComments(request, uuid);
return Response.status(Response.Status.OK).entity(comments).build(); return Response.status(Response.Status.OK).entity(comments).build();
} }
} catch (NotFoundException e){ } catch (NotFoundException e) {
log.error("Not found exception occurs to uuid "+uuid+" .",e); log.error("Not found exception occurs to uuid " + uuid + " .", e);
return Response.status(Response.Status.NOT_FOUND) return Response.status(Response.Status.NOT_FOUND).entity("Application with UUID " + uuid + " not found")
.entity("Application with UUID " + uuid + " not found").build(); .build();
} } catch (CommentManagementException e) {
catch (CommentManagementException e) {
String msg = "Error occurred while retrieving comments."; String msg = "Error occurred while retrieving comments.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
@ -89,17 +88,17 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
@PathParam("uuid") String uuid){ @PathParam("uuid") String uuid){
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
int tenantId= PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try { try {
Comment newComment = commentsManager.addComment(comment,uuid,tenantId); Comment newComment = commentsManager.addComment(comment, uuid, tenantId);
if (comment != null){ if (comment != null) {
return Response.status(Response.Status.CREATED).entity(newComment).build(); return Response.status(Response.Status.CREATED).entity(newComment).build();
}else{ } else {
String msg = "Given comment is not valid "; String msg = "Given comment is not valid ";
log.error(msg); log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).build(); return Response.status(Response.Status.BAD_REQUEST).build();
} }
}catch (CommentManagementException e) { } catch (CommentManagementException e) {
String msg = "Error occurred while creating the comment"; String msg = "Error occurred while creating the comment";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
@ -115,17 +114,16 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
@PathParam("CommentId") int CommentId) { @PathParam("CommentId") int CommentId) {
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
try { try {
if (CommentId == 0) { if (CommentId == 0) {
return Response.status(Response.Status.NOT_FOUND) return Response.status(Response.Status.NOT_FOUND)
.entity("Comment with comment id " + CommentId + " not found").build(); .entity("Comment with comment id " + CommentId + " not found").build();
}else if(comment==null){ } else if (comment == null) {
String msg = "Given comment is not valid "; String msg = "Given comment is not valid ";
log.error(msg); log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).build(); return Response.status(Response.Status.BAD_REQUEST).build();
} else{ } else {
comment = commentsManager.updateComment(comment,CommentId); comment = commentsManager.updateComment(comment, CommentId);
return Response.status(Response.Status.OK).entity(comment).build(); return Response.status(Response.Status.OK).entity(comment).build();
} }
} catch (CommentManagementException e) { } catch (CommentManagementException e) {
@ -150,9 +148,8 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
log.error("Not found exception occurs to comment id "+CommentId+" .",e); log.error("Not found exception occurs to comment id " + CommentId + " .", e);
return Response.status(Response.Status.NOT_FOUND) return Response.status(Response.Status.NOT_FOUND).entity("Comment with" + CommentId + " not found").build();
.entity("Comment with" + CommentId + " not found").build();
} }
return Response.status(Response.Status.OK).entity("Comment is deleted successfully.").build(); return Response.status(Response.Status.OK).entity("Comment is deleted successfully.").build();
} }
@ -165,15 +162,14 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
String uuid) { String uuid) {
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
int Stars=0; int Stars = 0;
try { try {
Stars= commentsManager.getStars(uuid); Stars = commentsManager.getStars(uuid);
} catch (CommentManagementException e) { } catch (CommentManagementException e) {
log.error("Comment Management Exception occurs",e); log.error("Comment Management Exception occurs", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
log.error("Application Management Exception occurs",e); log.error("Application Management Exception occurs", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} }
return Response.status(Response.Status.OK).entity(Stars).build(); return Response.status(Response.Status.OK).entity(Stars).build();
@ -187,15 +183,14 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
String uuid){ String uuid){
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
int ratedUsers=0; int ratedUsers = 0;
try { try {
ratedUsers= commentsManager.getRatedUser(uuid); ratedUsers = commentsManager.getRatedUser(uuid);
} catch (CommentManagementException e) { } catch (CommentManagementException e) {
log.error("Comment Management Exception occurs",e); log.error("Comment Management Exception occurs", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
log.error("Application Management Exception occurs",e); log.error("Application Management Exception occurs", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} }
return Response.status(Response.Status.OK).entity(ratedUsers).build(); return Response.status(Response.Status.OK).entity(ratedUsers).build();
@ -209,21 +204,20 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
@PathParam("uuid") String uuid) { @PathParam("uuid") String uuid) {
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
int newStars=0; int newStars = 0;
try { try {
newStars = commentsManager.updateStars(stars,uuid); newStars = commentsManager.updateStars(stars, uuid);
if (stars != 0){ if (stars != 0) {
return Response.status(Response.Status.CREATED).entity(newStars).build(); return Response.status(Response.Status.CREATED).entity(newStars).build();
}else{ } else {
String msg = "Given star value is not valid "; String msg = "Given star value is not valid ";
log.error(msg); log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).build(); return Response.status(Response.Status.BAD_REQUEST).build();
} }
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
log.error("Application Management Exception occurs",e); log.error("Application Management Exception occurs", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} }
} }

@ -51,7 +51,6 @@ public class Comment {
this.tenantId = tenantId; this.tenantId = tenantId;
} }
public int getId() { public int getId() {
return id; return id;
} }

@ -18,9 +18,6 @@
package org.wso2.carbon.device.application.mgt.common; package org.wso2.carbon.device.application.mgt.common;
import org.apache.commons.fileupload.MultipartStream;
/** /**
* This class holds required parameters for a querying a paginated device response. * This class holds required parameters for a querying a paginated device response.
*/ */
@ -50,19 +47,17 @@ public class PaginationRequest {
this.limit = limit; this.limit = limit;
} }
public boolean validatePaginationRequest(int offSet,int limit){ public boolean validatePaginationRequest(int offSet, int limit) {
if (offSet<0){ if (offSet < 0) {
throw new IllegalArgumentException("off set value can't be negative"); throw new IllegalArgumentException("off set value can't be negative");
} else if(limit<0){ } else if (limit < 0) {
throw new IllegalArgumentException("limit value can't be negative"); throw new IllegalArgumentException("limit value can't be negative");
}else { } else {
return true; return true;
} }
} }
@Override public String toString() {
@Override
public String toString() {
return "Off Set'" + this.offSet + "' row count '" + this.limit; return "Off Set'" + this.offSet + "' row count '" + this.limit;
} }
} }

@ -1,8 +1,24 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.common.exception; package org.wso2.carbon.device.application.mgt.common.exception;
import org.wso2.carbon.device.application.mgt.common.Comment; public class CommentManagementException extends Exception {
public class CommentManagementException extends Exception{
private String message; private String message;
public CommentManagementException(String message, Throwable throwable) { public CommentManagementException(String message, Throwable throwable) {
@ -18,8 +34,8 @@ public class CommentManagementException extends Exception{
public CommentManagementException() { public CommentManagementException() {
} }
@Override
public String getMessage() { @Override public String getMessage() {
return message; return message;
} }

@ -23,47 +23,45 @@ import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
import org.wso2.carbon.device.application.mgt.common.PaginationResult; import org.wso2.carbon.device.application.mgt.common.PaginationResult;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.CommentManagementException; import org.wso2.carbon.device.application.mgt.common.exception.CommentManagementException;
import java.util.List; import java.util.List;
/** /**
* CommentsManager is responsible for handling all the add/update/delete/get operations related with * CommentsManager is responsible for handling all the add/update/delete/get operations related with
*
*/ */
public interface CommentsManager { public interface CommentsManager {
/** /**
* To add a comment to a application * To add a comment to a application
* *
* @param comment comment of the application. * @param comment comment of the application.
* @param uuid uuid of the application release * @param uuid uuid of the application release
* @param tenantId tenant id of the application * @param tenantId tenant id of the application
* @return {@link Comment} Comment added * @return {@link Comment} Comment added
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
*/ */
Comment addComment(Comment comment,String uuid,int tenantId)throws CommentManagementException; Comment addComment(Comment comment, String uuid, int tenantId) throws CommentManagementException;
/** /**
* To validate the pre-request of the comment * To validate the pre-request of the comment
* *
* @param CommentId ID of the comment. * @param CommentId ID of the comment.
* @param comment comment needed to be validate. * @param comment comment needed to be validate.
* @return validated the comment. * @return validated the comment.
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
*
*/ */
Boolean validateComment(int CommentId,String comment) throws CommentManagementException; Boolean validateComment(int CommentId, String comment) throws CommentManagementException;
/** /**
* Get all comments to pagination * Get all comments to pagination
* *
* @param request Pagination request * @param request Pagination request
* @param uuid uuid of the application release * @param uuid uuid of the application release
* @return {@link PaginationResult} pagination result with starting offSet and limit * @return {@link PaginationResult} pagination result with starting offSet and limit
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
*/ */
List<Comment> getAllComments(PaginationRequest request, String uuid) throws CommentManagementException; List<Comment> getAllComments(PaginationRequest request, String uuid) throws CommentManagementException;
/** /**
* To get the comment with id. * To get the comment with id.
* *
@ -71,7 +69,7 @@ public interface CommentsManager {
* @return {@link Comment}Comment of the comment id * @return {@link Comment}Comment of the comment id
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
*/ */
Comment getComment(int CommentId)throws CommentManagementException; Comment getComment(int CommentId) throws CommentManagementException;
/** /**
* To delete comment using comment id. * To delete comment using comment id.
@ -81,23 +79,22 @@ public interface CommentsManager {
*/ */
void deleteComment(int CommentId) throws CommentManagementException; void deleteComment(int CommentId) throws CommentManagementException;
/** /**
* To update a comment. * To update a comment.
* *
* @param comment comment of the application. * @param comment comment of the application.
* @param CommentId id of the comment * @param CommentId id of the comment
* @return {@link Comment}updated comment * @return {@link Comment}updated comment
* @throws CommentManagementException Exceptions of the comment management * @throws CommentManagementException Exceptions of the comment management
*/ */
Comment updateComment(Comment comment,int CommentId) throws CommentManagementException; Comment updateComment(Comment comment, int CommentId) throws CommentManagementException;
/** /**
* To get number of rated users * To get number of rated users
* *
* @param uuid uuid of the application * @param uuid uuid of the application
* @return number of rated users * @return number of rated users
* @throws CommentManagementException Exceptions of the comment management * @throws CommentManagementException Exceptions of the comment management
* @throws ApplicationManagementException Application Management Exception. * @throws ApplicationManagementException Application Management Exception.
*/ */
int getRatedUser(String uuid) throws CommentManagementException, ApplicationManagementException; int getRatedUser(String uuid) throws CommentManagementException, ApplicationManagementException;
@ -107,7 +104,7 @@ public interface CommentsManager {
* *
* @param uuid uuid of the comment * @param uuid uuid of the comment
* @return value of the stars of an application * @return value of the stars of an application
* @throws CommentManagementException Exceptions of the comment management * @throws CommentManagementException Exceptions of the comment management
* @throws ApplicationManagementException Application Management Exception. * @throws ApplicationManagementException Application Management Exception.
*/ */
int getStars(String uuid) throws CommentManagementException, ApplicationManagementException; int getStars(String uuid) throws CommentManagementException, ApplicationManagementException;
@ -116,7 +113,7 @@ public interface CommentsManager {
* To update rating stars * To update rating stars
* *
* @param stars amount of stars * @param stars amount of stars
* @param uuid uuid of the application * @param uuid uuid of the application
* @return value of the added stars * @return value of the added stars
* @throws ApplicationManagementException Application Management Exception. * @throws ApplicationManagementException Application Management Exception.
*/ */

@ -24,8 +24,7 @@ import javax.xml.bind.annotation.XmlRootElement;
/** /**
* This class represents the information related to Pagination configuration. * This class represents the information related to Pagination configuration.
*/ */
@XmlRootElement(name = "PaginationConfiguration") @XmlRootElement(name = "PaginationConfiguration") public class PaginationConfiguration {
public class PaginationConfiguration {
private int commentListPageSize; private int commentListPageSize;
@ -33,8 +32,8 @@ public class PaginationConfiguration {
return commentListPageSize; return commentListPageSize;
} }
@XmlElement(name = "commentListPageSize", required = true) @XmlElement(name = "commentListPageSize", required = true) public void setCommentListPageSize(
public void setCommentListPageSize(int commentListPageSize) { int commentListPageSize) {
this.commentListPageSize = commentListPageSize; this.commentListPageSize = commentListPageSize;
} }

@ -32,64 +32,67 @@ import java.util.List;
* This interface specifies the database access operations performed for comments. * This interface specifies the database access operations performed for comments.
*/ */
@SuppressWarnings("ALL") @SuppressWarnings("ALL") public interface CommentDAO {
public interface CommentDAO {
/** /**
* To add a comment to a application. * To add a comment to a application.
* *
* @param tenantId tenantId of the commented application. * @param tenantId tenantId of the commented application.
* @param comment comment of the application. * @param comment comment of the application.
* @param createdBy Username of the created person. * @param createdBy Username of the created person.
* @param parentId parent id of the parent comment. * @param parentId parent id of the parent comment.
* @param uuid uuid of the application * @param uuid uuid of the application
* @return Comment Id * @return Comment Id
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
*/ */
int addComment(int tenantId , Comment comment, String createdBy, int parentId, String uuid) throws CommentManagementException, DBConnectionException, SQLException; int addComment(int tenantId, Comment comment, String createdBy, int parentId, String uuid)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To add a comment to a application. * To add a comment to a application.
* *
* @param comment comment of the application. * @param comment comment of the application.
* @param createdBy Username of the created person. * @param createdBy Username of the created person.
* @param appType type of the commented application. * @param appType type of the commented application.
* @param appName name of the commented application. * @param appName name of the commented application.
* @param version version of the commented application. * @param version version of the commented application.
* @return comment id * @return comment id
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
*/ */
int addComment(int tenantId, Comment comment,String createdBy,String appType,String appName,String version) throws CommentManagementException, DBConnectionException, SQLException; int addComment(int tenantId, Comment comment, String createdBy, String appType, String appName, String version)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To update already added comment. * To update already added comment.
* *
* @param CommentId id of the comment * @param CommentId id of the comment
* @param updatedComment comment after updated * @param updatedComment comment after updated
* @param modifiedBy Username of the modified person. * @param modifiedBy Username of the modified person.
* @param modifiedAt time of the modification. * @param modifiedAt time of the modification.
* @return {@link Comment}Updated comment * @return {@link Comment}Updated comment
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception * @throws DBConnectionException db connection exception
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
Comment updateComment(int CommentId, String updatedComment,String modifiedBy, Timestamp modifiedAt) throws CommentManagementException, DBConnectionException, SQLException; Comment updateComment(int CommentId, String updatedComment, String modifiedBy, Timestamp modifiedAt)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To update already added comment. * To update already added comment.
* *
* @param uuid uuid of the comment * @param uuid uuid of the comment
* @param CommentId id of the comment * @param CommentId id of the comment
* @param updatedComment comment after updated * @param updatedComment comment after updated
* @param modifiedBy Username of the modified person. * @param modifiedBy Username of the modified person.
* @param modifiedAt time of the modification. * @param modifiedAt time of the modification.
* @return {@link Comment}Updated comment * @return {@link Comment}Updated comment
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception * @throws DBConnectionException db connection exception
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
Comment updateComment(String uuid, int CommentId,String updatedComment,String modifiedBy, Timestamp modifiedAt) throws CommentManagementException, DBConnectionException, SQLException; Comment updateComment(String uuid, int CommentId, String updatedComment, String modifiedBy, Timestamp modifiedAt)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get the comment with id. * To get the comment with id.
@ -97,8 +100,8 @@ public interface CommentDAO {
* @param CommentId id of the comment * @param CommentId id of the comment
* @return {@link Comment}Comment * @return {@link Comment}Comment
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception * @throws DBConnectionException db connection exception
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
Comment getComment(int CommentId) throws CommentManagementException, SQLException, DBConnectionException; Comment getComment(int CommentId) throws CommentManagementException, SQLException, DBConnectionException;
@ -108,32 +111,33 @@ public interface CommentDAO {
* @param uuid uuid of the comment * @param uuid uuid of the comment
* @return {@link List} List of comments in the application * @return {@link List} List of comments in the application
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception * @throws DBConnectionException db connection exception
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
List<Comment> getComment(String uuid) throws CommentManagementException, SQLException, DBConnectionException; List<Comment> getComment(String uuid) throws CommentManagementException, SQLException, DBConnectionException;
/** /**
* To get all the comments * To get all the comments
* *
* @param uuid uuid of the application * @param uuid uuid of the application
* @param request {@link PaginationRequest}pagination request with offSet and limit * @param request {@link PaginationRequest}pagination request with offSet and limit
* @return {@link List}List of all the comments in an application * @return {@link List}List of all the comments in an application
* @throws CommentManagementException Exception of the comment management * @throws CommentManagementException Exception of the comment management
* @throws DBConnectionException db connection exception * @throws DBConnectionException db connection exception
* @throws SQLException sql exception * @throws SQLException sql exception
**/ **/
List<Comment> getAllComments(String uuid,PaginationRequest request) throws CommentManagementException, SQLException, DBConnectionException; List<Comment> getAllComments(String uuid, PaginationRequest request)
throws CommentManagementException, SQLException, DBConnectionException;
/** /**
* To get list of comments using release id and application id. * To get list of comments using release id and application id.
* *
* @param appReleasedId Id of the released version of the application. * @param appReleasedId Id of the released version of the application.
* @param appId id of the commented application. * @param appId id of the commented application.
* @return {@link List}List of comments * @return {@link List}List of comments
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
*/ */
List<Comment> getComments(int appReleasedId,int appId)throws CommentManagementException; List<Comment> getComments(int appReleasedId, int appId) throws CommentManagementException;
/** /**
* To get list of comments using application type, application name and version of the application. * To get list of comments using application type, application name and version of the application.
@ -143,10 +147,11 @@ public interface CommentDAO {
* @param version version of the commented application. * @param version version of the commented application.
* @return {@link List}List of comments * @return {@link List}List of comments
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
List<Comment> getComments(String appType,String appName,String version) throws CommentManagementException, DBConnectionException, SQLException; List<Comment> getComments(String appType, String appName, String version)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get list of comments using tenant id. * To get list of comments using tenant id.
@ -154,8 +159,8 @@ public interface CommentDAO {
* @param tenantId tenant id of the commented application * @param tenantId tenant id of the commented application
* @return {@link List}List of comments * @return {@link List}List of comments
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
List<Comment> getComments(int tenantId) throws CommentManagementException, DBConnectionException, SQLException; List<Comment> getComments(int tenantId) throws CommentManagementException, DBConnectionException, SQLException;
@ -165,10 +170,11 @@ public interface CommentDAO {
* @param createdBy Username of the created person. * @param createdBy Username of the created person.
* @return {@link List}List of comments * @return {@link List}List of comments
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
List<Comment> getCommentsByUser(String createdBy) throws CommentManagementException, DBConnectionException, SQLException; List<Comment> getCommentsByUser(String createdBy)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get list of comments by created use and created time. * To get list of comments by created use and created time.
@ -177,10 +183,11 @@ public interface CommentDAO {
* @param createdAt time of the comment created. * @param createdAt time of the comment created.
* @return {@link List}List of comments * @return {@link List}List of comments
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
List<Comment> getCommentsByUser(String createdBy,Timestamp createdAt) throws CommentManagementException, DBConnectionException, SQLException; List<Comment> getCommentsByUser(String createdBy, Timestamp createdAt)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get list of comments by modified users. * To get list of comments by modified users.
@ -188,10 +195,11 @@ public interface CommentDAO {
* @param modifiedBy Username of the modified person. * @param modifiedBy Username of the modified person.
* @return {@link List}List of comments * @return {@link List}List of comments
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
List<Comment> getCommentsByModifiedUser(String modifiedBy) throws CommentManagementException, DBConnectionException, SQLException; List<Comment> getCommentsByModifiedUser(String modifiedBy)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get list of comments using modified user's name and modified time. * To get list of comments using modified user's name and modified time.
@ -199,25 +207,27 @@ public interface CommentDAO {
* @param modifiedBy Username of the modified person. * @param modifiedBy Username of the modified person.
* @param modifiedAt time of the modification * @param modifiedAt time of the modification
* @return List of comments * @return List of comments
* @throws {@link List}CommentManagementException Exceptions of the comment management. * @throws {@link List}CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
List<Comment> getCommentsByModifiedUser(String modifiedBy,Timestamp modifiedAt) throws CommentManagementException, DBConnectionException, SQLException; List<Comment> getCommentsByModifiedUser(String modifiedBy, Timestamp modifiedAt)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get list of comments using application type, application name , application version and parent id of the comment. * To get list of comments using application type, application name , application version and parent id of the comment.
* *
* @param appType type of the commented application. * @param appType type of the commented application.
* @param appName name of the commented application. * @param appName name of the commented application.
* @param version version of the commented application. * @param version version of the commented application.
* @param parentId parent id of the parent comment. * @param parentId parent id of the parent comment.
* @return {@link List}List of comments * @return {@link List}List of comments
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
List<Comment> getComments(String appType,String appName,String version,int parentId) throws CommentManagementException, DBConnectionException, SQLException; List<Comment> getComments(String appType, String appName, String version, int parentId)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get a count of the comments by usernames. * To get a count of the comments by usernames.
@ -225,8 +235,8 @@ public interface CommentDAO {
* @param uuid uuid of the application * @param uuid uuid of the application
* @return Count of the comments * @return Count of the comments
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
int getCommentCount(String uuid) throws CommentManagementException, DBConnectionException, SQLException; int getCommentCount(String uuid) throws CommentManagementException, DBConnectionException, SQLException;
@ -236,46 +246,49 @@ public interface CommentDAO {
* @param createdBy Username of the created person. * @param createdBy Username of the created person.
* @return Count of the comments * @return Count of the comments
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
int getCommentCountByUser(String createdBy) throws CommentManagementException, DBConnectionException, SQLException; int getCommentCountByUser(String createdBy) throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get the comment count by parent comment id. * To get the comment count by parent comment id.
* *
* @param uuid uuid of the comment * @param uuid uuid of the comment
* @param parentId id of the parent comment * @param parentId id of the parent comment
* @return Count of the comments * @return Count of the comments
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
int getCommentCountByParent(String uuid,int parentId) throws CommentManagementException, DBConnectionException, SQLException; int getCommentCountByParent(String uuid, int parentId)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get a count of comments by modification details. * To get a count of comments by modification details.
* *
* @param modifiedBy Username of the modified person. * @param modifiedBy Username of the modified person.
* @param modifedAt time of the modification * @param modifedAt time of the modification
* @return Count of the comments * @return Count of the comments
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
int getCommentCountByUser(String modifiedBy,Timestamp modifedAt) throws CommentManagementException, DBConnectionException, SQLException; int getCommentCountByUser(String modifiedBy, Timestamp modifedAt)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get count of comments by application versions. * To get count of comments by application versions.
* *
* @param appId id of the commented application. * @param appId id of the commented application.
* @param appReleaseId Id of the released version of the application. * @param appReleaseId Id of the released version of the application.
* @return Count of the comments * @return Count of the comments
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
int getCommentCountByApp(int appId, int appReleaseId) throws CommentManagementException, DBConnectionException, SQLException; int getCommentCountByApp(int appId, int appReleaseId)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get count of comments by application details. * To get count of comments by application details.
@ -285,42 +298,43 @@ public interface CommentDAO {
* @param version version of the commented application. * @param version version of the commented application.
* @return Count of the comments * @return Count of the comments
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
int getCommentCountByApp(String appType,String appName,String version) throws CommentManagementException, DBConnectionException, SQLException; int getCommentCountByApp(String appType, String appName, String version)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To delete comment using comment id. * To delete comment using comment id.
* *
* @param CommentId id of the comment * @param CommentId id of the comment
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
void deleteComment(int CommentId) throws CommentManagementException, DBConnectionException, SQLException; void deleteComment(int CommentId) throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To delete comment using comment id. * To delete comment using comment id.
* *
* @param uuid uuid of the comment * @param uuid uuid of the comment
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
void deleteComment(String uuid) throws CommentManagementException, DBConnectionException, SQLException; void deleteComment(String uuid) throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To delete comments using application details. * To delete comments using application details.
* *
* @param appId id of the commented application. * @param appId id of the commented application.
* @param appReleaseID Id of the released version of the application. * @param appReleaseID Id of the released version of the application.
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
void deleteComments(int appId,int appReleaseID) throws CommentManagementException, DBConnectionException, SQLException; void deleteComments(int appId, int appReleaseID)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To delete comments using application details. * To delete comments using application details.
@ -330,35 +344,34 @@ public interface CommentDAO {
* @param version version of the commented application. * @param version version of the commented application.
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
*/ */
void deleteComments(String appType,String appName,String version)throws CommentManagementException; void deleteComments(String appType, String appName, String version) throws CommentManagementException;
/** /**
* To delete comments using users created and application details. * To delete comments using users created and application details.
* *
* @param appType type of the commented application. * @param appType type of the commented application.
* @param appName name of the commented application. * @param appName name of the commented application.
* @param version version of the commented application. * @param version version of the commented application.
* @param createdBy Username of the created person. * @param createdBy Username of the created person.
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
*/ */
void deleteComments(String appType,String appName,String version,String createdBy)throws CommentManagementException; void deleteComments(String appType, String appName, String version, String createdBy)
throws CommentManagementException;
/** /**
* To delete comments by parent id of the comment. * To delete comments by parent id of the comment.
* *
* @param uuid uuid of the application * @param uuid uuid of the application
* @param parentId parent id of the parent comment. * @param parentId parent id of the parent comment.
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
*/ */
void deleteComments(String uuid,int parentId)throws CommentManagementException; void deleteComments(String uuid, int parentId) throws CommentManagementException;
/** /**
* To add the star rating to the application. * To add the star rating to the application.
* *
* @param stars Star value * @param stars Star value
* @param uuid UUID of the application * @param uuid UUID of the application
* @return Star value * @return Star value
* @throws ApplicationManagementDAOException Application Management DAO Exception. * @throws ApplicationManagementDAOException Application Management DAO Exception.
*/ */
@ -371,7 +384,7 @@ public interface CommentDAO {
* @return Average of star values * @return Average of star values
* @throws ApplicationManagementDAOException Application Management DAO Exception. * @throws ApplicationManagementDAOException Application Management DAO Exception.
*/ */
int getStars(String uuid) throws ApplicationManagementDAOException; int getStars(String uuid) throws ApplicationManagementDAOException;
/** /**
* To get number of rated users * To get number of rated users

@ -236,20 +236,20 @@ public class ApplicationManagementDAOFactory {
} }
} }
public static CommentDAO getCommentDAO() { public static CommentDAO getCommentDAO() {
if (databaseEngine != null) { if (databaseEngine != null) {
switch (databaseEngine) { switch (databaseEngine) {
case Constants.DataBaseTypes.DB_TYPE_H2: case Constants.DataBaseTypes.DB_TYPE_H2:
case Constants.DataBaseTypes.DB_TYPE_MYSQL: case Constants.DataBaseTypes.DB_TYPE_MYSQL:
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL: case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
return new CommentDAOImpl(); return new CommentDAOImpl();
default: default:
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
} }
} }
throw new IllegalStateException("Database engine has not initialized properly."); throw new IllegalStateException("Database engine has not initialized properly.");
} }
}
}

@ -33,6 +33,7 @@ import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagem
import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.Instant; import java.time.Instant;
@ -41,8 +42,7 @@ import java.util.List;
/** /**
* This class is the default implementation for the Managing the comments. * This class is the default implementation for the Managing the comments.
*/ */
@SuppressWarnings( "deprecation" ) @SuppressWarnings("deprecation") public class CommentsManagerImpl implements CommentsManager {
public class CommentsManagerImpl implements CommentsManager {
private static final Log log = LogFactory.getLog(CommentsManagerImpl.class); private static final Log log = LogFactory.getLog(CommentsManagerImpl.class);
private CommentDAO commentDAO; private CommentDAO commentDAO;
@ -52,27 +52,27 @@ public class CommentsManagerImpl implements CommentsManager {
} }
private void initDataAccessObjects() { private void initDataAccessObjects() {
this.commentDAO= ApplicationManagementDAOFactory.getCommentDAO(); this.commentDAO = ApplicationManagementDAOFactory.getCommentDAO();
} }
@Override @Override
public Comment addComment(Comment comment,String uuid,int tenantId) throws CommentManagementException { public Comment addComment(Comment comment, String uuid, int tenantId) throws CommentManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request for comment is received for uuid" +uuid); log.debug("Request for comment is received for uuid" + uuid);
} }
comment.setCreatedAt(Timestamp.from(Instant.now())); comment.setCreatedAt(Timestamp.from(Instant.now()));
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
commentDAO.addComment(tenantId,comment, comment.getCreatedBy(),comment.getParent(),uuid); commentDAO.addComment(tenantId, comment, comment.getCreatedBy(), comment.getParent(), uuid);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return comment; return comment;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw new CommentManagementException("DB Connection Exception occurs.",e); throw new CommentManagementException("DB Connection Exception occurs.", e);
} catch (SQLException | TransactionManagementException e){ } catch (SQLException | TransactionManagementException e) {
throw new CommentManagementException("SQL Exception occurs.",e); throw new CommentManagementException("SQL Exception occurs.", e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@ -83,52 +83,50 @@ public class CommentsManagerImpl implements CommentsManager {
* To validate the pre-request of the comment * To validate the pre-request of the comment
* *
* @param CommentId ID of the comment. * @param CommentId ID of the comment.
* @param comment comment needed to be validate. * @param comment comment needed to be validate.
* @return Application related with the UUID. * @return Application related with the UUID.
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
*
*/ */
public Boolean validateComment(int CommentId,String comment) throws CommentManagementException{ public Boolean validateComment(int CommentId, String comment) throws CommentManagementException {
if (CommentId <= 0) { if (CommentId <= 0) {
throw new CommentManagementException("Comment ID is null or negative. Comment id is a required parameter to get the " + throw new CommentManagementException(
"relevant comment."); "Comment ID is null or negative. Comment id is a required parameter to get the "
+ "relevant comment.");
} }
if(comment==null){ if (comment == null) {
log.error("Null Point Exception.Comment at comment id "+CommentId+" is null."); log.error("Null Point Exception.Comment at comment id " + CommentId + " is null.");
return false; return false;
} }
return true; return true;
} }
@Override @Override
public List<Comment> getAllComments(PaginationRequest request,String uuid) throws CommentManagementException { public List<Comment> getAllComments(PaginationRequest request, String uuid) throws CommentManagementException {
PaginationResult paginationResult = new PaginationResult(); PaginationResult paginationResult = new PaginationResult();
List<Comment> comments; List<Comment> comments;
request = Util.validateCommentListPageSize(request); request = Util.validateCommentListPageSize(request);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("get all comments of the application release"+uuid); log.debug("get all comments of the application release" + uuid);
} }
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
comments=commentDAO.getAllComments(uuid,request); comments = commentDAO.getAllComments(uuid, request);
int count=commentDAO.getCommentCount(request,uuid); int count = commentDAO.getCommentCount(request, uuid);
paginationResult.setData(comments); paginationResult.setData(comments);
paginationResult.setRecordsFiltered(count); paginationResult.setRecordsFiltered(count);
paginationResult.setRecordsTotal(count); paginationResult.setRecordsTotal(count);
return comments; return comments;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new CommentManagementException("DB Connection Exception occurs.", e); throw new CommentManagementException("DB Connection Exception occurs.", e);
} catch (SQLException e){ } catch (SQLException e) {
throw new CommentManagementException("SQL Exception occurs.",e); throw new CommentManagementException("SQL Exception occurs.", e);
}finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
} }
@ -137,7 +135,7 @@ public class CommentsManagerImpl implements CommentsManager {
public Comment getComment(int CommentId) throws CommentManagementException { public Comment getComment(int CommentId) throws CommentManagementException {
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
Comment comment=null; Comment comment = null;
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Comment retrieval request is received for the comment id " + CommentId); log.debug("Comment retrieval request is received for the comment id " + CommentId);
@ -145,7 +143,7 @@ public class CommentsManagerImpl implements CommentsManager {
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
comment=commentDAO.getComment(CommentId); comment = commentDAO.getComment(CommentId);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new CommentManagementException("DB Connection Exception occurs.", e); throw new CommentManagementException("DB Connection Exception occurs.", e);
} catch (SQLException e) { } catch (SQLException e) {
@ -160,11 +158,11 @@ public class CommentsManagerImpl implements CommentsManager {
public void deleteComment(int CommentId) throws CommentManagementException { public void deleteComment(int CommentId) throws CommentManagementException {
Comment comment; Comment comment;
comment= getComment(CommentId); comment = getComment(CommentId);
if (comment == null) { if (comment == null) {
throw new CommentManagementException( throw new CommentManagementException(
"Cannot delete a non-existing comment for the application with comment id" + CommentId); "Cannot delete a non-existing comment for the application with comment id" + CommentId);
} }
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
@ -182,10 +180,10 @@ public class CommentsManagerImpl implements CommentsManager {
} }
@Override @Override
public Comment updateComment(Comment comment,int CommentId) throws CommentManagementException { public Comment updateComment(Comment comment, int CommentId) throws CommentManagementException {
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
validateComment(CommentId,comment.getComment()); validateComment(CommentId, comment.getComment());
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Comment retrieval request is received for the comment id " + CommentId); log.debug("Comment retrieval request is received for the comment id " + CommentId);
@ -196,26 +194,27 @@ public class CommentsManagerImpl implements CommentsManager {
commentDAO.getComment(CommentId); commentDAO.getComment(CommentId);
return commentDAO return commentDAO
.updateComment(CommentId, comment.getComment(), comment.getModifiedBy(), comment.getModifiedAt()); .updateComment(CommentId, comment.getComment(), comment.getModifiedBy(), comment.getModifiedAt());
} catch (SQLException e){ } catch (SQLException e) {
throw new CommentManagementException("SQL Exception occurs.",e); throw new CommentManagementException("SQL Exception occurs.", e);
}catch (DBConnectionException e){ } catch (DBConnectionException e) {
throw new CommentManagementException("DB Connection occurs.",e); throw new CommentManagementException("DB Connection occurs.", e);
}finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
} }
@Override
public int getRatedUser(String uuid) throws ApplicationManagementException { public int getRatedUser(String uuid) throws ApplicationManagementException {
int ratedUsers=0; int ratedUsers = 0;
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Get the rated users for the application release number"+uuid); log.debug("Get the rated users for the application release number" + uuid);
} }
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
ratedUsers =commentDAO.getRatedUser(uuid); ratedUsers = commentDAO.getRatedUser(uuid);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementException("DB Connection Exception occurs",e); throw new ApplicationManagementException("DB Connection Exception occurs", e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
throw new ApplicationManagementException("Application Management Exception occurs.", e); throw new ApplicationManagementException("Application Management Exception occurs.", e);
} finally { } finally {
@ -227,40 +226,40 @@ public class CommentsManagerImpl implements CommentsManager {
@Override @Override
public int getStars(String uuid) throws ApplicationManagementException { public int getStars(String uuid) throws ApplicationManagementException {
int stars=0; int stars = 0;
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Get the average of rated stars for the application "+uuid); log.debug("Get the average of rated stars for the application " + uuid);
} }
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
stars= commentDAO.getStars(uuid); stars = commentDAO.getStars(uuid);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementException("DB Connection Exception occurs",e); throw new ApplicationManagementException("DB Connection Exception occurs", e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
throw new ApplicationManagementException("Application Management Exception occurs.", e); throw new ApplicationManagementException("Application Management Exception occurs.", e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
return stars; return stars;
} }
@Override @Override
public int updateStars(int stars , String uuid) throws ApplicationManagementException { public int updateStars(int stars, String uuid) throws ApplicationManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Stars are received for the application " + uuid); log.debug("Stars are received for the application " + uuid);
} }
int newStars=0; int newStars = 0;
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
int ratedUsers = commentDAO.getRatedUser(uuid); int ratedUsers = commentDAO.getRatedUser(uuid);
int oldStars = commentDAO.getStars(uuid); int oldStars = commentDAO.getStars(uuid);
if(ratedUsers==0){ if (ratedUsers == 0) {
newStars=commentDAO.updateStars(stars,uuid); newStars = commentDAO.updateStars(stars, uuid);
return newStars; return newStars;
}else { } else {
int avgStars = ((oldStars*ratedUsers)+stars) / (ratedUsers+1); int avgStars = ((oldStars * ratedUsers) + stars) / (ratedUsers + 1);
newStars = commentDAO.updateStars(avgStars, uuid); newStars = commentDAO.updateStars(avgStars, uuid);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return newStars; return newStars;
@ -268,10 +267,9 @@ public class CommentsManagerImpl implements CommentsManager {
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException("Application Management Exception occurs.", e); throw new ApplicationManagementException("Application Management Exception occurs.", e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementException("DB Connection Exception occurs.", e); throw new ApplicationManagementException("DB Connection Exception occurs.", e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
} }

Loading…
Cancel
Save