Improve comment management

4.x.x
lasanthaDLPDS 6 years ago
parent 2fd7601139
commit e5ef68fa3c

@ -21,8 +21,6 @@ package org.wso2.carbon.device.application.mgt.common;
import org.wso2.carbon.device.application.mgt.common.jaxrs.Exclude;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
/**
* This class holds the details when releasing an Application to application store.
@ -78,28 +76,26 @@ public class ApplicationRelease {
private String metaData;
private int noOfRatedUsers;
private int ratedUsers;
private int stars;
private Double rating;
private String url;
private boolean isPublishedRelease;
public int getNoOfRatedUsers() {
return noOfRatedUsers;
public int getRatedUsers() {
return ratedUsers;
}
public void setNoOfRatedUsers(int noOfRatedUsers) {
this.noOfRatedUsers = noOfRatedUsers;
public void setRatedUsers(int ratedUsers) {
this.ratedUsers = ratedUsers;
}
public int getStars() {
return stars;
public Double getRating() {
return rating;
}
public void setStars(int stars) {
this.stars = stars;
public void setRating(Double rating) {
this.rating = rating;
}
public void setId(int id) {
@ -302,11 +298,4 @@ public class ApplicationRelease {
this.url = url;
}
public boolean isPublishedRelease() {
return isPublishedRelease;
}
public void setPublishedRelease(boolean publishedRelease) {
isPublishedRelease = publishedRelease;
}
}

@ -1,137 +0,0 @@
/*
* 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;
import java.util.Date;
import java.util.List;
/**
* Represents an lifecycle of an {@link Application}.
*/
public class Lifecycle {
private int id;
private Date createdAt;
private String createdBy;
private int isApproved;
private String approvedBy;
private Date approvedAt;
private int isPublished;
private String publishedBy;
private Date publishedAt;
private int isRetired;
private List<LifecycleStateTransition> lifecycleStateTransition;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
public int getIsApproved() {
return isApproved;
}
public void setIsApproved(int isApproved) {
this.isApproved = isApproved;
}
public String getApprovedBy() {
return approvedBy;
}
public void setApprovedBy(String approvedBy) {
this.approvedBy = approvedBy;
}
public Date getApprovedAt() {
return approvedAt;
}
public void setApprovedAt(Date approvedAt) {
this.approvedAt = approvedAt;
}
public int getIsPublished() {
return isPublished;
}
public void setIsPublished(int isPublished) {
this.isPublished = isPublished;
}
public String getPublishedBy() {
return publishedBy;
}
public void setPublishedBy(String publishedBy) {
this.publishedBy = publishedBy;
}
public Date getPublishedAt() {
return publishedAt;
}
public void setPublishedAt(Date publishedAt) {
this.publishedAt = publishedAt;
}
public int getIsRetired() {
return isRetired;
}
public void setIsRetired(int isRetired) {
this.isRetired = isRetired;
}
public List<LifecycleStateTransition> getLifecycleStateTransition() {
return lifecycleStateTransition;
}
public void setLifecycleStateTransition(List<LifecycleStateTransition> lifecycleStateTransition) {
this.lifecycleStateTransition = lifecycleStateTransition;
}
}

