From 627aaab233cfbb1486e13dc9adbd72c8a67510e0 Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 15:35:03 +0530 Subject: [PATCH 01/56] Adding Comment Management API --- .../api/services/CommentManagementAPI.java | 399 ++++++++++++++++++ 1 file changed, 399 insertions(+) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java new file mode 100644 index 0000000000..ac80295ad0 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java @@ -0,0 +1,399 @@ +package org.wso2.carbon.device.application.mgt.api.services; + +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.Api; +import io.swagger.annotations.Info; +import io.swagger.annotations.SwaggerDefinition; +import io.swagger.annotations.Extension; +import io.swagger.annotations.ExtensionProperty; +import io.swagger.annotations.Tag; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; +import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse; +import org.wso2.carbon.device.application.mgt.common.Comment; + +import javax.validation.Valid; +import javax.ws.rs.Path; +import javax.ws.rs.Consumes; +import javax.ws.rs.PUT; +import javax.ws.rs.GET; +import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; +import javax.ws.rs.Produces; +import javax.ws.rs.POST; +import javax.ws.rs.DELETE; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; +import java.sql.SQLException; +import java.util.List; + + /** + * APIs to handle comment management related tasks. + */ +@SwaggerDefinition( + info = @Info( + version = "1.0.0", + title = "Store Management Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = "name", value = "CommentManagementService"), + @ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/comments"), + }) + } + ), + tags = { + @Tag(name = "store_management", description = "Comment Management related " + + "APIs") + } +) +@Scopes( + scopes = { + @Scope( + name = "Get Comments Details", + description = "Get comments details", + key = "perm:comment:get", + permissions = {"/device-mgt/comment/get"} + ), + @Scope( + name = "Add a Comment", + description = "Add a comment", + key = "perm:comment:add", + permissions = {"/device-mgt/comment/add"} + ), + @Scope( + name = "Update a Comment", + description = "Update a Comment", + key = "perm:comment:update", + permissions = {"/device-mgt/comment/update"} + ), + + @Scope( + name = "Delete a Comment", + description = "Delete a comment", + key = "perm:comment:delete", + permissions = {"/device-mgt/comment/delete"} + ), + } +) + +@Path("/comments") +@Api(value = "Comments Management", description = "This API carries all comments management related operations " + + "such as get all the comments, add comment, etc.") +@Produces(MediaType.APPLICATION_JSON) + +public interface CommentManagementAPI { + String SCOPE = "scope"; + + @GET + @Path("/{uuid}") + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "get comments", + notes = "Get all comments", + tags = "Store Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:store:get") + }) + } + ) + + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully retrieved comments.", + response = List.class, + responseContainer = "List"), + @ApiResponse( + code = 404, + message = "Not Found. \n No activity found with the given ID.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while getting the comment list.", + response = ErrorResponse.class) + }) + + Response getAllComments( + @ApiParam( + name="uuid", + value="uuid of the released version of application.", + required = true) + @PathParam("uuid") + String uuid, + @ApiParam( + name="offSet", + value="Starting comment number.", + required = false) + @QueryParam("offSet") + int offSet, + @ApiParam( + name="limit", + value = "Limit of paginated comments", + required = false) + @QueryParam("limit") + int limit); + + @POST + @Path("/{uuid}") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Add a comment", + notes = "This will add a new comment", + tags = "Store Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:store:add") + }) + } + ) + + @ApiResponses( + value = { + @ApiResponse( + code = 201, + message = "OK. \n Successfully add a comment.", + response = Comment.class), + @ApiResponse( + code = 400, + message = + "Bad Request. \n"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred adding a comment.", + response = ErrorResponse.class) + }) + + Response addComments( + @ApiParam( + name = "comment", + value = "Comment details", + required = true) + Comment comment, + @ApiParam( + name="uuid", + value="uuid of the release version of the application", + required=true) + @PathParam("uuid") + String uuid); + + @PUT + @Path("/{apAppCommentId}") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "PUT", + value = "Edit a comment", + notes = "This will edit the comment", + tags = "Store Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:store:edit") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 201, + message = "OK. \n Successfully updated comment.", + response = Comment.class), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 404, + message = "Not Found. \n No activity found with the given ID.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while updating the new comment.", + response = ErrorResponse.class) + }) + Response updateComment( + @ApiParam( + name = "comment", + value = "The comment that need to be updated.", + required = true) + @Valid Comment comment, + @ApiParam( + name="apAppCommentId", + value = "comment id of the updating comment.", + required = true) + @QueryParam("apAppCommentId") + int apAppCommentId); + + @DELETE + @Path("/{apAppCommentId}") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "DELETE", + value = "Remove comment", + notes = "Remove comment", + tags = "Store Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:store:remove") + }) + } + ) + + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully deleted the comment"), + @ApiResponse( + code = 404, + message = "Not Found. \n No activity found with the given ID.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while deleting the comment.", + response = ErrorResponse.class) + }) + + Response deleteComment( + @ApiParam( + name="apAppCommentId", + value="Id of the comment.", + required = true) + @PathParam("apAppCommentId") + int apAppCommentId); + + @GET + @Path("/{uuid}/{stars}") + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "get stars", + notes = "Get all stars", + tags = "Store Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:stars:get") + }) + } + ) + + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully retrieved stars.", + response = List.class, + responseContainer = "List"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while getting the stars", + response = ErrorResponse.class) + }) + + Response getStars( + @ApiParam( + name = "uuid", + value = "uuid of the application release", + required = true) + @PathParam("uuid") + String uuid); + + @GET + @Path("/{uuid}/{stars}") + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "get rated users", + notes = "Get all users", + tags = "Store Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:user:get") + }) + } + ) + + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully retrieved user.", + response = List.class, + responseContainer = "List"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while getting the comment list.", + response = ErrorResponse.class) + }) + + Response getRatedUser( + @ApiParam( + name = "uuid", + value = "uuid of the application release", + required = true) + @PathParam("uuid") + String uuid); + + @POST + @Path("/uuid/{uuid}") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Add a star value", + notes = "This will add star value", + tags = "Store Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:stars:add") + }) + } + ) + + @ApiResponses( + value = { + @ApiResponse( + code = 201, + message = "OK. \n Successfully rated to the application.", + response = Comment.class), + @ApiResponse( + code = 304, + message = "Not Modified. \n " + + "Empty body because the client already has the latest rating of the requested resource."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred rating for the application.", + response = ErrorResponse.class) + }) + + Response updateStars( + @ApiParam( + name = "stars", + value = "ratings for the application", + required = true) + int stars, + @ApiParam( + name="uuid", + value="uuid of the release version of the application", + required=true) + @PathParam("uuid") + String uuid) throws SQLException; +} From b9bb6830f433a0f665b8f2508112f7b33ffc12a5 Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 15:35:35 +0530 Subject: [PATCH 02/56] Adding Implementation of Comment Management API --- .../impl/CommentManagementAPIImpl.java | 215 ++++++++++++++++++ 1 file changed, 215 insertions(+) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java new file mode 100644 index 0000000000..2e0a8b11dd --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java @@ -0,0 +1,215 @@ +package org.wso2.carbon.device.application.mgt.api.services.impl; + +import io.swagger.annotations.ApiParam; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.application.mgt.api.APIUtil; +import org.wso2.carbon.device.application.mgt.api.services.CommentManagementAPI; +import org.wso2.carbon.device.application.mgt.common.Comment; +import org.wso2.carbon.device.application.mgt.common.PaginationRequest; +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.DBConnectionException; +import org.wso2.carbon.device.application.mgt.common.services.CommentsManager; + +import javax.ws.rs.Path; +import javax.ws.rs.Consumes; +import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; +import javax.ws.rs.PUT; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.DELETE; +import javax.ws.rs.NotFoundException; +import javax.ws.rs.core.Response; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +/** + * Comment Management related jax-rs APIs. + */ +@Path("/comments") +@SuppressWarnings( "deprecation" ) +public class CommentManagementAPIImpl implements CommentManagementAPI{ + + private static Log log = LogFactory.getLog(CommentManagementAPIImpl.class); + + @Override + @GET + @Path("/{uuid}") + public Response getAllComments( + @PathParam("uuid") String uuid, + @QueryParam("offset")int offSet, + @QueryParam("limit")int limit){ + + CommentsManager commentsManager = APIUtil.getCommentsManager(); + List comments = new ArrayList<>(); + try { + 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) { + String msg = "Error occurred while retrieving comments."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (SQLException e) { + log.error("SQL Exception occurs", e); + } + return Response.status(Response.Status.OK).entity(comments).build(); + } + + @Override + @POST + @Consumes("application/json") + @Path("/{uuid}") + public Response addComments( + @ApiParam Comment comment, + @PathParam("uuid") String uuid){ + + CommentsManager commentsManager = APIUtil.getCommentsManager(); + int tenantId= PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + try { + Comment newComment = commentsManager.addComment(comment,uuid,tenantId); + if (comment != null){ + return Response.status(Response.Status.CREATED).entity(newComment).build(); + }else{ + String msg = "Given comment is not valid "; + log.error(msg); + return Response.status(Response.Status.BAD_REQUEST).build(); + } + }catch (CommentManagementException e) { + String msg = "Error occurred while creating the comment"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } + } + + @Override + @PUT + @Consumes("application/json") + @Path("/{apAppCommentId}") + public Response updateComment( + @ApiParam Comment comment, + @PathParam("apAppCommentId") int apAppCommentId) { + + CommentsManager commentsManager = APIUtil.getCommentsManager(); + //int tenantId= PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + try { + if (apAppCommentId == 0) { + return Response.status(Response.Status.NOT_FOUND) + .entity("Comment with comment id " + apAppCommentId + " not found").build(); + }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,apAppCommentId); + return Response.status(Response.Status.OK).entity(comment).build(); + } + } catch (CommentManagementException e) { + String msg = "Error occurred while retrieving comments."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } catch (SQLException e) { + log.error("SQL Exception occurs", e); + }catch (DBConnectionException e) { + log.error("DB Connection Exception occurs", e); + } + + return Response.status(Response.Status.OK).entity(comment).build(); + } + + @Override + @DELETE + @Path("/{apAppCommentId}") + public Response deleteComment( + @PathParam("apAppCommentId") + int apAppCommentId){ + + CommentsManager commentsManager = APIUtil.getCommentsManager(); + try { + commentsManager.deleteComment(apAppCommentId); + } catch (CommentManagementException e) { + String msg = "Error occurred while deleting the comment."; + 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 "+apAppCommentId+" .",e); + return Response.status(Response.Status.NOT_FOUND) + .entity("Comment with" + apAppCommentId + " not found").build(); + } + return Response.status(Response.Status.OK).entity("Comment is deleted successfully.").build(); + } + + @Override + @GET + @Path("/{uuid}") + public Response getStars( + @PathParam("uuid") + String uuid) { + + CommentsManager commentsManager = APIUtil.getCommentsManager(); + int Stars=0; + + try { + Stars= commentsManager.getStars(uuid); + } catch (SQLException e) { + log.error("SQL Exception occurs", e); + } + return Response.status(Response.Status.OK).entity(Stars).build(); + } + + @Override + @GET + @Path("/{uuid}") + public Response getRatedUser( + @PathParam("uuid") + String uuid){ + + CommentsManager commentsManager = APIUtil.getCommentsManager(); + int ratedUsers=0; + + try { + ratedUsers= commentsManager.getRatedUser(uuid); + } catch (SQLException e) { + log.error("SQL Exception occurs", e); + } + return Response.status(Response.Status.OK).entity(ratedUsers).build(); + } + + @Override + @POST + @Consumes("uuid/stars/json") + public Response updateStars( + @ApiParam int stars, + @PathParam("uuid") String uuid) throws SQLException { + + CommentsManager commentsManager = APIUtil.getCommentsManager(); + int newStars=commentsManager.getStars(uuid); + + try { + newStars = commentsManager.updateStars(stars,uuid); + + if (stars != 0){ + return Response.status(Response.Status.CREATED).entity(newStars).build(); + }else{ + String msg = "Given star value is not valid "; + log.error(msg); + return Response.status(Response.Status.BAD_REQUEST).build(); + } + + } catch (ApplicationManagementException e) { + log.error("Application Management Exception occurs", e); + } + return Response.status(Response.Status.OK).entity(newStars).build(); + } +} \ No newline at end of file From dbd9ad77ae411f4b5571fba99b10e4b3b44184b7 Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 15:37:03 +0530 Subject: [PATCH 03/56] Modified API Util getComment method is added to the APIUtil file. --- .../device/application/mgt/api/APIUtil.java | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java index 8be02fc146..8549f7b961 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java @@ -22,14 +22,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse; -import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; -import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager; -import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; -import org.wso2.carbon.device.application.mgt.common.services.CategoryManager; -import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; -import org.wso2.carbon.device.application.mgt.common.services.PlatformManager; -import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager; -import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; +import org.wso2.carbon.device.application.mgt.common.services.*; import javax.ws.rs.core.Response; @@ -49,6 +42,7 @@ public class APIUtil { private static SubscriptionManager subscriptionManager; private static PlatformStorageManager platformStorageManager; private static CategoryManager categoryManager; + private static CommentsManager commentsManager; public static ApplicationManager getApplicationManager() { if (applicationManager == null) { @@ -232,4 +226,22 @@ public class APIUtil { return subscriptionManager; } + + public static CommentsManager getCommentsManager() { + if (commentsManager == null) { + synchronized (APIUtil.class) { + if (commentsManager == null) { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + commentsManager = + (CommentsManager) ctx.getOSGiService(CommentsManager.class, null); + if (commentsManager == null) { + String msg = "Comments Manager service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + } + } + } + return commentsManager; + } } From 46f087f215e744e191381d19273339f3727f4d93 Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 15:39:48 +0530 Subject: [PATCH 04/56] Adding Comment Management Exception Handle the Exceptions of Comment Management. --- .../exception/CommentManagementException.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/CommentManagementException.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/CommentManagementException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/CommentManagementException.java new file mode 100644 index 0000000000..53d5ebc99b --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/CommentManagementException.java @@ -0,0 +1,29 @@ +package org.wso2.carbon.device.application.mgt.common.exception; + +import org.wso2.carbon.device.application.mgt.common.Comment; + +public class CommentManagementException extends Exception{ + private String message; + + public CommentManagementException(String message, Throwable throwable) { + super(message, throwable); + setMessage(message); + } + + public CommentManagementException(String message) { + super(message); + setMessage(message); + } + + public CommentManagementException() { + + } + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} From 6dbdddb3d2c2eda9ec02e415c51956006cb26e6a Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 15:48:38 +0530 Subject: [PATCH 05/56] Adding Comment Manager Interface Included the comment management methods and stars rating methods --- .../mgt/common/services/CommentsManager.java | 82 ++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java index b0e0f4bd82..d3bccd0c3c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java @@ -18,9 +18,89 @@ */ package org.wso2.carbon.device.application.mgt.common.services; +import org.wso2.carbon.device.application.mgt.common.Comment; +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 org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; + +import java.sql.SQLException; + /** * CommentsManager is responsible for handling all the add/update/delete/get operations related with - * {@link org.wso2.carbon.device.application.mgt.common.Comment}. + * */ public interface CommentsManager { + + /** + * To add a comment to a application + * + * @param comment comment of the application. + * @param uuid uuid of the application release + * @param tenantId tenant id of the application + * @return {@link Comment} + * @throws CommentManagementException Exceptions of the comment management. + */ + + /** + * Get all comments to pagination + * + *@param request Pagination request + * @param uuid uuid of the application release + * @return {@link PaginationResult} pagination result with starting index and limit + * @throws CommentManagementException Exceptions of the comment management. + * @throws SQLException SQL Exception + */ + PaginationResult getAllComments(PaginationRequest request,String uuid) throws CommentManagementException, SQLException; + + /** + * To get the comment with id. + * + * @param apAppCommentId id of the comment + * @return Comment of the comment id + * @throws CommentManagementException Exceptions of the comment management. + */ + Comment getComment(int apAppCommentId)throws CommentManagementException; + + + /** + * To update a comment. + * + * @param comment comment of the application. + * @param apAppCommentId id of the comment + * @return updated comment + * @throws CommentManagementException Exceptions of the comment management + * @throws SQLException SQL Exception + * @throws DBConnectionException Database connection Exception + */ + Comment updateComment(Comment comment,int apAppCommentId) throws CommentManagementException, SQLException, DBConnectionException; + + /** + * To get the average of stars + * + * @param uuid uuid of the comment + * @return value of the stars of an application + * @throws SQLException sql exception + */ + int getStars(String uuid)throws SQLException; + + /** + * To update rating stars + * + * @param stars amount of stars + * @param uuid uuid of the application + * @return value of the added stars + * @throws ApplicationManagementException Application Management Exception. + */ + int updateStars(int stars, String uuid) throws ApplicationManagementException; + + /** + * To get number of rated users + * + * @param uuid uuid of the application + * @return number of rated users + * @throws SQLException sql exception + */ + int getRatedUser(String uuid)throws SQLException; } From c00345e7d7c0d89bab15d3ce5cec4516bd21ed21 Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 15:50:47 +0530 Subject: [PATCH 06/56] Modify Application Release Variables are added- noOfRatedUsers and stars. --- .../mgt/common/ApplicationRelease.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java index e43b4fda64..48215fb121 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java @@ -53,6 +53,26 @@ public class ApplicationRelease { private boolean isDefault; + private int noOfRatedUsers; + + private int stars; + + public int getNoOfRatedUsers() { + return noOfRatedUsers; + } + + public void setNoOfRatedUsers(int noOfRatedUsers) { + this.noOfRatedUsers = noOfRatedUsers; + } + + public int getStars() { + return stars; + } + + public void setStars(int stars) { + this.stars = stars; + } + public int getId() { return id; } From a0ef2dbafed9619919ef2bbc747ffb20a9850b34 Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 15:51:18 +0530 Subject: [PATCH 07/56] Adding Comment --- .../application/mgt/common/Comment.java | 75 ++++++++++++------- 1 file changed, 46 insertions(+), 29 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Comment.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Comment.java index 6d6d61cdef..9e2050a626 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Comment.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Comment.java @@ -18,33 +18,46 @@ */ package org.wso2.carbon.device.application.mgt.common; +import java.sql.Timestamp; +import java.util.Date; + /** * Represents a comment for an {@link Application}. */ public class Comment { - private String id; + private int id; private String comment; - private int rating; - //TODO: Pagination, comment ID for child - private Comment parent; + private int parent; + + private int tenantId; private String createdBy; - private String createdAt; + private Timestamp createdAt; - private String modifiedAt; + private String modifiedBy; - private Application application; + private Timestamp modifiedAt; - public String getId() { +// private Application application; + public int getTenantId() { + return tenantId; + } + + public void setTenantId(int tenantId) { + this.tenantId = tenantId; + } + + + public int getId() { return id; } - public void setId(String id) { + public void setId(int id) { this.id = id; } @@ -56,19 +69,11 @@ public class Comment { this.comment = comment; } - public int getRating() { - return rating; - } - - public void setRating(int rating) { - this.rating = rating; - } - - public Comment getParent() { + public int getParent() { return parent; } - public void setParent(Comment parent) { + public void setParent(int parent) { this.parent = parent; } @@ -80,27 +85,39 @@ public class Comment { this.createdBy = createdBy; } - public String getCreatedAt() { + public Timestamp getCreatedAt() { return createdAt; } - public void setCreatedAt(String createdAt) { + public void setCreatedAt(Timestamp createdAt) { this.createdAt = createdAt; } - public String getModifiedAt() { - return modifiedAt; + public String getModifiedBy() { + return modifiedBy; } - public void setModifiedAt(String modifiedAt) { - this.modifiedAt = modifiedAt; + public void setModifiedBy(String modifiedBy) { + this.modifiedBy = modifiedBy; } - public Application getApplication() { - return application; + public Timestamp getModifiedAt() { + return modifiedAt; } - public void setApplication(Application application) { - this.application = application; + public void setModifiedAt(Timestamp modifiedAt) { + this.modifiedAt = modifiedAt; } + +// public Application getApplication() { +// return application; +// } +// +// public void setApplication(Application application) { +// this.application = application; +// } + + + } + From 849474de87e66c71ff4e6773ade87d8d7ec5208e Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 15:52:34 +0530 Subject: [PATCH 08/56] Adding Pagination Request for application-mgt --- .../mgt/common/PaginationRequest.java | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationRequest.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationRequest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationRequest.java new file mode 100644 index 0000000000..789c27215b --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationRequest.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2015, 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; + + +import org.apache.commons.fileupload.MultipartStream; + +/** + * This class holds required parameters for a querying a paginated device response. + */ +public class PaginationRequest { + + private int offSet; + private int limit; + + public PaginationRequest(int start, int limit) { + this.offSet = start; + this.limit = limit; + } + + public int getOffSet() { + return offSet; + } + + public void setOffSet(int offSet) { + this.offSet = offSet; + } + + public int getLimit() { + return limit; + } + + public void setLimit(int limit) { + this.limit = limit; + } + + public boolean validatePaginationRequest(int offSet,int limit){ + if (offSet<0){ + throw new IllegalArgumentException("off set value can't be negative"); + } else if(limit<0){ + throw new IllegalArgumentException("limit value can't be negative"); + }else { + return true; + } + } + + + @Override + public String toString() { + return "Off Set'" + this.offSet + "' row count '" + this.limit; + } +} From 9f67e527419d4ed1444b3783f4ca7f51cbcbcb7f Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 15:53:07 +0530 Subject: [PATCH 09/56] Adding Pagination Result for application-mgt --- .../mgt/common/PaginationResult.java | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationResult.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationResult.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationResult.java new file mode 100644 index 0000000000..aa95d2a880 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationResult.java @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2015, 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; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; +import java.util.List; + +/** + * This class holds necessary data to represent a paginated result. + */ +@ApiModel(value = "PaginationResult", description = "This class carries all information related Pagination Result") +public class PaginationResult implements Serializable { + + private static final long serialVersionUID = 1998101711L; + + @ApiModelProperty(name = "recordsTotal", value = "The total number of records that are given before filtering", required = true) + private int recordsTotal; + + @ApiModelProperty(name = "recordsFiltered", value = "The total number of records that are given after filtering", required = true) + private int recordsFiltered; + + @ApiModelProperty(name = "draw", value = "The draw counter that this object is a response to, from the draw parameter sent as part of the data request", required = true) + private int draw; + + @ApiModelProperty(name = "data", value = "This holds the database records that matches given criteria", required = true) + private List data; + + public int getRecordsTotal() { + return recordsTotal; + } + + public int getRecordsFiltered() { + return recordsFiltered; + } + + public void setRecordsFiltered(int recordsFiltered) { + this.recordsFiltered = recordsFiltered; + } + + public void setRecordsTotal(int recordsTotal) { + this.recordsTotal = recordsTotal; + + } + + public List getData() { + return data; + } + + public void setData(List data) { + this.data = data; + } + + public int getDraw() { + return draw; + } + + public void setDraw(int draw) { + this.draw = draw; + } +} From 9f44795682ba134420eb17ffa619cffa413b5c35 Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 15:54:52 +0530 Subject: [PATCH 10/56] Modify Configuration Pagination Configuration is added. --- .../device/application/mgt/core/config/Configuration.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/Configuration.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/Configuration.java index 4b085f8427..3ef617ff0e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/Configuration.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/Configuration.java @@ -35,6 +35,8 @@ public class Configuration { private Artifacts artifacts; + private PaginationConfiguration paginationConfiguration; + @XmlElement(name = "DatasourceName", required = true) public String getDatasourceName() { return datasourceName; @@ -53,6 +55,11 @@ public class Configuration { public void setExtensions(List extensions) { this.extensions = extensions; } + + @XmlElement(name = "PaginationConfiguration", required = true) + public PaginationConfiguration getPaginationConfiguration() { + return paginationConfiguration; + } } From 87d1928f4c0bd4860e216ed9a352a9d7bde4a5c9 Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 15:55:51 +0530 Subject: [PATCH 11/56] Modify Configuration Management --- .../device/application/mgt/core/config/ConfigurationManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ConfigurationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ConfigurationManager.java index 4e5ae24022..90675e0102 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ConfigurationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/ConfigurationManager.java @@ -97,4 +97,5 @@ public class ConfigurationManager { } throw new InvalidConfigurationException("Expecting an extension with name - " + extName + " , but not found!"); } + } From 5096654658c9ebaf4a46c6fdbf01b6dee0c34eaa Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 15:56:34 +0530 Subject: [PATCH 12/56] Adding Pagination Configuration for application-mgt --- .../core/config/PaginationConfiguration.java | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/PaginationConfiguration.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/PaginationConfiguration.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/PaginationConfiguration.java new file mode 100644 index 0000000000..8905b6de95 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/PaginationConfiguration.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2016, 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.core.config; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * This class represents the information related to Pagination configuration. + */ +@XmlRootElement(name = "PaginationConfiguration") +public class PaginationConfiguration { + + private int commentListPageSize; +// private int groupListPageSize; +// private int operationListPageSize; +// private int notificationListPageSize; +// private int activityListPageSize; +// private int topicListPageSize; + + public int getCommentListPageSize() { + return commentListPageSize; + } + + @XmlElement(name = "commentListPageSize", required = true) + public void setCommentListPageSize(int commentListPageSize) { + this.commentListPageSize = commentListPageSize; + } + +// public int getGroupListPageSize() { +// return groupListPageSize; +// } +// +// @XmlElement(name = "GroupListPageSize", required = true) +// public void setGroupListPageSize(int groupListPageSize) { +// this.groupListPageSize = groupListPageSize; +// } +// +// public int getOperationListPageSize() { +// return operationListPageSize; +// } +// +// @XmlElement(name = "OperationListPageSize", required = true) +// public void setOperationListPageSize(int operationListPageSize) { +// this.operationListPageSize = operationListPageSize; +// } +// +// public int getNotificationListPageSize() { +// return notificationListPageSize; +// } +// +// @XmlElement(name = "NotificationListPageSize", required = true) +// public void setNotificationListPageSize(int notificationListPageSize) { +// this.notificationListPageSize = notificationListPageSize; +// } +// +// public int getActivityListPageSize() { +// return activityListPageSize; +// } +// +// @XmlElement(name = "ActivityListPageSize", required = true) +// public void setActivityListPageSize(int activityListPageSize) { +// this.activityListPageSize = activityListPageSize; +// } +// +// public int getTopicListPageSize() { +// return deviceListPageSize; +// } +// +// @XmlElement(name = "TopicListPageSize", required = true) +// public void setTopicListPageSize(int topicListPageSize) { +// this.topicListPageSize = topicListPageSize; +// } + + +} From 35e4174211396ba103a44d260add5e452e875044 Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 16:00:02 +0530 Subject: [PATCH 13/56] Modify Application Management DAO Factory getCommentDAO method is added. --- .../ApplicationManagementDAOFactory.java | 255 ++++++++++++++++++ 1 file changed, 255 insertions(+) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOFactory.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOFactory.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOFactory.java new file mode 100644 index 0000000000..99c6d117fa --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOFactory.java @@ -0,0 +1,255 @@ +/* + * 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.core.dao.common; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.application.mgt.common.exception.UnsupportedDatabaseEngineException; +import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; +import org.wso2.carbon.device.application.mgt.core.dao.*; +import org.wso2.carbon.device.application.mgt.core.dao.impl.Comment.CommentDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.GenericApplicationReleaseDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.OracleApplicationDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.subscription.GenericSubscriptionDAOImpl; +import org.wso2.carbon.device.application.mgt.core.dao.impl.visibility.GenericVisibilityDAOImpl; +import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; +import org.wso2.carbon.device.application.mgt.core.util.ApplicationMgtDatabaseCreator; +import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; +import org.wso2.carbon.device.application.mgt.core.util.Constants; +import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; +import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; +import org.wso2.carbon.device.mgt.core.dao.impl.DeviceTypeDAOImpl; +import org.wso2.carbon.utils.dbcreator.DatabaseCreator; + +import javax.sql.DataSource; +import java.sql.SQLException; + +import static org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil.resolveDataSource; + +/** + * This class intends to act as the primary entity that hides all DAO instantiation related complexities and logic so + * that the business objection handling layer doesn't need to be aware of the same providing seamless plug-ability of + * different data sources, connection acquisition mechanisms as well as different forms of DAO implementations to the + * high-level implementations that require Application management related metadata persistence. + */ +public class ApplicationManagementDAOFactory { + + private static String databaseEngine; + private static DataSource dataSource; + private static final Log log = LogFactory.getLog(ApplicationManagementDAOFactory.class); + + public static void init(String datasourceName) { + ConnectionManagerUtil.resolveDataSource(datasourceName); + databaseEngine = ConnectionManagerUtil.getDatabaseType(); + } + public static void init(DataSource dtSource){ + dataSource=dtSource; + try { + databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName(); + } catch (SQLException e) { + log.error("Error occurred while retrieving config.datasource connection", e); + } + } + public static void init(DataSourceConfig config) { + dataSource = resolveDataSource(config); + try { + databaseEngine = dataSource.getConnection().getMetaData().getDatabaseProductName(); + } catch (SQLException e) { + log.error("Error occurred while retrieving config.datasource connection", e); + } + } + + + public static ApplicationDAO getApplicationDAO() { + 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 GenericApplicationDAOImpl(); + case Constants.DataBaseTypes.DB_TYPE_ORACLE: + return new OracleApplicationDAOImpl(); + default: + throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); + } + } + throw new IllegalStateException("Database engine has not initialized properly."); + } + + public static LifecycleStateDAO getLifecycleStateDAO() { + if (databaseEngine != null) { + switch (databaseEngine) { + case Constants.DataBaseTypes.DB_TYPE_H2: + case Constants.DataBaseTypes.DB_TYPE_MYSQL: + case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL: + case Constants.DataBaseTypes.DB_TYPE_ORACLE: + return new GenericLifecycleStateImpl(); + default: + throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); + } + } + throw new IllegalStateException("Database engine has not initialized properly."); + } + + /** + * To get the instance of ApplicationReleaseDAOImplementation of the particular database engine. + * + * @return specific ApplicationReleaseDAOImplementation + */ + public static ApplicationReleaseDAO getApplicationReleaseDAO() { + if (databaseEngine != null) { + switch (databaseEngine) { + case Constants.DataBaseTypes.DB_TYPE_H2: + case Constants.DataBaseTypes.DB_TYPE_MYSQL: + case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL: + case Constants.DataBaseTypes.DB_TYPE_ORACLE: + return new GenericApplicationReleaseDAOImpl(); + default: + throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); + } + } + throw new IllegalStateException("Database engine has not initialized properly."); + } + + /** + * To get the instance of VisibilityDAOImplementation of the particular database engine. + * + * @return specific VisibilityDAOImplementation + */ + public static VisibilityDAO getVisibilityDAO() { + if (databaseEngine != null) { + switch (databaseEngine) { + case Constants.DataBaseTypes.DB_TYPE_H2: + case Constants.DataBaseTypes.DB_TYPE_MYSQL: + return new GenericVisibilityDAOImpl(); + default: + throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); + } + } + throw new IllegalStateException("Database engine has not initialized properly."); + } + + /** + * To get the instance of SubscriptionDAOImplementation of the particular database engine. + * + * @return GenericSubscriptionDAOImpl + */ + public static SubscriptionDAO getSubscriptionDAO() { + 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 GenericSubscriptionDAOImpl(); + default: + throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); + } + } + throw new IllegalStateException("Database engine has not initialized properly."); + } + + /** + * To get the instance of DeviceTypeDAOImpl of the particular database engine. + * + * @return DeviceTypeDAOImpl + */ + public static DeviceTypeDAO getDeviceTypeDAO() { + 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 DeviceTypeDAOImpl(); + default: + throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); + } + } + throw new IllegalStateException("Database engine has not initialized properly."); + } + + /** + * To get the instance of LifecycleDAOImplementation of the particular database engine. + * + * @return GenericLifecycleDAOImpl + */ + public static LifecycleStateDAO getLifecycleDAO() { + 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 GenericLifecycleStateImpl(); + default: + throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine); + } + } + throw new IllegalStateException("Database engine has not initialized properly."); + } + + /** + * This method initializes the databases by creating the database. + * + * @throws ApplicationManagementDAOException Exceptions thrown during the creation of the tables + */ + public static void initDatabases() throws ApplicationManagementDAOException { + String dataSourceName = ConfigurationManager.getInstance().getConfiguration().getDatasourceName(); + String validationQuery = "SELECT * from APPM_PLATFORM"; + try { + if (System.getProperty("setup") == null) { + if (log.isDebugEnabled()) { + log.debug("Application Management Database schema initialization check was skipped since " + + "\'setup\' variable was not given during startup"); + } + } else { + DatabaseCreator databaseCreator = new ApplicationMgtDatabaseCreator(dataSourceName); + if (!databaseCreator.isDatabaseStructureCreated(validationQuery)) { + databaseCreator.createRegistryDatabase(); + log.info("Application Management tables are created in the database"); + } else { + log.info("Application Management Database structure already exists. Not creating the database."); + } + } + } catch (SQLException e) { + throw new ApplicationManagementDAOException( + "Error while creating application-mgt database during the " + "startup ", e); + } catch (Exception e) { + throw new ApplicationManagementDAOException( + "Error while creating application-mgt database in the " + "startup ", e); + } + } + + + 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); + } + } + throw new IllegalStateException("Database engine has not initialized properly."); + } + } + + From 99857c9acc91e16a110d443cd7b3716a3e3599b3 Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 16:01:19 +0530 Subject: [PATCH 14/56] Modify Util validateCommentListPageSize method is added. --- .../application/mgt/core/dao/common/Util.java | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java index 2743a120c6..1513951128 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java @@ -22,11 +22,16 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.JSONException; import org.wso2.carbon.device.application.mgt.common.Application; +import org.wso2.carbon.device.application.mgt.common.Platform; +import org.wso2.carbon.device.application.mgt.common.User; import org.wso2.carbon.device.application.mgt.common.Category; import org.wso2.carbon.device.application.mgt.common.Lifecycle; import org.wso2.carbon.device.application.mgt.common.LifecycleState; -import org.wso2.carbon.device.application.mgt.common.Platform; -import org.wso2.carbon.device.application.mgt.common.User; +import org.wso2.carbon.device.application.mgt.common.PaginationRequest; + +import org.wso2.carbon.device.application.mgt.common.exception.CommentManagementException; +import org.wso2.carbon.device.application.mgt.core.config.Configuration; +import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -123,4 +128,18 @@ public class Util { } } } + + public static PaginationRequest validateCommentListPageSize(PaginationRequest paginationRequest) throws + CommentManagementException{ + if (paginationRequest.getLimit() == 0) { + Configuration commentManagementConfig = ConfigurationManager.getInstance().getConfiguration(); + if (commentManagementConfig != null) { + paginationRequest.setLimit(commentManagementConfig.getPaginationConfiguration().getCommentListPageSize()); + } else { + throw new CommentManagementException("Device-Mgt configuration has not initialized. Please check the " + + "cdm-config.xml file."); + } + } + return paginationRequest; + } } From 64e8faa15330374658cf33c85ee29dafe8a60e99 Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 16:03:15 +0530 Subject: [PATCH 15/56] Adding CommentDAO Interface --- .../application/mgt/core/dao/CommentDAO.java | 373 +++++++++++++++++- 1 file changed, 371 insertions(+), 2 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java index 27cbe337e3..20333612e3 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java @@ -18,8 +18,377 @@ */ package org.wso2.carbon.device.application.mgt.core.dao; +import org.wso2.carbon.device.application.mgt.common.Comment; +import org.wso2.carbon.device.application.mgt.common.PaginationRequest; +import org.wso2.carbon.device.application.mgt.common.exception.CommentManagementException; +import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; +import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; + +import java.sql.SQLException; +import java.sql.Timestamp; +import java.util.List; + /** * This interface specifies the database access operations performed for comments. */ -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 createdBy Username of the created person. + * @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. + */ + 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 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. + * @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; + + /** + * To update already added comment. + * + * @param apAppCommentId id of the comment + * @param updatedComment comment after updated + * @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 + */ + Comment updateComment(int apAppCommentId, String updatedComment,String modifiedBy, Timestamp modifiedAt) throws CommentManagementException, DBConnectionException, SQLException; + + /** + * To update already added comment. + * + * @param uuid uuid of the comment + * @param apAppCommentId id of the comment + * @param updatedComment comment after updated + * @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 + */ + Comment updateComment(String uuid, int apAppCommentId,String updatedComment,String modifiedBy, Timestamp modifiedAt) throws CommentManagementException, DBConnectionException, SQLException; + + /** + * To get the comment with id. + * + * @param apAppCommentId id of the comment + * @return {@link Comment}Comment + * @throws CommentManagementException Exceptions of the comment management. + * @throws DBConnectionException db connection exception + * @throws SQLException sql exception + */ + Comment getComment(int apAppCommentId) throws CommentManagementException, SQLException, DBConnectionException; + + /** + * To get the comment with id. + * + * @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 + */ + List getComment(String uuid) throws CommentManagementException, SQLException, DBConnectionException; + + /** + * To get all the comments + * + * @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 + **/ + List 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. + * @return {@link List}List of comments + * @throws CommentManagementException Exceptions of the comment management. + */ + List getComments(int appReleasedId,int appId)throws CommentManagementException; + + /** + * To get list of comments using application type, application name and version of the application. + * + * @param appType type of the commented application. + * @param appName name of the commented application. + * @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 + */ + List getComments(String appType,String appName,String version) throws CommentManagementException, DBConnectionException, SQLException; + + /** + * To get list of comments using tenant id. + * + * @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 + */ + List getComments(int tenantId) throws CommentManagementException, DBConnectionException, SQLException; + + /** + * To get list of comments by created user. + * + * @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 + */ + List getCommentsByUser(String createdBy) throws CommentManagementException, DBConnectionException, SQLException; + + /** + * To get list of comments by created use and created time. + * + * @param createdBy Username of the created person. + * @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 + */ + List getCommentsByUser(String createdBy,Timestamp createdAt) throws CommentManagementException, DBConnectionException, SQLException; + + /** + * To get list of comments by modified users. + * + * @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 + */ + List getCommentsByModifiedUser(String modifiedBy) throws CommentManagementException, DBConnectionException, SQLException; + + /** + * To get list of comments using modified user's name and modified time. + * + * @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 DBConnectionException db connection exception. + * @throws SQLException sql exception + */ + List 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 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 + */ + List getComments(String appType,String appName,String version,int parentId) throws CommentManagementException, DBConnectionException, SQLException; + + /** + * To get a count of the comments by usernames. + * + * @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 + */ + int getCommentCount(String uuid) throws CommentManagementException, DBConnectionException, SQLException; + + /** + * To get a count of the comments by usernames. + * + * @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 + */ + int getCommentCountByUser(String createdBy) throws CommentManagementException, DBConnectionException, SQLException; + + /** + * To get the comment count by parent comment id. + * + * @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 + */ + 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 + * @return Count of the comments + * @throws CommentManagementException Exceptions of the comment management. + * @throws DBConnectionException db connection exception. + * @throws SQLException sql exception + */ + 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 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 + */ + int getCommentCountByApp(int appId, int appReleaseId) throws CommentManagementException, DBConnectionException, SQLException; + + /** + * To get count of comments by application details. + * + * @param appType type of the commented application. + * @param appName name of the commented application. + * @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 + */ + int getCommentCountByApp(String appType,String appName,String version) throws CommentManagementException, DBConnectionException, SQLException; + + /** + * To delete comment using comment id. + * + * @param apAppCommentId id of the comment + * @throws CommentManagementException Exceptions of the comment management. + * @throws DBConnectionException db connection exception. + * @throws SQLException sql exception + */ + void deleteComment(int apAppCommentId) 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 + */ + void deleteComment(String uuid) throws CommentManagementException, DBConnectionException, SQLException; + + /** + * To delete comments using application details. + * + * @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 + */ + void deleteComments(int appId,int appReleaseID) throws CommentManagementException, DBConnectionException, SQLException; + + /** + * To delete comments using application details. + * + * @param appType type of the commented application. + * @param appName name of the commented application. + * @param version version of the commented application. + * @throws CommentManagementException Exceptions of the comment management. + */ + 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 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; + + + /** + * To delete comments by parent id of the comment. + * + * @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; + + + /** + * To add the star rating to the application. + * + * @param stars Star value + * @param uuid UUID of the application + * @return Star value + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ + int updateStars(int stars, String uuid) throws ApplicationManagementDAOException; + + /** + * To get the average star value of the application + * + * @param uuid uuid of the application + * @return Average of star values + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ + int getStars(String uuid) throws ApplicationManagementDAOException; + + /** + * To get number of rated users + * + * @param uuid uuid of the application + * @return Number of rated users + * @throws ApplicationManagementDAOException Application Management DAO Exception. + */ + int getRatedUser(String uuid) throws ApplicationManagementDAOException; + + /** + * To get comment count for pagination + * + * @param request + * @param uuid + * @return Comment count + * @throws CommentManagementException + */ + int getCommentCount(PaginationRequest request, String uuid) throws CommentManagementException; +} \ No newline at end of file From 6b6a5bdbb199476130fba7e4acc23825d861c7ff Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 16:15:53 +0530 Subject: [PATCH 16/56] Adding Comment Manager Interface Included the comment management methods and stars rating methods --- .../mgt/common/services/CommentsManager.java | 54 +++++++++++++------ 1 file changed, 38 insertions(+), 16 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java index d3bccd0c3c..25e956ce20 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java @@ -26,6 +26,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.CommentManagement import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import java.sql.SQLException; +import java.util.List; /** * CommentsManager is responsible for handling all the add/update/delete/get operations related with @@ -39,43 +40,73 @@ public interface CommentsManager { * @param comment comment of the application. * @param uuid uuid of the application release * @param tenantId tenant id of the application - * @return {@link Comment} + * @return {@link Comment} Comment added * @throws CommentManagementException Exceptions of the comment management. */ + Comment addComment(Comment comment,String uuid,int tenantId)throws CommentManagementException; + + /** + * To validate the pre-request of the comment + * + * @param apAppCommentId ID of the comment. + * @param comment comment needed to be validate. + * @return validated the comment. + * @throws CommentManagementException Exceptions of the comment management. + * + */ + Boolean validateComment(int apAppCommentId,String comment) throws CommentManagementException; /** * Get all comments to pagination * - *@param request Pagination request + * @param request Pagination request * @param uuid uuid of the application release - * @return {@link PaginationResult} pagination result with starting index and limit + * @return {@link PaginationResult} pagination result with starting offSet and limit * @throws CommentManagementException Exceptions of the comment management. * @throws SQLException SQL Exception */ - PaginationResult getAllComments(PaginationRequest request,String uuid) throws CommentManagementException, SQLException; + List getAllComments(PaginationRequest request, String uuid) throws CommentManagementException, SQLException; + /** * To get the comment with id. * * @param apAppCommentId id of the comment - * @return Comment of the comment id + * @return {@link Comment}Comment of the comment id * @throws CommentManagementException Exceptions of the comment management. */ Comment getComment(int apAppCommentId)throws CommentManagementException; + /** + * To delete comment using comment id. + * + * @param apAppCommentId id of the comment + * @throws CommentManagementException Exceptions of the comment management + */ + void deleteComment(int apAppCommentId) throws CommentManagementException; + /** * To update a comment. * * @param comment comment of the application. * @param apAppCommentId id of the comment - * @return updated comment + * @return {@link Comment}updated comment * @throws CommentManagementException Exceptions of the comment management * @throws SQLException SQL Exception * @throws DBConnectionException Database connection Exception */ Comment updateComment(Comment comment,int apAppCommentId) throws CommentManagementException, SQLException, DBConnectionException; + /** + * To get number of rated users + * + * @param uuid uuid of the application + * @return number of rated users + * @throws SQLException sql exception + */ + int getRatedUser(String uuid)throws SQLException; + /** * To get the average of stars * @@ -94,13 +125,4 @@ public interface CommentsManager { * @throws ApplicationManagementException Application Management Exception. */ int updateStars(int stars, String uuid) throws ApplicationManagementException; - - /** - * To get number of rated users - * - * @param uuid uuid of the application - * @return number of rated users - * @throws SQLException sql exception - */ - int getRatedUser(String uuid)throws SQLException; -} +} \ No newline at end of file From 819034f97d8297ca5e53477399dbbca4b0bbe7b2 Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 16:17:31 +0530 Subject: [PATCH 17/56] Adding Implementation of Comment Manager --- .../mgt/core/impl/CommentsManagerImpl.java | 268 +++++++++++++++++- 1 file changed, 266 insertions(+), 2 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java index 23c5903344..5ca47278ca 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java @@ -17,10 +17,274 @@ */ package org.wso2.carbon.device.application.mgt.core.impl; -import org.wso2.carbon.device.application.mgt.common.services.CommentsManager; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.application.mgt.common.Comment; +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 org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; +import org.wso2.carbon.device.application.mgt.common.exception.TransactionManagementException; +import org.wso2.carbon.device.application.mgt.common.services.*; +import org.wso2.carbon.device.application.mgt.core.dao.CommentDAO; +import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; +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.NotFoundException; +import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; + +import java.sql.SQLException; +import java.sql.Timestamp; +import java.time.Instant; +import java.util.List; /** * This class is the default implementation for the Managing the comments. */ +@SuppressWarnings( "deprecation" ) public class CommentsManagerImpl implements CommentsManager { -} + + private static final Log log = LogFactory.getLog(CommentsManagerImpl.class); + private CommentDAO commentDAO; + + public CommentsManagerImpl() { + initDataAccessObjects(); + } + + private void initDataAccessObjects() { + this.commentDAO= ApplicationManagementDAOFactory.getCommentDAO(); + } + + @Override + public Comment addComment(Comment comment,String uuid,int tenantId) throws CommentManagementException { + + if (log.isDebugEnabled()) { + log.debug("Request for comment is received for uuid" +uuid); + } + comment.setCreatedAt(Timestamp.from(Instant.now())); + + try { + ConnectionManagerUtil.beginDBTransaction(); + ApplicationManagementDAOFactory.getCommentDAO().addComment(tenantId,comment, + comment.getCreatedBy(),comment.getParent(),uuid); + ConnectionManagerUtil.commitDBTransaction(); + return comment; + } catch (Exception e) { + log.error("Exception occurs.", e); + ConnectionManagerUtil.rollbackDBTransaction(); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + return comment; + } + + /** + * To validate the pre-request of the comment + * + * @param apAppCommentId ID of the comment. + * @param comment comment needed to be validate. + * @return Application related with the UUID. + * + * + */ + + public Boolean validateComment(int apAppCommentId,String comment) throws CommentManagementException{ + + if (apAppCommentId <= 0) { + throw new CommentManagementException("Comment ID is null or negative. Comment id is a required parameter to get the " + + "relevant comment."); + } + + if(comment==null){ + throw new NullPointerException("No comment is entered."); + } + + try { + throw new NotFoundException("Comment with comment id "+apAppCommentId+" does not exit"); + } catch (NotFoundException e) { + log.error("Not Found Exception occurs.", e); + } + return true; + } + + + @Override + public List getAllComments(PaginationRequest request,String uuid) throws CommentManagementException, + SQLException { + + PaginationResult paginationResult = new PaginationResult(); + List comments; + request = Util.validateCommentListPageSize(request); + + + if (log.isDebugEnabled()) { + log.debug("get all comments of the application release"+uuid); + } + + try { + ConnectionManagerUtil.openDBConnection(); + comments=commentDAO.getAllComments(uuid,request);//count ,pagination request + int count=commentDAO.getCommentCount(request,uuid); + paginationResult.setData(comments); + paginationResult.setRecordsFiltered(count); + paginationResult.setRecordsTotal(count); + + return comments; + } catch (DBConnectionException e) { + log.error("DB Connection Exception occurs.", e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + return null; + } + + @Override + public Comment getComment(int apAppCommentId) throws CommentManagementException { + + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + Comment comment=null; + + if (log.isDebugEnabled()) { + log.debug("Comment retrieval request is received for the comment id " + apAppCommentId ); + } + + try { + ConnectionManagerUtil.openDBConnection(); + comment=ApplicationManagementDAOFactory.getCommentDAO().getComment(apAppCommentId); + } catch (DBConnectionException e) { + log.error("DB Connection Exception occurs.", e); + } catch (SQLException e) { + log.error("SQL Exception occurs.", e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + return comment; + } + + @Override + public void deleteComment(int apAppCommentId) throws CommentManagementException { + + Comment comment; + comment= getComment(apAppCommentId); + + if (comment == null) { + throw new CommentManagementException( + "Cannot delete a non-existing comment for the application with comment id" + apAppCommentId); + } + try { + ConnectionManagerUtil.beginDBTransaction(); + ApplicationManagementDAOFactory.getCommentDAO().deleteComment(apAppCommentId); + ConnectionManagerUtil.commitDBTransaction(); + } catch (DBConnectionException e) { + log.error("DB Connection Exception occurs.", e); + } catch (SQLException e) { + log.error("SQL Exception occurs.", e); + } catch (TransactionManagementException e) { + log.error("Transaction Management Exception occurs.", e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } + + @Override + public Comment updateComment(Comment comment,int apAppCommentId) throws CommentManagementException, SQLException, + DBConnectionException { + + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + validateComment(apAppCommentId,comment.getComment()); + + if (log.isDebugEnabled()) { + log.debug("Comment retrieval request is received for the comment id " +apAppCommentId); + } + comment.setModifiedAt(Timestamp.from(Instant.now())); + try { + ConnectionManagerUtil.openDBConnection(); + ApplicationManagementDAOFactory.getCommentDAO().getComment(apAppCommentId); + return ApplicationManagementDAOFactory.getCommentDAO().updateComment(apAppCommentId, + comment.getComment(),comment.getModifiedBy(),comment.getModifiedAt()); + } catch (SQLException e) { + log.error("SQL Exception occurs.", e); + } catch (DBConnectionException e) { + log.error("DB Connection Exception occurs.", e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + return ApplicationManagementDAOFactory.getCommentDAO().getComment(apAppCommentId); + } + + public int getRatedUser(String uuid){ + + int ratedUsers=0; + if (log.isDebugEnabled()) { + log.debug("Get the rated users for the application release number"+uuid); + } + try { + ConnectionManagerUtil.openDBConnection(); + ratedUsers =ApplicationManagementDAOFactory.getCommentDAO().getRatedUser(uuid); + } catch (DBConnectionException e) { + log.error("DB Connection Exception occurs.", e); + } catch (ApplicationManagementDAOException e) { + log.error("Application Management Exception occurs.", e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + return ratedUsers; + } + + @Override + public int getStars(String uuid) throws SQLException { + + int stars=0; + if (log.isDebugEnabled()) { + log.debug("Get the average of rated stars for the application "+uuid); + } + try { + ConnectionManagerUtil.openDBConnection(); + stars= ApplicationManagementDAOFactory.getCommentDAO().getStars(uuid); + } catch (DBConnectionException e) { + log.error("DB Connection Exception occurs.", e); + } catch (ApplicationManagementDAOException e) { + log.error("Application Management Exception occurs.", e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + return stars; + } + + @Override + public int updateStars(int stars , String uuid) throws ApplicationManagementException { + + if (log.isDebugEnabled()) { + log.debug("Stars are received for the application " + uuid); + } + int newStars=0; + try { + ConnectionManagerUtil.beginDBTransaction(); + + int ratedUsers = ApplicationManagementDAOFactory.getCommentDAO().getRatedUser(uuid); + int oldStars = ApplicationManagementDAOFactory.getCommentDAO().getStars(uuid); + if(ratedUsers==0){ + newStars=ApplicationManagementDAOFactory.getCommentDAO().updateStars(stars,uuid); + return newStars; + }else { + int avgStars = ((oldStars*ratedUsers)+stars) / (ratedUsers+1); + newStars = ApplicationManagementDAOFactory.getCommentDAO().updateStars(avgStars, uuid); + ConnectionManagerUtil.commitDBTransaction(); + return newStars; + } + } catch (ApplicationManagementDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + log.error("Application Management Exception occurs.", e); + + } catch (DBConnectionException e) { + log.error("DB Connection Exception occurs.", e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + return newStars; + } + + +} \ No newline at end of file From f7caa02b81c3690d46b48401b74711f3842552a8 Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 16:33:52 +0530 Subject: [PATCH 18/56] Modify pom.xml at org.wso2.carbon.device.application.mgt.common Dependancy is added to org.wso2.carbon.device.application.mgt.core --- .../org.wso2.carbon.device.application.mgt.common/pom.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml index 4493c59c69..785ed5b20d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml @@ -108,6 +108,10 @@ com.google.code.gson gson + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.application.mgt.core + From 7fb0faa2b89e662a69518c97ba405bee81f2adca Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 16:36:01 +0530 Subject: [PATCH 19/56] Modify pom.xml at org.wso2.carbon.device.application.mgt.api --- .../pom.xml | 190 ++++++++++++++++++ 1 file changed, 190 insertions(+) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/pom.xml index 412879e98c..37f188ed5f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/pom.xml @@ -225,5 +225,195 @@ javax.ws.rs javax.ws.rs-api + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.annotations + + + org.sonatype.sisu + sisu-guice + 2.1.7 + + + org.sonatype.sisu + sisu-guice + 2.1.7 + + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.annotations + + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.annotations + + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.annotations + + + org.apache.ode.wso2 + ode + 1.3.5-wso2v14 + + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.annotations + + + org.apache.ode.wso2 + ode + 1.3.5-wso2v14 + + + org.wso2.bpel + ode-bpel-api + 1.3.5-wso4v18 + + + org.wso2.orbit.org.apache.ode + ode + 1.3.5-wso4v18 + + + org.apache.ode.wso2 + ode + 1.3.5-wso2v14 + + + org.wso2.bpel + ode-bpel-dao + 1.3.5-wso4v18 + + + org.wso2.orbit.org.apache.ode + ode + 1.3.5-wso4v18 + + + org.wso2.carbon.business-process + org.wso2.carbon.bpel.skeleton + 4.4.25 + + + org.wso2.carbon.business-process + org.wso2.carbon.bpel.stub + 4.4.27 + + + org.wso2.carbon.identity + org.wso2.carbon.identity.workflow.mgt.bps.stub + 5.1.2 + + + org.apache.spark + spark-streaming-kafka-assembly_2.10 + 1.4.3.wso2v2 + + + org.ballerinalang + workspace-service + 0.8.14 + + + org.wso2.carbon.identity.workflow.impl.bps + org.wso2.carbon.identity.workflow.mgt.bps.stub + 5.1.13 + + + org.sonatype.sisu + sisu-guice + 2.1.7 + + + org.wso2.carbon.devicemgt + org.wso2.carbon.apimgt.annotations + 3.0.184 + + + org.wso2.carbon.extension.identity.authenticator + org.wso2.carbon.extension.identity.authenticator.twitter.connector + 1.0.5 + + + org.wso2.carbon.extension.identity.authenticator.outbound.twitter + org.wso2.carbon.extension.identity.authenticator.twitter.connector + 1.0.7 + + + org.wso2.extension.siddhi.execution.ml + siddhi-execution-ml + 1.0.1 + + + org.wso2.orbit.com.github.azakordonets + fabricator_2.10 + 2.1.4.wso2v1 + + + org.wso2.extension.siddhi.execution.ml + siddhi-execution-ml + 1.0.1 + + + org.wso2.orbit.com.github.azakordonets + fabricator_2.10 + 2.1.4.wso2v1 + + + org.wso2.orbit.com.github.azakordonets + fabricator_2.10 + 2.1.4.wso2v1 + + + org.wso2.carbon.identity.inbound.auth.oauth2 + org.wso2.carbon.identity.oauth.scope.endpoint + 5.5.160-SNAPSHOT + + + org.wso2.carbon.identity.inbound.auth.oauth2 + org.wso2.carbon.identity.oauth.scope.endpoint + 5.5.160-SNAPSHOT + + + org.wso2.carbon.identity.inbound.auth.oauth2 + org.wso2.carbon.identity.oauth.scope.endpoint + 5.5.160-SNAPSHOT + + + org.wso2.carbon.identity.inbound.auth.oauth2 + org.wso2.carbon.identity.oauth.scope.endpoint + 5.5.160-SNAPSHOT + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.api + 3.0.185-SNAPSHOT + + + org.wso2.carbon.devicemgt + org.wso2.carbon.certificate.mgt.api + 3.0.185-SNAPSHOT + + + org.wso2.carbon.devicemgt + org.wso2.carbon.certificate.mgt.cert.admin.api + 3.0.185-SNAPSHOT + + + org.wso2.carbon.devicemgt + org.wso2.carbon.certificate.mgt.cert.admin.api + 3.0.185-SNAPSHOT + + + org.apache.ode.wso2 + ode + 1.3.5-wso2v14 + + + org.apache.ode.wso2 + ode + 1.3.5-wso2v14 + \ No newline at end of file From 5dce27e23ba50731d729ddf0078844bf7327e4ce Mon Sep 17 00:00:00 2001 From: nishadi Date: Tue, 16 Jan 2018 16:40:21 +0530 Subject: [PATCH 20/56] Adding CommentDAOImpl Implementation of CommentDAO interface. --- .../core/dao/impl/Comment/CommentDAOImpl.java | 1114 +++++++++++++++++ 1 file changed, 1114 insertions(+) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java new file mode 100644 index 0000000000..bcf77f3f48 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java @@ -0,0 +1,1114 @@ +/* + * 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.core.dao.impl.Comment; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; +import org.wso2.carbon.device.application.mgt.common.Comment; +import org.wso2.carbon.device.application.mgt.common.PaginationRequest; +import org.wso2.carbon.device.application.mgt.common.exception.CommentManagementException; +import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; +import org.wso2.carbon.device.application.mgt.core.dao.CommentDAO; +import org.wso2.carbon.device.application.mgt.core.dao.common.Util; +import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; +import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; + +import java.sql.SQLException; +import java.sql.Timestamp; +import java.sql.ResultSet; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.time.Instant; +import java.util.ArrayList; +import java.util.List; + +/** + * This handles CommentDAO related operations. + */ + +@SuppressWarnings( "deprecation" ) +public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { + + private static final Log log = LogFactory.getLog(CommentDAOImpl.class); + + @Override + public int addComment(int tenantId, Comment comment, String createdBy, int parentId, String uuid) + throws CommentManagementException, DBConnectionException, SQLException { + + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to add comment for application release ("+uuid+")"); + } + Connection conn=this.getDBConnection(); + PreparedStatement stmt = null; + ResultSet rs=null; + int commentId = -1; + String sql = "INSERT INTO AP_APP_COMMENT (TENANT_ID, COMMENT_TEXT, CREATED_BY, PARENT_ID,AP_APP_RELEASE_ID," + + "AP_APP_ID) VALUES (?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?)," + + "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));"; + try{ + stmt = conn.prepareStatement(sql,new String[] {"id"}); + stmt.setInt(1, tenantId); + stmt.setString(2, comment.getComment()); + stmt.setString(3,createdBy); + stmt.setInt(4,parentId); + stmt.setString(5,uuid); + stmt.setString(6,uuid); + stmt.executeUpdate(); + + rs = stmt.getGeneratedKeys(); + if (rs.next()) { + commentId = rs.getInt(1); + } + return commentId; + } finally { + Util.cleanupResources(stmt, rs); + } + } + + @Override + public int addComment(int tenantId,Comment comment, String createdBy, String appType, String appName, + String version) throws CommentManagementException, DBConnectionException, SQLException { + + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to add to application ("+appName+") and version ("+version+")"); + } + + Connection conn=this.getDBConnection(); + PreparedStatement stmt = null; + ResultSet rs; + int commentId = -1; + String sql = "INSERT INTO AP_APP_COMMENT ( TENANT_ID,COMMENT_TEXT, CREATED_BY,AP_APP_RELEASE_ID,AP_APP_ID) " + + "VALUES (?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE VERSION =? AND (SELECT ID FROM AP_APP WHERE " + + "TYPE=? AND NAME=?)),(SELECT ID FROM AP_APP WHERE TYPE=? AND NAME=?));"; + try{ + stmt = conn.prepareStatement(sql, new String[] {"id"}); + stmt.setInt(1, tenantId); + stmt.setString(2, comment.getComment()); + stmt.setString(3,createdBy); + stmt.setString(4,version); + stmt.setString(5,appType); + stmt.setString(6,appName); + stmt.setString(7,appType); + stmt.setString(8,appName); + + stmt.executeUpdate(); + rs = stmt.getGeneratedKeys(); + if (rs.next()) { + commentId = rs.getInt(1); + } + + } finally { + Util.cleanupResources(stmt, null); + } + return commentId; + } + + @Override + public Comment updateComment(int apAppCommentId, String updatedComment, String modifiedBy, Timestamp modifiedAt) + throws CommentManagementException, DBConnectionException, SQLException { + + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to update the comment with ID ("+apAppCommentId+")"); + } + + Connection connection; + PreparedStatement statement = null; + ResultSet rs = null; + + String sql = "UPDATE AP_APP_COMMENT SET COMMENT_TEXT=?, MODEFIED_BY=? WHERE ID=?;"; + try { + connection = this.getDBConnection(); + statement = connection.prepareStatement(sql); + statement.setString(1, updatedComment); + statement.setString(2, modifiedBy); + statement.setInt(3, apAppCommentId); + + statement.executeUpdate(); + rs = statement.executeQuery(); + + } finally { + Util.cleanupResources(statement, rs); + } + return getComment(apAppCommentId); + } + + public Comment updateComment(String uuid, int apAppCommentID,String updatedComment, String modifiedBy, Timestamp + modifiedAt) throws CommentManagementException, DBConnectionException, SQLException { + + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to update the comment with application ("+uuid+") and " + + "comment id ( "+apAppCommentID+")"); + } + + Connection connection; + PreparedStatement statement = null; + ResultSet rs = null; + + String sql = "UPDATE AP_APP_COMMENT SET COMMENT_TEXT=?,MODEFIED_BY=? WHERE ID=?; "; + try { + connection = this.getDBConnection(); + statement = connection.prepareStatement(sql); + statement.setString(1, updatedComment); + statement.setString(2,modifiedBy); + statement.setInt(3,apAppCommentID); + statement.executeUpdate(); + rs= statement.getResultSet(); + + } finally { + Util.cleanupResources(statement, rs); + } + return getComment(apAppCommentID); + } + + @Override + public Comment getComment(int apAppCommentId) throws CommentManagementException { + if (log.isDebugEnabled()) { + log.debug("Getting comment with the comment id(" + apAppCommentId + ") from the database"); + } + Connection conn; + PreparedStatement stmt = null; + ResultSet rs ; + String sql = ""; + Comment comment=new Comment(); + + try { + conn = this.getDBConnection(); + sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE ID=?;"; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, apAppCommentId); + rs=stmt.executeQuery(); + + if (rs.next()) { + + comment.setId(rs.getInt("ID")); + comment.setTenantId(rs.getInt("TENANT_ID")); + comment.setComment(rs.getString("COMMENT_TEXT")); + comment.setCreatedAt(rs.getTimestamp("CREATED_AT")); + comment.setCreatedBy(rs.getString("CREATED_BY")); + comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); + comment.setModifiedBy(rs.getString("MODEFIED_AT")); + comment.setParent(rs.getInt("PARENT_ID")); + + Util.cleanupResources(stmt,rs); + return comment; + } + + } catch (SQLException e) { + throw new CommentManagementException("Error occurred while retrieving information of the comment "+apAppCommentId, e); + } catch (DBConnectionException e) { + log.error("DB Connection Exception occurs.", e); + } finally { + Util.cleanupResources(stmt, null); + } + return comment; + } + + @Override + public List getComment(String uuid) throws CommentManagementException{ + + if (log.isDebugEnabled()) { + log.debug("Getting comment with the application release(" +uuid + ") from the database"); + } + Connection conn; + PreparedStatement stmt = null; + ResultSet rs ; + String sql = ""; + List comments=new ArrayList<>(); + + try { + conn = this.getDBConnection(); + sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE (SELECT ID FROM AP_APP_RELEASE where UUID=?)AND " + + "(SELECT AP_APP_ID FROM AP_APP_RELEASE where UUID=?);"; + + stmt = conn.prepareStatement(sql); + stmt.setString(1, uuid); + stmt.setString(2,uuid); + rs=stmt.executeQuery(); + + while (rs.next()) { + Comment comment=new Comment(); + comment.setId(rs.getInt("ID")); + comment.setTenantId(rs.getInt("TENANT_ID")); + comment.setComment(rs.getString("COMMENT_TEXT")); + comment.setCreatedAt(rs.getTimestamp("CREATED_AT")); + comment.setCreatedBy(rs.getString("CREATED_BY")); + comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); + comment.setModifiedBy(rs.getString("MODEFIED_AT")); + comment.setParent(rs.getInt("PARENT_ID")); + + comments.add(comment); + } + } catch (DBConnectionException e) { + log.error("DB Connection Exception occurs.", e); + } catch (SQLException e) { + throw new CommentManagementException("Error occurred while retrieving comments", e); + } finally { + Util.cleanupResources(stmt, null); + } + return comments; + } + + @Override + public List getAllComments(String uuid,PaginationRequest request) throws CommentManagementException, SQLException, + DBConnectionException { + if (log.isDebugEnabled()) { + log.debug("Getting comment of the application release ("+uuid+") from the database"); + } + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + List comments=new ArrayList<>(); + String sql = ""; + + try { + conn = this.getDBConnection(); + sql += "\n" + + "SELECT COMMENT_TEXT FROM AP_APP_COMMENT, AP_APP_RELEASE WHERE AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID " + + "AND AP_APP_RELEASE.UUID =? LIMIT ? OFFSET ?;"; + stmt = conn.prepareStatement(sql); + stmt.setString(1,uuid); + stmt.setInt(2,request.getLimit()); + stmt.setInt(3,request.getOffSet()); + rs= stmt.executeQuery(); + + while (rs.next()) { + Comment comment=new Comment(); + comment.setId(rs.getInt("ID")); + comment.setTenantId(rs.getInt("TENANT_ID")); + comment.setComment(rs.getString("COMMENT_TEXT")); + comment.setCreatedAt(rs.getTimestamp("CREATED_AT")); + comment.setCreatedBy(rs.getString("CREATED_BY")); + comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); + comment.setModifiedBy(rs.getString("MODEFIED_BY")); + comment.setParent(rs.getInt("PARENT_ID")); + + comments.add(comment); + } + } finally { + Util.cleanupResources(stmt, rs); + } + return comments; + } + + @Override + public int getCommentCount(PaginationRequest request, String uuid) throws CommentManagementException { + + int commentCount = 0; + Connection conn; + PreparedStatement stmt = null; + ResultSet rs = null; + boolean isUuidProvided=false; + + try { + conn = this.getDBConnection(); + if (uuid!= null) { + isUuidProvided = true; + } + + if (isUuidProvided) { + String sql = "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE " + + "WHERE AP_APP_COMMENT.AP_APP_RELEASE_ID= AP_APP_RELEASE.ID AND " + + "AP_APP_COMMENT.AP_APP_ID= AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;"; + stmt = conn.prepareStatement(sql); + stmt.setString(1, uuid); + rs = stmt.executeQuery(); + + if (rs.next()) { + commentCount = rs.getInt("COMMENTS_COUNT"); + } + } + } catch (SQLException e) { + throw new CommentManagementException("Error occurred while retrieving count of comments", e); + } catch (DBConnectionException e) { + log.error("DB Connection Exception occurs.", e); + } finally { + Util.cleanupResources(stmt, rs); + } + return commentCount; + } + + @Override + public List getComments(int appReleasedId, int appId) throws CommentManagementException { + + if (log.isDebugEnabled()) { + log.debug("Getting comments with the application release id(" + appReleasedId + ") and " + + "application id("+appId+") from the database"); + } + Connection conn; + PreparedStatement stmt = null; + ResultSet rs ; + String sql = ""; + List comments = new ArrayList<>(); + + try { + conn = this.getDBConnection(); + sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? AND AP_APP_ID=?;"; + + stmt = conn.prepareStatement(sql); + stmt.setInt(1, appReleasedId); + stmt.setInt(2,appId); + rs=stmt.executeQuery(); + + while (rs.next()) { + Comment comment=new Comment(); + comment.setId(rs.getInt("ID")); + comment.setTenantId(rs.getInt("TENANT_ID")); + comment.setComment(rs.getString("COMMENT_TEXT")); + comment.setCreatedAt(rs.getTimestamp("CREATED_AT")); + comment.setCreatedBy(rs.getString("CREATED_BY")); + comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); + comment.setModifiedBy(rs.getString("modifiedBy")); + comment.setParent(rs.getInt("PARENT_ID")); + + comments.add(comment); + } + } catch (DBConnectionException e) { + log.error("DB Connection Exception occurs.", e); + + } catch (SQLException e) { + throw new CommentManagementException("Error occurred while retrieving information of comments", e); + + } finally { + Util.cleanupResources(stmt, null); + } + return comments; + } + + @Override + public List getComments(String appType, String appName, String version) throws CommentManagementException, + DBConnectionException, SQLException { + if (log.isDebugEnabled()) { + log.debug("Getting comments with the application name(" + appName + "),application type("+appType+") " + + "and application version ("+version+") from the database"); + } + Connection conn; + PreparedStatement stmt = null; + ResultSet rs; + String sql = ""; + List comments =new ArrayList<>(); + + try { + conn = this.getDBConnection(); + sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID FROM AP_APP_COMMENT C ,"+ + "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=?) R,"+ + "(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? AND TYPE=?)P"+ + " WHERE AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND AP_APP_ID=RELEASE_AP_APP_ID"+ + "ORDER BY CREATED_AT DESC;"; + + stmt = conn.prepareStatement(sql); + stmt.setString(1, version); + stmt.setString(2,appName); + stmt.setString(3,appType); + rs=stmt.executeQuery(); + + while (rs.next()) { + Comment comment=new Comment(); + comment.setId(rs.getInt("ID")); + comment.setTenantId(rs.getInt("TENANT_ID")); + comment.setComment(rs.getString("COMMENT_TEXT")); + comment.setCreatedAt(rs.getTimestamp("CREATED_AT")); + comment.setCreatedBy(rs.getString("CREATED_BY")); + comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); + comment.setModifiedBy(rs.getString("modifiedBy")); + comment.setParent(rs.getInt("PARENT_ID")); + + comments.add(comment); + } + } finally { + Util.cleanupResources(stmt, null); + } + return comments; + } + + @Override + public List getComments(int tenantId) throws CommentManagementException, DBConnectionException, + SQLException { + + if (log.isDebugEnabled()) { + log.debug("Getting comments with the tenant_id(" + tenantId + ") from the database"); + } + + Connection conn; + PreparedStatement stmt = null; + ResultSet rs; + String sql = ""; + List comments = new ArrayList<>(); + + try { + conn = this.getDBConnection(); + sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE TENANT_ID='?';"; + + stmt = conn.prepareStatement(sql); + stmt.setInt(1, tenantId); + rs=stmt.executeQuery(); + + while (rs.next()) { + Comment comment=new Comment(); + comment.setId(rs.getInt("ID")); + comment.setTenantId(rs.getInt("TENANT_ID")); + comment.setComment(rs.getString("COMMENT_TEXT")); + comment.setCreatedAt(rs.getTimestamp("CREATED_AT")); + comment.setCreatedBy(rs.getString("CREATED_BY")); + comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); + comment.setModifiedBy(rs.getString("modifiedBy")); + comment.setParent(rs.getInt("PARENT_ID")); + + comments.add(comment); + } + } finally { + Util.cleanupResources(stmt, null); + } + return comments; + } + + @Override + public List getCommentsByUser(String createdBy) throws CommentManagementException, DBConnectionException, + SQLException { + + if (log.isDebugEnabled()) { + log.debug("Getting comments with the created by(" + createdBy + ") from the database"); + } + + Connection conn; + PreparedStatement stmt = null; + ResultSet rs; + String sql = ""; + List comments = new ArrayList<>(); + + try { + conn = this.getDBConnection(); + sql += "SELECT COMMENT_TEXT ,PARENT_ID,TENANT_ID,CREATED_AT FROM AP_APP_COMMENT WHERE CREATED_BY= ?" + + " ORDER BY CREATED_AT DESC;"; + + stmt = conn.prepareStatement(sql); + stmt.setString(1, createdBy); + rs=stmt.executeQuery(); + + while (rs.next()) { + Comment comment=new Comment(); + comment.setId(rs.getInt("ID")); + comment.setTenantId(rs.getInt("TENANT_ID")); + comment.setComment(rs.getString("COMMENT_TEXT")); + comment.setCreatedAt(rs.getTimestamp("CREATED_AT")); + comment.setCreatedBy(rs.getString("CREATED_BY")); + comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); + comment.setModifiedBy(rs.getString("modifiedBy")); + comment.setParent(rs.getInt("PARENT_ID")); + + comments.add(comment); + } + } finally { + Util.cleanupResources(stmt, null); + } + return comments; + } + + @Override + public List getCommentsByUser(String createdBy, Timestamp createdAt) throws CommentManagementException, + DBConnectionException, SQLException { + + if (log.isDebugEnabled()) { + log.debug("Getting comments with the created by(" + createdBy + ") at ("+createdAt+") from the database"); + } + + Connection conn; + PreparedStatement stmt = null; + ResultSet rs; + String sql = ""; + List comments = new ArrayList<>(); + + try { + conn = this.getDBConnection(); + sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID FROM AP_APP_COMMENT WHERE CREATED_BY=?" + + "AND CREATED_AT= ? ORDER BY CREATED_AT DESC;"; + + stmt = conn.prepareStatement(sql); + stmt.setString(1, createdBy); + stmt.setTimestamp(2,createdAt); + rs=stmt.executeQuery(); + + while (rs.next()) { + Comment comment=new Comment(); + comment.setId(rs.getInt("ID")); + comment.setTenantId(rs.getInt("TENANT_ID")); + comment.setComment(rs.getString("COMMENT_TEXT")); + comment.setCreatedAt(rs.getTimestamp("CREATED_AT")); + comment.setCreatedBy(rs.getString("CREATED_BY")); + comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); + comment.setModifiedBy(rs.getString("modifiedBy")); + comment.setParent(rs.getInt("PARENT_ID")); + + comments.add(comment); + } + } finally { + Util.cleanupResources(stmt, null); + } + return comments; + } + + @Override + public List getCommentsByModifiedUser(String modifiedBy) throws CommentManagementException, + DBConnectionException, SQLException { + + if (log.isDebugEnabled()) { + log.debug("Getting comments with the modified by(" +modifiedBy + ") from the database"); + } + + Connection conn; + PreparedStatement stmt = null; + ResultSet rs ; + String sql = ""; + List comments = new ArrayList<>(); + + try { + conn = this.getDBConnection(); + sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID,CREATED_AT,MODEFIED_AT FROM AP_APP_COMMENT " + + "WHERE MODEFIED_BY= ? ORDER BY CREATED_AT DESC;"; + + stmt = conn.prepareStatement(sql); + stmt.setString(1, modifiedBy); + rs=stmt.executeQuery(); + + while (rs.next()) { + Comment comment=new Comment(); + comment.setId(rs.getInt("ID")); + comment.setTenantId(rs.getInt("TENANT_ID")); + comment.setComment(rs.getString("COMMENT_TEXT")); + comment.setCreatedAt(rs.getTimestamp("CREATED_AT")); + comment.setCreatedBy(rs.getString("CREATED_BY")); + comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); + comment.setModifiedBy(rs.getString("modifiedBy")); + comment.setParent(rs.getInt("PARENT_ID")); + + comments.add(comment); + } + } finally { + Util.cleanupResources(stmt, null); + } + return comments; + } + + @Override + public List getCommentsByModifiedUser(String modifiedBy, Timestamp modifiedAt) + throws CommentManagementException, DBConnectionException, SQLException { + + if (log.isDebugEnabled()) { + log.debug("Getting comments with the modified by(" +modifiedBy + ") at ("+modifiedAt+") from the " + + "database"); + } + + Connection conn; + PreparedStatement stmt = null; + ResultSet rs; + String sql = ""; + List comments = new ArrayList<>(); + + try { + conn = this.getDBConnection(); + sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID,CREATED_AT FROM AP_APP_COMMENT WHERE MODEFIED_BY= ?," + + "MODEFIED_AT=? ORDER BY CREATED_AT DESC;"; + + stmt = conn.prepareStatement(sql); + stmt.setString(1, modifiedBy); + stmt.setTimestamp(2,modifiedAt); + rs=stmt.executeQuery(); + + while (rs.next()) { + Comment comment=new Comment(); + comment.setId(rs.getInt("ID")); + comment.setTenantId(rs.getInt("TENANT_ID")); + comment.setComment(rs.getString("COMMENT_TEXT")); + comment.setCreatedAt(rs.getTimestamp("CREATED_AT")); + comment.setCreatedBy(rs.getString("CREATED_BY")); + comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); + comment.setModifiedBy(rs.getString("modifiedBy")); + comment.setParent(rs.getInt("PARENT_ID")); + + comments.add(comment); + } + } finally { + Util.cleanupResources(stmt, null); + } + return comments; + } + + @Override + public List getComments(String appType, String appName, String version, int parentId) + throws CommentManagementException, DBConnectionException, SQLException { + + if (log.isDebugEnabled()) { + log.debug("Getting comments with the application name(" + appName + "),application type("+appType+") and" + + "application version ("+version+") from the database"); + } + + Connection conn; + PreparedStatement stmt = null; + ResultSet rs; + String sql = ""; + List comments =new ArrayList<>(); + + try { + conn = this.getDBConnection(); + sql += "SELECT COMMENT_TEXT,TENANT_ID FROM AP_APP_COMMENT C ," + + "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=? ) " + + "R,(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? AND TYPE=?)P " + + "WHERE PARENT_ID=? AND AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND " + + "AP_APP_ID=RELEASE_AP_APP_ID ORDER BY CREATED_AT DESC;"; + + stmt = conn.prepareStatement(sql); + stmt.setString(1, version); + stmt.setString(2,appName); + stmt.setString(3,appType); + stmt.setInt(4,parentId); + rs=stmt.executeQuery(); + + while (rs.next()) { + Comment comment=new Comment(); + comment.setId(rs.getInt("ID")); + comment.setTenantId(rs.getInt("TENANT_ID")); + comment.setComment(rs.getString("COMMENT_TEXT")); + comment.setCreatedAt(rs.getTimestamp("CREATED_AT")); + comment.setCreatedBy(rs.getString("CREATED_BY")); + comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); + comment.setModifiedBy(rs.getString("modifiedBy")); + comment.setParent(rs.getInt("PARENT_ID")); + + comments.add(comment); + } + } finally { + Util.cleanupResources(stmt, null); + } + return comments; + } + + @Override + public int getCommentCount(String uuid) throws CommentManagementException, DBConnectionException, + SQLException { + Connection conn; + PreparedStatement stmt = null; + int commentCount = 0; + + try { + conn = this.getDBConnection(); + String sql = "\n" + + "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE WHERE " + + "AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_COMMENT.AP_APP_ID=" + + "AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;"; + + stmt = conn.prepareStatement(sql); + stmt.setString(1, uuid); + ResultSet rs = stmt.executeQuery(); + if (rs.next()) { + commentCount = rs.getInt("ID"); + } + } finally { + Util.cleanupResources(stmt, null); + + return commentCount; + } + } + + @Override + public int getCommentCountByUser(String createdBy) throws CommentManagementException, DBConnectionException, + SQLException { + + Connection conn; + PreparedStatement stmt = null; + int commentCount = 0; + + try { + conn = this.getDBConnection(); + String sql = "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE CREATED_BY= ?;"; + + stmt = conn.prepareStatement(sql); + stmt.setString(1, createdBy); + ResultSet rs = stmt.executeQuery(); + + if (rs.next()) { + commentCount = rs.getInt("COMMENT_COUNT"); + } + } finally { + Util.cleanupResources(stmt, null); + + } + return commentCount; + + } + + @Override + public int getCommentCountByUser(String modifiedBy, Timestamp modifedAt) throws CommentManagementException, + DBConnectionException, SQLException { + + Connection conn; + PreparedStatement stmt = null; + int commentCount = 0; + + try { + conn = this.getDBConnection(); + String sql = "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE MODEFIED_BY= ? AND MODEFIED_AT=?;"; + stmt = conn.prepareStatement(sql); + stmt.setString(1, modifiedBy); + stmt.setTimestamp(2, modifedAt); + ResultSet rs = stmt.executeQuery(); + + if (rs.next()) { + commentCount = rs.getInt("COMMENT_COUNT"); + } + } finally { + Util.cleanupResources(stmt, null); + } + return commentCount; + } + + @Override + public int getCommentCountByApp(int appId, int appReleaseId) throws CommentManagementException, + DBConnectionException, SQLException { + + Connection conn; + PreparedStatement stmt = null; + int commentCount = 0; + + try { + conn = this.getDBConnection(); + String sql = "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? AND AP_APP_ID=?;"; + + stmt = conn.prepareStatement(sql); + stmt.setInt(1, appReleaseId); + stmt.setInt(2, appId); + ResultSet rs = stmt.executeQuery(); + + if (rs.next()) { + commentCount = rs.getInt("COMMENT_COUNT"); + } + } finally { + Util.cleanupResources(stmt, null); + } + return commentCount; + } + + @Override + public int getCommentCountByApp(String appType, String appName, String version) throws CommentManagementException, + DBConnectionException, SQLException { + + Connection conn; + PreparedStatement stmt = null; + int commentCount = 0; + + try { + conn = this.getDBConnection(); + String sql = "SELECT COUNT(ID) AS COMMENT_COUNT FROM AP_APP_COMMENT C, " + + "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=? )R," + + "(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? and TYPE=?)P " + + "WHERE AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND AP_APP_ID=RELEASE_AP_APP_ID;"; + + stmt = conn.prepareStatement(sql); + stmt.setString(1, version); + stmt.setString(2, appName); + stmt.setString(3, appType); + ResultSet rs = stmt.executeQuery(); + + if (rs.next()) { + commentCount = rs.getInt("COMMENT_COUNT"); + } + } finally { + Util.cleanupResources(stmt, null); + } + return commentCount; + } + + public int getCommentCountByParent(String uuid,int parentId) throws CommentManagementException, DBConnectionException, SQLException { + + Connection conn; + PreparedStatement stmt = null; + int commentCount = 0; + + try { + conn = this.getDBConnection(); + String sql = "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE WHERE " + + "AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND " + + "AP_APP_COMMENT.AP_APP_ID=AP_APP_RELEASE.AP_APP_ID and AP_APP_RELEASE.UUID=? and PARENT_ID=?;"; + + stmt = conn.prepareStatement(sql); + stmt.setString(1,uuid); + stmt.setInt(2,parentId); + ResultSet rs = stmt.executeQuery(); + if (rs.next()) { + commentCount = rs.getInt("COMMENT_COUNT"); + } + } finally { + Util.cleanupResources(stmt, null); + } + return commentCount; + } + + @Override + public void deleteComment(int apAppCommentId) throws CommentManagementException, DBConnectionException, + SQLException { + + Connection conn; + PreparedStatement stmt = null; + try { + conn = this.getDBConnection(); + String sql = "DELETE FROM AP_APP_COMMENT WHERE ID=?;"; + stmt = conn.prepareStatement(sql); + stmt.setInt(1, apAppCommentId); + stmt.executeUpdate(); + } finally { + Util.cleanupResources(stmt, null); + } + } + + public void deleteComment(String uuid) throws CommentManagementException, DBConnectionException, SQLException { + + Connection conn; + PreparedStatement stmt = null; + + try { + conn = this.getDBConnection(); + String sql = "DELETE FROM AP_APP_COMMENT WHERE " + + "(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?)AND (SELECT AP_APP_ID FROM AP_APP_RELEASE " + + "WHERE UUID=?);"; + + stmt = conn.prepareStatement(sql); + stmt.setString(1,uuid); + stmt.setString(2,uuid); + stmt.executeUpdate(); + } finally { + Util.cleanupResources(stmt, null); + } + } + + @Override + public void deleteComments(int appId, int appReleaseID) throws CommentManagementException, DBConnectionException, + SQLException { + + Connection conn; + PreparedStatement stmt = null; + + try { + conn = this.getDBConnection(); + String sql = "DELETE FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? and AP_APP_ID=?;"; + + stmt = conn.prepareStatement(sql); + stmt.setInt(1, appReleaseID); + stmt.setInt(2,appId); + stmt.executeUpdate(); + } finally { + Util.cleanupResources(stmt, null); + } + } + + @Override + public void deleteComments(String appType, String appName, String version) throws CommentManagementException { + + Connection conn; + PreparedStatement stmt = null; + + try { + conn = this.getDBConnection(); + String sql = "DELETE FROM AP_APP_COMMENT WHERE " + + "(SELECT AP_APP_RELEASE_ID FROM AP_APP_RELEASE WHERE VERSION=? AND " + + "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? AND TYPE=?)) AND " + + "(SELECT AP_APP_ID FROM AP_APP AND NAME=? AND TYPE=?);"; + + stmt = conn.prepareStatement(sql); + stmt.setString(1, version); + stmt.setString(2,appName); + stmt.setString(3,appType); + stmt.setString(4,appName); + stmt.setString(5,appType); + stmt.executeUpdate(); + } catch (DBConnectionException e) { + log.error("DB Connection Exception occurs.", e); + } catch (SQLException e) { + throw new CommentManagementException("Error occurred while deleting comments", e); + } finally { + Util.cleanupResources(stmt, null); + } + } + + @Override + public void deleteComments(String appType, String appName, String version, String createdBy) + throws CommentManagementException { + + Connection conn; + PreparedStatement stmt = null; + + try { + conn = this.getDBConnection(); + String sql = "DELETE FROM AP_APP_COMMENT WHERE " + + "(SELECT AP_APP_RELEASE_ID FROM AP_APP_RELEASE WHERE VERSION=? AND " + + "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? AND TYPE=?)) AND " + + "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? and TYPE=?) AND CREATED_BY=?;"; + + stmt = conn.prepareStatement(sql); + stmt.setString(1, version); + stmt.setString(2,appName); + stmt.setString(3,appType); + stmt.setString(4,appName); + stmt.setString(5,appType); + stmt.setString(6,createdBy); + stmt.executeUpdate(); + } catch (DBConnectionException e) { + log.error("DB Connection Exception occurs.", e); + } catch (SQLException e) { + throw new CommentManagementException("Error occurred while deleting comments", e); + } finally { + Util.cleanupResources(stmt, null); + } + } + + @Override + public void deleteComments(String uuid,int parentId) + throws CommentManagementException { + + Connection conn; + PreparedStatement stmt = null; + + try { + conn = this.getDBConnection(); + String sql = "DELETE FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?) " + + "AND AP_APP_ID=(SELECT AP_APP_ID FROM AP_APP_RELEASE where UUID=?)AND PARENT_ID=?;"; + + stmt = conn.prepareStatement(sql); + stmt.setString(1,uuid); + stmt.setString(2,uuid); + stmt.setInt(3,parentId); + stmt.executeUpdate(); + } catch (DBConnectionException e) { + log.error("DB Connection Exception occurs.", e); + } catch (SQLException e) { + throw new CommentManagementException("Error occurred while deleting comments", e); + } finally { + Util.cleanupResources(stmt, null); + } + } + + @Override + public int updateStars(int stars, String uuid) throws ApplicationManagementDAOException { + + Connection connection; + PreparedStatement stmt = null; + ResultSet resultSet = null; + try { + connection = this.getDBConnection(); + String sql = "UPDATE AP_APP_RELEASE SET STARS=?, NO_OF_RATED_USERS=(NO_OF_RATED_USERS+1) WHERE UUID=?;"; + + stmt = connection.prepareStatement(sql); + stmt.setInt(1,stars); + stmt.setString(2, uuid); + resultSet=stmt.executeQuery(); + + resultSet = stmt.executeQuery(sql); + if (resultSet != null) { + resultSet.getInt("STARS"); + } + int numORows=resultSet.getRow(); + + if (resultSet.next()) { + ApplicationRelease applicationRelease=new ApplicationRelease(); + applicationRelease.setStars(resultSet.getInt("STARS")); + + Util.cleanupResources(stmt, resultSet); + } + } catch (SQLException e) { + throw new ApplicationManagementDAOException( + "SQL Exception while trying to add stars to an application (UUID : " + uuid + "), by executing " + + "the query " + e); + } catch (DBConnectionException e) { + log.error("DB Connection Exception occurs.", e); + } finally { + Util.cleanupResources(stmt, null); + return getStars(uuid); + + } + + } + + @Override + public int getStars(String uuid) throws ApplicationManagementDAOException { + + Connection connection; + PreparedStatement statement = null; + ResultSet resultSet = null; + String sql; + int Stars=0; + + try { + connection = this.getDBConnection(); + sql="SELECT STARS FROM AP_APP_RELEASE WHERE UUID=?;"; + + statement = connection.prepareStatement(sql); + statement.setString(1,uuid); + resultSet = statement.executeQuery(); + + if (resultSet.next()) { + ApplicationRelease applicationRelease = new ApplicationRelease(); + Stars=resultSet.getInt("STARS"); + + return Stars; + } + } catch (SQLException e) { + throw new ApplicationManagementDAOException( + "SQL Exception while trying to get stars from an application (UUID : " + uuid + "), by executing " + + "the query " + e); + } catch (DBConnectionException e) { + log.error("DB Connection Exception occurs.", e); + } finally { + Util.cleanupResources(statement, resultSet); + } + return Stars ; + } + + @Override + public int getRatedUser(String uuid) throws ApplicationManagementDAOException { + + Connection connection; + PreparedStatement statement = null; + ResultSet resultSet = null; + String sql; + int ratedUsers=0; + + try { + connection = this.getDBConnection(); + sql = "SELECT NO_OF_RATED_USERS FROM AP_APP_RELEASE WHERE UUID=?;"; + statement = connection.prepareStatement(sql); + statement.setString(1,uuid); + resultSet = statement.executeQuery(); + + if (resultSet.next()) { + ApplicationRelease applicationRelease = new ApplicationRelease(); + ratedUsers =resultSet.getInt("NO_OF_RATED_USERS"); + applicationRelease.setNoOfRatedUsers(ratedUsers); + + Util.cleanupResources(statement, resultSet); + return ratedUsers; + } + } catch (SQLException e) { + log.error("SQL Exception occurs.", e); + } catch (DBConnectionException e) { + log.error("DB Connection Exception occurs.", e); + } finally { + Util.cleanupResources(statement, resultSet); + } + return ratedUsers; + } +} From a6434d918b50a4bff8803824da411890046bb182 Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 11:07:11 +0530 Subject: [PATCH 21/56] Modify APIUtil change the format of imports. --- .../carbon/device/application/mgt/api/APIUtil.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java index 8549f7b961..f58d74bb14 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java @@ -22,7 +22,15 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse; -import org.wso2.carbon.device.application.mgt.common.services.*; +import org.wso2.carbon.device.application.mgt.common.services.CommentsManager; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; +import org.wso2.carbon.device.application.mgt.common.services.PlatformManager; +import org.wso2.carbon.device.application.mgt.common.services.LifecycleStateManager; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationReleaseManager; +import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; +import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; +import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager; +import org.wso2.carbon.device.application.mgt.common.services.CategoryManager; import javax.ws.rs.core.Response; From 7849d0938bf71adc736f838dbe0e3a000bac8042 Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 11:09:39 +0530 Subject: [PATCH 22/56] Modify APIUtil change the format of imports. --- .../java/org/wso2/carbon/device/application/mgt/api/APIUtil.java | 1 - 1 file changed, 1 deletion(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java index f58d74bb14..54c2821052 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java @@ -31,7 +31,6 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager; import org.wso2.carbon.device.application.mgt.common.services.CategoryManager; - import javax.ws.rs.core.Response; From 0f4e4ea4831dee95645b910c345b6d56cfdb5551 Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 11:18:24 +0530 Subject: [PATCH 23/56] Modify CommentManagementAPI add "defaultValue" parameter here in the ApiParams --- .../application/mgt/api/services/CommentManagementAPI.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java index ac80295ad0..baccd8132f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java @@ -129,13 +129,13 @@ public interface CommentManagementAPI { String uuid, @ApiParam( name="offSet", - value="Starting comment number.", + value="Starting comment number.",defaultValue = "1", required = false) @QueryParam("offSet") int offSet, @ApiParam( name="limit", - value = "Limit of paginated comments", + value = "Limit of paginated comments",defaultValue = "20", required = false) @QueryParam("limit") int limit); From 06059cacf1713fbe8b04521a4822ef907619cc50 Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 11:19:56 +0530 Subject: [PATCH 24/56] Modify CommentManagementAPIImpl Removed the comment. --- .../mgt/api/services/impl/CommentManagementAPIImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java index 2e0a8b11dd..2c1830c57f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java @@ -102,7 +102,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ @PathParam("apAppCommentId") int apAppCommentId) { CommentsManager commentsManager = APIUtil.getCommentsManager(); - //int tenantId= PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + try { if (apAppCommentId == 0) { return Response.status(Response.Status.NOT_FOUND) From 453559a07b5d8d861cf0e14f3262e7d607c80781 Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 11:24:54 +0530 Subject: [PATCH 25/56] Modify CommentManagementAPIImpl returned Error Response. --- .../mgt/api/services/impl/CommentManagementAPIImpl.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java index 2c1830c57f..f920ccb963 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java @@ -63,6 +63,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } catch (SQLException e) { log.error("SQL Exception occurs", e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } return Response.status(Response.Status.OK).entity(comments).build(); } @@ -121,11 +122,11 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } catch (SQLException e) { log.error("SQL Exception occurs", e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); }catch (DBConnectionException e) { log.error("DB Connection Exception occurs", e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } - - return Response.status(Response.Status.OK).entity(comment).build(); } @Override @@ -164,6 +165,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ Stars= commentsManager.getStars(uuid); } catch (SQLException e) { log.error("SQL Exception occurs", e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } return Response.status(Response.Status.OK).entity(Stars).build(); } @@ -182,6 +184,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ ratedUsers= commentsManager.getRatedUser(uuid); } catch (SQLException e) { log.error("SQL Exception occurs", e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } return Response.status(Response.Status.OK).entity(ratedUsers).build(); } From 99b916d6ffac5faec6b696d4bc793fdd1357720f Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 11:30:02 +0530 Subject: [PATCH 26/56] Modify Comment Removed commented codes. --- .../carbon/device/application/mgt/common/Comment.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Comment.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Comment.java index 9e2050a626..219f711e72 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Comment.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Comment.java @@ -43,7 +43,6 @@ public class Comment { private Timestamp modifiedAt; -// private Application application; public int getTenantId() { return tenantId; } @@ -109,15 +108,5 @@ public class Comment { this.modifiedAt = modifiedAt; } -// public Application getApplication() { -// return application; -// } -// -// public void setApplication(Application application) { -// this.application = application; -// } - - - } From a1911432a6bf1e9420d18cf8e6de89eab7c0f91d Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 11:32:50 +0530 Subject: [PATCH 27/56] Modify PaginationConfiguration Removed commented codes. --- .../core/config/PaginationConfiguration.java | 51 ------------------- 1 file changed, 51 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/PaginationConfiguration.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/PaginationConfiguration.java index 8905b6de95..03be1dadc2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/PaginationConfiguration.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/PaginationConfiguration.java @@ -28,11 +28,6 @@ import javax.xml.bind.annotation.XmlRootElement; public class PaginationConfiguration { private int commentListPageSize; -// private int groupListPageSize; -// private int operationListPageSize; -// private int notificationListPageSize; -// private int activityListPageSize; -// private int topicListPageSize; public int getCommentListPageSize() { return commentListPageSize; @@ -43,50 +38,4 @@ public class PaginationConfiguration { this.commentListPageSize = commentListPageSize; } -// public int getGroupListPageSize() { -// return groupListPageSize; -// } -// -// @XmlElement(name = "GroupListPageSize", required = true) -// public void setGroupListPageSize(int groupListPageSize) { -// this.groupListPageSize = groupListPageSize; -// } -// -// public int getOperationListPageSize() { -// return operationListPageSize; -// } -// -// @XmlElement(name = "OperationListPageSize", required = true) -// public void setOperationListPageSize(int operationListPageSize) { -// this.operationListPageSize = operationListPageSize; -// } -// -// public int getNotificationListPageSize() { -// return notificationListPageSize; -// } -// -// @XmlElement(name = "NotificationListPageSize", required = true) -// public void setNotificationListPageSize(int notificationListPageSize) { -// this.notificationListPageSize = notificationListPageSize; -// } -// -// public int getActivityListPageSize() { -// return activityListPageSize; -// } -// -// @XmlElement(name = "ActivityListPageSize", required = true) -// public void setActivityListPageSize(int activityListPageSize) { -// this.activityListPageSize = activityListPageSize; -// } -// -// public int getTopicListPageSize() { -// return deviceListPageSize; -// } -// -// @XmlElement(name = "TopicListPageSize", required = true) -// public void setTopicListPageSize(int topicListPageSize) { -// this.topicListPageSize = topicListPageSize; -// } - - } From 4fb77cbee8d48ebc383f6dde4f12316313f9c354 Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 11:45:14 +0530 Subject: [PATCH 28/56] Modify CommentsManagerImpl Removed throwing NullPointerException; --- .../application/mgt/core/impl/CommentsManagerImpl.java | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java index 5ca47278ca..a310e77a53 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java @@ -35,6 +35,7 @@ import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManageme import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; +import javax.ws.rs.core.Response; import java.sql.SQLException; import java.sql.Timestamp; import java.time.Instant; @@ -96,9 +97,9 @@ public class CommentsManagerImpl implements CommentsManager { throw new CommentManagementException("Comment ID is null or negative. Comment id is a required parameter to get the " + "relevant comment."); } - if(comment==null){ - throw new NullPointerException("No comment is entered."); + log.error("Null Point Exception.Comment at comment id "+apAppCommentId+" is null."); + return false; } try { @@ -125,7 +126,7 @@ public class CommentsManagerImpl implements CommentsManager { try { ConnectionManagerUtil.openDBConnection(); - comments=commentDAO.getAllComments(uuid,request);//count ,pagination request + comments=commentDAO.getAllComments(uuid,request); int count=commentDAO.getCommentCount(request,uuid); paginationResult.setData(comments); paginationResult.setRecordsFiltered(count); From 906535eb2499ca27ac4c14feababe51b82825502 Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 11:51:32 +0530 Subject: [PATCH 29/56] Modify CommentsManagerImpl Removed Not found Exception --- .../application/mgt/core/impl/CommentsManagerImpl.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java index a310e77a53..024aaa9cac 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java @@ -101,12 +101,6 @@ public class CommentsManagerImpl implements CommentsManager { log.error("Null Point Exception.Comment at comment id "+apAppCommentId+" is null."); return false; } - - try { - throw new NotFoundException("Comment with comment id "+apAppCommentId+" does not exit"); - } catch (NotFoundException e) { - log.error("Not Found Exception occurs.", e); - } return true; } From a45ba625fec023bd026210e7381a8a2ebafea12c Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 12:26:42 +0530 Subject: [PATCH 30/56] Renamed apAppCommentId into CommentId --- .../api/services/CommentManagementAPI.java | 12 +++--- .../impl/CommentManagementAPIImpl.java | 40 ++++++++++++++----- .../mgt/common/PaginationRequest.java | 2 +- .../mgt/common/PaginationResult.java | 2 +- .../mgt/common/services/CommentsManager.java | 16 ++++---- .../application/mgt/core/dao/CommentDAO.java | 16 ++++---- .../core/dao/impl/Comment/CommentDAOImpl.java | 32 +++++++-------- .../mgt/core/impl/CommentsManagerImpl.java | 34 ++++++++-------- 8 files changed, 84 insertions(+), 70 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java index baccd8132f..0762f59f65 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java @@ -188,7 +188,7 @@ public interface CommentManagementAPI { String uuid); @PUT - @Path("/{apAppCommentId}") + @Path("/{CommentId}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation( @@ -229,14 +229,14 @@ public interface CommentManagementAPI { required = true) @Valid Comment comment, @ApiParam( - name="apAppCommentId", + name="CommentId", value = "comment id of the updating comment.", required = true) - @QueryParam("apAppCommentId") + @QueryParam("CommentId") int apAppCommentId); @DELETE - @Path("/{apAppCommentId}") + @Path("/{CommentId}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation( @@ -270,10 +270,10 @@ public interface CommentManagementAPI { Response deleteComment( @ApiParam( - name="apAppCommentId", + name="CommentId", value="Id of the comment.", required = true) - @PathParam("apAppCommentId") + @PathParam("CommentId") int apAppCommentId); @GET diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java index f920ccb963..19a4a43e4c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java @@ -1,3 +1,21 @@ +/* + * 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.api.services.impl; import io.swagger.annotations.ApiParam; @@ -97,23 +115,23 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ @Override @PUT @Consumes("application/json") - @Path("/{apAppCommentId}") + @Path("/{CommentId}") public Response updateComment( @ApiParam Comment comment, - @PathParam("apAppCommentId") int apAppCommentId) { + @PathParam("CommentId") int CommentId) { CommentsManager commentsManager = APIUtil.getCommentsManager(); try { - if (apAppCommentId == 0) { + if (CommentId == 0) { return Response.status(Response.Status.NOT_FOUND) - .entity("Comment with comment id " + apAppCommentId + " not found").build(); + .entity("Comment with comment id " + CommentId + " not found").build(); }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,apAppCommentId); + comment = commentsManager.updateComment(comment,CommentId); return Response.status(Response.Status.OK).entity(comment).build(); } } catch (CommentManagementException e) { @@ -131,22 +149,22 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ @Override @DELETE - @Path("/{apAppCommentId}") + @Path("/{CommentId}") public Response deleteComment( - @PathParam("apAppCommentId") - int apAppCommentId){ + @PathParam("CommentId") + int CommentId){ CommentsManager commentsManager = APIUtil.getCommentsManager(); try { - commentsManager.deleteComment(apAppCommentId); + commentsManager.deleteComment(CommentId); } catch (CommentManagementException e) { String msg = "Error occurred while deleting the comment."; 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 "+apAppCommentId+" .",e); + log.error("Not found exception occurs to comment id "+CommentId+" .",e); return Response.status(Response.Status.NOT_FOUND) - .entity("Comment with" + apAppCommentId + " not found").build(); + .entity("Comment with" + CommentId + " not found").build(); } return Response.status(Response.Status.OK).entity("Comment is deleted successfully.").build(); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationRequest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationRequest.java index 789c27215b..63c9af14f6 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationRequest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationRequest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationResult.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationResult.java index aa95d2a880..46bf0983fa 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationResult.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationResult.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * 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 diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java index 25e956ce20..693198b683 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java @@ -48,13 +48,13 @@ public interface CommentsManager { /** * To validate the pre-request of the comment * - * @param apAppCommentId ID of the comment. + * @param CommentId ID of the comment. * @param comment comment needed to be validate. * @return validated the comment. * @throws CommentManagementException Exceptions of the comment management. * */ - Boolean validateComment(int apAppCommentId,String comment) throws CommentManagementException; + Boolean validateComment(int CommentId,String comment) throws CommentManagementException; /** * Get all comments to pagination @@ -71,32 +71,32 @@ public interface CommentsManager { /** * To get the comment with id. * - * @param apAppCommentId id of the comment + * @param CommentId id of the comment * @return {@link Comment}Comment of the comment id * @throws CommentManagementException Exceptions of the comment management. */ - Comment getComment(int apAppCommentId)throws CommentManagementException; + Comment getComment(int CommentId)throws CommentManagementException; /** * To delete comment using comment id. * - * @param apAppCommentId id of the comment + * @param CommentId id of the comment * @throws CommentManagementException Exceptions of the comment management */ - void deleteComment(int apAppCommentId) throws CommentManagementException; + void deleteComment(int CommentId) throws CommentManagementException; /** * To update a comment. * * @param comment comment of the application. - * @param apAppCommentId id of the comment + * @param CommentId id of the comment * @return {@link Comment}updated comment * @throws CommentManagementException Exceptions of the comment management * @throws SQLException SQL Exception * @throws DBConnectionException Database connection Exception */ - Comment updateComment(Comment comment,int apAppCommentId) throws CommentManagementException, SQLException, DBConnectionException; + Comment updateComment(Comment comment,int CommentId) throws CommentManagementException, SQLException, DBConnectionException; /** * To get number of rated users diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java index 20333612e3..263b992740 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java @@ -65,7 +65,7 @@ public interface CommentDAO { /** * To update already added comment. * - * @param apAppCommentId 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. @@ -74,13 +74,13 @@ public interface CommentDAO { * @throws DBConnectionException db connection exception * @throws SQLException sql exception */ - Comment updateComment(int apAppCommentId, 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 apAppCommentId 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. @@ -89,18 +89,18 @@ public interface CommentDAO { * @throws DBConnectionException db connection exception * @throws SQLException sql exception */ - Comment updateComment(String uuid, int apAppCommentId,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. * - * @param apAppCommentId id of the comment + * @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 */ - Comment getComment(int apAppCommentId) throws CommentManagementException, SQLException, DBConnectionException; + Comment getComment(int CommentId) throws CommentManagementException, SQLException, DBConnectionException; /** * To get the comment with id. @@ -293,12 +293,12 @@ public interface CommentDAO { /** * To delete comment using comment id. * - * @param apAppCommentId id of the comment + * @param CommentId id of the comment * @throws CommentManagementException Exceptions of the comment management. * @throws DBConnectionException db connection exception. * @throws SQLException sql exception */ - void deleteComment(int apAppCommentId) throws CommentManagementException, DBConnectionException, SQLException; + void deleteComment(int CommentId) throws CommentManagementException, DBConnectionException, SQLException; /** diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java index bcf77f3f48..0435d269ee 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java @@ -30,13 +30,11 @@ import org.wso2.carbon.device.application.mgt.core.dao.CommentDAO; import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; - import java.sql.SQLException; import java.sql.Timestamp; import java.sql.ResultSet; import java.sql.Connection; import java.sql.PreparedStatement; -import java.time.Instant; import java.util.ArrayList; import java.util.List; @@ -122,11 +120,11 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { } @Override - public Comment updateComment(int apAppCommentId, String updatedComment, String modifiedBy, Timestamp modifiedAt) + public Comment updateComment(int CommentId, String updatedComment, String modifiedBy, Timestamp modifiedAt) throws CommentManagementException, DBConnectionException, SQLException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to update the comment with ID ("+apAppCommentId+")"); + log.debug("Request received in DAO Layer to update the comment with ID ("+ CommentId +")"); } Connection connection; @@ -139,7 +137,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { statement = connection.prepareStatement(sql); statement.setString(1, updatedComment); statement.setString(2, modifiedBy); - statement.setInt(3, apAppCommentId); + statement.setInt(3, CommentId); statement.executeUpdate(); rs = statement.executeQuery(); @@ -147,15 +145,15 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { } finally { Util.cleanupResources(statement, rs); } - return getComment(apAppCommentId); + return getComment(CommentId); } - public Comment updateComment(String uuid, int apAppCommentID,String updatedComment, String modifiedBy, Timestamp + public Comment updateComment(String uuid, int CommentId,String updatedComment, String modifiedBy, Timestamp modifiedAt) throws CommentManagementException, DBConnectionException, SQLException { if (log.isDebugEnabled()) { log.debug("Request received in DAO Layer to update the comment with application ("+uuid+") and " + - "comment id ( "+apAppCommentID+")"); + "comment id ( "+ CommentId +")"); } Connection connection; @@ -168,20 +166,20 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { statement = connection.prepareStatement(sql); statement.setString(1, updatedComment); statement.setString(2,modifiedBy); - statement.setInt(3,apAppCommentID); + statement.setInt(3, CommentId); statement.executeUpdate(); rs= statement.getResultSet(); } finally { Util.cleanupResources(statement, rs); } - return getComment(apAppCommentID); + return getComment(CommentId); } @Override - public Comment getComment(int apAppCommentId) throws CommentManagementException { + public Comment getComment(int CommentId) throws CommentManagementException { if (log.isDebugEnabled()) { - log.debug("Getting comment with the comment id(" + apAppCommentId + ") from the database"); + log.debug("Getting comment with the comment id(" + CommentId + ") from the database"); } Connection conn; PreparedStatement stmt = null; @@ -193,7 +191,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { conn = this.getDBConnection(); sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE ID=?;"; stmt = conn.prepareStatement(sql); - stmt.setInt(1, apAppCommentId); + stmt.setInt(1, CommentId); rs=stmt.executeQuery(); if (rs.next()) { @@ -212,7 +210,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { } } catch (SQLException e) { - throw new CommentManagementException("Error occurred while retrieving information of the comment "+apAppCommentId, e); + throw new CommentManagementException("Error occurred while retrieving information of the comment "+ CommentId, e); } catch (DBConnectionException e) { log.error("DB Connection Exception occurs.", e); } finally { @@ -721,7 +719,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { } } finally { Util.cleanupResources(stmt, null); - return commentCount; } } @@ -747,7 +744,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { } } finally { Util.cleanupResources(stmt, null); - } return commentCount; @@ -860,7 +856,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { } @Override - public void deleteComment(int apAppCommentId) throws CommentManagementException, DBConnectionException, + public void deleteComment(int CommentId) throws CommentManagementException, DBConnectionException, SQLException { Connection conn; @@ -869,7 +865,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { conn = this.getDBConnection(); String sql = "DELETE FROM AP_APP_COMMENT WHERE ID=?;"; stmt = conn.prepareStatement(sql); - stmt.setInt(1, apAppCommentId); + stmt.setInt(1, CommentId); stmt.executeUpdate(); } finally { Util.cleanupResources(stmt, null); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java index 024aaa9cac..b09a7a1029 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java @@ -84,21 +84,21 @@ public class CommentsManagerImpl implements CommentsManager { /** * To validate the pre-request of the comment * - * @param apAppCommentId ID of the comment. + * @param CommentId ID of the comment. * @param comment comment needed to be validate. * @return Application related with the UUID. * * */ - public Boolean validateComment(int apAppCommentId,String comment) throws CommentManagementException{ + public Boolean validateComment(int CommentId,String comment) throws CommentManagementException{ - if (apAppCommentId <= 0) { + if (CommentId <= 0) { 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 "+apAppCommentId+" is null."); + log.error("Null Point Exception.Comment at comment id "+CommentId+" is null."); return false; } return true; @@ -136,18 +136,18 @@ public class CommentsManagerImpl implements CommentsManager { } @Override - public Comment getComment(int apAppCommentId) throws CommentManagementException { + public Comment getComment(int CommentId) throws CommentManagementException { PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); Comment comment=null; if (log.isDebugEnabled()) { - log.debug("Comment retrieval request is received for the comment id " + apAppCommentId ); + log.debug("Comment retrieval request is received for the comment id " + CommentId); } try { ConnectionManagerUtil.openDBConnection(); - comment=ApplicationManagementDAOFactory.getCommentDAO().getComment(apAppCommentId); + comment=ApplicationManagementDAOFactory.getCommentDAO().getComment(CommentId); } catch (DBConnectionException e) { log.error("DB Connection Exception occurs.", e); } catch (SQLException e) { @@ -159,18 +159,18 @@ public class CommentsManagerImpl implements CommentsManager { } @Override - public void deleteComment(int apAppCommentId) throws CommentManagementException { + public void deleteComment(int CommentId) throws CommentManagementException { Comment comment; - comment= getComment(apAppCommentId); + comment= getComment(CommentId); if (comment == null) { throw new CommentManagementException( - "Cannot delete a non-existing comment for the application with comment id" + apAppCommentId); + "Cannot delete a non-existing comment for the application with comment id" + CommentId); } try { ConnectionManagerUtil.beginDBTransaction(); - ApplicationManagementDAOFactory.getCommentDAO().deleteComment(apAppCommentId); + ApplicationManagementDAOFactory.getCommentDAO().deleteComment(CommentId); ConnectionManagerUtil.commitDBTransaction(); } catch (DBConnectionException e) { log.error("DB Connection Exception occurs.", e); @@ -184,20 +184,20 @@ public class CommentsManagerImpl implements CommentsManager { } @Override - public Comment updateComment(Comment comment,int apAppCommentId) throws CommentManagementException, SQLException, + public Comment updateComment(Comment comment,int CommentId) throws CommentManagementException, SQLException, DBConnectionException { PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - validateComment(apAppCommentId,comment.getComment()); + validateComment(CommentId,comment.getComment()); if (log.isDebugEnabled()) { - log.debug("Comment retrieval request is received for the comment id " +apAppCommentId); + log.debug("Comment retrieval request is received for the comment id " + CommentId); } comment.setModifiedAt(Timestamp.from(Instant.now())); try { ConnectionManagerUtil.openDBConnection(); - ApplicationManagementDAOFactory.getCommentDAO().getComment(apAppCommentId); - return ApplicationManagementDAOFactory.getCommentDAO().updateComment(apAppCommentId, + ApplicationManagementDAOFactory.getCommentDAO().getComment(CommentId); + return ApplicationManagementDAOFactory.getCommentDAO().updateComment(CommentId, comment.getComment(),comment.getModifiedBy(),comment.getModifiedAt()); } catch (SQLException e) { log.error("SQL Exception occurs.", e); @@ -206,7 +206,7 @@ public class CommentsManagerImpl implements CommentsManager { } finally { ConnectionManagerUtil.closeDBConnection(); } - return ApplicationManagementDAOFactory.getCommentDAO().getComment(apAppCommentId); + return ApplicationManagementDAOFactory.getCommentDAO().getComment(CommentId); } public int getRatedUser(String uuid){ From 74ea82c926bff2a48b1f7e7b09705a1e871ce825 Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 13:36:42 +0530 Subject: [PATCH 31/56] Modified CommentManagerImpl Renamed ApplicationManagementDAOFactory.getCommentDAO as commentDAO --- .../mgt/core/impl/CommentsManagerImpl.java | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java index b09a7a1029..f7f0e53594 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java @@ -32,10 +32,7 @@ import org.wso2.carbon.device.application.mgt.core.dao.CommentDAO; import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; 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.NotFoundException; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; - -import javax.ws.rs.core.Response; import java.sql.SQLException; import java.sql.Timestamp; import java.time.Instant; @@ -68,8 +65,7 @@ public class CommentsManagerImpl implements CommentsManager { try { ConnectionManagerUtil.beginDBTransaction(); - ApplicationManagementDAOFactory.getCommentDAO().addComment(tenantId,comment, - comment.getCreatedBy(),comment.getParent(),uuid); + commentDAO.addComment(tenantId,comment, comment.getCreatedBy(),comment.getParent(),uuid); ConnectionManagerUtil.commitDBTransaction(); return comment; } catch (Exception e) { @@ -147,7 +143,7 @@ public class CommentsManagerImpl implements CommentsManager { try { ConnectionManagerUtil.openDBConnection(); - comment=ApplicationManagementDAOFactory.getCommentDAO().getComment(CommentId); + comment=commentDAO.getComment(CommentId); } catch (DBConnectionException e) { log.error("DB Connection Exception occurs.", e); } catch (SQLException e) { @@ -170,7 +166,7 @@ public class CommentsManagerImpl implements CommentsManager { } try { ConnectionManagerUtil.beginDBTransaction(); - ApplicationManagementDAOFactory.getCommentDAO().deleteComment(CommentId); + commentDAO.deleteComment(CommentId); ConnectionManagerUtil.commitDBTransaction(); } catch (DBConnectionException e) { log.error("DB Connection Exception occurs.", e); @@ -196,8 +192,8 @@ public class CommentsManagerImpl implements CommentsManager { comment.setModifiedAt(Timestamp.from(Instant.now())); try { ConnectionManagerUtil.openDBConnection(); - ApplicationManagementDAOFactory.getCommentDAO().getComment(CommentId); - return ApplicationManagementDAOFactory.getCommentDAO().updateComment(CommentId, + commentDAO.getComment(CommentId); + return commentDAO.updateComment(CommentId, comment.getComment(),comment.getModifiedBy(),comment.getModifiedAt()); } catch (SQLException e) { log.error("SQL Exception occurs.", e); @@ -206,7 +202,7 @@ public class CommentsManagerImpl implements CommentsManager { } finally { ConnectionManagerUtil.closeDBConnection(); } - return ApplicationManagementDAOFactory.getCommentDAO().getComment(CommentId); + return commentDAO.getComment(CommentId); } public int getRatedUser(String uuid){ @@ -217,7 +213,7 @@ public class CommentsManagerImpl implements CommentsManager { } try { ConnectionManagerUtil.openDBConnection(); - ratedUsers =ApplicationManagementDAOFactory.getCommentDAO().getRatedUser(uuid); + ratedUsers =commentDAO.getRatedUser(uuid); } catch (DBConnectionException e) { log.error("DB Connection Exception occurs.", e); } catch (ApplicationManagementDAOException e) { @@ -237,7 +233,7 @@ public class CommentsManagerImpl implements CommentsManager { } try { ConnectionManagerUtil.openDBConnection(); - stars= ApplicationManagementDAOFactory.getCommentDAO().getStars(uuid); + stars= commentDAO.getStars(uuid); } catch (DBConnectionException e) { log.error("DB Connection Exception occurs.", e); } catch (ApplicationManagementDAOException e) { @@ -258,14 +254,14 @@ public class CommentsManagerImpl implements CommentsManager { try { ConnectionManagerUtil.beginDBTransaction(); - int ratedUsers = ApplicationManagementDAOFactory.getCommentDAO().getRatedUser(uuid); - int oldStars = ApplicationManagementDAOFactory.getCommentDAO().getStars(uuid); + int ratedUsers = commentDAO.getRatedUser(uuid); + int oldStars = commentDAO.getStars(uuid); if(ratedUsers==0){ - newStars=ApplicationManagementDAOFactory.getCommentDAO().updateStars(stars,uuid); + newStars=commentDAO.updateStars(stars,uuid); return newStars; }else { int avgStars = ((oldStars*ratedUsers)+stars) / (ratedUsers+1); - newStars = ApplicationManagementDAOFactory.getCommentDAO().updateStars(avgStars, uuid); + newStars = commentDAO.updateStars(avgStars, uuid); ConnectionManagerUtil.commitDBTransaction(); return newStars; } From caa47417bcbc81333e0800b9baa3000a0ed58ee6 Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 14:27:44 +0530 Subject: [PATCH 32/56] Modified CommentManagerImpl removed catch (SQLException e) and catch (DBConnectionException e). --- .../application/mgt/core/impl/CommentsManagerImpl.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java index f7f0e53594..74ea9e57d4 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java @@ -193,16 +193,10 @@ public class CommentsManagerImpl implements CommentsManager { try { ConnectionManagerUtil.openDBConnection(); commentDAO.getComment(CommentId); - return commentDAO.updateComment(CommentId, - comment.getComment(),comment.getModifiedBy(),comment.getModifiedAt()); - } catch (SQLException e) { - log.error("SQL Exception occurs.", e); - } catch (DBConnectionException e) { - log.error("DB Connection Exception occurs.", e); + return commentDAO.updateComment(CommentId, comment.getComment(),comment.getModifiedBy(),comment.getModifiedAt()); } finally { ConnectionManagerUtil.closeDBConnection(); } - return commentDAO.getComment(CommentId); } public int getRatedUser(String uuid){ From 3bd6d03b4c730cdae7289bff0f1814055a02ba06 Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 15:13:22 +0530 Subject: [PATCH 33/56] Modified CommentManagerImpl and CommentManager wrapped & thrown the sql and db exceptions with CommentManagementException and ApplicationManagementException. --- .../mgt/common/services/CommentsManager.java | 9 +-- .../mgt/core/impl/CommentsManagerImpl.java | 60 ++++++++++--------- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java index 693198b683..d2793ed904 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java @@ -24,6 +24,7 @@ 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 org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; +import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import java.sql.SQLException; import java.util.List; @@ -65,7 +66,7 @@ public interface CommentsManager { * @throws CommentManagementException Exceptions of the comment management. * @throws SQLException SQL Exception */ - List getAllComments(PaginationRequest request, String uuid) throws CommentManagementException, SQLException; + List getAllComments(PaginationRequest request, String uuid) throws CommentManagementException; /** @@ -96,7 +97,7 @@ public interface CommentsManager { * @throws SQLException SQL Exception * @throws DBConnectionException Database connection Exception */ - Comment updateComment(Comment comment,int CommentId) throws CommentManagementException, SQLException, DBConnectionException; + Comment updateComment(Comment comment,int CommentId) throws CommentManagementException; /** * To get number of rated users @@ -105,7 +106,7 @@ public interface CommentsManager { * @return number of rated users * @throws SQLException sql exception */ - int getRatedUser(String uuid)throws SQLException; + int getRatedUser(String uuid) throws SQLException, CommentManagementException, ApplicationManagementException; /** * To get the average of stars @@ -114,7 +115,7 @@ public interface CommentsManager { * @return value of the stars of an application * @throws SQLException sql exception */ - int getStars(String uuid)throws SQLException; + int getStars(String uuid) throws SQLException, CommentManagementException, ApplicationManagementException; /** * To update rating stars diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java index 74ea9e57d4..f25a420d7e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java @@ -68,13 +68,15 @@ public class CommentsManagerImpl implements CommentsManager { commentDAO.addComment(tenantId,comment, comment.getCreatedBy(),comment.getParent(),uuid); ConnectionManagerUtil.commitDBTransaction(); return comment; - } catch (Exception e) { - log.error("Exception occurs.", e); + } catch (DBConnectionException e) { ConnectionManagerUtil.rollbackDBTransaction(); + throw new CommentManagementException("DB Connection Exception occurs.",e); + } catch (SQLException | TransactionManagementException e){ + throw new CommentManagementException("SQL Exception occurs.",e); } finally { ConnectionManagerUtil.closeDBConnection(); } - return comment; + } /** @@ -102,8 +104,7 @@ public class CommentsManagerImpl implements CommentsManager { @Override - public List getAllComments(PaginationRequest request,String uuid) throws CommentManagementException, - SQLException { + public List getAllComments(PaginationRequest request,String uuid) throws CommentManagementException { PaginationResult paginationResult = new PaginationResult(); List comments; @@ -124,11 +125,12 @@ public class CommentsManagerImpl implements CommentsManager { return comments; } catch (DBConnectionException e) { - log.error("DB Connection 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(); } - return null; } @Override @@ -145,9 +147,9 @@ public class CommentsManagerImpl implements CommentsManager { ConnectionManagerUtil.openDBConnection(); comment=commentDAO.getComment(CommentId); } catch (DBConnectionException e) { - log.error("DB Connection Exception occurs.", e); + throw new CommentManagementException("DB Connection Exception occurs.", e); } catch (SQLException e) { - log.error("SQL Exception occurs.", e); + throw new CommentManagementException("SQL Exception occurs.", e); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -169,19 +171,18 @@ public class CommentsManagerImpl implements CommentsManager { commentDAO.deleteComment(CommentId); ConnectionManagerUtil.commitDBTransaction(); } catch (DBConnectionException e) { - log.error("DB Connection Exception occurs.", e); + throw new CommentManagementException("DB Connection Exception occurs.", e); } catch (SQLException e) { - log.error("SQL Exception occurs.", e); + throw new CommentManagementException("SQL Exception occurs.", e); } catch (TransactionManagementException e) { - log.error("Transaction Management Exception occurs.", e); + throw new CommentManagementException("Transaction Management Exception occurs.", e); } finally { ConnectionManagerUtil.closeDBConnection(); } } @Override - public Comment updateComment(Comment comment,int CommentId) throws CommentManagementException, SQLException, - DBConnectionException { + public Comment updateComment(Comment comment,int CommentId) throws CommentManagementException { PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); validateComment(CommentId,comment.getComment()); @@ -193,13 +194,18 @@ public class CommentsManagerImpl implements CommentsManager { try { ConnectionManagerUtil.openDBConnection(); commentDAO.getComment(CommentId); - return commentDAO.updateComment(CommentId, comment.getComment(),comment.getModifiedBy(),comment.getModifiedAt()); - } finally { + 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 { ConnectionManagerUtil.closeDBConnection(); } } - public int getRatedUser(String uuid){ + public int getRatedUser(String uuid) throws ApplicationManagementException { int ratedUsers=0; if (log.isDebugEnabled()) { @@ -209,9 +215,9 @@ public class CommentsManagerImpl implements CommentsManager { ConnectionManagerUtil.openDBConnection(); ratedUsers =commentDAO.getRatedUser(uuid); } catch (DBConnectionException e) { - log.error("DB Connection Exception occurs.", e); + throw new ApplicationManagementException("DB Connection Exception occurs",e); } catch (ApplicationManagementDAOException e) { - log.error("Application Management Exception occurs.", e); + throw new ApplicationManagementException("Application Management Exception occurs.", e); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -219,7 +225,7 @@ public class CommentsManagerImpl implements CommentsManager { } @Override - public int getStars(String uuid) throws SQLException { + public int getStars(String uuid) throws ApplicationManagementException { int stars=0; if (log.isDebugEnabled()) { @@ -229,10 +235,10 @@ public class CommentsManagerImpl implements CommentsManager { ConnectionManagerUtil.openDBConnection(); stars= commentDAO.getStars(uuid); } catch (DBConnectionException e) { - log.error("DB Connection Exception occurs.", e); + throw new ApplicationManagementException("DB Connection Exception occurs",e); } catch (ApplicationManagementDAOException e) { - log.error("Application Management Exception occurs.", e); - } finally { + throw new ApplicationManagementException("Application Management Exception occurs.", e); + } finally { ConnectionManagerUtil.closeDBConnection(); } return stars; @@ -261,14 +267,14 @@ public class CommentsManagerImpl implements CommentsManager { } } catch (ApplicationManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); - log.error("Application Management Exception occurs.", e); + throw new ApplicationManagementException("Application Management Exception occurs.", e); } catch (DBConnectionException e) { - log.error("DB Connection Exception occurs.", e); + throw new ApplicationManagementException("DB Connection Exception occurs.", e); } finally { ConnectionManagerUtil.closeDBConnection(); } - return newStars; + } From c1dca737f78273d3f98447ccf52f86f7e076a4e7 Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 15:16:29 +0530 Subject: [PATCH 34/56] Modified CommentManager Edited the comments. --- .../mgt/common/services/CommentsManager.java | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java index d2793ed904..655c0ea3e5 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java @@ -23,10 +23,6 @@ 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 org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; -import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; - -import java.sql.SQLException; import java.util.List; /** @@ -64,7 +60,6 @@ public interface CommentsManager { * @param uuid uuid of the application release * @return {@link PaginationResult} pagination result with starting offSet and limit * @throws CommentManagementException Exceptions of the comment management. - * @throws SQLException SQL Exception */ List getAllComments(PaginationRequest request, String uuid) throws CommentManagementException; @@ -94,8 +89,6 @@ public interface CommentsManager { * @param CommentId id of the comment * @return {@link Comment}updated comment * @throws CommentManagementException Exceptions of the comment management - * @throws SQLException SQL Exception - * @throws DBConnectionException Database connection Exception */ Comment updateComment(Comment comment,int CommentId) throws CommentManagementException; @@ -104,18 +97,20 @@ public interface CommentsManager { * * @param uuid uuid of the application * @return number of rated users - * @throws SQLException sql exception + * @throws CommentManagementException Exceptions of the comment management + * @throws ApplicationManagementException Application Management Exception. */ - int getRatedUser(String uuid) throws SQLException, CommentManagementException, ApplicationManagementException; + int getRatedUser(String uuid) throws CommentManagementException, ApplicationManagementException; /** * To get the average of stars * * @param uuid uuid of the comment * @return value of the stars of an application - * @throws SQLException sql exception + * @throws CommentManagementException Exceptions of the comment management + * @throws ApplicationManagementException Application Management Exception. */ - int getStars(String uuid) throws SQLException, CommentManagementException, ApplicationManagementException; + int getStars(String uuid) throws CommentManagementException, ApplicationManagementException; /** * To update rating stars From 1bbd0b1aa51158cd472ab5f9b4ddb18bd2eca5cb Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 15:32:59 +0530 Subject: [PATCH 35/56] Modified CommentManagerImpl ,CommentManagementAPIImpl,CommentManagementAPI Modified the exceptions. --- .../api/services/CommentManagementAPI.java | 22 ++++++++++-- .../impl/CommentManagementAPIImpl.java | 34 ++++++++----------- .../mgt/core/impl/CommentsManagerImpl.java | 5 +-- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java index 0762f59f65..177f39606e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java @@ -1,3 +1,21 @@ +/* + * 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.api.services; import io.swagger.annotations.ApiParam; @@ -14,7 +32,6 @@ import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.application.mgt.api.beans.ErrorResponse; import org.wso2.carbon.device.application.mgt.common.Comment; - import javax.validation.Valid; import javax.ws.rs.Path; import javax.ws.rs.Consumes; @@ -27,7 +44,6 @@ import javax.ws.rs.POST; import javax.ws.rs.DELETE; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import java.sql.SQLException; import java.util.List; /** @@ -395,5 +411,5 @@ public interface CommentManagementAPI { value="uuid of the release version of the application", required=true) @PathParam("uuid") - String uuid) throws SQLException; + String uuid); } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java index 19a4a43e4c..c6fcabff26 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java @@ -28,9 +28,7 @@ import org.wso2.carbon.device.application.mgt.common.Comment; import org.wso2.carbon.device.application.mgt.common.PaginationRequest; 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.DBConnectionException; import org.wso2.carbon.device.application.mgt.common.services.CommentsManager; - import javax.ws.rs.Path; import javax.ws.rs.Consumes; import javax.ws.rs.PathParam; @@ -41,7 +39,6 @@ import javax.ws.rs.POST; import javax.ws.rs.DELETE; import javax.ws.rs.NotFoundException; import javax.ws.rs.core.Response; -import java.sql.SQLException; import java.util.ArrayList; import java.util.List; @@ -79,9 +76,6 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ String msg = "Error occurred while retrieving comments."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); - } catch (SQLException e) { - log.error("SQL Exception occurs", e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } return Response.status(Response.Status.OK).entity(comments).build(); } @@ -138,12 +132,6 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ String msg = "Error occurred while retrieving comments."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); - } catch (SQLException e) { - log.error("SQL Exception occurs", e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); - }catch (DBConnectionException e) { - log.error("DB Connection Exception occurs", e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } } @@ -181,8 +169,11 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ try { Stars= commentsManager.getStars(uuid); - } catch (SQLException e) { - log.error("SQL Exception occurs", e); + } 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); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } return Response.status(Response.Status.OK).entity(Stars).build(); @@ -200,8 +191,11 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ try { ratedUsers= commentsManager.getRatedUser(uuid); - } catch (SQLException e) { - log.error("SQL Exception occurs", e); + } 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); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } return Response.status(Response.Status.OK).entity(ratedUsers).build(); @@ -212,10 +206,10 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ @Consumes("uuid/stars/json") public Response updateStars( @ApiParam int stars, - @PathParam("uuid") String uuid) throws SQLException { + @PathParam("uuid") String uuid) { CommentsManager commentsManager = APIUtil.getCommentsManager(); - int newStars=commentsManager.getStars(uuid); + int newStars=0; try { newStars = commentsManager.updateStars(stars,uuid); @@ -229,8 +223,8 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ } } 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(newStars).build(); } } \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java index f25a420d7e..9244bf429a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java @@ -85,7 +85,7 @@ public class CommentsManagerImpl implements CommentsManager { * @param CommentId ID of the comment. * @param comment comment needed to be validate. * @return Application related with the UUID. - * + * @throws CommentManagementException Exceptions of the comment management. * */ @@ -274,8 +274,5 @@ public class CommentsManagerImpl implements CommentsManager { } finally { ConnectionManagerUtil.closeDBConnection(); } - } - - } \ No newline at end of file From 3bfb2addbb8ce738607583886f7e7fcf8f95e55a Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 15:58:01 +0530 Subject: [PATCH 36/56] Reformatted the code. --- .../impl/CommentManagementAPIImpl.java | 74 +++---- .../application/mgt/common/Comment.java | 1 - .../mgt/common/PaginationRequest.java | 15 +- .../exception/CommentManagementException.java | 26 ++- .../mgt/common/services/CommentsManager.java | 29 ++- .../core/config/PaginationConfiguration.java | 7 +- .../application/mgt/core/dao/CommentDAO.java | 209 ++++++++++-------- .../ApplicationManagementDAOFactory.java | 16 +- .../mgt/core/impl/CommentsManagerImpl.java | 110 +++++---- 9 files changed, 249 insertions(+), 238 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java index c6fcabff26..ef227a6f98 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java @@ -62,17 +62,16 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ CommentsManager commentsManager = APIUtil.getCommentsManager(); List 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(); } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Comment.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Comment.java index 219f711e72..92f9e84553 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Comment.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Comment.java @@ -51,7 +51,6 @@ public class Comment { this.tenantId = tenantId; } - public int getId() { return id; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationRequest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationRequest.java index 63c9af14f6..1f4e668f47 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationRequest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationRequest.java @@ -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; } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/CommentManagementException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/CommentManagementException.java index 53d5ebc99b..7bdfb764a7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/CommentManagementException.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/CommentManagementException.java @@ -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; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java index 655c0ea3e5..b8001652ac 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java @@ -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 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. */ diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/PaginationConfiguration.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/PaginationConfiguration.java index 03be1dadc2..7205802517 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/PaginationConfiguration.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/PaginationConfiguration.java @@ -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; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java index 263b992740..f51d58644c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java @@ -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 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 getAllComments(String uuid,PaginationRequest request) throws CommentManagementException, SQLException, DBConnectionException; + List 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 getComments(int appReleasedId,int appId)throws CommentManagementException; + List 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 getComments(String appType,String appName,String version) throws CommentManagementException, DBConnectionException, SQLException; + List 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 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 getCommentsByUser(String createdBy) throws CommentManagementException, DBConnectionException, SQLException; + List 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 getCommentsByUser(String createdBy,Timestamp createdAt) throws CommentManagementException, DBConnectionException, SQLException; + List 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 getCommentsByModifiedUser(String modifiedBy) throws CommentManagementException, DBConnectionException, SQLException; + List 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 getCommentsByModifiedUser(String modifiedBy,Timestamp modifiedAt) throws CommentManagementException, DBConnectionException, SQLException; + List 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 getComments(String appType,String appName,String version,int parentId) throws CommentManagementException, DBConnectionException, SQLException; + List 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 diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOFactory.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOFactory.java index 99c6d117fa..2e37423458 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOFactory.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/ApplicationManagementDAOFactory.java @@ -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."); } - } + +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java index 9244bf429a..029624f690 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java @@ -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 getAllComments(PaginationRequest request,String uuid) throws CommentManagementException { + public List getAllComments(PaginationRequest request, String uuid) throws CommentManagementException { PaginationResult paginationResult = new PaginationResult(); List 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(); } } From 3cc15d0df0c410cd43c363ae41ae14eb00a6df19 Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 16:06:41 +0530 Subject: [PATCH 37/56] Reformatted the code. --- .../org/wso2/carbon/device/application/mgt/api/APIUtil.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java index 54c2821052..c3c1cccfc4 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java @@ -239,8 +239,7 @@ public class APIUtil { synchronized (APIUtil.class) { if (commentsManager == null) { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - commentsManager = - (CommentsManager) ctx.getOSGiService(CommentsManager.class, null); + commentsManager = (CommentsManager) ctx.getOSGiService(CommentsManager.class, null); if (commentsManager == null) { String msg = "Comments Manager service has not initialized."; log.error(msg); From 4c1d8dfa4dfd25726969e8309110566344793fcb Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 16:28:17 +0530 Subject: [PATCH 38/56] Modified APIUtil Modified the osgi contexts and reformatted. --- .../device/application/mgt/api/APIUtil.java | 179 ++++++------------ 1 file changed, 59 insertions(+), 120 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java index c3c1cccfc4..6e2c1360f8 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/APIUtil.java @@ -31,8 +31,8 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorage import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager; import org.wso2.carbon.device.application.mgt.common.services.PlatformStorageManager; import org.wso2.carbon.device.application.mgt.common.services.CategoryManager; -import javax.ws.rs.core.Response; +import javax.ws.rs.core.Response; /** * Holds util methods required for Application-Mgt API component. @@ -41,67 +41,36 @@ public class APIUtil { private static Log log = LogFactory.getLog(APIUtil.class); - private static ApplicationManager applicationManager; - private static PlatformManager platformManager; - private static LifecycleStateManager lifecycleStateManager; - private static ApplicationReleaseManager applicationReleaseManager; - private static ApplicationStorageManager applicationStorageManager; - private static SubscriptionManager subscriptionManager; - private static PlatformStorageManager platformStorageManager; - private static CategoryManager categoryManager; - private static CommentsManager commentsManager; - public static ApplicationManager getApplicationManager() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ApplicationManager applicationManager = (ApplicationManager) ctx.getOSGiService(ApplicationManager.class, null); if (applicationManager == null) { - synchronized (APIUtil.class) { - if (applicationManager == null) { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - applicationManager = - (ApplicationManager) ctx.getOSGiService(ApplicationManager.class, null); - if (applicationManager == null) { - String msg = "Application Manager service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - } - } + String msg = "Application Manager service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); } - return applicationManager; } public static PlatformManager getPlatformManager() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + PlatformManager platformManager = (PlatformManager) ctx.getOSGiService(PlatformManager.class, null); if (platformManager == null) { - synchronized (APIUtil.class) { - if (platformManager == null) { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - platformManager = - (PlatformManager) ctx.getOSGiService(PlatformManager.class, null); - if (platformManager == null) { - String msg = "Platform Manager service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - } - } + String msg = "Platform Manager service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); } return platformManager; } public static LifecycleStateManager getLifecycleStateManager() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + LifecycleStateManager lifecycleStateManager = (LifecycleStateManager) ctx + .getOSGiService(LifecycleStateManager.class, null); if (lifecycleStateManager == null) { - synchronized (APIUtil.class) { - if (lifecycleStateManager == null) { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - lifecycleStateManager = - (LifecycleStateManager) ctx.getOSGiService(LifecycleStateManager.class, null); - if (lifecycleStateManager == null) { - String msg = "Lifecycle Manager service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - } - } + String msg = "Lifecycle Manager service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); } return lifecycleStateManager; } @@ -112,41 +81,30 @@ public class APIUtil { * @return ApplicationRelease Manager instance in the current osgi context. */ public static ApplicationReleaseManager getApplicationReleaseManager() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ApplicationReleaseManager applicationReleaseManager = (ApplicationReleaseManager) ctx + .getOSGiService(ApplicationReleaseManager.class, null); if (applicationReleaseManager == null) { - synchronized (APIUtil.class) { - if (applicationReleaseManager == null) { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - applicationReleaseManager = (ApplicationReleaseManager) ctx - .getOSGiService(ApplicationReleaseManager.class, null); - if (applicationReleaseManager == null) { - String msg = "Application Release Manager service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - } - } + String msg = "Application Release Manager service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); } return applicationReleaseManager; } /** * To get the Application Storage Manager from the osgi context. + * * @return ApplicationStoreManager instance in the current osgi context. */ public static ApplicationStorageManager getApplicationStorageManager() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + ApplicationStorageManager applicationStorageManager = (ApplicationStorageManager) ctx + .getOSGiService(ApplicationStorageManager.class, null); if (applicationStorageManager == null) { - synchronized (APIUtil.class) { - if (applicationStorageManager == null) { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - applicationStorageManager = (ApplicationStorageManager) ctx - .getOSGiService(ApplicationStorageManager.class, null); - if (applicationStorageManager == null) { - String msg = "Application Storage Manager service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - } - } + String msg = "Application Storage Manager service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); } return applicationStorageManager; } @@ -157,42 +115,29 @@ public class APIUtil { * @return PlatformStoreManager instance in the current osgi context. */ public static PlatformStorageManager getPlatformStorageManager() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + PlatformStorageManager platformStorageManager = (PlatformStorageManager) ctx + .getOSGiService(PlatformStorageManager.class, null); if (platformStorageManager == null) { - synchronized (APIUtil.class) { - if (platformStorageManager == null) { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - platformStorageManager = (PlatformStorageManager) ctx - .getOSGiService(PlatformStorageManager.class, null); - if (platformStorageManager == null) { - String msg = "Platform Storage Manager service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - } - } + String msg = "Platform Storage Manager service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); } return platformStorageManager; } - /** * To get the Category Manager from the osgi context. * * @return CategoryManager instance in the current osgi context. */ public static CategoryManager getCategoryManager() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + CategoryManager categoryManager = (CategoryManager) ctx.getOSGiService(CategoryManager.class, null); if (categoryManager == null) { - synchronized (APIUtil.class) { - if (categoryManager == null) { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - categoryManager = (CategoryManager) ctx.getOSGiService(CategoryManager.class, null); - if (categoryManager == null) { - String msg = "Category Manager service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - } - } + String msg = "Category Manager service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); } return categoryManager; } @@ -213,40 +158,34 @@ public class APIUtil { /** * To get the Subscription Manager from the osgi context. + * * @return SubscriptionManager instance in the current osgi context. */ public static SubscriptionManager getSubscriptionManager() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + SubscriptionManager subscriptionManager = (SubscriptionManager) ctx + .getOSGiService(SubscriptionManager.class, null); if (subscriptionManager == null) { - synchronized (APIUtil.class) { - if (subscriptionManager == null) { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - subscriptionManager = - (SubscriptionManager) ctx.getOSGiService(SubscriptionManager.class, null); - if (subscriptionManager == null) { - String msg = "Subscription Manager service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - } - } + String msg = "Subscription Manager service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); } - return subscriptionManager; } + /** + * To get the Comment Manager from the osgi context. + * + * @return CommentsManager instance in the current osgi context. + */ + public static CommentsManager getCommentsManager() { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + CommentsManager commentsManager = (CommentsManager) ctx.getOSGiService(CommentsManager.class, null); if (commentsManager == null) { - synchronized (APIUtil.class) { - if (commentsManager == null) { - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - commentsManager = (CommentsManager) ctx.getOSGiService(CommentsManager.class, null); - if (commentsManager == null) { - String msg = "Comments Manager service has not initialized."; - log.error(msg); - throw new IllegalStateException(msg); - } - } - } + String msg = "Comments Manager service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); } return commentsManager; } From 919a7a8ddd5c326f242949fbda8354fa0be05f11 Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 17:27:18 +0530 Subject: [PATCH 39/56] Modified pom.xml at org.wso2.carbon.device.application.mgt.api removed extra dependencies --- .../pom.xml | 190 ------------------ 1 file changed, 190 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/pom.xml index 37f188ed5f..412879e98c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/pom.xml @@ -225,195 +225,5 @@ javax.ws.rs javax.ws.rs-api - - org.wso2.carbon.devicemgt - org.wso2.carbon.apimgt.annotations - - - org.sonatype.sisu - sisu-guice - 2.1.7 - - - org.sonatype.sisu - sisu-guice - 2.1.7 - - - org.wso2.carbon.devicemgt - org.wso2.carbon.apimgt.annotations - - - org.wso2.carbon.devicemgt - org.wso2.carbon.apimgt.annotations - - - org.wso2.carbon.devicemgt - org.wso2.carbon.apimgt.annotations - - - org.apache.ode.wso2 - ode - 1.3.5-wso2v14 - - - org.wso2.carbon.devicemgt - org.wso2.carbon.apimgt.annotations - - - org.apache.ode.wso2 - ode - 1.3.5-wso2v14 - - - org.wso2.bpel - ode-bpel-api - 1.3.5-wso4v18 - - - org.wso2.orbit.org.apache.ode - ode - 1.3.5-wso4v18 - - - org.apache.ode.wso2 - ode - 1.3.5-wso2v14 - - - org.wso2.bpel - ode-bpel-dao - 1.3.5-wso4v18 - - - org.wso2.orbit.org.apache.ode - ode - 1.3.5-wso4v18 - - - org.wso2.carbon.business-process - org.wso2.carbon.bpel.skeleton - 4.4.25 - - - org.wso2.carbon.business-process - org.wso2.carbon.bpel.stub - 4.4.27 - - - org.wso2.carbon.identity - org.wso2.carbon.identity.workflow.mgt.bps.stub - 5.1.2 - - - org.apache.spark - spark-streaming-kafka-assembly_2.10 - 1.4.3.wso2v2 - - - org.ballerinalang - workspace-service - 0.8.14 - - - org.wso2.carbon.identity.workflow.impl.bps - org.wso2.carbon.identity.workflow.mgt.bps.stub - 5.1.13 - - - org.sonatype.sisu - sisu-guice - 2.1.7 - - - org.wso2.carbon.devicemgt - org.wso2.carbon.apimgt.annotations - 3.0.184 - - - org.wso2.carbon.extension.identity.authenticator - org.wso2.carbon.extension.identity.authenticator.twitter.connector - 1.0.5 - - - org.wso2.carbon.extension.identity.authenticator.outbound.twitter - org.wso2.carbon.extension.identity.authenticator.twitter.connector - 1.0.7 - - - org.wso2.extension.siddhi.execution.ml - siddhi-execution-ml - 1.0.1 - - - org.wso2.orbit.com.github.azakordonets - fabricator_2.10 - 2.1.4.wso2v1 - - - org.wso2.extension.siddhi.execution.ml - siddhi-execution-ml - 1.0.1 - - - org.wso2.orbit.com.github.azakordonets - fabricator_2.10 - 2.1.4.wso2v1 - - - org.wso2.orbit.com.github.azakordonets - fabricator_2.10 - 2.1.4.wso2v1 - - - org.wso2.carbon.identity.inbound.auth.oauth2 - org.wso2.carbon.identity.oauth.scope.endpoint - 5.5.160-SNAPSHOT - - - org.wso2.carbon.identity.inbound.auth.oauth2 - org.wso2.carbon.identity.oauth.scope.endpoint - 5.5.160-SNAPSHOT - - - org.wso2.carbon.identity.inbound.auth.oauth2 - org.wso2.carbon.identity.oauth.scope.endpoint - 5.5.160-SNAPSHOT - - - org.wso2.carbon.identity.inbound.auth.oauth2 - org.wso2.carbon.identity.oauth.scope.endpoint - 5.5.160-SNAPSHOT - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.api - 3.0.185-SNAPSHOT - - - org.wso2.carbon.devicemgt - org.wso2.carbon.certificate.mgt.api - 3.0.185-SNAPSHOT - - - org.wso2.carbon.devicemgt - org.wso2.carbon.certificate.mgt.cert.admin.api - 3.0.185-SNAPSHOT - - - org.wso2.carbon.devicemgt - org.wso2.carbon.certificate.mgt.cert.admin.api - 3.0.185-SNAPSHOT - - - org.apache.ode.wso2 - ode - 1.3.5-wso2v14 - - - org.apache.ode.wso2 - ode - 1.3.5-wso2v14 - \ No newline at end of file From a6f2486ec6f54c2e53fe1cdc16a66482ae543825 Mon Sep 17 00:00:00 2001 From: nishadi Date: Thu, 18 Jan 2018 00:03:46 +0530 Subject: [PATCH 40/56] Modified Comment ManagementAPiImpl changed returning error response message into "return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();" --- .../impl/CommentManagementAPIImpl.java | 68 ++++++++----------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java index ef227a6f98..def742fe28 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java @@ -29,6 +29,7 @@ import org.wso2.carbon.device.application.mgt.common.PaginationRequest; 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.services.CommentsManager; + import javax.ws.rs.Path; import javax.ws.rs.Consumes; import javax.ws.rs.PathParam; @@ -46,8 +47,7 @@ import java.util.List; * Comment Management related jax-rs APIs. */ @Path("/comments") -@SuppressWarnings( "deprecation" ) -public class CommentManagementAPIImpl implements CommentManagementAPI{ +public class CommentManagementAPIImpl implements CommentManagementAPI { private static Log log = LogFactory.getLog(CommentManagementAPIImpl.class); @@ -56,8 +56,8 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ @Path("/{uuid}") public Response getAllComments( @PathParam("uuid") String uuid, - @QueryParam("offset")int offSet, - @QueryParam("limit")int limit){ + @QueryParam("offset") int offSet, @ + QueryParam("limit") int limit) { CommentsManager commentsManager = APIUtil.getCommentsManager(); List comments = new ArrayList<>(); @@ -74,18 +74,14 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ } catch (CommentManagementException e) { String msg = "Error occurred while retrieving comments."; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR) + .entity("Application with UUID" + uuid + " Internal server error occurs").build(); } return Response.status(Response.Status.OK).entity(comments).build(); } - @Override - @POST - @Consumes("application/json") - @Path("/{uuid}") - public Response addComments( - @ApiParam Comment comment, - @PathParam("uuid") String uuid){ + @Override @POST @Consumes("application/json") @Path("/{uuid}") public Response addComments( + @ApiParam Comment comment, @PathParam("uuid") String uuid) { CommentsManager commentsManager = APIUtil.getCommentsManager(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); @@ -101,17 +97,13 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ } catch (CommentManagementException e) { String msg = "Error occurred while creating the comment"; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR) + .entity("Application with UUID" + uuid + " Internal server error occurs").build(); } } - @Override - @PUT - @Consumes("application/json") - @Path("/{CommentId}") - public Response updateComment( - @ApiParam Comment comment, - @PathParam("CommentId") int CommentId) { + @Override @PUT @Consumes("application/json") @Path("/{CommentId}") public Response updateComment( + @ApiParam Comment comment, @PathParam("CommentId") int CommentId) { CommentsManager commentsManager = APIUtil.getCommentsManager(); try { @@ -129,16 +121,15 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ } catch (CommentManagementException e) { String msg = "Error occurred while retrieving comments."; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR) + .entity("Comment with Comment Id" + CommentId + " Internal server error occurs").build(); } } @Override @DELETE @Path("/{CommentId}") - public Response deleteComment( - @PathParam("CommentId") - int CommentId){ + public Response deleteComment(@PathParam("CommentId") int CommentId) { CommentsManager commentsManager = APIUtil.getCommentsManager(); try { @@ -146,7 +137,8 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ } catch (CommentManagementException e) { String msg = "Error occurred while deleting the comment."; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR) + .entity("Comment with Comment Id" + CommentId + " Internal server error occurs").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(); @@ -157,9 +149,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ @Override @GET @Path("/{uuid}") - public Response getStars( - @PathParam("uuid") - String uuid) { + public Response getStars(@PathParam("uuid") String uuid) { CommentsManager commentsManager = APIUtil.getCommentsManager(); int Stars = 0; @@ -170,7 +160,8 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } catch (ApplicationManagementException 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) + .entity("Application with UUID" + uuid + " Internal server error occurs").build(); } return Response.status(Response.Status.OK).entity(Stars).build(); } @@ -178,9 +169,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ @Override @GET @Path("/{uuid}") - public Response getRatedUser( - @PathParam("uuid") - String uuid){ + public Response getRatedUser(@PathParam("uuid") String uuid) { CommentsManager commentsManager = APIUtil.getCommentsManager(); int ratedUsers = 0; @@ -188,19 +177,17 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ ratedUsers = commentsManager.getRatedUser(uuid); } catch (CommentManagementException 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) + .entity("Application with UUID" + uuid + " Internal server error occurs").build(); } catch (ApplicationManagementException 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) + .entity("Application with UUID" + uuid + " Internal server error occurs").build(); } return Response.status(Response.Status.OK).entity(ratedUsers).build(); } - @Override - @POST - @Consumes("uuid/stars/json") - public Response updateStars( - @ApiParam int stars, + @Override @POST @Consumes("uuid/stars/json") public Response updateStars(@ApiParam int stars, @PathParam("uuid") String uuid) { CommentsManager commentsManager = APIUtil.getCommentsManager(); @@ -218,7 +205,8 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{ } catch (ApplicationManagementException 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) + .entity("Application with UUID" + uuid + " Internal server error occurs").build(); } } } \ No newline at end of file From ff3eacd0ba94e33daab20698c2c28a9ed5361905 Mon Sep 17 00:00:00 2001 From: nishadi Date: Thu, 18 Jan 2018 00:06:41 +0530 Subject: [PATCH 41/56] Removed suppressing deprecated warning. --- .../application/mgt/core/dao/impl/Comment/CommentDAOImpl.java | 1 - .../device/application/mgt/core/impl/CommentsManagerImpl.java | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java index 0435d269ee..a42c0788ab 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java @@ -42,7 +42,6 @@ import java.util.List; * This handles CommentDAO related operations. */ -@SuppressWarnings( "deprecation" ) public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { private static final Log log = LogFactory.getLog(CommentDAOImpl.class); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java index 029624f690..2aed36f99d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java @@ -42,7 +42,7 @@ import java.util.List; /** * This class is the default implementation for the Managing the comments. */ -@SuppressWarnings("deprecation") public class CommentsManagerImpl implements CommentsManager { +public class CommentsManagerImpl implements CommentsManager { private static final Log log = LogFactory.getLog(CommentsManagerImpl.class); private CommentDAO commentDAO; From 62ac3455ddfe83a6daf10cff7426666509dca4af Mon Sep 17 00:00:00 2001 From: nishadi Date: Thu, 18 Jan 2018 00:11:52 +0530 Subject: [PATCH 42/56] Changed license year --- .../application/mgt/api/services/CommentManagementAPI.java | 2 +- .../mgt/api/services/impl/CommentManagementAPIImpl.java | 2 +- .../wso2/carbon/device/application/mgt/common/Comment.java | 2 +- .../device/application/mgt/common/PaginationRequest.java | 2 +- .../device/application/mgt/common/PaginationResult.java | 2 +- .../mgt/common/exception/CommentManagementException.java | 2 +- .../application/mgt/common/services/CommentsManager.java | 2 +- .../carbon/device/application/mgt/core/dao/CommentDAO.java | 2 +- .../application/mgt/core/dao/impl/Comment/CommentDAOImpl.java | 4 +--- .../device/application/mgt/core/impl/CommentsManagerImpl.java | 2 +- 10 files changed, 10 insertions(+), 12 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java index 177f39606e..9c1fab9d56 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2018, 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 diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java index def742fe28..05273b6979 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2018, 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 diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Comment.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Comment.java index 92f9e84553..ef6fab4543 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Comment.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Comment.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2018, 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 diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationRequest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationRequest.java index 1f4e668f47..915b3e40da 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationRequest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationRequest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2018, 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 diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationResult.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationResult.java index 46bf0983fa..df7354924f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationResult.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/PaginationResult.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2018, 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 diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/CommentManagementException.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/CommentManagementException.java index 7bdfb764a7..2f81f5144a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/CommentManagementException.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/exception/CommentManagementException.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2018, 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 diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java index b8001652ac..e297f03fd4 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2018, 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 diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java index f51d58644c..f0ca66e0c9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2018, 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 diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java index a42c0788ab..4c728c1f66 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * Copyright (c) 2018, 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 @@ -1010,8 +1010,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { stmt = connection.prepareStatement(sql); stmt.setInt(1,stars); stmt.setString(2, uuid); - resultSet=stmt.executeQuery(); - resultSet = stmt.executeQuery(sql); if (resultSet != null) { resultSet.getInt("STARS"); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java index 2aed36f99d..c5ff650d0f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java @@ -1,5 +1,5 @@ /* -* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +* Copyright (c) 2018, 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. From c35ccf9888dd62fdc21e5c198b8f9f717fcd04cc Mon Sep 17 00:00:00 2001 From: nishadi Date: Thu, 18 Jan 2018 02:06:15 +0530 Subject: [PATCH 43/56] Modified CommentManagerImpl Changed the messages of the Exceptions. --- .../mgt/core/impl/CommentsManagerImpl.java | 63 +++++++++++-------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java index c5ff650d0f..d56d70169e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java @@ -70,13 +70,18 @@ public class CommentsManagerImpl implements CommentsManager { 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 error occurs ,Comment for application with UUID " + uuid + "cannot add.", e); + } catch (SQLException e) { + throw new CommentManagementException( + "SQL Exception occurs,Comment for application with UUID " + uuid + "cannot add.", e); + } catch (TransactionManagementException e) { + throw new CommentManagementException( + "Transaction Management Exception occurs,Comment for application with UUID " + uuid + "cannot add.", + e); } finally { ConnectionManagerUtil.closeDBConnection(); } - } /** @@ -96,14 +101,15 @@ public class CommentsManagerImpl implements CommentsManager { + "relevant comment."); } if (comment == null) { - log.error("Null Point Exception.Comment at comment id " + CommentId + " is null."); + log.error("Comment can not be null, but Comment at comment id " + CommentId + " is null."); return false; } return true; } @Override - public List getAllComments(PaginationRequest request, String uuid) throws CommentManagementException { + public List getAllComments(PaginationRequest request, String uuid) + throws CommentManagementException { PaginationResult paginationResult = new PaginationResult(); List comments; @@ -123,9 +129,11 @@ public class CommentsManagerImpl implements CommentsManager { return comments; } catch (DBConnectionException e) { - throw new CommentManagementException("DB Connection Exception occurs.", e); + throw new CommentManagementException( + "DB Connection error occurs ,Comments of application with UUID " + uuid + "cannot get.", e); } catch (SQLException e) { - throw new CommentManagementException("SQL Exception occurs.", e); + throw new CommentManagementException( + "SQL Exception occurs,Comments of application with UUID " + uuid + "cannot get.", e); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -145,17 +153,18 @@ public class CommentsManagerImpl implements CommentsManager { ConnectionManagerUtil.openDBConnection(); comment = commentDAO.getComment(CommentId); } catch (DBConnectionException e) { - throw new CommentManagementException("DB Connection Exception occurs.", e); + throw new CommentManagementException( + "DB Connection error occurs ,Comment with comment id " + CommentId + "cannot get.", e); } catch (SQLException e) { - throw new CommentManagementException("SQL Exception occurs.", e); + throw new CommentManagementException( + "SQL Exception occurs,Comment with comment id " + CommentId + "cannot get.", e); } finally { ConnectionManagerUtil.closeDBConnection(); } return comment; } - @Override - public void deleteComment(int CommentId) throws CommentManagementException { + @Override public void deleteComment(int CommentId) throws CommentManagementException { Comment comment; comment = getComment(CommentId); @@ -169,11 +178,14 @@ public class CommentsManagerImpl implements CommentsManager { commentDAO.deleteComment(CommentId); ConnectionManagerUtil.commitDBTransaction(); } catch (DBConnectionException e) { - throw new CommentManagementException("DB Connection Exception occurs.", e); + throw new CommentManagementException( + "DB Connection error occurs deleting comment with comment id " + CommentId + ".", e); } catch (SQLException e) { - throw new CommentManagementException("SQL Exception occurs.", e); + throw new CommentManagementException("SQL error occurs deleting comment with comment id " + CommentId + ".", + e); } catch (TransactionManagementException e) { - throw new CommentManagementException("Transaction Management Exception occurs.", e); + throw new CommentManagementException( + "Transaction Management Exception occurs deleting comment with comment id " + CommentId + ".", e); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -195,9 +207,11 @@ public class CommentsManagerImpl implements CommentsManager { return commentDAO .updateComment(CommentId, comment.getComment(), comment.getModifiedBy(), comment.getModifiedAt()); } catch (SQLException e) { - throw new CommentManagementException("SQL Exception occurs.", e); + throw new CommentManagementException("SQL Error occurs updating comment with comment id " + CommentId + ".", + e); } catch (DBConnectionException e) { - throw new CommentManagementException("DB Connection occurs.", e); + throw new CommentManagementException( + "DB Connection error occurs updating comment with comment id " + CommentId + ".", e); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -213,10 +227,9 @@ public class CommentsManagerImpl implements CommentsManager { try { ConnectionManagerUtil.openDBConnection(); ratedUsers = commentDAO.getRatedUser(uuid); - } catch (DBConnectionException e) { - throw new ApplicationManagementException("DB Connection Exception occurs", e); } catch (ApplicationManagementDAOException e) { - throw new ApplicationManagementException("Application Management Exception occurs.", e); + throw new ApplicationManagementException( + "Rated Users of the Application with UUID " + uuid + " can not get.", e); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -233,10 +246,9 @@ public class CommentsManagerImpl implements CommentsManager { try { ConnectionManagerUtil.openDBConnection(); stars = commentDAO.getStars(uuid); - } catch (DBConnectionException e) { - throw new ApplicationManagementException("DB Connection Exception occurs", e); } catch (ApplicationManagementDAOException e) { - throw new ApplicationManagementException("Application Management Exception occurs.", e); + throw new ApplicationManagementException( + "Average stars of the Application with UUID " + uuid + " can not get.", e); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -266,9 +278,8 @@ 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); + throw new ApplicationManagementException( + "Updated average stars of the Application with UUID " + uuid + " can not get.", e); } finally { ConnectionManagerUtil.closeDBConnection(); } From 30ae09b0674de8804f13239d4589424a43183d6e Mon Sep 17 00:00:00 2001 From: nishadi Date: Thu, 18 Jan 2018 02:42:57 +0530 Subject: [PATCH 44/56] Modified CommentDAOImpl Reformatted --- .../core/dao/impl/Comment/CommentDAOImpl.java | 489 +++++++----------- 1 file changed, 200 insertions(+), 289 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java index 4c728c1f66..66bfbb1df7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java @@ -51,85 +51,80 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { throws CommentManagementException, DBConnectionException, SQLException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to add comment for application release ("+uuid+")"); + log.debug("Request received in DAO Layer to add comment for application release (" + uuid + ")"); } - Connection conn=this.getDBConnection(); + Connection conn = this.getDBConnection(); PreparedStatement stmt = null; - ResultSet rs=null; + ResultSet rs = null; int commentId = -1; - String sql = "INSERT INTO AP_APP_COMMENT (TENANT_ID, COMMENT_TEXT, CREATED_BY, PARENT_ID,AP_APP_RELEASE_ID," + - "AP_APP_ID) VALUES (?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?)," + - "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));"; - try{ - stmt = conn.prepareStatement(sql,new String[] {"id"}); + String sql = "INSERT INTO AP_APP_COMMENT (TENANT_ID, COMMENT_TEXT, CREATED_BY, PARENT_ID,AP_APP_RELEASE_ID," + + "AP_APP_ID) VALUES (?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?)," + + "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));"; + try { + stmt = conn.prepareStatement(sql, new String[] { "id" }); stmt.setInt(1, tenantId); stmt.setString(2, comment.getComment()); - stmt.setString(3,createdBy); - stmt.setInt(4,parentId); - stmt.setString(5,uuid); - stmt.setString(6,uuid); + stmt.setString(3, createdBy); + stmt.setInt(4, parentId); + stmt.setString(5, uuid); + stmt.setString(6, uuid); stmt.executeUpdate(); - rs = stmt.getGeneratedKeys(); if (rs.next()) { commentId = rs.getInt(1); } return commentId; - } finally { + } finally { Util.cleanupResources(stmt, rs); } } @Override - public int addComment(int tenantId,Comment comment, String createdBy, String appType, String appName, - String version) throws CommentManagementException, DBConnectionException, SQLException { + public int addComment(int tenantId, Comment comment, String createdBy, String appType, String appName, + String version) throws CommentManagementException, DBConnectionException, SQLException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to add to application ("+appName+") and version ("+version+")"); + log.debug("Request received in DAO Layer to add to application (" + appName + ") and version (" + version + + ")"); } - - Connection conn=this.getDBConnection(); + Connection conn = this.getDBConnection(); PreparedStatement stmt = null; ResultSet rs; int commentId = -1; - String sql = "INSERT INTO AP_APP_COMMENT ( TENANT_ID,COMMENT_TEXT, CREATED_BY,AP_APP_RELEASE_ID,AP_APP_ID) " + - "VALUES (?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE VERSION =? AND (SELECT ID FROM AP_APP WHERE " + - "TYPE=? AND NAME=?)),(SELECT ID FROM AP_APP WHERE TYPE=? AND NAME=?));"; - try{ - stmt = conn.prepareStatement(sql, new String[] {"id"}); + String sql = "INSERT INTO AP_APP_COMMENT ( TENANT_ID,COMMENT_TEXT, CREATED_BY,AP_APP_RELEASE_ID,AP_APP_ID) " + + "VALUES (?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE VERSION =? AND (SELECT ID FROM AP_APP WHERE " + + "TYPE=? AND NAME=?)),(SELECT ID FROM AP_APP WHERE TYPE=? AND NAME=?));"; + try { + stmt = conn.prepareStatement(sql, new String[] { "id" }); stmt.setInt(1, tenantId); stmt.setString(2, comment.getComment()); - stmt.setString(3,createdBy); - stmt.setString(4,version); - stmt.setString(5,appType); - stmt.setString(6,appName); - stmt.setString(7,appType); - stmt.setString(8,appName); - + stmt.setString(3, createdBy); + stmt.setString(4, version); + stmt.setString(5, appType); + stmt.setString(6, appName); + stmt.setString(7, appType); + stmt.setString(8, appName); stmt.executeUpdate(); rs = stmt.getGeneratedKeys(); if (rs.next()) { commentId = rs.getInt(1); } - } finally { Util.cleanupResources(stmt, null); } - return commentId; + return commentId; } @Override - public Comment updateComment(int CommentId, String updatedComment, String modifiedBy, Timestamp modifiedAt) - throws CommentManagementException, DBConnectionException, SQLException { + public Comment updateComment(int CommentId, String updatedComment, String modifiedBy, + Timestamp modifiedAt) throws CommentManagementException, DBConnectionException, SQLException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to update the comment with ID ("+ CommentId +")"); + log.debug("Request received in DAO Layer to update the comment with ID (" + CommentId + ")"); } - Connection connection; PreparedStatement statement = null; ResultSet rs = null; - String sql = "UPDATE AP_APP_COMMENT SET COMMENT_TEXT=?, MODEFIED_BY=? WHERE ID=?;"; try { connection = this.getDBConnection(); @@ -137,39 +132,35 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { statement.setString(1, updatedComment); statement.setString(2, modifiedBy); statement.setInt(3, CommentId); - statement.executeUpdate(); rs = statement.executeQuery(); - } finally { Util.cleanupResources(statement, rs); } return getComment(CommentId); } - public Comment updateComment(String uuid, int CommentId,String updatedComment, String modifiedBy, Timestamp - modifiedAt) throws CommentManagementException, DBConnectionException, SQLException { + @Override + public Comment updateComment(String uuid, int CommentId, String updatedComment, String modifiedBy, + Timestamp modifiedAt) throws CommentManagementException, DBConnectionException, SQLException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to update the comment with application ("+uuid+") and " + - "comment id ( "+ CommentId +")"); + log.debug("Request received in DAO Layer to update the comment with application (" + uuid + ") and " + + "comment id ( " + CommentId + ")"); } - Connection connection; PreparedStatement statement = null; ResultSet rs = null; - String sql = "UPDATE AP_APP_COMMENT SET COMMENT_TEXT=?,MODEFIED_BY=? WHERE ID=?; "; try { connection = this.getDBConnection(); statement = connection.prepareStatement(sql); statement.setString(1, updatedComment); - statement.setString(2,modifiedBy); + statement.setString(2, modifiedBy); statement.setInt(3, CommentId); statement.executeUpdate(); - rs= statement.getResultSet(); - - } finally { + rs = statement.getResultSet(); + } finally { Util.cleanupResources(statement, rs); } return getComment(CommentId); @@ -177,24 +168,22 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { @Override public Comment getComment(int CommentId) throws CommentManagementException { + if (log.isDebugEnabled()) { log.debug("Getting comment with the comment id(" + CommentId + ") from the database"); } Connection conn; PreparedStatement stmt = null; - ResultSet rs ; + ResultSet rs; String sql = ""; - Comment comment=new Comment(); - + Comment comment = new Comment(); try { conn = this.getDBConnection(); sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE ID=?;"; stmt = conn.prepareStatement(sql); stmt.setInt(1, CommentId); - rs=stmt.executeQuery(); - + rs = stmt.executeQuery(); if (rs.next()) { - comment.setId(rs.getInt("ID")); comment.setTenantId(rs.getInt("TENANT_ID")); comment.setComment(rs.getString("COMMENT_TEXT")); @@ -203,16 +192,15 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedBy(rs.getString("MODEFIED_AT")); comment.setParent(rs.getInt("PARENT_ID")); - - Util.cleanupResources(stmt,rs); + Util.cleanupResources(stmt, rs); return comment; } - } catch (SQLException e) { - throw new CommentManagementException("Error occurred while retrieving information of the comment "+ CommentId, e); + throw new CommentManagementException( + "SQL Error occurred while retrieving information of the comment " + CommentId, e); } catch (DBConnectionException e) { - log.error("DB Connection Exception occurs.", e); - } finally { + log.error("DB Connection Exception occurred while retrieving information of the comment " + CommentId, e); + } finally { Util.cleanupResources(stmt, null); } return comment; @@ -222,26 +210,23 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { public List getComment(String uuid) throws CommentManagementException{ if (log.isDebugEnabled()) { - log.debug("Getting comment with the application release(" +uuid + ") from the database"); + log.debug("Getting comment with the application release(" + uuid + ") from the database"); } Connection conn; PreparedStatement stmt = null; - ResultSet rs ; + ResultSet rs; String sql = ""; - List comments=new ArrayList<>(); - + List comments = new ArrayList<>(); try { conn = this.getDBConnection(); - sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE (SELECT ID FROM AP_APP_RELEASE where UUID=?)AND " + - "(SELECT AP_APP_ID FROM AP_APP_RELEASE where UUID=?);"; - + sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE (SELECT ID FROM AP_APP_RELEASE where UUID=?)AND " + + "(SELECT AP_APP_ID FROM AP_APP_RELEASE where UUID=?);"; stmt = conn.prepareStatement(sql); stmt.setString(1, uuid); - stmt.setString(2,uuid); - rs=stmt.executeQuery(); - + stmt.setString(2, uuid); + rs = stmt.executeQuery(); while (rs.next()) { - Comment comment=new Comment(); + Comment comment = new Comment(); comment.setId(rs.getInt("ID")); comment.setTenantId(rs.getInt("TENANT_ID")); comment.setComment(rs.getString("COMMENT_TEXT")); @@ -250,7 +235,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedBy(rs.getString("MODEFIED_AT")); comment.setParent(rs.getInt("PARENT_ID")); - comments.add(comment); } } catch (DBConnectionException e) { @@ -264,30 +248,28 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { } @Override - public List getAllComments(String uuid,PaginationRequest request) throws CommentManagementException, SQLException, - DBConnectionException { + public List getAllComments(String uuid, PaginationRequest request) + throws CommentManagementException, SQLException, DBConnectionException { + if (log.isDebugEnabled()) { - log.debug("Getting comment of the application release ("+uuid+") from the database"); + log.debug("Getting comment of the application release (" + uuid + ") from the database"); } Connection conn; PreparedStatement stmt = null; ResultSet rs = null; - List comments=new ArrayList<>(); + List comments = new ArrayList<>(); String sql = ""; - try { conn = this.getDBConnection(); - sql += "\n" + - "SELECT COMMENT_TEXT FROM AP_APP_COMMENT, AP_APP_RELEASE WHERE AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID " + - "AND AP_APP_RELEASE.UUID =? LIMIT ? OFFSET ?;"; + sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT, AP_APP_RELEASE WHERE AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID " + + "AND AP_APP_RELEASE.UUID =? LIMIT ? OFFSET ?;"; stmt = conn.prepareStatement(sql); - stmt.setString(1,uuid); - stmt.setInt(2,request.getLimit()); - stmt.setInt(3,request.getOffSet()); - rs= stmt.executeQuery(); - + stmt.setString(1, uuid); + stmt.setInt(2, request.getLimit()); + stmt.setInt(3, request.getOffSet()); + rs = stmt.executeQuery(); while (rs.next()) { - Comment comment=new Comment(); + Comment comment = new Comment(); comment.setId(rs.getInt("ID")); comment.setTenantId(rs.getInt("TENANT_ID")); comment.setComment(rs.getString("COMMENT_TEXT")); @@ -296,7 +278,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedBy(rs.getString("MODEFIED_BY")); comment.setParent(rs.getInt("PARENT_ID")); - comments.add(comment); } } finally { @@ -312,22 +293,19 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Connection conn; PreparedStatement stmt = null; ResultSet rs = null; - boolean isUuidProvided=false; - + boolean isUuidProvided = false; try { conn = this.getDBConnection(); - if (uuid!= null) { + if (uuid != null) { isUuidProvided = true; } - if (isUuidProvided) { - String sql = "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE " + - "WHERE AP_APP_COMMENT.AP_APP_RELEASE_ID= AP_APP_RELEASE.ID AND " + - "AP_APP_COMMENT.AP_APP_ID= AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;"; + String sql = "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE " + + "WHERE AP_APP_COMMENT.AP_APP_RELEASE_ID= AP_APP_RELEASE.ID AND " + + "AP_APP_COMMENT.AP_APP_ID= AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;"; stmt = conn.prepareStatement(sql); stmt.setString(1, uuid); rs = stmt.executeQuery(); - if (rs.next()) { commentCount = rs.getInt("COMMENTS_COUNT"); } @@ -346,26 +324,23 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { public List getComments(int appReleasedId, int appId) throws CommentManagementException { if (log.isDebugEnabled()) { - log.debug("Getting comments with the application release id(" + appReleasedId + ") and " + - "application id("+appId+") from the database"); + log.debug("Getting comments with the application release id(" + appReleasedId + ") and " + "application id(" + + appId + ") from the database"); } Connection conn; PreparedStatement stmt = null; - ResultSet rs ; + ResultSet rs; String sql = ""; List comments = new ArrayList<>(); - try { conn = this.getDBConnection(); sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? AND AP_APP_ID=?;"; - stmt = conn.prepareStatement(sql); stmt.setInt(1, appReleasedId); - stmt.setInt(2,appId); - rs=stmt.executeQuery(); - + stmt.setInt(2, appId); + rs = stmt.executeQuery(); while (rs.next()) { - Comment comment=new Comment(); + Comment comment = new Comment(); comment.setId(rs.getInt("ID")); comment.setTenantId(rs.getInt("TENANT_ID")); comment.setComment(rs.getString("COMMENT_TEXT")); @@ -374,15 +349,12 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedBy(rs.getString("modifiedBy")); comment.setParent(rs.getInt("PARENT_ID")); - comments.add(comment); } } catch (DBConnectionException e) { - log.error("DB Connection Exception occurs.", e); - + log.error("DB Connection Exception occurred while retrieving information of comments", e); } catch (SQLException e) { - throw new CommentManagementException("Error occurred while retrieving information of comments", e); - + throw new CommentManagementException("SQL Error occurred while retrieving information of comments", e); } finally { Util.cleanupResources(stmt, null); } @@ -392,32 +364,30 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { @Override public List getComments(String appType, String appName, String version) throws CommentManagementException, DBConnectionException, SQLException { + if (log.isDebugEnabled()) { - log.debug("Getting comments with the application name(" + appName + "),application type("+appType+") " + - "and application version ("+version+") from the database"); + log.debug("Getting comments with the application name(" + appName + "),application type(" + appType + ") " + + "and application version (" + version + ") from the database"); } Connection conn; PreparedStatement stmt = null; ResultSet rs; String sql = ""; - List comments =new ArrayList<>(); - + List comments = new ArrayList<>(); try { conn = this.getDBConnection(); - sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID FROM AP_APP_COMMENT C ,"+ - "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=?) R,"+ - "(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? AND TYPE=?)P"+ - " WHERE AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND AP_APP_ID=RELEASE_AP_APP_ID"+ - "ORDER BY CREATED_AT DESC;"; - + sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID FROM AP_APP_COMMENT C ," + + "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=?) R," + + "(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? AND TYPE=?)P" + + " WHERE AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND AP_APP_ID=RELEASE_AP_APP_ID" + + "ORDER BY CREATED_AT DESC;"; stmt = conn.prepareStatement(sql); stmt.setString(1, version); - stmt.setString(2,appName); - stmt.setString(3,appType); - rs=stmt.executeQuery(); - + stmt.setString(2, appName); + stmt.setString(3, appType); + rs = stmt.executeQuery(); while (rs.next()) { - Comment comment=new Comment(); + Comment comment = new Comment(); comment.setId(rs.getInt("ID")); comment.setTenantId(rs.getInt("TENANT_ID")); comment.setComment(rs.getString("COMMENT_TEXT")); @@ -426,7 +396,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedBy(rs.getString("modifiedBy")); comment.setParent(rs.getInt("PARENT_ID")); - comments.add(comment); } } finally { @@ -442,23 +411,19 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { if (log.isDebugEnabled()) { log.debug("Getting comments with the tenant_id(" + tenantId + ") from the database"); } - Connection conn; PreparedStatement stmt = null; ResultSet rs; String sql = ""; List comments = new ArrayList<>(); - try { conn = this.getDBConnection(); sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE TENANT_ID='?';"; - stmt = conn.prepareStatement(sql); stmt.setInt(1, tenantId); - rs=stmt.executeQuery(); - + rs = stmt.executeQuery(); while (rs.next()) { - Comment comment=new Comment(); + Comment comment = new Comment(); comment.setId(rs.getInt("ID")); comment.setTenantId(rs.getInt("TENANT_ID")); comment.setComment(rs.getString("COMMENT_TEXT")); @@ -467,7 +432,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedBy(rs.getString("modifiedBy")); comment.setParent(rs.getInt("PARENT_ID")); - comments.add(comment); } } finally { @@ -483,24 +447,20 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { if (log.isDebugEnabled()) { log.debug("Getting comments with the created by(" + createdBy + ") from the database"); } - Connection conn; PreparedStatement stmt = null; ResultSet rs; String sql = ""; List comments = new ArrayList<>(); - try { conn = this.getDBConnection(); - sql += "SELECT COMMENT_TEXT ,PARENT_ID,TENANT_ID,CREATED_AT FROM AP_APP_COMMENT WHERE CREATED_BY= ?" + - " ORDER BY CREATED_AT DESC;"; - + sql += "SELECT COMMENT_TEXT ,PARENT_ID,TENANT_ID,CREATED_AT FROM AP_APP_COMMENT WHERE CREATED_BY= ?" + + " ORDER BY CREATED_AT DESC;"; stmt = conn.prepareStatement(sql); stmt.setString(1, createdBy); - rs=stmt.executeQuery(); - + rs = stmt.executeQuery(); while (rs.next()) { - Comment comment=new Comment(); + Comment comment = new Comment(); comment.setId(rs.getInt("ID")); comment.setTenantId(rs.getInt("TENANT_ID")); comment.setComment(rs.getString("COMMENT_TEXT")); @@ -509,7 +469,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedBy(rs.getString("modifiedBy")); comment.setParent(rs.getInt("PARENT_ID")); - comments.add(comment); } } finally { @@ -523,27 +482,24 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { DBConnectionException, SQLException { if (log.isDebugEnabled()) { - log.debug("Getting comments with the created by(" + createdBy + ") at ("+createdAt+") from the database"); + log.debug( + "Getting comments with the created by(" + createdBy + ") at (" + createdAt + ") from the database"); } - Connection conn; PreparedStatement stmt = null; ResultSet rs; String sql = ""; List comments = new ArrayList<>(); - try { conn = this.getDBConnection(); - sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID FROM AP_APP_COMMENT WHERE CREATED_BY=?" + - "AND CREATED_AT= ? ORDER BY CREATED_AT DESC;"; - + sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID FROM AP_APP_COMMENT WHERE CREATED_BY=?" + + "AND CREATED_AT= ? ORDER BY CREATED_AT DESC;"; stmt = conn.prepareStatement(sql); stmt.setString(1, createdBy); - stmt.setTimestamp(2,createdAt); - rs=stmt.executeQuery(); - + stmt.setTimestamp(2, createdAt); + rs = stmt.executeQuery(); while (rs.next()) { - Comment comment=new Comment(); + Comment comment = new Comment(); comment.setId(rs.getInt("ID")); comment.setTenantId(rs.getInt("TENANT_ID")); comment.setComment(rs.getString("COMMENT_TEXT")); @@ -552,7 +508,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedBy(rs.getString("modifiedBy")); comment.setParent(rs.getInt("PARENT_ID")); - comments.add(comment); } } finally { @@ -566,26 +521,22 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { DBConnectionException, SQLException { if (log.isDebugEnabled()) { - log.debug("Getting comments with the modified by(" +modifiedBy + ") from the database"); + log.debug("Getting comments with the modified by(" + modifiedBy + ") from the database"); } - Connection conn; PreparedStatement stmt = null; - ResultSet rs ; + ResultSet rs; String sql = ""; List comments = new ArrayList<>(); - try { conn = this.getDBConnection(); - sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID,CREATED_AT,MODEFIED_AT FROM AP_APP_COMMENT " + - "WHERE MODEFIED_BY= ? ORDER BY CREATED_AT DESC;"; - + sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID,CREATED_AT,MODEFIED_AT FROM AP_APP_COMMENT " + + "WHERE MODEFIED_BY= ? ORDER BY CREATED_AT DESC;"; stmt = conn.prepareStatement(sql); stmt.setString(1, modifiedBy); - rs=stmt.executeQuery(); - + rs = stmt.executeQuery(); while (rs.next()) { - Comment comment=new Comment(); + Comment comment = new Comment(); comment.setId(rs.getInt("ID")); comment.setTenantId(rs.getInt("TENANT_ID")); comment.setComment(rs.getString("COMMENT_TEXT")); @@ -594,7 +545,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedBy(rs.getString("modifiedBy")); comment.setParent(rs.getInt("PARENT_ID")); - comments.add(comment); } } finally { @@ -608,28 +558,24 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { throws CommentManagementException, DBConnectionException, SQLException { if (log.isDebugEnabled()) { - log.debug("Getting comments with the modified by(" +modifiedBy + ") at ("+modifiedAt+") from the " + - "database"); + log.debug("Getting comments with the modified by(" + modifiedBy + ") at (" + modifiedAt + ") from the " + + "database"); } - Connection conn; PreparedStatement stmt = null; ResultSet rs; String sql = ""; List comments = new ArrayList<>(); - try { conn = this.getDBConnection(); - sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID,CREATED_AT FROM AP_APP_COMMENT WHERE MODEFIED_BY= ?," + - "MODEFIED_AT=? ORDER BY CREATED_AT DESC;"; - + sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID,CREATED_AT FROM AP_APP_COMMENT WHERE MODEFIED_BY= ?," + + "MODEFIED_AT=? ORDER BY CREATED_AT DESC;"; stmt = conn.prepareStatement(sql); stmt.setString(1, modifiedBy); - stmt.setTimestamp(2,modifiedAt); - rs=stmt.executeQuery(); - + stmt.setTimestamp(2, modifiedAt); + rs = stmt.executeQuery(); while (rs.next()) { - Comment comment=new Comment(); + Comment comment = new Comment(); comment.setId(rs.getInt("ID")); comment.setTenantId(rs.getInt("TENANT_ID")); comment.setComment(rs.getString("COMMENT_TEXT")); @@ -638,7 +584,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedBy(rs.getString("modifiedBy")); comment.setParent(rs.getInt("PARENT_ID")); - comments.add(comment); } } finally { @@ -652,33 +597,30 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { throws CommentManagementException, DBConnectionException, SQLException { if (log.isDebugEnabled()) { - log.debug("Getting comments with the application name(" + appName + "),application type("+appType+") and" + - "application version ("+version+") from the database"); + log.debug( + "Getting comments with the application name(" + appName + "),application type(" + appType + ") and" + + "application version (" + version + ") from the database"); } - Connection conn; PreparedStatement stmt = null; ResultSet rs; String sql = ""; - List comments =new ArrayList<>(); - + List comments = new ArrayList<>(); try { conn = this.getDBConnection(); - sql += "SELECT COMMENT_TEXT,TENANT_ID FROM AP_APP_COMMENT C ," + - "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=? ) " + - "R,(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? AND TYPE=?)P " + - "WHERE PARENT_ID=? AND AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND " + - "AP_APP_ID=RELEASE_AP_APP_ID ORDER BY CREATED_AT DESC;"; - + sql += "SELECT COMMENT_TEXT,TENANT_ID FROM AP_APP_COMMENT C ," + + "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=? ) " + + "R,(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? AND TYPE=?)P " + + "WHERE PARENT_ID=? AND AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND " + + "AP_APP_ID=RELEASE_AP_APP_ID ORDER BY CREATED_AT DESC;"; stmt = conn.prepareStatement(sql); stmt.setString(1, version); - stmt.setString(2,appName); - stmt.setString(3,appType); - stmt.setInt(4,parentId); - rs=stmt.executeQuery(); - + stmt.setString(2, appName); + stmt.setString(3, appType); + stmt.setInt(4, parentId); + rs = stmt.executeQuery(); while (rs.next()) { - Comment comment=new Comment(); + Comment comment = new Comment(); comment.setId(rs.getInt("ID")); comment.setTenantId(rs.getInt("TENANT_ID")); comment.setComment(rs.getString("COMMENT_TEXT")); @@ -687,29 +629,26 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedBy(rs.getString("modifiedBy")); comment.setParent(rs.getInt("PARENT_ID")); - comments.add(comment); } } finally { Util.cleanupResources(stmt, null); } - return comments; + return comments; } @Override public int getCommentCount(String uuid) throws CommentManagementException, DBConnectionException, SQLException { + Connection conn; PreparedStatement stmt = null; int commentCount = 0; - try { conn = this.getDBConnection(); - String sql = "\n" + - "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE WHERE " + - "AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_COMMENT.AP_APP_ID=" + - "AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;"; - + String sql = "\n" + "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE WHERE " + + "AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_COMMENT.AP_APP_ID=" + + "AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;"; stmt = conn.prepareStatement(sql); stmt.setString(1, uuid); ResultSet rs = stmt.executeQuery(); @@ -729,15 +668,12 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Connection conn; PreparedStatement stmt = null; int commentCount = 0; - try { conn = this.getDBConnection(); String sql = "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE CREATED_BY= ?;"; - stmt = conn.prepareStatement(sql); stmt.setString(1, createdBy); ResultSet rs = stmt.executeQuery(); - if (rs.next()) { commentCount = rs.getInt("COMMENT_COUNT"); } @@ -745,7 +681,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Util.cleanupResources(stmt, null); } return commentCount; - } @Override @@ -755,7 +690,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Connection conn; PreparedStatement stmt = null; int commentCount = 0; - try { conn = this.getDBConnection(); String sql = "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE MODEFIED_BY= ? AND MODEFIED_AT=?;"; @@ -763,7 +697,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { stmt.setString(1, modifiedBy); stmt.setTimestamp(2, modifedAt); ResultSet rs = stmt.executeQuery(); - if (rs.next()) { commentCount = rs.getInt("COMMENT_COUNT"); } @@ -780,16 +713,13 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Connection conn; PreparedStatement stmt = null; int commentCount = 0; - try { conn = this.getDBConnection(); String sql = "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? AND AP_APP_ID=?;"; - stmt = conn.prepareStatement(sql); stmt.setInt(1, appReleaseId); stmt.setInt(2, appId); ResultSet rs = stmt.executeQuery(); - if (rs.next()) { commentCount = rs.getInt("COMMENT_COUNT"); } @@ -806,20 +736,17 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Connection conn; PreparedStatement stmt = null; int commentCount = 0; - try { conn = this.getDBConnection(); - String sql = "SELECT COUNT(ID) AS COMMENT_COUNT FROM AP_APP_COMMENT C, " + - "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=? )R," + - "(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? and TYPE=?)P " + - "WHERE AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND AP_APP_ID=RELEASE_AP_APP_ID;"; - + String sql = "SELECT COUNT(ID) AS COMMENT_COUNT FROM AP_APP_COMMENT C, " + + "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=? )R," + + "(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? and TYPE=?)P " + + "WHERE AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND AP_APP_ID=RELEASE_AP_APP_ID;"; stmt = conn.prepareStatement(sql); stmt.setString(1, version); stmt.setString(2, appName); stmt.setString(3, appType); ResultSet rs = stmt.executeQuery(); - if (rs.next()) { commentCount = rs.getInt("COMMENT_COUNT"); } @@ -834,16 +761,15 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Connection conn; PreparedStatement stmt = null; int commentCount = 0; - try { conn = this.getDBConnection(); - String sql = "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE WHERE " + - "AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND " + - "AP_APP_COMMENT.AP_APP_ID=AP_APP_RELEASE.AP_APP_ID and AP_APP_RELEASE.UUID=? and PARENT_ID=?;"; + String sql = "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE WHERE " + + "AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND " + + "AP_APP_COMMENT.AP_APP_ID=AP_APP_RELEASE.AP_APP_ID and AP_APP_RELEASE.UUID=? and PARENT_ID=?;"; stmt = conn.prepareStatement(sql); - stmt.setString(1,uuid); - stmt.setInt(2,parentId); + stmt.setString(1, uuid); + stmt.setInt(2, parentId); ResultSet rs = stmt.executeQuery(); if (rs.next()) { commentCount = rs.getInt("COMMENT_COUNT"); @@ -875,16 +801,14 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Connection conn; PreparedStatement stmt = null; - try { conn = this.getDBConnection(); - String sql = "DELETE FROM AP_APP_COMMENT WHERE " + - "(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?)AND (SELECT AP_APP_ID FROM AP_APP_RELEASE " + - "WHERE UUID=?);"; - + String sql = "DELETE FROM AP_APP_COMMENT WHERE " + + "(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?)AND (SELECT AP_APP_ID FROM AP_APP_RELEASE " + + "WHERE UUID=?);"; stmt = conn.prepareStatement(sql); - stmt.setString(1,uuid); - stmt.setString(2,uuid); + stmt.setString(1, uuid); + stmt.setString(2, uuid); stmt.executeUpdate(); } finally { Util.cleanupResources(stmt, null); @@ -897,14 +821,12 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Connection conn; PreparedStatement stmt = null; - try { conn = this.getDBConnection(); String sql = "DELETE FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? and AP_APP_ID=?;"; - stmt = conn.prepareStatement(sql); stmt.setInt(1, appReleaseID); - stmt.setInt(2,appId); + stmt.setInt(2, appId); stmt.executeUpdate(); } finally { Util.cleanupResources(stmt, null); @@ -916,25 +838,23 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Connection conn; PreparedStatement stmt = null; - try { conn = this.getDBConnection(); - String sql = "DELETE FROM AP_APP_COMMENT WHERE " + - "(SELECT AP_APP_RELEASE_ID FROM AP_APP_RELEASE WHERE VERSION=? AND " + - "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? AND TYPE=?)) AND " + - "(SELECT AP_APP_ID FROM AP_APP AND NAME=? AND TYPE=?);"; - + String sql = "DELETE FROM AP_APP_COMMENT WHERE " + + "(SELECT AP_APP_RELEASE_ID FROM AP_APP_RELEASE WHERE VERSION=? AND " + + "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? AND TYPE=?)) AND " + + "(SELECT AP_APP_ID FROM AP_APP AND NAME=? AND TYPE=?);"; stmt = conn.prepareStatement(sql); stmt.setString(1, version); - stmt.setString(2,appName); - stmt.setString(3,appType); - stmt.setString(4,appName); - stmt.setString(5,appType); + stmt.setString(2, appName); + stmt.setString(3, appType); + stmt.setString(4, appName); + stmt.setString(5, appType); stmt.executeUpdate(); } catch (DBConnectionException e) { - log.error("DB Connection Exception occurs.", e); + log.error("DB Connection Exception occurred while deleting comments", e); } catch (SQLException e) { - throw new CommentManagementException("Error occurred while deleting comments", e); + throw new CommentManagementException("SQL Error occurred while deleting comments", e); } finally { Util.cleanupResources(stmt, null); } @@ -946,24 +866,22 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Connection conn; PreparedStatement stmt = null; - try { conn = this.getDBConnection(); - String sql = "DELETE FROM AP_APP_COMMENT WHERE " + - "(SELECT AP_APP_RELEASE_ID FROM AP_APP_RELEASE WHERE VERSION=? AND " + - "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? AND TYPE=?)) AND " + - "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? and TYPE=?) AND CREATED_BY=?;"; - + String sql = "DELETE FROM AP_APP_COMMENT WHERE " + + "(SELECT AP_APP_RELEASE_ID FROM AP_APP_RELEASE WHERE VERSION=? AND " + + "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? AND TYPE=?)) AND " + + "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? and TYPE=?) AND CREATED_BY=?;"; stmt = conn.prepareStatement(sql); stmt.setString(1, version); - stmt.setString(2,appName); - stmt.setString(3,appType); - stmt.setString(4,appName); - stmt.setString(5,appType); - stmt.setString(6,createdBy); + stmt.setString(2, appName); + stmt.setString(3, appType); + stmt.setString(4, appName); + stmt.setString(5, appType); + stmt.setString(6, createdBy); stmt.executeUpdate(); } catch (DBConnectionException e) { - log.error("DB Connection Exception occurs.", e); + log.error("DB Connection Exception occurred while deleting comments ", e); } catch (SQLException e) { throw new CommentManagementException("Error occurred while deleting comments", e); } finally { @@ -977,19 +895,18 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Connection conn; PreparedStatement stmt = null; - try { conn = this.getDBConnection(); - String sql = "DELETE FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?) " + - "AND AP_APP_ID=(SELECT AP_APP_ID FROM AP_APP_RELEASE where UUID=?)AND PARENT_ID=?;"; - + String sql = + "DELETE FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?) " + + "AND AP_APP_ID=(SELECT AP_APP_ID FROM AP_APP_RELEASE where UUID=?)AND PARENT_ID=?;"; stmt = conn.prepareStatement(sql); - stmt.setString(1,uuid); - stmt.setString(2,uuid); - stmt.setInt(3,parentId); + stmt.setString(1, uuid); + stmt.setString(2, uuid); + stmt.setInt(3, parentId); stmt.executeUpdate(); } catch (DBConnectionException e) { - log.error("DB Connection Exception occurs.", e); + log.error("DB Connection Exception occurred while deleting comments.", e); } catch (SQLException e) { throw new CommentManagementException("Error occurred while deleting comments", e); } finally { @@ -1006,34 +923,30 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { try { connection = this.getDBConnection(); String sql = "UPDATE AP_APP_RELEASE SET STARS=?, NO_OF_RATED_USERS=(NO_OF_RATED_USERS+1) WHERE UUID=?;"; - stmt = connection.prepareStatement(sql); - stmt.setInt(1,stars); + stmt.setInt(1, stars); stmt.setString(2, uuid); resultSet = stmt.executeQuery(sql); if (resultSet != null) { resultSet.getInt("STARS"); } - int numORows=resultSet.getRow(); - + int numORows = resultSet.getRow(); if (resultSet.next()) { - ApplicationRelease applicationRelease=new ApplicationRelease(); + ApplicationRelease applicationRelease = new ApplicationRelease(); applicationRelease.setStars(resultSet.getInt("STARS")); - Util.cleanupResources(stmt, resultSet); - } + } } catch (SQLException e) { throw new ApplicationManagementDAOException( - "SQL Exception while trying to add stars to an application (UUID : " + uuid + "), by executing " + - "the query " + e); + "SQL Exception while trying to add stars to an application (UUID : " + uuid + "), by executing " + + "the query " + e); } catch (DBConnectionException e) { - log.error("DB Connection Exception occurs.", e); + log.error("DB Connection Exception while trying to add stars to an application (UUID : " + uuid + "), ", + e); } finally { Util.cleanupResources(stmt, null); return getStars(uuid); - } - } @Override @@ -1043,32 +956,30 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { PreparedStatement statement = null; ResultSet resultSet = null; String sql; - int Stars=0; + int Stars = 0; try { connection = this.getDBConnection(); - sql="SELECT STARS FROM AP_APP_RELEASE WHERE UUID=?;"; - + sql = "SELECT STARS FROM AP_APP_RELEASE WHERE UUID=?;"; statement = connection.prepareStatement(sql); - statement.setString(1,uuid); + statement.setString(1, uuid); resultSet = statement.executeQuery(); - if (resultSet.next()) { ApplicationRelease applicationRelease = new ApplicationRelease(); - Stars=resultSet.getInt("STARS"); - + Stars = resultSet.getInt("STARS"); return Stars; } } catch (SQLException e) { throw new ApplicationManagementDAOException( - "SQL Exception while trying to get stars from an application (UUID : " + uuid + "), by executing " + - "the query " + e); + "SQL Exception while trying to get stars from an application (UUID : " + uuid + "), by executing " + + "the query " + e); } catch (DBConnectionException e) { - log.error("DB Connection Exception occurs.", e); + log.error( + "DB Connection Exception while trying to get stars from an application (UUID : " + uuid + ")," + e); } finally { Util.cleanupResources(statement, resultSet); } - return Stars ; + return Stars; } @Override From a1868939a7e7b33e17b3334388effb1b53bb4ea4 Mon Sep 17 00:00:00 2001 From: nishadi Date: Thu, 18 Jan 2018 02:44:56 +0530 Subject: [PATCH 45/56] Modified CommentDAOImpl Reformatted --- .../mgt/core/dao/impl/Comment/CommentDAOImpl.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java index 66bfbb1df7..6edbd0218a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java @@ -238,9 +238,9 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comments.add(comment); } } catch (DBConnectionException e) { - log.error("DB Connection Exception occurs.", e); + log.error("DB Connection Exception occurred while retrieving comments", e); } catch (SQLException e) { - throw new CommentManagementException("Error occurred while retrieving comments", e); + throw new CommentManagementException("SQL Error occurred while retrieving comments", e); } finally { Util.cleanupResources(stmt, null); } @@ -311,9 +311,9 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { } } } catch (SQLException e) { - throw new CommentManagementException("Error occurred while retrieving count of comments", e); + throw new CommentManagementException("SQL Error occurred while retrieving count of comments", e); } catch (DBConnectionException e) { - log.error("DB Connection Exception occurs.", e); + log.error("DB Connection Exception occurred while retrieving count of comments", e); } finally { Util.cleanupResources(stmt, rs); } From 4ea87284f2a6850c301c2b3bfc970788f2c7a629 Mon Sep 17 00:00:00 2001 From: nishadi Date: Thu, 18 Jan 2018 11:17:05 +0530 Subject: [PATCH 46/56] Modified CommentAPIImpl Reformatted --- .../impl/CommentManagementAPIImpl.java | 33 ++++++++++++++----- 1 file changed, 25 insertions(+), 8 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java index 05273b6979..f6d93cd9b1 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java @@ -80,8 +80,13 @@ public class CommentManagementAPIImpl implements CommentManagementAPI { return Response.status(Response.Status.OK).entity(comments).build(); } - @Override @POST @Consumes("application/json") @Path("/{uuid}") public Response addComments( - @ApiParam Comment comment, @PathParam("uuid") String uuid) { + @Override + @POST + @Consumes("application/json") + @Path("/{uuid}") + public Response addComments( + @ApiParam Comment comment, + @PathParam("uuid") String uuid) { CommentsManager commentsManager = APIUtil.getCommentsManager(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); @@ -102,8 +107,13 @@ public class CommentManagementAPIImpl implements CommentManagementAPI { } } - @Override @PUT @Consumes("application/json") @Path("/{CommentId}") public Response updateComment( - @ApiParam Comment comment, @PathParam("CommentId") int CommentId) { + @Override + @PUT + @Consumes("application/json") + @Path("/{CommentId}") + public Response updateComment( + @ApiParam Comment comment, + @PathParam("CommentId") int CommentId) { CommentsManager commentsManager = APIUtil.getCommentsManager(); try { @@ -129,7 +139,8 @@ public class CommentManagementAPIImpl implements CommentManagementAPI { @Override @DELETE @Path("/{CommentId}") - public Response deleteComment(@PathParam("CommentId") int CommentId) { + public Response deleteComment( + @PathParam("CommentId") int CommentId) { CommentsManager commentsManager = APIUtil.getCommentsManager(); try { @@ -149,7 +160,8 @@ public class CommentManagementAPIImpl implements CommentManagementAPI { @Override @GET @Path("/{uuid}") - public Response getStars(@PathParam("uuid") String uuid) { + public Response getStars( + @PathParam("uuid") String uuid) { CommentsManager commentsManager = APIUtil.getCommentsManager(); int Stars = 0; @@ -169,7 +181,8 @@ public class CommentManagementAPIImpl implements CommentManagementAPI { @Override @GET @Path("/{uuid}") - public Response getRatedUser(@PathParam("uuid") String uuid) { + public Response getRatedUser( + @PathParam("uuid") String uuid) { CommentsManager commentsManager = APIUtil.getCommentsManager(); int ratedUsers = 0; @@ -187,7 +200,11 @@ public class CommentManagementAPIImpl implements CommentManagementAPI { return Response.status(Response.Status.OK).entity(ratedUsers).build(); } - @Override @POST @Consumes("uuid/stars/json") public Response updateStars(@ApiParam int stars, + @Override + @POST + @Consumes("uuid/stars/json") + public Response updateStars( + @ApiParam int stars, @PathParam("uuid") String uuid) { CommentsManager commentsManager = APIUtil.getCommentsManager(); From f02a0b9e6c20c3f0475e94cd6a9104f741d854f1 Mon Sep 17 00:00:00 2001 From: nishadi Date: Thu, 18 Jan 2018 11:32:32 +0530 Subject: [PATCH 47/56] Modified pom.xml at org.wso2.carbon.device.application.mgt.common Extra dependency to "org.wso2.carbon.device.application.mgt.core" is removed. --- .../org.wso2.carbon.device.application.mgt.common/pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml index 785ed5b20d..4493c59c69 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/pom.xml @@ -108,10 +108,6 @@ com.google.code.gson gson - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.application.mgt.core - From da0b1470500377789081fc59767fbeeaa7e16850 Mon Sep 17 00:00:00 2001 From: nishadi Date: Thu, 18 Jan 2018 13:31:21 +0530 Subject: [PATCH 48/56] modified commentsManagerImpl Reformatted. --- .../device/application/mgt/core/impl/CommentsManagerImpl.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java index d56d70169e..7f52998e1a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java @@ -164,7 +164,8 @@ public class CommentsManagerImpl implements CommentsManager { return comment; } - @Override public void deleteComment(int CommentId) throws CommentManagementException { + @Override + public void deleteComment(int CommentId) throws CommentManagementException { Comment comment; comment = getComment(CommentId); From 3b86f8a443a25b81fff3fc876826b4eb9060cb7b Mon Sep 17 00:00:00 2001 From: nishadi Date: Thu, 18 Jan 2018 14:16:48 +0530 Subject: [PATCH 49/56] CommentId changed into commentId --- .../api/services/CommentManagementAPI.java | 12 ++--- .../impl/CommentManagementAPIImpl.java | 25 +++++------ .../mgt/common/services/CommentsManager.java | 12 ++--- .../application/mgt/core/dao/CommentDAO.java | 18 ++++---- .../core/dao/impl/Comment/CommentDAOImpl.java | 30 ++++++------- .../mgt/core/impl/CommentsManagerImpl.java | 45 ++++++++----------- 6 files changed, 67 insertions(+), 75 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java index 9c1fab9d56..e52f0416fb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java @@ -245,11 +245,11 @@ public interface CommentManagementAPI { required = true) @Valid Comment comment, @ApiParam( - name="CommentId", + name="commentId", value = "comment id of the updating comment.", required = true) - @QueryParam("CommentId") - int apAppCommentId); + @QueryParam("commentId") + int commentId); @DELETE @Path("/{CommentId}") @@ -286,11 +286,11 @@ public interface CommentManagementAPI { Response deleteComment( @ApiParam( - name="CommentId", + name="commentId", value="Id of the comment.", required = true) - @PathParam("CommentId") - int apAppCommentId); + @PathParam("commentId") + int commentId); @GET @Path("/{uuid}/{stars}") diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java index f6d93cd9b1..12d0b5ff70 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java @@ -110,49 +110,49 @@ public class CommentManagementAPIImpl implements CommentManagementAPI { @Override @PUT @Consumes("application/json") - @Path("/{CommentId}") + @Path("/{commentId}") public Response updateComment( @ApiParam Comment comment, - @PathParam("CommentId") int CommentId) { + @PathParam("commentId") int commentId) { CommentsManager commentsManager = APIUtil.getCommentsManager(); try { - if (CommentId == 0) { + if (commentId == 0) { 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) { String msg = "Given comment is not valid "; log.error(msg); return Response.status(Response.Status.BAD_REQUEST).build(); } else { - comment = commentsManager.updateComment(comment, CommentId); + comment = commentsManager.updateComment(comment, commentId); return Response.status(Response.Status.OK).entity(comment).build(); } } catch (CommentManagementException e) { String msg = "Error occurred while retrieving comments."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR) - .entity("Comment with Comment Id" + CommentId + " Internal server error occurs").build(); + .entity("Comment with Comment Id" + commentId + " Internal server error occurs").build(); } } @Override @DELETE - @Path("/{CommentId}") + @Path("/{commentId}") public Response deleteComment( - @PathParam("CommentId") int CommentId) { + @PathParam("commentId") int commentId) { CommentsManager commentsManager = APIUtil.getCommentsManager(); try { - commentsManager.deleteComment(CommentId); + commentsManager.deleteComment(commentId); } catch (CommentManagementException e) { String msg = "Error occurred while deleting the comment."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR) - .entity("Comment with Comment Id" + CommentId + " Internal server error occurs").build(); + .entity("Comment with Comment Id" + commentId + " Internal server error occurs").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(); } @@ -219,7 +219,6 @@ public class CommentManagementAPIImpl implements CommentManagementAPI { log.error(msg); return Response.status(Response.Status.BAD_REQUEST).build(); } - } catch (ApplicationManagementException e) { log.error("Application Management Exception occurs", e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java index e297f03fd4..ab2b2b59d9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java @@ -65,29 +65,29 @@ public interface CommentsManager { /** * To get the comment with id. * - * @param CommentId id of the comment + * @param commentId id of the comment * @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. * - * @param CommentId id of the comment + * @param commentId id of the comment * @throws CommentManagementException Exceptions of the comment management */ - void deleteComment(int CommentId) throws CommentManagementException; + void deleteComment(int commentId) throws CommentManagementException; /** * To update a comment. * * @param comment comment of the application. - * @param CommentId id of the comment + * @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 diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java index f0ca66e0c9..4ef62e3e8c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java @@ -32,7 +32,7 @@ import java.util.List; * This interface specifies the database access operations performed for comments. */ -@SuppressWarnings("ALL") public interface CommentDAO { + public interface CommentDAO { /** * To add a comment to a application. @@ -66,7 +66,7 @@ import java.util.List; /** * 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. @@ -75,14 +75,14 @@ import java.util.List; * @throws DBConnectionException db connection exception * @throws SQLException sql exception */ - Comment updateComment(int CommentId, String updatedComment, String modifiedBy, Timestamp modifiedAt) + 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 commentId id of the comment * @param updatedComment comment after updated * @param modifiedBy Username of the modified person. * @param modifiedAt time of the modification. @@ -91,19 +91,19 @@ import java.util.List; * @throws DBConnectionException db connection exception * @throws SQLException sql exception */ - Comment updateComment(String uuid, int CommentId, String updatedComment, String modifiedBy, Timestamp modifiedAt) + Comment updateComment(String uuid, int commentId, String updatedComment, String modifiedBy, Timestamp modifiedAt) throws CommentManagementException, DBConnectionException, SQLException; /** * To get the comment with id. * - * @param CommentId id of the comment + * @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 */ - Comment getComment(int CommentId) throws CommentManagementException, SQLException, DBConnectionException; + Comment getComment(int commentId) throws CommentManagementException, SQLException, DBConnectionException; /** * To get the comment with id. @@ -307,12 +307,12 @@ import java.util.List; /** * To delete comment using comment id. * - * @param CommentId id of the comment + * @param commentId id of the comment * @throws CommentManagementException Exceptions of the comment management. * @throws DBConnectionException db connection exception. * @throws SQLException sql exception */ - void deleteComment(int CommentId) throws CommentManagementException, DBConnectionException, SQLException; + void deleteComment(int commentId) throws CommentManagementException, DBConnectionException, SQLException; /** * To delete comment using comment id. diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java index 6edbd0218a..2bad38a904 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java @@ -116,11 +116,11 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { } @Override - public Comment updateComment(int CommentId, String updatedComment, String modifiedBy, + public Comment updateComment(int commentId, String updatedComment, String modifiedBy, Timestamp modifiedAt) throws CommentManagementException, DBConnectionException, SQLException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to update the comment with ID (" + CommentId + ")"); + log.debug("Request received in DAO Layer to update the comment with ID (" + commentId + ")"); } Connection connection; PreparedStatement statement = null; @@ -131,22 +131,22 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { statement = connection.prepareStatement(sql); statement.setString(1, updatedComment); statement.setString(2, modifiedBy); - statement.setInt(3, CommentId); + statement.setInt(3, commentId); statement.executeUpdate(); rs = statement.executeQuery(); } finally { Util.cleanupResources(statement, rs); } - return getComment(CommentId); + return getComment(commentId); } @Override - public Comment updateComment(String uuid, int CommentId, String updatedComment, String modifiedBy, + public Comment updateComment(String uuid, int commentId, String updatedComment, String modifiedBy, Timestamp modifiedAt) throws CommentManagementException, DBConnectionException, SQLException { if (log.isDebugEnabled()) { log.debug("Request received in DAO Layer to update the comment with application (" + uuid + ") and " - + "comment id ( " + CommentId + ")"); + + "comment id ( " + commentId + ")"); } Connection connection; PreparedStatement statement = null; @@ -157,20 +157,20 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { statement = connection.prepareStatement(sql); statement.setString(1, updatedComment); statement.setString(2, modifiedBy); - statement.setInt(3, CommentId); + statement.setInt(3, commentId); statement.executeUpdate(); rs = statement.getResultSet(); } finally { Util.cleanupResources(statement, rs); } - return getComment(CommentId); + return getComment(commentId); } @Override - public Comment getComment(int CommentId) throws CommentManagementException { + public Comment getComment(int commentId) throws CommentManagementException { if (log.isDebugEnabled()) { - log.debug("Getting comment with the comment id(" + CommentId + ") from the database"); + log.debug("Getting comment with the comment id(" + commentId + ") from the database"); } Connection conn; PreparedStatement stmt = null; @@ -181,7 +181,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { conn = this.getDBConnection(); sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE ID=?;"; stmt = conn.prepareStatement(sql); - stmt.setInt(1, CommentId); + stmt.setInt(1, commentId); rs = stmt.executeQuery(); if (rs.next()) { comment.setId(rs.getInt("ID")); @@ -197,9 +197,9 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { } } catch (SQLException e) { throw new CommentManagementException( - "SQL Error occurred while retrieving information of the comment " + CommentId, e); + "SQL Error occurred while retrieving information of the comment " + commentId, e); } catch (DBConnectionException e) { - log.error("DB Connection Exception occurred while retrieving information of the comment " + CommentId, e); + log.error("DB Connection Exception occurred while retrieving information of the comment " + commentId, e); } finally { Util.cleanupResources(stmt, null); } @@ -781,7 +781,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { } @Override - public void deleteComment(int CommentId) throws CommentManagementException, DBConnectionException, + public void deleteComment(int commentId) throws CommentManagementException, DBConnectionException, SQLException { Connection conn; @@ -790,7 +790,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { conn = this.getDBConnection(); String sql = "DELETE FROM AP_APP_COMMENT WHERE ID=?;"; stmt = conn.prepareStatement(sql); - stmt.setInt(1, CommentId); + stmt.setInt(1, commentId); stmt.executeUpdate(); } finally { Util.cleanupResources(stmt, null); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java index 7f52998e1a..ad01b692e4 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java @@ -62,7 +62,6 @@ public class CommentsManagerImpl implements CommentsManager { 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); @@ -114,11 +113,9 @@ public class CommentsManagerImpl implements CommentsManager { PaginationResult paginationResult = new PaginationResult(); List comments; request = Util.validateCommentListPageSize(request); - if (log.isDebugEnabled()) { log.debug("get all comments of the application release" + uuid); } - try { ConnectionManagerUtil.openDBConnection(); comments = commentDAO.getAllComments(uuid, request); @@ -140,24 +137,22 @@ public class CommentsManagerImpl implements CommentsManager { } @Override - public Comment getComment(int CommentId) throws CommentManagementException { + public Comment getComment(int commentId) throws CommentManagementException { PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); Comment comment = null; - 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); } - try { ConnectionManagerUtil.openDBConnection(); - comment = commentDAO.getComment(CommentId); + comment = commentDAO.getComment(commentId); } catch (DBConnectionException e) { throw new CommentManagementException( - "DB Connection error occurs ,Comment with comment id " + CommentId + "cannot get.", e); + "DB Connection error occurs ,Comment with comment id " + commentId + "cannot get.", e); } catch (SQLException e) { throw new CommentManagementException( - "SQL Exception occurs,Comment with comment id " + CommentId + "cannot get.", e); + "SQL Exception occurs,Comment with comment id " + commentId + "cannot get.", e); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -165,54 +160,52 @@ public class CommentsManagerImpl implements CommentsManager { } @Override - public void deleteComment(int CommentId) throws CommentManagementException { + 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(); - commentDAO.deleteComment(CommentId); + commentDAO.deleteComment(commentId); ConnectionManagerUtil.commitDBTransaction(); } catch (DBConnectionException e) { throw new CommentManagementException( - "DB Connection error occurs deleting comment with comment id " + CommentId + ".", e); + "DB Connection error occurs deleting comment with comment id " + commentId + ".", e); } catch (SQLException e) { - throw new CommentManagementException("SQL error occurs deleting comment with comment id " + CommentId + ".", + throw new CommentManagementException("SQL error occurs deleting comment with comment id " + commentId + ".", e); } catch (TransactionManagementException e) { throw new CommentManagementException( - "Transaction Management Exception occurs deleting comment with comment id " + CommentId + ".", e); + "Transaction Management Exception occurs deleting comment with comment id " + commentId + ".", e); } finally { ConnectionManagerUtil.closeDBConnection(); } } @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); + log.debug("Comment retrieval request is received for the comment id " + commentId); } comment.setModifiedAt(Timestamp.from(Instant.now())); try { ConnectionManagerUtil.openDBConnection(); - commentDAO.getComment(CommentId); + commentDAO.getComment(commentId); return commentDAO - .updateComment(CommentId, comment.getComment(), comment.getModifiedBy(), comment.getModifiedAt()); + .updateComment(commentId, comment.getComment(), comment.getModifiedBy(), comment.getModifiedAt()); } catch (SQLException e) { - throw new CommentManagementException("SQL Error occurs updating comment with comment id " + CommentId + ".", + throw new CommentManagementException("SQL Error occurs updating comment with comment id " + commentId + ".", e); } catch (DBConnectionException e) { throw new CommentManagementException( - "DB Connection error occurs updating comment with comment id " + CommentId + ".", e); + "DB Connection error occurs updating comment with comment id " + commentId + ".", e); } finally { ConnectionManagerUtil.closeDBConnection(); } From 27d3862ac8fa962c835097aed7dbfbf79147ded4 Mon Sep 17 00:00:00 2001 From: nishadi Date: Thu, 18 Jan 2018 14:42:40 +0530 Subject: [PATCH 50/56] CommentId changed into commentId --- .../application/mgt/api/services/CommentManagementAPI.java | 1 + 1 file changed, 1 insertion(+) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java index e52f0416fb..87a391758a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/CommentManagementAPI.java @@ -49,6 +49,7 @@ import java.util.List; /** * APIs to handle comment management related tasks. */ + @SwaggerDefinition( info = @Info( version = "1.0.0", From 7242c63e60fb865cbf7842582329bf28434a7ef4 Mon Sep 17 00:00:00 2001 From: nishadi Date: Thu, 18 Jan 2018 14:54:15 +0530 Subject: [PATCH 51/56] CommentId changed into commentId --- .../application/mgt/common/services/CommentsManager.java | 4 ++-- .../device/application/mgt/core/dao/CommentDAO.java | 4 ++-- .../application/mgt/core/impl/CommentsManagerImpl.java | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java index ab2b2b59d9..6428f11ceb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/CommentsManager.java @@ -45,12 +45,12 @@ public interface CommentsManager { /** * To validate the pre-request of the comment * - * @param CommentId ID of the comment. + * @param commentId ID of the comment. * @param comment comment needed to be validate. * @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 diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java index 4ef62e3e8c..90e3600744 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/CommentDAO.java @@ -206,8 +206,8 @@ import java.util.List; * * @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. + * @return {@link List}List of comments + * @throws CommentManagementException Exceptions of the comment management. * @throws DBConnectionException db connection exception. * @throws SQLException sql exception */ diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java index ad01b692e4..0b75c69f66 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java @@ -86,21 +86,21 @@ public class CommentsManagerImpl implements CommentsManager { /** * To validate the pre-request of the comment * - * @param CommentId ID of the comment. + * @param commentId ID of the comment. * @param comment comment needed to be validate. * @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) { + if (commentId <= 0) { 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("Comment can not be null, but Comment at comment id " + CommentId + " is null."); + log.error("Comment can not be null, but Comment at comment id " + commentId + " is null."); return false; } return true; From eced883e7feca0d7aa977ddd55ecd02248a80516 Mon Sep 17 00:00:00 2001 From: nishadi Date: Thu, 18 Jan 2018 15:54:34 +0530 Subject: [PATCH 52/56] Error response message changed. --- .../impl/CommentManagementAPIImpl.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java index 12d0b5ff70..66d115bbcb 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java @@ -75,7 +75,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI { String msg = "Error occurred while retrieving comments."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR) - .entity("Application with UUID" + uuid + " Internal server error occurs").build(); + .entity(" Internal server error occurs").build(); } return Response.status(Response.Status.OK).entity(comments).build(); } @@ -103,7 +103,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI { String msg = "Error occurred while creating the comment"; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR) - .entity("Application with UUID" + uuid + " Internal server error occurs").build(); + .entity("Internal server error occurs").build(); } } @@ -119,7 +119,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI { try { if (commentId == 0) { return Response.status(Response.Status.NOT_FOUND) - .entity("Comment with comment id " + commentId + " not found").build(); + .entity("Comment not found").build(); } else if (comment == null) { String msg = "Given comment is not valid "; log.error(msg); @@ -132,7 +132,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI { String msg = "Error occurred while retrieving comments."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR) - .entity("Comment with Comment Id" + commentId + " Internal server error occurs").build(); + .entity(" Internal server error occurs").build(); } } @@ -149,10 +149,10 @@ public class CommentManagementAPIImpl implements CommentManagementAPI { String msg = "Error occurred while deleting the comment."; log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR) - .entity("Comment with Comment Id" + commentId + " Internal server error occurs").build(); + .entity("Internal server error occurs").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(); + return Response.status(Response.Status.NOT_FOUND).entity("Comment not found").build(); } return Response.status(Response.Status.OK).entity("Comment is deleted successfully.").build(); } @@ -173,7 +173,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI { } catch (ApplicationManagementException e) { log.error("Application Management Exception occurs", e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR) - .entity("Application with UUID" + uuid + " Internal server error occurs").build(); + .entity("Internal server error occurs").build(); } return Response.status(Response.Status.OK).entity(Stars).build(); } @@ -191,7 +191,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI { } catch (CommentManagementException e) { log.error("Comment Management Exception occurs", e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR) - .entity("Application with UUID" + uuid + " Internal server error occurs").build(); + .entity("Internal server error occurs").build(); } catch (ApplicationManagementException e) { log.error("Application Management Exception occurs", e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR) @@ -222,7 +222,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI { } catch (ApplicationManagementException e) { log.error("Application Management Exception occurs", e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR) - .entity("Application with UUID" + uuid + " Internal server error occurs").build(); + .entity(" Internal server error occurs").build(); } } } \ No newline at end of file From 8f8ec9a86a1e735eb53a184b4878980009102ab9 Mon Sep 17 00:00:00 2001 From: nishadi Date: Thu, 18 Jan 2018 15:56:38 +0530 Subject: [PATCH 53/56] parameter in the consumes annotation changed to application/json --- .../mgt/api/services/impl/CommentManagementAPIImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java index 66d115bbcb..be1a7cfe85 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.api/src/main/java/org/wso2/carbon/device/application/mgt/api/services/impl/CommentManagementAPIImpl.java @@ -202,7 +202,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI { @Override @POST - @Consumes("uuid/stars/json") + @Consumes("application/json") public Response updateStars( @ApiParam int stars, @PathParam("uuid") String uuid) { From 40771cbfcd5fb5750260070e5b28c6a41e6893ae Mon Sep 17 00:00:00 2001 From: nishadi Date: Thu, 18 Jan 2018 16:21:18 +0530 Subject: [PATCH 54/56] Modified CommentDAOImpl String sql change int constant. --- .../core/dao/impl/Comment/CommentDAOImpl.java | 489 +++++++++--------- 1 file changed, 237 insertions(+), 252 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java index 2bad38a904..63a76921b4 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java @@ -30,6 +30,7 @@ import org.wso2.carbon.device.application.mgt.core.dao.CommentDAO; import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; + import java.sql.SQLException; import java.sql.Timestamp; import java.sql.ResultSet; @@ -45,6 +46,7 @@ import java.util.List; public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { private static final Log log = LogFactory.getLog(CommentDAOImpl.class); + String sql = ""; @Override public int addComment(int tenantId, Comment comment, String createdBy, int parentId, String uuid) @@ -54,28 +56,28 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { log.debug("Request received in DAO Layer to add comment for application release (" + uuid + ")"); } Connection conn = this.getDBConnection(); - PreparedStatement stmt = null; + PreparedStatement statement = null; ResultSet rs = null; int commentId = -1; - String sql = "INSERT INTO AP_APP_COMMENT (TENANT_ID, COMMENT_TEXT, CREATED_BY, PARENT_ID,AP_APP_RELEASE_ID," + sql += "INSERT INTO AP_APP_COMMENT (TENANT_ID, COMMENT_TEXT, CREATED_BY, PARENT_ID,AP_APP_RELEASE_ID," + "AP_APP_ID) VALUES (?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?)," + "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));"; try { - stmt = conn.prepareStatement(sql, new String[] { "id" }); - stmt.setInt(1, tenantId); - stmt.setString(2, comment.getComment()); - stmt.setString(3, createdBy); - stmt.setInt(4, parentId); - stmt.setString(5, uuid); - stmt.setString(6, uuid); - stmt.executeUpdate(); - rs = stmt.getGeneratedKeys(); + statement = conn.prepareStatement(sql, new String[] { "id" }); + statement.setInt(1, tenantId); + statement.setString(2, comment.getComment()); + statement.setString(3, createdBy); + statement.setInt(4, parentId); + statement.setString(5, uuid); + statement.setString(6, uuid); + statement.executeUpdate(); + rs = statement.getGeneratedKeys(); if (rs.next()) { commentId = rs.getInt(1); } return commentId; } finally { - Util.cleanupResources(stmt, rs); + Util.cleanupResources(statement, rs); } } @@ -88,29 +90,29 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { + ")"); } Connection conn = this.getDBConnection(); - PreparedStatement stmt = null; + PreparedStatement statement = null; ResultSet rs; int commentId = -1; - String sql = "INSERT INTO AP_APP_COMMENT ( TENANT_ID,COMMENT_TEXT, CREATED_BY,AP_APP_RELEASE_ID,AP_APP_ID) " + sql += "INSERT INTO AP_APP_COMMENT ( TENANT_ID,COMMENT_TEXT, CREATED_BY,AP_APP_RELEASE_ID,AP_APP_ID) " + "VALUES (?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE VERSION =? AND (SELECT ID FROM AP_APP WHERE " + "TYPE=? AND NAME=?)),(SELECT ID FROM AP_APP WHERE TYPE=? AND NAME=?));"; try { - stmt = conn.prepareStatement(sql, new String[] { "id" }); - stmt.setInt(1, tenantId); - stmt.setString(2, comment.getComment()); - stmt.setString(3, createdBy); - stmt.setString(4, version); - stmt.setString(5, appType); - stmt.setString(6, appName); - stmt.setString(7, appType); - stmt.setString(8, appName); - stmt.executeUpdate(); - rs = stmt.getGeneratedKeys(); + statement = conn.prepareStatement(sql, new String[] { "id" }); + statement.setInt(1, tenantId); + statement.setString(2, comment.getComment()); + statement.setString(3, createdBy); + statement.setString(4, version); + statement.setString(5, appType); + statement.setString(6, appName); + statement.setString(7, appType); + statement.setString(8, appName); + statement.executeUpdate(); + rs = statement.getGeneratedKeys(); if (rs.next()) { commentId = rs.getInt(1); } } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } return commentId; } @@ -125,7 +127,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Connection connection; PreparedStatement statement = null; ResultSet rs = null; - String sql = "UPDATE AP_APP_COMMENT SET COMMENT_TEXT=?, MODEFIED_BY=? WHERE ID=?;"; + sql += "UPDATE AP_APP_COMMENT SET COMMENT_TEXT=?, MODEFIED_BY=? WHERE ID=?;"; try { connection = this.getDBConnection(); statement = connection.prepareStatement(sql); @@ -151,7 +153,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Connection connection; PreparedStatement statement = null; ResultSet rs = null; - String sql = "UPDATE AP_APP_COMMENT SET COMMENT_TEXT=?,MODEFIED_BY=? WHERE ID=?; "; + sql += "UPDATE AP_APP_COMMENT SET COMMENT_TEXT=?,MODEFIED_BY=? WHERE ID=?; "; try { connection = this.getDBConnection(); statement = connection.prepareStatement(sql); @@ -173,16 +175,15 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { log.debug("Getting comment with the comment id(" + commentId + ") from the database"); } Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; ResultSet rs; - String sql = ""; Comment comment = new Comment(); try { conn = this.getDBConnection(); sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE ID=?;"; - stmt = conn.prepareStatement(sql); - stmt.setInt(1, commentId); - rs = stmt.executeQuery(); + statement = conn.prepareStatement(sql); + statement.setInt(1, commentId); + rs = statement.executeQuery(); if (rs.next()) { comment.setId(rs.getInt("ID")); comment.setTenantId(rs.getInt("TENANT_ID")); @@ -192,7 +193,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comment.setModifiedAt(rs.getTimestamp("MODEFIED_AT")); comment.setModifiedBy(rs.getString("MODEFIED_AT")); comment.setParent(rs.getInt("PARENT_ID")); - Util.cleanupResources(stmt, rs); + Util.cleanupResources(statement, rs); return comment; } } catch (SQLException e) { @@ -201,30 +202,29 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { } catch (DBConnectionException e) { log.error("DB Connection Exception occurred while retrieving information of the comment " + commentId, e); } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } return comment; } @Override - public List getComment(String uuid) throws CommentManagementException{ + public List getComment(String uuid) throws CommentManagementException { if (log.isDebugEnabled()) { log.debug("Getting comment with the application release(" + uuid + ") from the database"); } Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; ResultSet rs; - String sql = ""; List comments = new ArrayList<>(); try { conn = this.getDBConnection(); sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE (SELECT ID FROM AP_APP_RELEASE where UUID=?)AND " + "(SELECT AP_APP_ID FROM AP_APP_RELEASE where UUID=?);"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, uuid); - stmt.setString(2, uuid); - rs = stmt.executeQuery(); + statement = conn.prepareStatement(sql); + statement.setString(1, uuid); + statement.setString(2, uuid); + rs = statement.executeQuery(); while (rs.next()) { Comment comment = new Comment(); comment.setId(rs.getInt("ID")); @@ -242,7 +242,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { } catch (SQLException e) { throw new CommentManagementException("SQL Error occurred while retrieving comments", e); } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } return comments; } @@ -255,19 +255,18 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { log.debug("Getting comment of the application release (" + uuid + ") from the database"); } Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; ResultSet rs = null; List comments = new ArrayList<>(); - String sql = ""; try { conn = this.getDBConnection(); sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT, AP_APP_RELEASE WHERE AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID " + "AND AP_APP_RELEASE.UUID =? LIMIT ? OFFSET ?;"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, uuid); - stmt.setInt(2, request.getLimit()); - stmt.setInt(3, request.getOffSet()); - rs = stmt.executeQuery(); + statement = conn.prepareStatement(sql); + statement.setString(1, uuid); + statement.setInt(2, request.getLimit()); + statement.setInt(3, request.getOffSet()); + rs = statement.executeQuery(); while (rs.next()) { Comment comment = new Comment(); comment.setId(rs.getInt("ID")); @@ -281,7 +280,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comments.add(comment); } } finally { - Util.cleanupResources(stmt, rs); + Util.cleanupResources(statement, rs); } return comments; } @@ -291,7 +290,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { int commentCount = 0; Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; ResultSet rs = null; boolean isUuidProvided = false; try { @@ -300,12 +299,12 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { isUuidProvided = true; } if (isUuidProvided) { - String sql = "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE " + sql += "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE " + "WHERE AP_APP_COMMENT.AP_APP_RELEASE_ID= AP_APP_RELEASE.ID AND " + "AP_APP_COMMENT.AP_APP_ID= AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, uuid); - rs = stmt.executeQuery(); + statement = conn.prepareStatement(sql); + statement.setString(1, uuid); + rs = statement.executeQuery(); if (rs.next()) { commentCount = rs.getInt("COMMENTS_COUNT"); } @@ -315,7 +314,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { } catch (DBConnectionException e) { log.error("DB Connection Exception occurred while retrieving count of comments", e); } finally { - Util.cleanupResources(stmt, rs); + Util.cleanupResources(statement, rs); } return commentCount; } @@ -328,17 +327,16 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { + appId + ") from the database"); } Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; ResultSet rs; - String sql = ""; List comments = new ArrayList<>(); try { conn = this.getDBConnection(); sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? AND AP_APP_ID=?;"; - stmt = conn.prepareStatement(sql); - stmt.setInt(1, appReleasedId); - stmt.setInt(2, appId); - rs = stmt.executeQuery(); + statement = conn.prepareStatement(sql); + statement.setInt(1, appReleasedId); + statement.setInt(2, appId); + rs = statement.executeQuery(); while (rs.next()) { Comment comment = new Comment(); comment.setId(rs.getInt("ID")); @@ -356,23 +354,22 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { } catch (SQLException e) { throw new CommentManagementException("SQL Error occurred while retrieving information of comments", e); } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } return comments; } @Override - public List getComments(String appType, String appName, String version) throws CommentManagementException, - DBConnectionException, SQLException { + public List getComments(String appType, String appName, String version) + throws CommentManagementException, DBConnectionException, SQLException { if (log.isDebugEnabled()) { log.debug("Getting comments with the application name(" + appName + "),application type(" + appType + ") " + "and application version (" + version + ") from the database"); } Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; ResultSet rs; - String sql = ""; List comments = new ArrayList<>(); try { conn = this.getDBConnection(); @@ -381,11 +378,11 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { + "(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? AND TYPE=?)P" + " WHERE AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND AP_APP_ID=RELEASE_AP_APP_ID" + "ORDER BY CREATED_AT DESC;"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, version); - stmt.setString(2, appName); - stmt.setString(3, appType); - rs = stmt.executeQuery(); + statement = conn.prepareStatement(sql); + statement.setString(1, version); + statement.setString(2, appName); + statement.setString(3, appType); + rs = statement.executeQuery(); while (rs.next()) { Comment comment = new Comment(); comment.setId(rs.getInt("ID")); @@ -399,29 +396,28 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comments.add(comment); } } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } return comments; } @Override - public List getComments(int tenantId) throws CommentManagementException, DBConnectionException, - SQLException { + public List getComments(int tenantId) + throws CommentManagementException, DBConnectionException, SQLException { if (log.isDebugEnabled()) { log.debug("Getting comments with the tenant_id(" + tenantId + ") from the database"); } Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; ResultSet rs; - String sql = ""; List comments = new ArrayList<>(); try { conn = this.getDBConnection(); sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE TENANT_ID='?';"; - stmt = conn.prepareStatement(sql); - stmt.setInt(1, tenantId); - rs = stmt.executeQuery(); + statement = conn.prepareStatement(sql); + statement.setInt(1, tenantId); + rs = statement.executeQuery(); while (rs.next()) { Comment comment = new Comment(); comment.setId(rs.getInt("ID")); @@ -435,30 +431,29 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comments.add(comment); } } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } return comments; } @Override - public List getCommentsByUser(String createdBy) throws CommentManagementException, DBConnectionException, - SQLException { + public List getCommentsByUser(String createdBy) + throws CommentManagementException, DBConnectionException, SQLException { if (log.isDebugEnabled()) { log.debug("Getting comments with the created by(" + createdBy + ") from the database"); } Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; ResultSet rs; - String sql = ""; List comments = new ArrayList<>(); try { conn = this.getDBConnection(); sql += "SELECT COMMENT_TEXT ,PARENT_ID,TENANT_ID,CREATED_AT FROM AP_APP_COMMENT WHERE CREATED_BY= ?" + " ORDER BY CREATED_AT DESC;"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, createdBy); - rs = stmt.executeQuery(); + statement = conn.prepareStatement(sql); + statement.setString(1, createdBy); + rs = statement.executeQuery(); while (rs.next()) { Comment comment = new Comment(); comment.setId(rs.getInt("ID")); @@ -472,32 +467,31 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comments.add(comment); } } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } return comments; } @Override - public List getCommentsByUser(String createdBy, Timestamp createdAt) throws CommentManagementException, - DBConnectionException, SQLException { + public List getCommentsByUser(String createdBy, Timestamp createdAt) + throws CommentManagementException, DBConnectionException, SQLException { if (log.isDebugEnabled()) { log.debug( "Getting comments with the created by(" + createdBy + ") at (" + createdAt + ") from the database"); } Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; ResultSet rs; - String sql = ""; List comments = new ArrayList<>(); try { conn = this.getDBConnection(); sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID FROM AP_APP_COMMENT WHERE CREATED_BY=?" + "AND CREATED_AT= ? ORDER BY CREATED_AT DESC;"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, createdBy); - stmt.setTimestamp(2, createdAt); - rs = stmt.executeQuery(); + statement = conn.prepareStatement(sql); + statement.setString(1, createdBy); + statement.setTimestamp(2, createdAt); + rs = statement.executeQuery(); while (rs.next()) { Comment comment = new Comment(); comment.setId(rs.getInt("ID")); @@ -511,30 +505,29 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comments.add(comment); } } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } return comments; } @Override - public List getCommentsByModifiedUser(String modifiedBy) throws CommentManagementException, - DBConnectionException, SQLException { + public List getCommentsByModifiedUser(String modifiedBy) + throws CommentManagementException, DBConnectionException, SQLException { if (log.isDebugEnabled()) { log.debug("Getting comments with the modified by(" + modifiedBy + ") from the database"); } Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; ResultSet rs; - String sql = ""; List comments = new ArrayList<>(); try { conn = this.getDBConnection(); sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID,CREATED_AT,MODEFIED_AT FROM AP_APP_COMMENT " + "WHERE MODEFIED_BY= ? ORDER BY CREATED_AT DESC;"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, modifiedBy); - rs = stmt.executeQuery(); + statement = conn.prepareStatement(sql); + statement.setString(1, modifiedBy); + rs = statement.executeQuery(); while (rs.next()) { Comment comment = new Comment(); comment.setId(rs.getInt("ID")); @@ -548,7 +541,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comments.add(comment); } } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } return comments; } @@ -562,18 +555,17 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { + "database"); } Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; ResultSet rs; - String sql = ""; List comments = new ArrayList<>(); try { conn = this.getDBConnection(); sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID,CREATED_AT FROM AP_APP_COMMENT WHERE MODEFIED_BY= ?," + "MODEFIED_AT=? ORDER BY CREATED_AT DESC;"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, modifiedBy); - stmt.setTimestamp(2, modifiedAt); - rs = stmt.executeQuery(); + statement = conn.prepareStatement(sql); + statement.setString(1, modifiedBy); + statement.setTimestamp(2, modifiedAt); + rs = statement.executeQuery(); while (rs.next()) { Comment comment = new Comment(); comment.setId(rs.getInt("ID")); @@ -587,7 +579,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comments.add(comment); } } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } return comments; } @@ -602,9 +594,8 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { + "application version (" + version + ") from the database"); } Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; ResultSet rs; - String sql = ""; List comments = new ArrayList<>(); try { conn = this.getDBConnection(); @@ -613,12 +604,12 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { + "R,(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? AND TYPE=?)P " + "WHERE PARENT_ID=? AND AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND " + "AP_APP_ID=RELEASE_AP_APP_ID ORDER BY CREATED_AT DESC;"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, version); - stmt.setString(2, appName); - stmt.setString(3, appType); - stmt.setInt(4, parentId); - rs = stmt.executeQuery(); + statement = conn.prepareStatement(sql); + statement.setString(1, version); + statement.setString(2, appName); + statement.setString(3, appType); + statement.setInt(4, parentId); + rs = statement.executeQuery(); while (rs.next()) { Comment comment = new Comment(); comment.setId(rs.getInt("ID")); @@ -632,231 +623,233 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { comments.add(comment); } } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } return comments; } @Override - public int getCommentCount(String uuid) throws CommentManagementException, DBConnectionException, - SQLException { + public int getCommentCount(String uuid) + throws CommentManagementException, DBConnectionException, SQLException { Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; int commentCount = 0; try { conn = this.getDBConnection(); - String sql = "\n" + "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE WHERE " + sql += "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE WHERE " + "AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_COMMENT.AP_APP_ID=" + "AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, uuid); - ResultSet rs = stmt.executeQuery(); + statement = conn.prepareStatement(sql); + statement.setString(1, uuid); + ResultSet rs = statement.executeQuery(); if (rs.next()) { commentCount = rs.getInt("ID"); } } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); return commentCount; } } @Override - public int getCommentCountByUser(String createdBy) throws CommentManagementException, DBConnectionException, - SQLException { + public int getCommentCountByUser(String createdBy) + throws CommentManagementException, DBConnectionException, SQLException { Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; int commentCount = 0; try { conn = this.getDBConnection(); - String sql = "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE CREATED_BY= ?;"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, createdBy); - ResultSet rs = stmt.executeQuery(); + sql += "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE CREATED_BY= ?;"; + statement = conn.prepareStatement(sql); + statement.setString(1, createdBy); + ResultSet rs = statement.executeQuery(); if (rs.next()) { commentCount = rs.getInt("COMMENT_COUNT"); } } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } return commentCount; } @Override - public int getCommentCountByUser(String modifiedBy, Timestamp modifedAt) throws CommentManagementException, - DBConnectionException, SQLException { + public int getCommentCountByUser(String modifiedBy, Timestamp modifedAt) + throws CommentManagementException, DBConnectionException, SQLException { Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; int commentCount = 0; try { conn = this.getDBConnection(); - String sql = "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE MODEFIED_BY= ? AND MODEFIED_AT=?;"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, modifiedBy); - stmt.setTimestamp(2, modifedAt); - ResultSet rs = stmt.executeQuery(); + sql += "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE MODEFIED_BY= ? AND MODEFIED_AT=?;"; + statement = conn.prepareStatement(sql); + statement.setString(1, modifiedBy); + statement.setTimestamp(2, modifedAt); + ResultSet rs = statement.executeQuery(); if (rs.next()) { commentCount = rs.getInt("COMMENT_COUNT"); } } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } return commentCount; } @Override - public int getCommentCountByApp(int appId, int appReleaseId) throws CommentManagementException, - DBConnectionException, SQLException { + public int getCommentCountByApp(int appId, int appReleaseId) + throws CommentManagementException, DBConnectionException, SQLException { Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; int commentCount = 0; try { conn = this.getDBConnection(); - String sql = "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? AND AP_APP_ID=?;"; - stmt = conn.prepareStatement(sql); - stmt.setInt(1, appReleaseId); - stmt.setInt(2, appId); - ResultSet rs = stmt.executeQuery(); + sql += "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? AND AP_APP_ID=?;"; + statement = conn.prepareStatement(sql); + statement.setInt(1, appReleaseId); + statement.setInt(2, appId); + ResultSet rs = statement.executeQuery(); if (rs.next()) { commentCount = rs.getInt("COMMENT_COUNT"); } } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } return commentCount; } @Override - public int getCommentCountByApp(String appType, String appName, String version) throws CommentManagementException, - DBConnectionException, SQLException { + public int getCommentCountByApp(String appType, String appName, String version) + throws CommentManagementException, DBConnectionException, SQLException { Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; int commentCount = 0; try { conn = this.getDBConnection(); - String sql = "SELECT COUNT(ID) AS COMMENT_COUNT FROM AP_APP_COMMENT C, " + sql += "SELECT COUNT(ID) AS COMMENT_COUNT FROM AP_APP_COMMENT C, " + "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=? )R," + "(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? and TYPE=?)P " + "WHERE AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND AP_APP_ID=RELEASE_AP_APP_ID;"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, version); - stmt.setString(2, appName); - stmt.setString(3, appType); - ResultSet rs = stmt.executeQuery(); + statement = conn.prepareStatement(sql); + statement.setString(1, version); + statement.setString(2, appName); + statement.setString(3, appType); + ResultSet rs = statement.executeQuery(); if (rs.next()) { commentCount = rs.getInt("COMMENT_COUNT"); } } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } return commentCount; } - public int getCommentCountByParent(String uuid,int parentId) throws CommentManagementException, DBConnectionException, SQLException { + public int getCommentCountByParent(String uuid, int parentId) + throws CommentManagementException, DBConnectionException, SQLException { Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; int commentCount = 0; try { conn = this.getDBConnection(); - String sql = "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE WHERE " + sql += "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE WHERE " + "AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND " + "AP_APP_COMMENT.AP_APP_ID=AP_APP_RELEASE.AP_APP_ID and AP_APP_RELEASE.UUID=? and PARENT_ID=?;"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, uuid); - stmt.setInt(2, parentId); - ResultSet rs = stmt.executeQuery(); + statement = conn.prepareStatement(sql); + statement.setString(1, uuid); + statement.setInt(2, parentId); + ResultSet rs = statement.executeQuery(); if (rs.next()) { commentCount = rs.getInt("COMMENT_COUNT"); } } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } return commentCount; } @Override - public void deleteComment(int commentId) throws CommentManagementException, DBConnectionException, - SQLException { + public void deleteComment(int commentId) + throws CommentManagementException, DBConnectionException, SQLException { Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; try { conn = this.getDBConnection(); - String sql = "DELETE FROM AP_APP_COMMENT WHERE ID=?;"; - stmt = conn.prepareStatement(sql); - stmt.setInt(1, commentId); - stmt.executeUpdate(); + sql += "DELETE FROM AP_APP_COMMENT WHERE ID=?;"; + statement = conn.prepareStatement(sql); + statement.setInt(1, commentId); + statement.executeUpdate(); } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } } public void deleteComment(String uuid) throws CommentManagementException, DBConnectionException, SQLException { Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; try { conn = this.getDBConnection(); - String sql = "DELETE FROM AP_APP_COMMENT WHERE " + sql += "DELETE FROM AP_APP_COMMENT WHERE " + "(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?)AND (SELECT AP_APP_ID FROM AP_APP_RELEASE " + "WHERE UUID=?);"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, uuid); - stmt.setString(2, uuid); - stmt.executeUpdate(); + statement = conn.prepareStatement(sql); + statement.setString(1, uuid); + statement.setString(2, uuid); + statement.executeUpdate(); } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } } @Override - public void deleteComments(int appId, int appReleaseID) throws CommentManagementException, DBConnectionException, - SQLException { + public void deleteComments(int appId, int appReleaseID) + throws CommentManagementException, DBConnectionException, SQLException { Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; try { conn = this.getDBConnection(); - String sql = "DELETE FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? and AP_APP_ID=?;"; - stmt = conn.prepareStatement(sql); - stmt.setInt(1, appReleaseID); - stmt.setInt(2, appId); - stmt.executeUpdate(); + sql += "DELETE FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? and AP_APP_ID=?;"; + statement = conn.prepareStatement(sql); + statement.setInt(1, appReleaseID); + statement.setInt(2, appId); + statement.executeUpdate(); } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } } @Override - public void deleteComments(String appType, String appName, String version) throws CommentManagementException { + public void deleteComments(String appType, String appName, String version) + throws CommentManagementException { Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; try { conn = this.getDBConnection(); - String sql = "DELETE FROM AP_APP_COMMENT WHERE " + sql += "DELETE FROM AP_APP_COMMENT WHERE " + "(SELECT AP_APP_RELEASE_ID FROM AP_APP_RELEASE WHERE VERSION=? AND " + "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? AND TYPE=?)) AND " + "(SELECT AP_APP_ID FROM AP_APP AND NAME=? AND TYPE=?);"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, version); - stmt.setString(2, appName); - stmt.setString(3, appType); - stmt.setString(4, appName); - stmt.setString(5, appType); - stmt.executeUpdate(); + statement = conn.prepareStatement(sql); + statement.setString(1, version); + statement.setString(2, appName); + statement.setString(3, appType); + statement.setString(4, appName); + statement.setString(5, appType); + statement.executeUpdate(); } catch (DBConnectionException e) { log.error("DB Connection Exception occurred while deleting comments", e); } catch (SQLException e) { throw new CommentManagementException("SQL Error occurred while deleting comments", e); } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } } @@ -865,52 +858,50 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { throws CommentManagementException { Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; try { conn = this.getDBConnection(); - String sql = "DELETE FROM AP_APP_COMMENT WHERE " + sql += "DELETE FROM AP_APP_COMMENT WHERE " + "(SELECT AP_APP_RELEASE_ID FROM AP_APP_RELEASE WHERE VERSION=? AND " + "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? AND TYPE=?)) AND " + "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? and TYPE=?) AND CREATED_BY=?;"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, version); - stmt.setString(2, appName); - stmt.setString(3, appType); - stmt.setString(4, appName); - stmt.setString(5, appType); - stmt.setString(6, createdBy); - stmt.executeUpdate(); + statement = conn.prepareStatement(sql); + statement.setString(1, version); + statement.setString(2, appName); + statement.setString(3, appType); + statement.setString(4, appName); + statement.setString(5, appType); + statement.setString(6, createdBy); + statement.executeUpdate(); } catch (DBConnectionException e) { log.error("DB Connection Exception occurred while deleting comments ", e); } catch (SQLException e) { throw new CommentManagementException("Error occurred while deleting comments", e); } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } } @Override - public void deleteComments(String uuid,int parentId) - throws CommentManagementException { + public void deleteComments(String uuid, int parentId) throws CommentManagementException { Connection conn; - PreparedStatement stmt = null; + PreparedStatement statement = null; try { conn = this.getDBConnection(); - String sql = - "DELETE FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?) " - + "AND AP_APP_ID=(SELECT AP_APP_ID FROM AP_APP_RELEASE where UUID=?)AND PARENT_ID=?;"; - stmt = conn.prepareStatement(sql); - stmt.setString(1, uuid); - stmt.setString(2, uuid); - stmt.setInt(3, parentId); - stmt.executeUpdate(); + sql += "DELETE FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?) " + + "AND AP_APP_ID=(SELECT AP_APP_ID FROM AP_APP_RELEASE where UUID=?)AND PARENT_ID=?;"; + statement = conn.prepareStatement(sql); + statement.setString(1, uuid); + statement.setString(2, uuid); + statement.setInt(3, parentId); + statement.executeUpdate(); } catch (DBConnectionException e) { log.error("DB Connection Exception occurred while deleting comments.", e); } catch (SQLException e) { throw new CommentManagementException("Error occurred while deleting comments", e); } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); } } @@ -918,15 +909,15 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { public int updateStars(int stars, String uuid) throws ApplicationManagementDAOException { Connection connection; - PreparedStatement stmt = null; + PreparedStatement statement = null; ResultSet resultSet = null; try { connection = this.getDBConnection(); - String sql = "UPDATE AP_APP_RELEASE SET STARS=?, NO_OF_RATED_USERS=(NO_OF_RATED_USERS+1) WHERE UUID=?;"; - stmt = connection.prepareStatement(sql); - stmt.setInt(1, stars); - stmt.setString(2, uuid); - resultSet = stmt.executeQuery(sql); + sql += "UPDATE AP_APP_RELEASE SET STARS=?, NO_OF_RATED_USERS=(NO_OF_RATED_USERS+1) WHERE UUID=?;"; + statement = connection.prepareStatement(sql); + statement.setInt(1, stars); + statement.setString(2, uuid); + resultSet = statement.executeQuery(sql); if (resultSet != null) { resultSet.getInt("STARS"); } @@ -934,7 +925,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { if (resultSet.next()) { ApplicationRelease applicationRelease = new ApplicationRelease(); applicationRelease.setStars(resultSet.getInt("STARS")); - Util.cleanupResources(stmt, resultSet); + Util.cleanupResources(statement, resultSet); } } catch (SQLException e) { throw new ApplicationManagementDAOException( @@ -944,7 +935,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { log.error("DB Connection Exception while trying to add stars to an application (UUID : " + uuid + "), ", e); } finally { - Util.cleanupResources(stmt, null); + Util.cleanupResources(statement, null); return getStars(uuid); } } @@ -955,12 +946,10 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Connection connection; PreparedStatement statement = null; ResultSet resultSet = null; - String sql; int Stars = 0; - try { connection = this.getDBConnection(); - sql = "SELECT STARS FROM AP_APP_RELEASE WHERE UUID=?;"; + sql += "SELECT STARS FROM AP_APP_RELEASE WHERE UUID=?;"; statement = connection.prepareStatement(sql); statement.setString(1, uuid); resultSet = statement.executeQuery(); @@ -988,21 +977,17 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Connection connection; PreparedStatement statement = null; ResultSet resultSet = null; - String sql; - int ratedUsers=0; - + int ratedUsers = 0; try { connection = this.getDBConnection(); - sql = "SELECT NO_OF_RATED_USERS FROM AP_APP_RELEASE WHERE UUID=?;"; + sql += "SELECT NO_OF_RATED_USERS FROM AP_APP_RELEASE WHERE UUID=?;"; statement = connection.prepareStatement(sql); - statement.setString(1,uuid); + statement.setString(1, uuid); resultSet = statement.executeQuery(); - if (resultSet.next()) { ApplicationRelease applicationRelease = new ApplicationRelease(); - ratedUsers =resultSet.getInt("NO_OF_RATED_USERS"); + ratedUsers = resultSet.getInt("NO_OF_RATED_USERS"); applicationRelease.setNoOfRatedUsers(ratedUsers); - Util.cleanupResources(statement, resultSet); return ratedUsers; } From a321bf934bb46d4f82656418644c523cd0ce522d Mon Sep 17 00:00:00 2001 From: nishadi Date: Thu, 18 Jan 2018 16:26:40 +0530 Subject: [PATCH 55/56] Modified CommentsManagerImpl Reformatted. --- .../device/application/mgt/core/impl/CommentsManagerImpl.java | 1 - 1 file changed, 1 deletion(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java index 0b75c69f66..4a5ab8b1c9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/CommentsManagerImpl.java @@ -258,7 +258,6 @@ public class CommentsManagerImpl implements CommentsManager { int newStars = 0; try { ConnectionManagerUtil.beginDBTransaction(); - int ratedUsers = commentDAO.getRatedUser(uuid); int oldStars = commentDAO.getStars(uuid); if (ratedUsers == 0) { From c50de8e2de3fcbb40b9576057bf389fafed24da7 Mon Sep 17 00:00:00 2001 From: nishadi Date: Thu, 18 Jan 2018 16:33:04 +0530 Subject: [PATCH 56/56] Modified CommentsDAOmpl Removed concatenation. --- .../core/dao/impl/Comment/CommentDAOImpl.java | 64 +++++++++---------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java index 63a76921b4..bf9da2448e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/Comment/CommentDAOImpl.java @@ -46,7 +46,7 @@ import java.util.List; public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { private static final Log log = LogFactory.getLog(CommentDAOImpl.class); - String sql = ""; + String sql; @Override public int addComment(int tenantId, Comment comment, String createdBy, int parentId, String uuid) @@ -59,7 +59,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { PreparedStatement statement = null; ResultSet rs = null; int commentId = -1; - sql += "INSERT INTO AP_APP_COMMENT (TENANT_ID, COMMENT_TEXT, CREATED_BY, PARENT_ID,AP_APP_RELEASE_ID," + sql = "INSERT INTO AP_APP_COMMENT (TENANT_ID, COMMENT_TEXT, CREATED_BY, PARENT_ID,AP_APP_RELEASE_ID," + "AP_APP_ID) VALUES (?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?)," + "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));"; try { @@ -93,7 +93,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { PreparedStatement statement = null; ResultSet rs; int commentId = -1; - sql += "INSERT INTO AP_APP_COMMENT ( TENANT_ID,COMMENT_TEXT, CREATED_BY,AP_APP_RELEASE_ID,AP_APP_ID) " + sql = "INSERT INTO AP_APP_COMMENT ( TENANT_ID,COMMENT_TEXT, CREATED_BY,AP_APP_RELEASE_ID,AP_APP_ID) " + "VALUES (?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE VERSION =? AND (SELECT ID FROM AP_APP WHERE " + "TYPE=? AND NAME=?)),(SELECT ID FROM AP_APP WHERE TYPE=? AND NAME=?));"; try { @@ -127,7 +127,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Connection connection; PreparedStatement statement = null; ResultSet rs = null; - sql += "UPDATE AP_APP_COMMENT SET COMMENT_TEXT=?, MODEFIED_BY=? WHERE ID=?;"; + sql = "UPDATE AP_APP_COMMENT SET COMMENT_TEXT=?, MODEFIED_BY=? WHERE ID=?;"; try { connection = this.getDBConnection(); statement = connection.prepareStatement(sql); @@ -153,7 +153,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Connection connection; PreparedStatement statement = null; ResultSet rs = null; - sql += "UPDATE AP_APP_COMMENT SET COMMENT_TEXT=?,MODEFIED_BY=? WHERE ID=?; "; + sql = "UPDATE AP_APP_COMMENT SET COMMENT_TEXT=?,MODEFIED_BY=? WHERE ID=?; "; try { connection = this.getDBConnection(); statement = connection.prepareStatement(sql); @@ -180,7 +180,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { Comment comment = new Comment(); try { conn = this.getDBConnection(); - sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE ID=?;"; + sql = "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE ID=?;"; statement = conn.prepareStatement(sql); statement.setInt(1, commentId); rs = statement.executeQuery(); @@ -219,7 +219,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { List comments = new ArrayList<>(); try { conn = this.getDBConnection(); - sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE (SELECT ID FROM AP_APP_RELEASE where UUID=?)AND " + sql = "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE (SELECT ID FROM AP_APP_RELEASE where UUID=?)AND " + "(SELECT AP_APP_ID FROM AP_APP_RELEASE where UUID=?);"; statement = conn.prepareStatement(sql); statement.setString(1, uuid); @@ -260,7 +260,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { List comments = new ArrayList<>(); try { conn = this.getDBConnection(); - sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT, AP_APP_RELEASE WHERE AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID " + sql = "SELECT COMMENT_TEXT FROM AP_APP_COMMENT, AP_APP_RELEASE WHERE AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID " + "AND AP_APP_RELEASE.UUID =? LIMIT ? OFFSET ?;"; statement = conn.prepareStatement(sql); statement.setString(1, uuid); @@ -299,7 +299,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { isUuidProvided = true; } if (isUuidProvided) { - sql += "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE " + sql = "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE " + "WHERE AP_APP_COMMENT.AP_APP_RELEASE_ID= AP_APP_RELEASE.ID AND " + "AP_APP_COMMENT.AP_APP_ID= AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;"; statement = conn.prepareStatement(sql); @@ -332,7 +332,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { List comments = new ArrayList<>(); try { conn = this.getDBConnection(); - sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? AND AP_APP_ID=?;"; + sql = "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? AND AP_APP_ID=?;"; statement = conn.prepareStatement(sql); statement.setInt(1, appReleasedId); statement.setInt(2, appId); @@ -373,7 +373,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { List comments = new ArrayList<>(); try { conn = this.getDBConnection(); - sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID FROM AP_APP_COMMENT C ," + sql = "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID FROM AP_APP_COMMENT C ," + "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=?) R," + "(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? AND TYPE=?)P" + " WHERE AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND AP_APP_ID=RELEASE_AP_APP_ID" @@ -414,7 +414,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { List comments = new ArrayList<>(); try { conn = this.getDBConnection(); - sql += "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE TENANT_ID='?';"; + sql = "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE TENANT_ID='?';"; statement = conn.prepareStatement(sql); statement.setInt(1, tenantId); rs = statement.executeQuery(); @@ -449,7 +449,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { List comments = new ArrayList<>(); try { conn = this.getDBConnection(); - sql += "SELECT COMMENT_TEXT ,PARENT_ID,TENANT_ID,CREATED_AT FROM AP_APP_COMMENT WHERE CREATED_BY= ?" + sql = "SELECT COMMENT_TEXT ,PARENT_ID,TENANT_ID,CREATED_AT FROM AP_APP_COMMENT WHERE CREATED_BY= ?" + " ORDER BY CREATED_AT DESC;"; statement = conn.prepareStatement(sql); statement.setString(1, createdBy); @@ -486,7 +486,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { List comments = new ArrayList<>(); try { conn = this.getDBConnection(); - sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID FROM AP_APP_COMMENT WHERE CREATED_BY=?" + sql = "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID FROM AP_APP_COMMENT WHERE CREATED_BY=?" + "AND CREATED_AT= ? ORDER BY CREATED_AT DESC;"; statement = conn.prepareStatement(sql); statement.setString(1, createdBy); @@ -523,7 +523,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { List comments = new ArrayList<>(); try { conn = this.getDBConnection(); - sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID,CREATED_AT,MODEFIED_AT FROM AP_APP_COMMENT " + sql = "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID,CREATED_AT,MODEFIED_AT FROM AP_APP_COMMENT " + "WHERE MODEFIED_BY= ? ORDER BY CREATED_AT DESC;"; statement = conn.prepareStatement(sql); statement.setString(1, modifiedBy); @@ -560,7 +560,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { List comments = new ArrayList<>(); try { conn = this.getDBConnection(); - sql += "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID,CREATED_AT FROM AP_APP_COMMENT WHERE MODEFIED_BY= ?," + sql = "SELECT COMMENT_TEXT,PARENT_ID,TENANT_ID,CREATED_AT FROM AP_APP_COMMENT WHERE MODEFIED_BY= ?," + "MODEFIED_AT=? ORDER BY CREATED_AT DESC;"; statement = conn.prepareStatement(sql); statement.setString(1, modifiedBy); @@ -599,7 +599,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { List comments = new ArrayList<>(); try { conn = this.getDBConnection(); - sql += "SELECT COMMENT_TEXT,TENANT_ID FROM AP_APP_COMMENT C ," + sql = "SELECT COMMENT_TEXT,TENANT_ID FROM AP_APP_COMMENT C ," + "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=? ) " + "R,(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? AND TYPE=?)P " + "WHERE PARENT_ID=? AND AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND " @@ -637,7 +637,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { int commentCount = 0; try { conn = this.getDBConnection(); - sql += "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE WHERE " + sql = "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE WHERE " + "AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_COMMENT.AP_APP_ID=" + "AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;"; statement = conn.prepareStatement(sql); @@ -661,7 +661,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { int commentCount = 0; try { conn = this.getDBConnection(); - sql += "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE CREATED_BY= ?;"; + sql = "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE CREATED_BY= ?;"; statement = conn.prepareStatement(sql); statement.setString(1, createdBy); ResultSet rs = statement.executeQuery(); @@ -683,7 +683,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { int commentCount = 0; try { conn = this.getDBConnection(); - sql += "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE MODEFIED_BY= ? AND MODEFIED_AT=?;"; + sql = "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE MODEFIED_BY= ? AND MODEFIED_AT=?;"; statement = conn.prepareStatement(sql); statement.setString(1, modifiedBy); statement.setTimestamp(2, modifedAt); @@ -706,7 +706,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { int commentCount = 0; try { conn = this.getDBConnection(); - sql += "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? AND AP_APP_ID=?;"; + sql = "SELECT COUNT(ID) FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? AND AP_APP_ID=?;"; statement = conn.prepareStatement(sql); statement.setInt(1, appReleaseId); statement.setInt(2, appId); @@ -729,7 +729,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { int commentCount = 0; try { conn = this.getDBConnection(); - sql += "SELECT COUNT(ID) AS COMMENT_COUNT FROM AP_APP_COMMENT C, " + sql = "SELECT COUNT(ID) AS COMMENT_COUNT FROM AP_APP_COMMENT C, " + "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=? )R," + "(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? and TYPE=?)P " + "WHERE AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND AP_APP_ID=RELEASE_AP_APP_ID;"; @@ -755,7 +755,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { int commentCount = 0; try { conn = this.getDBConnection(); - sql += "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE WHERE " + sql = "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE WHERE " + "AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND " + "AP_APP_COMMENT.AP_APP_ID=AP_APP_RELEASE.AP_APP_ID and AP_APP_RELEASE.UUID=? and PARENT_ID=?;"; @@ -780,7 +780,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { PreparedStatement statement = null; try { conn = this.getDBConnection(); - sql += "DELETE FROM AP_APP_COMMENT WHERE ID=?;"; + sql = "DELETE FROM AP_APP_COMMENT WHERE ID=?;"; statement = conn.prepareStatement(sql); statement.setInt(1, commentId); statement.executeUpdate(); @@ -795,7 +795,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { PreparedStatement statement = null; try { conn = this.getDBConnection(); - sql += "DELETE FROM AP_APP_COMMENT WHERE " + sql = "DELETE FROM AP_APP_COMMENT WHERE " + "(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?)AND (SELECT AP_APP_ID FROM AP_APP_RELEASE " + "WHERE UUID=?);"; statement = conn.prepareStatement(sql); @@ -815,7 +815,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { PreparedStatement statement = null; try { conn = this.getDBConnection(); - sql += "DELETE FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? and AP_APP_ID=?;"; + sql = "DELETE FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=? and AP_APP_ID=?;"; statement = conn.prepareStatement(sql); statement.setInt(1, appReleaseID); statement.setInt(2, appId); @@ -833,7 +833,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { PreparedStatement statement = null; try { conn = this.getDBConnection(); - sql += "DELETE FROM AP_APP_COMMENT WHERE " + sql = "DELETE FROM AP_APP_COMMENT WHERE " + "(SELECT AP_APP_RELEASE_ID FROM AP_APP_RELEASE WHERE VERSION=? AND " + "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? AND TYPE=?)) AND " + "(SELECT AP_APP_ID FROM AP_APP AND NAME=? AND TYPE=?);"; @@ -861,7 +861,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { PreparedStatement statement = null; try { conn = this.getDBConnection(); - sql += "DELETE FROM AP_APP_COMMENT WHERE " + sql = "DELETE FROM AP_APP_COMMENT WHERE " + "(SELECT AP_APP_RELEASE_ID FROM AP_APP_RELEASE WHERE VERSION=? AND " + "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? AND TYPE=?)) AND " + "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? and TYPE=?) AND CREATED_BY=?;"; @@ -889,7 +889,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { PreparedStatement statement = null; try { conn = this.getDBConnection(); - sql += "DELETE FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?) " + sql = "DELETE FROM AP_APP_COMMENT WHERE AP_APP_RELEASE_ID=(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?) " + "AND AP_APP_ID=(SELECT AP_APP_ID FROM AP_APP_RELEASE where UUID=?)AND PARENT_ID=?;"; statement = conn.prepareStatement(sql); statement.setString(1, uuid); @@ -913,7 +913,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { ResultSet resultSet = null; try { connection = this.getDBConnection(); - sql += "UPDATE AP_APP_RELEASE SET STARS=?, NO_OF_RATED_USERS=(NO_OF_RATED_USERS+1) WHERE UUID=?;"; + sql = "UPDATE AP_APP_RELEASE SET STARS=?, NO_OF_RATED_USERS=(NO_OF_RATED_USERS+1) WHERE UUID=?;"; statement = connection.prepareStatement(sql); statement.setInt(1, stars); statement.setString(2, uuid); @@ -949,7 +949,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { int Stars = 0; try { connection = this.getDBConnection(); - sql += "SELECT STARS FROM AP_APP_RELEASE WHERE UUID=?;"; + sql = "SELECT STARS FROM AP_APP_RELEASE WHERE UUID=?;"; statement = connection.prepareStatement(sql); statement.setString(1, uuid); resultSet = statement.executeQuery(); @@ -980,7 +980,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO { int ratedUsers = 0; try { connection = this.getDBConnection(); - sql += "SELECT NO_OF_RATED_USERS FROM AP_APP_RELEASE WHERE UUID=?;"; + sql = "SELECT NO_OF_RATED_USERS FROM AP_APP_RELEASE WHERE UUID=?;"; statement = connection.prepareStatement(sql); statement.setString(1, uuid); resultSet = statement.executeQuery();