1 /* 2 * Make.org Core API 3 * Copyright (C) 2018 Make.org 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU Affero General Public License as 7 * published by the Free Software Foundation, either version 3 of the 8 * License, or (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU Affero General Public License for more details. 14 * 15 * You should have received a copy of the GNU Affero General Public License 16 * along with this program. If not, see <https://www.gnu.org/licenses/>. 17 * 18 */ 19 20 package org.make.api.technical 21 22 import com.sksamuel.elastic4s.{ElasticClient, Handler} 23 import grizzled.slf4j.Logging 24 25 import scala.concurrent.{ExecutionContext, Future} 26 27 package object elasticsearch extends Logging { 28 implicit class RichHttpClient(val self: ElasticClient) extends AnyVal { 29 def executeAsFuture[T, U]( 30 request: T 31 )(implicit exec: Handler[T, U], executionContext: ExecutionContext, manifest: Manifest[U]): Future[U] = { 32 33 logger.debug(self.show(request).replace('\n', ' ')) 34 self.execute(request).flatMap { result => 35 if (result.isSuccess) { 36 Future.successful(result.result) 37 } else { 38 Future.failed(new ElasticException(result.error, self.show(request))) 39 } 40 } 41 } 42 } 43 }
| Line | Stmt Id | Pos | Tree | Symbol | Tests | Code |
|---|---|---|---|---|---|---|
| 33 | 8803 | 1201 - 1252 | Apply | grizzled.slf4j.Logger.debug | org.scalatest.testsuite | `package`.this.logger.debug(RichHttpClient.this.self.show[T](request)(exec).replace('\n', ' ')) |
| 33 | 7940 | 1214 - 1251 | Apply | java.lang.String.replace | RichHttpClient.this.self.show[T](request)(exec).replace('\n', ' ') | |
| 34 | 8372 | 1259 - 1490 | ApplyToImplicitArgs | scala.concurrent.Future.flatMap | org.scalatest.testsuite | RichHttpClient.this.self.execute[T, U, [+T]scala.concurrent.Future[T]](request)(elastic4s.this.Executor.FutureExecutor(executionContext), elastic4s.this.Functor.FutureFunctor(executionContext), exec, scala.this.JavaTypeable.gen0JavaTypeable[U](manifest), elastic4s.this.CommonRequestOptions.defaults).flatMap[U](((result: com.sksamuel.elastic4s.Response[U]) => if (result.isSuccess) scala.concurrent.Future.successful[U](result.result) else scala.concurrent.Future.failed[Nothing](new ElasticException(result.error, RichHttpClient.this.self.show[T](request)(exec)))))(executionContext) |