@ -53,7 +53,7 @@ public interface ApplicationDAO {
* @param tenantId tenantId that need to identify application.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
int isExistApplication(String appName, String type, int tenantId) throws ApplicationManagementDAOException;
boolean isExistApplication(String appName, String type, int tenantId) throws ApplicationManagementDAOException;
/**
* To get the applications that satisfy the given criteria.

@ -42,11 +42,11 @@ import java.util.List;
* @param createdBy Username of the created person.
* @param parentId parent id of the parent comment.
* @param uuid uuid of the application
* @return Comment Id
* @return If comment is added successfully, it return true otherwise false
* @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception.
*/
int addComment(int tenantId, Comment comment, String createdBy, int parentId, String uuid)
boolean addComment(int tenantId, Comment comment, String createdBy, int parentId, String uuid)
throws CommentManagementException, DBConnectionException, SQLException;
/**

@ -171,7 +171,7 @@ public class Util {
appRelease.setCreatedAt(rs.getTimestamp("CREATED_AT"));
appRelease.setPublishedBy(rs.getString("PUBLISHED_BY"));
appRelease.setPublishedAt(rs.getTimestamp("PUBLISHED_AT"));
appRelease.setStars(rs.getInt("STARS"));
appRelease.setRating(rs.getInt("STARS"));
appRelease.setIsSharedWithAllTenants(rs.getInt("SHARED_WITH_ALL_TENANTS"));
appRelease.setMetaData(rs.getString("APP_META_INFO"));
appRelease.setScreenshotLoc1(rs.getString("SC_1_LOCATION"));

@ -46,10 +46,10 @@ import java.util.List;
public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
private static final Log log = LogFactory.getLog(CommentDAOImpl.class);
String sql;
private String sql;
@Override
public int addComment(int tenantId, Comment comment, String createdBy, int parentId, String uuid)
public boolean addComment(int tenantId, Comment comment, String createdBy, int parentId, String uuid)
throws CommentManagementException, DBConnectionException, SQLException {
if (log.isDebugEnabled()) {
@ -58,7 +58,6 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
Connection conn = this.getDBConnection();
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,"
+ "AP_APP_ID) VALUES (?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?),"
+ "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));";
@ -72,10 +71,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
statement.setString(6, uuid);
statement.executeUpdate();
rs = statement.getGeneratedKeys();
if (rs.next()) {
commentId = rs.getInt(1);
}
return commentId;
return rs.next();
} finally {
Util.cleanupResources(statement, rs);
}
@ -924,7 +920,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
int numORows = resultSet.getRow();
if (resultSet.next()) {
ApplicationRelease applicationRelease = new ApplicationRelease();
applicationRelease.setStars(resultSet.getInt("STARS"));
applicationRelease.setRating(resultSet.getDouble("RATING"));
Util.cleanupResources(statement, resultSet);
}
} catch (SQLException e) {
@ -987,7 +983,7 @@ public class CommentDAOImpl extends AbstractDAOImpl implements CommentDAO {
if (resultSet.next()) {
ApplicationRelease applicationRelease = new ApplicationRelease();
ratedUsers = resultSet.getInt("NO_OF_RATED_USERS");
applicationRelease.setNoOfRatedUsers(ratedUsers);
applicationRelease.setRatedUsers(ratedUsers);
Util.cleanupResources(statement, resultSet);
return ratedUsers;
}

@ -94,14 +94,13 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
}
@Override
public int isExistApplication(String appName, String type, int tenantId) throws ApplicationManagementDAOException {
public boolean isExistApplication(String appName, String type, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to verify whether the registering app is registered or not");
}
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
int isExist = 0;
String sql = "SELECT * FROM AP_APP WHERE NAME = ? AND TYPE = ? AND TENANT_ID = ?";
try {
conn = this.getDBConnection();
@ -111,11 +110,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
stmt.setString(2, type);
stmt.setInt(3, tenantId);
rs = stmt.executeQuery();
if (rs.next()) {
isExist = 1;
}
return isExist;
return rs.next();
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(

@ -112,7 +112,6 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
Connection connection;
PreparedStatement statement = null;
ResultSet resultSet = null;
ApplicationRelease applicationRelease = null;
String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE,"
+ " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, "
+ "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, "
@ -134,31 +133,9 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
resultSet = statement.executeQuery();
if (resultSet.next()) {
applicationRelease = new ApplicationRelease();
applicationRelease.setId(resultSet.getInt("RELEASE_ID"));
applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION"));
applicationRelease.setUuid(resultSet.getString("UUID"));
applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE"));
applicationRelease.setPrice(resultSet.getDouble("APP_PRICE"));
applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION"));
applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION"));
applicationRelease.setScreenshotLoc1(resultSet.getString("SCREEN_SHOT_1"));
applicationRelease.setScreenshotLoc2(resultSet.getString("SCREEN_SHOT_2"));
applicationRelease.setScreenshotLoc3(resultSet.getString("SCREEN_SHOT_3"));
applicationRelease.setAppHashValue(resultSet.getString("HASH_VALUE"));
applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED"));
applicationRelease.setMetaData(resultSet.getString("APP_META_INFO"));
applicationRelease.setApplicationCreator(resultSet.getString("CREATED_BY"));
applicationRelease.setCreatedAt(resultSet.getTimestamp("CREATED_AT"));
applicationRelease.setPublishedBy(resultSet.getString("PUBLISHED_BY"));
applicationRelease.setPublishedAt(resultSet.getTimestamp("PUBLISHED_AT"));
applicationRelease.setStars(resultSet.getInt("STARS"));
applicationRelease.setCurrentState(resultSet.getString("CURRENT_STATE"));
applicationRelease.setPreviousState(resultSet.getString("PREVIOUSE_STATE"));
applicationRelease.setStateModifiedBy(resultSet.getString("UPDATED_BY"));
applicationRelease.setStateModifiedAt(resultSet.getTimestamp("UPDATED_AT"));
return constructApplicationRelease(resultSet);
}
return applicationRelease;
return null;
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Database connection exception while trying to get the "
+ "release details of the application with " + applicationName + " and version " +
@ -186,7 +163,6 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
Connection connection;
PreparedStatement statement = null;
ResultSet resultSet = null;
ApplicationRelease applicationRelease = null;
String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE,"
+ " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, "
+ "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS " +
@ -205,31 +181,9 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
resultSet = statement.executeQuery();
if (resultSet.next()) {
applicationRelease = new ApplicationRelease();
applicationRelease.setId(resultSet.getInt("RELEASE_ID"));
applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION"));
applicationRelease.setUuid(resultSet.getString("UUID"));
applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE"));
applicationRelease.setPrice(resultSet.getDouble("APP_PRICE"));
applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION"));
applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION"));
applicationRelease.setScreenshotLoc1(resultSet.getString("SCREEN_SHOT_1"));
applicationRelease.setScreenshotLoc2(resultSet.getString("SCREEN_SHOT_2"));
applicationRelease.setScreenshotLoc3(resultSet.getString("SCREEN_SHOT_3"));
applicationRelease.setAppHashValue(resultSet.getString("HASH_VALUE"));
applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED"));
applicationRelease.setMetaData(resultSet.getString("APP_META_INFO"));
applicationRelease.setApplicationCreator(resultSet.getString("CREATED_BY"));
applicationRelease.setCreatedAt(resultSet.getTimestamp("CREATED_AT"));
applicationRelease.setPublishedBy(resultSet.getString("PUBLISHED_BY"));
applicationRelease.setPublishedAt(resultSet.getTimestamp("PUBLISHED_AT"));
applicationRelease.setStars(resultSet.getInt("STARS"));
applicationRelease.setCurrentState(resultSet.getString("CURRENT_STATE"));
applicationRelease.setPreviousState(resultSet.getString("PREVIOUSE_STATE"));
applicationRelease.setStateModifiedBy(resultSet.getString("UPDATED_BY"));
applicationRelease.setStateModifiedAt(resultSet.getTimestamp("UPDATED_AT"));
return constructApplicationRelease(resultSet);
}
return applicationRelease;
return null;
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Database connection exception while trying to get the release details of the " +
@ -296,7 +250,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
applicationRelease.setCreatedAt(resultSet.getTimestamp("CREATED_AT"));
applicationRelease.setPublishedBy(resultSet.getString("PUBLISHED_BY"));
applicationRelease.setPublishedAt(resultSet.getTimestamp("PUBLISHED_AT"));
applicationRelease.setStars(resultSet.getInt("STARS"));
applicationRelease.setRating(resultSet.getDouble("RATING"));
applicationReleases.add(applicationRelease);
}
@ -417,4 +371,37 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
}
}
/**
* This method is capable to construct {@ApplicationRelease} and return the object
* @param resultSet result set obtained from the query executing.
* @throws SQLException SQL exception while accessing result set data.
*/
private ApplicationRelease constructApplicationRelease(ResultSet resultSet) throws SQLException {
ApplicationRelease applicationRelease = new ApplicationRelease();
applicationRelease.setId(resultSet.getInt("RELEASE_ID"));
applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION"));
applicationRelease.setUuid(resultSet.getString("UUID"));
applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE"));
applicationRelease.setPrice(resultSet.getDouble("APP_PRICE"));
applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION"));
applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION"));
applicationRelease.setScreenshotLoc1(resultSet.getString("SCREEN_SHOT_1"));
applicationRelease.setScreenshotLoc2(resultSet.getString("SCREEN_SHOT_2"));
applicationRelease.setScreenshotLoc3(resultSet.getString("SCREEN_SHOT_3"));
applicationRelease.setAppHashValue(resultSet.getString("HASH_VALUE"));
applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED"));
applicationRelease.setMetaData(resultSet.getString("APP_META_INFO"));
applicationRelease.setApplicationCreator(resultSet.getString("CREATED_BY"));
applicationRelease.setCreatedAt(resultSet.getTimestamp("CREATED_AT"));
applicationRelease.setPublishedBy(resultSet.getString("PUBLISHED_BY"));
applicationRelease.setPublishedAt(resultSet.getTimestamp("PUBLISHED_AT"));
applicationRelease.setRating(resultSet.getDouble("RATING"));
applicationRelease.setCurrentState(resultSet.getString("CURRENT_STATE"));
applicationRelease.setPreviousState(resultSet.getString("PREVIOUS_STATE"));
applicationRelease.setStateModifiedBy(resultSet.getString("UPDATED_BY"));
applicationRelease.setStateModifiedAt(resultSet.getTimestamp("UPDATED_AT"));
return applicationRelease;
}
}

