Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import org.opensearch.rest.RestStatus
import java.io.IOException

class GetFindingsResponse : BaseResponse {
private var status: RestStatus
var totalFindings: Int?
var findings: List<FindingWithDocs>

Expand All @@ -19,43 +18,29 @@ class GetFindingsResponse : BaseResponse {
totalFindings: Int?,
findings: List<FindingWithDocs>
) : super() {
this.status = status
this.totalFindings = totalFindings
this.findings = findings
}

@Throws(IOException::class)
constructor(sin: StreamInput) {
this.status = sin.readEnum(RestStatus::class.java)
val findings = mutableListOf<FindingWithDocs>()
this.totalFindings = sin.readOptionalInt()
var currentSize = sin.readInt()
for (i in 0 until currentSize) {
findings.add(FindingWithDocs.readFrom(sin))
}
this.findings = findings
}
constructor(sin: StreamInput) : this(
status = RestStatus.OK,
totalFindings = sin.readOptionalInt(),
findings = sin.readList((FindingWithDocs)::readFrom)
)

@Throws(IOException::class)
override fun writeTo(out: StreamOutput) {
out.writeEnum(status)
out.writeOptionalInt(totalFindings)
out.writeInt(findings.size)
for (finding in findings) {
finding.writeTo(out)
}
out.writeCollection(findings)
}

@Throws(IOException::class)
override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
builder.startObject()
.field("total_findings", totalFindings)
.field("findings", findings)
.field("findings", findings.toTypedArray())

return builder.endObject()
}

override fun getStatus(): RestStatus {
return this.status
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ package org.opensearch.commons.alerting.model
import org.apache.logging.log4j.LogManager
import org.opensearch.common.io.stream.StreamInput
import org.opensearch.common.io.stream.StreamOutput
import org.opensearch.common.io.stream.Writeable
import org.opensearch.common.xcontent.ToXContent
import org.opensearch.common.xcontent.XContentBuilder
import org.opensearch.common.xcontent.XContentParser
import org.opensearch.common.xcontent.XContentParserUtils
import org.opensearch.commons.notifications.model.BaseModel
import java.io.IOException

private val log = LogManager.getLogger(FindingDocument::class.java)

class FindingDocument(
data class FindingDocument(
val index: String,
val id: String,
val found: Boolean,
val document: String
) : Writeable, ToXContent {
) : BaseModel {

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
Expand Down Expand Up @@ -52,7 +52,7 @@ class FindingDocument(
const val NO_ID = ""
const val NO_INDEX = ""

@JvmStatic @JvmOverloads
@JvmStatic
@Throws(IOException::class)
fun parse(xcp: XContentParser, id: String = NO_ID, index: String = NO_INDEX): FindingDocument {
var found = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,26 @@ package org.opensearch.commons.alerting.model
import org.apache.logging.log4j.LogManager
import org.opensearch.common.io.stream.StreamInput
import org.opensearch.common.io.stream.StreamOutput
import org.opensearch.common.io.stream.Writeable
import org.opensearch.common.xcontent.ToXContent
import org.opensearch.common.xcontent.XContentBuilder
import org.opensearch.common.xcontent.XContentParser
import org.opensearch.common.xcontent.XContentParserUtils
import org.opensearch.commons.notifications.model.BaseModel
import java.io.IOException

private val log = LogManager.getLogger(Finding::class.java)

class FindingWithDocs(
val finding: Finding,
val documents: List<FindingDocument>
) : Writeable, ToXContent {
class FindingWithDocs : BaseModel {
var finding: Finding
var documents: List<FindingDocument>

constructor(
finding: Finding,
documents: List<FindingDocument>
) : super() {
this.finding = finding
this.documents = documents
}

@Throws(IOException::class)
constructor(sin: StreamInput) : this(
Expand All @@ -26,15 +33,15 @@ class FindingWithDocs(
@Throws(IOException::class)
override fun writeTo(out: StreamOutput) {
finding.writeTo(out)
documents.forEach {
it.writeTo(out)
}
out.writeCollection(documents)
}

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
builder.startObject()
.startObject("finding_with_docs")
.field(FINDING_FIELD, finding)
.field(DOCUMENTS_FIELD, documents)
.field(DOCUMENTS_FIELD, documents.toTypedArray())
.endObject()
builder.endObject()
return builder
}
Expand Down