From 27373ef35e78ef27033a5a628c5275a6d75fe33b Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Thu, 4 Jul 2019 22:43:51 +0530 Subject: [PATCH] Move review delete functionality into store --- .../GenericApplicationDAOImpl.java | 32 +++-- ...=> ReviewManagementPublisherAdminAPI.java} | 49 +------ ...eviewManagementPublisherAdminAPIImpl.java} | 37 +----- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 +- .../services/ApplicationManagementAPI.java | 2 +- .../api/services/ReviewManagementAPI.java | 2 +- .../services/SubscriptionManagementAPI.java | 2 +- .../admin/ReviewManagementStoreAdminAPI.java | 121 ++++++++++++++++++ .../ReviewManagementStoreAdminAPIImpl.java | 72 +++++++++++ .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 + .../main/resources/conf/application-mgt.xml | 1 + 11 files changed, 225 insertions(+), 97 deletions(-) rename components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/{ReviewManagementAdminAPI.java => ReviewManagementPublisherAdminAPI.java} (82%) rename components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/{ReviewManagementAdminAPIImpl.java => ReviewManagementPublisherAdminAPIImpl.java} (75%) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/admin/ReviewManagementStoreAdminAPI.java create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/admin/ReviewManagementStoreAdminAPIImpl.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/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index 37408748c3..c9aeaf9e42 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -1003,12 +1003,12 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic if (log.isDebugEnabled()) { log.debug("Request received in DAO Layer to get tag for given tag name."); } + String sql = "SELECT AP_APP_TAG.ID AS ID" + + " FROM AP_APP_TAG " + + "WHERE AP_APP_TAG.TAG = ? AND " + + "AP_APP_TAG.TENANT_ID = ?"; try { Connection conn = this.getDBConnection(); - String sql = "SELECT AP_APP_TAG.ID AS ID" - + " FROM AP_APP_TAG " - + "WHERE AP_APP_TAG.TAG = ? AND " - + "AP_APP_TAG.TENANT_ID = ?"; try (PreparedStatement ps = conn.prepareStatement(sql)) { ps.setString(1, tagName); ps.setInt(2, tenantId); @@ -1023,11 +1023,12 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } return null; } catch (DBConnectionException e) { - String msg = "Error occurred while obtaining the DB connection when getting tag for given tag name"; + String msg = "Error occurred while obtaining the DB connection when getting tag for given tag name: " + + tagName; log.error(msg); throw new ApplicationManagementDAOException(msg, e); } catch (SQLException e) { - String msg = "SQL Error occurred while getting tag for tag name."; + String msg = "SQL Error occurred while getting tag for tag name: " + tagName + ". Executed query: " + sql; throw new ApplicationManagementDAOException(msg, e); } } @@ -1037,10 +1038,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic if (log.isDebugEnabled()) { log.debug("Request received in DAO Layer to get distinct tag ids in tag mapping."); } + String sql = "SELECT DISTINCT tm.AP_APP_TAG_ID AS ID FROM AP_APP_TAG_MAPPING tm"; try { Connection conn = this.getDBConnection(); List distinctTagIds = new ArrayList<>(); - String sql = "SELECT DISTINCT tm.AP_APP_TAG_ID AS ID FROM AP_APP_TAG_MAPPING tm"; try (PreparedStatement ps = conn.prepareStatement(sql)) { try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { @@ -1050,16 +1051,23 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } return distinctTagIds; } catch (DBConnectionException e) { - throw new ApplicationManagementDAOException( - "Error occurred while obtaining the DB connection when getting distinct tag ids in tag mapping", e); + String msg = "Error occurred while obtaining the DB connection when getting distinct tag ids in tag " + + "mapping"; + log.error(msg); + throw new ApplicationManagementDAOException(msg, e); } catch (SQLException e) { - throw new ApplicationManagementDAOException("Error occurred while getting distinct tag ids in tag mapping", e); + String msg = "SQL Error occurred while getting distinct tag ids in tag mapping. Executed query: " + sql; + log.error(msg); + throw new ApplicationManagementDAOException(msg, e); } } - public void addTagMapping (List tagIds, int applicationId, int tenantId) throws ApplicationManagementDAOException { + @Override + public void addTagMapping(List tagIds, int applicationId, int tenantId) + throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to add tags"); + log.debug("Request received in DAO Layer to add application tags which has application ID: " + + applicationId); } Connection conn; PreparedStatement stmt = null; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ReviewManagementAdminAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ReviewManagementPublisherAdminAPI.java similarity index 82% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ReviewManagementAdminAPI.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ReviewManagementPublisherAdminAPI.java index e8f8a4c783..1b649af7c5 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ReviewManagementAdminAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ReviewManagementPublisherAdminAPI.java @@ -57,7 +57,7 @@ info = @Info( extensions = { @Extension(properties = { @ExtensionProperty(name = "name", value = "PublisherReviewManagementAdminService"), - @ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/admin/review"), + @ExtensionProperty(name = "context", value = "/api/application-mgt-publisher/v1.0/admin/review"), }) } ), @@ -85,54 +85,9 @@ scopes = { @Path("/admin/reviews") @Api(value = "Publisher Review Management Admin API") @Produces(MediaType.APPLICATION_JSON) -public interface ReviewManagementAdminAPI { +public interface ReviewManagementPublisherAdminAPI { String SCOPE = "scope"; - @DELETE - @Path("/{uuid}/{reviewId}") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "DELETE", - value = "Remove review", - notes = "Remove review", - tags = "Review Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:admin:app:review:update") - }) - } - ) - - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully deleted the review"), - @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 review.", - response = ErrorResponse.class) - }) - - Response deleteReview( - @ApiParam( - name = "uuid", - value = "UUID of the application release.", - required = true) - @PathParam("uuid") String uuid, - @ApiParam( - name = "reviewId", - value = "Id of the review.", - required = true) - @PathParam("reviewId") int reviewId); - @GET @Path("/release/{uuid}") @Produces(MediaType.APPLICATION_JSON) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ReviewManagementAdminAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ReviewManagementPublisherAdminAPIImpl.java similarity index 75% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ReviewManagementAdminAPIImpl.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ReviewManagementPublisherAdminAPIImpl.java index fbda07e392..87aab15997 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ReviewManagementAdminAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ReviewManagementPublisherAdminAPIImpl.java @@ -16,7 +16,6 @@ */ package org.wso2.carbon.device.application.mgt.publisher.api.services.impl.admin; -import io.swagger.annotations.ApiParam; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.application.mgt.common.PaginationRequest; @@ -25,16 +24,12 @@ import org.wso2.carbon.device.application.mgt.common.Rating; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException; import org.wso2.carbon.device.application.mgt.common.services.ReviewManager; -import org.wso2.carbon.device.application.mgt.common.wrapper.ReviewWrapper; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.core.util.APIUtil; -import org.wso2.carbon.device.application.mgt.publisher.api.services.admin.ReviewManagementAdminAPI; +import org.wso2.carbon.device.application.mgt.publisher.api.services.admin.ReviewManagementPublisherAdminAPI; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; -import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.QueryParam; @@ -44,35 +39,9 @@ import javax.ws.rs.core.Response; * Review Management related jax-rs APIs. */ @Path("/admin/reviews") -public class ReviewManagementAdminAPIImpl implements ReviewManagementAdminAPI { +public class ReviewManagementPublisherAdminAPIImpl implements ReviewManagementPublisherAdminAPI { - private static Log log = LogFactory.getLog(ReviewManagementAdminAPIImpl.class); - - @Override - @DELETE - @Path("/{uuid}/{reviewId}") - public Response deleteReview( - @PathParam("uuid") String uuid, - @PathParam("reviewId") int reviewId) { - - ReviewManager reviewManager = APIUtil.getReviewManager(); - try { - reviewManager.deleteReview(uuid, reviewId, true); - return Response.status(Response.Status.OK).entity("Review is deleted successfully.").build(); - } catch (NotFoundException e) { - String msg = "Couldn't found an application review to delete which match with the request."; - log.error(msg, e); - return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); - } catch (ReviewManagementException e) { - String msg = "Error occurred while deleting the comment."; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } catch (ApplicationManagementException e) { - String msg = "Error occurred while getting application release data."; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } - } + private static Log log = LogFactory.getLog(ReviewManagementPublisherAdminAPIImpl.class); @Override @GET diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 6f108fe514..6030979220 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -56,7 +56,7 @@ - + diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ApplicationManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ApplicationManagementAPI.java index 68548f4640..60781d3881 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ApplicationManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ApplicationManagementAPI.java @@ -53,7 +53,7 @@ import javax.ws.rs.core.Response; extensions = { @Extension(properties = { @ExtensionProperty(name = "name", value = "ApplicationStorageManagementService"), - @ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/store-applications"), + @ExtensionProperty(name = "context", value = "/api/application-mgt-store/v1.0/store-applications"), }) } ), diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java index d72e9e4c27..5c1868134b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/ReviewManagementAPI.java @@ -60,7 +60,7 @@ import java.util.List; extensions = { @Extension(properties = { @ExtensionProperty(name = "name", value = "ReviewManagementService"), - @ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/store/review"), + @ExtensionProperty(name = "context", value = "/api/application-mgt-store/v1.0/store/review"), }) } ), diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/SubscriptionManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/SubscriptionManagementAPI.java index b6a4878789..dbb41fb34a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/SubscriptionManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/SubscriptionManagementAPI.java @@ -49,7 +49,7 @@ import java.util.List; extensions = { @Extension(properties = { @ExtensionProperty(name = "name", value = "SubscriptionManagementService"), - @ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/subscription"), + @ExtensionProperty(name = "context", value = "/api/application-mgt-store/v1.0/subscription"), }) } ), diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/admin/ReviewManagementStoreAdminAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/admin/ReviewManagementStoreAdminAPI.java new file mode 100644 index 0000000000..a1d7a77de1 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/admin/ReviewManagementStoreAdminAPI.java @@ -0,0 +1,121 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.store.api.services.admin; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.Extension; +import io.swagger.annotations.ExtensionProperty; +import io.swagger.annotations.Info; +import io.swagger.annotations.SwaggerDefinition; +import io.swagger.annotations.Tag; +import org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; +import org.wso2.carbon.device.application.mgt.common.ErrorResponse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.MediaType; +import javax.ws.rs.core.Response; + +/** +* APIs to handle admin review management related tasks in store. +*/ + +@SwaggerDefinition( +info = @Info( + version = "1.0.0", + title = "Store Review Management Admin Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = "name", value = "StoreReviewManagementAdminService"), + @ExtensionProperty(name = "context", value = "/api/application-mgt-store/v1.0/admin/review"), + }) + } +), +tags = { + @Tag(name = "review_management", description = "Store Review Management related Admin APIs") +} +) +@Scopes( +scopes = { + @Scope( + name = "Update a Review", + description = "Update a Review of applications.", + key = "perm:admin:app:review:update", + permissions = {"/app-mgt/store/admin/review/update"} + ) +} +) + +@Path("/admin/reviews") +@Api(value = "Store Review Management Admin API") +@Produces(MediaType.APPLICATION_JSON) +public interface ReviewManagementStoreAdminAPI { +String SCOPE = "scope"; + + @DELETE + @Path("/{uuid}/{reviewId}") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "DELETE", + value = "Remove review", + notes = "Remove review", + tags = "Review Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:admin:app:review:update") + }) + } + ) + + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully deleted the review"), + @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 review.", + response = ErrorResponse.class) + }) + + Response deleteReview( + @ApiParam( + name = "uuid", + value = "UUID of the application release.", + required = true) + @PathParam("uuid") String uuid, + @ApiParam( + name = "reviewId", + value = "Id of the review.", + required = true) + @PathParam("reviewId") int reviewId); +} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/admin/ReviewManagementStoreAdminAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/admin/ReviewManagementStoreAdminAPIImpl.java new file mode 100644 index 0000000000..92ca6a84f1 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/admin/ReviewManagementStoreAdminAPIImpl.java @@ -0,0 +1,72 @@ +/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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.store.api.services.impl.admin; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +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.Rating; +import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; +import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException; +import org.wso2.carbon.device.application.mgt.common.services.ReviewManager; +import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; +import org.wso2.carbon.device.application.mgt.core.util.APIUtil; +import org.wso2.carbon.device.application.mgt.store.api.services.admin.ReviewManagementStoreAdminAPI; + +import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; +import javax.ws.rs.core.Response; + +/** + * Review Management related jax-rs APIs. + */ +@Path("/admin/reviews") +public class ReviewManagementStoreAdminAPIImpl implements ReviewManagementStoreAdminAPI { + + private static Log log = LogFactory.getLog(ReviewManagementStoreAdminAPIImpl.class); + + @Override + @DELETE + @Path("/{uuid}/{reviewId}") + public Response deleteReview( + @PathParam("uuid") String uuid, + @PathParam("reviewId") int reviewId) { + + ReviewManager reviewManager = APIUtil.getReviewManager(); + try { + reviewManager.deleteReview(uuid, reviewId, true); + return Response.status(Response.Status.OK).entity("Review is deleted successfully.").build(); + } catch (NotFoundException e) { + String msg = "Couldn't found an application review to delete which match with the request."; + log.error(msg, e); + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); + } catch (ReviewManagementException e) { + String msg = "Error occurred while deleting the comment."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } catch (ApplicationManagementException e) { + String msg = "Error occurred while getting application release data."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + } +} \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/cxf-servlet.xml index da9e97ccea..bfc0b03095 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -24,6 +24,7 @@ + @@ -53,6 +54,7 @@ + diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml index ad7b89a56b..c5d034e6ac 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml @@ -155,6 +155,7 @@ perm:admin:app:review:update perm:admin:app:review:view perm:admin:app:publisher:update + perm:admin:app:review:update app-mgt