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

Add APIs for APPM review management

See merge request entgra/carbon-device-mgt!95
feature/appm-store/pbac
Inosh Perara 5 years ago
commit bdca76405a

@ -122,8 +122,6 @@
<groupId>org.codehaus.jackson</groupId> <groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId> <artifactId>jackson-core-asl</artifactId>
</dependency> </dependency>
</dependencies> </dependencies>
</project> </project>

@ -0,0 +1,67 @@
package org.wso2.carbon.device.application.mgt.common;
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import java.util.ArrayList;
import java.util.List;
public class ReviewNode<T> {
private T data = null;
private List<ReviewNode<T>> children = new ArrayList<>();
private ReviewNode<T> parent = null;
public ReviewNode(T data) {
this.data = data;
}
public ReviewNode<T> addChild(ReviewNode<T> child) {
child.setParent(this);
this.children.add(child);
return child;
}
public void addChildren(List<ReviewNode<T>> children) {
children.forEach(each -> each.setParent(this));
this.children.addAll(children);
}
public List<ReviewNode<T>> getChildren() {
return children;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
private void setParent(ReviewNode<T> parent) {
this.parent = parent;
}
public ReviewNode<T> getParent() {
return parent;
}
}

@ -23,8 +23,8 @@ import io.swagger.annotations.ApiModelProperty;
import java.sql.Timestamp; import java.sql.Timestamp;
@ApiModel(value = "Review", description = "Review represents the user's review for an application release") @ApiModel(value = "ReviewTmp", description = "ReviewTmp represents the user's review for an application release")
public class Review { public class ReviewTmp {
@ApiModelProperty(name = "id", @ApiModelProperty(name = "id",
value = "The Id given to the comment when it store to the App manager") value = "The Id given to the comment when it store to the App manager")
@ -55,9 +55,9 @@ public class Review {
value = "Rating value of the application release") value = "Rating value of the application release")
private int rating; private int rating;
@ApiModelProperty(name = "replyReview", @ApiModelProperty(name = "replyReviewTmp",
value = "Replying review") value = "Replying review")
private Review replyReview; private ReviewTmp replyReviewTmp;
public int getId() { public int getId() {
return id; return id;
@ -115,12 +115,12 @@ public class Review {
this.parentId = parentId; this.parentId = parentId;
} }
public Review getReplyReview() { public ReviewTmp getReplyReviewTmp() {
return replyReview; return replyReviewTmp;
} }
public void setReplyReview(Review replyReview) { public void setReplyReviewTmp(ReviewTmp replyReviewTmp) {
this.replyReview = replyReview; this.replyReviewTmp = replyReviewTmp;
} }
} }

@ -0,0 +1,87 @@
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.application.mgt.common.dto;
import java.sql.Timestamp;
public class ReviewDTO {
private int id;
private String content;
private String username;
private Timestamp createdAt;
private Timestamp modifiedAt;
private int rating;
private int rootParentId;
private int immediateParentId;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Timestamp getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Timestamp createdAt) {
this.createdAt = createdAt;
}
public Timestamp getModifiedAt() {
return modifiedAt;
}
public void setModifiedAt(Timestamp modifiedAt) {
this.modifiedAt = modifiedAt;
}
public int getRating() {
return rating;
}
public void setRating(int rating) {
this.rating = rating;
}
public int getRootParentId() { return rootParentId; }
public void setRootParentId(int rootParentId) { this.rootParentId = rootParentId; }
public int getImmediateParentId() { return immediateParentId; }
public void setImmediateParentId(int immediateParentId) { this.immediateParentId = immediateParentId; }
}

