mirror of
https://github.com/datahub-project/datahub.git
synced 2025-08-22 08:08:01 +00:00
Fix Dataset comment PUT API (#748)
This commit is contained in:
parent
0d6f952d50
commit
adcf3a7c93
@ -420,7 +420,6 @@ public class Dataset extends Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Result postDatasetComment(int id) {
|
public static Result postDatasetComment(int id) {
|
||||||
String body = request().body().asText();
|
|
||||||
ObjectNode result = Json.newObject();
|
ObjectNode result = Json.newObject();
|
||||||
String username = session("user");
|
String username = session("user");
|
||||||
Map<String, String[]> params = request().body().asFormUrlEncoded();
|
Map<String, String[]> params = request().body().asFormUrlEncoded();
|
||||||
@ -428,6 +427,7 @@ public class Dataset extends Controller {
|
|||||||
if (StringUtils.isNotBlank(username)) {
|
if (StringUtils.isNotBlank(username)) {
|
||||||
if (DatasetsDAO.postComment(id, params, username)) {
|
if (DatasetsDAO.postComment(id, params, username)) {
|
||||||
result.put("status", "success");
|
result.put("status", "success");
|
||||||
|
return ok(result);
|
||||||
} else {
|
} else {
|
||||||
result.put("status", "failed");
|
result.put("status", "failed");
|
||||||
result.put("error", "true");
|
result.put("error", "true");
|
||||||
@ -440,22 +440,15 @@ public class Dataset extends Controller {
|
|||||||
result.put("msg", "Unauthorized User.");
|
result.put("msg", "Unauthorized User.");
|
||||||
return badRequest(result);
|
return badRequest(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ok(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Result putDatasetComment(int id, int commentId) {
|
public static Result putDatasetComment(int id, int commentId) {
|
||||||
String body = request().body().asText();
|
|
||||||
ObjectNode result = Json.newObject();
|
ObjectNode result = Json.newObject();
|
||||||
String username = session("user");
|
String username = session("user");
|
||||||
Map<String, String[]> params = request().body().asFormUrlEncoded();
|
Map<String, String[]> params = request().body().asFormUrlEncoded();
|
||||||
|
|
||||||
if (StringUtils.isNotBlank(username)) {
|
if (StringUtils.isNotBlank(username)) {
|
||||||
if (!params.containsKey("id")) {
|
if (DatasetsDAO.postComment(id, commentId, params, username)) {
|
||||||
params.put("id", new String[]{String.valueOf(commentId)});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (DatasetsDAO.postComment(id, params, username)) {
|
|
||||||
result.put("status", "success");
|
result.put("status", "success");
|
||||||
return ok(result);
|
return ok(result);
|
||||||
} else {
|
} else {
|
||||||
|
@ -982,77 +982,38 @@ public class DatasetsDAO extends AbstractMySQLOpenSourceDAO
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean postComment(int datasetId, Map<String, String[]> commentMap, String user)
|
public static boolean postComment(int datasetId, Map<String, String[]> commentMap, String user) {
|
||||||
{
|
return postComment(datasetId, 0, commentMap, user);
|
||||||
boolean result = false;
|
}
|
||||||
if ((commentMap == null) || commentMap.size() == 0)
|
|
||||||
{
|
public static boolean postComment(int datasetId, int commentId, Map<String, String[]> commentMap, String user) {
|
||||||
|
if (commentMap == null || commentMap.size() == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
String text = "";
|
if (!commentMap.containsKey("text") || commentMap.get("text") == null || commentMap.get("text").length == 0) {
|
||||||
if (commentMap.containsKey("text")) {
|
return false;
|
||||||
String[] textArray = commentMap.get("text");
|
|
||||||
if (textArray != null && textArray.length > 0)
|
|
||||||
{
|
|
||||||
text = textArray[0];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (StringUtils.isBlank(text))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
String text = commentMap.get("text")[0];
|
||||||
|
|
||||||
String type = "Comment";
|
String type = "Comment";
|
||||||
if (commentMap.containsKey("type")) {
|
if (commentMap.containsKey("type")) {
|
||||||
String[] typeArray = commentMap.get("type");
|
String[] typeArray = commentMap.get("type");
|
||||||
if (typeArray != null && typeArray.length > 0)
|
if (typeArray != null && typeArray.length > 0) {
|
||||||
{
|
|
||||||
type = typeArray[0];
|
type = typeArray[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Integer commentId = 0;
|
|
||||||
if (commentMap.containsKey("id")) {
|
|
||||||
String[] idArray = commentMap.get("id");
|
|
||||||
if (idArray != null && idArray.length > 0)
|
|
||||||
{
|
|
||||||
String idStr = idArray[0];
|
|
||||||
try
|
|
||||||
{
|
|
||||||
commentId = Integer.parseInt(idStr);
|
|
||||||
}
|
|
||||||
catch(NumberFormatException e)
|
|
||||||
{
|
|
||||||
Logger.error("DatasetDAO postComment wrong id parameter. Error message: " +
|
|
||||||
e.getMessage());
|
|
||||||
commentId = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Integer userId = UserDAO.getUserIDByUserName(user);
|
Integer userId = UserDAO.getUserIDByUserName(user);
|
||||||
|
if (userId == null || userId == 0) {
|
||||||
if (userId != null && userId !=0)
|
return false;
|
||||||
{
|
}
|
||||||
if (commentId != null && commentId != 0)
|
|
||||||
{
|
if (commentId > 0) {
|
||||||
int row = getJdbcTemplate().update(UPDATE_DATASET_COMMENT, text, type, commentId);
|
return getJdbcTemplate().update(UPDATE_DATASET_COMMENT, text, type, commentId) > 0;
|
||||||
if (row > 0)
|
} else {
|
||||||
{
|
return getJdbcTemplate().update(CREATE_DATASET_COMMENT, text, userId, datasetId, type) > 0;
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int row = getJdbcTemplate().update(CREATE_DATASET_COMMENT, text, userId, datasetId, type);
|
|
||||||
if (row > 0)
|
|
||||||
{
|
|
||||||
result = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean deleteComment(int id)
|
public static boolean deleteComment(int id)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user