Skip to content

Commit

Permalink
#280 Make number of maximum similar cases configurable under key "max…
Browse files Browse the repository at this point in the history
…SimilarCases" (default=100)
  • Loading branch information
To-om committed Sep 5, 2017
1 parent b7d2320 commit a5d9fed
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 2 additions & 0 deletions thehive-backend/app/services/AlertSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ object AlertSrv {

@Singleton
class AlertSrv(
maxSimilarCases: Int,
templates: Map[String, String],
alertModel: AlertModel,
createSrv: CreateSrv,
Expand Down Expand Up @@ -68,6 +69,7 @@ class AlertSrv(
connectors: ConnectorRouter,
ec: ExecutionContext,
mat: Materializer) = this(
configuration.getOptional[Int]("maxSimilarCases").getOrElse(100),
Map.empty[String, String],
alertModel: AlertModel,
createSrv,
Expand Down
31 changes: 28 additions & 3 deletions thehive-backend/app/services/CaseSrv.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import javax.inject.{ Inject, Singleton }
import scala.concurrent.{ ExecutionContext, Future }
import scala.util.Try

import play.api.Logger
import play.api.{ Configuration, Logger }
import play.api.libs.json.Json.toJsFieldJsValueWrapper
import play.api.libs.json._

Expand All @@ -18,7 +18,8 @@ import org.elastic4play.controllers.Fields
import org.elastic4play.services._

@Singleton
class CaseSrv @Inject() (
class CaseSrv(
maxSimilarCases: Int,
caseModel: CaseModel,
artifactModel: ArtifactModel,
taskModel: TaskModel,
Expand All @@ -30,6 +31,30 @@ class CaseSrv @Inject() (
findSrv: FindSrv,
implicit val ec: ExecutionContext) {

@Inject() def this(
configuration: Configuration,
caseModel: CaseModel,
artifactModel: ArtifactModel,
taskModel: TaskModel,
createSrv: CreateSrv,
artifactSrv: ArtifactSrv,
getSrv: GetSrv,
updateSrv: UpdateSrv,
deleteSrv: DeleteSrv,
findSrv: FindSrv,
ec: ExecutionContext) = this(
configuration.getOptional[Int]("maxSimilarCases").getOrElse(100),
caseModel,
artifactModel,
taskModel,
createSrv,
artifactSrv,
getSrv,
updateSrv,
deleteSrv,
findSrv,
ec)

private[CaseSrv] lazy val logger = Logger(getClass)

def applyTemplate(template: CaseTemplate, originalFields: Fields): Fields = {
Expand Down Expand Up @@ -120,7 +145,7 @@ class CaseSrv @Inject() (
"status" ~= "Ok"), Some("all"), Nil)
._1
.flatMapConcat { artifact artifactSrv.findSimilar(artifact, Some("all"), Nil)._1 }
.groupBy(100, _.parentId)
.groupBy(maxSimilarCases, _.parentId)
.map { a (a.parentId, Seq(a)) }
.reduce((l, r) (l._1, r._2 ++ l._2))
.mergeSubstreams
Expand Down

0 comments on commit a5d9fed

Please sign in to comment.