Merge branch 'application-mgt-new' into 'application-mgt-new'

Improve review management and fix store service registration issue

See merge request entgra/carbon-device-mgt!9
feature/appm-store/pbac
Inosh Perara 6 years ago
commit 1c124f45e6

@ -24,7 +24,6 @@ import io.swagger.annotations.ApiModelProperty;
import java.util.List;
@ApiModel(value = "Application", description = "Application represents the an Application in Application Store")
public class Application {

@ -177,7 +177,6 @@ public class ApplicationRelease {
this.price = price;
}
public String getAppHashValue() {
return appHashValue;
}

@ -18,8 +18,6 @@
*/
package org.wso2.carbon.device.application.mgt.common;
import com.google.gson.Gson;
import java.io.Serializable;
/**

@ -1,85 +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;
//TODO
/**
* FilterProperty defines the property that can be used to filter the Application.
*/
public class FilterProperty {
/**
* Operators that can be used in search.
*/
public enum Operator {
EQUALS ("="),
GRATER_THAN (">"),
GREATER_THAN_AND_EQUAL(">="),
LESS_THAN ("<"),
LESS_THAN_AND_EQUAL ("<=");
private final String value;
Operator(String value) {
this.value = value;
}
public String getValue() {
return value;
}
}
public FilterProperty(String key, Operator operator, String value) {
this.key = key;
this.operator = operator;
this.value = value;
}
private String key;
private Operator operator;
private String value;
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public Operator getOperator() {
return operator;
}
public void setOperator(Operator operator) {
this.operator = operator;
}
}

@ -1,34 +0,0 @@
package org.wso2.carbon.device.application.mgt.common;
/**
* This represents the LifeCycleStateTransition from one state to next state.
*/
public class LifecycleStateTransition {
private String nextState;
private String permission;
private String description;
public String getNextState() {
return nextState;
}
public String getPermission() {
return permission;
}
public String getDescription() {
return description;
}
public void setNextState(String nextState) {
this.nextState = nextState;
}
public void setPermission(String permission) {
this.permission = permission;
}
public void setDescription(String description) {
this.description = description;
}
}

@ -1,53 +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;
/**
* Represents the payment related information for the {@link Application}.
*/
public class Payment {
private boolean freeApp;
private String paymentCurrency;
private float paymentPrice;
public boolean isFreeApp() {
return freeApp;
}
public void setFreeApp(boolean freeApp) {
this.freeApp = freeApp;
}
public String getPaymentCurrency() {
return paymentCurrency;
}
public void setPaymentCurrency(String paymentCurrency) {
this.paymentCurrency = paymentCurrency;
}
public float getPaymentPrice() {
return paymentPrice;
}
public void setPaymentPrice(float paymentPrice) {
this.paymentPrice = paymentPrice;
}
}

@ -1,77 +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;
/**
* Represents subscription of an {@link Application}
*/
public class Subscription {
private Visibility.Type type;
private String value;
private Date createdAt;
private Application application;
private ApplicationRelease applicationRelease;
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public Visibility.Type getType() {
return type;
}
public void setType(Visibility.Type type) {
this.type = type;
}
public Date getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Date createdAt) {
this.createdAt = createdAt;
}
public Application getApplication() {
return application;
}
public void setApplication(Application application) {
this.application = application;
}
public ApplicationRelease getApplicationRelease() {
return applicationRelease;
}
public void setApplicationRelease(ApplicationRelease applicationRelease) {
this.applicationRelease = applicationRelease;
}
}

@ -1,54 +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.List;
/**
* This class represents the visibility details of an Application.
*/
public class Visibility {
private Type type;
private List<String> allowedList;
public Type getType() {
return type;
}
public void setType(Type type) {
this.type = type;
}
public List<String> getAllowedList() {
return allowedList;
}
public void setAllowedList(List<String> allowedList) {
this.allowedList = allowedList;
}
/**
* Type of the visibility of the application.
*/
public enum Type {
PUBLIC, ROLES, DEVICE_GROUPS
}
}

