Modified CommentManagerImpl

Renamed ApplicationManagementDAOFactory.getCommentDAO as commentDAO
feature/appm-store/pbac
nishadi 7 years ago
parent a45ba625fe
commit 74ea82c926

@ -32,10 +32,7 @@ import org.wso2.carbon.device.application.mgt.core.dao.CommentDAO;
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.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.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import javax.ws.rs.core.Response;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.time.Instant; import java.time.Instant;
@ -68,8 +65,7 @@ public class CommentsManagerImpl implements CommentsManager {
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationManagementDAOFactory.getCommentDAO().addComment(tenantId,comment, commentDAO.addComment(tenantId,comment, comment.getCreatedBy(),comment.getParent(),uuid);
comment.getCreatedBy(),comment.getParent(),uuid);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return comment; return comment;
} catch (Exception e) { } catch (Exception e) {
@ -147,7 +143,7 @@ public class CommentsManagerImpl implements CommentsManager {
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
comment=ApplicationManagementDAOFactory.getCommentDAO().getComment(CommentId); comment=commentDAO.getComment(CommentId);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
log.error("DB Connection Exception occurs.", e); log.error("DB Connection Exception occurs.", e);
} catch (SQLException e) { } catch (SQLException e) {
@ -170,7 +166,7 @@ public class CommentsManagerImpl implements CommentsManager {
} }
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationManagementDAOFactory.getCommentDAO().deleteComment(CommentId); commentDAO.deleteComment(CommentId);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
log.error("DB Connection Exception occurs.", e); log.error("DB Connection Exception occurs.", e);
@ -196,8 +192,8 @@ public class CommentsManagerImpl implements CommentsManager {
comment.setModifiedAt(Timestamp.from(Instant.now())); comment.setModifiedAt(Timestamp.from(Instant.now()));
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
ApplicationManagementDAOFactory.getCommentDAO().getComment(CommentId); commentDAO.getComment(CommentId);
return ApplicationManagementDAOFactory.getCommentDAO().updateComment(CommentId, return commentDAO.updateComment(CommentId,
comment.getComment(),comment.getModifiedBy(),comment.getModifiedAt()); comment.getComment(),comment.getModifiedBy(),comment.getModifiedAt());
} catch (SQLException e) { } catch (SQLException e) {
log.error("SQL Exception occurs.", e); log.error("SQL Exception occurs.", e);
@ -206,7 +202,7 @@ public class CommentsManagerImpl implements CommentsManager {
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
return ApplicationManagementDAOFactory.getCommentDAO().getComment(CommentId); return commentDAO.getComment(CommentId);
} }
public int getRatedUser(String uuid){ public int getRatedUser(String uuid){
@ -217,7 +213,7 @@ public class CommentsManagerImpl implements CommentsManager {
} }
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
ratedUsers =ApplicationManagementDAOFactory.getCommentDAO().getRatedUser(uuid); ratedUsers =commentDAO.getRatedUser(uuid);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
log.error("DB Connection Exception occurs.", e); log.error("DB Connection Exception occurs.", e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
@ -237,7 +233,7 @@ public class CommentsManagerImpl implements CommentsManager {
} }
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
stars= ApplicationManagementDAOFactory.getCommentDAO().getStars(uuid); stars= commentDAO.getStars(uuid);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
log.error("DB Connection Exception occurs.", e); log.error("DB Connection Exception occurs.", e);
} catch (ApplicationManagementDAOException e) { } catch (ApplicationManagementDAOException e) {
@ -258,14 +254,14 @@ public class CommentsManagerImpl implements CommentsManager {
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
int ratedUsers = ApplicationManagementDAOFactory.getCommentDAO().getRatedUser(uuid); int ratedUsers = commentDAO.getRatedUser(uuid);
int oldStars = ApplicationManagementDAOFactory.getCommentDAO().getStars(uuid); int oldStars = commentDAO.getStars(uuid);
if(ratedUsers==0){ if(ratedUsers==0){
newStars=ApplicationManagementDAOFactory.getCommentDAO().updateStars(stars,uuid); newStars=commentDAO.updateStars(stars,uuid);
return newStars; return newStars;
}else { }else {
int avgStars = ((oldStars*ratedUsers)+stars) / (ratedUsers+1); int avgStars = ((oldStars*ratedUsers)+stars) / (ratedUsers+1);
newStars = ApplicationManagementDAOFactory.getCommentDAO().updateStars(avgStars, uuid); newStars = commentDAO.updateStars(avgStars, uuid);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return newStars; return newStars;
} }

Loading…
Cancel
Save