Modified CommentManagerImpl and CommentManager

wrapped & thrown the sql and db exceptions with CommentManagementException and ApplicationManagementException.
feature/appm-store/pbac
nishadi 7 years ago
parent caa47417bc
commit 3bd6d03b4c

@ -24,6 +24,7 @@ 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.CommentManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import java.sql.SQLException;
import java.util.List;
@ -65,7 +66,7 @@ public interface CommentsManager {
* @throws CommentManagementException Exceptions of the comment management.
* @throws SQLException SQL Exception
*/
List<Comment> getAllComments(PaginationRequest request, String uuid) throws CommentManagementException, SQLException;
List<Comment> getAllComments(PaginationRequest request, String uuid) throws CommentManagementException;
/**
@ -96,7 +97,7 @@ public interface CommentsManager {
* @throws SQLException SQL Exception
* @throws DBConnectionException Database connection Exception
*/
Comment updateComment(Comment comment,int CommentId) throws CommentManagementException, SQLException, DBConnectionException;
Comment updateComment(Comment comment,int CommentId) throws CommentManagementException;
/**
* To get number of rated users
@ -105,7 +106,7 @@ public interface CommentsManager {
* @return number of rated users
* @throws SQLException sql exception
*/
int getRatedUser(String uuid)throws SQLException;
int getRatedUser(String uuid) throws SQLException, CommentManagementException, ApplicationManagementException;
/**
* To get the average of stars
@ -114,7 +115,7 @@ public interface CommentsManager {
* @return value of the stars of an application
* @throws SQLException sql exception
*/
int getStars(String uuid)throws SQLException;
int getStars(String uuid) throws SQLException, CommentManagementException, ApplicationManagementException;
/**
* To update rating stars

@ -68,13 +68,15 @@ public class CommentsManagerImpl implements CommentsManager {
commentDAO.addComment(tenantId,comment, comment.getCreatedBy(),comment.getParent(),uuid);
ConnectionManagerUtil.commitDBTransaction();
return comment;
} catch (Exception e) {
log.error("Exception occurs.", e);
} catch (DBConnectionException e) {
ConnectionManagerUtil.rollbackDBTransaction();
throw new CommentManagementException("DB Connection Exception occurs.",e);
} catch (SQLException | TransactionManagementException e){
throw new CommentManagementException("SQL Exception occurs.",e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
return comment;
}
/**
@ -102,8 +104,7 @@ public class CommentsManagerImpl implements CommentsManager {
@Override
public List<Comment> getAllComments(PaginationRequest request,String uuid) throws CommentManagementException,
SQLException {
public List<Comment> getAllComments(PaginationRequest request,String uuid) throws CommentManagementException {
PaginationResult paginationResult = new PaginationResult();
List<Comment> comments;
@ -124,11 +125,12 @@ public class CommentsManagerImpl implements CommentsManager {
return comments;
} catch (DBConnectionException e) {
log.error("DB Connection Exception occurs.", e);
throw new CommentManagementException("DB Connection Exception occurs.", e);
} catch (SQLException e){
throw new CommentManagementException("SQL Exception occurs.",e);
}finally {
ConnectionManagerUtil.closeDBConnection();
}
return null;
}
@Override
@ -145,9 +147,9 @@ public class CommentsManagerImpl implements CommentsManager {
ConnectionManagerUtil.openDBConnection();
comment=commentDAO.getComment(CommentId);
} catch (DBConnectionException e) {
log.error("DB Connection Exception occurs.", e);
throw new CommentManagementException("DB Connection Exception occurs.", e);
} catch (SQLException e) {
log.error("SQL Exception occurs.", e);
throw new CommentManagementException("SQL Exception occurs.", e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
@ -169,19 +171,18 @@ public class CommentsManagerImpl implements CommentsManager {
commentDAO.deleteComment(CommentId);
ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) {
log.error("DB Connection Exception occurs.", e);
throw new CommentManagementException("DB Connection Exception occurs.", e);
} catch (SQLException e) {
log.error("SQL Exception occurs.", e);
throw new CommentManagementException("SQL Exception occurs.", e);
} catch (TransactionManagementException e) {
log.error("Transaction Management Exception occurs.", e);
throw new CommentManagementException("Transaction Management Exception occurs.", e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public Comment updateComment(Comment comment,int CommentId) throws CommentManagementException, SQLException,
DBConnectionException {
public Comment updateComment(Comment comment,int CommentId) throws CommentManagementException {
PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
validateComment(CommentId,comment.getComment());
@ -193,13 +194,18 @@ public class CommentsManagerImpl implements CommentsManager {
try {
ConnectionManagerUtil.openDBConnection();
commentDAO.getComment(CommentId);
return commentDAO.updateComment(CommentId, comment.getComment(),comment.getModifiedBy(),comment.getModifiedAt());
return commentDAO
.updateComment(CommentId, comment.getComment(), comment.getModifiedBy(), comment.getModifiedAt());
} catch (SQLException e){
throw new CommentManagementException("SQL Exception occurs.",e);
}catch (DBConnectionException e){
throw new CommentManagementException("DB Connection occurs.",e);
}finally {
ConnectionManagerUtil.closeDBConnection();
}
}
public int getRatedUser(String uuid){
public int getRatedUser(String uuid) throws ApplicationManagementException {
int ratedUsers=0;
if (log.isDebugEnabled()) {
@ -209,9 +215,9 @@ public class CommentsManagerImpl implements CommentsManager {
ConnectionManagerUtil.openDBConnection();
ratedUsers =commentDAO.getRatedUser(uuid);
} catch (DBConnectionException e) {
log.error("DB Connection Exception occurs.", e);
throw new ApplicationManagementException("DB Connection Exception occurs",e);
} catch (ApplicationManagementDAOException e) {
log.error("Application Management Exception occurs.", e);
throw new ApplicationManagementException("Application Management Exception occurs.", e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
@ -219,7 +225,7 @@ public class CommentsManagerImpl implements CommentsManager {
}
@Override
public int getStars(String uuid) throws SQLException {
public int getStars(String uuid) throws ApplicationManagementException {
int stars=0;
if (log.isDebugEnabled()) {
@ -229,9 +235,9 @@ public class CommentsManagerImpl implements CommentsManager {
ConnectionManagerUtil.openDBConnection();
stars= commentDAO.getStars(uuid);
} catch (DBConnectionException e) {
log.error("DB Connection Exception occurs.", e);
throw new ApplicationManagementException("DB Connection Exception occurs",e);
} catch (ApplicationManagementDAOException e) {
log.error("Application Management Exception occurs.", e);
throw new ApplicationManagementException("Application Management Exception occurs.", e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
@ -261,14 +267,14 @@ public class CommentsManagerImpl implements CommentsManager {
}
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
log.error("Application Management Exception occurs.", e);
throw new ApplicationManagementException("Application Management Exception occurs.", e);
} catch (DBConnectionException e) {
log.error("DB Connection Exception occurs.", e);
throw new ApplicationManagementException("DB Connection Exception occurs.", e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
return newStars;
}

Loading…
Cancel
Save