@@ -15,7 +15,7 @@ import org.elastic4play.services.JsonFormat.queryReads
15
15
import org .elastic4play .services .{QueryDSL , QueryDef }
16
16
17
17
@ Singleton
18
- class AnalyzerCtrl @ Inject ()(
18
+ class AnalyzerCtrl @ Inject () (
19
19
workerSrv : WorkerSrv ,
20
20
userSrv : UserSrv ,
21
21
authenticated : Authenticated ,
@@ -26,7 +26,7 @@ class AnalyzerCtrl @Inject()(
26
26
implicit val mat : Materializer
27
27
) extends AbstractController (components) {
28
28
29
- def find : Action [Fields ] = authenticated(Roles .read).async(fieldsBodyParser) { request ⇒
29
+ def find : Action [Fields ] = authenticated(Roles .read).async(fieldsBodyParser) { request =>
30
30
val query = request.body.getValue(" query" ).fold[QueryDef ](QueryDSL .any)(_.as[QueryDef ])
31
31
val range = request.body.getString(" range" )
32
32
val sort = request.body.getStrings(" sort" ).getOrElse(Nil )
@@ -35,54 +35,54 @@ class AnalyzerCtrl @Inject()(
35
35
renderer.toOutput(OK , analyzers.map(analyzerJson(isAdmin)), analyzerTotal)
36
36
}
37
37
38
- def get (analyzerId : String ): Action [AnyContent ] = authenticated(Roles .read).async { request ⇒
38
+ def get (analyzerId : String ): Action [AnyContent ] = authenticated(Roles .read).async { request =>
39
39
val isAdmin = request.roles.contains(Roles .orgAdmin)
40
40
workerSrv
41
41
.getForUser(request.userId, analyzerId)
42
- .map(a ⇒ renderer.toOutput(OK , analyzerJson(isAdmin)(a)))
42
+ .map(a => renderer.toOutput(OK , analyzerJson(isAdmin)(a)))
43
43
}
44
44
45
45
private def analyzerJson (isAdmin : Boolean )(analyzer : Worker ): JsObject =
46
46
if (isAdmin)
47
- analyzer.toJson + (" configuration" → Json .parse(analyzer.configuration())) + (" analyzerDefinitionId" → JsString (analyzer.workerDefinitionId()))
47
+ analyzer.toJson + (" configuration" -> Json .parse(analyzer.configuration())) + (" analyzerDefinitionId" -> JsString (analyzer.workerDefinitionId()))
48
48
else
49
- analyzer.toJson + (" analyzerDefinitionId" → JsString (analyzer.workerDefinitionId()))
49
+ analyzer.toJson + (" analyzerDefinitionId" -> JsString (analyzer.workerDefinitionId()))
50
50
51
- def listForType (dataType : String ): Action [AnyContent ] = authenticated(Roles .read).async { request ⇒
51
+ def listForType (dataType : String ): Action [AnyContent ] = authenticated(Roles .read).async { request =>
52
52
import org .elastic4play .services .QueryDSL ._
53
53
val (responderList, responderCount) = workerSrv.findAnalyzersForUser(request.userId, " dataTypeList" ~= dataType, Some (" all" ), Nil )
54
54
renderer.toOutput(OK , responderList.map(analyzerJson(isAdmin = false )), responderCount)
55
55
}
56
56
57
- def create (analyzerDefinitionId : String ): Action [Fields ] = authenticated(Roles .orgAdmin).async(fieldsBodyParser) { implicit request ⇒
57
+ def create (analyzerDefinitionId : String ): Action [Fields ] = authenticated(Roles .orgAdmin).async(fieldsBodyParser) { implicit request =>
58
58
for {
59
- organizationId ← userSrv.getOrganizationId(request.userId)
60
- workerDefinition ← Future .fromTry(workerSrv.getDefinition(analyzerDefinitionId))
61
- analyzer ← workerSrv.create(organizationId, workerDefinition, request.body)
59
+ organizationId <- userSrv.getOrganizationId(request.userId)
60
+ workerDefinition <- Future .fromTry(workerSrv.getDefinition(analyzerDefinitionId))
61
+ analyzer <- workerSrv.create(organizationId, workerDefinition, request.body)
62
62
} yield renderer.toOutput(CREATED , analyzerJson(isAdmin = false )(analyzer))
63
63
}
64
64
65
- def listDefinitions : Action [AnyContent ] = authenticated(Roles .orgAdmin, Roles .superAdmin).async { _ ⇒
65
+ def listDefinitions : Action [AnyContent ] = authenticated(Roles .orgAdmin, Roles .superAdmin).async { _ =>
66
66
val (analyzers, analyzerTotal) = workerSrv.listAnalyzerDefinitions
67
67
renderer.toOutput(OK , analyzers, analyzerTotal)
68
68
}
69
69
70
- def scan : Action [AnyContent ] = authenticated(Roles .orgAdmin, Roles .superAdmin) { _ ⇒
70
+ def scan : Action [AnyContent ] = authenticated(Roles .orgAdmin, Roles .superAdmin) { _ =>
71
71
workerSrv.rescan()
72
72
NoContent
73
73
}
74
74
75
- def delete (analyzerId : String ): Action [AnyContent ] = authenticated(Roles .orgAdmin, Roles .superAdmin).async { implicit request ⇒
75
+ def delete (analyzerId : String ): Action [AnyContent ] = authenticated(Roles .orgAdmin, Roles .superAdmin).async { implicit request =>
76
76
for {
77
- analyzer ← workerSrv.getForUser(request.userId, analyzerId)
78
- _ ← workerSrv.delete(analyzer)
77
+ analyzer <- workerSrv.getForUser(request.userId, analyzerId)
78
+ _ <- workerSrv.delete(analyzer)
79
79
} yield NoContent
80
80
}
81
81
82
- def update (analyzerId : String ): Action [Fields ] = authenticated(Roles .orgAdmin).async(fieldsBodyParser) { implicit request ⇒
82
+ def update (analyzerId : String ): Action [Fields ] = authenticated(Roles .orgAdmin).async(fieldsBodyParser) { implicit request =>
83
83
for {
84
- analyzer ← workerSrv.getForUser(request.userId, analyzerId)
85
- updatedAnalyzer ← workerSrv.update(analyzer, request.body)
84
+ analyzer <- workerSrv.getForUser(request.userId, analyzerId)
85
+ updatedAnalyzer <- workerSrv.update(analyzer, request.body)
86
86
} yield renderer.toOutput(OK , analyzerJson(isAdmin = true )(updatedAnalyzer))
87
87
}
88
88
}
0 commit comments