mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Reformatted the code.
This commit is contained in:
parent
1bbd0b1aa5
commit
3bfb2addbb
@ -62,17 +62,16 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
|
||||
CommentsManager commentsManager = APIUtil.getCommentsManager();
|
||||
List<Comment> comments = new ArrayList<>();
|
||||
try {
|
||||
PaginationRequest request=new PaginationRequest(offSet,limit);
|
||||
if(request.validatePaginationRequest(offSet,limit)) {
|
||||
PaginationRequest request = new PaginationRequest(offSet, limit);
|
||||
if (request.validatePaginationRequest(offSet, limit)) {
|
||||
commentsManager.getAllComments(request, uuid);
|
||||
return Response.status(Response.Status.OK).entity(comments).build();
|
||||
}
|
||||
} catch (NotFoundException e){
|
||||
log.error("Not found exception occurs to uuid "+uuid+" .",e);
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
.entity("Application with UUID " + uuid + " not found").build();
|
||||
}
|
||||
catch (CommentManagementException e) {
|
||||
} catch (NotFoundException e) {
|
||||
log.error("Not found exception occurs to uuid " + uuid + " .", e);
|
||||
return Response.status(Response.Status.NOT_FOUND).entity("Application with UUID " + uuid + " not found")
|
||||
.build();
|
||||
} catch (CommentManagementException e) {
|
||||
String msg = "Error occurred while retrieving comments.";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||
@ -89,17 +88,17 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
|
||||
@PathParam("uuid") String uuid){
|
||||
|
||||
CommentsManager commentsManager = APIUtil.getCommentsManager();
|
||||
int tenantId= PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
try {
|
||||
Comment newComment = commentsManager.addComment(comment,uuid,tenantId);
|
||||
if (comment != null){
|
||||
Comment newComment = commentsManager.addComment(comment, uuid, tenantId);
|
||||
if (comment != null) {
|
||||
return Response.status(Response.Status.CREATED).entity(newComment).build();
|
||||
}else{
|
||||
} else {
|
||||
String msg = "Given comment is not valid ";
|
||||
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";
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||
@ -115,17 +114,16 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
|
||||
@PathParam("CommentId") int CommentId) {
|
||||
|
||||
CommentsManager commentsManager = APIUtil.getCommentsManager();
|
||||
|
||||
try {
|
||||
if (CommentId == 0) {
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
.entity("Comment with comment id " + CommentId + " not found").build();
|
||||
}else if(comment==null){
|
||||
} else if (comment == null) {
|
||||
String msg = "Given comment is not valid ";
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
} else{
|
||||
comment = commentsManager.updateComment(comment,CommentId);
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
} else {
|
||||
comment = commentsManager.updateComment(comment, CommentId);
|
||||
return Response.status(Response.Status.OK).entity(comment).build();
|
||||
}
|
||||
} catch (CommentManagementException e) {
|
||||
@ -150,9 +148,8 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
|
||||
log.error(msg, e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||
} catch (NotFoundException e) {
|
||||
log.error("Not found exception occurs to comment id "+CommentId+" .",e);
|
||||
return Response.status(Response.Status.NOT_FOUND)
|
||||
.entity("Comment with" + CommentId + " not found").build();
|
||||
log.error("Not found exception occurs to comment id " + CommentId + " .", e);
|
||||
return Response.status(Response.Status.NOT_FOUND).entity("Comment with" + CommentId + " not found").build();
|
||||
}
|
||||
return Response.status(Response.Status.OK).entity("Comment is deleted successfully.").build();
|
||||
}
|
||||
@ -165,15 +162,14 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
|
||||
String uuid) {
|
||||
|
||||
CommentsManager commentsManager = APIUtil.getCommentsManager();
|
||||
int Stars=0;
|
||||
|
||||
int Stars = 0;
|
||||
try {
|
||||
Stars= commentsManager.getStars(uuid);
|
||||
} catch (CommentManagementException e) {
|
||||
log.error("Comment Management Exception occurs",e);
|
||||
Stars = commentsManager.getStars(uuid);
|
||||
} catch (CommentManagementException e) {
|
||||
log.error("Comment Management Exception occurs", e);
|
||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
|
||||
} 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.OK).entity(Stars).build();
|
||||
@ -187,15 +183,14 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
|
||||
String uuid){
|
||||
|
||||
CommentsManager commentsManager = APIUtil.getCommentsManager();
|
||||
int ratedUsers=0;
|
||||
|
||||
int ratedUsers = 0;
|
||||
try {
|
||||
ratedUsers= commentsManager.getRatedUser(uuid);
|
||||
ratedUsers = commentsManager.getRatedUser(uuid);
|
||||
} 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();
|
||||
} 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.OK).entity(ratedUsers).build();
|
||||
@ -209,21 +204,20 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
|
||||
@PathParam("uuid") String uuid) {
|
||||
|
||||
CommentsManager commentsManager = APIUtil.getCommentsManager();
|
||||
int newStars=0;
|
||||
|
||||
int newStars = 0;
|
||||
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();
|
||||
}else{
|
||||
} else {
|
||||
String msg = "Given star value is not valid ";
|
||||
log.error(msg);
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
||||
}
|
||||
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
|
||||
@ -51,7 +51,6 @@ public class Comment {
|
||||
this.tenantId = tenantId;
|
||||
}
|
||||
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@ -18,9 +18,6 @@
|
||||
|
||||
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.
|
||||
*/
|
||||
@ -50,19 +47,17 @@ public class PaginationRequest {
|
||||
this.limit = limit;
|
||||
}
|
||||
|
||||
public boolean validatePaginationRequest(int offSet,int limit){
|
||||
if (offSet<0){
|
||||
public boolean validatePaginationRequest(int offSet, int limit) {
|
||||
if (offSet < 0) {
|
||||
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");
|
||||
}else {
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
@Override public String toString() {
|
||||
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;
|
||||
|
||||
import org.wso2.carbon.device.application.mgt.common.Comment;
|
||||
|
||||
public class CommentManagementException extends Exception{
|
||||
public class CommentManagementException extends Exception {
|
||||
private String message;
|
||||
|
||||
public CommentManagementException(String message, Throwable throwable) {
|
||||
@ -18,8 +34,8 @@ public class CommentManagementException extends Exception{
|
||||
public CommentManagementException() {
|
||||
|
||||
}
|
||||
@Override
|
||||
public String getMessage() {
|
||||
|
||||
@Override public String getMessage() {
|
||||
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.exception.ApplicationManagementException;
|
||||
import org.wso2.carbon.device.application.mgt.common.exception.CommentManagementException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* CommentsManager is responsible for handling all the add/update/delete/get operations related with
|
||||
*
|
||||
*/
|
||||
public interface CommentsManager {
|
||||
|
||||
/**
|
||||
* To add a comment to a application
|
||||
*
|
||||
* @param comment comment of the application.
|
||||
* @param uuid uuid of the application release
|
||||
* @param comment comment of the application.
|
||||
* @param uuid uuid of the application release
|
||||
* @param tenantId tenant id of the application
|
||||
* @return {@link Comment} Comment added
|
||||
* @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
|
||||
*
|
||||
* @param CommentId ID of the comment.
|
||||
* @param comment comment needed to be validate.
|
||||
* @param comment comment needed to be validate.
|
||||
* @return validated the comment.
|
||||
* @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
|
||||
*
|
||||
* @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
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
*/
|
||||
List<Comment> getAllComments(PaginationRequest request, String uuid) throws CommentManagementException;
|
||||
|
||||
|
||||
/**
|
||||
* To get the comment with id.
|
||||
*
|
||||
@ -71,7 +69,7 @@ public interface CommentsManager {
|
||||
* @return {@link Comment}Comment of the comment id
|
||||
* @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.
|
||||
@ -81,23 +79,22 @@ public interface CommentsManager {
|
||||
*/
|
||||
void deleteComment(int CommentId) throws CommentManagementException;
|
||||
|
||||
|
||||
/**
|
||||
* To update a comment.
|
||||
*
|
||||
* @param comment comment of the application.
|
||||
* @param comment comment of the application.
|
||||
* @param CommentId id of the comment
|
||||
* @return {@link Comment}updated comment
|
||||
* @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
|
||||
*
|
||||
* @param uuid uuid of the application
|
||||
* @return number of rated users
|
||||
* @throws CommentManagementException Exceptions of the comment management
|
||||
* @throws CommentManagementException Exceptions of the comment management
|
||||
* @throws ApplicationManagementException Application Management Exception.
|
||||
*/
|
||||
int getRatedUser(String uuid) throws CommentManagementException, ApplicationManagementException;
|
||||
@ -107,7 +104,7 @@ public interface CommentsManager {
|
||||
*
|
||||
* @param uuid uuid of the comment
|
||||
* @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.
|
||||
*/
|
||||
int getStars(String uuid) throws CommentManagementException, ApplicationManagementException;
|
||||
@ -116,7 +113,7 @@ public interface CommentsManager {
|
||||
* To update rating stars
|
||||
*
|
||||
* @param stars amount of stars
|
||||
* @param uuid uuid of the application
|
||||
* @param uuid uuid of the application
|
||||
* @return value of the added stars
|
||||
* @throws ApplicationManagementException Application Management Exception.
|
||||
*/
|
||||
|
||||
@ -24,8 +24,7 @@ import javax.xml.bind.annotation.XmlRootElement;
|
||||
/**
|
||||
* This class represents the information related to Pagination configuration.
|
||||
*/
|
||||
@XmlRootElement(name = "PaginationConfiguration")
|
||||
public class PaginationConfiguration {
|
||||
@XmlRootElement(name = "PaginationConfiguration") public class PaginationConfiguration {
|
||||
|
||||
private int commentListPageSize;
|
||||
|
||||
@ -33,8 +32,8 @@ public class PaginationConfiguration {
|
||||
return commentListPageSize;
|
||||
}
|
||||
|
||||
@XmlElement(name = "commentListPageSize", required = true)
|
||||
public void setCommentListPageSize(int commentListPageSize) {
|
||||
@XmlElement(name = "commentListPageSize", required = true) public void setCommentListPageSize(
|
||||
int commentListPageSize) {
|
||||
this.commentListPageSize = commentListPageSize;
|
||||
}
|
||||
|
||||
|
||||
@ -32,64 +32,67 @@ import java.util.List;
|
||||
* This interface specifies the database access operations performed for comments.
|
||||
*/
|
||||
|
||||
@SuppressWarnings("ALL")
|
||||
public interface CommentDAO {
|
||||
@SuppressWarnings("ALL") public interface CommentDAO {
|
||||
|
||||
/**
|
||||
* To add a comment to a application.
|
||||
*
|
||||
* @param tenantId tenantId of the commented application.
|
||||
* @param comment comment of the application.
|
||||
* @param tenantId tenantId of the commented application.
|
||||
* @param comment comment of the application.
|
||||
* @param createdBy Username of the created person.
|
||||
* @param parentId parent id of the parent comment.
|
||||
* @param uuid uuid of the application
|
||||
* @param parentId parent id of the parent comment.
|
||||
* @param uuid uuid of the application
|
||||
* @return Comment Id
|
||||
* @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.
|
||||
*
|
||||
* @param comment comment of the application.
|
||||
* @param comment comment of the application.
|
||||
* @param createdBy Username of the created person.
|
||||
* @param appType type of the commented application.
|
||||
* @param appName name of the commented application.
|
||||
* @param version version of the commented application.
|
||||
* @param appType type of the commented application.
|
||||
* @param appName name of the commented application.
|
||||
* @param version version of the commented application.
|
||||
* @return comment id
|
||||
* @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.
|
||||
*
|
||||
* @param CommentId id of the comment
|
||||
* @param CommentId id of the comment
|
||||
* @param updatedComment comment after updated
|
||||
* @param modifiedBy Username of the modified person.
|
||||
* @param modifiedAt time of the modification.
|
||||
* @param modifiedBy Username of the modified person.
|
||||
* @param modifiedAt time of the modification.
|
||||
* @return {@link Comment}Updated comment
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection 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.
|
||||
*
|
||||
* @param uuid uuid of the comment
|
||||
* @param CommentId id of the comment
|
||||
* @param uuid uuid of the comment
|
||||
* @param CommentId id of the comment
|
||||
* @param updatedComment comment after updated
|
||||
* @param modifiedBy Username of the modified person.
|
||||
* @param modifiedAt time of the modification.
|
||||
* @param modifiedBy Username of the modified person.
|
||||
* @param modifiedAt time of the modification.
|
||||
* @return {@link Comment}Updated comment
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection 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.
|
||||
@ -97,8 +100,8 @@ public interface CommentDAO {
|
||||
* @param CommentId id of the comment
|
||||
* @return {@link Comment}Comment
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection exception
|
||||
* @throws SQLException sql exception
|
||||
*/
|
||||
Comment getComment(int CommentId) throws CommentManagementException, SQLException, DBConnectionException;
|
||||
|
||||
@ -108,32 +111,33 @@ public interface CommentDAO {
|
||||
* @param uuid uuid of the comment
|
||||
* @return {@link List} List of comments in the application
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection exception
|
||||
* @throws SQLException sql exception
|
||||
*/
|
||||
List<Comment> getComment(String uuid) throws CommentManagementException, SQLException, DBConnectionException;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return {@link List}List of all the comments in an application
|
||||
* @throws CommentManagementException Exception of the comment management
|
||||
* @throws DBConnectionException db connection exception
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection 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.
|
||||
*
|
||||
* @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
|
||||
* @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.
|
||||
@ -143,10 +147,11 @@ public interface CommentDAO {
|
||||
* @param version version of the commented application.
|
||||
* @return {@link List}List of comments
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection 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.
|
||||
@ -154,8 +159,8 @@ public interface CommentDAO {
|
||||
* @param tenantId tenant id of the commented application
|
||||
* @return {@link List}List of comments
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
*/
|
||||
List<Comment> getComments(int tenantId) throws CommentManagementException, DBConnectionException, SQLException;
|
||||
|
||||
@ -165,10 +170,11 @@ public interface CommentDAO {
|
||||
* @param createdBy Username of the created person.
|
||||
* @return {@link List}List of comments
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection 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.
|
||||
@ -177,10 +183,11 @@ public interface CommentDAO {
|
||||
* @param createdAt time of the comment created.
|
||||
* @return {@link List}List of comments
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection 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.
|
||||
@ -188,10 +195,11 @@ public interface CommentDAO {
|
||||
* @param modifiedBy Username of the modified person.
|
||||
* @return {@link List}List of comments
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection 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.
|
||||
@ -199,25 +207,27 @@ public interface CommentDAO {
|
||||
* @param modifiedBy Username of the modified person.
|
||||
* @param modifiedAt time of the modification
|
||||
* @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 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.
|
||||
*
|
||||
* @param appType type of the commented application.
|
||||
* @param appName name of the commented application.
|
||||
* @param version version of the commented application.
|
||||
* @param appType type of the commented application.
|
||||
* @param appName name of the commented application.
|
||||
* @param version version of the commented application.
|
||||
* @param parentId parent id of the parent comment.
|
||||
* @return {@link List}List of comments
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection 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.
|
||||
@ -225,8 +235,8 @@ public interface CommentDAO {
|
||||
* @param uuid uuid of the application
|
||||
* @return Count of the comments
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
*/
|
||||
int getCommentCount(String uuid) throws CommentManagementException, DBConnectionException, SQLException;
|
||||
|
||||
@ -236,46 +246,49 @@ public interface CommentDAO {
|
||||
* @param createdBy Username of the created person.
|
||||
* @return Count of the comments
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
*/
|
||||
int getCommentCountByUser(String createdBy) throws CommentManagementException, DBConnectionException, SQLException;
|
||||
|
||||
/**
|
||||
* 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
|
||||
* @return Count of the comments
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection 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.
|
||||
*
|
||||
* @param modifiedBy Username of the modified person.
|
||||
* @param modifedAt time of the modification
|
||||
* @param modifedAt time of the modification
|
||||
* @return Count of the comments
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection 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.
|
||||
*
|
||||
* @param appId id of the commented application.
|
||||
* @param appId id of the commented application.
|
||||
* @param appReleaseId Id of the released version of the application.
|
||||
* @return Count of the comments
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection 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.
|
||||
@ -285,42 +298,43 @@ public interface CommentDAO {
|
||||
* @param version version of the commented application.
|
||||
* @return Count of the comments
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection 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.
|
||||
*
|
||||
* @param CommentId id of the comment
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
*/
|
||||
void deleteComment(int CommentId) throws CommentManagementException, DBConnectionException, SQLException;
|
||||
|
||||
|
||||
/**
|
||||
* To delete comment using comment id.
|
||||
*
|
||||
* @param uuid uuid of the comment
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
*/
|
||||
void deleteComment(String uuid) throws CommentManagementException, DBConnectionException, SQLException;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @throws CommentManagementException Exceptions of the comment management.
|
||||
* @throws DBConnectionException db connection exception.
|
||||
* @throws SQLException sql exception
|
||||
* @throws DBConnectionException db connection 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.
|
||||
@ -330,35 +344,34 @@ public interface CommentDAO {
|
||||
* @param version version of the commented application.
|
||||
* @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.
|
||||
*
|
||||
* @param appType type of the commented application.
|
||||
* @param appName name of the commented application.
|
||||
* @param version version of the commented application.
|
||||
* @param appType type of the commented application.
|
||||
* @param appName name of the commented application.
|
||||
* @param version version of the commented application.
|
||||
* @param createdBy Username of the created person.
|
||||
* @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.
|
||||
*
|
||||
* @param uuid uuid of the application
|
||||
* @param uuid uuid of the application
|
||||
* @param parentId parent id of the parent comment.
|
||||
* @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.
|
||||
*
|
||||
* @param stars Star value
|
||||
* @param uuid UUID of the application
|
||||
* @param uuid UUID of the application
|
||||
* @return Star value
|
||||
* @throws ApplicationManagementDAOException Application Management DAO Exception.
|
||||
*/
|
||||
@ -371,7 +384,7 @@ public interface CommentDAO {
|
||||
* @return Average of star values
|
||||
* @throws ApplicationManagementDAOException Application Management DAO Exception.
|
||||
*/
|
||||
int getStars(String uuid) throws ApplicationManagementDAOException;
|
||||
int getStars(String uuid) throws ApplicationManagementDAOException;
|
||||
|
||||
/**
|
||||
* To get number of rated users
|
||||
|
||||
@ -236,20 +236,20 @@ public class ApplicationManagementDAOFactory {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static CommentDAO getCommentDAO() {
|
||||
if (databaseEngine != null) {
|
||||
switch (databaseEngine) {
|
||||
case Constants.DataBaseTypes.DB_TYPE_H2:
|
||||
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
|
||||
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
|
||||
return new CommentDAOImpl();
|
||||
default:
|
||||
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
|
||||
case Constants.DataBaseTypes.DB_TYPE_H2:
|
||||
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
|
||||
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
|
||||
return new CommentDAOImpl();
|
||||
default:
|
||||
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
|
||||
}
|
||||
}
|
||||
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.exception.ApplicationManagementDAOException;
|
||||
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Timestamp;
|
||||
import java.time.Instant;
|
||||
@ -41,8 +42,7 @@ import java.util.List;
|
||||
/**
|
||||
* This class is the default implementation for the Managing the comments.
|
||||
*/
|
||||
@SuppressWarnings( "deprecation" )
|
||||
public class CommentsManagerImpl implements CommentsManager {
|
||||
@SuppressWarnings("deprecation") public class CommentsManagerImpl implements CommentsManager {
|
||||
|
||||
private static final Log log = LogFactory.getLog(CommentsManagerImpl.class);
|
||||
private CommentDAO commentDAO;
|
||||
@ -52,27 +52,27 @@ public class CommentsManagerImpl implements CommentsManager {
|
||||
}
|
||||
|
||||
private void initDataAccessObjects() {
|
||||
this.commentDAO= ApplicationManagementDAOFactory.getCommentDAO();
|
||||
this.commentDAO = ApplicationManagementDAOFactory.getCommentDAO();
|
||||
}
|
||||
|
||||
@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()) {
|
||||
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()));
|
||||
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
commentDAO.addComment(tenantId,comment, comment.getCreatedBy(),comment.getParent(),uuid);
|
||||
commentDAO.addComment(tenantId, comment, comment.getCreatedBy(), comment.getParent(), uuid);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return comment;
|
||||
} catch (DBConnectionException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new CommentManagementException("DB Connection Exception occurs.",e);
|
||||
} catch (SQLException | TransactionManagementException e){
|
||||
throw new CommentManagementException("SQL Exception occurs.",e);
|
||||
throw new CommentManagementException("DB Connection Exception occurs.", e);
|
||||
} catch (SQLException | TransactionManagementException e) {
|
||||
throw new CommentManagementException("SQL Exception occurs.", e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
@ -83,52 +83,50 @@ public class CommentsManagerImpl implements CommentsManager {
|
||||
* To validate the pre-request 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.
|
||||
* @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) {
|
||||
throw new CommentManagementException("Comment ID is null or negative. Comment id is a required parameter to get the " +
|
||||
"relevant comment.");
|
||||
throw new CommentManagementException(
|
||||
"Comment ID is null or negative. Comment id is a required parameter to get the "
|
||||
+ "relevant comment.");
|
||||
}
|
||||
if(comment==null){
|
||||
log.error("Null Point Exception.Comment at comment id "+CommentId+" is null.");
|
||||
return false;
|
||||
if (comment == null) {
|
||||
log.error("Null Point Exception.Comment at comment id " + CommentId + " is null.");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@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();
|
||||
List<Comment> comments;
|
||||
request = Util.validateCommentListPageSize(request);
|
||||
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("get all comments of the application release"+uuid);
|
||||
log.debug("get all comments of the application release" + uuid);
|
||||
}
|
||||
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
comments=commentDAO.getAllComments(uuid,request);
|
||||
int count=commentDAO.getCommentCount(request,uuid);
|
||||
comments = commentDAO.getAllComments(uuid, request);
|
||||
int count = commentDAO.getCommentCount(request, uuid);
|
||||
paginationResult.setData(comments);
|
||||
paginationResult.setRecordsFiltered(count);
|
||||
paginationResult.setRecordsTotal(count);
|
||||
|
||||
return comments;
|
||||
} catch (DBConnectionException e) {
|
||||
throw new CommentManagementException("DB Connection Exception occurs.", e);
|
||||
} catch (SQLException e){
|
||||
throw new CommentManagementException("SQL Exception occurs.",e);
|
||||
}finally {
|
||||
throw new CommentManagementException("DB Connection Exception occurs.", e);
|
||||
} catch (SQLException e) {
|
||||
throw new CommentManagementException("SQL Exception occurs.", e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
@ -137,7 +135,7 @@ public class CommentsManagerImpl implements CommentsManager {
|
||||
public Comment getComment(int CommentId) throws CommentManagementException {
|
||||
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
Comment comment=null;
|
||||
Comment comment = null;
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Comment retrieval request is received for the comment id " + CommentId);
|
||||
@ -145,7 +143,7 @@ public class CommentsManagerImpl implements CommentsManager {
|
||||
|
||||
try {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
comment=commentDAO.getComment(CommentId);
|
||||
comment = commentDAO.getComment(CommentId);
|
||||
} catch (DBConnectionException e) {
|
||||
throw new CommentManagementException("DB Connection Exception occurs.", e);
|
||||
} catch (SQLException e) {
|
||||
@ -160,11 +158,11 @@ public class CommentsManagerImpl implements CommentsManager {
|
||||
public void deleteComment(int CommentId) throws CommentManagementException {
|
||||
|
||||
Comment comment;
|
||||
comment= getComment(CommentId);
|
||||
comment = getComment(CommentId);
|
||||
|
||||
if (comment == null) {
|
||||
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 {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
@ -182,10 +180,10 @@ public class CommentsManagerImpl implements CommentsManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Comment updateComment(Comment comment,int CommentId) throws CommentManagementException {
|
||||
public Comment updateComment(Comment comment, int CommentId) throws CommentManagementException {
|
||||
|
||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||
validateComment(CommentId,comment.getComment());
|
||||
validateComment(CommentId, comment.getComment());
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Comment retrieval request is received for the comment id " + CommentId);
|
||||
@ -196,26 +194,27 @@ public class CommentsManagerImpl implements CommentsManager {
|
||||
commentDAO.getComment(CommentId);
|
||||
return commentDAO
|
||||
.updateComment(CommentId, comment.getComment(), comment.getModifiedBy(), comment.getModifiedAt());
|
||||
} catch (SQLException e){
|
||||
throw new CommentManagementException("SQL Exception occurs.",e);
|
||||
}catch (DBConnectionException e){
|
||||
throw new CommentManagementException("DB Connection occurs.",e);
|
||||
}finally {
|
||||
} catch (SQLException e) {
|
||||
throw new CommentManagementException("SQL Exception occurs.", e);
|
||||
} catch (DBConnectionException e) {
|
||||
throw new CommentManagementException("DB Connection occurs.", e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getRatedUser(String uuid) throws ApplicationManagementException {
|
||||
|
||||
int ratedUsers=0;
|
||||
int ratedUsers = 0;
|
||||
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 {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
ratedUsers =commentDAO.getRatedUser(uuid);
|
||||
ratedUsers = commentDAO.getRatedUser(uuid);
|
||||
} catch (DBConnectionException e) {
|
||||
throw new ApplicationManagementException("DB Connection Exception occurs",e);
|
||||
throw new ApplicationManagementException("DB Connection Exception occurs", e);
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
throw new ApplicationManagementException("Application Management Exception occurs.", e);
|
||||
} finally {
|
||||
@ -227,40 +226,40 @@ public class CommentsManagerImpl implements CommentsManager {
|
||||
@Override
|
||||
public int getStars(String uuid) throws ApplicationManagementException {
|
||||
|
||||
int stars=0;
|
||||
int stars = 0;
|
||||
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 {
|
||||
ConnectionManagerUtil.openDBConnection();
|
||||
stars= commentDAO.getStars(uuid);
|
||||
stars = commentDAO.getStars(uuid);
|
||||
} catch (DBConnectionException e) {
|
||||
throw new ApplicationManagementException("DB Connection Exception occurs",e);
|
||||
throw new ApplicationManagementException("DB Connection Exception occurs", e);
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
throw new ApplicationManagementException("Application Management Exception occurs.", e);
|
||||
} finally {
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
return stars;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int updateStars(int stars , String uuid) throws ApplicationManagementException {
|
||||
public int updateStars(int stars, String uuid) throws ApplicationManagementException {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Stars are received for the application " + uuid);
|
||||
}
|
||||
int newStars=0;
|
||||
int newStars = 0;
|
||||
try {
|
||||
ConnectionManagerUtil.beginDBTransaction();
|
||||
|
||||
int ratedUsers = commentDAO.getRatedUser(uuid);
|
||||
int oldStars = commentDAO.getStars(uuid);
|
||||
if(ratedUsers==0){
|
||||
newStars=commentDAO.updateStars(stars,uuid);
|
||||
if (ratedUsers == 0) {
|
||||
newStars = commentDAO.updateStars(stars, uuid);
|
||||
return newStars;
|
||||
}else {
|
||||
int avgStars = ((oldStars*ratedUsers)+stars) / (ratedUsers+1);
|
||||
} else {
|
||||
int avgStars = ((oldStars * ratedUsers) + stars) / (ratedUsers + 1);
|
||||
newStars = commentDAO.updateStars(avgStars, uuid);
|
||||
ConnectionManagerUtil.commitDBTransaction();
|
||||
return newStars;
|
||||
@ -268,10 +267,9 @@ public class CommentsManagerImpl implements CommentsManager {
|
||||
} catch (ApplicationManagementDAOException e) {
|
||||
ConnectionManagerUtil.rollbackDBTransaction();
|
||||
throw new ApplicationManagementException("Application Management Exception occurs.", e);
|
||||
|
||||
} catch (DBConnectionException e) {
|
||||
throw new ApplicationManagementException("DB Connection Exception occurs.", e);
|
||||
} finally {
|
||||
throw new ApplicationManagementException("DB Connection Exception occurs.", e);
|
||||
} finally {
|
||||
ConnectionManagerUtil.closeDBConnection();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user