diff --git a/thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala b/thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala index e88f443fdd..fc8c340add 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/CaseCtrl.scala @@ -65,7 +65,7 @@ class CaseCtrl @Inject() ( Query.init[Long]( "countCase", (graph, authContext) => - graph.indexCountQuery(s"""v."_label":Case AND v.organisationIds:${organisationSrv.currentId(graph, authContext).value} """) + graph.indexCountQuery(s"""v."_label":Case AND v.organisationIds:${organisationSrv.currentId(graph, authContext).value}""") ), Query[Traversal.V[Case], Traversal.V[Observable]]( "observables", diff --git a/thehive/app/org/thp/thehive/controllers/v1/CaseRenderer.scala b/thehive/app/org/thp/thehive/controllers/v1/CaseRenderer.scala index 1fb00388e0..def02c9dc0 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/CaseRenderer.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/CaseRenderer.scala @@ -17,11 +17,15 @@ import java.util.{Collection => JCollection, List => JList, Map => JMap} trait CaseRenderer extends BaseRenderer[Case] { val limitedCountThreshold: Long - def observableStats(implicit authContext: AuthContext): Traversal.V[Case] => Traversal[JsValue, JLong, Converter[JsValue, JLong]] = - _.share - .observables - .limitedCount(limitedCountThreshold) - .domainMap(count => Json.obj("total" -> count)) + def observableStats(implicit authContext: AuthContext): Traversal.V[Case] => Traversal[JsObject, AnyRef, Converter[JsObject, AnyRef]] = + t => + t._id.domainMap { caseId => + Json.obj("total" -> t.graph.indexCountQuery(s"""v."_label":Case AND v.relatedId:${caseId.value}""")) + } +// _.share +// .observables +// .limitedCount(limitedCountThreshold) +// .domainMap(count => Json.obj("total" -> count)) def taskStats(implicit authContext: AuthContext diff --git a/thehive/app/org/thp/thehive/controllers/v1/TagRenderer.scala b/thehive/app/org/thp/thehive/controllers/v1/TagRenderer.scala index 489887c737..31246eb65a 100644 --- a/thehive/app/org/thp/thehive/controllers/v1/TagRenderer.scala +++ b/thehive/app/org/thp/thehive/controllers/v1/TagRenderer.scala @@ -15,20 +15,36 @@ trait TagRenderer extends BaseRenderer[Tag] { def usageStats(implicit authContext: AuthContext ): Traversal.V[Tag] => Traversal[JsObject, JMap[String, Any], Converter[JsObject, JMap[String, Any]]] = - _.project( - _.by(_.`case`.limitedCount(limitedCountThreshold)) - .by(_.alert.limitedCount(limitedCountThreshold)) - .by(_.observable.limitedCount(limitedCountThreshold)) - .by(_.caseTemplate.limitedCount(limitedCountThreshold)) - ).domainMap { - case (caseCount, alertCount, observableCount, caseTemplateCount) => - Json.obj( - "case" -> caseCount, - "alert" -> alertCount, - "observable" -> observableCount, - "caseTemplate" -> caseTemplateCount - ) - } + t => + t.project( + _.by(_.value(_.predicate)) + .by(_.caseTemplate.limitedCount(limitedCountThreshold)) + ).domainMap { + case (tag, caseTemplateCount) => + Json.obj( + "case" -> t.graph.indexCountQuery(s"""v."_label":Case AND v.tags:"${tag.replaceAllLiterally("\"", "\\\"")}""""), + "alert" -> t.graph.indexCountQuery(s"""v."_label":Alert AND v.tags:"${tag.replaceAllLiterally("\"", "\\\"")}""""), + "observable" -> t.graph.indexCountQuery(s"""v."_label":Observable AND v.tags:"${tag.replaceAllLiterally("\"", "\\\"")}""""), + "caseTemplate" -> caseTemplateCount + ) + } +// def usageStats(implicit +// authContext: AuthContext +// ): Traversal.V[Tag] => Traversal[JsObject, JMap[String, Any], Converter[JsObject, JMap[String, Any]]] = +// _.project( +// _.by(_.`case`.limitedCount(limitedCountThreshold)) +// .by(_.alert.limitedCount(limitedCountThreshold)) +// .by(_.observable.limitedCount(limitedCountThreshold)) +// .by(_.caseTemplate.limitedCount(limitedCountThreshold)) +// ).domainMap { +// case (caseCount, alertCount, observableCount, caseTemplateCount) => +// Json.obj( +// "case" -> caseCount, +// "alert" -> alertCount, +// "observable" -> observableCount, +// "caseTemplate" -> caseTemplateCount +// ) +// } def tagStatsRenderer(extraData: Set[String])(implicit authContext: AuthContext