Skip to content

Commit

Permalink
Update fleet segments table and related cypress tests
Browse files Browse the repository at this point in the history
  • Loading branch information
louptheron committed Jan 9, 2025
1 parent a17c229 commit c6dcc2a
Show file tree
Hide file tree
Showing 13 changed files with 384 additions and 362 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ data class GearDataOutput(
val name: String,
val category: String? = null,
val groupId: Int? = null,
val isMeshRequiredForSegment: Boolean
val isMeshRequiredForSegment: Boolean,
) {
companion object {
fun fromGear(gear: Gear): GearDataOutput {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ data class FleetSegmentEntity(
val minMesh: Double?,
@Column(name = "min_share_of_target_species", nullable = true)
val minShareOfTargetSpecies: Double?,
@Column(name = "vessel_types", columnDefinition = "varchar(15)[]")
@Column(name = "vessel_types", columnDefinition = "varchar[]")
val vesselTypes: List<String>?,
@Column(name = "gears", columnDefinition = "varchar(3)[]")
val gears: List<String>?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import fr.gouv.cnsp.monitorfish.domain.repositories.FleetSegmentRepository
import fr.gouv.cnsp.monitorfish.domain.use_cases.dtos.CreateOrUpdateFleetSegmentFields
import fr.gouv.cnsp.monitorfish.infrastructure.database.entities.FleetSegmentEntity
import fr.gouv.cnsp.monitorfish.infrastructure.database.repositories.interfaces.DBFleetSegmentRepository
import fr.gouv.cnsp.monitorfish.infrastructure.database.repositories.utils.toSqlArrayString
import jakarta.transaction.Transactional
import org.springframework.cache.annotation.Cacheable
import org.springframework.stereotype.Repository
Expand Down Expand Up @@ -115,7 +116,18 @@ class JpaFleetSegmentRepository(

@Transactional
override fun save(segment: FleetSegment): FleetSegment {
dbFleetSegmentRepository.saveFleetSegment(FleetSegmentEntity.fromFleetSegment(segment))
val fleetSegmentEntity = FleetSegmentEntity.fromFleetSegment(segment)

// The list properties needs to be formatted
val escapedFleetSegmentEntity =
fleetSegmentEntity.copy(
vesselTypes = toSqlArrayString(fleetSegmentEntity.vesselTypes)?.let { listOf(it) },
gears = toSqlArrayString(fleetSegmentEntity.gears)?.let { listOf(it) },
faoAreas = toSqlArrayString(fleetSegmentEntity.faoAreas)?.let { listOf(it) },
targetSpecies = toSqlArrayString(fleetSegmentEntity.targetSpecies)?.let { listOf(it) },
)

dbFleetSegmentRepository.saveFleetSegment(escapedFleetSegmentEntity)

return dbFleetSegmentRepository.findBySegmentAndYearEquals(segment.segment, segment.year).toFleetSegment()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ interface DBFleetSegmentRepository : CrudRepository<FleetSegmentEntity, Long> {
:#{#fleetSegment.maxMesh},
:#{#fleetSegment.minMesh},
:#{#fleetSegment.minShareOfTargetSpecies},
:#{#fleetSegment.vesselTypes},
:#{#fleetSegment.gears},
:#{#fleetSegment.faoAreas},
:#{#fleetSegment.targetSpecies},
CAST(:#{#fleetSegment.vesselTypes} AS varchar[]),
CAST(:#{#fleetSegment.gears} AS varchar(3)[]),
CAST(:#{#fleetSegment.faoAreas} AS varchar(15)[]),
CAST(:#{#fleetSegment.targetSpecies} AS varchar(3)[]),
:#{#fleetSegment.impactRiskFactor},
:#{#fleetSegment.year}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,111 +4,130 @@
INSERT INTO control_objectives (facade, segment, year, target_number_of_controls_at_sea,
target_number_of_controls_at_port, control_priority_level)
VALUES ('MEMN', 'NWW01/02', 2022, 78, 82, 3),
('MEMN', 'NS01/03', 2022, 12, 11, 3),
('MEMN', 'PEL03', 2022, 109, 119, 3),
('SA', 'ATL01', 2022, 4, 3, 3),
('SA', 'MED06/ATL02', 2022, 8, 12, 3),
('MED', 'MED06/ATL02', 2022, 152, 317, 4),
('MED', 'MED01', 2022, 157, 63, 1),
('MED', 'MED02', 2022, 35, 0, 1),
('MED', 'MED04', 2022, 20, 50, 1),
('MED', 'MED05', 2022, 133, 87, 1),
('MED', 'MED07', 2022, 132, 80, 1),
('MED', 'FR_ELE', 2022, 90, 60, 1),
('MED', 'FR_DRB', 2022, 16, 8, 1),
('MED', 'FR_TMB', 2022, 20, 27, 1),
('MEMN', 'FR_SCE', 2022, 141, 147, 1),
('MEMN', 'NS13', 2022, 12, 12, 1),
('MEMN', 'NS14', 2022, 3, 2, 1),
('MEMN', 'NWW05', 2022, 15, 15, 1),
('MEMN', 'NWW06', 2022, 7, 4, 1),
('MEMN', 'NWW07', 2022, 5, 6, 1),
('MEMN', 'NWW08', 2022, 36, 38, 1),
('MEMN', 'NWW09', 2022, 19, 21, 1),
('MEMN', 'NWW10', 2022, 97, 107, 1),
('NAMO', 'FR_ELE', 2022, 0, 86, 1),
('NAMO', 'ATL01', 2022, 20, 0, 1),
('NAMO', 'FR_SCE', 2022, 51, 126, 1),
('NAMO', 'MED06/ATL02', 2022, 3, 0, 1),
('NAMO', 'NWW01/02', 2022, 80, 73, 1),
('NAMO', 'NWW07', 2022, 24, 15, 1),
('NAMO', 'NWW08', 2022, 20, 24, 1),
('NAMO', 'NWW09', 2022, 12, 14, 1),
('NAMO', 'NWW10', 2022, 36, 27, 1),
('NAMO', 'PEL01', 2022, 14, 24, 1),
('NAMO', 'PEL03', 2022, 103, 65, 1),
('NAMO', 'PEL08', 2022, 24, 24, 1),
('NAMO', 'PEL13', 2022, 6, 21, 1),
('NAMO', 'PEL14', 2022, 3, 0, 1),
('NAMO', 'SWW01/02', 2022, 103, 66, 1),
('NAMO', 'SWW04', 2022, 13, 24, 1),
('NAMO', 'SWW06', 2022, 14, 6, 1),
('NAMO', 'SWW07/03', 2022, 100, 106, 1),
('NAMO', 'SWW10', 2022, 20, 22, 1),
('SA', 'FR_SCE', 2022, 51, 42, 1),
('SA', 'PEL03', 2022, 130, 37, 1),
('SA', 'PEL05', 2022, 30, 2, 1),
('SA', 'PEL08', 2022, 23, 12, 1),
('SA', 'PEL13', 2022, 2, 0, 1),
('SA', 'SWW01/08', 2022, 139, 43, 1),
('SA', 'SWW06', 2022, 3, 0, 1),
('SA', 'SWW07/02', 2022, 53, 51, 1),
('SA', 'SWW10', 2022, 32, 20, 1),
('SA', 'PEL14', 2022, 8, 7, 1),
('SA', 'FR_ELE', 2022, 0, 129, 1),
('MEMN', 'NWW01/02', 2023, 78, 82, 3),
('MEMN', 'NS01/03', 2023, 12, 11, 3),
('MEMN', 'PEL03', 2023, 109, 119, 3),
('SA', 'ATL01', 2023, 4, 3, 3),
('SA', 'MED06/ATL02', 2023, 8, 12, 3),
('MED', 'MED06/ATL02', 2023, 152, 317, 4),
('MED', 'MED01', 2023, 157, 63, 1),
('MED', 'MED02', 2023, 35, 0, 1),
('MED', 'MED04', 2023, 20, 50, 1),
('MED', 'MED05', 2023, 133, 87, 2),
('MED', 'MED07', 2023, 232, 80, 2),
('MED', 'FR_ELE', 2023, 90, 60, 2),
('MED', 'FR_DRB', 2023, 26, 8, 2),
('MED', 'FR_TMB', 2023, 20, 27, 2),
('MEMN', 'FR_SCE', 2023, 242, 247, 2),
('MEMN', 'NS23', 2023, 12, 12, 1),
('MEMN', 'NS14', 2023, 3, 2, 1),
('MEMN', 'NWW05', 2023, 15, 15, 1),
('MEMN', 'NWW06', 2023, 7, 4, 1),
('MEMN', 'NWW07', 2023, 5, 6, 1),
('MEMN', 'NWW08', 2023, 36, 38, 1),
('MEMN', 'NWW09', 2023, 19, 21, 1),
('MEMN', 'NWW10', 2023, 97, 107, 1),
('NAMO', 'FR_ELE', 2023, 0, 86, 1),
('NAMO', 'ATL01', 2023, 20, 0, 1),
('NAMO', 'FR_SCE', 2023, 51, 126, 1),
('NAMO', 'MED06/ATL02', 2023, 3, 0, 1),
('NAMO', 'NWW01/02', 2023, 80, 73, 1),
('NAMO', 'NWW07', 2023, 24, 15, 1),
('NAMO', 'NWW08', 2023, 20, 24, 1),
('NAMO', 'NWW09', 2023, 12, 14, 1),
('NAMO', 'NWW10', 2023, 36, 27, 1),
('NAMO', 'PEL01', 2023, 14, 24, 1),
('NAMO', 'PEL03', 2023, 103, 65, 1),
('NAMO', 'PEL08', 2023, 24, 24, 1),
('NAMO', 'PEL13', 2023, 6, 21, 1),
('NAMO', 'PEL14', 2023, 3, 0, 1),
('NAMO', 'SWW01/02', 2023, 103, 66, 1),
('NAMO', 'SWW04', 2023, 13, 24, 1),
('NAMO', 'SWW06', 2023, 14, 6, 1),
('NAMO', 'SWW07/03', 2023, 100, 106, 1),
('NAMO', 'SWW10', 2023, 20, 22, 1),
('SA', 'FR_SCE', 2023, 51, 42, 1),
('SA', 'PEL03', 2023, 130, 37, 1),
('SA', 'PEL05', 2023, 30, 2, 1),
('SA', 'PEL08', 2023, 23, 12, 1),
('SA', 'PEL13', 2023, 2, 0, 1),
('SA', 'SWW01/08', 2023, 139, 43, 1),
('SA', 'SWW06', 2023, 3, 0, 1),
('SA', 'SWW07/02', 2023, 53, 51, 1),
('SA', 'SWW10', 2023, 32, 20, 1),
('SA', 'PEL14', 2023, 8, 7, 1),
('SA', 'FR_ELE', 2023, 0, 129, 1);
('MEMN', 'NS01/03', 2022, 12, 11, 3),
('MEMN', 'PEL03', 2022, 109, 119, 3),
('SA', 'ATL01', 2022, 4, 3, 3),
('SA', 'MED06/ATL02', 2022, 8, 12, 3),
('MED', 'MED06/ATL02', 2022, 152, 317, 4),
('MED', 'MED01', 2022, 157, 63, 1),
('MED', 'MED02', 2022, 35, 0, 1),
('MED', 'MED04', 2022, 20, 50, 1),
('MED', 'MED05', 2022, 133, 87, 1),
('MED', 'MED07', 2022, 132, 80, 1),
('MED', 'FR_ELE', 2022, 90, 60, 1),
('MED', 'FR_DRB', 2022, 16, 8, 1),
('MED', 'FR_TMB', 2022, 20, 27, 1),
('MEMN', 'FR_SCE', 2022, 141, 147, 1),
('MEMN', 'NS13', 2022, 12, 12, 1),
('MEMN', 'NS14', 2022, 3, 2, 1),
('MEMN', 'NWW05', 2022, 15, 15, 1),
('MEMN', 'NWW06', 2022, 7, 4, 1),
('MEMN', 'NWW07', 2022, 5, 6, 1),
('MEMN', 'NWW08', 2022, 36, 38, 1),
('MEMN', 'NWW09', 2022, 19, 21, 1),
('MEMN', 'NWW10', 2022, 97, 107, 1),
('NAMO', 'FR_ELE', 2022, 0, 86, 1),
('NAMO', 'ATL01', 2022, 20, 0, 1),
('NAMO', 'FR_SCE', 2022, 51, 126, 1),
('NAMO', 'MED06/ATL02', 2022, 3, 0, 1),
('NAMO', 'NWW01/02', 2022, 80, 73, 1),
('NAMO', 'NWW07', 2022, 24, 15, 1),
('NAMO', 'NWW08', 2022, 20, 24, 1),
('NAMO', 'NWW09', 2022, 12, 14, 1),
('NAMO', 'NWW10', 2022, 36, 27, 1),
('NAMO', 'PEL01', 2022, 14, 24, 1),
('NAMO', 'PEL03', 2022, 103, 65, 1),
('NAMO', 'PEL08', 2022, 24, 24, 1),
('NAMO', 'PEL13', 2022, 6, 21, 1),
('NAMO', 'PEL14', 2022, 3, 0, 1),
('NAMO', 'SWW01/02', 2022, 103, 66, 1),
('NAMO', 'SWW04', 2022, 13, 24, 1),
('NAMO', 'SWW06', 2022, 14, 6, 1),
('NAMO', 'SWW07/03', 2022, 100, 106, 1),
('NAMO', 'SWW10', 2022, 20, 22, 1),
('SA', 'FR_SCE', 2022, 51, 42, 1),
('SA', 'PEL03', 2022, 130, 37, 1),
('SA', 'PEL05', 2022, 30, 2, 1),
('SA', 'PEL08', 2022, 23, 12, 1),
('SA', 'PEL13', 2022, 2, 0, 1),
('SA', 'SWW01/08', 2022, 139, 43, 1),
('SA', 'SWW06', 2022, 3, 0, 1),
('SA', 'SWW07/02', 2022, 53, 51, 1),
('SA', 'SWW10', 2022, 32, 20, 1),
('SA', 'PEL14', 2022, 8, 7, 1),
('SA', 'FR_ELE', 2022, 0, 129, 1),
('SA', 'ATL01', 2023, 78, 82, 3),
('SA', 'ATL02', 2023, 12, 11, 3),
('MEMN', 'FR_anguille', 2023, 109, 119, 3),
('MEMN', 'FR_DRB', 2023, 4, 3, 3),
('MEMN', 'FR_ELE', 2023, 8, 12, 3),
('MEMN', 'FR_FOO', 2023, 152, 317, 4),
('MEMN', 'FR_FPO', 2023, 157, 63, 1),
('MEMN', 'FR_LOD', 2023, 35, 0, 1),
('MEMN', 'FR_SCE', 2023, 20, 50, 1),
('MEMN', 'FR_TMB', 2023, 133, 87, 2),
('MED', 'MED01', 2023, 232, 80, 2),
('MED', 'MED02', 2023, 90, 60, 2),
('MED', 'MED03', 2023, 26, 8, 2),
('MED', 'MED04', 2023, 20, 27, 2),
('MED', 'MED05', 2023, 242, 247, 2),
('MED', 'MED06', 2023, 12, 12, 1),
('MED', 'MED07', 2023, 3, 2, 1),
('MED', 'MED09', 2023, 15, 15, 1),
('MED', 'MED10', 2023, 7, 4, 1),
('MEMN', 'NS01', 2023, 5, 6, 1),
('MEMN', 'NS02', 2023, 36, 38, 1),
('MEMN', 'NS03', 2023, 19, 21, 1),
('MEMN', 'NS04', 2023, 97, 107, 1),
('MEMN', 'NS05', 2023, 0, 86, 1),
('MEMN', 'NWW01', 2023, 103, 65, 1),
('MEMN', 'NWW02', 2023, 24, 24, 1),
('MEMN', 'NWW03', 2023, 6, 21, 1),
('MEMN', 'NWW04', 2023, 3, 0, 1),
('MEMN', 'NWW05', 2023, 103, 66, 1),
('MEMN', 'NWW06', 2023, 13, 24, 1),
('MEMN', 'NWW07', 2023, 14, 6, 1),
('MEMN', 'NWW08', 2023, 100, 106, 1),
('MEMN', 'NWW09', 2023, 20, 22, 1),
('NAMO', 'NS06', 2023, 20, 0, 1),
('NAMO', 'NS07', 2023, 51, 126, 1),
('NAMO', 'NS08', 2023, 3, 0, 1),
('NAMO', 'NS09', 2023, 80, 73, 1),
('NAMO', 'NS10', 2023, 24, 15, 1),
('NAMO', 'NS11', 2023, 20, 24, 1),
('NAMO', 'NS12', 2023, 12, 14, 1),
('NAMO', 'NS13', 2023, 36, 27, 1),
('NAMO', 'NS14', 2023, 14, 24, 1),
('NAMO', 'NWW01', 2023, 103, 65, 1),
('NAMO', 'NWW02', 2023, 24, 24, 1),
('NAMO', 'NWW03', 2023, 6, 21, 1),
('NAMO', 'NWW04', 2023, 3, 0, 1),
('NAMO', 'NWW05', 2023, 103, 66, 1),
('NAMO', 'NWW06', 2023, 13, 24, 1),
('NAMO', 'NWW07', 2023, 14, 6, 1),
('NAMO', 'NWW08', 2023, 100, 106, 1),
('NAMO', 'NWW09', 2023, 20, 22, 1),
('SA', 'NWW10', 2023, 51, 42, 1),
('SA', 'PEL01', 2023, 130, 37, 1),
('SA', 'PEL02', 2023, 30, 2, 1),
('SA', 'PEL03', 2023, 23, 12, 1),
('SA', 'PEL04', 2023, 2, 0, 1),
('SA', 'PEL05', 2023, 139, 43, 1),
('SA', 'PEL06', 2023, 3, 0, 1),
('SA', 'PEL08', 2023, 53, 51, 1),
('SA', 'PEL13', 2023, 32, 20, 1),
('SA', 'PEL14', 2023, 8, 7, 1),
('SA', 'PEL15', 2023, 0, 129, 1),
('SA', 'SWW01', 2023, 130, 37, 1),
('SA', 'SWW02', 2023, 30, 2, 1),
('SA', 'SWW03', 2023, 23, 12, 1),
('SA', 'SWW04', 2023, 2, 0, 1),
('SA', 'SWW05', 2023, 139, 43, 1),
('SA', 'SWW06', 2023, 3, 0, 1),
('SA', 'SWW07', 2023, 53, 51, 1),
('SA', 'SWW08', 2023, 32, 20, 1),
('SA', 'SWW09', 2023, 8, 7, 1),
('SA', 'SWW10', 2023, 0, 129, 1);

UPDATE control_objectives SET year = date_part('year', CURRENT_DATE) WHERE year = 2023;
UPDATE control_objectives SET year = date_part('year', CURRENT_DATE - interval '1 year') WHERE year = 2022;
Loading

0 comments on commit c6dcc2a

Please sign in to comment.