From f961fe1b6a28c14fc891a2eb606e0eb5195ebfb7 Mon Sep 17 00:00:00 2001 From: Robin Riclet Date: Fri, 6 Nov 2020 13:59:21 +0100 Subject: [PATCH] #1552 Renamed val & used contains() --- .../app/org/thp/thehive/services/AlertSrv.scala | 16 ++++++++-------- .../app/org/thp/thehive/services/CaseSrv.scala | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/thehive/app/org/thp/thehive/services/AlertSrv.scala b/thehive/app/org/thp/thehive/services/AlertSrv.scala index c45a656ee6..f665692ecc 100644 --- a/thehive/app/org/thp/thehive/services/AlertSrv.scala +++ b/thehive/app/org/thp/thehive/services/AlertSrv.scala @@ -83,7 +83,7 @@ class AlertSrv @Inject() ( _ <- alertOrganisationSrv.create(AlertOrganisation(), createdAlert, organisation) _ <- caseTemplate.map(ct => alertCaseTemplateSrv.create(AlertCaseTemplate(), createdAlert, ct)).flip _ <- tags.toTry(t => alertTagSrv.create(AlertTag(), createdAlert, t)) - cfs <- customFields.toTry { simpleCf: InputCustomFieldValue => createCustomField(createdAlert, simpleCf) } + cfs <- customFields.toTry { cf: InputCustomFieldValue => createCustomField(createdAlert, cf) } richAlert = RichAlert(createdAlert, organisation.name, tags, cfs, None, caseTemplate.map(_.name), 0) _ <- auditSrv.alert.create(createdAlert, richAlert.toJson) } yield richAlert @@ -171,23 +171,23 @@ class AlertSrv @Inject() ( def createCustomField( alert: Alert with Entity, - simpleCf: InputCustomFieldValue + inputCf: InputCustomFieldValue )(implicit graph: Graph, authContext: AuthContext): Try[RichCustomField] = for { - cf <- customFieldSrv.getOrFail(EntityIdOrName(simpleCf.name)) - ccf <- CustomFieldType.map(cf.`type`).setValue(AlertCustomField(), simpleCf.value).map(_.order_=(simpleCf.order)) + cf <- customFieldSrv.getOrFail(EntityIdOrName(inputCf.name)) + ccf <- CustomFieldType.map(cf.`type`).setValue(AlertCustomField(), inputCf.value).map(_.order_=(inputCf.order)) ccfe <- alertCustomFieldSrv.create(ccf, alert, cf) } yield RichCustomField(cf, ccfe) - def setOrCreateCustomField(alert: Alert with Entity, simpleCf: InputCustomFieldValue)(implicit + def setOrCreateCustomField(alert: Alert with Entity, cf: InputCustomFieldValue)(implicit graph: Graph, authContext: AuthContext ): Try[Unit] = { - val cfv = get(alert).customFields(simpleCf.name) + val cfv = get(alert).customFields(cf.name) if (cfv.clone().exists) - cfv.setValue(simpleCf.value) + cfv.setValue(cf.value) else - createCustomField(alert, simpleCf).map(_ => ()) + createCustomField(alert, cf).map(_ => ()) } def getCustomField(alert: Alert with Entity, customFieldName: String)(implicit graph: Graph): Option[RichCustomField] = diff --git a/thehive/app/org/thp/thehive/services/CaseSrv.scala b/thehive/app/org/thp/thehive/services/CaseSrv.scala index 84123daa92..dfcc74af4c 100644 --- a/thehive/app/org/thp/thehive/services/CaseSrv.scala +++ b/thehive/app/org/thp/thehive/services/CaseSrv.scala @@ -96,7 +96,7 @@ class CaseSrv @Inject() ( private def cleanCustomFields(caseTemplateCf: Seq[InputCustomFieldValue], caseCf: Seq[InputCustomFieldValue]): Seq[InputCustomFieldValue] = { val uniqueFields = caseTemplateCf.filter { - case InputCustomFieldValue(name, _, _) => !caseCf.map(c => c.name).contains(name) + case InputCustomFieldValue(name, _, _) => !caseCf.exists(_.name == name) } (caseCf ++ uniqueFields) .sortBy(cf => (cf.order.isEmpty, cf.order))