@ -0,0 +1,102 @@
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.application.mgt.common.response;
import java.sql.Timestamp;
import java.util.List;
public class Review {
private int id;
private String content;
private int rootParentId;
private int immediateParentId;
private String username;
private Timestamp createdAt;
private Timestamp modifiedAt;
private int rating;
private List<Review> replies;
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public int getRootParentId() {
return rootParentId;
}
public void setRootParentId(int rootParentId) {
this.rootParentId = rootParentId;
}
public int getImmediateParentId() {
return immediateParentId;
}
public void setImmediateParentId(int immediateParentId) {
this.immediateParentId = immediateParentId;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Timestamp getCreatedAt() {
return createdAt;
}
public void setCreatedAt(Timestamp createdAt) {
this.createdAt = createdAt;
}
public Timestamp getModifiedAt() {
return modifiedAt;
}
public void setModifiedAt(Timestamp modifiedAt) {
this.modifiedAt = modifiedAt;
}
public int getRating() {
return rating;
}
public void setRating(int rating) {
this.rating = rating;
}
public List<Review> getReplies() { return replies; }
public void setReplies(List<Review> replies) { this.replies = replies; }
}

@ -150,8 +150,9 @@ public interface ApplicationManager {
* @param releaseUuid UUID of the ApplicationDTO Release. * @param releaseUuid UUID of the ApplicationDTO Release.
* @param lifecycleChanger Lifecycle changer that contains the action and the reson for the change. * @param lifecycleChanger Lifecycle changer that contains the action and the reson for the change.
* @throws ApplicationManagementException ApplicationDTO Management Exception. * @throws ApplicationManagementException ApplicationDTO Management Exception.
* @return
*/ */
void changeLifecycleState(String releaseUuid, LifecycleChanger lifecycleChanger) ApplicationRelease changeLifecycleState(String releaseUuid, LifecycleChanger lifecycleChanger)
throws ApplicationManagementException; throws ApplicationManagementException;
/** /**

@ -18,16 +18,14 @@
*/ */
package org.wso2.carbon.device.application.mgt.common.services; package org.wso2.carbon.device.application.mgt.common.services;
import javassist.NotFoundException;
import org.wso2.carbon.device.application.mgt.common.Rating; import org.wso2.carbon.device.application.mgt.common.Rating;
import org.wso2.carbon.device.application.mgt.common.Review; import org.wso2.carbon.device.application.mgt.common.ReviewTmp;
import org.wso2.carbon.device.application.mgt.common.PaginationRequest; 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.PaginationResult;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewDoesNotExistException; 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.ReviewManagementException;
import org.wso2.carbon.device.application.mgt.common.wrapper.ReviewWrapper;
/** /**
* ReviewManager is responsible for handling all the add/update/delete/get operations related with * ReviewManager is responsible for handling all the add/update/delete/get operations related with
@ -35,15 +33,18 @@ import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementE
public interface ReviewManager { public interface ReviewManager {
/** /**
* To add a review to an application release * To add a reviewTmp to an application release
* *
* @param review review of the application. * @param reviewWrapper reviewTmp of the application.
* @param uuid uuid of the application release. * @param uuid uuid of the application release.
* @return {@link Review} Review added * @return {@link ReviewTmp} ReviewTmp added
* @throws ReviewManagementException Exceptions of the review management. * @throws ReviewManagementException Exceptions of the reviewTmp management.
*/ */
boolean addReview(Review review, String uuid) boolean addReview(ReviewWrapper reviewWrapper, String uuid)
throws ReviewManagementException, RequestValidatingException, ApplicationManagementException; throws ReviewManagementException, ApplicationManagementException;
boolean addReplyComment(ReviewWrapper reviewWrapper, String uuid, int parentReviewId)
throws ReviewManagementException, ApplicationManagementException;
/** /**
* Get all review with pagination * Get all review with pagination
@ -53,7 +54,8 @@ public interface ReviewManager {
* @return {@link PaginationResult} pagination result with starting offSet and limit * @return {@link PaginationResult} pagination result with starting offSet and limit
* @throws ReviewManagementException Exceptions of the comment management. * @throws ReviewManagementException Exceptions of the comment management.
*/ */
PaginationResult getAllReviews(PaginationRequest request, String uuid) throws ReviewManagementException; PaginationResult getAllReviews(PaginationRequest request, String uuid)
throws ReviewManagementException, ApplicationManagementException;
/** /**
* To delete review using review id. * To delete review using review id.
@ -67,24 +69,21 @@ public interface ReviewManager {
throws ReviewManagementException, ReviewDoesNotExistException; throws ReviewManagementException, ReviewDoesNotExistException;
/** /**
* To update a review. * To update a reviewTmp.
* *
* @param review review of the application. * @param reviewId id of the reviewTmp
* @param reviewId id of the review
* @param uuid UUID of the application release * @param uuid UUID of the application release
* @param existingReview Pass existing review when same user adding a review for same application release, * @return {@link ReviewTmp}updated reviewTmp
* otherwise pass null * @throws ReviewManagementException Exceptions of the reviewTmp management
* @return {@link Review}updated review
* @throws ReviewManagementException Exceptions of the review management
*/ */
boolean updateReview(Review review, int reviewId, String uuid, Review existingReview) boolean updateReview(ReviewWrapper updatingReview, int reviewId, String uuid)
throws ReviewManagementException, RequestValidatingException; throws ReviewManagementException, ApplicationManagementException;
/** /**
* To get the overall rating for a application release * To get the overall rating for a application release
* *
* @param appReleaseUuuid UUID of the application release. * @param appReleaseUuuid UUID of the application release.
* @return {@link Review}updated review * @return {@link ReviewTmp}updated review
* @throws ReviewManagementException Exceptions of the review management * @throws ReviewManagementException Exceptions of the review management
*/ */
Rating getRating(String appReleaseUuuid) throws ReviewManagementException; Rating getRating(String appReleaseUuuid) throws ReviewManagementException;

@ -0,0 +1,39 @@
/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.application.mgt.common.wrapper;
public class ReviewWrapper {
private String content;
private int rating;
public String getContent() {
return content;
}
public void setContent(String content) {
this.content = content;
}
public int getRating() {
return rating;
}
public void setRating(int rating) {
this.rating = rating;
}
}

@ -18,8 +18,9 @@
*/ */
package org.wso2.carbon.device.application.mgt.core.dao; package org.wso2.carbon.device.application.mgt.core.dao;
import org.wso2.carbon.device.application.mgt.common.Review; import org.wso2.carbon.device.application.mgt.common.ReviewTmp;
import org.wso2.carbon.device.application.mgt.common.PaginationRequest; import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
import org.wso2.carbon.device.application.mgt.common.dto.ReviewDTO;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException; 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.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.exception.ReviewManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ReviewManagementDAOException;
@ -34,38 +35,37 @@ import java.util.List;
public interface ReviewDAO { public interface ReviewDAO {
/** /**
* To add a review to an application release. * To add a reviewTmp to an application release.
* *
* @param tenantId tenantId. * @param tenantId tenantId.
* @param review review of the application. * @param reviewDTO reviewTmp of the application.
* @param uuid UUID of the application release * @param appReleaseId UUID of the application release
* @return If review is added successfully, it return true otherwise false * @return If reviewTmp is added successfully, it return true otherwise false
* @throws ReviewManagementDAOException Exceptions of the review management DAO. * @throws ReviewManagementDAOException Exceptions of the reviewTmp management DAO.
*/ */
boolean addReview(Review review, String uuid, int tenantId) throws ReviewManagementDAOException; boolean addReview(ReviewDTO reviewDTO, int appReleaseId, int tenantId) throws ReviewManagementDAOException;
/** /**
* To verify whether user has already commented for the application release or not. * To verify whether user has already commented for the application release or not.
* *
* @param uuid UUID of the application release. * @param appReleaseId ID of the application release.
* @param username username of the logged in user. * @param username username of the logged in user.
* @param tenantId tenantId of the commented application. * @param tenantId tenantId of the commented application.
* @return If review exists, review returns * @return If review exists, review returns
* @throws ReviewManagementDAOException Exceptions of the review management DAO. * @throws ReviewManagementDAOException Exceptions of the review management DAO.
*/ */
Review haveUerCommented(String uuid, String username, int tenantId) throws ReviewManagementDAOException; boolean haveUerReviewed(int appReleaseId, String username, int tenantId) throws ReviewManagementDAOException;
/** /**
* To update already added comment. * To update already added comment.
* *
* @param review Updating review * @param reviewDTO Updating reviewTmp
* @param reviewId id of the updating review * @param reviewId id of the updating reviewTmp
* @param username review owner
* @param tenantId tenant id * @param tenantId tenant id
* @return row count if updating is succeed otherwise 0 * @return row count if updating is succeed otherwise 0
* @throws ReviewManagementDAOException Exceptions of the review management. * @throws ReviewManagementDAOException Exceptions of the reviewTmp management.
*/ */
int updateReview(Review review, int reviewId, String username, int tenantId) int updateReview(ReviewDTO reviewDTO, int reviewId, int tenantId)
throws ReviewManagementDAOException; throws ReviewManagementDAOException;
@ -73,23 +73,29 @@ import java.util.List;
* To get the comment with id. * To get the comment with id.
* *
* @param reviewId id of the review * @param reviewId id of the review
* @return {@link Review}Review * @return {@link ReviewTmp}ReviewTmp
* @throws ReviewManagementDAOException Exceptions of the review management DAO. * @throws ReviewManagementDAOException Exceptions of the review management DAO.
*/ */
Review getReview(int reviewId) throws ReviewManagementDAOException; ReviewDTO getReview(int reviewId) throws ReviewManagementDAOException;
ReviewDTO getReview(int appReleaseId, int reviewId) throws ReviewManagementDAOException;
/** /**
* To get all reviews * To get all reviews
* *
* @param uuid uuid of the application * @param releaseId ID of the application release.
* @param request {@link PaginationRequest}pagination request with offSet and limit * @param request {@link PaginationRequest}pagination request with offSet and limit
* @param tenantId Tenant id * @param tenantId Tenant id
* @return {@link List}List of all reviews for the application release * @return {@link List}List of all reviews for the application release
* @throws ReviewManagementDAOException Review management DAO exception * @throws ReviewManagementDAOException ReviewTmp management DAO exception
**/ **/
List<Review> getAllReviews(String uuid, PaginationRequest request, int tenantId) List<ReviewDTO> getAllReviews(int releaseId, PaginationRequest request, int tenantId)
throws ReviewManagementDAOException; throws ReviewManagementDAOException;
List<ReviewDTO> getReplyComments(int parentId, int tenantId)
throws ReviewManagementDAOException;
/** /**
* To get list of comments using release id and application id. * To get list of comments using release id and application id.
* @param uuid UUID of the application release * @param uuid UUID of the application release
@ -119,7 +125,7 @@ import java.util.List;
* @param username username of the review owner * @param username username of the review owner
* @param reviewId id of the review * @param reviewId id of the review
* @return If review is successfully deleted return 1, otherwise returns 0. * @return If review is successfully deleted return 1, otherwise returns 0.
* @throws ReviewManagementDAOException Review management DAO exception. * @throws ReviewManagementDAOException ReviewTmp management DAO exception.
*/ */
int deleteReview(String username, int reviewId) throws ReviewManagementDAOException; int deleteReview(String username, int reviewId) throws ReviewManagementDAOException;
@ -137,8 +143,8 @@ import java.util.List;
* To get review count for a specific application release * To get review count for a specific application release
* *
* @param uuid uuid of the application release * @param uuid uuid of the application release
* @return Review count * @return ReviewTmp count
* @throws ReviewManagementDAOException Review management DAO exception * @throws ReviewManagementDAOException ReviewTmp management DAO exception
*/ */
int getReviewCount(String uuid) throws ReviewManagementDAOException; 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.common.exception.UnsupportedDatabaseEngineException;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; 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.*;
import org.wso2.carbon.device.application.mgt.core.dao.impl.Review.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.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.release.GenericApplicationReleaseDAOImpl;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.OracleApplicationDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.application.OracleApplicationDAOImpl;

@ -30,7 +30,7 @@ import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.dto.TagDTO; import org.wso2.carbon.device.application.mgt.common.dto.TagDTO;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.util.DAOUtil;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException; import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
@ -90,7 +90,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding the application", e); throw new ApplicationManagementDAOException("Error occurred while adding the application", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -120,7 +120,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"DB connection error occured while checking whether application exist or not.", e); "DB connection error occured while checking whether application exist or not.", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -158,6 +158,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "AP_APP_RELEASE.APP_HASH_VALUE AS RELEASE_HASH_VALUE, " + "AP_APP_RELEASE.APP_HASH_VALUE AS RELEASE_HASH_VALUE, "
+ "AP_APP_RELEASE.APP_PRICE AS RELEASE_PRICE, " + "AP_APP_RELEASE.APP_PRICE AS RELEASE_PRICE, "
+ "AP_APP_RELEASE.APP_META_INFO AS RELEASE_META_INFO, " + "AP_APP_RELEASE.APP_META_INFO AS RELEASE_META_INFO, "
+ "AP_APP_RELEASE.PACKAGE_NAME AS PACKAGE_NAME, "
+ "AP_APP_RELEASE.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, " + "AP_APP_RELEASE.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, "
+ "AP_APP_RELEASE.RATING AS RELEASE_RATING, " + "AP_APP_RELEASE.RATING AS RELEASE_RATING, "
+ "AP_APP_RELEASE.CURRENT_STATE AS RELEASE_CURRENT_STATE, " + "AP_APP_RELEASE.CURRENT_STATE AS RELEASE_CURRENT_STATE, "
@ -248,7 +249,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
stmt.setInt(paramIndex, filter.getOffset()); stmt.setInt(paramIndex, filter.getOffset());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
return Util.loadApplications(rs); return DAOUtil.loadApplications(rs);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while getting application list for the tenant" throw new ApplicationManagementDAOException("Error occurred while getting application list for the tenant"
+ " " + tenantId + ". While executing " + sql, e); + " " + tenantId + ". While executing " + sql, e);
@ -259,7 +260,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (JSONException e) { } catch (JSONException e) {
throw new ApplicationManagementDAOException("Error occurred while parsing JSON ", e); throw new ApplicationManagementDAOException("Error occurred while parsing JSON ", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -294,7 +295,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection for " throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection for "
+ "getting app release id", e); + "getting app release id", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -338,7 +339,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
return count; return count;
} }
@ -373,7 +374,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ appType + "and app name " + appName); + appType + "and app name " + appName);
} }
return Util.loadApplication(rs); return DAOUtil.loadApplication(rs);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
@ -386,7 +387,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (UnexpectedServerErrorException e) { } catch (UnexpectedServerErrorException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -416,7 +417,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
log.debug("Successfully retrieved basic details of the application with the id:" + id); log.debug("Successfully retrieved basic details of the application with the id:" + id);
} }
return Util.loadApplication(rs); return DAOUtil.loadApplication(rs);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
@ -429,7 +430,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (UnexpectedServerErrorException e) { } catch (UnexpectedServerErrorException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -468,6 +469,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "AP_APP_RELEASE.APP_HASH_VALUE AS RELEASE_HASH_VALUE, " + "AP_APP_RELEASE.APP_HASH_VALUE AS RELEASE_HASH_VALUE, "
+ "AP_APP_RELEASE.APP_PRICE AS RELEASE_PRICE, " + "AP_APP_RELEASE.APP_PRICE AS RELEASE_PRICE, "
+ "AP_APP_RELEASE.APP_META_INFO AS RELEASE_META_INFO, " + "AP_APP_RELEASE.APP_META_INFO AS RELEASE_META_INFO, "
+ "AP_APP_RELEASE.PACKAGE_NAME AS PACKAGE_NAME, "
+ "AP_APP_RELEASE.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, " + "AP_APP_RELEASE.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, "
+ "AP_APP_RELEASE.RATING AS RELEASE_RATING, " + "AP_APP_RELEASE.RATING AS RELEASE_RATING, "
+ "AP_APP_RELEASE.CURRENT_STATE AS RELEASE_CURRENT_STATE, " + "AP_APP_RELEASE.CURRENT_STATE AS RELEASE_CURRENT_STATE, "
@ -490,7 +492,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ releaseUuid); + releaseUuid);
} }
return Util.loadApplication(rs); return DAOUtil.loadApplication(rs);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
@ -503,7 +505,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (UnexpectedServerErrorException e) { } catch (UnexpectedServerErrorException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -542,6 +544,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "AP_APP_RELEASE.APP_HASH_VALUE AS RELEASE_HASH_VALUE, " + "AP_APP_RELEASE.APP_HASH_VALUE AS RELEASE_HASH_VALUE, "
+ "AP_APP_RELEASE.APP_PRICE AS RELEASE_PRICE, " + "AP_APP_RELEASE.APP_PRICE AS RELEASE_PRICE, "
+ "AP_APP_RELEASE.APP_META_INFO AS RELEASE_META_INFO, " + "AP_APP_RELEASE.APP_META_INFO AS RELEASE_META_INFO, "
+ "AP_APP_RELEASE.PACKAGE_NAME AS PACKAGE_NAME, "
+ "AP_APP_RELEASE.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, " + "AP_APP_RELEASE.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, "
+ "AP_APP_RELEASE.RATING AS RELEASE_RATING, " + "AP_APP_RELEASE.RATING AS RELEASE_RATING, "
+ "AP_APP_RELEASE.CURRENT_STATE AS RELEASE_CURRENT_STATE, " + "AP_APP_RELEASE.CURRENT_STATE AS RELEASE_CURRENT_STATE, "
@ -562,7 +565,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
log.debug("Successfully retrieved basic details of the application with the id " log.debug("Successfully retrieved basic details of the application with the id "
+ applicationId); + applicationId);
} }
return Util.loadApplication(rs); return DAOUtil.loadApplication(rs);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"Error occurred while getting application details with app id " + applicationId + "Error occurred while getting application details with app id " + applicationId +
@ -574,7 +577,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (UnexpectedServerErrorException e) { } catch (UnexpectedServerErrorException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -607,7 +610,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -662,7 +665,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while deleting the application: ", e); throw new ApplicationManagementDAOException("Error occurred while deleting the application: ", e);
} finally { } finally {
Util.cleanupResources(stmt, null); DAOUtil.cleanupResources(stmt, null);
} }
} }
@ -693,7 +696,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding tags", e); throw new ApplicationManagementDAOException("Error occurred while adding tags", e);
} finally { } finally {
Util.cleanupResources(stmt, null); DAOUtil.cleanupResources(stmt, null);
} }
} }
@ -730,7 +733,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding tags", e); throw new ApplicationManagementDAOException("Error occurred while adding tags", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -767,7 +770,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while getting categories", e); throw new ApplicationManagementDAOException("Error occurred while getting categories", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -859,7 +862,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding categories.", e); throw new ApplicationManagementDAOException("Error occurred while adding categories.", e);
} finally { } finally {
Util.cleanupResources(stmt, null); DAOUtil.cleanupResources(stmt, null);
} }
} }
@ -892,7 +895,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding data into category mapping.", e); throw new ApplicationManagementDAOException("Error occurred while adding data into category mapping.", e);
} finally { } finally {
Util.cleanupResources(stmt, null); DAOUtil.cleanupResources(stmt, null);
} }
} }
@ -1101,7 +1104,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding tags", e); throw new ApplicationManagementDAOException("Error occurred while adding tags", e);
} finally { } finally {
Util.cleanupResources(stmt, null); DAOUtil.cleanupResources(stmt, null);
} }
} }
@ -1459,7 +1462,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"Error occurred while deleting tags of application: " + applicationId, e); "Error occurred while deleting tags of application: " + applicationId, e);
} finally { } finally {
Util.cleanupResources(stmt, null); DAOUtil.cleanupResources(stmt, null);
} }
} }
@ -1497,7 +1500,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
ApplicationDTO application = null; ApplicationDTO application = null;
while (rs.next()) { while (rs.next()) {
ApplicationReleaseDTO appRelease = Util.loadApplicationRelease(rs); ApplicationReleaseDTO appRelease = DAOUtil.loadApplicationRelease(rs);
application = new ApplicationDTO(); application = new ApplicationDTO();
application.setId(rs.getInt("APP_ID")); application.setId(rs.getInt("APP_ID"));
@ -1528,7 +1531,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -1557,7 +1560,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while getting application List", e); throw new ApplicationManagementDAOException("Error occurred while getting application List", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }

@ -21,20 +21,6 @@ package org.wso2.carbon.device.application.mgt.core.dao.impl.application;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
import org.wso2.carbon.device.application.mgt.common.AppLifecycleState;
import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.Pagination;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
/** /**
* This is a ApplicationDAO Implementation specific to Oracle. * This is a ApplicationDAO Implementation specific to Oracle.

@ -21,13 +21,11 @@ package org.wso2.carbon.device.application.mgt.core.dao.impl.application.release
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.AppLifecycleState;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.ApplicationReleaseArtifactPaths;
import org.wso2.carbon.device.application.mgt.common.Rating; import org.wso2.carbon.device.application.mgt.common.Rating;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.util.DAOUtil;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
@ -118,7 +116,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"Database Connection Exception while trying to release a new version", e); "Database Connection Exception while trying to release a new version", e);
} finally { } finally {
Util.cleanupResources(statement, resultSet); DAOUtil.cleanupResources(statement, resultSet);
} }
} }
@ -160,7 +158,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
if (resultSet.next()) { if (resultSet.next()) {
return Util.loadApplicationRelease(resultSet); return DAOUtil.loadApplicationRelease(resultSet);
} }
return null; return null;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
@ -170,7 +168,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"Error while getting release details of the application " + applicationName + " and version " + versionName + " , while executing the query " + sql, e); "Error while getting release details of the application " + applicationName + " and version " + versionName + " , while executing the query " + sql, e);
} finally { } finally {
Util.cleanupResources(statement, resultSet); DAOUtil.cleanupResources(statement, resultSet);
} }
} }
@ -207,7 +205,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
if (resultSet.next()) { if (resultSet.next()) {
return Util.loadApplicationRelease(resultSet); return DAOUtil.loadApplicationRelease(resultSet);
} }
return null; return null;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
@ -219,7 +217,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
"Error while getting release details of the application id: " + applicationId "Error while getting release details of the application id: " + applicationId
+ " and theUUID of the application " + "release: " + releaseUuid + " , while executing the query " + sql, e); + " and theUUID of the application " + "release: " + releaseUuid + " , while executing the query " + sql, e);
} finally { } finally {
Util.cleanupResources(statement, resultSet); DAOUtil.cleanupResources(statement, resultSet);
} }
} }
@ -241,6 +239,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
+ "AR.APP_HASH_VALUE AS RELEASE_HASH_VALUE, " + "AR.APP_HASH_VALUE AS RELEASE_HASH_VALUE, "
+ "AR.APP_PRICE AS RELEASE_PRICE, " + "AR.APP_PRICE AS RELEASE_PRICE, "
+ "AR.APP_META_INFO AS RELEASE_META_INFO, " + "AR.APP_META_INFO AS RELEASE_META_INFO, "
+ "AR.PACKAGE_NAME AS PACKAGE_NAME, "
+ "AR.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, " + "AR.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, "
+ "AR.RATING AS RELEASE_RATING, " + "AR.RATING AS RELEASE_RATING, "
+ "AR.CURRENT_STATE AS RELEASE_CURRENT_STATE, " + "AR.CURRENT_STATE AS RELEASE_CURRENT_STATE, "
@ -255,7 +254,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
statement.setInt(2, tenantId); statement.setInt(2, tenantId);
try (ResultSet resultSet = statement.executeQuery()) { try (ResultSet resultSet = statement.executeQuery()) {
if (resultSet.next()) { if (resultSet.next()) {
return Util.loadAppRelease(resultSet); return DAOUtil.loadAppRelease(resultSet);
} }
return null; return null;
} }
@ -299,7 +298,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
ApplicationReleaseDTO applicationRelease = Util.loadApplicationRelease(resultSet); ApplicationReleaseDTO applicationRelease = DAOUtil.loadApplicationRelease(resultSet);
applicationReleases.add(applicationRelease); applicationReleases.add(applicationRelease);
} }
return applicationReleases; return applicationReleases;
@ -311,7 +310,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
"Error while getting all the release details of the app ID: " + applicationId "Error while getting all the release details of the app ID: " + applicationId
+ ", while executing the query " + sql, e); + ", while executing the query " + sql, e);
} finally { } finally {
Util.cleanupResources(statement, resultSet); DAOUtil.cleanupResources(statement, resultSet);
} }
} }
@ -342,7 +341,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
ApplicationReleaseDTO appRelease = Util.loadApplicationRelease(resultSet); ApplicationReleaseDTO appRelease = DAOUtil.loadApplicationRelease(resultSet);
applicationReleases.add(appRelease); applicationReleases.add(appRelease);
} }
return applicationReleases; return applicationReleases;
@ -354,7 +353,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
"Error while getting all the release details of the app id" + appId + " application" "Error while getting all the release details of the app id" + appId + " application"
+ ", while executing the query " + sql, e); + ", while executing the query " + sql, e);
} finally { } finally {
Util.cleanupResources(statement, resultSet); DAOUtil.cleanupResources(statement, resultSet);
} }
} }
@ -384,7 +383,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"SQL exception while updating the release rating value ,while executing the query " + sql, e); "SQL exception while updating the release rating value ,while executing the query " + sql, e);
} finally { } finally {
Util.cleanupResources(statement, null); DAOUtil.cleanupResources(statement, null);
} }
} }
@ -420,7 +419,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"SQL exception while updating the release ,while executing the query " + sql, e); "SQL exception while updating the release ,while executing the query " + sql, e);
} finally { } finally {
Util.cleanupResources(statement, resultSet); DAOUtil.cleanupResources(statement, resultSet);
} }
} }
@ -487,7 +486,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"SQL exception while updating the release ,while executing the query " + sql, e); "SQL exception while updating the release ,while executing the query " + sql, e);
} finally { } finally {
Util.cleanupResources(statement, null); DAOUtil.cleanupResources(statement, null);
} }
return applicationReleaseDTO; return applicationReleaseDTO;
} }
@ -512,7 +511,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
"SQL exception while deleting the release for release ID: " + id + ",while executing the query sql" "SQL exception while deleting the release for release ID: " + id + ",while executing the query sql"
, e); , e);
} finally { } finally {
Util.cleanupResources(statement, null); DAOUtil.cleanupResources(statement, null);
} }
} }
@ -566,7 +565,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -603,7 +602,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"Error occurred while obtaining the DB connection to get application release package name.", e); "Error occurred while obtaining the DB connection to get application release package name.", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -640,7 +639,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -674,7 +673,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -721,7 +720,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }

@ -24,7 +24,7 @@ import org.wso2.carbon.device.application.mgt.common.AppLifecycleState;
import org.wso2.carbon.device.application.mgt.common.LifecycleState; import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO; import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.util.DAOUtil;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagementDAOException;
@ -64,7 +64,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection to get latest" throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection to get latest"
+ " lifecycle state for a specific application", e); + " lifecycle state for a specific application", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -89,7 +89,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection to get latest" throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection to get latest"
+ " lifecycle state for a specific application", e); + " lifecycle state for a specific application", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -120,7 +120,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection to get latest" throw new LifeCycleManagementDAOException("Error occurred while obtaining the DB connection to get latest"
+ " lifecycle state for a specific application", e); + " lifecycle state for a specific application", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -199,7 +199,7 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif
log.error("Error occurred while adding lifecycle: " + state.getCurrentState(), e); log.error("Error occurred while adding lifecycle: " + state.getCurrentState(), e);
throw new LifeCycleManagementDAOException("Error occurred while adding lifecycle: " + state.getCurrentState(), e); throw new LifeCycleManagementDAOException("Error occurred while adding lifecycle: " + state.getCurrentState(), e);
} finally { } finally {
Util.cleanupResources(stmt, null); DAOUtil.cleanupResources(stmt, null);
} }
} }

@ -16,19 +16,21 @@
* under the License. * under the License.
* *
*/ */
package org.wso2.carbon.device.application.mgt.core.dao.impl.Review; package org.wso2.carbon.device.application.mgt.core.dao.impl.review;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.Review;
import org.wso2.carbon.device.application.mgt.common.PaginationRequest; import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
import org.wso2.carbon.device.application.mgt.common.dto.ReviewDTO;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException; 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.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.ReviewDAO; 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.exception.UnexpectedServerErrorException;
import org.wso2.carbon.device.application.mgt.core.util.DAOUtil;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
import org.wso2.carbon.device.application.mgt.core.exception.ReviewManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ReviewManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.util.Constants;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -49,206 +51,286 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
private String sql; private String sql;
@Override @Override
public boolean addReview(Review review, String uuid, int tenantId) throws ReviewManagementDAOException { public boolean addReview(ReviewDTO reviewDTO, int appReleaseId, int tenantId) throws ReviewManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to add review for application release. ApplicationDTO UUID: " + uuid); log.debug("Request received in DAO Layer to add review for application release. Application Release UUID: "
+ appReleaseId);
} }
PreparedStatement statement = null; sql = "INSERT INTO AP_APP_REVIEW "
ResultSet rs = null; + "(TENANT_ID, "
sql = "INSERT INTO AP_APP_REVIEW (TENANT_ID, COMMENT, PARENT_ID, RATING, USERNAME,CREATED_AT, MODIFIED_AT, " + "COMMENT, "
+ "AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?,?,?,?,?,?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID= ?)," + "ROOT_PARENT_ID,"
+ "(SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID=?));"; + "IMMEDIATE_PARENT_ID, "
+ "RATING, "
+ "USERNAME, "
+ "CREATED_AT, "
+ "MODIFIED_AT, "
+ "AP_APP_RELEASE_ID) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ? )";
try { try {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
statement = conn.prepareStatement(sql, new String[] { "id" }); try (PreparedStatement statement = conn.prepareStatement(sql, new String[] { "id" });) {
statement.setInt(1, tenantId); statement.setInt(1, tenantId);
statement.setString(2, review.getComment()); statement.setString(2, reviewDTO.getContent());
statement.setInt(3, review.getParentId()); statement.setInt(3, reviewDTO.getRootParentId());
statement.setInt(4, review.getRating()); statement.setInt(4, reviewDTO.getImmediateParentId());
statement.setString(5, review.getUsername()); statement.setInt(5, reviewDTO.getRating());
statement.setTimestamp(6, timestamp); statement.setString(6, reviewDTO.getUsername());
statement.setTimestamp(7,timestamp); statement.setTimestamp(7, timestamp);
statement.setString(8,uuid); statement.setTimestamp(8, timestamp);
statement.setString(9,uuid); statement.setInt(9, appReleaseId);
statement.executeUpdate(); statement.executeUpdate();
rs = statement.getGeneratedKeys(); try (ResultSet rs = statement.getGeneratedKeys()) {
return rs.next(); return rs.next();
} }
catch (DBConnectionException e) { }
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException("Error occurred while obtaining the DB connection while " throw new ReviewManagementDAOException("Error occurred while obtaining the DB connection while "
+ "adding review for application UUID: "+ "Tenant Id: " + tenantId, e); + "adding review for application release which has ID: "+ appReleaseId + "Tenant Id: " + tenantId, e);
}catch (SQLException e) { } catch (SQLException e) {
throw new ReviewManagementDAOException("Error occurred while getting application list for the tenant" throw new ReviewManagementDAOException(
+ " " + tenantId + ". While executing " + sql, e); "Error occurred while executing SQL statement to add application review. Application ID: "
} finally { + appReleaseId + " tenant " + tenantId, e);
Util.cleanupResources(statement, rs);
} }
} }
@Override @Override
public Review haveUerCommented(String uuid, String username, int tenantId) throws ReviewManagementDAOException { public boolean haveUerReviewed(int appReleaseId, String username, int tenantId) throws ReviewManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug( log.debug("Request received in DAO Layer to check whether user have already reviewed or not for the "
"Request received in DAO Layer to check whether user have already commented or not for the " + "application release. Commenting user: " + username + " and tenant-id: " + tenantId);
+ "application release. ApplicationDTO UUID: " + uuid + " comment owner: " + username +
" tenant-id " + tenantId);
} }
Connection conn; Connection conn;
PreparedStatement statement = null; sql = "SELECT "
ResultSet rs = null; + "rv.ID "
Review review = null; + "FROM AP_APP_REVIEW rv "
sql = "SELECT ID, COMMENT, CREATED_AT, MODIFIED_AT, USERNAME, PARENT_ID, RATING FROM AP_APP_REVIEW WHERE " + "WHERE "
+ "AP_APP_RELEASE_ID = (SELECT ID FROM AP_APP_RELEASE WHERE UUID=?) AND USERNAME = ? AND TENANT_ID = ?;"; + "rv.AP_APP_RELEASE_ID = ? AND "
+ "rv.USERNAME = ? AND "
+ "rv.TENANT_ID = ?";
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
statement = conn.prepareStatement(sql); try (PreparedStatement statement = conn.prepareStatement(sql)) {
statement.setString(1, uuid); statement.setInt(1, appReleaseId);
statement.setString(2, username); statement.setString(2, username);
statement.setInt(3, tenantId); statement.setInt(3, tenantId);
rs = statement.executeQuery(); try (ResultSet rs = statement.executeQuery()) {
if (rs.next()){ return rs.next();
review = new Review();
review.setId(rs.getInt("ID")); }
review.setComment(rs.getString("COMMENT"));
review.setParentId(rs.getInt("PARENT_ID"));
review.setCreatedAt(rs.getTimestamp("CREATED_AT"));
review.setModifiedAt(rs.getTimestamp("MODIFIED_AT"));
review.setUsername(rs.getString("USERNAME"));
review.setRating(rs.getInt("RATING"));
} }
return review;
} catch (SQLException e) { } catch (SQLException e) {
throw new ReviewManagementDAOException("Error occured while accessing the Database when checking whether " throw new ReviewManagementDAOException("Error occured while accessing the Database when checking whether "
+ "user has already commented for the application ro not", e); + "user has already commented for the application ro not", e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ReviewManagementDAOException("Error occured while getting the database connection when checking " throw new ReviewManagementDAOException("Error occured while getting the database connection when checking "
+ "whether user has already commented for the application ro not", e); + "whether user has already commented for the application ro not", e);
} finally {
Util.cleanupResources(statement, rs);
} }
} }
@Override @Override
public int updateReview(Review review, int reviewId, String username, int tenantId) public int updateReview(ReviewDTO reviewDTO, int reviewId, int tenantId)
throws ReviewManagementDAOException { throws ReviewManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to update the comment with ID (" + reviewId + ")"); log.debug("Request received in DAO Layer to update the Review with ID (" + reviewId + ")");
} }
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet rs = null; ResultSet rs = null;
sql = "UPDATE AP_APP_REVIEW SET COMMENT=?, RATING=?, MODIFIED_AT=? WHERE ID=? AND USERNAME=? AND TENANT_ID=?;"; sql = "UPDATE "
+ "AP_APP_REVIEW "
+ "SET "
+ "COMMENT = ?, "
+ "RATING = ?, "
+ "MODIFIED_AT = ? "
+ "WHERE ID = ? AND "
+ "TENANT_ID = ?";
try { try {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
connection = this.getDBConnection(); connection = this.getDBConnection();
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
statement.setString(1, review.getComment()); statement.setString(1, reviewDTO.getContent());
statement.setInt(2, review.getRating()); statement.setInt(2, reviewDTO.getRating());
statement.setTimestamp(3, timestamp); statement.setTimestamp(3, timestamp);
statement.setInt(4, reviewId); statement.setInt(4, reviewId);
statement.setString(5, username); statement.setInt(5, tenantId);
statement.setInt(6, tenantId);
return statement.executeUpdate(); return statement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
throw new ReviewManagementDAOException("Error occurred while executing review updating query"); throw new ReviewManagementDAOException("Error occurred while executing reviewTmp updating query");
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ReviewManagementDAOException("Error occured while getting the db connection to update review"); throw new ReviewManagementDAOException("Error occured while getting the db connection to update reviewTmp");
} finally { } finally {
Util.cleanupResources(statement, rs); DAOUtil.cleanupResources(statement, rs);
} }
} }
@Override @Override
public Review getReview(int reviewId) throws ReviewManagementDAOException { public ReviewDTO getReview(int reviewId) throws ReviewManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting review with the review id(" + reviewId + ") from the database"); log.debug("Getting reviewDTO with the review id(" + reviewId + ") from the database");
} }
Connection conn; Connection conn;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet rs = null; ResultSet rs = null;
Review review = null;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql = "SELECT ID, COMMENT, CREATED_AT, MODIFIED_AT, RATING, USERNAME FROM AP_APP_REVIEW WHERE ID=?;"; sql = "SELECT "
+ "ID, "
+ "COMMENT,"
+ "ROOT_PARENT_ID,"
+ "IMMEDIATE_PARENT_ID, "
+ "CREATED_AT, "
+ "MODIFIED_AT, "
+ "RATING, "
+ "USERNAME "
+ "FROM AP_APP_REVIEW "
+ "WHERE ID = ?";
statement = conn.prepareStatement(sql); statement = conn.prepareStatement(sql);
statement.setInt(1, reviewId); statement.setInt(1, reviewId);
rs = statement.executeQuery(); rs = statement.executeQuery();
if (rs.next()) { return DAOUtil.loadReview(rs);
review = new Review();
review.setId(rs.getInt("ID"));
review.setComment(rs.getString("COMMENT"));
review.setCreatedAt(rs.getTimestamp("CREATED_AT"));
review.setModifiedAt(rs.getTimestamp("MODIFIED_AT"));
review.setRating(rs.getInt("RATING"));
review.setUsername(rs.getString("USERNAME"));
return review;
}
} catch (SQLException e) { } catch (SQLException e) {
throw new ReviewManagementDAOException( throw new ReviewManagementDAOException(
"SQL Error occurred while retrieving information of the review " + reviewId, e); "SQL Error occurred while retrieving information of the reviewTmp " + reviewId, e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ReviewManagementDAOException( throw new ReviewManagementDAOException(
"DB Connection Exception occurred while retrieving information of the review " + reviewId, e); "DB Connection Exception occurred while retrieving information of the reviewTmp " + reviewId, e);
} catch (UnexpectedServerErrorException e) {
throw new ReviewManagementDAOException("Found more than one review for review ID: " + reviewId, e);
} finally { } finally {
Util.cleanupResources(statement, rs); DAOUtil.cleanupResources(statement, rs);
} }
return review;
} }
@Override @Override
public List<Review> getAllReviews(String uuid, PaginationRequest request, int tenantId) public ReviewDTO getReview(int appReleaseId, int reviewId) throws ReviewManagementDAOException {
throws ReviewManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting comment of the application release (" + uuid + ") from the database"); log.debug("Getting reviewDTO with the review id(" + reviewId + ") from the database");
} }
Connection conn; Connection conn;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet rs = null; ResultSet rs = null;
List<Review> reviews = new ArrayList<>();
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql = "SELECT AP_APP_REVIEW.ID AS ID, AP_APP_REVIEW.COMMENT AS COMMENT, " sql = "SELECT "
+ "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, " + "ID, "
+ "AP_APP_REVIEW.USERNAME AS USERNAME, AP_APP_REVIEW.PARENT_ID AS PARENT_ID, " + "COMMENT,"
+ "AP_APP_REVIEW.RATING AS RATING FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE " + "ROOT_PARENT_ID,"
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_RELEASE.UUID =? " + "IMMEDIATE_PARENT_ID, "
+ "AND AP_APP_REVIEW.TENANT_ID = ? AND " + "CREATED_AT, "
+ "AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID LIMIT ? OFFSET ?;"; + "MODIFIED_AT, "
+ "RATING, "
+ "USERNAME "
+ "FROM AP_APP_REVIEW "
+ "WHERE ID = ? AND "
+ "AP_APP_RELEASE_ID = ?";
statement = conn.prepareStatement(sql); statement = conn.prepareStatement(sql);
statement.setString(1, uuid); statement.setInt(1, reviewId);
statement.setInt(2, tenantId); statement.setInt(2, appReleaseId);
statement.setInt(3, request.getLimit());
statement.setInt(4, request.getOffSet());
rs = statement.executeQuery(); rs = statement.executeQuery();
while (rs.next()) { return DAOUtil.loadReview(rs);
Review review = new Review(); } catch (SQLException e) {
review.setId(rs.getInt("ID")); throw new ReviewManagementDAOException(
review.setComment(rs.getString("COMMENT")); "SQL Error occurred while retrieving information of the reviewTmp " + reviewId, e);
review.setCreatedAt(rs.getTimestamp("CREATED_AT")); } catch (DBConnectionException e) {
review.setModifiedAt(rs.getTimestamp("MODIFIED_AT")); throw new ReviewManagementDAOException(
review.setParentId(rs.getInt("PARENT_ID")); "DB Connection Exception occurred while retrieving information of the reviewTmp " + reviewId, e);
review.setUsername(rs.getString("USERNAME")); } catch (UnexpectedServerErrorException e) {
review.setRating(rs.getInt("RATING")); throw new ReviewManagementDAOException("Found more than one review for review ID: " + reviewId, e);
reviews.add(review); } finally {
DAOUtil.cleanupResources(statement, rs);
}
}
@Override
public List<ReviewDTO> getAllReviews(int releaseId, PaginationRequest request, int tenantId)
throws ReviewManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting comment of the application release (" + releaseId + ") from the database");
}
Connection conn;
List<ReviewDTO> reviewDTOs = new ArrayList<>();
try {
conn = this.getDBConnection();
sql = "SELECT "
+ "AP_APP_REVIEW.ID AS ID, "
+ "AP_APP_REVIEW.COMMENT AS COMMENT, "
+ "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, "
+ "AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, "
+ "AP_APP_REVIEW.USERNAME AS USERNAME, "
+ "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, "
+ "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, "
+ "AP_APP_REVIEW.RATING AS RATING "
+ "FROM AP_APP_REVIEW "
+ "WHERE "
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID = ? AND "
+ "AP_APP_REVIEW.ROOT_PARENT_ID = ? AND "
+ "AP_APP_REVIEW.TENANT_ID = ? "
+ "LIMIT ? OFFSET ?";
try (PreparedStatement statement = conn.prepareStatement(sql)) {
statement.setInt(1, releaseId);
statement.setInt(2, Constants.REVIEW_PARENT_ID);
statement.setInt(3, tenantId);
statement.setInt(4, request.getLimit());
statement.setInt(5, request.getOffSet());
try (ResultSet rs = statement.executeQuery()) {
reviewDTOs = DAOUtil.loadReviews(rs);
}
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ReviewManagementDAOException( throw new ReviewManagementDAOException(
"Error occurred while obtaining the DB connection when verifying application existence", e); "Error occurred while obtaining the DB connection when verifying application existence", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ReviewManagementDAOException("DB connection error occurred while getting all reviews", e); throw new ReviewManagementDAOException("DB connection error occurred while getting all reviewTmps", e);
}finally { } return reviewDTOs;
Util.cleanupResources(statement, rs); }
@Override
public List<ReviewDTO> getReplyComments(int parentId, int tenantId) throws ReviewManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting comment of the application release (" + parentId + ") from the database");
} }
return reviews; Connection conn;
List<ReviewDTO> reviewDTOs;
try {
conn = this.getDBConnection();
sql = "SELECT "
+ "AP_APP_REVIEW.ID AS ID, "
+ "AP_APP_REVIEW.COMMENT AS COMMENT, "
+ "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, "
+ "AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, "
+ "AP_APP_REVIEW.USERNAME AS USERNAME, "
+ "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, "
+ "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, "
+ "AP_APP_REVIEW.RATING AS RATING "
+ "FROM AP_APP_REVIEW "
+ "WHERE "
+ "AP_APP_REVIEW.ROOT_PARENT_ID = ? AND "
+ "AP_APP_REVIEW.TENANT_ID = ?";
try (PreparedStatement statement = conn.prepareStatement(sql)) {
statement.setInt(1, parentId);
statement.setInt(2, tenantId);
try (ResultSet rs = statement.executeQuery();) {
reviewDTOs = DAOUtil.loadReviews(rs);
}
}
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException(
"Error occurred while obtaining the DB connection when getting reply comments for a review.", e);
} catch (SQLException e) {
throw new ReviewManagementDAOException("DB connection error occurred while getting reply comments", e);
}
return reviewDTOs;
} }
@Override @Override
@ -282,7 +364,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
"Error occured while getting DB connection to retrieve all rating values for the application release. App release UUID: " "Error occured while getting DB connection to retrieve all rating values for the application release. App release UUID: "
+ uuid, e); + uuid, e);
} finally { } finally {
Util.cleanupResources(statement, rs); DAOUtil.cleanupResources(statement, rs);
} }
return reviews; return reviews;
} }
@ -316,7 +398,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ReviewManagementDAOException("DB Connection Exception occurred while retrieving review counts", e); throw new ReviewManagementDAOException("DB Connection Exception occurred while retrieving review counts", e);
} finally { } finally {
Util.cleanupResources(statement, rs); DAOUtil.cleanupResources(statement, rs);
} }
return commentCount; return commentCount;
} }
@ -345,7 +427,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
commentCount = rs.getInt("COMMENT_COUNT"); commentCount = rs.getInt("COMMENT_COUNT");
} }
} finally { } finally {
Util.cleanupResources(statement, rs); DAOUtil.cleanupResources(statement, rs);
} }
return commentCount; return commentCount;
} }
@ -367,7 +449,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
throw new ReviewManagementDAOException("Error occured while getting the database connection", e); throw new ReviewManagementDAOException("Error occured while getting the database connection", e);
} finally { } finally {
Util.cleanupResources(statement, null); DAOUtil.cleanupResources(statement, null);
} }
} }
@ -395,7 +477,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
} catch (SQLException e) { } catch (SQLException e) {
throw new ReviewManagementException("SQL Error occurred while deleting comments", e); throw new ReviewManagementException("SQL Error occurred while deleting comments", e);
} finally { } finally {
Util.cleanupResources(statement, null); DAOUtil.cleanupResources(statement, null);
} }
} }
} }

