Skip to content

Commit

Permalink
Use kotlin syntax instead of optional
Browse files Browse the repository at this point in the history
Signed-off-by: Chase Engelbrecht <[email protected]>
  • Loading branch information
engechas committed Jan 3, 2024
1 parent 6ac125c commit d4ba8de
Showing 1 changed file with 4 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ import org.opensearch.index.reindex.DeleteByQueryRequestBuilder
import org.opensearch.search.builder.SearchSourceBuilder
import org.opensearch.tasks.Task
import org.opensearch.transport.TransportService
import java.util.Optional

private val scope: CoroutineScope = CoroutineScope(Dispatchers.IO)
/**
Expand Down Expand Up @@ -120,12 +119,7 @@ class TransportDeleteWorkflowAction @Inject constructor(
) {
suspend fun resolveUserAndStart() {
try {
val optionalWorkflow = getWorkflow()
if (optionalWorkflow.isEmpty) {
return
}

val workflow = optionalWorkflow.get()
val workflow: Workflow = getWorkflow() ?: return

val canDelete = user == null ||
!doFilterForUser(user) ||
Expand Down Expand Up @@ -302,16 +296,16 @@ class TransportDeleteWorkflowAction @Inject constructor(
return deletableMonitors
}

private suspend fun getWorkflow(): Optional<Workflow> {
private suspend fun getWorkflow(): Workflow? {
val getRequest = GetRequest(ScheduledJob.SCHEDULED_JOBS_INDEX, workflowId)

val getResponse: GetResponse = client.suspendUntil { get(getRequest, it) }
if (!getResponse.isExists) {
handleWorkflowMissing()
return Optional.empty()
return null
}

return Optional.of(parseWorkflow(getResponse))
return parseWorkflow(getResponse)
}

private fun handleWorkflowMissing() {
Expand Down

0 comments on commit d4ba8de

Please sign in to comment.