@@ -29,15 +29,15 @@ import models.team.TeamDAO
29
29
import models .user .{MultiUserDAO , User , UserDAO , UserService }
30
30
import net .liftweb .common .Full
31
31
import play .api .i18n .{Messages , MessagesProvider }
32
- import play .api .libs .json .{ JsError , JsSuccess , JsValue , Json }
32
+ import play .api .libs .json .Json
33
33
import play .api .mvc .{Action , AnyContent , PlayBodyParsers }
34
34
import security .{WebknossosBearerTokenAuthenticatorService , WkSilhouetteEnvironment }
35
35
import telemetry .SlackNotificationService
36
36
import utils .WkConf
37
37
38
38
import scala .concurrent .duration .DurationInt
39
39
import javax .inject .Inject
40
- import scala .concurrent .{ ExecutionContext , Future }
40
+ import scala .concurrent .ExecutionContext
41
41
42
42
class WKRemoteDataStoreController @ Inject ()(
43
43
datasetService : DatasetService ,
@@ -175,21 +175,17 @@ class WKRemoteDataStoreController @Inject()(
175
175
s " For organization: ${organization.name}. < $resultLink|Result> " )
176
176
} yield ()
177
177
178
- def statusUpdate (name : String , key : String ): Action [JsValue ] = Action .async(parse.json) { implicit request =>
179
- dataStoreService.validateAccess(name, key) { _ =>
180
- request.body.validate[DataStoreStatus ] match {
181
- case JsSuccess (status, _) =>
182
- logger.debug(s " Status update from data store ' $name'. Status: " + status.ok)
183
- for {
184
- _ <- dataStoreDAO.updateUrlByName(name, status.url)
185
- _ <- dataStoreDAO.updateReportUsedStorageEnabledByName(name,
186
- status.reportUsedStorageEnabled.getOrElse(false ))
187
- } yield Ok
188
- case e : JsError =>
189
- logger.error(" Data store '$name' sent invalid update. Error: " + e)
190
- Future .successful(JsonBadRequest (JsError .toJson(e)))
178
+ def statusUpdate (name : String , key : String ): Action [DataStoreStatus ] = Action .async(validateJson[DataStoreStatus ]) {
179
+ implicit request =>
180
+ dataStoreService.validateAccess(name, key) { _ =>
181
+ val okLabel = if (request.body.ok) " ok" else " not ok"
182
+ logger.debug(s " Status update from data store ' $name'. Status $okLabel" )
183
+ for {
184
+ _ <- dataStoreDAO.updateUrlByName(name, request.body.url)
185
+ _ <- dataStoreDAO.updateReportUsedStorageEnabledByName(name,
186
+ request.body.reportUsedStorageEnabled.getOrElse(false ))
187
+ } yield Ok
191
188
}
192
- }
193
189
}
194
190
195
191
def updateAll (name : String , key : String ): Action [List [InboxDataSource ]] =
@@ -209,37 +205,23 @@ class WKRemoteDataStoreController @Inject()(
209
205
}
210
206
}
211
207
212
- def updateOne (name : String , key : String ): Action [JsValue ] = Action .async(parse.json) { implicit request =>
213
- dataStoreService.validateAccess(name, key) { dataStore =>
214
- request.body.validate[InboxDataSource ] match {
215
- case JsSuccess (dataSource, _) =>
216
- for {
217
- _ <- datasetService.updateDataSources(dataStore, List (dataSource))(GlobalAccessContext )
218
- } yield {
219
- JsonOk
220
- }
221
- case e : JsError =>
222
- logger.warn(" Data store reported invalid json for data source." )
223
- Fox .successful(JsonBadRequest (JsError .toJson(e)))
208
+ def updateOne (name : String , key : String ): Action [InboxDataSource ] =
209
+ Action .async(validateJson[InboxDataSource ]) { implicit request =>
210
+ dataStoreService.validateAccess(name, key) { dataStore =>
211
+ for {
212
+ _ <- datasetService.updateDataSources(dataStore, List (request.body))(GlobalAccessContext )
213
+ } yield Ok
224
214
}
225
215
}
226
- }
227
216
228
- def updatePaths (name : String , key : String ): Action [JsValue ] = Action .async(parse.json) { implicit request =>
229
- dataStoreService.validateAccess(name, key) { _ =>
230
- request.body.validate[List [DataSourcePathInfo ]] match {
231
- case JsSuccess (infos, _) =>
232
- for {
233
- _ <- datasetService.updateRealPaths(infos)(GlobalAccessContext )
234
- } yield {
235
- JsonOk
236
- }
237
- case e : JsError =>
238
- logger.warn(" Data store reported invalid json for data source paths." )
239
- Fox .successful(JsonBadRequest (JsError .toJson(e)))
217
+ def updatePaths (name : String , key : String ): Action [List [DataSourcePathInfo ]] =
218
+ Action .async(validateJson[List [DataSourcePathInfo ]]) { implicit request =>
219
+ dataStoreService.validateAccess(name, key) { _ =>
220
+ for {
221
+ _ <- datasetService.updateRealPaths(request.body)(GlobalAccessContext )
222
+ } yield Ok
240
223
}
241
224
}
242
- }
243
225
244
226
def deleteDataset (name : String , key : String ): Action [DataSourceId ] = Action .async(validateJson[DataSourceId ]) {
245
227
implicit request =>
0 commit comments