@ -19,15 +19,12 @@ package org.wso2.carbon.device.application.mgt.core.dao.impl.subscription;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.json.JSONException;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO; import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO; import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.util.DAOUtil;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup;
@ -70,7 +67,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
throw new ApplicationManagementDAOException("Error occurred while adding device application mapping to DB", throw new ApplicationManagementDAOException("Error occurred while adding device application mapping to DB",
e); e);
} finally { } finally {
Util.cleanupResources(stmt, null); DAOUtil.cleanupResources(stmt, null);
} }
} }
@ -104,7 +101,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
throw new ApplicationManagementDAOException("Error occurred while adding device application mapping to DB", throw new ApplicationManagementDAOException("Error occurred while adding device application mapping to DB",
e); e);
} finally { } finally {
Util.cleanupResources(stmt, null); DAOUtil.cleanupResources(stmt, null);
} }
} }
@ -137,7 +134,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
throw new ApplicationManagementDAOException("Error occurred while adding device application mapping to DB", throw new ApplicationManagementDAOException("Error occurred while adding device application mapping to DB",
e); e);
} finally { } finally {
Util.cleanupResources(stmt, null); DAOUtil.cleanupResources(stmt, null);
} }
} }
@ -170,7 +167,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
throw new ApplicationManagementDAOException("Error occurred while adding device application mapping to DB", throw new ApplicationManagementDAOException("Error occurred while adding device application mapping to DB",
e); e);
} finally { } finally {
Util.cleanupResources(stmt, null); DAOUtil.cleanupResources(stmt, null);
} }
} }
@ -203,7 +200,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
log.debug("Successfully retrieved device subscriptions for application release id " log.debug("Successfully retrieved device subscriptions for application release id "
+ appReleaseId); + appReleaseId);
} }
return Util.loadDeviceSubscriptions(rs); return DAOUtil.loadDeviceSubscriptions(rs);
} }
} }
} catch (SQLException e) { } catch (SQLException e) {

@ -21,7 +21,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO; import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.util.DAOUtil;
import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl; import org.wso2.carbon.device.application.mgt.core.dao.impl.AbstractDAOImpl;
import org.wso2.carbon.device.application.mgt.core.exception.VisibilityManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.VisibilityManagementDAOException;
@ -66,7 +66,7 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
}catch (SQLException e) { }catch (SQLException e) {
throw new VisibilityManagementDAOException("Error occurred while adding unrestricted roles", e); throw new VisibilityManagementDAOException("Error occurred while adding unrestricted roles", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -100,7 +100,7 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
}catch (SQLException e) { }catch (SQLException e) {
throw new VisibilityManagementDAOException("Error occurred while adding unrestricted roles", e); throw new VisibilityManagementDAOException("Error occurred while adding unrestricted roles", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -167,7 +167,7 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
}catch (SQLException e) { }catch (SQLException e) {
throw new VisibilityManagementDAOException("Error occurred while adding unrestricted roles", e); throw new VisibilityManagementDAOException("Error occurred while adding unrestricted roles", e);
} finally { } finally {
Util.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
} }
} }

