Skip to content

Commit

Permalink
#1635 Add more handling duration properties
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Nov 10, 2020
1 parent 5e5ed04 commit 37f03d6
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 2 deletions.
49 changes: 47 additions & 2 deletions thehive/app/org/thp/thehive/controllers/v0/CaseCtrl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -338,9 +338,24 @@ class PublicCase @Inject() (
} yield Json.obj("customFields" -> values)
case _ => Failure(BadRequestError("Invalid custom fields format"))
})
.property("computed.handlingDurationInDays", UMapping.long)(
_.select(
_.coalesceIdent(
_.has(_.endDate)
.sack(
(_: JLong, endDate: JLong) => endDate,
_.by(_.value(_.endDate).graphMap[Long, JLong, Converter[Long, JLong]](_.getTime, Converter.long))
)
.sack((_: Long) - (_: JLong), _.by(_.value(_.startDate).graphMap[Long, JLong, Converter[Long, JLong]](_.getTime, Converter.long)))
.sack((_: Long) / (_: Long), _.by(_.constant(86400000L)))
.sack[Long],
_.constant(0L)
)
).readonly
)
.property("computed.handlingDurationInHours", UMapping.long)(
_.select(
_.coalesce(
_.coalesceIdent(
_.has(_.endDate)
.sack(
(_: JLong, endDate: JLong) => endDate,
Expand All @@ -349,7 +364,37 @@ class PublicCase @Inject() (
.sack((_: Long) - (_: JLong), _.by(_.value(_.startDate).graphMap[Long, JLong, Converter[Long, JLong]](_.getTime, Converter.long)))
.sack((_: Long) / (_: Long), _.by(_.constant(3600000L)))
.sack[Long],
0L
_.constant(0L)
)
).readonly
)
.property("computed.handlingDurationInMinutes", UMapping.long)(
_.select(
_.coalesceIdent(
_.has(_.endDate)
.sack(
(_: JLong, endDate: JLong) => endDate,
_.by(_.value(_.endDate).graphMap[Long, JLong, Converter[Long, JLong]](_.getTime, Converter.long))
)
.sack((_: Long) - (_: JLong), _.by(_.value(_.startDate).graphMap[Long, JLong, Converter[Long, JLong]](_.getTime, Converter.long)))
.sack((_: Long) / (_: Long), _.by(_.constant(60000L)))
.sack[Long],
_.constant(0L)
)
).readonly
)
.property("computed.handlingDurationInSeconds", UMapping.long)(
_.select(
_.coalesceIdent(
_.has(_.endDate)
.sack(
(_: JLong, endDate: JLong) => endDate,
_.by(_.value(_.endDate).graphMap[Long, JLong, Converter[Long, JLong]](_.getTime, Converter.long))
)
.sack((_: Long) - (_: JLong), _.by(_.value(_.startDate).graphMap[Long, JLong, Converter[Long, JLong]](_.getTime, Converter.long)))
.sack((_: Long) / (_: Long), _.by(_.constant(1000L)))
.sack[Long],
_.constant(0L)
)
).readonly
)
Expand Down
68 changes: 68 additions & 0 deletions thehive/app/org/thp/thehive/controllers/v1/Properties.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.thp.thehive.controllers.v1

import java.lang.{Long => JLong}
import java.util.Date

import javax.inject.{Inject, Named, Singleton}
Expand All @@ -18,6 +19,7 @@ import org.thp.thehive.services.CaseTemplateOps._
import org.thp.thehive.services.CustomFieldOps._
import org.thp.thehive.services.LogOps._
import org.thp.thehive.services.ObservableOps._
import org.thp.thehive.services.OrganisationOps._
import org.thp.thehive.services.TagOps._
import org.thp.thehive.services.TaskOps._
import org.thp.thehive.services.UserOps._
Expand Down Expand Up @@ -233,6 +235,72 @@ class Properties @Inject() (
} yield Json.obj("customFields" -> values)
case _ => Failure(BadRequestError("Invalid custom fields format"))
})
.property("computed.handlingDurationInDays", UMapping.long)(
_.select(
_.coalesceIdent(
_.has(_.endDate)
.sack(
(_: JLong, endDate: JLong) => endDate,
_.by(_.value(_.endDate).graphMap[Long, JLong, Converter[Long, JLong]](_.getTime, Converter.long))
)
.sack((_: Long) - (_: JLong), _.by(_.value(_.startDate).graphMap[Long, JLong, Converter[Long, JLong]](_.getTime, Converter.long)))
.sack((_: Long) / (_: Long), _.by(_.constant(86400000L)))
.sack[Long],
_.constant(0L)
)
).readonly
)
.property("computed.handlingDurationInHours", UMapping.long)(
_.select(
_.coalesceIdent(
_.has(_.endDate)
.sack(
(_: JLong, endDate: JLong) => endDate,
_.by(_.value(_.endDate).graphMap[Long, JLong, Converter[Long, JLong]](_.getTime, Converter.long))
)
.sack((_: Long) - (_: JLong), _.by(_.value(_.startDate).graphMap[Long, JLong, Converter[Long, JLong]](_.getTime, Converter.long)))
.sack((_: Long) / (_: Long), _.by(_.constant(3600000L)))
.sack[Long],
_.constant(0L)
)
).readonly
)
.property("computed.handlingDurationInMinutes", UMapping.long)(
_.select(
_.coalesceIdent(
_.has(_.endDate)
.sack(
(_: JLong, endDate: JLong) => endDate,
_.by(_.value(_.endDate).graphMap[Long, JLong, Converter[Long, JLong]](_.getTime, Converter.long))
)
.sack((_: Long) - (_: JLong), _.by(_.value(_.startDate).graphMap[Long, JLong, Converter[Long, JLong]](_.getTime, Converter.long)))
.sack((_: Long) / (_: Long), _.by(_.constant(60000L)))
.sack[Long],
_.constant(0L)
)
).readonly
)
.property("computed.handlingDurationInSeconds", UMapping.long)(
_.select(
_.coalesceIdent(
_.has(_.endDate)
.sack(
(_: JLong, endDate: JLong) => endDate,
_.by(_.value(_.endDate).graphMap[Long, JLong, Converter[Long, JLong]](_.getTime, Converter.long))
)
.sack((_: Long) - (_: JLong), _.by(_.value(_.startDate).graphMap[Long, JLong, Converter[Long, JLong]](_.getTime, Converter.long)))
.sack((_: Long) / (_: Long), _.by(_.constant(1000L)))
.sack[Long],
_.constant(0L)
)
).readonly
)
.property("viewingOrganisation", UMapping.string)(
_.authSelect((cases, authContext) => cases.organisations.visible(authContext).value(_.name)).readonly
)
.property("owningOrganisation", UMapping.string)(
_.authSelect((cases, authContext) => cases.origin.visible(authContext).value(_.name)).readonly
)
.build

lazy val caseTemplate: PublicProperties =
Expand Down

0 comments on commit 37f03d6

Please sign in to comment.