Reformatted the code.

feature/appm-store/pbac
nishadi 7 years ago
parent 1bbd0b1aa5
commit 3bfb2addbb

@ -69,10 +69,9 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
} }
} catch (NotFoundException e) { } catch (NotFoundException e) {
log.error("Not found exception occurs to uuid " + uuid + " .", e); log.error("Not found exception occurs to uuid " + uuid + " .", e);
return Response.status(Response.Status.NOT_FOUND) return Response.status(Response.Status.NOT_FOUND).entity("Application with UUID " + uuid + " not found")
.entity("Application with UUID " + uuid + " not found").build(); .build();
} } catch (CommentManagementException e) {
catch (CommentManagementException e) {
String msg = "Error occurred while retrieving comments."; String msg = "Error occurred while retrieving comments.";
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
@ -115,7 +114,6 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
@PathParam("CommentId") int CommentId) { @PathParam("CommentId") int CommentId) {
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
try { try {
if (CommentId == 0) { if (CommentId == 0) {
return Response.status(Response.Status.NOT_FOUND) return Response.status(Response.Status.NOT_FOUND)
@ -151,8 +149,7 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
log.error("Not found exception occurs to comment id " + CommentId + " .", e); log.error("Not found exception occurs to comment id " + CommentId + " .", e);
return Response.status(Response.Status.NOT_FOUND) return Response.status(Response.Status.NOT_FOUND).entity("Comment with" + CommentId + " not found").build();
.entity("Comment with" + CommentId + " not found").build();
} }
return Response.status(Response.Status.OK).entity("Comment is deleted successfully.").build(); return Response.status(Response.Status.OK).entity("Comment is deleted successfully.").build();
} }
@ -166,7 +163,6 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
int Stars = 0; int Stars = 0;
try { try {
Stars = commentsManager.getStars(uuid); Stars = commentsManager.getStars(uuid);
} catch (CommentManagementException e) { } catch (CommentManagementException e) {
@ -188,7 +184,6 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
int ratedUsers = 0; int ratedUsers = 0;
try { try {
ratedUsers = commentsManager.getRatedUser(uuid); ratedUsers = commentsManager.getRatedUser(uuid);
} catch (CommentManagementException e) { } catch (CommentManagementException e) {
@ -210,7 +205,6 @@ public class CommentManagementAPIImpl implements CommentManagementAPI{
CommentsManager commentsManager = APIUtil.getCommentsManager(); CommentsManager commentsManager = APIUtil.getCommentsManager();
int newStars = 0; int newStars = 0;
try { try {
newStars = commentsManager.updateStars(stars, uuid); newStars = commentsManager.updateStars(stars, uuid);

@ -51,7 +51,6 @@ public class Comment {
this.tenantId = tenantId; this.tenantId = tenantId;
} }
public int getId() { public int getId() {
return id; return id;
} }

@ -18,9 +18,6 @@
package org.wso2.carbon.device.application.mgt.common; package org.wso2.carbon.device.application.mgt.common;
import org.apache.commons.fileupload.MultipartStream;
/** /**
* This class holds required parameters for a querying a paginated device response. * This class holds required parameters for a querying a paginated device response.
*/ */
@ -60,9 +57,7 @@ public class PaginationRequest {
} }
} }
@Override public String toString() {
@Override
public String toString() {
return "Off Set'" + this.offSet + "' row count '" + this.limit; return "Off Set'" + this.offSet + "' row count '" + this.limit;
} }
} }

@ -1,7 +1,23 @@
/*
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.application.mgt.common.exception; package org.wso2.carbon.device.application.mgt.common.exception;
import org.wso2.carbon.device.application.mgt.common.Comment;
public class CommentManagementException extends Exception { public class CommentManagementException extends Exception {
private String message; private String message;
@ -18,8 +34,8 @@ public class CommentManagementException extends Exception{
public CommentManagementException() { public CommentManagementException() {
} }
@Override
public String getMessage() { @Override public String getMessage() {
return message; return message;
} }

@ -23,11 +23,11 @@ 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.CommentManagementException; import org.wso2.carbon.device.application.mgt.common.exception.CommentManagementException;
import java.util.List; import java.util.List;
/** /**
* CommentsManager is responsible for handling all the add/update/delete/get operations related with * CommentsManager is responsible for handling all the add/update/delete/get operations related with
*
*/ */
public interface CommentsManager { public interface CommentsManager {
@ -49,7 +49,6 @@ public interface CommentsManager {
* @param comment comment needed to be validate. * @param comment comment needed to be validate.
* @return validated the comment. * @return validated the comment.
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
*
*/ */
Boolean validateComment(int CommentId, String comment) throws CommentManagementException; Boolean validateComment(int CommentId, String comment) throws CommentManagementException;
@ -63,7 +62,6 @@ public interface CommentsManager {
*/ */
List<Comment> getAllComments(PaginationRequest request, String uuid) throws CommentManagementException; List<Comment> getAllComments(PaginationRequest request, String uuid) throws CommentManagementException;
/** /**
* To get the comment with id. * To get the comment with id.
* *
@ -81,7 +79,6 @@ public interface CommentsManager {
*/ */
void deleteComment(int CommentId) throws CommentManagementException; void deleteComment(int CommentId) throws CommentManagementException;
/** /**
* To update a comment. * To update a comment.
* *

@ -24,8 +24,7 @@ import javax.xml.bind.annotation.XmlRootElement;
/** /**
* This class represents the information related to Pagination configuration. * This class represents the information related to Pagination configuration.
*/ */
@XmlRootElement(name = "PaginationConfiguration") @XmlRootElement(name = "PaginationConfiguration") public class PaginationConfiguration {
public class PaginationConfiguration {
private int commentListPageSize; private int commentListPageSize;
@ -33,8 +32,8 @@ public class PaginationConfiguration {
return commentListPageSize; return commentListPageSize;
} }
@XmlElement(name = "commentListPageSize", required = true) @XmlElement(name = "commentListPageSize", required = true) public void setCommentListPageSize(
public void setCommentListPageSize(int commentListPageSize) { int commentListPageSize) {
this.commentListPageSize = commentListPageSize; this.commentListPageSize = commentListPageSize;
} }

@ -32,8 +32,7 @@ import java.util.List;
* This interface specifies the database access operations performed for comments. * This interface specifies the database access operations performed for comments.
*/ */
@SuppressWarnings("ALL") @SuppressWarnings("ALL") public interface CommentDAO {
public interface CommentDAO {
/** /**
* To add a comment to a application. * To add a comment to a application.
@ -47,7 +46,8 @@ public interface CommentDAO {
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
*/ */
int addComment(int tenantId , Comment comment, String createdBy, int parentId, String uuid) throws CommentManagementException, DBConnectionException, SQLException; int addComment(int tenantId, Comment comment, String createdBy, int parentId, String uuid)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To add a comment to a application. * To add a comment to a application.
@ -60,7 +60,8 @@ public interface CommentDAO {
* @return comment id * @return comment id
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
*/ */
int addComment(int tenantId, Comment comment,String createdBy,String appType,String appName,String version) throws CommentManagementException, DBConnectionException, SQLException; int addComment(int tenantId, Comment comment, String createdBy, String appType, String appName, String version)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To update already added comment. * To update already added comment.
@ -74,7 +75,8 @@ public interface CommentDAO {
* @throws DBConnectionException db connection exception * @throws DBConnectionException db connection exception
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
Comment updateComment(int CommentId, String updatedComment,String modifiedBy, Timestamp modifiedAt) throws CommentManagementException, DBConnectionException, SQLException; Comment updateComment(int CommentId, String updatedComment, String modifiedBy, Timestamp modifiedAt)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To update already added comment. * To update already added comment.
@ -89,7 +91,8 @@ public interface CommentDAO {
* @throws DBConnectionException db connection exception * @throws DBConnectionException db connection exception
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
Comment updateComment(String uuid, int CommentId,String updatedComment,String modifiedBy, Timestamp modifiedAt) throws CommentManagementException, DBConnectionException, SQLException; Comment updateComment(String uuid, int CommentId, String updatedComment, String modifiedBy, Timestamp modifiedAt)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get the comment with id. * To get the comment with id.
@ -123,7 +126,8 @@ public interface CommentDAO {
* @throws DBConnectionException db connection exception * @throws DBConnectionException db connection exception
* @throws SQLException sql exception * @throws SQLException sql exception
**/ **/
List<Comment> getAllComments(String uuid,PaginationRequest request) throws CommentManagementException, SQLException, DBConnectionException; List<Comment> getAllComments(String uuid, PaginationRequest request)
throws CommentManagementException, SQLException, DBConnectionException;
/** /**
* To get list of comments using release id and application id. * To get list of comments using release id and application id.
@ -146,7 +150,8 @@ public interface CommentDAO {
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
List<Comment> getComments(String appType,String appName,String version) throws CommentManagementException, DBConnectionException, SQLException; List<Comment> getComments(String appType, String appName, String version)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get list of comments using tenant id. * To get list of comments using tenant id.
@ -168,7 +173,8 @@ public interface CommentDAO {
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
List<Comment> getCommentsByUser(String createdBy) throws CommentManagementException, DBConnectionException, SQLException; List<Comment> getCommentsByUser(String createdBy)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get list of comments by created use and created time. * To get list of comments by created use and created time.
@ -180,7 +186,8 @@ public interface CommentDAO {
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
List<Comment> getCommentsByUser(String createdBy,Timestamp createdAt) throws CommentManagementException, DBConnectionException, SQLException; List<Comment> getCommentsByUser(String createdBy, Timestamp createdAt)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get list of comments by modified users. * To get list of comments by modified users.
@ -191,7 +198,8 @@ public interface CommentDAO {
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
List<Comment> getCommentsByModifiedUser(String modifiedBy) throws CommentManagementException, DBConnectionException, SQLException; List<Comment> getCommentsByModifiedUser(String modifiedBy)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get list of comments using modified user's name and modified time. * To get list of comments using modified user's name and modified time.
@ -203,7 +211,8 @@ public interface CommentDAO {
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
List<Comment> getCommentsByModifiedUser(String modifiedBy,Timestamp modifiedAt) throws CommentManagementException, DBConnectionException, SQLException; List<Comment> getCommentsByModifiedUser(String modifiedBy, Timestamp modifiedAt)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get list of comments using application type, application name , application version and parent id of the comment. * To get list of comments using application type, application name , application version and parent id of the comment.
@ -217,7 +226,8 @@ public interface CommentDAO {
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
List<Comment> getComments(String appType,String appName,String version,int parentId) throws CommentManagementException, DBConnectionException, SQLException; List<Comment> getComments(String appType, String appName, String version, int parentId)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get a count of the comments by usernames. * To get a count of the comments by usernames.
@ -251,7 +261,8 @@ public interface CommentDAO {
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
int getCommentCountByParent(String uuid,int parentId) throws CommentManagementException, DBConnectionException, SQLException; int getCommentCountByParent(String uuid, int parentId)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get a count of comments by modification details. * To get a count of comments by modification details.
@ -263,7 +274,8 @@ public interface CommentDAO {
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
int getCommentCountByUser(String modifiedBy,Timestamp modifedAt) throws CommentManagementException, DBConnectionException, SQLException; int getCommentCountByUser(String modifiedBy, Timestamp modifedAt)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get count of comments by application versions. * To get count of comments by application versions.
@ -275,7 +287,8 @@ public interface CommentDAO {
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
int getCommentCountByApp(int appId, int appReleaseId) throws CommentManagementException, DBConnectionException, SQLException; int getCommentCountByApp(int appId, int appReleaseId)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To get count of comments by application details. * To get count of comments by application details.
@ -288,7 +301,8 @@ public interface CommentDAO {
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
int getCommentCountByApp(String appType,String appName,String version) throws CommentManagementException, DBConnectionException, SQLException; int getCommentCountByApp(String appType, String appName, String version)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To delete comment using comment id. * To delete comment using comment id.
@ -300,7 +314,6 @@ public interface CommentDAO {
*/ */
void deleteComment(int CommentId) throws CommentManagementException, DBConnectionException, SQLException; void deleteComment(int CommentId) throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To delete comment using comment id. * To delete comment using comment id.
* *
@ -320,7 +333,8 @@ public interface CommentDAO {
* @throws DBConnectionException db connection exception. * @throws DBConnectionException db connection exception.
* @throws SQLException sql exception * @throws SQLException sql exception
*/ */
void deleteComments(int appId,int appReleaseID) throws CommentManagementException, DBConnectionException, SQLException; void deleteComments(int appId, int appReleaseID)
throws CommentManagementException, DBConnectionException, SQLException;
/** /**
* To delete comments using application details. * To delete comments using application details.
@ -341,8 +355,8 @@ public interface CommentDAO {
* @param createdBy Username of the created person. * @param createdBy Username of the created person.
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
*/ */
void deleteComments(String appType,String appName,String version,String createdBy)throws CommentManagementException; void deleteComments(String appType, String appName, String version, String createdBy)
throws CommentManagementException;
/** /**
* To delete comments by parent id of the comment. * To delete comments by parent id of the comment.
@ -353,7 +367,6 @@ public interface CommentDAO {
*/ */
void deleteComments(String uuid, int parentId) throws CommentManagementException; void deleteComments(String uuid, int parentId) throws CommentManagementException;
/** /**
* To add the star rating to the application. * To add the star rating to the application.
* *

@ -236,7 +236,6 @@ public class ApplicationManagementDAOFactory {
} }
} }
public static CommentDAO getCommentDAO() { public static CommentDAO getCommentDAO() {
if (databaseEngine != null) { if (databaseEngine != null) {
switch (databaseEngine) { switch (databaseEngine) {
@ -250,6 +249,7 @@ public class ApplicationManagementDAOFactory {
} }
throw new IllegalStateException("Database engine has not initialized properly."); throw new IllegalStateException("Database engine has not initialized properly.");
} }
} }

@ -33,6 +33,7 @@ import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagem
import org.wso2.carbon.device.application.mgt.core.dao.common.Util; import org.wso2.carbon.device.application.mgt.core.dao.common.Util;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.Instant; import java.time.Instant;
@ -41,8 +42,7 @@ import java.util.List;
/** /**
* This class is the default implementation for the Managing the comments. * This class is the default implementation for the Managing the comments.
*/ */
@SuppressWarnings( "deprecation" ) @SuppressWarnings("deprecation") public class CommentsManagerImpl implements CommentsManager {
public class CommentsManagerImpl implements CommentsManager {
private static final Log log = LogFactory.getLog(CommentsManagerImpl.class); private static final Log log = LogFactory.getLog(CommentsManagerImpl.class);
private CommentDAO commentDAO; private CommentDAO commentDAO;
@ -86,14 +86,14 @@ public class CommentsManagerImpl implements CommentsManager {
* @param comment comment needed to be validate. * @param comment comment needed to be validate.
* @return Application related with the UUID. * @return Application related with the UUID.
* @throws CommentManagementException Exceptions of the comment management. * @throws CommentManagementException Exceptions of the comment management.
*
*/ */
public Boolean validateComment(int CommentId, String comment) throws CommentManagementException { public Boolean validateComment(int CommentId, String comment) throws CommentManagementException {
if (CommentId <= 0) { if (CommentId <= 0) {
throw new CommentManagementException("Comment ID is null or negative. Comment id is a required parameter to get the " + throw new CommentManagementException(
"relevant comment."); "Comment ID is null or negative. Comment id is a required parameter to get the "
+ "relevant comment.");
} }
if (comment == null) { if (comment == null) {
log.error("Null Point Exception.Comment at comment id " + CommentId + " is null."); log.error("Null Point Exception.Comment at comment id " + CommentId + " is null.");
@ -102,7 +102,6 @@ public class CommentsManagerImpl implements CommentsManager {
return true; return true;
} }
@Override @Override
public List<Comment> getAllComments(PaginationRequest request, String uuid) throws CommentManagementException { public List<Comment> getAllComments(PaginationRequest request, String uuid) throws CommentManagementException {
@ -110,7 +109,6 @@ public class CommentsManagerImpl implements CommentsManager {
List<Comment> comments; List<Comment> comments;
request = Util.validateCommentListPageSize(request); request = Util.validateCommentListPageSize(request);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("get all comments of the application release" + uuid); log.debug("get all comments of the application release" + uuid);
} }
@ -205,6 +203,7 @@ public class CommentsManagerImpl implements CommentsManager {
} }
} }
@Override
public int getRatedUser(String uuid) throws ApplicationManagementException { public int getRatedUser(String uuid) throws ApplicationManagementException {
int ratedUsers = 0; int ratedUsers = 0;
@ -268,7 +267,6 @@ public class CommentsManagerImpl implements CommentsManager {
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction(); ConnectionManagerUtil.rollbackDBTransaction();
throw new ApplicationManagementException("Application Management Exception occurs.", e); throw new ApplicationManagementException("Application Management Exception occurs.", e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementException("DB Connection Exception occurs.", e); throw new ApplicationManagementException("DB Connection Exception occurs.", e);
} finally { } finally {

Loading…
Cancel
Save