diff --git a/app/controllers/AdminController.scala b/app/controllers/AdminController.scala index d51e21fbf..8ad6791bc 100644 --- a/app/controllers/AdminController.scala +++ b/app/controllers/AdminController.scala @@ -98,6 +98,7 @@ class AdminController( details = List(toDetailInputValue("test")), companyId = Some(UUID.randomUUID()), companyName = Some("Dummy Inc."), + companyBrand = Some("Dummy Inc. Store"), companyAddress = Address(Some("3 bis"), Some("Rue des exemples"), None, Some("13006"), Some("Douceville")), companySiret = Some(SIRET("12345678912345")), companyActivityCode = None, @@ -142,12 +143,14 @@ class AdminController( number = Some("3"), street = Some("rue des Champs"), postalCode = Some("75015"), - city = Some("Paris") + city = Some("Paris"), + country = None ), activityCode = None, isHeadOffice = true, isOpen = true, - isPublic = true + isPublic = true, + brand = Some("une super enseigne") ) private def genUser = User( diff --git a/app/models/company/Company.scala b/app/models/company/Company.scala index bf2cf6e74..1c861a65b 100644 --- a/app/models/company/Company.scala +++ b/app/models/company/Company.scala @@ -42,7 +42,8 @@ case class Company( activityCode: Option[String], isHeadOffice: Boolean, isOpen: Boolean, - isPublic: Boolean + isPublic: Boolean, + brand: Option[String] ) { def shortId = this.id.toString.substring(0, 13).toUpperCase } @@ -61,7 +62,7 @@ object CompanyRegisteredSearch { departments = mapper.seq("departments"), activityCodes = mapper.seq("activityCodes"), emailsWithAccess = mapper.string("emailsWithAccess"), - identity = mapper.string("identity").map(SearchCompanyIdentity.fromString) + identity = mapper.nonEmptyString("identity").map(SearchCompanyIdentity.fromString) ) } } @@ -90,7 +91,8 @@ case class CompanyCreation( activityCode: Option[String], isHeadOffice: Option[Boolean], isOpen: Option[Boolean], - isPublic: Option[Boolean] + isPublic: Option[Boolean], + brand: Option[String] ) { def toCompany(): Company = Company( siret = siret, @@ -99,7 +101,8 @@ case class CompanyCreation( activityCode = activityCode, isHeadOffice = isHeadOffice.getOrElse(false), isOpen = isOpen.getOrElse(true), - isPublic = isPublic.getOrElse(true) + isPublic = isPublic.getOrElse(true), + brand = brand ) } @@ -113,6 +116,7 @@ case class CompanyWithNbReports( siret: SIRET, creationDate: OffsetDateTime = OffsetDateTime.now(), name: String, + brand: Option[String], address: Address, activityCode: Option[String], count: Int, diff --git a/app/models/report/Report.scala b/app/models/report/Report.scala index 8b7e25eb8..ff9618022 100644 --- a/app/models/report/Report.scala +++ b/app/models/report/Report.scala @@ -32,6 +32,7 @@ case class Report( influencer: Option[Influencer], companyId: Option[UUID], companyName: Option[String], + companyBrand: Option[String], companyAddress: Address, companySiret: Option[SIRET], companyActivityCode: Option[String], @@ -97,6 +98,7 @@ object Report { "influencer" -> report.influencer, "companyId" -> report.companyId, "companyName" -> report.companyName, + "companyBrand" -> report.companyBrand, "companyAddress" -> Json.toJson(report.companyAddress), "companySiret" -> report.companySiret, "creationDate" -> report.creationDate, @@ -204,6 +206,7 @@ object DeprecatedCompanyWithNbReports { case class ReportCompany( name: String, + brand: Option[String], address: Address, siret: SIRET, activityCode: Option[String], diff --git a/app/models/report/ReportDraft.scala b/app/models/report/ReportDraft.scala index 6e6b113e5..5a97fd208 100644 --- a/app/models/report/ReportDraft.scala +++ b/app/models/report/ReportDraft.scala @@ -25,6 +25,7 @@ case class ReportDraft( details: List[DetailInputValue], influencer: Option[Influencer], companyName: Option[String], + companyBrand: Option[String], companyAddress: Option[Address], companySiret: Option[SIRET], companyActivityCode: Option[String], @@ -67,6 +68,7 @@ case class ReportDraft( influencer = influencer, companyId = maybeCompanyId.orElse(socialNetworkCompany.map(_.id)), companyName = companyName.orElse(socialNetworkCompany.map(_.name)), + companyBrand = companyBrand.orElse(socialNetworkCompany.flatMap(_.brand)), companyAddress = companyAddress.orElse(socialNetworkCompany.map(_.address)).getOrElse(Address()), companySiret = companySiret.orElse(socialNetworkCompany.map(_.siret)), companyActivityCode = companyActivityCode.orElse(socialNetworkCompany.flatMap(_.activityCode)), diff --git a/app/orchestrators/ReportOrchestrator.scala b/app/orchestrators/ReportOrchestrator.scala index 619ee50d3..d759f2d02 100644 --- a/app/orchestrators/ReportOrchestrator.scala +++ b/app/orchestrators/ReportOrchestrator.scala @@ -367,7 +367,8 @@ class ReportOrchestrator( logger.error(s"draftReport.companyIsPublic should not be empty, company details (siret: $siret)") } draftReport.companyIsPublic.getOrElse(false) - } + }, + brand = draftReport.companyBrand ) companyRepository.getOrCreate(siret, company).map { company => logger.debug("Company extracted from report") @@ -389,7 +390,8 @@ class ReportOrchestrator( activityCode = companyToCreate.activityCode, isHeadOffice = companyToCreate.isHeadOffice, isOpen = companyToCreate.isOpen, - isPublic = companyToCreate.isPublic + isPublic = companyToCreate.isPublic, + brand = companyToCreate.brand ) company <- OptionT.liftF(companyRepository.getOrCreate(companyToCreate.siret, c)) } yield company).value @@ -465,7 +467,8 @@ class ReportOrchestrator( activityCode = reportCompany.activityCode, isHeadOffice = reportCompany.isHeadOffice, isOpen = reportCompany.isOpen, - isPublic = reportCompany.isPublic + isPublic = reportCompany.isPublic, + brand = reportCompany.brand ) ) users <- companiesVisibilityOrchestrator.fetchUsersWithHeadOffices(company.siret) diff --git a/app/orchestrators/WebsitesOrchestrator.scala b/app/orchestrators/WebsitesOrchestrator.scala index 675203606..8c8ddf9f1 100644 --- a/app/orchestrators/WebsitesOrchestrator.scala +++ b/app/orchestrators/WebsitesOrchestrator.scala @@ -221,7 +221,8 @@ class WebsitesOrchestrator( activityCode = company.activityCode, isHeadOffice = company.isHeadOffice, isOpen = company.isOpen, - isPublic = company.isPublic + isPublic = company.isPublic, + brand = company.brand ) for { reportIds <- reportRepository.getForWebsiteWithoutCompany(websiteHost) diff --git a/app/repositories/company/CompanyRepository.scala b/app/repositories/company/CompanyRepository.scala index e2ee75fd5..c9870bd91 100644 --- a/app/repositories/company/CompanyRepository.scala +++ b/app/repositories/company/CompanyRepository.scala @@ -79,8 +79,9 @@ class CompanyRepository(override val dbConfig: DatabaseConfig[JdbcProfile])(impl case SearchCompanyIdentityRCS(q) => query.filter(_._1.id.asColumnOf[String] like s"%${q}%") case SearchCompanyIdentitySiret(q) => query.filter(_._1.siret === SIRET.fromUnsafe(q)) case SearchCompanyIdentitySiren(q) => query.filter(_._1.siret.asColumnOf[String] like s"${q}_____") - case SearchCompanyIdentityName(q) => query.filter(_._1.name.toLowerCase like s"%${q.toLowerCase}%") - case id: SearchCompanyIdentityId => query.filter(_._1.id === id.value) + case SearchCompanyIdentityName(q) => + query.filter(tuple => toTsVector(tuple._1.name ++ " " ++ tuple._1.brand) @@ plainToTsQuery(q)) + case id: SearchCompanyIdentityId => query.filter(_._1.id === id.value) } .getOrElse(query) .filterOpt(search.emailsWithAccess) { case (table, email) => diff --git a/app/repositories/company/CompanyTable.scala b/app/repositories/company/CompanyTable.scala index 29c39cd80..509e6cadc 100644 --- a/app/repositories/company/CompanyTable.scala +++ b/app/repositories/company/CompanyTable.scala @@ -5,6 +5,7 @@ import models.company.Company import repositories.DatabaseTable import slick.lifted.TableQuery import utils.Constants.Departments +import utils.Country import utils.SIRET import repositories.PostgresProfile.api._ @@ -25,6 +26,8 @@ class CompanyTable(tag: Tag) extends DatabaseTable[Company](tag, "companies") { def isHeadOffice = column[Boolean]("is_headoffice") def isOpen = column[Boolean]("is_open") def isPublic = column[Boolean]("is_public") + def brand = column[Option[String]]("brand") + def country = column[Option[String]]("country") type CompanyTuple = ( UUID, @@ -40,7 +43,9 @@ class CompanyTable(tag: Tag) extends DatabaseTable[Company](tag, "companies") { Option[String], Boolean, Boolean, - Boolean + Boolean, + Option[String], + Option[String] ) def constructCompany: CompanyTuple => Company = { @@ -58,7 +63,9 @@ class CompanyTable(tag: Tag) extends DatabaseTable[Company](tag, "companies") { activityCode, isHeadOffice, isOpen, - isPublic + isPublic, + brand, + country ) => Company( id = id, @@ -70,12 +77,14 @@ class CompanyTable(tag: Tag) extends DatabaseTable[Company](tag, "companies") { street = street, addressSupplement = addressSupplement, postalCode = postalCode, - city = city + city = city, + country = country.map(Country.fromCode) ), activityCode = activityCode, isHeadOffice = isHeadOffice, isOpen = isOpen, - isPublic = isPublic + isPublic = isPublic, + brand = brand ) } @@ -89,7 +98,8 @@ class CompanyTable(tag: Tag) extends DatabaseTable[Company](tag, "companies") { activityCode, isHeadOffice, isOpen, - isPublic + isPublic, + brand ) => ( id, @@ -105,7 +115,9 @@ class CompanyTable(tag: Tag) extends DatabaseTable[Company](tag, "companies") { activityCode, isHeadOffice, isOpen, - isPublic + isPublic, + brand, + address.country.map(_.code) ) } @@ -123,7 +135,9 @@ class CompanyTable(tag: Tag) extends DatabaseTable[Company](tag, "companies") { activityCode, isHeadOffice, isOpen, - isPublic + isPublic, + brand, + country ) <> (constructCompany, extractCompany.lift) } diff --git a/app/repositories/report/ReportTable.scala b/app/repositories/report/ReportTable.scala index b4ca950cd..1315ae7ca 100644 --- a/app/repositories/report/ReportTable.scala +++ b/app/repositories/report/ReportTable.scala @@ -28,6 +28,7 @@ class ReportTable(tag: Tag) extends DatabaseTable[Report](tag, "reports") { def influencerName = column[Option[String]]("influencer_name") def companyId = column[Option[UUID]]("company_id") def companyName = column[Option[String]]("company_name") + def companyBrand = column[Option[String]]("company_brand") def companySiret = column[Option[SIRET]]("company_siret") def companyStreetNumber = column[Option[String]]("company_street_number") def companyStreet = column[Option[String]]("company_street") @@ -73,6 +74,7 @@ class ReportTable(tag: Tag) extends DatabaseTable[Report](tag, "reports") { influencerName :: companyId :: companyName :: + companyBrand :: companySiret :: companyStreetNumber :: companyStreet :: @@ -110,6 +112,7 @@ class ReportTable(tag: Tag) extends DatabaseTable[Report](tag, "reports") { details = details.filter(_ != null).map(toDetailInputValue), companyId = companyId, companyName = companyName, + companyBrand = companyBrand, companyAddress = Address( number = companyStreetNumber, street = companyStreet, @@ -156,6 +159,7 @@ class ReportTable(tag: Tag) extends DatabaseTable[Report](tag, "reports") { r.influencer.map(_.name) :: r.companyId :: r.companyName :: + r.companyBrand :: r.companySiret :: r.companyAddress.number :: r.companyAddress.street :: @@ -197,6 +201,7 @@ class ReportTable(tag: Tag) extends DatabaseTable[Report](tag, "reports") { Option[String] :: Option[UUID] :: Option[String] :: + Option[String] :: Option[SIRET] :: Option[String] :: Option[String] :: @@ -237,6 +242,7 @@ class ReportTable(tag: Tag) extends DatabaseTable[Report](tag, "reports") { influencerName :: companyId :: companyName :: + companyBrand :: companySiret :: companyStreetNumber :: companyStreet :: diff --git a/app/utils/QueryStringMapper.scala b/app/utils/QueryStringMapper.scala index 5929ed3c8..62fbdb3e2 100644 --- a/app/utils/QueryStringMapper.scala +++ b/app/utils/QueryStringMapper.scala @@ -17,6 +17,8 @@ class QueryStringMapper(q: Map[String, Seq[String]]) { def string(k: String): Option[String] = q.get(k).flatMap(_.headOption) + def nonEmptyString(k: String): Option[String] = q.get(k).flatMap(_.headOption).filter(_.nonEmpty) + def UUID(k: String): Option[UUID] = q.get(k).flatMap(_.headOption).map(extractUUID) def seq(k: String): Seq[String] = q.getOrElse(k, Nil) diff --git a/conf/db/migration/default/V13__add_brand_and_country_to_companies.sql b/conf/db/migration/default/V13__add_brand_and_country_to_companies.sql new file mode 100644 index 000000000..d35d1f408 --- /dev/null +++ b/conf/db/migration/default/V13__add_brand_and_country_to_companies.sql @@ -0,0 +1,6 @@ +ALTER TABLE companies + ADD brand varchar, + ADD country varchar; + +ALTER TABLE reports + ADD company_brand varchar; \ No newline at end of file diff --git a/test/controllers/report/GetReportSpec.scala b/test/controllers/report/GetReportSpec.scala index bdeccfadb..da3fc1b0c 100644 --- a/test/controllers/report/GetReportSpec.scala +++ b/test/controllers/report/GetReportSpec.scala @@ -267,6 +267,7 @@ trait GetReportContext extends AppSpec { influencer = None, companyId = Some(company.id), companyName = Some("companyName"), + companyBrand = Some("companyBrand"), companyAddress = company.address, companySiret = Some(company.siret), companyActivityCode = company.activityCode, @@ -291,6 +292,7 @@ trait GetReportContext extends AppSpec { influencer = None, companyId = Some(company.id), companyName = Some("companyName"), + companyBrand = Some("companyBrand"), companyAddress = company.address, companySiret = Some(company.siret), companyActivityCode = company.activityCode, @@ -315,6 +317,7 @@ trait GetReportContext extends AppSpec { influencer = None, companyId = Some(company.id), companyName = Some("companyName"), + companyBrand = Some("companyBrand"), companyAddress = company.address, companySiret = Some(company.siret), companyActivityCode = company.activityCode, diff --git a/test/utils/Fixtures.scala b/test/utils/Fixtures.scala index c8595f141..27dfb62c9 100644 --- a/test/utils/Fixtures.scala +++ b/test/utils/Fixtures.scala @@ -82,6 +82,7 @@ object Fixtures { val genCompany = for { _ <- arbitrary[UUID] name <- arbString.arbitrary + brand <- Gen.option(arbString.arbitrary) siret <- genSiret() address <- genAddress() } yield Company( @@ -92,7 +93,8 @@ object Fixtures { activityCode = None, isOpen = true, isHeadOffice = false, - isPublic = true + isPublic = true, + brand = brand ) val genInfluencer = for { @@ -125,6 +127,7 @@ object Fixtures { details = List(), influencer = None, companyName = Some(company.name), + companyBrand = company.brand, companyAddress = Some(company.address), companySiret = Some(company.siret), companyActivityCode = None, @@ -172,6 +175,7 @@ object Fixtures { companyId = Some(company.id), creationDate = OffsetDateTime.now().truncatedTo(ChronoUnit.MILLIS), companyName = Some(company.name), + companyBrand = company.brand, companyAddress = company.address, companySiret = Some(company.siret), companyActivityCode = company.activityCode, @@ -205,9 +209,10 @@ object Fixtures { def genReportCompany = for { name <- arbString.arbitrary + brand <- Gen.option(arbString.arbitrary) address <- genAddress(postalCode = Some(Gen.choose(10000, 99999).toString)) siret <- genSiret() - } yield ReportCompany(name, address, siret, None, isHeadOffice = true, isOpen = true, isPublic = true) + } yield ReportCompany(name, brand, address, siret, None, isHeadOffice = true, isOpen = true, isPublic = true) def genEventForReport(reportId: UUID, eventType: EventTypeValue, actionEvent: ActionEventValue) = for { id <- arbitrary[UUID]