-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#53 Add API to import a bundle of report templates
- Loading branch information
To-om
committed
Dec 7, 2016
1 parent
5737f98
commit 065ba3d
Showing
8 changed files
with
102 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 26 additions & 5 deletions
31
thehive-cortex/app/connectors/cortex/models/ReportTemplate.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,38 @@ | ||
package models | ||
package connectors.cortex.models | ||
|
||
import javax.inject.{ Inject, Singleton } | ||
|
||
import play.api.libs.json.JsObject | ||
|
||
import org.elastic4play.models.{ AttributeDef, AttributeFormat ⇒ F, EntityDef, ModelDef } | ||
import org.elastic4play.models.{ AttributeDef, AttributeFormat ⇒ F, AttributeOption ⇒ O, EntityDef, ModelDef } | ||
import org.elastic4play.BadRequestError | ||
import org.elastic4play.models.BaseEntity | ||
import play.api.libs.json.JsString | ||
import scala.concurrent.Future | ||
import org.elastic4play.models.HiveEnumeration | ||
|
||
import JsonFormat._ | ||
|
||
object ReportType extends Enumeration with HiveEnumeration { | ||
type Type = Value | ||
val short, long = Value | ||
} | ||
|
||
trait ReportTemplateAttributes { _: AttributeDef ⇒ | ||
val reportTemplateId = attribute("_id", F.stringFmt, "Report template id", O.model) | ||
val content = attribute("content", F.textFmt, "Content of the template") | ||
val falvor = attribute("flavor", F.stringFmt, "Flavor of the report (short or long)") | ||
val analyzers = multiAttribute("analyzers", F.stringFmt, "Id of analyzers") | ||
val flavor = attribute("flavor", F.enumFmt(ReportType), "Flavor of the report (short or long)") | ||
val analyzers = attribute("analyzers", F.stringFmt, "Id of analyzers") | ||
} | ||
|
||
@Singleton | ||
class ReportTemplateModel @Inject() extends ModelDef[ReportTemplateModel, ReportTemplate]("reportTemplate") with ReportTemplateAttributes | ||
class ReportTemplateModel @Inject() extends ModelDef[ReportTemplateModel, ReportTemplate]("reportTemplate") with ReportTemplateAttributes { | ||
override def creationHook(parent: Option[BaseEntity], attrs: JsObject) = { | ||
val maybeId = for { | ||
analyzers ← (attrs \ "analyzers").asOpt[String] | ||
flavor ← (attrs \ "flavor").asOpt[String] | ||
} yield analyzers + "_" + flavor | ||
Future.successful(maybeId.fold(attrs)(id ⇒ attrs + ("_id" → JsString(id)))) | ||
} | ||
} | ||
class ReportTemplate(model: ReportTemplateModel, attributes: JsObject) extends EntityDef[ReportTemplateModel, ReportTemplate](model, attributes) with ReportTemplateAttributes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters