Modified Comment ManagementAPiImpl

changed returning error response message into "return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();"
feature/appm-store/pbac
nishadi 7 years ago
parent 919a7a8ddd
commit a6f2486ec6

@ -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.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.CommentManagementException; import org.wso2.carbon.device.application.mgt.common.exception.CommentManagementException;
import org.wso2.carbon.device.application.mgt.common.services.CommentsManager; import org.wso2.carbon.device.application.mgt.common.services.CommentsManager;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
@ -46,7 +47,6 @@ import java.util.List;
* Comment Management related jax-rs APIs. * Comment Management related jax-rs APIs.
*/ */
@Path("/comments") @Path("/comments")
@SuppressWarnings( "deprecation" )
public class CommentManagementAPIImpl implements CommentManagementAPI { public class CommentManagementAPIImpl implements CommentManagementAPI {
private static Log log = LogFactory.getLog(CommentManagementAPIImpl.class); private static Log log = LogFactory.getLog(CommentManagementAPIImpl.class);
@ -56,8 +56,8 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
@Path("/{uuid}") @Path("/{uuid}")
public Response getAllComments( public Response getAllComments(
@PathParam("uuid") String uuid, @PathParam("uuid") String uuid,
@QueryParam("offset")int offSet, @QueryParam("offset") int offSet, @
@QueryParam("limit")int limit){ QueryParam("limit") int limit) {
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
List<Comment> comments = new ArrayList<>(); List<Comment> comments = new ArrayList<>();
@ -74,18 +74,14 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
} catch (CommentManagementException e) { } catch (CommentManagementException e) {
String msg = "Error occurred while retrieving comments."; String msg = "Error occurred while retrieving comments.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("Application with UUID" + uuid + " Internal server error occurs").build();
} }
return Response.status(Response.Status.OK).entity(comments).build(); return Response.status(Response.Status.OK).entity(comments).build();
} }
@Override @Override @POST @Consumes("application/json") @Path("/{uuid}") public Response addComments(
@POST @ApiParam Comment comment, @PathParam("uuid") String uuid) {
@Consumes("application/json")
@Path("/{uuid}")
public Response addComments(
@ApiParam Comment comment,
@PathParam("uuid") String uuid){
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -101,17 +97,13 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
} catch (CommentManagementException e) { } catch (CommentManagementException e) {
String msg = "Error occurred while creating the comment"; String msg = "Error occurred while creating the comment";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("Application with UUID" + uuid + " Internal server error occurs").build();
} }
} }
@Override @Override @PUT @Consumes("application/json") @Path("/{CommentId}") public Response updateComment(
@PUT @ApiParam Comment comment, @PathParam("CommentId") int CommentId) {
@Consumes("application/json")
@Path("/{CommentId}")
public Response updateComment(
@ApiParam Comment comment,
@PathParam("CommentId") int CommentId) {
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
try { try {
@ -129,16 +121,15 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
} catch (CommentManagementException e) { } catch (CommentManagementException e) {
String msg = "Error occurred while retrieving comments."; String msg = "Error occurred while retrieving comments.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("Comment with Comment Id" + CommentId + " Internal server error occurs").build();
} }
} }
@Override @Override
@DELETE @DELETE
@Path("/{CommentId}") @Path("/{CommentId}")
public Response deleteComment( public Response deleteComment(@PathParam("CommentId") int CommentId) {
@PathParam("CommentId")
int CommentId){
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
try { try {
@ -146,7 +137,8 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
} catch (CommentManagementException e) { } catch (CommentManagementException e) {
String msg = "Error occurred while deleting the comment."; String msg = "Error occurred while deleting the comment.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("Comment with Comment Id" + CommentId + " Internal server error occurs").build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
log.error("Not found exception occurs to comment id " + CommentId + " .", e); log.error("Not found exception occurs to comment id " + CommentId + " .", e);
return Response.status(Response.Status.NOT_FOUND).entity("Comment with" + CommentId + " not found").build(); return Response.status(Response.Status.NOT_FOUND).entity("Comment with" + CommentId + " not found").build();
@ -157,9 +149,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
@Override @Override
@GET @GET
@Path("/{uuid}") @Path("/{uuid}")
public Response getStars( public Response getStars(@PathParam("uuid") String uuid) {
@PathParam("uuid")
String uuid) {
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
int Stars = 0; int Stars = 0;
@ -170,7 +160,8 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
log.error("Application Management Exception occurs", e); log.error("Application Management Exception occurs", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("Application with UUID" + uuid + " Internal server error occurs").build();
} }
return Response.status(Response.Status.OK).entity(Stars).build(); return Response.status(Response.Status.OK).entity(Stars).build();
} }
@ -178,9 +169,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
@Override @Override
@GET @GET
@Path("/{uuid}") @Path("/{uuid}")
public Response getRatedUser( public Response getRatedUser(@PathParam("uuid") String uuid) {
@PathParam("uuid")
String uuid){
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
int ratedUsers = 0; int ratedUsers = 0;
@ -188,19 +177,17 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
ratedUsers = commentsManager.getRatedUser(uuid); ratedUsers = commentsManager.getRatedUser(uuid);
} catch (CommentManagementException e) { } catch (CommentManagementException e) {
log.error("Comment Management Exception occurs", e); log.error("Comment Management Exception occurs", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("Application with UUID" + uuid + " Internal server error occurs").build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
log.error("Application Management Exception occurs", e); log.error("Application Management Exception occurs", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("Application with UUID" + uuid + " Internal server error occurs").build();
} }
return Response.status(Response.Status.OK).entity(ratedUsers).build(); return Response.status(Response.Status.OK).entity(ratedUsers).build();
} }
@Override @Override @POST @Consumes("uuid/stars/json") public Response updateStars(@ApiParam int stars,
@POST
@Consumes("uuid/stars/json")
public Response updateStars(
@ApiParam int stars,
@PathParam("uuid") String uuid) { @PathParam("uuid") String uuid) {
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
@ -218,7 +205,8 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
log.error("Application Management Exception occurs", e); log.error("Application Management Exception occurs", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("Application with UUID" + uuid + " Internal server error occurs").build();
} }
} }
} }
Loading…
Cancel
Save