@ -0,0 +1,45 @@
/*
* Copyright (c) 2018, 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.exception;
public class ReviewDoesNotExistException extends Exception {
private String message;
public ReviewDoesNotExistException(String message, Throwable throwable) {
super(message, throwable);
setMessage(message);
}
public ReviewDoesNotExistException(String message) {
super(message);
setMessage(message);
}
public ReviewDoesNotExistException() {
}
@Override public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}

@ -23,10 +23,8 @@ import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.LifecycleStateTransition;
import org.wso2.carbon.device.application.mgt.common.UnrestrictedRole;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.LifecycleManagementException;
import java.util.List;

@ -22,25 +22,29 @@ 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.PaginationRequest;
import org.wso2.carbon.device.application.mgt.common.PaginationResult;
import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewDoesNotExistException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException;
/**
* ReviewManager is responsible for handling all the add/update/delete/get operations related with
*/
public interface ReviewManager {
/**
* To add a review to a application
* To add a review to an application release
*
* @param review review of the application.
* @param uuid uuid of the application release.
* @return {@link Review} Review added
* @throws ReviewManagementException Exceptions of the review management.
*/
boolean addReview(Review review, String uuid) throws ReviewManagementException;
boolean addReview(Review review, String uuid) throws ReviewManagementException, RequestValidatingException;
/**
* Get all comments to pagination
* Get all review with pagination
*
* @param request Pagination request {@link PaginationRequest}
* @param uuid uuid of the application release
@ -49,15 +53,6 @@ public interface ReviewManager {
*/
PaginationResult getAllReviews(PaginationRequest request, String uuid) throws ReviewManagementException;
/**
* To get the comment with id.
*
* @param commentId id of the comment
* @return {@link Review}Review of the comment id
* @throws ReviewManagementException Exceptions of the comment management.
*/
Review getReview(int commentId) throws ReviewManagementException;
/**
* To delete review using review id.
*
@ -66,7 +61,8 @@ public interface ReviewManager {
* @return If review is successfully deleted return true, otherwise returns false
* @throws ReviewManagementException Exceptions of the comment management
*/
boolean deleteReview(String uuid, int commentId) throws ReviewManagementException;
boolean deleteReview(String uuid, int commentId)
throws ReviewManagementException, ReviewDoesNotExistException;
/**
* To update a review.
@ -74,12 +70,13 @@ public interface ReviewManager {
* @param review review of the application.
* @param reviewId id of the review
* @param uuid UUID of the application release
* @param checkExistence Pass true if it is required to check the existence of the review, otherwise pass false
* @param existingReview Pass existing review when same user adding a review for same application release,
* otherwise pass null
* @return {@link Review}updated review
* @throws ReviewManagementException Exceptions of the review management
*/
boolean updateReview(Review review, int reviewId, String uuid, boolean checkExistence)
throws ReviewManagementException;
boolean updateReview(Review review, int reviewId, String uuid, Review existingReview)
throws ReviewManagementException, RequestValidatingException;
/**
* To get the overall rating for a application release

@ -1,59 +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.services;
import org.wso2.carbon.device.application.mgt.common.UnrestrictedRole;
import org.wso2.carbon.device.application.mgt.common.Visibility;
import org.wso2.carbon.device.application.mgt.common.exception.VisibilityManagementException;
import java.util.List;
/**
* This interface manages all the operations related with Application Visibility.
* This will be invoking the necessary backend calls for the data bases layer
* and provide the functional implementation.
*/
public interface UnrestrictedRoleManager {
/**
* Add (if there is no visibility configuration for the application) or
* Update (if there is already existing configuration for the application)
* the visibility related configuration for the application
*
* @param applicationID The ID of the application
* @param visibility The visibility configuration for the particular application.
*/
Visibility put(int applicationID, Visibility visibility) throws VisibilityManagementException;
/**
* Returns the Visibility configuration of the provided applicationUUID.
*
* @param applicationID The ID of the application
* @param tenantId tenant Id
* @return Visibility configuration
*/
List<UnrestrictedRole> getUnrestrictedRoles(int applicationID, int tenantId) throws VisibilityManagementException;
/**
* Remove the visibility configuration mapping for the provided application.
*
* @param applicationID The ID of the application
*/
void remove(int applicationID) throws VisibilityManagementException;
}

@ -81,19 +81,21 @@ public interface ApplicationReleaseDAO {
/**
* To update an Application release.
* @param id id of the ApplicationRelease that need to be updated.
* @param uuid UUID of the ApplicationRelease that need to be updated.
* @param rating given stars for the application.
* @param ratedUsers number of users who has rated for the application release.
* @throws ApplicationManagementDAOException Application Management DAO Exception
*/
int updateRatingValue(int id, double rating, int ratedUsers) throws ApplicationManagementDAOException;
void updateRatingValue(String uuid, double rating, int ratedUsers) throws ApplicationManagementDAOException;
/**
* To retrieve rating of an application release.
*
* @param uuid UUID of the application Release.
* @param tenantId Tenant Id
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
Rating getRating(String uuid) throws ApplicationManagementDAOException;
Rating getRating(String uuid, int tenantId) throws ApplicationManagementDAOException;
/**

@ -45,7 +45,7 @@ import java.util.List;
boolean addReview(Review review, String uuid, int tenantId) throws ReviewManagementDAOException;
/**
* To verify whether review is exists or not.
* To verify whether user has already commented for the application release or not.
*
* @param uuid UUID of the application release.
* @param username username of the logged in user.
@ -58,33 +58,33 @@ import java.util.List;
/**
* To update already added comment.
*
* @return {@link Review}Updated comment
* @throws ReviewManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception
* @throws SQLException sql exception
* @param review Updating review
* @param reviewId id of the updating review
* @param username review owner
* @param tenantId tenant id
* @return row count if updating is succeed otherwise 0
* @throws ReviewManagementDAOException Exceptions of the review management.
*/
boolean updateReview(Review review, int reviewId, int tenantId)
throws ReviewManagementException, DBConnectionException, SQLException;
int updateReview(Review review, int reviewId, String username, int tenantId)
throws ReviewManagementDAOException;
/**
* To get the comment with id.
*
* @param commentId id of the comment
* @param reviewId id of the review
* @return {@link Review}Review
* @throws ReviewManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception
* @throws SQLException sql exception
* @throws ReviewManagementDAOException Exceptions of the review management DAO.
*/
Review getReview(int commentId) throws ReviewManagementException, SQLException, DBConnectionException;
Review getReview(int reviewId) throws ReviewManagementDAOException;
/**
* To get all the comments
* To get all reviews
*
* @param uuid uuid of the application
* @param request {@link PaginationRequest}pagination request with offSet and limit
* @param tenantId Tenant id
* @return {@link List}List of all the comments in an application
* @return {@link List}List of all reviews for the application release
* @throws ReviewManagementDAOException Review management DAO exception
**/
List<Review> getAllReviews(String uuid, PaginationRequest request, int tenantId)
@ -92,11 +92,12 @@ import java.util.List;
/**
* To get list of comments using release id and application id.
*
* @param uuid UUID of the application release
* @param tenantId tenant id
* @return {@link List}List of comments
* @throws ReviewManagementException Exceptions of the comment management.
* @throws ReviewManagementDAOException Exceptions of the review management DAO.
*/
List<Integer> getAllRatingValues(String uuid)throws SQLException, DBConnectionException;
List<Integer> getAllRatingValues(String uuid, int tenantId) throws ReviewManagementDAOException;
/**
* To get count of comments by application details.
@ -122,15 +123,6 @@ import java.util.List;
*/
int deleteReview(String username, int reviewId) throws ReviewManagementDAOException;
/**
* To delete review using review id, in this case, it doesn't check whether user is review owner or not.
*
* @param reviewId id of the review
* @return If review is successfully deleted return 1, otherwise returns 0.
* @throws ReviewManagementDAOException Review management DAO exception.
*/
int deleteReviewByAdmin(int reviewId) throws ReviewManagementDAOException;
/**
* To delete comments using application details.
*
@ -142,12 +134,11 @@ import java.util.List;
void deleteReviews(String appType, String appName, String version) throws ReviewManagementException;
/**
* To get comment count for pagination
* To get review count for a specific application release
*
* @param request pagination request
* @param uuid uuid of the application release
* @return Review count
* @throws ReviewManagementException
* @throws ReviewManagementDAOException Review management DAO exception
*/
int getReviewCount(PaginationRequest request, String uuid) throws ReviewManagementException;
int getReviewCount(String uuid) throws ReviewManagementDAOException;
}

@ -23,7 +23,7 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.exception.UnsupportedDatabaseEngineException;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.dao.*;
import org.wso2.carbon.device.application.mgt.core.dao.impl.Comment.ReviewDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.Review.ReviewDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.release.GenericApplicationReleaseDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.OracleApplicationDAOImpl;

@ -16,7 +16,7 @@
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.core.dao.impl.Comment;
package org.wso2.carbon.device.application.mgt.core.dao.impl.Review;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -28,7 +28,6 @@ import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionExcep
import org.wso2.carbon.device.application.mgt.core.dao.ReviewDAO;
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.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.exception.ReviewManagementDAOException;
import java.sql.SQLException;
@ -48,14 +47,13 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
private String sql;
@Override
public boolean addReview(Review review, String uuid, int tenantId)
throws ReviewManagementDAOException {
public boolean addReview(Review review, String uuid, int tenantId) throws ReviewManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to add review for application release. Application UUID: " + uuid);
}
PreparedStatement statement = null;
ResultSet rs = null;
sql = "INSERT INTO AP_APP_Review (TENANT_ID, COMMENT, PARENT_ID, USERNAME, AP_APP_RELEASE_ID, AP_APP_ID) "
sql = "INSERT INTO AP_APP_REVIEW (TENANT_ID, COMMENT, PARENT_ID, USERNAME, 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=?));";
try {
@ -102,7 +100,6 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
statement.setString(1, uuid);
statement.setString(2, username);
statement.setInt(3, tenantId);
rs = statement.executeQuery();
if (rs.next()){
review = new Review();
@ -128,7 +125,8 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
}
@Override
public boolean updateReview(Review review, int reviewId, int tenantId) throws ReviewManagementException, DBConnectionException, SQLException {
public int updateReview(Review review, int reviewId, String username, int tenantId)
throws ReviewManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to update the comment with ID (" + reviewId + ")");
@ -136,55 +134,59 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
Connection connection;
PreparedStatement statement = null;
ResultSet rs = null;
sql = "UPDATE AP_APP_COMMENT SET COMMENT_TEXT=?, MODEFIED_BY=? WHERE ID=?;";
sql = "UPDATE AP_APP_REVIEW SET COMMENT=?, RATING=? WHERE ID=? AND USERNAME=? AND TENANT_ID=?;";
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql);
// statement.setString(1, updatedComment);
// statement.setString(2, modifiedBy);
statement.setString(1, review.getComment());
statement.setInt(2, review.getRating());
statement.setInt(3, reviewId);
statement.executeUpdate();
rs = statement.executeQuery();
statement.setString(4, username);
statement.setInt(5, tenantId);
return statement.executeUpdate();
} catch (SQLException e) {
throw new ReviewManagementDAOException("Error occurred while executing review updating query");
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException("Error occured while getting the db connection to update review");
} finally {
Util.cleanupResources(statement, rs);
}
// todo
return false;
}
@Override
public Review getReview(int commentId) throws ReviewManagementException {
public Review getReview(int reviewId) throws ReviewManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting review with the review id(" + commentId + ") from the database");
log.debug("Getting review with the review id(" + reviewId + ") from the database");
}
Connection conn;
PreparedStatement statement = null;
ResultSet rs;
ResultSet rs = null;
Review review = new Review();
try {
conn = this.getDBConnection();
sql = "SELECT COMMENT_TEXT FROM AP_APP_COMMENT WHERE ID=?;";
sql = "SELECT ID, COMMENT, CREATED_AT, MODIFIED_AT, RATING, USERNAME FROM AP_APP_REVIEWE WHERE ID=?;";
statement = conn.prepareStatement(sql);
statement.setInt(1, commentId);
statement.setInt(1, reviewId);
rs = statement.executeQuery();
if (rs.next()) {
review.setId(rs.getInt("ID"));
// review.setTenantId(rs.getInt("TENANT_ID"));
review.setComment(rs.getString("COMMENT_TEXT"));
review.setComment(rs.getString("COMMENT"));
review.setCreatedAt(rs.getTimestamp("CREATED_AT"));
review.setUsername(rs.getString("CREATED_BY"));
review.setModifiedAt(rs.getTimestamp("MODEFIED_AT"));
Util.cleanupResources(statement, rs);
review.setModifiedAt(rs.getTimestamp("MODIFIED_AT"));
review.setRating(rs.getInt("RATING"));
review.setUsername(rs.getString("USERNAME"));
return review;
}
} catch (SQLException e) {
throw new ReviewManagementException(
"SQL Error occurred while retrieving information of the review " + commentId, e);
throw new ReviewManagementDAOException(
"SQL Error occurred while retrieving information of the review " + reviewId, e);
} catch (DBConnectionException e) {
log.error("DB Connection Exception occurred while retrieving information of the review " + commentId, e);
throw new ReviewManagementDAOException(
"DB Connection Exception occurred while retrieving information of the review " + reviewId, e);
} finally {
Util.cleanupResources(statement, null);
Util.cleanupResources(statement, rs);
}
return review;
}
@ -202,11 +204,11 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
List<Review> reviews = new ArrayList<>();
try {
conn = this.getDBConnection();
sql = "SELECT AP_APP_COMMENT.ID AS ID, AP_APP_COMMENT.COMMENT_TEXT AS COMMENT_TEXT, "
+ "AP_APP_COMMENT.CREATED_BY AS CREATED_BY, AP_APP_COMMENT.MODIFIED_BY AS MODIFIED_BY, "
+ "AP_APP_COMMENT.PARENT_ID AS PARENT_ID FROM AP_APP_COMMENT, AP_APP_RELEASE WHERE "
+ "AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_RELEASE.UUID =? AND "
+ "AP_APP_COMMENT.TENANT_ID = ? AND AP_APP_COMMENT.TENANT_ID = AP_APP_RELEASE.TENANT_ID "
sql = "SELECT AP_APP_REVIEW.ID AS ID, AP_APP_REVIEW.COMMENT AS COMMENT, "
+ "AP_APP_REVIEW.CREATED_BY AS CREATED_BY, AP_APP_REVIEW.MODIFIED_BY AS MODIFIED_BY, "
+ "AP_APP_REVIEW.PARENT_ID AS PARENT_ID FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE "
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_RELEASE.UUID =? AND "
+ "AP_APP_REVIEW.TENANT_ID = ? AND AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID "
+ "LIMIT ? OFFSET ?;";
statement = conn.prepareStatement(sql);
statement.setString(1, uuid);
@ -233,7 +235,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
}
@Override
public List<Integer> getAllRatingValues(String uuid)throws SQLException, DBConnectionException {
public List<Integer> getAllRatingValues(String uuid, int tenantId) throws ReviewManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting comment of the application release (" + uuid + ") from the database");
@ -244,18 +246,24 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
List<Integer> reviews = new ArrayList<>();
try {
conn = this.getDBConnection();
// todo
sql = "SELECT AP_APP_COMMENT.ID AS ID, AP_APP_COMMENT.COMMENT_TEXT AS "
+ "COMMENT_TEXT, AP_APP_COMMENT.CREATED_BY AS CREATED_BY, AP_APP_COMMENT.MODIFIED_BY AS "
+ "MODIFIED_BY, AP_APP_COMMENT.PARENT_ID AS PARENT_ID FROM AP_APP_COMMENT, AP_APP_RELEASE WHERE "
+ "AP_APP_COMMENT.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_RELEASE.UUID =? AND "
+ "AP_APP_COMMENT.TENANT_ID = ? AND AP_APP_COMMENT.TENANT_ID = AP_APP_RELEASE.TENANT_ID;";
sql = "SELECT AP_APP_COMMENT.RATING AS RATING FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE "
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_RELEASE.UUID =? AND "
+ "AP_APP_COMMENT.TENANT_ID = AP_APP_RELEASE.TENANT_ID AND AP_APP_COMMENT.TENANT_ID = ?;";
statement = conn.prepareStatement(sql);
statement.setString(1, uuid);
statement.setInt(2, tenantId);
rs = statement.executeQuery();
while (rs.next()) {
reviews.add(rs.getInt("RATING"));
}
} catch (SQLException e) {
throw new ReviewManagementDAOException(
"Error occured while getting all rating values for the application release. App release UUID: "
+ uuid, e);
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException(
"Error occured while getting DB connection to retrieve all rating values for the application release. App release UUID: "
+ uuid, e);
} finally {
Util.cleanupResources(statement, rs);
}
@ -263,7 +271,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
}
@Override
public int getReviewCount(PaginationRequest request, String uuid) throws ReviewManagementException {
public int getReviewCount(String uuid) throws ReviewManagementDAOException {
int commentCount = 0;
Connection conn;
@ -276,20 +284,20 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
isUuidProvided = true;
}
if (isUuidProvided) {
sql = "SELECT COUNT(AP_APP_COMMENT.ID) FROM AP_APP_COMMENT,AP_APP_RELEASE "
+ "WHERE AP_APP_COMMENT.AP_APP_RELEASE_ID= AP_APP_RELEASE.ID AND "
+ "AP_APP_COMMENT.AP_APP_ID= AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;";
sql = "SELECT COUNT(AP_APP_REVIEW.ID) AS REVIEW_COUNT FROM AP_APP_REVIEW,AP_APP_RELEASE "
+ "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID= AP_APP_RELEASE.ID AND "
+ "AP_APP_REVIEW.AP_APP_ID= AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;";
statement = conn.prepareStatement(sql);
statement.setString(1, uuid);
rs = statement.executeQuery();
if (rs.next()) {
commentCount = rs.getInt("COMMENTS_COUNT");
commentCount = rs.getInt("REVIEW_COUNT");
}
}
} catch (SQLException e) {
throw new ReviewManagementException("SQL Error occurred while retrieving count of comments", e);
throw new ReviewManagementDAOException("SQL Error occurred while retrieving review counts", e);
} catch (DBConnectionException e) {
log.error("DB Connection Exception occurred while retrieving count of comments", e);
throw new ReviewManagementDAOException("DB Connection Exception occurred while retrieving review counts", e);
} finally {
Util.cleanupResources(statement, rs);
}
@ -302,8 +310,10 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
Connection conn;
PreparedStatement statement = null;
ResultSet rs = null;
int commentCount = 0;
try {
//todo need to reconstruct the query
conn = this.getDBConnection();
sql = "SELECT COUNT(ID) AS COMMENT_COUNT FROM AP_APP_COMMENT C, "
+ "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=? )R,"
@ -313,12 +323,12 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
statement.setString(1, version);
statement.setString(2, appName);
statement.setString(3, appType);
ResultSet rs = statement.executeQuery();
rs = statement.executeQuery();
if (rs.next()) {
commentCount = rs.getInt("COMMENT_COUNT");
}
} finally {
Util.cleanupResources(statement, null);
Util.cleanupResources(statement, rs);
}
return commentCount;
}
@ -345,33 +355,13 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
}
@Override
public int deleteReviewByAdmin(int reviewId) throws ReviewManagementDAOException {
Connection conn;
PreparedStatement statement = null;
try {
conn = this.getDBConnection();
sql = "DELETE FROM AP_APP_REVIEW WHERE ID=?;";
statement = conn.prepareStatement(sql);
statement.setInt(1, reviewId);
return statement.executeUpdate();
} catch (SQLException e) {
throw new ReviewManagementDAOException("Error occured while accessing the Database", e);
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException("Error occured while getting the database connection", e);
} finally {
Util.cleanupResources(statement, null);
}
}
@Override
public void deleteReviews(String appType, String appName, String version)
throws ReviewManagementException {
public void deleteReviews(String appType, String appName, String version) throws ReviewManagementException {
Connection conn;
PreparedStatement statement = null;
try {
conn = this.getDBConnection();
//todo need to reconstruct the query,
sql = "DELETE FROM AP_APP_COMMENT WHERE "
+ "(SELECT AP_APP_RELEASE_ID FROM AP_APP_RELEASE WHERE VERSION=? AND "
+ "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? AND TYPE=?)) AND "

@ -279,28 +279,28 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
/**
* To Update starts of an application release.
*
* @param id Id of the application Release.
* @param uuid UUID of the application Release.
* @param rating given stars for the application release.
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
@Override
public int updateRatingValue(int id, double rating, int ratedUsers) throws ApplicationManagementDAOException {
public void updateRatingValue(String uuid, double rating, int ratedUsers) throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
String sql = "UPDATE AP_APP_RELEASE SET RATING = ? AND RATED_USERS = ? WHERE ID = ?;";
String sql = "UPDATE AP_APP_RELEASE SET RATING = ? AND RATED_USERS = ? WHERE UUID = ?;";
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql);
statement.setDouble(1, rating);
statement.setInt(2, ratedUsers);
statement.setInt(2, id);
return statement.executeUpdate();
statement.setString(3, uuid);
statement.executeUpdate();
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Database connection exception while trying to update the application release", e);
"Database connection exception while trying to update the application release rating value", e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"SQL exception while updating the release ,while executing the query " + sql, e);
"SQL exception while updating the release rating value ,while executing the query " + sql, e);
} finally {
Util.cleanupResources(statement, null);
}
@ -313,16 +313,17 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
@Override
public Rating getRating(String uuid) throws ApplicationManagementDAOException {
public Rating getRating(String uuid, int tenantId) throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
ResultSet resultSet = null;
Rating rating = null;
String sql = "SELECT RATING, RATED_USERS FROM AP_APP_RELEASE WHERE UUID = ?;";
String sql = "SELECT RATING, RATED_USERS FROM AP_APP_RELEASE WHERE UUID = ? AND TENANT_D=?;";
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql);
statement.setString(1, uuid);
statement.setInt(2, tenantId);
resultSet = statement.executeQuery();
if (resultSet.next()){

@ -96,8 +96,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
application.setUser(new User(userName, tenantId));
if (log.isDebugEnabled()) {
log.debug("Create Application received for the tenant : " + application.getUser().getTenantId() + " From"
+ " the user : " + application.getUser().getUserName());
log.debug("Create Application received for the tenant : " + tenantId + " From" + " the user : " + userName);
}
validateAppCreatingRequest(application);
@ -161,11 +160,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException(msg, e);
} catch (DeviceManagementException e) {
e.printStackTrace();
String msg = "Error occurred while getting device type id of " + application.getType();
log.error(msg, e);
ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException(msg, e);
} finally {
//ConnectionManagerUtil.closeDBConnection(); //todo: check this again
}
return null;
}
@Override

@ -25,6 +25,8 @@ 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.PaginationRequest;
import org.wso2.carbon.device.application.mgt.common.PaginationResult;
import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewDoesNotExistException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.common.exception.TransactionManagementException;
@ -41,7 +43,6 @@ import org.wso2.carbon.user.api.UserRealm;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
@ -64,34 +65,29 @@ public class ReviewManagerImpl implements ReviewManager {
this.applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO();
}
@Override public boolean addReview(Review review, String uuid) throws ReviewManagementException {
@Override public boolean addReview(Review review, String uuid)
throws ReviewManagementException, RequestValidatingException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
boolean isSuccess;
boolean isSuccess = false;
try {
ConnectionManagerUtil.beginDBTransaction();
Review existingReview = reviewDAO.haveUerCommented(uuid, username, tenantId);
if (existingReview != null && review.getRating() > 0 && review.getRating() != existingReview.getRating()) {
if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId)
&& review.getRating() > 0 && review.getRating() != existingReview.getRating()) {
Runnable task = () -> calculateRating(review.getRating(), existingReview.getRating(), uuid);
new Thread(task).start();
isSuccess = updateReview(review, existingReview.getId(),uuid, false);
if (isSuccess) {
ConnectionManagerUtil.commitDBTransaction();
} else {
ConnectionManagerUtil.rollbackDBTransaction();
}
} else {
if (review.getRating() > 0) {
Runnable task = () -> calculateRating(review.getRating(), -12345, uuid);
new Thread(task).start();
}
isSuccess = updateReview(review, existingReview.getId(), uuid, existingReview);
} else if (review.getRating() > 0) {
Runnable task = () -> calculateRating(review.getRating(), -12345, uuid);
new Thread(task).start();
review.setUsername(username);
isSuccess = this.reviewDAO.addReview(review, uuid, tenantId);
if (isSuccess) {
ConnectionManagerUtil.commitDBTransaction();
} else {
ConnectionManagerUtil.rollbackDBTransaction();
}
}
if (isSuccess) {
ConnectionManagerUtil.commitDBTransaction();
} else {
ConnectionManagerUtil.rollbackDBTransaction();
}
return isSuccess;
} catch (DBConnectionException e) {
@ -103,49 +99,54 @@ public class ReviewManagerImpl implements ReviewManager {
throw new ReviewManagementException(
"Transaction Management Exception occurs,Review for application release with UUID:" + uuid +
" is failed ", e);
} catch (UserStoreException e) {
throw new ReviewManagementException("Error occured while verifying user's permission to update the review.",
e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public boolean updateReview(Review review, int reviewId, String uuid, boolean checkExistence)
public boolean updateReview(Review review, int reviewId, String uuid, Review existingReview)
throws ReviewManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
Review existingReview;
boolean isSuccess;
if (log.isDebugEnabled()) {
log.debug("Review updating request is received for the review id " + reviewId);
}
try {
ConnectionManagerUtil.openDBConnection();
// todo
if (!username.equals(review.getUsername())) {
throw new ReviewManagementException(
"User " + review.getUsername() + "doesn't match with the logged in user: " + username);
}
if (checkExistence) {
if (existingReview == null) {
existingReview = this.reviewDAO.getReview(reviewId);
if (existingReview != null) {
if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId)) {
if (review.getRating() > 0 && review.getRating() != existingReview.getRating()) {
Runnable task = () -> calculateRating(review.getRating(), existingReview.getRating(), uuid);
Review finalExistingReview = existingReview;
Runnable task = () -> calculateRating(review.getRating(), finalExistingReview.getRating(),
uuid);
new Thread(task).start();
}
} else {
throw new ReviewManagementException("Couldn't find a review for review id: " + reviewId);
throw new ReviewManagementException(
"Please check the existence of the review, Review-Id: " + reviewId
+ " or permission of the " + username + " to update the review.");
}
}
if (review.getComment().isEmpty()) {
review.setComment(existingReview.getComment());
}
if (review.getRating() == 0) {
review.setRating(existingReview.getRating());
}
ConnectionManagerUtil.beginDBTransaction();
isSuccess = this.reviewDAO.updateReview(review, reviewId, tenantId);
if (isSuccess) {
if (this.reviewDAO.updateReview(review, reviewId, username, tenantId) == 1) {
ConnectionManagerUtil.commitDBTransaction();
} else {
ConnectionManagerUtil.rollbackDBTransaction();
return true;
}
return isSuccess;
} catch (SQLException e) {
throw new ReviewManagementException("SQL Error occurs updating review with review id " + reviewId + ".",
ConnectionManagerUtil.rollbackDBTransaction();
return false;
} catch (ReviewManagementDAOException e) {
throw new ReviewManagementException("Error occured while updating review with review id " + reviewId + ".",
e);
} catch (DBConnectionException e) {
throw new ReviewManagementException(
@ -153,6 +154,10 @@ public class ReviewManagerImpl implements ReviewManager {
} catch (TransactionManagementException e) {
throw new ReviewManagementException(
"Transaction management error occurs when updating review with review id " + reviewId + ".", e);
} catch (UserStoreException e) {
throw new ReviewManagementException(
"Error occured while verifying user's permission to update the review. review id: " + reviewId
+ ".", e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
@ -203,55 +208,28 @@ public class ReviewManagerImpl implements ReviewManager {
}
}
@Override public Review getReview(int commentId) throws ReviewManagementException {
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
Review review;
if (log.isDebugEnabled()) {
log.debug("Review retrieval request is received for the review id " + commentId);
}
try {
ConnectionManagerUtil.openDBConnection();
review = this.reviewDAO.getReview(commentId);
} catch (DBConnectionException e) {
throw new ReviewManagementException(
"DB Connection error occurs ,Review with review id " + commentId + "cannot get.", e);
} catch (SQLException e) {
throw new ReviewManagementException(
"SQL Exception occurs,Review with review id " + commentId + "cannot get.", e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
return review;
}
@Override
public boolean deleteReview(String uuid, int reviewId) throws ReviewManagementException {
public boolean deleteReview(String uuid, int reviewId)
throws ReviewManagementException, ReviewDoesNotExistException {
Review existingReview;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
int isReviewDeleted;
try {
existingReview = getReview(reviewId);
ConnectionManagerUtil.openDBConnection();
existingReview = this.reviewDAO.getReview(reviewId);
if (existingReview == null) {
throw new ReviewManagementException(
throw new ReviewDoesNotExistException(
"Cannot delete a non-existing review for the application with review id" + reviewId);
}
Runnable task = () -> calculateRating(0, existingReview.getRating(), uuid);
new Thread(task).start();
ConnectionManagerUtil.beginDBTransaction();
if (isAdminUser(username, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
isReviewDeleted = this.reviewDAO.deleteReviewByAdmin(reviewId);
if (isReviewDeleted == 1) {
ConnectionManagerUtil.commitDBTransaction();
return true;
}
} else {
isReviewDeleted = this.reviewDAO.deleteReview(username, reviewId);
if (isReviewDeleted == 1) {
ConnectionManagerUtil.commitDBTransaction();
return true;
}
if (isAuthorizedUser(username, existingReview.getUsername(), tenantId)
&& this.reviewDAO.deleteReview(username, reviewId) == 1) {
ConnectionManagerUtil.commitDBTransaction();
return true;
}
ConnectionManagerUtil.rollbackDBTransaction();
return false;
} catch (DBConnectionException e) {
throw new ReviewManagementException(
@ -272,17 +250,17 @@ public class ReviewManagerImpl implements ReviewManager {
}
@Override public Rating getRating(String appReleaseUuuid) throws ReviewManagementException {
//todo
int appReleaseId = 0;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ConnectionManagerUtil.openDBConnection();
Rating rating = this.applicationReleaseDAO.getRating(appReleaseUuuid);
Rating rating = this.applicationReleaseDAO.getRating(appReleaseUuuid, tenantId);
if (rating == null) {
throw new ReviewManagementException("Couldn't find rating for application release id: " + appReleaseId
+ ". Please check the existence of the application relese");
throw new ReviewManagementException(
"Couldn't find rating for application release UUID: " + appReleaseUuuid
+ ". Please check the existence of the application release");
}
List<Integer> ratingValues = this.reviewDAO.getAllRatingValues(appReleaseUuuid);
List<Integer> ratingValues = this.reviewDAO.getAllRatingValues(appReleaseUuuid, tenantId);
TreeMap<Integer, Integer> ratingVariety = rating.getRatingVariety();
for (Integer ratingVal : ratingValues) {
if (ratingVariety.containsKey(ratingVal)) {
@ -296,62 +274,59 @@ public class ReviewManagerImpl implements ReviewManager {
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw new ReviewManagementException(
"Error occured while updated the rating value of the application release id: " + appReleaseId
+ " can not get.", e);
"Error occured while getting the rating value of the application release uuid: " + appReleaseUuuid,
e);
} catch (DBConnectionException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw new ReviewManagementException(
"DB Connection error occured while updated the rating value of the application release id: "
+ appReleaseId + " can not get.", e);
} catch (SQLException e) {
"DB Connection error occured while getting the rating value of the application release uuid: "
+ appReleaseUuuid, e);
} catch (ReviewManagementDAOException e) {
throw new ReviewManagementException(
"DB Connection error occured while updated the rating value of the application release id: "
+ appReleaseId + " can not get.", e);
"Error occured while getting all rating values for the application release UUID: "
+ appReleaseUuuid, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
private void calculateRating(int newRatingVal, int oldRatingVal, String uuid) {
// todo need to pass app release id
int appReleaseId = 0;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ConnectionManagerUtil.beginDBTransaction();
Rating rating = this.applicationReleaseDAO.getRating(uuid);
Rating rating = this.applicationReleaseDAO.getRating(uuid, tenantId);
if (rating == null) {
log.error("Couldn't find rating for application release id: " + appReleaseId);
log.error("Couldn't find rating for application release uuid: " + uuid);
} else {
double updatedRating;
int numOfUsers = rating.getNoOfUsers();
double currentRating = rating.getRatingValue() * numOfUsers;
if (oldRatingVal == -12345) {
updatedRating = (currentRating + newRatingVal) / (numOfUsers + 1);
this.applicationReleaseDAO.updateRatingValue(appReleaseId, updatedRating, numOfUsers + 1);
this.applicationReleaseDAO.updateRatingValue(uuid, updatedRating, numOfUsers + 1);
} else if (newRatingVal == 0) {
updatedRating = (currentRating - newRatingVal) / (numOfUsers - 1);
this.applicationReleaseDAO.updateRatingValue(appReleaseId, updatedRating, numOfUsers - 1);
this.applicationReleaseDAO.updateRatingValue(uuid, updatedRating, numOfUsers - 1);
} else {
double tmpVal;
tmpVal = currentRating - oldRatingVal;
updatedRating = (tmpVal + newRatingVal) / numOfUsers;
this.applicationReleaseDAO.updateRatingValue(appReleaseId, updatedRating, numOfUsers);
this.applicationReleaseDAO.updateRatingValue(uuid, updatedRating, numOfUsers);
}
}
ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
log.error("Error occured while updated the rating value of the application release id: " + appReleaseId
+ " can not get.");
log.error("Error occured while updated the rating value of the application release UUID: " + uuid);
} catch (TransactionManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction();
log.error(
"Transaction Management Exception occured while updated the rating value of the application release id: "
+ appReleaseId + " can not get.");
"Transaction Management Exception occured while updated the rating value of the application release UUID: "
+ uuid);
} catch (DBConnectionException e) {
ConnectionManagerUtil.rollbackDBTransaction();
log.error("DB Connection error occured while updated the rating value of the application release id: "
+ appReleaseId + " can not get.");
log.error("DB Connection error occured while updated the rating value of the application release UUID: "
+ uuid + " can not get.");
} finally {
ConnectionManagerUtil.closeDBConnection();
}
@ -372,4 +347,20 @@ public class ReviewManagerImpl implements ReviewManager {
.isUserAuthorized(MultitenantUtils.getTenantAwareUsername(username), permission,
CarbonConstants.UI_PERMISSION_ACTION);
}
/**
* To check whether logged in user is authorized user to do an specific action.
*
* @param loggedInUser username of the loggedin user.
* @param reviewOwner username of the review owner.
* @param tenantId ID of the tenant.
* @return true if the current user has the permission, otherwise false.
* @throws UserStoreException UserStoreException
*/
private boolean isAuthorizedUser(String loggedInUser, String reviewOwner, int tenantId) throws UserStoreException {
return loggedInUser.equals(reviewOwner) || isAdminUser(loggedInUser, tenantId,
CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION);
}
}

@ -1,117 +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.core.impl;
import org.wso2.carbon.device.application.mgt.common.UnrestrictedRole;
import org.wso2.carbon.device.application.mgt.common.Visibility;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.VisibilityManagementException;
import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleManager;
import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import java.util.Collection;
import java.util.List;
//todo need to work on business logic
/**
* This is the default implementation for the visibility manager.
*/
public class UnrestrictedRoleManagerImpl implements UnrestrictedRoleManager {
@Override
public Visibility put(int applicationID, Visibility visibility) throws VisibilityManagementException {
return null;
// if (visibility == null) {
// visibility = new Visibility();
// visibility.setType(Visibility.Type.PUBLIC);
// }
// if (visibility.getAllowedList() == null && !visibility.getType().equals(Visibility.Type.PUBLIC)) {
// throw new VisibilityManagementException("Visibility is configured for '" + visibility.getType()
// + "' but doesn't have any allowed list provided!");
// }
// boolean isTransactionStarted = false;
// try {
// isTransactionStarted = ConnectionManagerUtil.isTransactionStarted();
// if (!isTransactionStarted) {
// ConnectionManagerUtil.beginDBTransaction();
// }
// VisibilityDAO visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
// int visibilityTypeId = visibilityDAO.getVisibilityID(visibility.getType());
// visibilityDAO.delete(applicationID);
// visibilityDAO.add(applicationID, visibilityTypeId, visibility.getAllowedList());
// if (!isTransactionStarted) {
// ConnectionManagerUtil.commitDBTransaction();
// }
// return visibility;
// } catch (ApplicationManagementException e) {
// if (!isTransactionStarted) {
// ConnectionManagerUtil.rollbackDBTransaction();
// }
// throw new VisibilityManagementException("Problem occured when trying to fetch the application with ID - "
// + applicationID, e);
// } finally {
// if (!isTransactionStarted) {
// ConnectionManagerUtil.closeDBConnection();
// }
// }
}
@Override
public List<UnrestrictedRole> getUnrestrictedRoles(int applicationID, int tenantId) throws VisibilityManagementException {
try {
VisibilityDAO visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
List<UnrestrictedRole> unrestrictedRoles = visibilityDAO.getUnrestrictedRoles(applicationID, tenantId);
if (unrestrictedRoles == null) {
return null;
}
return unrestrictedRoles;
} catch (ApplicationManagementException e) {
throw new VisibilityManagementException("Problem occured when trying to fetch the application with ID - "
+ applicationID, e);
}
}
@Override
public void remove(int applicationID) throws VisibilityManagementException {
// boolean isTransactionStarted = false;
// try {
// isTransactionStarted = ConnectionManagerUtil.isTransactionStarted();
// if (!isTransactionStarted) {
// ConnectionManagerUtil.beginDBTransaction();
// }
// VisibilityDAO visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
// visibilityDAO.delete(applicationID);
// if (!isTransactionStarted) {
// ConnectionManagerUtil.commitDBTransaction();
// }
// } catch (ApplicationManagementException e) {
// if (!isTransactionStarted) {
// ConnectionManagerUtil.rollbackDBTransaction();
// }
// throw new VisibilityManagementException("Problem occurred when trying to fetch the application with ID - "
// + applicationID, e);
// } finally {
// if (!isTransactionStarted) {
// ConnectionManagerUtil.closeDBConnection();
// }
// }
}
}

@ -22,15 +22,12 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.wso2.carbon.device.application.mgt.common.exception.InvalidConfigurationException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.common.services.ReviewManager;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleManager;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger;
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState;
import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagementUtil;
@ -38,7 +35,6 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.ndatasource.core.DataSourceService;
import org.wso2.carbon.user.core.service.RealmService;
import javax.naming.NamingException;
import java.util.List;
/**
@ -90,10 +86,6 @@ public class ApplicationManagementServiceComponent {
DataHolder.getInstance().setSubscriptionManager(subscriptionManager);
bundleContext.registerService(SubscriptionManager.class.getName(), subscriptionManager, null);
UnrestrictedRoleManager unrestrictedRoleManager = ApplicationManagementUtil.getVisibilityManagerInstance();
DataHolder.getInstance().setVisibilityManager(unrestrictedRoleManager);
bundleContext.registerService(UnrestrictedRoleManager.class.getName(), unrestrictedRoleManager, null);
ApplicationStorageManager applicationStorageManager = ApplicationManagementUtil
.getApplicationStorageManagerInstance();
DataHolder.getInstance().setApplicationStorageManager(applicationStorageManager);

@ -22,7 +22,6 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.common.services.ReviewManager;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleManager;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.user.core.service.RealmService;
@ -42,8 +41,6 @@ public class DataHolder {
private SubscriptionManager subscriptionManager;
private UnrestrictedRoleManager unrestrictedRoleManager;
private ApplicationStorageManager applicationStorageManager;
private LifecycleStateManger lifecycleStateManger;
@ -90,14 +87,6 @@ public class DataHolder {
this.subscriptionManager = subscriptionManager;
}
public UnrestrictedRoleManager getVisibilityManager() {
return unrestrictedRoleManager;
}
public void setVisibilityManager(UnrestrictedRoleManager unrestrictedRoleManager) {
this.unrestrictedRoleManager = unrestrictedRoleManager;
}
public RealmService getRealmService() {
return realmService;
}

@ -26,9 +26,6 @@ public class LifecycleStateManger {
}
public boolean isValidStateChange(String currentState, String nextState) {
if (lifecycleStates.get(currentState).getProceedingStates().contains(nextState)) {
return true;
}
return false;
return lifecycleStates.get(currentState).getProceedingStates().contains(nextState);
}
}

@ -25,7 +25,6 @@ import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager
import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager;
import org.wso2.carbon.device.application.mgt.common.services.ReviewManager;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.application.mgt.common.services.UnrestrictedRoleManager;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.config.Extension;
@ -51,12 +50,6 @@ public class ApplicationManagementUtil {
return getInstance(extension, ReviewManager.class);
}
public static UnrestrictedRoleManager getVisibilityManagerInstance() throws InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.VisibilityManager);
return getInstance(extension, UnrestrictedRoleManager.class);
}
public static SubscriptionManager getSubscriptionManagerInstance() throws InvalidConfigurationException {
ConfigurationManager configurationManager = ConfigurationManager.getInstance();
Extension extension = configurationManager.getExtension(Extension.Name.SubscriptionManager);

@ -23,39 +23,18 @@
<DatasourceName>jdbc/APPM_DS</DatasourceName>
<Extensions>
<Extension name="ApplicationUploadManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationUploadManagerImpl</ClassName>
<Parameters>
<Parameter name="UploadPath">repository/resources/mobileapps</Parameter>
</Parameters>
</Extension>
<Extension name="ApplicationManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationManagerImpl</ClassName>
</Extension>
<Extension name="ApplicationReleaseManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationReleaseManagerImpl</ClassName>
</Extension>
<Extension name="CategoryManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.CategoryManagerImpl</ClassName>
</Extension>
<Extension name="CommentsManager">
<Extension name="ReviewManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ReviewManagerImpl</ClassName>
</Extension>
<Extension name="LifecycleStateManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.LifecycleStateManagerImpl</ClassName>
</Extension>
<Extension name="PlatformManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.PlatformManagerImpl</ClassName>
<ClassName>org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger</ClassName>
</Extension>
<Extension name="SubscriptionManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.SubscriptionManagerImpl</ClassName>
</Extension>
<Extension name="VisibilityManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.UnrestrictedRoleManagerImpl</ClassName>
</Extension>
<Extension name="VisibilityTypeManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.VisibilityTypeManagerImpl</ClassName>
</Extension>
</Extensions>
<LifecycleStates>

@ -37,7 +37,6 @@ public class APIUtil {
private static ApplicationManager applicationManager;
private static ApplicationStorageManager applicationStorageManager;
private static SubscriptionManager subscriptionManager;
private static UnrestrictedRoleManager unrestrictedRoleManager;
public static ApplicationManager getApplicationManager() {
if (applicationManager == null) {
@ -116,26 +115,4 @@ public class APIUtil {
return subscriptionManager;
}
/**
* To get the Unrestricted Role manager from the osgi context.
* @return Unrestricted Role manager instance in the current osgi context.
*/
public static UnrestrictedRoleManager getUnrestrictedRoleManager() {
if (unrestrictedRoleManager == null) {
synchronized (APIUtil.class) {
if (unrestrictedRoleManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
unrestrictedRoleManager =
(UnrestrictedRoleManager) ctx.getOSGiService(UnrestrictedRoleManager.class, null);
if (unrestrictedRoleManager == null) {
String msg = "Subscription Manager service has not initialized.";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return unrestrictedRoleManager;
}
}

@ -28,23 +28,16 @@ import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Info;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.cxf.jaxrs.ext.multipart.Multipart;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.Application;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.ApplicationRelease;
import java.util.List;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
@ -53,22 +46,22 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
/**
* APIs to handle application management related tasks.
* APIs to handle application storage management related tasks.
*/
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "Application Management Service",
title = "Application Storage Management Service",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "ApplicationManagementService"),
@ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/applications"),
@ExtensionProperty(name = "name", value = "ApplicationStorageManagementService"),
@ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/store-applications"),
})
}
),
tags = {
@Tag(name = "application_management, device_management", description = "Application Management related "
+ "APIs")
@Tag(name = "application_management, device_management", description = "Application Storage Management "
+ "related APIs")
}
)
@Scopes(

@ -30,6 +30,7 @@ import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.application.mgt.common.PaginationResult;
import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.Review;
import javax.validation.Valid;
@ -47,7 +48,7 @@ import javax.ws.rs.core.Response;
import java.util.List;
/**
* APIs to handle comment management related tasks.
* APIs to handle review management related tasks.
*/
@SwaggerDefinition(
@ -56,51 +57,36 @@ import java.util.List;
title = "Store Management Service",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "CommentManagementService"),
@ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/comments"),
@ExtensionProperty(name = "name", value = "ReviewManagementService"),
@ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/review"),
})
}
),
tags = {
@Tag(name = "store_management", description = "Review Management related "
+ "APIs")
@Tag(name = "store_management", description = "Review Management related APIs")
}
)
@Scopes(
scopes = {
@Scope(
name = "Get Comments Details",
description = "Get comments details",
key = "perm:comment:get",
permissions = {"/device-mgt/comment/get"}
),
@Scope(
name = "Add a Review",
description = "Add a comment",
key = "perm:comment:add",
permissions = {"/device-mgt/comment/add"}
name = "Get Review Details",
description = "Get review details",
key = "perm:app:review:view",
permissions = {"/device-mgt/review/view"}
),
@Scope(
name = "Update a Review",
description = "Update a Review",
key = "perm:comment:update",
permissions = {"/device-mgt/comment/update"}
),
@Scope(
name = "Delete a Review",
description = "Delete a comment",
key = "perm:comment:delete",
permissions = {"/device-mgt/comment/delete"}
description = "Update a comment",
key = "perm:app:review:update",
permissions = {"/device-mgt/review/update"}
),
}
)
@Path("/review")
@Api(value = "Comments Management", description = "This API carries all comments management related operations " +
"such as get all the comments, add comment, etc.")
@Api(value = "Review Management", description = "This API carries all review management related operations such as get "
+ "all the reviews, add review, etc.")
@Produces(MediaType.APPLICATION_JSON)
public interface ReviewManagementAPI {
String SCOPE = "scope";
@ -110,12 +96,12 @@ public interface ReviewManagementAPI {
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get comments",
notes = "Get all comments",
value = "get reviews",
notes = "Get all reviews",
tags = "Store Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:store:get")
@ExtensionProperty(name = SCOPE, value = "perm:app:review:view")
})
}
)
@ -124,36 +110,30 @@ public interface ReviewManagementAPI {
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved comments.",
response = List.class,
responseContainer = "List"),
@ApiResponse(
code = 404,
message = "Not Found. \n No activity found with the given ID.",
response = ErrorResponse.class),
message = "OK. \n Successfully retrieved reviews.",
response = PaginationResult.class,
responseContainer = "PaginationResult"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the comment list.",
message = "Internal Server Error. \n Error occurred while getting the review list.",
response = ErrorResponse.class)
})
Response getAllReviews(
@ApiParam(
name="uuid",
value="uuid of the released version of application.",
value="uuid of the application release.",
required = true)
@PathParam("uuid")
String uuid,
@ApiParam(
name="offSet",
value="Starting comment number.",defaultValue = "1",
required = false)
value="Starting review number.",defaultValue = "0")
@QueryParam("offSet")
int offSet,
@ApiParam(
name="limit",
value = "Limit of paginated comments",defaultValue = "20",
required = false)
value = "Limit of paginated reviews",defaultValue = "20")
@QueryParam("limit")
int limit);
@ -170,7 +150,7 @@ public interface ReviewManagementAPI {
tags = "Store Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:store:add")
@ExtensionProperty(name = SCOPE, value = "perm:app:review:update")
})
}
)
@ -215,23 +195,19 @@ public interface ReviewManagementAPI {
tags = "Store Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:store:edit")
@ExtensionProperty(name = SCOPE, value = "perm:app:review:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 201,
code = 200,
message = "OK. \n Successfully updated review.",
response = Review.class),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
@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 updating the new review.",
@ -267,7 +243,7 @@ public interface ReviewManagementAPI {
tags = "Store Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:store:remove")
@ExtensionProperty(name = SCOPE, value = "perm:app:review:update")
})
}
)
@ -276,14 +252,14 @@ public interface ReviewManagementAPI {
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully deleted the comment"),
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 comment.",
message = "Internal Server Error. \n Error occurred while deleting the review.",
response = ErrorResponse.class)
})
@ -300,17 +276,17 @@ public interface ReviewManagementAPI {
@PathParam("reviewId") int reviewId);
@GET
@Path("/{uuid}/{stars}")
@Path("/{uuid}/rating")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get stars",
notes = "Get all stars",
value = "get ratings",
notes = "Get all ratings",
tags = "Store Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:stars:get")
@ExtensionProperty(name = SCOPE, value = "perm:app:review:view")
})
}
)
@ -319,12 +295,12 @@ public interface ReviewManagementAPI {
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved stars.",
message = "OK. \n Successfully retrieved ratings.",
response = List.class,
responseContainer = "List"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred while getting the stars",
message = "Internal Server Error. \n Error occurred while getting ratings",
response = ErrorResponse.class)
})

