Skip to content

Commit

Permalink
Trello 2537 (#1738)
Browse files Browse the repository at this point in the history
* TRELLO-2537 : create sample user,companies & reports
  • Loading branch information
ssedoudbgouv authored Sep 28, 2024
1 parent 8ff71eb commit 30d0c6c
Show file tree
Hide file tree
Showing 27 changed files with 690 additions and 42 deletions.
4 changes: 3 additions & 1 deletion app/config/TaskConfiguration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ case class TaskConfiguration(
inactiveAccounts: InactiveAccountsTaskConfiguration,
companyUpdate: CompanyUpdateTaskConfiguration,
probe: ProbeConfiguration,
exportReportsToSFTP: ExportReportsToSFTPConfiguration
exportReportsToSFTP: ExportReportsToSFTPConfiguration,
sampleData: SampleDataConfiguration
)

case class SubscriptionTaskConfiguration(startTime: LocalTime, startDay: DayOfWeek)
Expand Down Expand Up @@ -54,3 +55,4 @@ case class ReportRemindersTaskConfiguration(
case class ProbeConfiguration(active: Boolean)

case class ExportReportsToSFTPConfiguration(filePath: String, startTime: LocalTime)
case class SampleDataConfiguration(isActive: Boolean = false, startTime: LocalTime)
4 changes: 2 additions & 2 deletions app/controllers/AccountController.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ class AccountController(
}

def fetchPendingAgent(role: Option[UserRole]) =
SecuredAction.andThen(WithRole(UserRole.AdminsAndReadOnly)).async { request =>
SecuredAction.andThen(WithRole(UserRole.AdminsAndReadOnly)).async { _ =>
role match {
case Some(UserRole.DGCCRF) | Some(UserRole.DGAL) | None =>
accessesOrchestrator
.listAgentPendingTokens(request.identity, role)
.listAgentPendingTokens(role)
.map(tokens => Ok(Json.toJson(tokens)))
case Some(role) => Future.failed(error.AppError.WrongUserRole(role))
}
Expand Down
34 changes: 31 additions & 3 deletions app/loader/SignalConsoApplicationLoader.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import authentication._
import com.typesafe.config.Config
import com.typesafe.config.ConfigFactory
import config._
import models.report.sampledata.SampleDataService
import orchestrators._
import orchestrators.socialmedia.InfluencerOrchestrator
import orchestrators.socialmedia.SocialBladeClient
Expand Down Expand Up @@ -90,8 +91,10 @@ import repositories.website.WebsiteRepositoryInterface
import services._
import services.antivirus.AntivirusService
import services.antivirus.AntivirusServiceInterface
import services.emails.BaseEmail
import services.emails.MailRetriesService
import services.emails.MailService
import services.emails.MailServiceInterface
import slick.basic.DatabaseConfig
import slick.jdbc.JdbcProfile
import sttp.capabilities
Expand All @@ -108,6 +111,7 @@ import tasks.report.OrphanReportFileDeletionTask
import tasks.report.ReportClosureTask
import tasks.report.ReportNotificationTask
import tasks.report.ReportRemindersTask
import tasks.report.SampleDataGenerationTask
import utils.CustomIpFilter
import utils.EmailAddress
import utils.FrontRoute
Expand Down Expand Up @@ -271,7 +275,7 @@ class SignalConsoComponents(
implicit val frontRoute: FrontRoute = new FrontRoute(signalConsoConfiguration)
val attachmentService = new AttachmentService(environment, pdfService, frontRoute)
lazy val mailRetriesService = new MailRetriesService(mailerClient, executionContext, actorSystem)
val mailService = new MailService(
var mailService = new MailService(
mailRetriesService,
emailConfiguration,
reportNotificationBlockedRepository,
Expand Down Expand Up @@ -385,8 +389,9 @@ class SignalConsoComponents(
)

val emailNotificationOrchestrator = new EmailNotificationOrchestrator(mailService, subscriptionRepository)
val reportOrchestrator = new ReportOrchestrator(
mailService,

def buildReportOrchestrator(emailService: MailServiceInterface) = new ReportOrchestrator(
emailService,
reportConsumerReviewOrchestrator,
reportRepository,
reportMetadataRepository,
Expand All @@ -410,6 +415,8 @@ class SignalConsoComponents(
messagesApi
)

val reportOrchestrator = buildReportOrchestrator(mailService)

val reportAssignmentOrchestrator = new ReportAssignmentOrchestrator(
reportOrchestrator,
companiesVisibilityOrchestrator,
Expand Down Expand Up @@ -553,6 +560,24 @@ class SignalConsoComponents(
taskRepository
)

private val reportOrchestratorWithFakeMailer = buildReportOrchestrator(_ => Future.unit)

val sampleDataService = new SampleDataService(
companyRepository,
userRepository,
accessTokenRepository,
reportOrchestratorWithFakeMailer,
reportRepository,
companyAccessRepository,
reportAdminActionOrchestrator,
websiteRepository
)(
actorSystem
)

val sampleDataGenerationTask =
new SampleDataGenerationTask(actorSystem, sampleDataService, taskConfiguration, taskRepository)

val inactiveDgccrfAccountRemoveTask =
new InactiveDgccrfAccountRemoveTask(userRepository, subscriptionRepository, asyncFileRepository)

Expand Down Expand Up @@ -835,6 +860,9 @@ class SignalConsoComponents(
if (applicationConfiguration.task.probe.active) {
probeOrchestrator.scheduleProbeTasks()
}
if (applicationConfiguration.task.sampleData.isActive) {
sampleDataGenerationTask.schedule()
}
}

override def config: Config = ConfigFactory.load()
Expand Down
2 changes: 2 additions & 0 deletions app/models/company/Address.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ case class Address(
object Address {
implicit val addressFormat: OFormat[Address] = Json.format[Address]

val Empty = Address(None, None, None, None, None, None)

def merge(base: Option[Address], alternative: Option[Address]): Address = {
val a = base.getOrElse(Address())
val b = alternative.getOrElse(Address())
Expand Down
1 change: 1 addition & 0 deletions app/models/report/Report.scala
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ case class WebsiteURL(websiteURL: Option[URL], host: Option[String])

object WebsiteURL {
implicit val WebsiteURLFormat: OFormat[WebsiteURL] = Json.format[WebsiteURL]
val Empty = WebsiteURL(None, None)
}

case class ReportWithFiles(
Expand Down
37 changes: 37 additions & 0 deletions app/models/report/sampledata/AddressGenerator.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package models.report.sampledata

import models.company.Address
import utils.Country.Espagne

object AddressGenerator {

def frenchAddress(): Address =
Address(
number = Some("789"),
street = Some("Rue de la Paix"),
addressSupplement = Some("Appartement 12, Bâtiment C"),
postalCode = Some("75008"),
city = Some("Paris"),
country = None
)

def domTomAddress(): Address =
Address(
number = Some("12"),
street = Some("Rue du Lagon"),
addressSupplement = Some("Résidence Les Tropiques, Appartement 4B"),
postalCode = Some("97100"),
city = Some("Basse-Terre"),
country = None
)

def foreignAddress(): Address =
Address(
number = Some("456"),
street = Some("Calle Falsa"),
addressSupplement = Some("Piso 3, Puerta B"),
postalCode = Some("28080"),
city = Some("Madrid"),
country = Some(Espagne)
)
}
78 changes: 78 additions & 0 deletions app/models/report/sampledata/CompanyGenerator.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package models.report.sampledata

import models.company.Address
import models.company.Company
import utils.SIREN
import utils.SIRET

import java.util.UUID
import scala.collection.mutable.ListBuffer
import scala.util.Random

object CompanyGenerator {

def randomCompany(
siren: SIREN,
name: String,
address: Address,
isHeadOffice: Boolean,
isOpen: Boolean,
isPublic: Boolean
): Company =
Company(
id = UUID.randomUUID(),
siret = SIRET(siren.value + f"${Random.nextInt(100000)}%05d"),
name = name,
address = address,
activityCode = Random.shuffle(List("40.7Z", "12.4A", "62.01Z")).headOption,
isHeadOffice = isHeadOffice,
isOpen = isOpen,
isPublic = isPublic,
brand = Some(s"Marque ${name}"),
commercialName = Some(s"Nom commercial ${name}"),
establishmentCommercialName = Some(s"Nom établissement commercial ${name}")
)

def createCompany = {
val randomSiren = SIREN((100000000 + Random.nextInt(900000000)).toString)
randomCompany(
siren = randomSiren,
name = s"MAISON MERE ${randomSiren.value}",
address = AddressGenerator.frenchAddress(),
isHeadOffice = true,
isOpen = true,
isPublic = true
)
}

def createCompanies(subsidiaryCount: Int) = {

val randomSiren = SIREN((100000000 + Random.nextInt(900000000)).toString)
val headOffice = randomCompany(
siren = randomSiren,
name = s"MAISON MERE ${randomSiren.value}",
address = AddressGenerator.frenchAddress(),
isHeadOffice = true,
isOpen = true,
isPublic = true
)

val companies = ListBuffer(headOffice)

for (i <- 1 to subsidiaryCount) {
val c = randomCompany(
siren = randomSiren,
name = s" FILLIALE $randomSiren n$i",
address = AddressGenerator.frenchAddress(),
isHeadOffice = false,
isOpen = true,
isPublic = true
)
companies += c
}

companies.toList

}

}
Loading

0 comments on commit 30d0c6c

Please sign in to comment.