From 1bbd0b1aa51158cd472ab5f9b4ddb18bd2eca5cb Mon Sep 17 00:00:00 2001 From: nishadi Date: Wed, 17 Jan 2018 15:32:59 +0530 Subject: [PATCH] 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