From c1db0c5c064000bcf2b421eee241563872f8df00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20B=C3=BC=C3=9Femeyer?= Date: Thu, 28 Nov 2024 16:50:47 +0100 Subject: [PATCH] remove logging --- app/controllers/DatasetController.scala | 105 ++++++++++-------------- app/models/dataset/Dataset.scala | 14 ++-- 2 files changed, 47 insertions(+), 72 deletions(-) diff --git a/app/controllers/DatasetController.scala b/app/controllers/DatasetController.scala index 83009b13a6e..f7c600459db 100755 --- a/app/controllers/DatasetController.scala +++ b/app/controllers/DatasetController.scala @@ -176,79 +176,58 @@ class DatasetController @Inject()(userService: UserService, // Change output format to return only a compact list with essential information on the datasets compact: Option[Boolean] ): Action[AnyContent] = sil.UserAwareAction.async { implicit request => - log() { - for { - folderIdValidated <- Fox.runOptional(folderId)(ObjectId.fromString) - uploaderIdValidated <- Fox.runOptional(uploaderId)(ObjectId.fromString) - organizationIdOpt = if (onlyMyOrganization.getOrElse(false)) - request.identity.map(_._organization) - else - organizationId - js <- if (compact.getOrElse(false)) { - for { - datasetInfos <- datasetDAO.findAllCompactWithSearch( - isActive, - isUnreported, - organizationIdOpt, - folderIdValidated, - uploaderIdValidated, - searchQuery, - request.identity.map(_._id), - recursive.getOrElse(false), - limitOpt = limit - ) - } yield Json.toJson(datasetInfos) - } else { - for { - _ <- Fox.successful(()) - _ = logger.info( - s"Requesting listing datasets with isActive '$isActive', isUnreported '$isUnreported', organizationId '$organizationIdOpt', folderId '$folderIdValidated', uploaderId '$uploaderIdValidated', searchQuery '$searchQuery', recursive '$recursive', limit '$limit'") - datasets <- datasetDAO.findAllWithSearch(isActive, - isUnreported, - organizationIdOpt, - folderIdValidated, - uploaderIdValidated, - searchQuery, - recursive.getOrElse(false), - limit) ?~> "dataset.list.failed" ?~> "Dataset listing failed" - _ = logger.info(s"Found ${datasets.size} datasets successfully") - js <- listGrouped(datasets, request.identity) ?~> "dataset.list.failed" ?~> "Grouping datasets failed" - } yield Json.toJson(js) - } - _ = Fox.runOptional(request.identity)(user => userDAO.updateLastActivity(user._id)) - } yield addRemoteOriginHeaders(Ok(js)) - } + for { + folderIdValidated <- Fox.runOptional(folderId)(ObjectId.fromString) + uploaderIdValidated <- Fox.runOptional(uploaderId)(ObjectId.fromString) + organizationIdOpt = if (onlyMyOrganization.getOrElse(false)) + request.identity.map(_._organization) + else + organizationId + js <- if (compact.getOrElse(false)) { + for { + datasetInfos <- datasetDAO.findAllCompactWithSearch( + isActive, + isUnreported, + organizationIdOpt, + folderIdValidated, + uploaderIdValidated, + searchQuery, + request.identity.map(_._id), + recursive.getOrElse(false), + limitOpt = limit + ) + } yield Json.toJson(datasetInfos) + } else { + for { + datasets <- datasetDAO.findAllWithSearch(isActive, + isUnreported, + organizationIdOpt, + folderIdValidated, + uploaderIdValidated, + searchQuery, + recursive.getOrElse(false), + limit) ?~> "dataset.list.failed" + js <- listGrouped(datasets, request.identity) ?~> "dataset.list.failed" + } yield Json.toJson(js) + } + _ = Fox.runOptional(request.identity)(user => userDAO.updateLastActivity(user._id)) + } yield addRemoteOriginHeaders(Ok(js)) } private def listGrouped(datasets: List[Dataset], requestingUser: Option[User])( implicit ctx: DBAccessContext, m: MessagesProvider): Fox[List[JsObject]] = for { - _ <- Fox.successful(()) - _ = logger.info(s"datasets: $datasets, requestingUser: ${requestingUser.map(_._id)}") requestingUserTeamManagerMemberships <- Fox.runOptional(requestingUser)(user => - userService - .teamManagerMembershipsFor(user._id)) ?~> s"Could not find team manager memberships for user ${requestingUser - .map(_._id)}" - _ = logger.info( - s"requestingUserTeamManagerMemberships: ${requestingUserTeamManagerMemberships.map(_.map(_.toString))}") + userService.teamManagerMembershipsFor(user._id)) groupedByOrga = datasets.groupBy(_._organization).toList js <- Fox.serialCombined(groupedByOrga) { byOrgaTuple: (String, List[Dataset]) => for { - _ <- Fox.successful(()) - _ = logger.info(s"byOrgaTuple orga: ${byOrgaTuple._1}, datasets: ${byOrgaTuple._2}") - organization <- organizationDAO.findOne(byOrgaTuple._1) ?~> s"Could not find organization ${byOrgaTuple._1}" + organization <- organizationDAO.findOne(byOrgaTuple._1) groupedByDataStore = byOrgaTuple._2.groupBy(_._dataStore).toList - _ <- Fox.serialCombined(groupedByDataStore) { byDataStoreTuple: (String, List[Dataset]) => - { - logger.info(s"datastore: ${byDataStoreTuple._1}, datasets: ${byDataStoreTuple._2}") - Fox.successful(()) - } - } result <- Fox.serialCombined(groupedByDataStore) { byDataStoreTuple: (String, List[Dataset]) => for { - dataStore <- dataStoreDAO.findOneByName(byDataStoreTuple._1.trim)(GlobalAccessContext) ?~> - s"Could not find data store ${byDataStoreTuple._1}" + dataStore <- dataStoreDAO.findOneByName(byDataStoreTuple._1.trim)(GlobalAccessContext) resultByDataStore: Seq[JsObject] <- Fox.serialCombined(byDataStoreTuple._2) { d => datasetService.publicWrites( d, @@ -256,11 +235,11 @@ class DatasetController @Inject()(userService: UserService, Some(organization), Some(dataStore), requestingUserTeamManagerMemberships) ?~> Messages("dataset.list.writesFailed", d.name) - } ?~> "Could not find public writes for datasets" + } } yield resultByDataStore - } ?~> s"Could not group by datastore for datasets ${byOrgaTuple._2.map(_._id)}" + } } yield result.flatten - } ?~> s"Could not group by organization for datasets ${datasets.map(_._id)}" + } } yield js.flatten def accessList(datasetId: String): Action[AnyContent] = sil.SecuredAction.async { implicit request => diff --git a/app/models/dataset/Dataset.scala b/app/models/dataset/Dataset.scala index bb6feade662..ebfa63387a1 100755 --- a/app/models/dataset/Dataset.scala +++ b/app/models/dataset/Dataset.scala @@ -115,14 +115,12 @@ class DatasetDAO @Inject()(sqlClient: SqlClient, datasetLayerDAO: DatasetLayerDA protected def parse(r: DatasetsRow): Fox[Dataset] = for { - voxelSize <- parseVoxelSizeOpt(r.voxelsizefactor, r.voxelsizeunit) ?~> "could not parse dataset voxel size" + voxelSize <- parseVoxelSizeOpt(r.voxelsizefactor, r.voxelsizeunit) defaultViewConfigurationOpt <- Fox.runOptional(r.defaultviewconfiguration)( - JsonHelper - .parseAndValidateJson[DatasetViewConfiguration](_)) ?~> "could not parse dataset default view configuration" + JsonHelper.parseAndValidateJson[DatasetViewConfiguration](_)) adminViewConfigurationOpt <- Fox.runOptional(r.adminviewconfiguration)( - JsonHelper - .parseAndValidateJson[DatasetViewConfiguration](_)) ?~> "could not parse dataset admin view configuration" - metadata <- JsonHelper.parseAndValidateJson[JsArray](r.metadata) ?~> "could not parse dataset metadata" + JsonHelper.parseAndValidateJson[DatasetViewConfiguration](_)) + metadata <- JsonHelper.parseAndValidateJson[JsArray](r.metadata) } yield { Dataset( ObjectId(r._Id), @@ -220,11 +218,9 @@ class DatasetDAO @Inject()(sqlClient: SqlClient, datasetLayerDAO: DatasetLayerDA includeSubfolders, None, None) - _ = logger.info(s"Requesting datasets with selection predicates '$selectionPredicates'") limitQuery = limitOpt.map(l => q"LIMIT $l").getOrElse(q"") - _ = logger.info("Requesting datasets with query") r <- run(q"SELECT $columns FROM $existingCollectionName WHERE $selectionPredicates $limitQuery".as[DatasetsRow]) - parsed <- parseAll(r) ?~> "Parsing datasets failed" + parsed <- parseAll(r) } yield parsed def findAllCompactWithSearch(isActiveOpt: Option[Boolean] = None,