@ -99,6 +99,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationRelease applicationRelease;
try {
ConnectionManagerUtil.beginDBTransaction();
// todo think about web clip and try to remove application - type
deviceType = this.deviceTypeDAO.getDeviceType(application.getType(), tenantId);
if (deviceType == null) {
@ -351,12 +352,12 @@ public class ApplicationManagerImpl implements ApplicationManager {
applicationReleases = ApplicationManagementDAOFactory.getApplicationReleaseDAO()
.getReleases(application.getName(), application.getType(), tenantId);
for (ApplicationRelease applicationRelease : applicationReleases) {
if (AppLifecycleState.PUBLISHED.toString().equals(ApplicationManagementDAOFactory.getLifecycleStateDAO().
getLatestLifeCycleStateByReleaseID(applicationRelease.getId()).getCurrentState())){
applicationRelease.setPublishedRelease(true);
}
if (!AppLifecycleState.REMOVED.toString().equals(ApplicationManagementDAOFactory.getLifecycleStateDAO().
getLatestLifeCycleStateByReleaseID(applicationRelease.getId()).getCurrentState())) {
LifecycleState lifecycleState = ApplicationManagementDAOFactory.getLifecycleStateDAO().
getLatestLifeCycleStateByReleaseID(applicationRelease.getId());
applicationRelease.setCurrentState(lifecycleState.getCurrentState());
applicationRelease.setPreviousState(lifecycleState.getPreviousState());
if (!AppLifecycleState.REMOVED.toString().equals(applicationRelease.getCurrentState())) {
filteredApplicationReleases.add(applicationRelease);
}
}

@ -65,9 +65,13 @@ public class CommentsManagerImpl implements CommentsManager {
comment.setCreatedAt(Timestamp.from(Instant.now()));
try {
ConnectionManagerUtil.beginDBTransaction();
commentDAO.addComment(tenantId, comment, comment.getCreatedBy(), comment.getParent(), uuid);
if (commentDAO.addComment(tenantId, comment, comment.getCreatedBy(), comment.getParent(), uuid)) {
ConnectionManagerUtil.commitDBTransaction();
return comment;
} else {
ConnectionManagerUtil.rollbackDBTransaction();
return null;
}
} catch (DBConnectionException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw new CommentManagementException(

@ -96,12 +96,12 @@ import java.util.List;
}
)
@Path("/comments")
@Path("/reviews")
@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 {
public interface ReviewManagementAPI {
String SCOPE = "scope";
@GET
@ -191,7 +191,7 @@ public interface CommentManagementAPI {
response = ErrorResponse.class)
})
Response addComments(
Response addComment(
@ApiParam(
name = "comment",
value = "Comment details",
@ -322,7 +322,7 @@ public interface CommentManagementAPI {
response = ErrorResponse.class)
})
Response getStars(
Response getRating(
@ApiParam(
name = "uuid",
value = "uuid of the application release",
@ -359,7 +359,7 @@ public interface CommentManagementAPI {
response = ErrorResponse.class)
})
Response getRatedUser(
Response getNumOfRatedUsers(
@ApiParam(
name = "uuid",
value = "uuid of the application release",
@ -401,7 +401,7 @@ public interface CommentManagementAPI {
response = ErrorResponse.class)
})
Response updateStars(
Response updateRatings(
@ApiParam(
name = "stars",
value = "ratings for the application",

@ -20,6 +20,7 @@ package org.wso2.carbon.device.application.mgt.store.api.services.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.AppLifecycleState;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.store.api.APIUtil;
import org.wso2.carbon.device.application.mgt.common.Application;
@ -48,7 +49,6 @@ import java.util.List;
@Path("/store/applications")
public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
private static final int DEFAULT_LIMIT = 20;
private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class);
@GET
@ -70,7 +70,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
for (Application application : applications.getApplications()) {
for (ApplicationRelease appRelease: application.getApplicationReleases()){
if (appRelease.isPublishedRelease()){
if (AppLifecycleState.PUBLISHED.toString().equals(appRelease.getCurrentState())){
publishedApplicationRelease.add(appRelease);
}
}
@ -110,7 +110,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
}
for (ApplicationRelease appRelease : application.getApplicationReleases()) {
if (appRelease.isPublishedRelease()) {
if (AppLifecycleState.PUBLISHED.toString().equals(appRelease.getCurrentState())){
publishedApplicationRelease.add(appRelease);
}
}

@ -22,7 +22,7 @@ import io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.store.api.APIUtil;
import org.wso2.carbon.device.application.mgt.store.api.services.CommentManagementAPI;
import org.wso2.carbon.device.application.mgt.store.api.services.ReviewManagementAPI;
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;
@ -44,18 +44,18 @@ import java.util.List;
/**
* Comment Management related jax-rs APIs.
*/
@Path("/comments")
public class CommentManagementAPIImpl implements CommentManagementAPI {
@Path("/review")
public class ReviewManagementAPIImpl implements ReviewManagementAPI {
private static Log log = LogFactory.getLog(CommentManagementAPIImpl.class);
private static Log log = LogFactory.getLog(ReviewManagementAPIImpl.class);
@Override
@GET
@Path("/{uuid}")
@Path("/application/{uuid}/comments")
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<Comment> comments = new ArrayList<>();
@ -79,16 +79,15 @@ public class CommentManagementAPIImpl implements CommentManagementAPI {
@Override
@POST
@Consumes("application/json")
@Path("/{uuid}")
public Response addComments(
@Path("/application/{uuid}/comment")
public Response addComment(
@ApiParam Comment comment,
@PathParam("uuid") String uuid) {
CommentsManager commentsManager = APIUtil.getCommentsManager();
try {
Comment newComment = commentsManager.addComment(comment, uuid);
if (comment != null) {
return Response.status(Response.Status.CREATED).entity(newComment).build();
if (commentsManager.addComment(comment, uuid) != null) {
return Response.status(Response.Status.CREATED).entity(comment).build();
} else {
String msg = "Given comment is not valid ";
log.error(msg);
@ -105,7 +104,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI {
@Override
@PUT
@Consumes("application/json")
@Path("/{commentId}")
@Path("/comment/{commentId}")
public Response updateComment(
@ApiParam Comment comment,
@PathParam("commentId") int commentId) {
@ -133,7 +132,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI {
@Override
@DELETE
@Path("/{commentId}")
@Path("/comment/{commentId}")
public Response deleteComment(
@PathParam("commentId") int commentId) {
@ -155,14 +154,14 @@ public class CommentManagementAPIImpl implements CommentManagementAPI {
@Override
@GET
@Path("/{uuid}")
public Response getStars(
@Path("/application/{uuid}/rating")
public Response getRating(
@PathParam("uuid") String uuid) {
CommentsManager commentsManager = APIUtil.getCommentsManager();
int Stars;
int stars;
try {
Stars = commentsManager.getStars(uuid);
stars = commentsManager.getStars(uuid);
} catch (CommentManagementException e) {
log.error("Comment Management Exception occurs", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
@ -172,13 +171,13 @@ public class CommentManagementAPIImpl implements CommentManagementAPI {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(msg).build();
}
return Response.status(Response.Status.OK).entity(Stars).build();
return Response.status(Response.Status.OK).entity(stars).build();
}
@Override
@GET
@Path("/{uuid}")
public Response getRatedUser(
@Path("/application/{uuid}/total-rated-users")
public Response getNumOfRatedUsers(
@PathParam("uuid") String uuid) {
CommentsManager commentsManager = APIUtil.getCommentsManager();
@ -200,9 +199,10 @@ public class CommentManagementAPIImpl implements CommentManagementAPI {
}
@Override
@POST
@PUT
@Consumes("application/json")
public Response updateStars(
@Path("/application/{uuid}/rating")
public Response updateRatings(
@ApiParam int stars,
@PathParam("uuid") String uuid) {

@ -35,7 +35,7 @@ import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManage
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.store.api.APIUtil;
import org.wso2.carbon.device.application.mgt.store.api.services.impl.CommentManagementAPIImpl;
import org.wso2.carbon.device.application.mgt.store.api.services.impl.ReviewManagementAPIImpl;
import org.wso2.carbon.device.application.mgt.store.api.services.util.CommentMgtTestHelper;
import javax.ws.rs.core.Response;
@ -48,9 +48,9 @@ import static org.mockito.MockitoAnnotations.initMocks;
@PrepareForTest({ APIUtil.class, CommentsManager.class,
CommentManagementAPITest.class})
public class CommentManagementAPITest {
private static final Log log = LogFactory.getLog(CommentManagementAPI.class);
private static final Log log = LogFactory.getLog(ReviewManagementAPI.class);
private CommentManagementAPI commentManagementAPI;
private ReviewManagementAPI commentManagementAPI;
private CommentsManager commentsManager;
@ObjectFactory
@ -61,10 +61,10 @@ public class CommentManagementAPITest {
@BeforeClass
void init() throws CommentManagementException {
log.info("Initializing CommentManagementAPI tests");
log.info("Initializing ReviewManagementAPI tests");
initMocks(this);
this.commentsManager = Mockito.mock(CommentsManager.class, Mockito.RETURNS_DEFAULTS);
this.commentManagementAPI = new CommentManagementAPIImpl();
this.commentManagementAPI = new ReviewManagementAPIImpl();
}
@Test
@ -103,7 +103,7 @@ public class CommentManagementAPITest {
public void testAddComments() throws Exception {
Comment comment = CommentMgtTestHelper.getDummyComment("a", "a");
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Response response = this.commentManagementAPI.addComments(comment, "a");
Response response = this.commentManagementAPI.addComment(comment, "a");
Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(),
"The response status should be 201.");
@ -113,7 +113,7 @@ public class CommentManagementAPITest {
@Test
public void testAddNullComment() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Response response = this.commentManagementAPI.addComments(null, "a");
Response response = this.commentManagementAPI.addComment(null, "a");
Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400.");
@ -124,9 +124,9 @@ public class CommentManagementAPITest {
public void testAddCommentsInternalError() throws Exception {
Comment comment = CommentMgtTestHelper.getDummyComment("a", "a");
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Mockito.when(this.commentManagementAPI.addComments(Mockito.any(), Mockito.anyString()))
Mockito.when(this.commentManagementAPI.addComment(Mockito.any(), Mockito.anyString()))
.thenThrow(new CommentManagementException());
Response response = this.commentManagementAPI.addComments(comment, null);
Response response = this.commentManagementAPI.addComment(comment, null);
Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500.");
@ -204,7 +204,7 @@ public class CommentManagementAPITest {
@Test
public void testGetStars() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Response response = this.commentManagementAPI.getStars("a");
Response response = this.commentManagementAPI.getRating("a");
Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"The response status should be 200.");
@ -214,9 +214,9 @@ public class CommentManagementAPITest {
@Test
public void testGetStarsCommentError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Mockito.when(this.commentManagementAPI.getStars(Mockito.anyString()))
Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString()))
.thenThrow(new CommentManagementException());
Response response = this.commentManagementAPI.getStars("a");
Response response = this.commentManagementAPI.getRating("a");
Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500.");
@ -226,9 +226,9 @@ public class CommentManagementAPITest {
@Test
public void testGetStarsApplicationError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Mockito.when(this.commentManagementAPI.getStars(Mockito.anyString()))
Mockito.when(this.commentManagementAPI.getRating(Mockito.anyString()))
.thenThrow(new ApplicationManagementException());
Response response = this.commentManagementAPI.getStars("a");
Response response = this.commentManagementAPI.getRating("a");
Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500.");
@ -238,7 +238,7 @@ public class CommentManagementAPITest {
@Test
public void testGetRatedUser() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Response response = this.commentManagementAPI.getRatedUser("a");
Response response = this.commentManagementAPI.getNumOfRatedUsers("a");
Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode(),
"The response status should be 200.");
@ -248,9 +248,9 @@ public class CommentManagementAPITest {
@Test
public void testGetRatedUserCommentError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Mockito.when(this.commentManagementAPI.getRatedUser(Mockito.anyString()))
Mockito.when(this.commentManagementAPI.getNumOfRatedUsers(Mockito.anyString()))
.thenThrow(new CommentManagementException());
Response response = this.commentManagementAPI.getRatedUser("a");
Response response = this.commentManagementAPI.getNumOfRatedUsers("a");
Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500.");
@ -260,9 +260,9 @@ public class CommentManagementAPITest {
@Test
public void testGetRatedUserApplicationError() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Mockito.when(this.commentManagementAPI.getRatedUser(Mockito.anyString()))
Mockito.when(this.commentManagementAPI.getNumOfRatedUsers(Mockito.anyString()))
.thenThrow(new ApplicationManagementException());
Response response = this.commentManagementAPI.getRatedUser("a");
Response response = this.commentManagementAPI.getNumOfRatedUsers("a");
Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500.");
@ -272,7 +272,7 @@ public class CommentManagementAPITest {
@Test
public void testUpdateStars() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Response response = this.commentManagementAPI.updateStars(3, "a");
Response response = this.commentManagementAPI.updateRatings(3, "a");
Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(),
"The response status should be 201.");
@ -282,7 +282,7 @@ public class CommentManagementAPITest {
@Test
public void testUpdateInvalidStars() throws Exception {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Response response = this.commentManagementAPI.updateStars(0, "a");
Response response = this.commentManagementAPI.updateRatings(0, "a");
Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.BAD_REQUEST.getStatusCode(),
"The response status should be 400.");
@ -294,7 +294,7 @@ public class CommentManagementAPITest {
PowerMockito.stub(PowerMockito.method(APIUtil.class, "getCommentsManager")).toReturn(this.commentsManager);
Mockito.doThrow(new ApplicationManagementException()).when(this.commentsManager)
.updateStars(Mockito.anyInt(), Mockito.anyString());
Response response = this.commentManagementAPI.updateStars(3, "a");
Response response = this.commentManagementAPI.updateRatings(3, "a");
Assert.assertNotNull(response, "The response object is null.");
Assert.assertEquals(response.getStatus(), Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(),
"The response status should be 500.");

Loading…
Cancel
Save