@ -15,7 +15,7 @@
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.application.mgt.publisher.api.services;
package org.wso2.carbon.device.application.mgt.store.api.services;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@ -25,6 +25,8 @@ import org.wso2.carbon.device.application.mgt.common.Application;
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.Review;
import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewDoesNotExistException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager;
import org.wso2.carbon.device.application.mgt.common.services.ReviewManager;
import org.wso2.carbon.device.application.mgt.store.api.APIUtil;
@ -106,6 +108,10 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
log.error("Error occured while getting the application for application UUID: " + uuid);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity("").build();
} catch (RequestValidatingException e) {
String msg = "Error occurred while adding for application release. UUID of the application release: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
@ -119,7 +125,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
@PathParam("reviewId") int reviewId) {
ReviewManager reviewManager = APIUtil.getReviewManager();
try {
if (reviewManager.updateReview(review, reviewId, uuid, true)) {
if (reviewManager.updateReview(review, reviewId, uuid, null)) {
return Response.status(Response.Status.OK).entity(review).build();
} else {
String msg = "Review updating failed. Please contact the administrator";
@ -130,6 +136,10 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
String msg = "Error occurred while retrieving comments.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (RequestValidatingException e) {
String msg = "Error occurred while updating review. Review id: " + reviewId;
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
}
@ -142,9 +152,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
ReviewManager reviewManager = APIUtil.getReviewManager();
try {
if (reviewId == 0) {
return Response.status(Response.Status.NOT_FOUND).entity("Review not found").build();
} else if (reviewManager.deleteReview(uuid, reviewId)) {
if (reviewManager.deleteReview(uuid, reviewId)) {
return Response.status(Response.Status.OK).entity("Review is deleted successfully.").build();
} else {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Review deleting is failed.")
@ -154,6 +162,10 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
String msg = "Error occurred while deleting the comment.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ReviewDoesNotExistException e) {
String msg = "Couldn't find a review for review-id: " + reviewId + " to delete.";
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
}
}

@ -23,18 +23,16 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.ApplicationInstallResponse;
import org.wso2.carbon.device.application.mgt.common.EnterpriseInstallationDetails;
import org.wso2.carbon.device.application.mgt.store.api.APIUtil;
import org.wso2.carbon.device.application.mgt.publisher.api.services.SubscriptionManagementAPI;
import org.wso2.carbon.device.application.mgt.store.api.services.SubscriptionManagementAPI;
import org.wso2.carbon.device.application.mgt.common.InstallationDetails;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManager;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import javax.validation.Valid;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.Response;
import java.util.HashMap;
import java.util.List;
/**

@ -25,27 +25,15 @@
<Extension name="ApplicationManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationManagerImpl</ClassName>
</Extension>
<Extension name="ApplicationReleaseManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationReleaseManagerImpl</ClassName>
</Extension>
<Extension name="CategoryManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.CategoryManagerImpl</ClassName>
</Extension>
<Extension name="ReviewManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ReviewManagerImpl</ClassName>
</Extension>
<Extension name="LifecycleStateManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.LifecycleStateManagerImpl</ClassName>
</Extension>
<Extension name="PlatformManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.PlatformManagerImpl</ClassName>
<ClassName>org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger</ClassName>
</Extension>
<Extension name="SubscriptionManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.SubscriptionManagerImpl</ClassName>
</Extension>
<Extension name="VisibilityManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.UnrestrictedRoleManagerImpl</ClassName>
</Extension>
<Extension name="ApplicationStorageManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.ApplicationStorageManagerImpl</ClassName>
<Parameters>
@ -53,12 +41,6 @@
<Parameter name="MaxScreenShotCount">6</Parameter>
</Parameters>
</Extension>
<Extension name="PlatformStorageManager">
<ClassName>org.wso2.carbon.device.application.mgt.core.impl.PlatformStorageManagerImpl</ClassName>
<Parameters>
<Parameter name="StoragePath">repository/resources/platforms</Parameter>
</Parameters>
</Extension>
</Extensions>
<!-- This is for publisher lifecycle -->

Loading…
Cancel
Save