Skip to content

Commit

Permalink
[Mission] add possibility to search mission by id
Browse files Browse the repository at this point in the history
  • Loading branch information
claire2212 committed Dec 2, 2024
1 parent 70bcb75 commit 9ba3544
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ import fr.gouv.cacem.monitorenv.domain.entities.mission.envAction.envActionContr
import fr.gouv.cacem.monitorenv.domain.repositories.IMissionRepository
import fr.gouv.cacem.monitorenv.domain.use_cases.missions.dtos.MissionDTO
import fr.gouv.cacem.monitorenv.infrastructure.database.model.MissionModel
import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.interfaces.IDBControlPlanSubThemeRepository
import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.interfaces.IDBControlPlanTagRepository
import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.interfaces.IDBControlPlanThemeRepository
import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.interfaces.IDBControlUnitResourceRepository
import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.interfaces.IDBMissionRepository
import fr.gouv.cacem.monitorenv.infrastructure.database.repositories.interfaces.*
import org.apache.commons.lang3.StringUtils
import org.springframework.data.domain.PageRequest
import org.springframework.data.domain.Pageable
Expand Down Expand Up @@ -137,22 +133,26 @@ class JpaMissionRepository(
return true
}

return mission.envActions?.any { action ->
(action as? EnvActionControlEntity)?.infractions?.any { infraction ->
listOf(
infraction.imo,
infraction.mmsi,
infraction.registrationNumber,
infraction.vesselName,
infraction.companyName,
infraction.controlledPersonIdentity,
).any { field ->
!field.isNullOrBlank() &&
normalizeField(field)
.contains(normalizeField(searchQuery), ignoreCase = true)
}
return mission.id?.toString()?.let {
normalizeField(it)
.contains(normalizeField(searchQuery), ignoreCase = true)
} == true ||
mission.envActions?.any { action ->
(action as? EnvActionControlEntity)?.infractions?.any { infraction ->
listOf(
infraction.imo,
infraction.mmsi,
infraction.registrationNumber,
infraction.vesselName,
infraction.companyName,
infraction.controlledPersonIdentity,
).any { field ->
!field.isNullOrBlank() &&
normalizeField(field)
.contains(normalizeField(searchQuery), ignoreCase = true)
}
} ?: false
} ?: false
} ?: false
}

private fun normalizeField(input: String): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,19 @@ import org.springframework.dao.InvalidDataAccessApiUsageException
import org.springframework.test.context.junit.jupiter.SpringExtension
import org.springframework.transaction.annotation.Transactional
import java.time.ZonedDateTime
import java.util.UUID
import java.util.*

@ExtendWith(SpringExtension::class)
@Import(DataSourceProxyBeanPostProcessor::class)
class JpaMissionRepositoryITests : AbstractDBTests() {
@Autowired private val customQueryCountListener: CustomQueryCountListener? = null
@Autowired
private val customQueryCountListener: CustomQueryCountListener? = null

@Autowired private lateinit var jpaMissionRepository: JpaMissionRepository
@Autowired
private lateinit var jpaMissionRepository: JpaMissionRepository

@Autowired private lateinit var jpaControlUnitRepository: JpaControlUnitRepository
@Autowired
private lateinit var jpaControlUnitRepository: JpaControlUnitRepository

@Autowired
private lateinit var jpaControlUnitResourceRepository: JpaControlUnitResourceRepository
Expand Down Expand Up @@ -348,6 +351,27 @@ class JpaMissionRepositoryITests : AbstractDBTests() {
println("Number of Queries Executed: $queryCount")
}

@Test
@Transactional
fun `findAll Should return filtered missions when search query is an id`() {
// When
val missions =
jpaMissionRepository.findAllFullMissions(
startedAfter = ZonedDateTime.parse("2000-01-01T00:01:00Z").toInstant(),
startedBefore = null,
missionTypes = null,
seaFronts = null,
missionStatuses = null,
pageNumber = null,
pageSize = null,
searchQuery = "53",
)
assertThat(missions).hasSize(1)

val queryCount = customQueryCountListener!!.getQueryCount()
println("Number of Queries Executed: $queryCount")
}

@Test
@Transactional
fun `findAll with pagenumber and pagesize Should return subset of missions`() {
Expand Down

0 comments on commit 9ba3544

Please sign in to comment.