use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.
the class ApiMgtDAO method getComments.
/**
**************************************
* Returns all the Comments on an API
*
* @param apiTypeWrapper API type Wrapper
* @param parentCommentID Parent Comment ID
* @return Comment Array
* @throws APIManagementException
*/
public CommentList getComments(ApiTypeWrapper apiTypeWrapper, String parentCommentID, Integer limit, Integer offset) throws APIManagementException {
CommentList commentList = null;
try (Connection connection = APIMgtDBUtil.getConnection()) {
int id = -1;
String uuid;
Identifier identifier;
String currentApiUuid;
if (apiTypeWrapper.isAPIProduct()) {
identifier = apiTypeWrapper.getApiProduct().getId();
uuid = apiTypeWrapper.getApiProduct().getUuid();
APIRevision apiRevision = checkAPIUUIDIsARevisionUUID(uuid);
if (apiRevision != null && apiRevision.getApiUUID() != null) {
currentApiUuid = apiRevision.getApiUUID();
} else {
currentApiUuid = uuid;
}
} else {
identifier = apiTypeWrapper.getApi().getId();
uuid = apiTypeWrapper.getApi().getUuid();
APIRevision apiRevision = checkAPIUUIDIsARevisionUUID(uuid);
if (apiRevision != null && apiRevision.getApiUUID() != null) {
currentApiUuid = apiRevision.getApiUUID();
} else {
currentApiUuid = uuid;
}
}
id = getAPIID(currentApiUuid, connection);
if (id == -1) {
String msg = "Could not load API record for: " + identifier.getName();
throw new APIManagementException(msg);
}
commentList = getComments(currentApiUuid, parentCommentID, limit, offset, connection);
} catch (SQLException e) {
handleException("Failed to retrieve comments for " + apiTypeWrapper.getName(), e);
}
return commentList;
}
use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.
the class ApiMgtDAO method getComment.
/**
************************
* Returns a specific comment of an API
*
* @param commentId Comment ID
* @param apiTypeWrapper Api Type Wrapper
* @return Comment Array
* @throws APIManagementException
*/
public Comment getComment(ApiTypeWrapper apiTypeWrapper, String commentId, Integer replyLimit, Integer replyOffset) throws APIManagementException {
String uuid;
Identifier identifier;
if (apiTypeWrapper.isAPIProduct()) {
identifier = apiTypeWrapper.getApiProduct().getId();
uuid = apiTypeWrapper.getApiProduct().getUuid();
} else {
identifier = apiTypeWrapper.getApi().getId();
uuid = apiTypeWrapper.getApi().getUuid();
}
try (Connection connection = APIMgtDBUtil.getConnection()) {
Comment comment = new Comment();
int id = -1;
String getCommentQuery = SQLConstants.GET_COMMENT_SQL;
id = getAPIID(uuid, connection);
if (id == -1) {
String msg = "Could not load API record for: " + identifier.getName();
throw new APIManagementException(msg);
}
try (PreparedStatement prepStmt = connection.prepareStatement(getCommentQuery)) {
prepStmt.setString(1, uuid);
prepStmt.setString(2, commentId);
try (ResultSet resultSet = prepStmt.executeQuery()) {
if (resultSet.next()) {
comment.setId(resultSet.getString("COMMENT_ID"));
comment.setText(resultSet.getString("COMMENT_TEXT"));
comment.setUser(resultSet.getString("CREATED_BY"));
comment.setCreatedTime(resultSet.getTimestamp("CREATED_TIME"));
comment.setUpdatedTime(resultSet.getTimestamp("UPDATED_TIME"));
comment.setApiId(resultSet.getString("API_ID"));
comment.setParentCommentID(resultSet.getString("PARENT_COMMENT_ID"));
comment.setEntryPoint(resultSet.getString("ENTRY_POINT"));
comment.setCategory(resultSet.getString("CATEGORY"));
comment.setReplies(getComments(uuid, commentId, replyLimit, replyOffset, connection));
return comment;
}
}
}
} catch (SQLException e) {
handleException("Failed to retrieve comment for API " + identifier.getName() + "with comment ID " + commentId, e);
}
return null;
}
use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.
the class CommentMappingUtil method fromCommentToDTOWithUserInfo.
/**
* Converts a Comment object into corresponding REST API CommentDTO object with User Info.
*
* @param comment comment object
* @return CommentDTO
*/
public static CommentDTO fromCommentToDTOWithUserInfo(Comment comment, Map<String, Map<String, String>> userClaimsMap) throws APIManagementException {
CommentDTO commentDTO = fromCommentToDTO(comment);
if (userClaimsMap.get(comment.getUser()) != null) {
Map userClaims = userClaimsMap.get(comment.getUser());
CommenterInfoDTO commenterInfoDTO = new CommenterInfoDTO();
commenterInfoDTO.setFullName((String) userClaims.get(APIConstants.FULL_NAME));
commenterInfoDTO.setFirstName((String) userClaims.get(APIConstants.FIRST_NAME));
commenterInfoDTO.setLastName((String) userClaims.get(APIConstants.LAST_NAME));
commentDTO.setCommenterInfo(commenterInfoDTO);
}
return commentDTO;
}
use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.
the class CommentMappingUtil method fromCommentListToDTO.
/**
* Wraps a List of Comments to a CommentListDTO.
*
* @param commentList list of comments
* @return CommentListDTO
*/
public static CommentListDTO fromCommentListToDTO(CommentList commentList, boolean includeCommenterInfo) {
CommentListDTO commentListDTO = new CommentListDTO();
List<CommentDTO> listOfCommentDTOs = new ArrayList<>();
commentListDTO.setCount(commentList.getCount());
PaginationDTO paginationDTO = new PaginationDTO();
paginationDTO.setLimit(commentList.getPagination().getLimit());
paginationDTO.setOffset(commentList.getPagination().getOffset());
paginationDTO.setTotal(commentList.getPagination().getTotal());
paginationDTO.setNext(commentList.getPagination().getNext());
paginationDTO.setPrevious(commentList.getPagination().getPrevious());
commentListDTO.setPagination(paginationDTO);
Map<String, Map<String, String>> userClaimsMap = new HashMap<>();
for (Comment comment : commentList.getList()) {
try {
if (includeCommenterInfo) {
userClaimsMap = retrieveUserClaims(comment.getUser(), userClaimsMap);
listOfCommentDTOs.add(fromCommentToDTOWithUserInfo(comment, userClaimsMap));
} else {
listOfCommentDTOs.add(fromCommentToDTO(comment));
}
} catch (APIManagementException e) {
log.error("Error while creating comments list", e);
}
}
commentListDTO.setList(listOfCommentDTOs);
return commentListDTO;
}
use of org.wso2.carbon.apimgt.core.models.Comment in project carbon-apimgt by wso2.
the class CommentMappingUtil method fromCommentToDTOWithUserInfo.
/**
* Converts a Comment object into corresponding REST API CommentDTO object with User Info
*
* @param comment comment object
* @return CommentDTO
*/
public static CommentDTO fromCommentToDTOWithUserInfo(Comment comment, Map<String, Map<String, String>> userClaimsMap) throws APIManagementException {
CommentDTO commentDTO = fromCommentToDTO(comment);
if (userClaimsMap.get(comment.getUser()) != null) {
Map userClaims = userClaimsMap.get(comment.getUser());
CommenterInfoDTO commenterInfoDTO = new CommenterInfoDTO();
commenterInfoDTO.setFullName((String) userClaims.get(APIConstants.FULL_NAME));
commenterInfoDTO.setFirstName((String) userClaims.get(APIConstants.FIRST_NAME));
commenterInfoDTO.setLastName((String) userClaims.get(APIConstants.LAST_NAME));
commentDTO.setCommenterInfo(commenterInfoDTO);
}
return commentDTO;
}
Aggregations