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

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

Loading…
Cancel
Save