Skip to content

Commit

Permalink
misc cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Dennis Toepker <[email protected]>
  • Loading branch information
toepkerd-zz committed Jun 5, 2024
1 parent a833a9f commit 3b3566e
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ class DeleteCommentRequest : ActionRequest {
)

override fun validate(): ActionRequestValidationException? {
if (commentId.isBlank()) {
return ActionRequestValidationException()
}
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@ import org.opensearch.core.xcontent.ToXContent
import org.opensearch.core.xcontent.XContentBuilder

class DeleteCommentResponse : BaseResponse {
var id: String
var commentId: String

constructor(
id: String
) : super() {
this.id = id
this.commentId = id
}

constructor(sin: StreamInput) : this(
sin.readString() // id
sin.readString() // commentId
)

override fun writeTo(out: StreamOutput) {
out.writeString(id)
out.writeString(commentId)
}

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
return builder.startObject()
.field(IndexUtils._ID, id)
.field(IndexUtils._ID, commentId)
.endObject()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ import org.opensearch.core.common.io.stream.StreamOutput
import org.opensearch.rest.RestRequest
import java.io.IOException

/**
* Request to index/create a Comment
*
* entityId: the entity that the Comment is attached to and therefore associated with (e.g. in Alerting,
* the entity is an Alert). This field is expected to be non-blank if the request is to create a new Comment.
*
* commentId: the ID of an existing Comment. This field is expected to be non-blank if the request is to
* update an existing Comment.
*/
class IndexCommentRequest : ActionRequest {
val entityId: String
val commentId: String
Expand Down Expand Up @@ -42,6 +51,11 @@ class IndexCommentRequest : ActionRequest {
)

override fun validate(): ActionRequestValidationException? {
if (method == RestRequest.Method.POST && entityId.isBlank() ||
method == RestRequest.Method.PUT && commentId.isBlank()
) {
return ActionRequestValidationException()
}
return null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.opensearch.core.xcontent.XContentBuilder
import java.io.IOException

class IndexCommentResponse : BaseResponse {
// TODO: do we really need sequence num and primary term? probs delete em
var id: String
var seqNo: Long
var primaryTerm: Long
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.opensearch.core.common.io.stream.StreamInput

class DeleteCommentRequestTests {
@Test
fun `test delete comment request`() {
fun `test delete comment request writing and parsing`() {
val req = DeleteCommentRequest("1234")
assertNotNull(req)
assertEquals("1234", req.commentId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import org.opensearch.core.common.io.stream.StreamInput

class DeleteCommentResponseTests {
@Test
fun `test delete comment response`() {
fun `test delete comment response writing and parsing`() {
val res = DeleteCommentResponse(id = "123")
assertNotNull(res)
assertEquals("123", res.id)
assertEquals("123", res.commentId)

val out = BytesStreamOutput()
res.writeTo(out)
val sin = StreamInput.wrap(out.bytes().toBytesRef().bytes)
val newRes = DeleteCommentResponse(sin)
assertEquals("123", newRes.id)
assertEquals("123", newRes.commentId)
}
}

0 comments on commit 3b3566e

Please sign in to comment.