mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'application-mgt-new' of https://github.com/lasanthaDLPDS/carbon-device-mgt into application-mgt-new
This commit is contained in:
commit
106632403e
@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.wso2.carbon.device.application.mgt.core.dao;
|
package org.wso2.carbon.device.application.mgt.core.dao;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.application.mgt.common.Application;
|
||||||
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
|
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
|
||||||
import org.wso2.carbon.device.application.mgt.common.Rating;
|
import org.wso2.carbon.device.application.mgt.common.Rating;
|
||||||
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||||
|
|||||||
@ -380,7 +380,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
|||||||
Connection conn;
|
Connection conn;
|
||||||
PreparedStatement stmt = null;
|
PreparedStatement stmt = null;
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
boolean isAppExist = false;
|
|
||||||
try {
|
try {
|
||||||
conn = this.getDBConnection();
|
conn = this.getDBConnection();
|
||||||
String sql =
|
String sql =
|
||||||
@ -396,13 +395,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Successfully retrieved basic details of the application with the application ID " + appId);
|
log.debug("Successfully retrieved basic details of the application with the application ID " + appId);
|
||||||
}
|
}
|
||||||
|
return rs.next();
|
||||||
if (rs.next()) {
|
|
||||||
isAppExist = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return isAppExist;
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
throw new ApplicationManagementDAOException(
|
throw new ApplicationManagementDAOException(
|
||||||
"Error occurred while getting application details with app ID " + appId + " While executing query ",
|
"Error occurred while getting application details with app ID " + appId + " While executing query ",
|
||||||
|
|||||||
@ -19,12 +19,17 @@
|
|||||||
|
|
||||||
package org.wso2.carbon.device.application.mgt.core.dao.impl.application.release;
|
package org.wso2.carbon.device.application.mgt.core.dao.impl.application.release;
|
||||||
|
|
||||||
|
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.ApplicationRelease;
|
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
|
||||||
import org.wso2.carbon.device.application.mgt.common.Rating;
|
import org.wso2.carbon.device.application.mgt.common.Rating;
|
||||||
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
|
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
|
||||||
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
|
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
|
||||||
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
|
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
|
||||||
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
|
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
|
||||||
|
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl;
|
||||||
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@ -40,6 +45,9 @@ import java.util.List;
|
|||||||
*/
|
*/
|
||||||
public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements ApplicationReleaseDAO {
|
public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements ApplicationReleaseDAO {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(GenericApplicationReleaseDAOImpl.class);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To insert the Application Release Details.
|
* To insert the Application Release Details.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -92,7 +92,7 @@ public class APIUtil {
|
|||||||
* @return ReviewManager instance in the current osgi context.
|
* @return ReviewManager instance in the current osgi context.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static ReviewManager getCommentsManager() {
|
public static ReviewManager getReviewManager() {
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
ReviewManager reviewManager = (ReviewManager) ctx.getOSGiService(ReviewManager.class, null);
|
ReviewManager reviewManager = (ReviewManager) ctx.getOSGiService(ReviewManager.class, null);
|
||||||
if (reviewManager == null) {
|
if (reviewManager == null) {
|
||||||
|
|||||||
@ -200,11 +200,10 @@ public interface ReviewManagementAPI {
|
|||||||
name="uuid",
|
name="uuid",
|
||||||
value="uuid of the release version of the application",
|
value="uuid of the release version of the application",
|
||||||
required=true)
|
required=true)
|
||||||
@PathParam("uuid")
|
@PathParam("uuid") String uuid);
|
||||||
String uuid);
|
|
||||||
|
|
||||||
@PUT
|
@PUT
|
||||||
@Path("/{CommentId}")
|
@Path("/{uuid}/{reviewId}")
|
||||||
@Produces(MediaType.APPLICATION_JSON)
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
@Consumes(MediaType.APPLICATION_JSON)
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
@ApiOperation(
|
@ApiOperation(
|
||||||
@ -238,18 +237,22 @@ public interface ReviewManagementAPI {
|
|||||||
message = "Internal Server Error. \n Error occurred while updating the new review.",
|
message = "Internal Server Error. \n Error occurred while updating the new review.",
|
||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
Response updateComment(
|
Response updateReview(
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "review",
|
name = "review",
|
||||||
value = "The review that need to be updated.",
|
value = "The review that need to be updated.",
|
||||||
required = true)
|
required = true)
|
||||||
@Valid Review review,
|
@Valid Review review,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name="commentId",
|
name="uuid",
|
||||||
|
value = "uuid of the application release",
|
||||||
|
required = true)
|
||||||
|
@PathParam("uuid") String uuid,
|
||||||
|
@ApiParam(
|
||||||
|
name="reviewId",
|
||||||
value = "review id of the updating review.",
|
value = "review id of the updating review.",
|
||||||
required = true)
|
required = true)
|
||||||
@QueryParam("commentId")
|
@PathParam("reviewId") int reviewId);
|
||||||
int commentId);
|
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/{commentId}")
|
@Path("/{commentId}")
|
||||||
|
|||||||
@ -22,7 +22,6 @@ import io.swagger.annotations.ApiParam;
|
|||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.wso2.carbon.device.application.mgt.common.Application;
|
import org.wso2.carbon.device.application.mgt.common.Application;
|
||||||
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
|
|
||||||
import org.wso2.carbon.device.application.mgt.common.PaginationResult;
|
import org.wso2.carbon.device.application.mgt.common.PaginationResult;
|
||||||
import org.wso2.carbon.device.application.mgt.common.Rating;
|
import org.wso2.carbon.device.application.mgt.common.Rating;
|
||||||
import org.wso2.carbon.device.application.mgt.common.Review;
|
import org.wso2.carbon.device.application.mgt.common.Review;
|
||||||
@ -59,7 +58,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
|
|||||||
@PathParam("uuid") String uuid,
|
@PathParam("uuid") String uuid,
|
||||||
@QueryParam("offset") int offSet,
|
@QueryParam("offset") int offSet,
|
||||||
@QueryParam("limit") int limit) {
|
@QueryParam("limit") int limit) {
|
||||||
ReviewManager reviewManager = APIUtil.getCommentsManager();
|
ReviewManager reviewManager = APIUtil.getReviewManager();
|
||||||
PaginationRequest request = new PaginationRequest(offSet, limit);
|
PaginationRequest request = new PaginationRequest(offSet, limit);
|
||||||
try {
|
try {
|
||||||
PaginationResult paginationResult = reviewManager.getAllReviews(request, uuid);
|
PaginationResult paginationResult = reviewManager.getAllReviews(request, uuid);
|
||||||
@ -78,29 +77,34 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
|
|||||||
public Response addReview(
|
public Response addReview(
|
||||||
@ApiParam Review review,
|
@ApiParam Review review,
|
||||||
@PathParam("uuid") String uuid) {
|
@PathParam("uuid") String uuid) {
|
||||||
ReviewManager reviewManager = APIUtil.getCommentsManager();
|
ReviewManager reviewManager = APIUtil.getReviewManager();
|
||||||
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||||
Application application;
|
Application application;
|
||||||
ApplicationRelease applicationRelease;
|
|
||||||
try {
|
try {
|
||||||
application = applicationManager.getApplicationByRelease(uuid);
|
application = applicationManager.getApplicationByRelease(uuid);
|
||||||
applicationRelease = applicationManager.getAppReleaseIfExists(application.getId(), uuid);
|
if (application.getApplicationReleases().isEmpty()){
|
||||||
boolean abc = reviewManager.addReview(review, application.getId(), applicationRelease.getId());
|
String msg = "Couldn't Found an one application release for the UUID: " + uuid;
|
||||||
if (abc) {
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
|
}
|
||||||
|
if (application.getApplicationReleases().size()>1){
|
||||||
|
String msg = "Found more than one application release for the UUID: " + uuid;
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
|
}
|
||||||
|
boolean isReviewCreated = reviewManager
|
||||||
|
.addReview(review, application.getId(), application.getApplicationReleases().get(0).getId());
|
||||||
|
if (isReviewCreated) {
|
||||||
return Response.status(Response.Status.CREATED).entity(review).build();
|
return Response.status(Response.Status.CREATED).entity(review).build();
|
||||||
} else {
|
} else {
|
||||||
String msg = "Given review is not valid ";
|
String msg = "Given review is not valid. Please check the review payload.";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
|
||||||
}
|
}
|
||||||
} catch (ReviewManagementException e) {
|
} catch (ReviewManagementException e) {
|
||||||
String msg = "Error occurred while creating the review";
|
String msg = "Error occurred while creating the review";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
.entity(msg).build();
|
|
||||||
} catch (ApplicationManagementException e) {
|
} catch (ApplicationManagementException e) {
|
||||||
// todo
|
log.error("Error occured while getting the application for application UUID: " + uuid);
|
||||||
log.error("");
|
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
|
||||||
.entity("").build();
|
.entity("").build();
|
||||||
}
|
}
|
||||||
@ -109,41 +113,35 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
|
|||||||
@Override
|
@Override
|
||||||
@PUT
|
@PUT
|
||||||
@Consumes("application/json")
|
@Consumes("application/json")
|
||||||
@Path("/review/{commentId}")
|
@Path("/{uuid}/{reviewId}")
|
||||||
public Response updateComment(
|
public Response updateReview(
|
||||||
@ApiParam Review review,
|
@ApiParam Review review,
|
||||||
@PathParam("commentId") int commentId) {
|
@PathParam("uuid") String uuid,
|
||||||
|
@PathParam("reviewId") int reviewId) {
|
||||||
ReviewManager reviewManager = APIUtil.getCommentsManager();
|
ReviewManager reviewManager = APIUtil.getReviewManager();
|
||||||
try {
|
try {
|
||||||
if (commentId == 0) {
|
if (reviewManager.updateReview(review, reviewId, true)) {
|
||||||
return Response.status(Response.Status.NOT_FOUND)
|
|
||||||
.entity("Review not found").build();
|
|
||||||
} else if (review == null) {
|
|
||||||
String msg = "Given review is not valid ";
|
|
||||||
log.error(msg);
|
|
||||||
return Response.status(Response.Status.BAD_REQUEST).build();
|
|
||||||
} else if (reviewManager.updateReview(review, commentId, true)) {
|
|
||||||
return Response.status(Response.Status.OK).entity(review).build();
|
return Response.status(Response.Status.OK).entity(review).build();
|
||||||
} else {
|
} else {
|
||||||
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("").build();
|
String msg = "Review updating failed. Please contact the administrator";
|
||||||
|
log.error(msg);
|
||||||
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
}
|
}
|
||||||
} catch (ReviewManagementException e) {
|
} catch (ReviewManagementException 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)
|
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
|
||||||
.entity(msg).build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@DELETE
|
@DELETE
|
||||||
@Path("/comment/{commentId}")
|
@Path("/{commentId}")
|
||||||
public Response deleteComment(
|
public Response deleteComment(
|
||||||
@PathParam("commentId") int commentId,
|
@PathParam("commentId") int commentId,
|
||||||
@QueryParam("username") String username) {
|
@QueryParam("username") String username) {
|
||||||
|
|
||||||
ReviewManager reviewManager = APIUtil.getCommentsManager();
|
ReviewManager reviewManager = APIUtil.getReviewManager();
|
||||||
try {
|
try {
|
||||||
if (commentId == 0) {
|
if (commentId == 0) {
|
||||||
return Response.status(Response.Status.NOT_FOUND).entity("Review not found").build();
|
return Response.status(Response.Status.NOT_FOUND).entity("Review not found").build();
|
||||||
@ -164,8 +162,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
|
|||||||
@Path("/{uuid}/rating")
|
@Path("/{uuid}/rating")
|
||||||
public Response getRating(
|
public Response getRating(
|
||||||
@PathParam("uuid") String uuid) {
|
@PathParam("uuid") String uuid) {
|
||||||
|
ReviewManager reviewManager = APIUtil.getReviewManager();
|
||||||
ReviewManager reviewManager = APIUtil.getCommentsManager();
|
|
||||||
Rating rating;
|
Rating rating;
|
||||||
try {
|
try {
|
||||||
rating = reviewManager.getRating(uuid);
|
rating = reviewManager.getRating(uuid);
|
||||||
|
|||||||
@ -141,7 +141,7 @@ import static org.mockito.MockitoAnnotations.initMocks;
|
|||||||
public void testUpdateComment() throws Exception {
|
public void testUpdateComment() throws Exception {
|
||||||
Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||||
Response response = this.commentManagementAPI.updateComment(review, 1);
|
Response response = this.commentManagementAPI.updateReview(review, 1);
|
||||||
Assert.assertNotNull(response, "The response object is null.");
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
|
||||||
"The response status should be 200.");
|
"The response status should be 200.");
|
||||||
@ -150,7 +150,7 @@ import static org.mockito.MockitoAnnotations.initMocks;
|
|||||||
@Test
|
@Test
|
||||||
public void testUpdateNullComment() throws Exception {
|
public void testUpdateNullComment() throws Exception {
|
||||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||||
Response response = this.commentManagementAPI.updateComment(null, 1);
|
Response response = this.commentManagementAPI.updateReview(null, 1);
|
||||||
Assert.assertNotNull(response, "The response object is null.");
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
|
||||||
"The response status should be 400.");
|
"The response status should be 400.");
|
||||||
@ -160,7 +160,7 @@ import static org.mockito.MockitoAnnotations.initMocks;
|
|||||||
public void testUpdateCommentWhenNullCommentId() throws Exception {
|
public void testUpdateCommentWhenNullCommentId() throws Exception {
|
||||||
Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||||
Response response = this.commentManagementAPI.updateComment(review, 0);
|
Response response = this.commentManagementAPI.updateReview(review, 0);
|
||||||
Assert.assertNotNull(response, "The response object is null.");
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
|
Assert.assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(),
|
||||||
"The response status should be 404.");
|
"The response status should be 404.");
|
||||||
@ -171,7 +171,7 @@ import static org.mockito.MockitoAnnotations.initMocks;
|
|||||||
Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
Review review = CommentMgtTestHelper.getDummyComment("a", "a");
|
||||||
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getReviewManager")).toReturn(this.reviewManager);
|
||||||
Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager).updateReview(review, 9, true);
|
Mockito.doThrow(new ReviewManagementException()).when(this.reviewManager).updateReview(review, 9, true);
|
||||||
Response response = this.commentManagementAPI.updateComment(review, 9);
|
Response response = this.commentManagementAPI.updateReview(review, 9);
|
||||||
Assert.assertNotNull(response, "The response object is null.");
|
Assert.assertNotNull(response, "The response object is null.");
|
||||||
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
|
||||||
"The response status should be 500.");
|
"The response status should be 500.");
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user