@ -16,8 +16,6 @@
*/ */
package org.wso2.carbon.device.application.mgt.core.exception; package org.wso2.carbon.device.application.mgt.core.exception;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
/** /**
* Exception thrown during the ApplicationDTO Management DAO operations. * Exception thrown during the ApplicationDTO Management DAO operations.
*/ */

@ -21,7 +21,7 @@ package org.wso2.carbon.device.application.mgt.core.exception;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException;
/** /**
* Exception thrown during the Review Management DAO operations. * Exception thrown during the ReviewTmp Management DAO operations.
*/ */
public class ReviewManagementDAOException extends ReviewManagementException { public class ReviewManagementDAOException extends ReviewManagementException {

@ -65,7 +65,7 @@ import org.wso2.carbon.device.application.mgt.core.dao.LifecycleStateDAO;
import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO; import org.wso2.carbon.device.application.mgt.core.dao.SubscriptionDAO;
import org.wso2.carbon.device.application.mgt.core.dao.VisibilityDAO; 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.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.util.DAOUtil;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException; import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException;
@ -251,7 +251,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
//insert application data into databse //insert application data into databse
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
try { try {
List<ApplicationReleaseDTO> applicationReleaseEntities = new ArrayList<>(); List<ApplicationReleaseDTO> applicationReleaseEntities = new ArrayList<>();
@ -379,7 +379,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
private void deleteApplicationArtifacts(List<String> directoryPaths) throws ApplicationManagementException { private void deleteApplicationArtifacts(List<String> directoryPaths) throws ApplicationManagementException {
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
try { try {
applicationStorageManager.deleteAllApplicationReleaseArtifacts(directoryPaths); applicationStorageManager.deleteAllApplicationReleaseArtifacts(directoryPaths);
@ -395,7 +395,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact, boolean isNewRelease) ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact, boolean isNewRelease)
throws ResourceManagementException, ApplicationManagementException { throws ResourceManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
applicationReleaseDTO.setUuid(uuid); applicationReleaseDTO.setUuid(uuid);
@ -478,7 +478,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact) ApplicationReleaseDTO applicationReleaseDTO, ApplicationArtifact applicationArtifact)
throws ResourceManagementException, ApplicationManagementException { throws ResourceManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
// The application executable artifacts such as apks are uploaded. // The application executable artifacts such as apks are uploaded.
if (ApplicationType.ENTERPRISE.toString().equals(applicationType)) { if (ApplicationType.ENTERPRISE.toString().equals(applicationType)) {
@ -562,7 +562,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
private ApplicationReleaseDTO addImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO, private ApplicationReleaseDTO addImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO,
ApplicationArtifact applicationArtifact) throws ResourceManagementException { ApplicationArtifact applicationArtifact) throws ResourceManagementException {
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
applicationReleaseDTO.setIconName(applicationArtifact.getIconName()); applicationReleaseDTO.setIconName(applicationArtifact.getIconName());
applicationReleaseDTO.setBannerName(applicationArtifact.getBannerName()); applicationReleaseDTO.setBannerName(applicationArtifact.getBannerName());
@ -591,7 +591,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
private ApplicationReleaseDTO updateImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO, private ApplicationReleaseDTO updateImageArtifacts(ApplicationReleaseDTO applicationReleaseDTO,
ApplicationArtifact applicationArtifact) throws ResourceManagementException{ ApplicationArtifact applicationArtifact) throws ResourceManagementException{
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
applicationStorageManager.deleteImageArtifacts(applicationReleaseDTO); applicationStorageManager.deleteImageArtifacts(applicationReleaseDTO);
@ -1193,7 +1193,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ applicationId); + applicationId);
} }
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
ApplicationDTO applicationDTO = getApplication(applicationId); ApplicationDTO applicationDTO = getApplication(applicationId);
List<ApplicationReleaseDTO> applicationReleaseDTOs = applicationDTO.getApplicationReleaseDTOs(); List<ApplicationReleaseDTO> applicationReleaseDTOs = applicationDTO.getApplicationReleaseDTOs();
for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOs) { for (ApplicationReleaseDTO applicationReleaseDTO : applicationReleaseDTOs) {
@ -1334,7 +1334,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
public void deleteApplicationRelease(String releaseUuid) public void deleteApplicationRelease(String releaseUuid)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO
@ -1477,7 +1477,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
boolean isValidDeviceType = false; boolean isValidDeviceType = false;
List<DeviceType> deviceTypes; List<DeviceType> deviceTypes;
try { try {
deviceTypes = Util.getDeviceManagementService().getDeviceTypes(); deviceTypes = DAOUtil.getDeviceManagementService().getDeviceTypes();
for (DeviceType dt : deviceTypes) { for (DeviceType dt : deviceTypes) {
if (dt.getName().equals(deviceType)) { if (dt.getName().equals(deviceType)) {
@ -1618,7 +1618,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public void changeLifecycleState(String releaseUuid, LifecycleChanger lifecycleChanger) public ApplicationRelease changeLifecycleState(String releaseUuid, LifecycleChanger lifecycleChanger)
throws ApplicationManagementException { throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -1664,6 +1664,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId); this.lifecycleStateDAO.addLifecycleState(lifecycleState, applicationReleaseDTO.getId(), tenantId);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return releaseDtoToRelease(applicationReleaseDTO);
} else { } else {
String msg = "Invalid lifecycle state transition from '" + applicationReleaseDTO.getCurrentState() + "'" String msg = "Invalid lifecycle state transition from '" + applicationReleaseDTO.getCurrentState() + "'"
+ " to '" + lifecycleChanger.getAction() + "'"; + " to '" + lifecycleChanger.getAction() + "'";
@ -2397,6 +2398,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new RequestValidatingException(msg); throw new RequestValidatingException(msg);
} }
if (applicationWrapper.getAppCategories() == null) {
String msg = "Application category can't be null.";
log.error(msg);
throw new RequestValidatingException(msg);
}
if (applicationWrapper.getAppCategories().isEmpty()) { if (applicationWrapper.getAppCategories().isEmpty()) {
String msg = "Application category can't be empty."; String msg = "Application category can't be empty.";
log.error(msg); log.error(msg);
@ -2595,7 +2601,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throws BadRequestException, UnexpectedServerErrorException { throws BadRequestException, UnexpectedServerErrorException {
List<DeviceType> deviceTypes; List<DeviceType> deviceTypes;
try { try {
deviceTypes = Util.getDeviceManagementService().getDeviceTypes(); deviceTypes = DAOUtil.getDeviceManagementService().getDeviceTypes();
if(deviceTypeAttr instanceof String){ if(deviceTypeAttr instanceof String){
for (DeviceType dt : deviceTypes) { for (DeviceType dt : deviceTypes) {

@ -29,7 +29,7 @@ import org.wso2.carbon.device.application.mgt.common.services.AppmDataHandler;
import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration; import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.util.DAOUtil;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
@ -67,7 +67,7 @@ public class AppmDataHandlerImpl implements AppmDataHandler {
@Override @Override
public InputStream getArtifactStream(String uuid, String artifactName) throws ApplicationManagementException { public InputStream getArtifactStream(String uuid, String artifactName) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
ApplicationReleaseDAO applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO(); ApplicationReleaseDAO applicationReleaseDAO = ApplicationManagementDAOFactory.getApplicationReleaseDAO();
String artifactPath; String artifactPath;
String appReleaseHashValue; String appReleaseHashValue;

@ -22,17 +22,25 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.Rating; import org.wso2.carbon.device.application.mgt.common.Rating;
import org.wso2.carbon.device.application.mgt.common.Review; import org.wso2.carbon.device.application.mgt.common.ReviewNode;
import org.wso2.carbon.device.application.mgt.common.PaginationRequest; 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.PaginationResult;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.dto.ReviewDTO;
import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewDoesNotExistException; 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.ReviewManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException; import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.common.exception.TransactionManagementException;
import org.wso2.carbon.device.application.mgt.common.response.Review;
import org.wso2.carbon.device.application.mgt.common.services.*; import org.wso2.carbon.device.application.mgt.common.services.*;
import org.wso2.carbon.device.application.mgt.common.wrapper.ReviewWrapper;
import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO; import org.wso2.carbon.device.application.mgt.core.dao.ApplicationReleaseDAO;
import org.wso2.carbon.device.application.mgt.core.dao.ReviewDAO; import org.wso2.carbon.device.application.mgt.core.dao.ReviewDAO;
import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagementDAOFactory; 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.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.exception.ReviewManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ReviewManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
@ -42,6 +50,7 @@ import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Comparator;
import java.util.List; import java.util.List;
import java.util.TreeMap; import java.util.TreeMap;
@ -64,34 +73,124 @@ public class ReviewManagerImpl implements ReviewManager {
} }
@Override @Override
public boolean addReview(Review review, String uuid) throws ReviewManagementException, NotFoundException { public boolean addReview(ReviewWrapper reviewWrapper, String uuid)
throws ReviewManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
boolean isSuccess = false;
if (reviewWrapper == null) {
String msg = "Request payload is null. Please verify the request payload.";
log.error(msg);
throw new BadRequestException(msg);
}
if (reviewWrapper.getRating() < 0) {
String msg = "You are trying to add invalid rating value as rating. Therefore please verify the request "
+ "payload.";
log.error(msg);
throw new ForbiddenException(msg);
}
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.beginDBTransaction();
if (!this.applicationReleaseDAO.verifyReleaseExistenceByUuid(uuid, tenantId)){ ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO.getReleaseByUUID(uuid, tenantId);
throw new NotFoundException("Couldn't find application release for the application UUID: " + uuid); if (applicationReleaseDTO == null) {
String msg = "Couldn't find application release for the application UUID: " + uuid;
log.error(msg);
throw new NotFoundException(msg);
} }
Review existingReview = this.reviewDAO.haveUerCommented(uuid, username, tenantId); if (this.reviewDAO.haveUerReviewed(applicationReleaseDTO.getId(), username, tenantId)) {
if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId) String msg =
&& review.getRating() > 0 && review.getRating() != existingReview.getRating()) { "User " + username + " has already reviewed the application release which has UUID: " + uuid
Runnable task = () -> calculateRating(review.getRating(), existingReview.getRating(), uuid, tenantId); + ". Hence you can't add another review for same application release. But you can update "
new Thread(task).start(); + "the review that you have already added for ths application release.";
isSuccess = updateReview(review, existingReview.getId(), uuid, existingReview); log.error(msg);
} else if (review.getRating() > 0) { throw new ForbiddenException(msg);
Runnable task = () -> calculateRating(review.getRating(), -12345, uuid, tenantId); }
new Thread(task).start(); Runnable task = () -> calculateRating(reviewWrapper.getRating(), -12345, uuid, tenantId);
review.setUsername(username); new Thread(task).start();
isSuccess = this.reviewDAO.addReview(review, uuid, tenantId);
ReviewDTO reviewDTO = reviewWrapperToDO(reviewWrapper);
reviewDTO.setUsername(username);
reviewDTO.setRootParentId(-1);
reviewDTO.setImmediateParentId(-1);
if (this.reviewDAO.addReview(reviewDTO, applicationReleaseDTO.getId(), tenantId)) {
ConnectionManagerUtil.commitDBTransaction();
return true;
}
ConnectionManagerUtil.rollbackDBTransaction();
return false;
} catch (DBConnectionException e) {
String msg = "DB Connection error occurs when adding Review for application release with UUID: " + uuid
+ " is failed";
log.error(msg);
throw new ReviewManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "DB transaction error occurred when adding review for application release which has "
+ "application UUID: " + uuid;
log.error(msg);
throw new ReviewManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when getting application release data for application release UUID:." + uuid;
log.error(msg);
throw new ReviewManagementException(msg, e);
} catch (ReviewManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred when getting review data or adding review data for application release which "
+ "has UUID: " + uuid;
log.error(msg);
throw new ReviewManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public boolean addReplyComment(ReviewWrapper reviewWrapper, String uuid, int parentReviewId)
throws ReviewManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (reviewWrapper == null) {
String msg = "Request payload is null. Please verify the request payload.";
log.error(msg);
throw new BadRequestException(msg);
}
try {
ConnectionManagerUtil.beginDBTransaction();
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO.getReleaseByUUID(uuid, tenantId);
if (applicationReleaseDTO == null) {
String msg = "Couldn't find application release for the application UUID: " + uuid;
log.error(msg);
throw new NotFoundException(msg);
} }
return isSuccess; ReviewDTO parentReview = this.reviewDAO.getReview(applicationReleaseDTO.getId(), parentReviewId);
if (parentReview == null) {
String msg = "Couldn't find an review which has review ID: " + parentReviewId
+ " for application release which has UUID: " + uuid;
log.error(msg);
throw new BadRequestException(msg);
}
ReviewDTO replyComment = reviewWrapperToDO(reviewWrapper);
replyComment.setUsername(username);
replyComment.setImmediateParentId(parentReview.getId());
if (parentReview.getRootParentId() == -1) {
replyComment.setRootParentId(parentReview.getId());
} else {
replyComment.setRootParentId(parentReview.getRootParentId());
}
if (this.reviewDAO.addReview(replyComment, applicationReleaseDTO.getId(), tenantId)) {
ConnectionManagerUtil.commitDBTransaction();
return true;
}
return false;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ReviewManagementException( throw new ReviewManagementException(
"DB Connection error occurs ,Review for application release with UUID: " + uuid + " is failed", e); "DB Connection error occurs ,ReviewTmp for application release with UUID: " + uuid + " is failed",
} catch (UserStoreException e) {
throw new ReviewManagementException("Error occured while verifying user's permission to update the review.",
e); e);
} catch (TransactionManagementException e) {
String msg = "DB transaction error occurred when adding reply comment for comment which has comment id: "
+ parentReviewId;
log.error(msg);
throw new ReviewManagementException(msg, e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
throw new ReviewManagementException( throw new ReviewManagementException(
"Error occured while verifying whether application release is exists or not.", e); "Error occured while verifying whether application release is exists or not.", e);
@ -100,106 +199,182 @@ public class ReviewManagerImpl implements ReviewManager {
} }
} }
private ReviewDTO reviewWrapperToDO(ReviewWrapper reviewWrapper){
ReviewDTO reviewDTO = new ReviewDTO();
reviewDTO.setContent(reviewWrapper.getContent());
reviewDTO.setRating(reviewWrapper.getRating());
return reviewDTO;
}
private List<Review> reviewDTOToReview(List<ReviewDTO> reviewDTOs){
List<Review> reviews = new ArrayList<>();
for (ReviewDTO reviewDTO : reviewDTOs){
Review review = new Review();
review.setId(reviewDTO.getId());
review.setContent(reviewDTO.getContent());
review.setRootParentId(reviewDTO.getRootParentId());
review.setImmediateParentId(reviewDTO.getImmediateParentId());
review.setCreatedAt(reviewDTO.getCreatedAt());
review.setModifiedAt(reviewDTO.getModifiedAt());
review.setReplies(new ArrayList<>());
reviews.add(review);
}
return reviews;
}
private Review reviewDTOToReview(ReviewDTO reviewDTO){
Review review = new Review();
review.setId(reviewDTO.getId());
review.setContent(reviewDTO.getContent());
review.setRootParentId(reviewDTO.getRootParentId());
review.setImmediateParentId(reviewDTO.getImmediateParentId());
review.setCreatedAt(reviewDTO.getCreatedAt());
review.setModifiedAt(reviewDTO.getModifiedAt());
review.setReplies(new ArrayList<>());
return review;
}
@Override @Override
public boolean updateReview(Review review, int reviewId, String uuid, Review existingReview) public boolean updateReview(ReviewWrapper updatingReview, int reviewId, String uuid)
throws ReviewManagementException { throws ReviewManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
boolean isConnectionOpen = false;
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Review updating request is received for the review id " + reviewId); log.debug("ReviewTmp updating request is received for the reviewTmp id " + reviewId);
} }
try { try {
if (existingReview == null) { ConnectionManagerUtil.openDBConnection();
ConnectionManagerUtil.openDBConnection(); ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO.getReleaseByUUID(uuid, tenantId);
isConnectionOpen = true; if (applicationReleaseDTO == null) {
existingReview = this.reviewDAO.getReview(reviewId); String msg = "Couldn't found an application release for UUID: " + uuid;
if (existingReview != null && isAuthorizedUser(username, existingReview.getUsername(), tenantId)) { log.error(msg);
if (review.getRating() > 0 && review.getRating() != existingReview.getRating()) { throw new NotFoundException(msg);
Review finalExistingReview = existingReview;
Runnable task = () -> calculateRating(review.getRating(), finalExistingReview.getRating(),
uuid, tenantId);
new Thread(task).start();
}
} else {
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()) { ReviewDTO reviewDTO = this.reviewDAO.getReview(applicationReleaseDTO.getId(), reviewId);
review.setComment(existingReview.getComment()); if (reviewDTO == null) {
String msg =
"Couldn't found a review for application release which has UUID: " + uuid + " and review ID: "
+ reviewId;
log.error(msg);
throw new NotFoundException(msg);
} }
if (review.getRating() == 0) {
review.setRating(existingReview.getRating()); if (!username.equals(reviewDTO.getUsername())) {
String msg = "You are trying to update a review which is triggered by " + reviewDTO.getUsername()
+ ". Hence you are not permitted to update the review.";
log.error(msg);
throw new ForbiddenException(msg);
} }
return this.reviewDAO.updateReview(review, reviewId, username, tenantId) == 1;
if (reviewDTO.getRootParentId() == -1 && reviewDTO.getImmediateParentId() == -1
&& updatingReview.getRating() > 0 && updatingReview.getRating() != reviewDTO.getRating()) {
Runnable task = () -> calculateRating(updatingReview.getRating(), reviewDTO.getRating(), uuid,
tenantId);
new Thread(task).start();
reviewDTO.setRating(updatingReview.getRating());
}
reviewDTO.setContent(updatingReview.getContent());
return this.reviewDAO.updateReview(reviewDTO, reviewId, tenantId) == 1;
} catch (ReviewManagementDAOException e) { } catch (ReviewManagementDAOException e) {
throw new ReviewManagementException("Error occured while getting review with review id " + reviewId + ".", String msg = "Error occured while getting reviewTmp with reviewTmp id " + reviewId + ".";
e); log.error(msg);
throw new ReviewManagementException(msg, e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ReviewManagementException( String msg = "DB Connection error occurs updating reviewTmp with reviewTmp id " + reviewId + ".";
"DB Connection error occurs updating review with review id " + reviewId + ".", e); log.error(msg);
} catch (UserStoreException e) { throw new ReviewManagementException(msg, e);
throw new ReviewManagementException( } catch (ApplicationManagementDAOException e) {
"Error occured while verifying user's permission to update the review. review id: " + reviewId String msg = "Error occured when getting application release data for application release UUID: " + uuid;
+ ".", e); log.error(msg);
throw new ApplicationManagementException(msg, e);
} finally { } finally {
if (isConnectionOpen) { ConnectionManagerUtil.closeDBConnection();
ConnectionManagerUtil.closeDBConnection();
}
} }
} }
@Override @Override
public PaginationResult getAllReviews(PaginationRequest request, String uuid) public PaginationResult getAllReviews(PaginationRequest request, String uuid)
throws ReviewManagementException { throws ReviewManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
PaginationResult paginationResult = new PaginationResult(); PaginationResult paginationResult = new PaginationResult();
int numOfComments; TreeMap<Integer, ReviewNode<ReviewDTO>> reviewTree = new TreeMap<>();
List<Review> reviews;
TreeMap<Integer, Review> hierarchicalReviewSet = new TreeMap<>();
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Get all reviews of the application release uuid: " + uuid); log.debug("Get all reviewTmps of the application release uuid: " + uuid);
} }
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
reviews = this.reviewDAO.getAllReviews(uuid, request, tenantId); ApplicationReleaseDTO releaseDTO = this.applicationReleaseDAO.getReleaseByUUID(uuid, tenantId);
if (releaseDTO == null){
for (Review review : reviews) { String msg = "Couldn't found an application release for UUID: " + uuid;
if (hierarchicalReviewSet.containsKey(review.getParentId())) { log.error(msg);
Review parentReview = hierarchicalReviewSet.get(review.getParentId()); throw new NotFoundException(msg);
parentReview.setReplyReview(review); }
hierarchicalReviewSet.replace(review.getParentId(), parentReview); List<ReviewDTO> reviewDTOs= this.reviewDAO.getAllReviews(releaseDTO.getId(), request, tenantId);
} else { for (ReviewDTO reviewDTO : reviewDTOs){
hierarchicalReviewSet.put(review.getId(), review); ReviewNode<ReviewDTO> rootNode = new ReviewNode<>(reviewDTO);
reviewTree.put(reviewDTO.getId(), rootNode);
List<ReviewDTO> replyComments = this.reviewDAO.getReplyComments(reviewDTO.getId(), tenantId);
replyComments.sort(Comparator.comparing(ReviewDTO::getId));
for (ReviewDTO reply : replyComments){
reviewTree.put(reply.getRootParentId(),
findAndSetChild(reviewTree.get(reply.getRootParentId()), reply));
} }
} }
numOfComments = hierarchicalReviewSet.size(); int numOfReviews = reviewTree.size();
if (numOfComments > 0) { List<Review> results = new ArrayList<>();
paginationResult.setData(new ArrayList<>(hierarchicalReviewSet.values()));
paginationResult.setRecordsFiltered(numOfComments); for (ReviewNode<ReviewDTO> reviewNode : reviewTree.values()){
paginationResult.setRecordsTotal(numOfComments); results.add(constructReviewResponse(null, reviewNode));
} else {
paginationResult.setData(new ArrayList<Review>());
paginationResult.setRecordsFiltered(0);
paginationResult.setRecordsTotal(0);
} }
paginationResult.setData(new ArrayList<>(results));
paginationResult.setRecordsFiltered(numOfReviews);
paginationResult.setRecordsTotal(numOfReviews);
return paginationResult; return paginationResult;
} catch (ReviewManagementDAOException e) { } catch (ReviewManagementDAOException e) {
throw new ReviewManagementException("Error occured while getting all reviews for application uuid: " + uuid, throw new ReviewManagementException("Error occured while getting all reviewTmps for application uuid: " + uuid,
e); e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ReviewManagementException("Error occured while getting the DB connection.", e); throw new ReviewManagementException("Error occured while getting the DB connection.", e);
} catch (ApplicationManagementDAOException e) {
String msg = "Error occurred while getting application release details for application release UUId " + uuid;
log.error(msg);
throw new ApplicationManagementException(msg, e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
} }
private ReviewNode<ReviewDTO> findAndSetChild(ReviewNode<ReviewDTO> node, ReviewDTO reviewDTO) {
if (node.getData().getId() == reviewDTO.getImmediateParentId()){
ReviewNode<ReviewDTO> childNode = new ReviewNode<>(reviewDTO);
node.addChild(childNode);
return node;
}
for (ReviewNode<ReviewDTO> each : node.getChildren()) {
findAndSetChild(each, reviewDTO);
}
return node;
}
private Review constructReviewResponse(Review parentReview, ReviewNode<ReviewDTO> node) {
Review review = reviewDTOToReview(node.getData());
if (parentReview != null){
parentReview.getReplies().add(review);
}
if (node.getChildren().isEmpty()){
return review;
}
for (ReviewNode<ReviewDTO> reviewDTOReviewNode : node.getChildren()) {
constructReviewResponse(review, reviewDTOReviewNode);
}
return review;
}
@Override @Override
public boolean deleteReview(String uuid, int reviewId) public boolean deleteReview(String uuid, int reviewId)
throws ReviewManagementException, ReviewDoesNotExistException { throws ReviewManagementException, ReviewDoesNotExistException {
Review existingReview; ReviewDTO existingReview;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
try { try {

@ -120,7 +120,7 @@ public class APIUtil {
} }
/** /**
* To get the Review Manager from the osgi context. * To get the ReviewTmp Manager from the osgi context.
* @return ReviewManager instance in the current osgi context. * @return ReviewManager instance in the current osgi context.
*/ */
public static ReviewManager getReviewManager() { public static ReviewManager getReviewManager() {
@ -131,7 +131,7 @@ public class APIUtil {
reviewManager = reviewManager =
(ReviewManager) ctx.getOSGiService(ReviewManager.class, null); (ReviewManager) ctx.getOSGiService(ReviewManager.class, null);
if (reviewManager == null) { if (reviewManager == null) {
String msg = "Review Manager service has not initialized."; String msg = "ReviewTmp Manager service has not initialized.";
log.error(msg); log.error(msg);
throw new IllegalStateException(msg); throw new IllegalStateException(msg);
} }

@ -32,7 +32,7 @@ import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManag
import java.lang.reflect.Constructor; import java.lang.reflect.Constructor;
/** /**
* This Util class is responsible for making sure single instance of each Extension Manager is used throughout for * This DAOUtil class is responsible for making sure single instance of each Extension Manager is used throughout for
* all the tasks. * all the tasks.
*/ */
public class ApplicationManagementUtil { public class ApplicationManagementUtil {

@ -63,4 +63,6 @@ public class Constants {
* Directory name of the release artifacts that are saved in the file system. * Directory name of the release artifacts that are saved in the file system.
*/ */
public static final String RELEASE_ARTIFACT = "artifact"; public static final String RELEASE_ARTIFACT = "artifact";
public static final int REVIEW_PARENT_ID = -1;
} }

@ -16,7 +16,7 @@
* under the License. * under the License.
* *
*/ */
package org.wso2.carbon.device.application.mgt.core.dao.common; package org.wso2.carbon.device.application.mgt.core.util;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -27,6 +27,7 @@ import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO; import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO;
import org.wso2.carbon.device.application.mgt.common.dto.ReviewDTO;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException;
import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; 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.ApplicationStorageManager;
@ -34,8 +35,6 @@ import org.wso2.carbon.device.application.mgt.common.services.SubscriptionManage
import org.wso2.carbon.device.application.mgt.core.config.Configuration; import org.wso2.carbon.device.application.mgt.core.config.Configuration;
import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager; import org.wso2.carbon.device.application.mgt.core.config.ConfigurationManager;
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException; import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
import org.wso2.carbon.device.application.mgt.core.impl.ApplicationStorageManagerImpl;
import org.wso2.carbon.device.application.mgt.core.util.ApplicationManagementUtil;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl;
@ -48,9 +47,9 @@ import java.util.List;
/** /**
* This class is responsible for handling the utils of the Application Management DAO. * This class is responsible for handling the utils of the Application Management DAO.
*/ */
public class Util { public class DAOUtil {
private static final Log log = LogFactory.getLog(Util.class); private static final Log log = LogFactory.getLog(DAOUtil.class);
/** /**
* To create application object from the result set retrieved from the Database. * To create application object from the result set retrieved from the Database.
@ -146,6 +145,7 @@ public class Util {
appRelease.setAppHashValue(rs.getString("RELEASE_HASH_VALUE")); appRelease.setAppHashValue(rs.getString("RELEASE_HASH_VALUE"));
appRelease.setPrice(rs.getDouble("RELEASE_PRICE")); appRelease.setPrice(rs.getDouble("RELEASE_PRICE"));
appRelease.setMetaData(rs.getString("RELEASE_META_INFO")); appRelease.setMetaData(rs.getString("RELEASE_META_INFO"));
appRelease.setPackageName(rs.getString("PACKAGE_NAME"));
appRelease.setSupportedOsVersions(rs.getString("RELEASE_SUP_OS_VERSIONS")); appRelease.setSupportedOsVersions(rs.getString("RELEASE_SUP_OS_VERSIONS"));
appRelease.setRating(rs.getDouble("RELEASE_RATING")); appRelease.setRating(rs.getDouble("RELEASE_RATING"));
appRelease.setCurrentState(rs.getString("RELEASE_CURRENT_STATE")); appRelease.setCurrentState(rs.getString("RELEASE_CURRENT_STATE"));
@ -204,6 +204,36 @@ public class Util {
return applicationRelease; return applicationRelease;
} }
public static ReviewDTO loadReview(ResultSet rs) throws SQLException, UnexpectedServerErrorException {
List<ReviewDTO> reviewDTOs = loadReviews(rs);
if (reviewDTOs.isEmpty()) {
return null;
}
if (reviewDTOs.size() > 1) {
String msg = "Internal server error. Found more than one review for requested review ID";
log.error(msg);
throw new UnexpectedServerErrorException(msg);
}
return reviewDTOs.get(0);
}
public static List<ReviewDTO> loadReviews (ResultSet rs) throws SQLException {
List<ReviewDTO> reviewDTOs = new ArrayList<>();
while (rs.next()) {
ReviewDTO reviewDTO = new ReviewDTO();
reviewDTO.setId(rs.getInt("ID"));
reviewDTO.setContent(rs.getString("COMMENT"));
reviewDTO.setCreatedAt(rs.getTimestamp("CREATED_AT"));
reviewDTO.setModifiedAt(rs.getTimestamp("MODIFIED_AT"));
reviewDTO.setRootParentId(rs.getInt("ROOT_PARENT_ID"));
reviewDTO.setImmediateParentId(rs.getInt("IMMEDIATE_PARENT_ID"));
reviewDTO.setUsername(rs.getString("USERNAME"));
reviewDTO.setRating(rs.getInt("RATING"));
reviewDTOs.add(reviewDTO);
}
return reviewDTOs;
}
/** /**
* Cleans up the statement and resultset after executing the query * Cleans up the statement and resultset after executing the query
* *
@ -248,7 +278,7 @@ public class Util {
public static ApplicationManager getApplicationManager() { public static ApplicationManager getApplicationManager() {
if (applicationManager == null) { if (applicationManager == null) {
synchronized (Util.class) { synchronized (DAOUtil.class) {
if (applicationManager == null) { if (applicationManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
applicationManager = applicationManager =
@ -272,7 +302,7 @@ public class Util {
try { try {
if (applicationStorageManager == null) { if (applicationStorageManager == null) {
synchronized (Util.class) { synchronized (DAOUtil.class) {
if (applicationStorageManager == null) { if (applicationStorageManager == null) {
applicationStorageManager = ApplicationManagementUtil applicationStorageManager = ApplicationManagementUtil
.getApplicationStorageManagerInstance(); .getApplicationStorageManagerInstance();
@ -299,7 +329,7 @@ public class Util {
*/ */
public static SubscriptionManager getSubscriptionManager() { public static SubscriptionManager getSubscriptionManager() {
if (subscriptionManager == null) { if (subscriptionManager == null) {
synchronized (Util.class) { synchronized (DAOUtil.class) {
if (subscriptionManager == null) { if (subscriptionManager == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
subscriptionManager = subscriptionManager =

@ -453,7 +453,9 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Valid LifecycleChanger lifecycleChanger) { @Valid LifecycleChanger lifecycleChanger) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
applicationManager.changeLifecycleState(applicationUuid, lifecycleChanger); ApplicationRelease applicationRelease = applicationManager
.changeLifecycleState(applicationUuid, lifecycleChanger);
return Response.status(Response.Status.CREATED).entity(applicationRelease).build();
} catch (BadRequestException e) { } catch (BadRequestException e) {
String msg = "Request payload contains invalid data, hence veryfy the request payload."; String msg = "Request payload contains invalid data, hence veryfy the request payload.";
log.error(msg, e); log.error(msg, e);
@ -472,7 +474,6 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} }
return Response.status(Response.Status.CREATED).entity("Lifecycle state added successfully.").build();
} }
@GET @GET

@ -157,16 +157,6 @@
<groupId>org.wso2.carbon.devicemgt</groupId> <groupId>org.wso2.carbon.devicemgt</groupId>
<artifactId>org.wso2.carbon.device.application.mgt.core</artifactId> <artifactId>org.wso2.carbon.device.application.mgt.core</artifactId>
<scope>provided</scope> <scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</exclusion>
<exclusion>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
</exclusion>
</exclusions>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.wso2.carbon.devicemgt</groupId> <groupId>org.wso2.carbon.devicemgt</groupId>

@ -32,7 +32,9 @@ import org.wso2.carbon.apimgt.annotations.api.Scope;
import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.apimgt.annotations.api.Scopes;
import org.wso2.carbon.device.application.mgt.common.PaginationResult; import org.wso2.carbon.device.application.mgt.common.PaginationResult;
import org.wso2.carbon.device.application.mgt.common.ErrorResponse; import org.wso2.carbon.device.application.mgt.common.ErrorResponse;
import org.wso2.carbon.device.application.mgt.common.Review; import org.wso2.carbon.device.application.mgt.common.ReviewTmp;
import org.wso2.carbon.device.application.mgt.common.wrapper.ReviewWrapper;
import javax.validation.Valid; import javax.validation.Valid;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
@ -63,29 +65,28 @@ import java.util.List;
} }
), ),
tags = { tags = {
@Tag(name = "review_management", description = "Review Management related APIs") @Tag(name = "review_management", description = "ReviewTmp Management related APIs")
} }
) )
@Scopes( @Scopes(
scopes = { scopes = {
@Scope( @Scope(
name = "Get Review Details", name = "Get Review Details",
description = "Get review details", description = "Get review details from application store.",
key = "perm:app:review:view", key = "perm:app:review:view",
permissions = {"/app-mgt/store/review/view"} permissions = {"/app-mgt/store/review/view"}
), ),
@Scope( @Scope(
name = "Update a Review", name = "Update a Review",
description = "Update a comment", description = "Update a Review from the application store.",
key = "perm:app:review:update", key = "perm:app:review:update",
permissions = {"/app-mgt/store/review/update"} permissions = {"/app-mgt/store/review/update"}
), ),
} }
) )
@Path("/review") @Path("/reviews")
@Api(value = "Review Management", description = "This API carries all review management related operations such as get " @Api(value = "ReviewTmp Management")
+ "all the reviews, add review, etc.")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
public interface ReviewManagementAPI { public interface ReviewManagementAPI {
String SCOPE = "scope"; String SCOPE = "scope";
@ -113,6 +114,9 @@ public interface ReviewManagementAPI {
message = "OK. \n Successfully retrieved reviews.", message = "OK. \n Successfully retrieved reviews.",
response = PaginationResult.class, response = PaginationResult.class,
responseContainer = "PaginationResult"), responseContainer = "PaginationResult"),
@ApiResponse(
code = 404,
message = "Not Found. \n Not found an application release for requested UUID."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Error occurred while getting the review list.", message = "Internal Server Error. \n Error occurred while getting the review list.",
@ -145,7 +149,7 @@ public interface ReviewManagementAPI {
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "POST", httpMethod = "POST",
value = "Add a review", value = "Add a review",
notes = "This will add a new review", notes = "This will add a new review for application release.",
tags = "Store Management", tags = "Store Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ -158,29 +162,89 @@ public interface ReviewManagementAPI {
value = { value = {
@ApiResponse( @ApiResponse(
code = 201, code = 201,
message = "OK. \n Successfully add a review.", message = "OK. \n Successfully add a reviewTmp.",
response = Review.class), response = ReviewTmp.class),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = message =
"Bad Request. \n"), "Bad Request. \n Found invalid payload with the request."),
@ApiResponse(
code = 403,
message = "Don't have permission to add a review."),
@ApiResponse(
code = 404,
message = "Not Found. \n Not found an application release for requested UUID."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Error occurred adding a review.", message = "Internal Server Error. \n Error occurred adding a reviewTmp.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response addReview( Response addReview(
@ApiParam( @ApiParam(
name = "review", name = "reviewTmp",
value = "Review details", value = "ReviewTmp details",
required = true) Review review, required = true) ReviewWrapper reviewWrapper,
@ApiParam( @ApiParam(
name="uuid", name="uuid",
value="uuid of the release version of the application", value="uuid of the application release.",
required=true) required=true)
@PathParam("uuid") String uuid); @PathParam("uuid") String uuid);
@POST
@Path("/{uuid}/{parentReviewId}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "POST",
value = "Add a reply comment",
notes = "This will add a reply comment for a comment or review.",
tags = "Store Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm:app:reviewTmp:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 201,
message = "OK. \n Successfully add a reviewTmp.",
response = ReviewTmp.class),
@ApiResponse(
code = 400,
message =
"Bad Request. \n Found invalid payload with the request."),
@ApiResponse(
code = 404,
message = "Not Found. \n Not found an application release for requested UUID."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Error occurred adding a reviewTmp.",
response = ErrorResponse.class)
})
Response addReplyComment(
@ApiParam(
name = "review",
value = "Reply comment details",
required = true) ReviewWrapper reviewWrapper,
@ApiParam(
name="uuid",
value="uuid of the application release.",
required=true)
@PathParam("uuid") String uuid,
@ApiParam(
name="parentReviewId",
value="uuid of the application release.",
required=true)
@PathParam("parentReviewId") int parentReviewId);
@PUT @PUT
@Path("/{uuid}/{reviewId}") @Path("/{uuid}/{reviewId}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -189,8 +253,8 @@ public interface ReviewManagementAPI {
consumes = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON, produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT", httpMethod = "PUT",
value = "Edit a review", value = "Edit a reviewTmp",
notes = "This will edit the review", notes = "This will edit the reviewTmp",
tags = "Store Management", tags = "Store Management",
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ -202,22 +266,22 @@ public interface ReviewManagementAPI {
value = { value = {
@ApiResponse( @ApiResponse(
code = 200, code = 200,
message = "OK. \n Successfully updated review.", message = "OK. \n Successfully updated reviewTmp.",
response = Review.class), response = ReviewTmp.class),
@ApiResponse( @ApiResponse(
code = 400, code = 400,
message = "Bad Request. \n Invalid request or validation error."), message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse( @ApiResponse(
code = 500, code = 500,
message = "Internal Server Error. \n Error occurred while updating the new review.", message = "Internal Server Error. \n Error occurred while updating the new reviewTmp.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response updateReview( Response updateReview(
@ApiParam( @ApiParam(
name = "review", name = "reviewTmp",
value = "The review that need to be updated.", value = "The reviewTmp that need to be updated.",
required = true) required = true)
@Valid Review review, @Valid ReviewWrapper updatingReview,
@ApiParam( @ApiParam(
name="uuid", name="uuid",
value = "uuid of the application release", value = "uuid of the application release",
@ -225,7 +289,7 @@ public interface ReviewManagementAPI {
@PathParam("uuid") String uuid, @PathParam("uuid") String uuid,
@ApiParam( @ApiParam(
name="reviewId", name="reviewId",
value = "review id of the updating review.", value = "reviewTmp id of the updating reviewTmp.",
required = true) required = true)
@PathParam("reviewId") int reviewId); @PathParam("reviewId") int reviewId);

@ -23,10 +23,11 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.PaginationResult; import org.wso2.carbon.device.application.mgt.common.PaginationResult;
import org.wso2.carbon.device.application.mgt.common.Rating; import org.wso2.carbon.device.application.mgt.common.Rating;
import org.wso2.carbon.device.application.mgt.common.Review;
import org.wso2.carbon.device.application.mgt.common.exception.RequestValidatingException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewDoesNotExistException; import org.wso2.carbon.device.application.mgt.common.exception.ReviewDoesNotExistException;
import org.wso2.carbon.device.application.mgt.common.services.ReviewManager; import org.wso2.carbon.device.application.mgt.common.services.ReviewManager;
import org.wso2.carbon.device.application.mgt.common.wrapper.ReviewWrapper;
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.store.api.services.ReviewManagementAPI; import org.wso2.carbon.device.application.mgt.store.api.services.ReviewManagementAPI;
import org.wso2.carbon.device.application.mgt.common.PaginationRequest; import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
@ -46,9 +47,9 @@ import javax.ws.rs.DELETE;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
/** /**
* Review Management related jax-rs APIs. * ReviewTmp Management related jax-rs APIs.
*/ */
@Path("/review") @Path("/reviews")
public class ReviewManagementAPIImpl implements ReviewManagementAPI { public class ReviewManagementAPIImpl implements ReviewManagementAPI {
private static Log log = LogFactory.getLog(ReviewManagementAPIImpl.class); private static Log log = LogFactory.getLog(ReviewManagementAPIImpl.class);
@ -65,10 +66,18 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
try { try {
PaginationResult paginationResult = reviewManager.getAllReviews(request, uuid); PaginationResult paginationResult = reviewManager.getAllReviews(request, uuid);
return Response.status(Response.Status.OK).entity(paginationResult).build(); return Response.status(Response.Status.OK).entity(paginationResult).build();
} catch (NotFoundException e) {
String msg = "Couldn't find an application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ReviewManagementException e) { } catch (ReviewManagementException e) {
String msg = "Error occurred while retrieving reviews for application UUID: " + uuid; String msg = "Error occurred while retrieving reviews for application UUID: " + uuid;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred while retrieving application release details for application UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
} }
@ -77,31 +86,73 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
@Consumes("application/json") @Consumes("application/json")
@Path("/{uuid}") @Path("/{uuid}")
public Response addReview( public Response addReview(
@ApiParam Review review, @ApiParam ReviewWrapper reviewWrapper,
@PathParam("uuid") String uuid) { @PathParam("uuid") String uuid) {
ReviewManager reviewManager = APIUtil.getReviewManager(); ReviewManager reviewManager = APIUtil.getReviewManager();
try { try {
boolean isReviewCreated = reviewManager.addReview(review, uuid); boolean isReviewCreated = reviewManager.addReview(reviewWrapper, uuid);
if (isReviewCreated) { if (isReviewCreated) {
return Response.status(Response.Status.CREATED).entity(review).build(); return Response.status(Response.Status.CREATED).entity(reviewWrapper).build();
} else { } else {
String msg = "Given review is not valid. Please check the review payload."; String msg = "Review adding is failed. Please contact the administrator.";
log.error(msg); log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Couldn't find an application release for UUID: " + uuid; String msg = "Couldn't find an application release for UUID: " + uuid;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Found invalid payload data with the request. Hence, please verify the request payload.";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "You have already reviewed the application. Hence you are not permitted to review the "
+ "application again.";
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ReviewManagementException e) { } catch (ReviewManagementException e) {
String msg = "Error occurred while creating the review"; String msg = "Error occurred while creating the reviewTmp";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (RequestValidatingException e) { } catch (ApplicationManagementException e) {
String msg = String msg = "Error occured while accessing application release for UUID: " + uuid;
"Error occurred while adding for application release. UUID of the application release: " + uuid;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@POST
@Consumes("application/json")
@Path("/{uuid}/{parentReviewId}")
public Response addReplyComment(
@ApiParam ReviewWrapper reviewWrapper,
@PathParam("uuid") String uuid,
@PathParam("parentReviewId") int parentReviewId) {
ReviewManager reviewManager = APIUtil.getReviewManager();
try {
boolean isRepliedForReview = reviewManager.addReplyComment(reviewWrapper, uuid, parentReviewId);
if (isRepliedForReview) {
return Response.status(Response.Status.CREATED).entity(reviewWrapper).build();
} else {
String msg = "Error occured when adding reply comment for the review. Please contact the administrator..";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
} catch (NotFoundException e) {
String msg = "Couldn't find an application release for UUID: " + uuid;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (BadRequestException e) {
String msg = "Found invalid payload data with the request to add reply comment. Hence, please verify the "
+ "request payload.";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}catch (ReviewManagementException e) {
String msg = "Error occurred while creating the reviewTmp";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ApplicationManagementException e) { } catch (ApplicationManagementException e) {
String msg = "Error occured while accessing application release for UUID: " + uuid; String msg = "Error occured while accessing application release for UUID: " + uuid;
log.error(msg, e); log.error(msg, e);
@ -114,13 +165,13 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
@Consumes("application/json") @Consumes("application/json")
@Path("/{uuid}/{reviewId}") @Path("/{uuid}/{reviewId}")
public Response updateReview( public Response updateReview(
@ApiParam Review review, @ApiParam ReviewWrapper updatingReview,
@PathParam("uuid") String uuid, @PathParam("uuid") String uuid,
@PathParam("reviewId") int reviewId) { @PathParam("reviewId") int reviewId) {
ReviewManager reviewManager = APIUtil.getReviewManager(); ReviewManager reviewManager = APIUtil.getReviewManager();
try { try {
if (reviewManager.updateReview(review, reviewId, uuid, null)) { if (reviewManager.updateReview(updatingReview, reviewId, uuid)) {
return Response.status(Response.Status.OK).entity(review).build(); return Response.status(Response.Status.OK).entity(updatingReview).build();
} else { } else {
String msg = "Review updating failed. Please contact the administrator"; String msg = "Review updating failed. Please contact the administrator";
log.error(msg); log.error(msg);
@ -130,11 +181,18 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
String msg = "Error occurred while retrieving comments."; String msg = "Error occurred while retrieving comments.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (RequestValidatingException e) { } catch (NotFoundException e) {
String msg = "Error occurred while updating review. Review id: " + reviewId; String msg = "Couldn't found application release data for UUID " + uuid + " or Review for review ID: " + reviewId;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} } catch (ForbiddenException e) {
String msg = "You dont have permission to update application release review.";
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error occurred when getting application release data for application release UUID:." + uuid;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); }
} }
@Override @Override
@ -147,9 +205,9 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
ReviewManager reviewManager = APIUtil.getReviewManager(); ReviewManager reviewManager = APIUtil.getReviewManager();
try { try {
if (reviewManager.deleteReview(uuid, reviewId)) { if (reviewManager.deleteReview(uuid, reviewId)) {
return Response.status(Response.Status.OK).entity("Review is deleted successfully.").build(); return Response.status(Response.Status.OK).entity("ReviewTmp is deleted successfully.").build();
} else { } else {
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Review deleting is failed.") return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("ReviewTmp deleting is failed.")
.build(); .build();
} }
} catch (ReviewManagementException e) { } catch (ReviewManagementException e) {
@ -173,7 +231,7 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
try { try {
rating = reviewManager.getRating(uuid); rating = reviewManager.getRating(uuid);
} catch (ReviewManagementException e) { } catch (ReviewManagementException e) {
log.error("Review Management Exception occurs", e); log.error("ReviewTmp Management Exception occurs", e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} }
return Response.status(Response.Status.OK).entity(rating).build(); return Response.status(Response.Status.OK).entity(rating).build();

@ -17,34 +17,34 @@
*/ */
package org.wso2.carbon.device.application.mgt.store.api.services.util; package org.wso2.carbon.device.application.mgt.store.api.services.util;
import org.wso2.carbon.device.application.mgt.common.Review; import org.wso2.carbon.device.application.mgt.common.ReviewTmp;
/** /**
* Helper class for Review Management API test cases. * Helper class for ReviewTmp Management API test cases.
*/ */
public class CommentMgtTestHelper { public class CommentMgtTestHelper {
private static final String COMMENT_TEXT = "Dummy Review"; private static final String COMMENT_TEXT = "Dummy ReviewTmp";
private static final String CREATED_BY = "TEST_CREATED_BY"; private static final String CREATED_BY = "TEST_CREATED_BY";
private static final String MODIFIED_BY = "TEST_MODIFIED_BY"; private static final String MODIFIED_BY = "TEST_MODIFIED_BY";
private static final int PARENT_ID = 123; private static final int PARENT_ID = 123;
private static final int COMMENT_ID = 1; private static final int COMMENT_ID = 1;
/** /**
* Creates a Review with given text and given uuid. * Creates a ReviewTmp with given text and given uuid.
* If the text is null, the COMMENT_TEXT will be used as the Dummy Review. * If the text is null, the COMMENT_TEXT will be used as the Dummy ReviewTmp.
* *
* @param commentText : Text of the Review * @param commentText : Text of the ReviewTmp
* @return Review * @return ReviewTmp
*/ */
public static Review getDummyComment(String commentText, String uuid) { public static ReviewTmp getDummyComment(String commentText, String uuid) {
Review review = new Review(); ReviewTmp reviewTmp = new ReviewTmp();
review.setId(COMMENT_ID); reviewTmp.setId(COMMENT_ID);
review.setUsername(CREATED_BY); reviewTmp.setUsername(CREATED_BY);
review.setComment(commentText != null ? commentText : COMMENT_TEXT); reviewTmp.setComment(commentText != null ? commentText : COMMENT_TEXT);
return review; return reviewTmp;
} }
} }

@ -55,7 +55,8 @@ CREATE TABLE IF NOT EXISTS AP_APP_REVIEW(
ID INTEGER NOT NULL AUTO_INCREMENT, ID INTEGER NOT NULL AUTO_INCREMENT,
TENANT_ID INTEGER NOT NULL, TENANT_ID INTEGER NOT NULL,
COMMENT VARCHAR(250) NOT NULL, COMMENT VARCHAR(250) NOT NULL,
REPLY_COMMENT VARCHAR(250) NULL, ROOT_PARENT_ID INTEGER NOT NULL,
IMMEDIATE_PARENT_ID INTEGER NOT NULL,
CREATED_AT TIMESTAMP NOT NULL, CREATED_AT TIMESTAMP NOT NULL,
MODIFIED_AT TIMESTAMP NOT NULL, MODIFIED_AT TIMESTAMP NOT NULL,
RATING INTEGER NULL, RATING INTEGER NULL,

Loading…
Cancel
Save