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,11 +23,11 @@ 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 {
@ -40,7 +40,7 @@ public interface CommentsManager {
* @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
@ -49,9 +49,8 @@ public interface CommentsManager {
* @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
@ -63,7 +62,6 @@ public interface CommentsManager {
*/ */
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,7 +79,6 @@ public interface CommentsManager {
*/ */
void deleteComment(int CommentId) throws CommentManagementException; void deleteComment(int CommentId) throws CommentManagementException;
/** /**
* To update a comment. * To update a comment.
* *
@ -90,7 +87,7 @@ public interface CommentsManager {
* @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

@ -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,8 +32,7 @@ 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.
@ -47,7 +46,8 @@ public interface CommentDAO {
* @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.
@ -60,7 +60,8 @@ public interface CommentDAO {
* @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.
@ -74,7 +75,8 @@ public interface CommentDAO {
* @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.
@ -89,7 +91,8 @@ public interface CommentDAO {
* @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.
@ -123,7 +126,8 @@ public interface CommentDAO {
* @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.
@ -133,7 +137,7 @@ public interface CommentDAO {
* @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.
@ -146,7 +150,8 @@ public interface CommentDAO {
* @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.
@ -168,7 +173,8 @@ public interface CommentDAO {
* @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.
@ -180,7 +186,8 @@ public interface CommentDAO {
* @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.
@ -191,7 +198,8 @@ public interface CommentDAO {
* @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.
@ -203,7 +211,8 @@ public interface CommentDAO {
* @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.
@ -217,7 +226,8 @@ public interface CommentDAO {
* @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.
@ -251,7 +261,8 @@ public interface CommentDAO {
* @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.
@ -263,7 +274,8 @@ public interface CommentDAO {
* @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.
@ -275,7 +287,8 @@ public interface CommentDAO {
* @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.
@ -288,7 +301,8 @@ public interface CommentDAO {
* @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.
@ -300,7 +314,6 @@ public interface CommentDAO {
*/ */
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.
* *
@ -320,7 +333,8 @@ public interface CommentDAO {
* @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,7 +344,7 @@ 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.
@ -341,8 +355,8 @@ public interface CommentDAO {
* @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.
@ -351,8 +365,7 @@ public interface CommentDAO {
* @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.

@ -236,7 +236,6 @@ public class ApplicationManagementDAOFactory {
} }
} }
public static CommentDAO getCommentDAO() { public static CommentDAO getCommentDAO() {
if (databaseEngine != null) { if (databaseEngine != null) {
switch (databaseEngine) { switch (databaseEngine) {
@ -250,6 +249,7 @@ public class ApplicationManagementDAOFactory {
} }
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();
} }
@ -86,39 +86,37 @@ public class CommentsManagerImpl implements CommentsManager {
* @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);
@ -126,9 +124,9 @@ public class CommentsManagerImpl implements CommentsManager {
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,7 +158,7 @@ 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(
@ -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,15 +226,15 @@ 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 {
@ -245,22 +244,22 @@ public class CommentsManagerImpl implements CommentsManager {
} }
@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,7 +267,6 @@ 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 {

Loading…
Cancel
Save