@@ -61,19 +61,14 @@ public class ViolationNotionHandler implements RequestHandler {
|
||||
switch (action) {
|
||||
case "get_notions":
|
||||
return handleGetNotions(request, notionRequest, userId);
|
||||
|
||||
case "get_notion":
|
||||
return handleGetNotion(request, notionRequest, userId);
|
||||
|
||||
case "add_notion":
|
||||
return handleAddNotion(request, notionRequest, userId);
|
||||
|
||||
case "update_notion":
|
||||
return handleUpdateNotion(request, notionRequest, userId);
|
||||
|
||||
case "delete_notion":
|
||||
return handleDeleteNotion(request, notionRequest, userId);
|
||||
|
||||
default:
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
@@ -83,21 +78,21 @@ public class ViolationNotionHandler implements RequestHandler {
|
||||
}
|
||||
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.error("Validation error in ViolationNotionHandler: {}", e.getMessage());
|
||||
log.error("Validation error: {}", e.getMessage());
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.VALIDATION_ERROR.getCode(),
|
||||
e.getMessage(),
|
||||
null);
|
||||
} catch (SecurityException e) {
|
||||
log.error("Security error in ViolationNotionHandler: {}", e.getMessage());
|
||||
log.error("Security error: {}", e.getMessage());
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.ACCESS_DENIED.getCode(),
|
||||
e.getMessage(),
|
||||
null);
|
||||
} catch (Exception e) {
|
||||
log.error("Unexpected error in ViolationNotionHandler", e);
|
||||
log.error("Unexpected error", e);
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.INTERNAL_ERROR.getCode(),
|
||||
@@ -107,26 +102,25 @@ public class ViolationNotionHandler implements RequestHandler {
|
||||
}
|
||||
|
||||
private BaseResponse handleGetNotions(BaseRequest request, ViolationNotionRequest notionRequest, Long userId) {
|
||||
if (notionRequest.getFileId() == null) {
|
||||
if (notionRequest.getViolationId() == null) {
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.INVALID_JSON_BODY.getCode(),
|
||||
"FileId is required for get_notions action",
|
||||
"ViolationId is required for get_notions action",
|
||||
null);
|
||||
}
|
||||
|
||||
try {
|
||||
ViolationNotionsListResponse notions = notionService.getNotionsByFileId(
|
||||
notionRequest.getFileId(), userId);
|
||||
ViolationNotionsListResponse notions = notionService.getNotionsByViolationId(
|
||||
notionRequest.getViolationId(), userId);
|
||||
return BaseResponse.builder()
|
||||
.msgId(request.getMsgId())
|
||||
.messageCode(MessageCode.SUCCESS.getCode())
|
||||
.messageBody(notions)
|
||||
.build();
|
||||
} catch (IllegalArgumentException e) {
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.FILE_NOT_FOUND.getCode(),
|
||||
MessageCode.NOTION_NOT_FOUND.getCode(),
|
||||
e.getMessage(),
|
||||
null);
|
||||
}
|
||||
@@ -136,7 +130,7 @@ public class ViolationNotionHandler implements RequestHandler {
|
||||
if (notionRequest.getNotionId() == null) {
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.NOTION_NOT_FOUND.getCode(),
|
||||
MessageCode.INVALID_JSON_BODY.getCode(),
|
||||
"NotionId is required for get_notion action",
|
||||
null);
|
||||
}
|
||||
@@ -146,7 +140,6 @@ public class ViolationNotionHandler implements RequestHandler {
|
||||
notionRequest.getNotionId(), userId);
|
||||
return BaseResponse.builder()
|
||||
.msgId(request.getMsgId())
|
||||
.messageCode(MessageCode.SUCCESS.getCode())
|
||||
.messageBody(notion)
|
||||
.build();
|
||||
} catch (IllegalArgumentException e) {
|
||||
@@ -159,28 +152,27 @@ public class ViolationNotionHandler implements RequestHandler {
|
||||
}
|
||||
|
||||
private BaseResponse handleAddNotion(BaseRequest request, ViolationNotionRequest notionRequest, Long userId) {
|
||||
if (notionRequest.getFileId() == null) {
|
||||
if (notionRequest.getViolationId() == null) {
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.FILE_NOT_FOUND.getCode(),
|
||||
"FileId is required for add_notion action",
|
||||
MessageCode.INVALID_JSON_BODY.getCode(),
|
||||
"ViolationId is required for add_notion action",
|
||||
null);
|
||||
}
|
||||
|
||||
if (notionRequest.getMessage() == null || notionRequest.getMessage().trim().isEmpty()) {
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.MESSAGE_IS_REQUIRED_FOR_NOTION.getCode(),
|
||||
MessageCode.INVALID_JSON_BODY.getCode(),
|
||||
"Message is required for add_notion action",
|
||||
null);
|
||||
}
|
||||
|
||||
try {
|
||||
ViolationNotionResponse created = notionService.createNotion(
|
||||
notionRequest.getFileId(), userId, notionRequest.getMessage());
|
||||
notionRequest.getViolationId(), userId, notionRequest.getMessage());
|
||||
return BaseResponse.builder()
|
||||
.msgId(request.getMsgId())
|
||||
.messageCode(MessageCode.SUCCESS.getCode())
|
||||
.messageBody(created)
|
||||
.build();
|
||||
} catch (IllegalArgumentException e) {
|
||||
@@ -196,7 +188,7 @@ public class ViolationNotionHandler implements RequestHandler {
|
||||
if (notionRequest.getNotionId() == null) {
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.NOTION_NOT_FOUND.getCode(),
|
||||
MessageCode.INVALID_JSON_BODY.getCode(),
|
||||
"NotionId is required for update_notion action",
|
||||
null);
|
||||
}
|
||||
@@ -204,7 +196,7 @@ public class ViolationNotionHandler implements RequestHandler {
|
||||
if (notionRequest.getMessage() == null || notionRequest.getMessage().trim().isEmpty()) {
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.MESSAGE_IS_REQUIRED_FOR_NOTION.getCode(),
|
||||
MessageCode.INVALID_JSON_BODY.getCode(),
|
||||
"Message is required for update_notion action",
|
||||
null);
|
||||
}
|
||||
@@ -214,7 +206,6 @@ public class ViolationNotionHandler implements RequestHandler {
|
||||
notionRequest.getNotionId(), userId, notionRequest.getMessage());
|
||||
return BaseResponse.builder()
|
||||
.msgId(request.getMsgId())
|
||||
.messageCode(MessageCode.SUCCESS.getCode())
|
||||
.messageBody(updated)
|
||||
.build();
|
||||
} catch (IllegalArgumentException e) {
|
||||
@@ -236,7 +227,7 @@ public class ViolationNotionHandler implements RequestHandler {
|
||||
if (notionRequest.getNotionId() == null) {
|
||||
return new BaseResponse(
|
||||
request.getMsgId(),
|
||||
MessageCode.NOTION_NOT_FOUND.getCode(),
|
||||
MessageCode.INVALID_JSON_BODY.getCode(),
|
||||
"NotionId is required for delete_notion action",
|
||||
null);
|
||||
}
|
||||
@@ -250,7 +241,6 @@ public class ViolationNotionHandler implements RequestHandler {
|
||||
.build();
|
||||
return BaseResponse.builder()
|
||||
.msgId(request.getMsgId())
|
||||
.messageCode(MessageCode.SUCCESS.getCode())
|
||||
.messageBody(deleteResponse)
|
||||
.build();
|
||||
} catch (IllegalArgumentException e) {
|
||||
@@ -264,7 +254,7 @@ public class ViolationNotionHandler implements RequestHandler {
|
||||
request.getMsgId(),
|
||||
MessageCode.ACCESS_DENIED.getCode(),
|
||||
e.getMessage(),
|
||||
MessageCode.ACCESS_DENIED.getDescription());
|
||||
null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user