From 3fdff62e50799fd02b78086887cdfdb0cb840e2d Mon Sep 17 00:00:00 2001 From: eletallbetagouv <107104509+eletallbetagouv@users.noreply.github.com> Date: Wed, 11 Sep 2024 09:48:53 +0200 Subject: [PATCH] Remove all temporary code to fill department column --- app/controllers/EtablissementController.scala | 16 -------- .../EtablissementImportService.scala | 39 ------------------- .../insee/EtablissementRepository.scala | 18 --------- .../EtablissementRepositoryInterface.scala | 3 -- conf/routes | 2 - ...EtablissementRepositoryInterfaceMock.scala | 4 -- 6 files changed, 82 deletions(-) diff --git a/app/controllers/EtablissementController.scala b/app/controllers/EtablissementController.scala index 241c243..39dfa66 100644 --- a/app/controllers/EtablissementController.scala +++ b/app/controllers/EtablissementController.scala @@ -124,22 +124,6 @@ class EtablissementController( res.recover { case err => handleError(request, err) } } - def fillDepartementWithLimit() = Action.async { request => - val res = for { - _ <- validateToken(request, token) - _ <- importService.fillDepartmentWithLimit() - } yield NoContent - res.recover { case err => handleError(request, err) } - } - - def fillDepartementUntilAllDone() = Action.async { request => - val res = for { - _ <- validateToken(request, token) - _ <- importService.fillDepartementUntilAllDone() - } yield NoContent - res.recover { case err => handleError(request, err) } - } - } object EtablissementController { diff --git a/app/orchestrators/EtablissementImportService.scala b/app/orchestrators/EtablissementImportService.scala index 0898d64..6237935 100644 --- a/app/orchestrators/EtablissementImportService.scala +++ b/app/orchestrators/EtablissementImportService.scala @@ -35,45 +35,6 @@ class EtablissementImportService( private[this] val logger = Logger(this.getClass) - // This fill the department column for every etablissement that still doesn't have it - // We should only need to use this once, can be deleted after - - // Note : rows for which the department code can't be found (should be really rare) - // are just ignored, but are then queried again by the next iteration. - // It could be a problem if there are too many of them, for now we just try like that. - def fillDepartementUntilAllDone(): Future[Unit] = - for { - rowsProcessed <- fillDepartmentWithLimit() - _ <- - if (rowsProcessed == 0) { - logger.info("All etablissements filled with departments ") - Future.successful(()) - } else { - fillDepartementUntilAllDone() - } - } yield () - - def fillDepartmentWithLimit(): Future[Int] = - for { - allCommunes <- geoApiClient.getAllCommunes() - etablissements <- repository.listWithoutMissingDepartment(1000) - _ = logger.info(s"Filling codeDepartement for ${etablissements.length} etablissements") - rowsSuccess <- etablissements.foldLeft(Future.successful(0)) { case (previous, etab) => - for { - previousCount <- previous - maybeCodeDepartment = Departments.findCodeDepartementOfEtablissement(Right(etab), allCommunes) - rowsUpdatedSuccessfully <- maybeCodeDepartment match { - case Some(codeDepartement) => - repository.updateDepartment(etab.siret, codeDepartement) - case None => - logger.warn(s"Can't find departement of ${etab.siret} (CP ${etab.codePostalEtablissement})") - Future.successful(0) - } - } yield previousCount + rowsUpdatedSuccessfully - } - _ = logger.info(s"Filled codeDepartement for $rowsSuccess/${etablissements.length} etablissements") - } yield etablissements.length - // One shot, API def runImportEtablissementsRequest(importRequest: ImportRequest): Future[Unit] = for { diff --git a/app/repositories/insee/EtablissementRepository.scala b/app/repositories/insee/EtablissementRepository.scala index 8c1e508..eb2db30 100644 --- a/app/repositories/insee/EtablissementRepository.scala +++ b/app/repositories/insee/EtablissementRepository.scala @@ -48,14 +48,6 @@ class EtablissementRepository(val dbConfig: DatabaseConfig[JdbcProfile], conf: S """) } - override def updateDepartment(siret: SIRET, codeDepartment: String): Future[Int] = - db.run( - table - .filter(_.siret === siret) - .map(a => a.codeDepartement) - .update(Some(codeDepartment)) - ) - // Be careful when modifying this search, the order is important to use PG Indexes correctly. // Check the generated query with an EXPLAIN if necessary. override def search( @@ -159,16 +151,6 @@ class EtablissementRepository(val dbConfig: DatabaseConfig[JdbcProfile], conf: S .result ).map(_.headOption) - override def listWithoutMissingDepartment(limit: Int): Future[Seq[EtablissementData]] = - db.run( - table - .filter(_.codeDepartement.isEmpty) - .filter(_.codePostalEtablissement.isDefined) - .filter(_.codePaysEtrangerEtablissement.isEmpty) - .filter(_.libellePaysEtrangerEtablissement.isEmpty) - .take(limit) - .result - ) } object EtablissementRepository { diff --git a/app/repositories/insee/EtablissementRepositoryInterface.scala b/app/repositories/insee/EtablissementRepositoryInterface.scala index 1d5c43a..7a991c5 100644 --- a/app/repositories/insee/EtablissementRepositoryInterface.scala +++ b/app/repositories/insee/EtablissementRepositoryInterface.scala @@ -11,8 +11,6 @@ trait EtablissementRepositoryInterface { def insertOrUpdate(companies: Map[String, Option[String]]): Future[Int] - def updateDepartment(siret: SIRET, codeDepartment: String): Future[Int] - def search( q: String, postalCode: Option[String], @@ -39,5 +37,4 @@ trait EtablissementRepositoryInterface { openCompaniesOnly: Boolean ): Future[Option[(EtablissementData, Option[ActivityCode])]] - def listWithoutMissingDepartment(limit: Int): Future[Seq[EtablissementData]] } diff --git a/conf/routes b/conf/routes index 147848a..9f12e95 100644 --- a/conf/routes +++ b/conf/routes @@ -9,5 +9,3 @@ GET /api/companies/search controllers.EtablissementCont POST /api/companies/search controllers.EtablissementController.getBySiret(lang: Option[java.util.Locale]) POST /api/companies/siren/search controllers.EtablissementController.getBySiren(lang: Option[java.util.Locale], onlyHeadOffice: Option[Boolean]) POST /api/companies/import controllers.EtablissementController.importEtablissements() -POST /api/companies/fill-department controllers.EtablissementController.fillDepartementWithLimit() -POST /api/companies/fill-department/all controllers.EtablissementController.fillDepartementUntilAllDone() diff --git a/test/orchestrators/EtablissementRepositoryInterfaceMock.scala b/test/orchestrators/EtablissementRepositoryInterfaceMock.scala index c6e8d6c..0cae075 100644 --- a/test/orchestrators/EtablissementRepositoryInterfaceMock.scala +++ b/test/orchestrators/EtablissementRepositoryInterfaceMock.scala @@ -17,8 +17,6 @@ class EtablissementRepositoryInterfaceMock( override def insertOrUpdate(companies: Map[String, Option[String]]): Future[Int] = ??? - override def updateDepartment(siret: SIRET, codeDepartment: String): Future[Int] = ??? - override def search( q: String, postalCode: Option[String], @@ -44,6 +42,4 @@ class EtablissementRepositoryInterfaceMock( openCompaniesOnly: Boolean ): Future[Option[(EtablissementData, Option[ActivityCode])]] = Future.successful(searchHeadOfficeBySirenFunc) - override def listWithoutMissingDepartment(limit: Int): Future[List[EtablissementData]] = ??? - }