Skip to content

Commit

Permalink
Merge pull request #95 from MTES-MCT/sonar-fixes
Browse files Browse the repository at this point in the history
Try SonarLint and fix some sonar issues
  • Loading branch information
lwih authored Mar 4, 2024
2 parents e67d6d1 + 069b4dd commit 4b29b62
Show file tree
Hide file tree
Showing 25 changed files with 253 additions and 218 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/trivy-db.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
- name: Run Trivy on Postgres image
uses: aquasecurity/trivy-action@master
with:
image-ref: "postgres:15.5-alpine"
image-ref: "postgres:15.6-alpine"
format: sarif
output: "postgres-trivy-results.sarif"
severity: "CRITICAL,HIGH"
Expand Down
2 changes: 1 addition & 1 deletion .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ variables:
value: rapportnav-v2
description: "Nom du projet à déployer"
BDD_IAMGE:
value: postgres:15.5-alpine
value: postgres:15.6-alpine
description: "Image de la base de données"
PROJECT_VERSION:
value: "1.1.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ fun main(args: Array<String>) {
if (isSentryEnabled == "true") {
Sentry.init { options ->
options.dsn = sentryDsn
options.proxy = SentryOptions.Proxy("172.27.229.197", "8090")
options.proxy = SentryOptions.Proxy(
ctx.environment.getProperty("sentry.proxy.host"),
ctx.environment.getProperty("sentry.proxy.port")
)
options.tracesSampleRate = 1.0
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fr.gouv.dgampa.rapportnav.domain.entities.mission.env.envActions

import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonSubTypes
import com.fasterxml.jackson.annotation.JsonTypeInfo
import com.fasterxml.jackson.databind.annotation.JsonDeserialize
Expand All @@ -21,15 +20,15 @@ import java.util.*
JsonSubTypes.Type(EnvActionNoteEntity::class, name = "NOTE"),
)
abstract class EnvActionEntity(
open val id: UUID,
open val actionType: ActionTypeEnum,
open val actionStartDateTimeUtc: ZonedDateTime? = null,
open val actionEndDateTimeUtc: ZonedDateTime? = null,
open val department: String? = null,
open val facade: String? = null,
@JsonDeserialize(using = GeometryDeserializer::class) open val geom: Geometry? = null,
open val isAdministrativeControl: Boolean? = null,
open val isComplianceWithWaterRegulationsControl: Boolean? = null,
open val isSafetyEquipmentAndStandardsComplianceControl: Boolean? = null,
open val isSeafarersControl: Boolean? = null,
open val id: UUID,
open val actionType: ActionTypeEnum,
open val actionStartDateTimeUtc: ZonedDateTime? = null,
open val actionEndDateTimeUtc: ZonedDateTime? = null,
open val department: String? = null,
open val facade: String? = null,
@JsonDeserialize(using = GeometryDeserializer::class) open val geom: Geometry? = null,
open val isAdministrativeControl: Boolean? = null,
open val isComplianceWithWaterRegulationsControl: Boolean? = null,
open val isSafetyEquipmentAndStandardsComplianceControl: Boolean? = null,
open val isSeafarersControl: Boolean? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ class AttachControlsToActionControl(
actionId: String?,
action: ExtendedFishActionEntity
): ExtendedFishActionEntity {
if (actionId != null && action != null) {
action?.controlAction?.controlAdministrative =
if (actionId != null) {
action.controlAction?.controlAdministrative =
getControlByActionId.getControlAdministrative(actionControlId = actionId)
action?.controlAction?.controlSecurity =
action.controlAction?.controlSecurity =
getControlByActionId.getControlSecurity(actionControlId = actionId)
action?.controlAction?.controlNavigation =
action.controlAction?.controlNavigation =
getControlByActionId.getControlNavigation(
actionControlId = actionId
)
action?.controlAction?.controlGensDeMer =
action.controlAction?.controlGensDeMer =
getControlByActionId.getControlGensDeMer(actionControlId = actionId)

return action
Expand All @@ -36,15 +36,15 @@ class AttachControlsToActionControl(
action: ExtendedEnvActionEntity
): ExtendedEnvActionEntity {
if (actionId != null) {
action?.controlAction?.controlAdministrative =
action.controlAction?.controlAdministrative =
getControlByActionId.getControlAdministrative(actionControlId = actionId)
action?.controlAction?.controlSecurity =
action.controlAction?.controlSecurity =
getControlByActionId.getControlSecurity(actionControlId = actionId)
action?.controlAction?.controlNavigation =
action.controlAction?.controlNavigation =
getControlByActionId.getControlNavigation(
actionControlId = actionId
)
action?.controlAction?.controlGensDeMer =
action.controlAction?.controlGensDeMer =
getControlByActionId.getControlGensDeMer(actionControlId = actionId)

return action
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class GetNavActionByIdAndMissionId(
attachControlsToActionControl.toNavAction(
actionId = id.toString(),
action = actionControl
)?.toNavAction()
).toNavAction()
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class AddOrUpdateControl(

fun addOrUpdateControlAdministrative(control: ControlAdministrativeEntity): ControlAdministrativeEntity {
val existingControl = getControlByActionId.getControlAdministrative(control.actionControlId)
var controlToSave: ControlAdministrativeEntity? = null
var controlToSave: ControlAdministrativeEntity?
if (existingControl != null) {
controlToSave = control
controlToSave.id = existingControl.id
Expand All @@ -35,7 +35,7 @@ class AddOrUpdateControl(

fun addOrUpdateControlSecurity(control: ControlSecurityEntity): ControlSecurityEntity {
val existingControl = getControlByActionId.getControlSecurity(control.actionControlId)
var controlToSave: ControlSecurityEntity? = null
var controlToSave: ControlSecurityEntity?
if (existingControl != null) {
controlToSave = control
controlToSave.id = existingControl.id
Expand All @@ -48,7 +48,7 @@ class AddOrUpdateControl(

fun addOrUpdateControlNavigation(control: ControlNavigationEntity): ControlNavigationEntity {
val existingControl = getControlByActionId.getControlNavigation(control.actionControlId)
var controlToSave: ControlNavigationEntity? = null
var controlToSave: ControlNavigationEntity?
if (existingControl != null) {
controlToSave = control
controlToSave.id = existingControl.id
Expand All @@ -61,7 +61,7 @@ class AddOrUpdateControl(

fun addOrUpdateControlGensDeMer(control: ControlGensDeMerEntity): ControlGensDeMerEntity {
val existingControl = getControlByActionId.getControlGensDeMer(control.actionControlId)
var controlToSave: ControlGensDeMerEntity? = null
var controlToSave: ControlGensDeMerEntity?
if (existingControl != null) {
controlToSave = control
controlToSave.id = existingControl.id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class AddOrUpdateInfraction(
fun execute(infraction: InfractionEntity): InfractionEntity {
// create control if it doesn't exist
// users might add infractions without having checked a control
if (infraction.controlId != null) {
return if (infraction.controlId != null) {
val savedData = infractionRepo.save(infraction).toInfractionEntity()
return savedData
savedData
} else {
// Check if any of the controls already exist
val existingControl =
Expand Down Expand Up @@ -74,7 +74,7 @@ class AddOrUpdateInfraction(

if (newControl != null) {
// save the control
val control = when (infraction.controlType) {
when (infraction.controlType) {
ControlType.ADMINISTRATIVE -> controlAdministrativeRepo.save(newControl as ControlAdministrativeEntity)
ControlType.SECURITY -> controlSecurityRepo.save(newControl as ControlSecurityEntity)
ControlType.NAVIGATION -> controlNavigationRepo.save(newControl as ControlNavigationEntity)
Expand All @@ -89,7 +89,7 @@ class AddOrUpdateInfraction(


val savedData = infractionRepo.save(infraction).toInfractionEntity()
return savedData
savedData
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import java.util.*
class GetInfractionById(private val repo: IInfractionRepository) {
fun execute(id: UUID): InfractionEntity? {
val infractionModel = repo.findById(id)
if (infractionModel.isPresent) {
return infractionModel.get().toInfractionEntity()
return if (infractionModel.isPresent) {
infractionModel.get().toInfractionEntity()
} else {
return null
null
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class ActionController(
} else if (id in fakeMissionData.getFishActionIds()) {
val fakeAction =
getFishActionsByMissionId.getFakeActions(missionId)
.first { it -> it.controlAction?.action?.id.toString() == id }
.first { it.controlAction?.action?.id.toString() == id }
return Action.fromFishAction(
fishAction = fakeAction,
missionId = missionId
Expand Down Expand Up @@ -145,10 +145,8 @@ class ActionController(
fun getActionStatus(action: Action): ActionStatusType {

// if already a status action - no need to recompute
if (action.source == MissionSourceEnum.RAPPORTNAV) {
if (action.data is NavActionStatus) {
return action.data.status
}
if (action.source == MissionSourceEnum.RAPPORTNAV && action.data is NavActionStatus) {
return action.data.status
}

// get last started status for this time and missionId
Expand Down Expand Up @@ -273,7 +271,7 @@ class ActionController(
}
}
val withReportCountNatinf =
allNatinfs?.count { it != null }
allNatinfs?.count { true }

val natinfTag = if (withReportCountNatinf == 0) {
"Sans infraction"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,24 +62,24 @@ class MissionController(

@QueryMapping
fun mission(@Argument missionId: Int): Mission? {
if (missionId in fakeMissionData.getEmptyMissionIds()) {
return if (missionId in fakeMissionData.getEmptyMissionIds()) {
var fakeMission = fakeMissionData.emptyMission(missionId)
val navMission = getNavMissionById.execute(missionId = missionId)
fakeMission.actions =
fakeMission.actions?.plus(navMission.actions.map { MissionActionEntity.NavAction(it) })
return Mission.fromMissionEntity(fakeMission)
Mission.fromMissionEntity(fakeMission)
} else if (missionId in fakeMissionData.getFullMissionIds()) {
val fakeMission = fakeMissionData.fullMission(missionId)
val navMission = getNavMissionById.execute(missionId = missionId)
fakeMission.actions =
fakeMission.actions?.plus(navMission.actions.map { MissionActionEntity.NavAction(it) })
return Mission.fromMissionEntity(fakeMission)
Mission.fromMissionEntity(fakeMission)
} else {
val envMission = getEnvMissionById.execute(missionId = missionId) ?: return null
val fishMissionActions = getFishActionsByMissionId.execute(missionId = missionId)
val navMission = getNavMissionById.execute(missionId = missionId)

return Mission.fromMissionEntity(MissionEntity(envMission, navMission, fishMissionActions))
Mission.fromMissionEntity(MissionEntity(envMission, navMission, fishMissionActions))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,6 @@ data class Mission(
val actions: List<Action>?,
val openBy: String? = null,
) {
// fun fromMissionEntity(mission: MissionEntity): Mission {
// return Mission(
// id = mission.id,
// isClosed = mission.isClosed,
// missionSource = mission.missionSource,
// startDateTimeUtc = mission.startDateTimeUtc,
// endDateTimeUtc = mission.endDateTimeUtc,
// actions = mission.actions
// )
// }

companion object {
fun fromMissionEntity(mission: MissionEntity): Mission {
val actions: List<Action>? = mission.actions?.mapNotNull { missionAction ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ data class Action(
companion object {
fun fromEnvAction(envAction: ExtendedEnvActionEntity? = null, missionId: Int): Action? {

if (envAction?.controlAction?.action != null) {
return Action(
return envAction?.controlAction?.action?.let {
Action(
id = envAction.controlAction.action.id,
missionId = missionId,
source = MissionSourceEnum.MONITORENV,
Expand All @@ -36,7 +36,7 @@ data class Action(
id = envAction.controlAction.action.id,
actionStartDateTimeUtc = it,
actionEndDateTimeUtc = envAction.controlAction.action.actionEndDateTimeUtc,
actionType = envAction.controlAction.action.actionType!!,
actionType = envAction.controlAction.action.actionType,
geom = envAction.controlAction.action.geom,
observations = envAction.controlAction.action.observations,
actionNumberOfControls = envAction.controlAction.action.actionNumberOfControls,
Expand All @@ -55,14 +55,12 @@ data class Action(
)
}
)
} else {
return null
}
}

fun fromFishAction(fishAction: ExtendedFishActionEntity, missionId: Int): Action? {
if (fishAction?.controlAction?.action != null) {
val action = fishAction?.controlAction?.action
return fishAction.controlAction?.action?.let {
val action = fishAction.controlAction?.action
return Action(
id = action.id.toString(),
missionId = missionId,
Expand Down Expand Up @@ -122,26 +120,30 @@ data class Action(
isSafetyEquipmentAndStandardsComplianceControl = action.isSafetyEquipmentAndStandardsComplianceControl,
isSeafarersControl = action.isSeafarersControl,
// controls
controlAdministrative = ControlAdministrative.fromControlAdministrativeEntity(fishAction?.controlAction?.controlAdministrative),
controlNavigation = ControlNavigation.fromControlNavigationEntity(fishAction?.controlAction?.controlNavigation),
controlSecurity = ControlSecurity.fromControlSecurityEntity(fishAction?.controlAction?.controlSecurity),
controlGensDeMer = ControlGensDeMer.fromControlGensDeMerEntity(fishAction?.controlAction?.controlGensDeMer),
controlAdministrative = ControlAdministrative.fromControlAdministrativeEntity(fishAction.controlAction?.controlAdministrative),
controlNavigation = ControlNavigation.fromControlNavigationEntity(fishAction.controlAction?.controlNavigation),
controlSecurity = ControlSecurity.fromControlSecurityEntity(fishAction.controlAction?.controlSecurity),
controlGensDeMer = ControlGensDeMer.fromControlGensDeMerEntity(fishAction.controlAction?.controlGensDeMer),
)
)
} else {
return null
}
}


fun fromNavAction(navAction: NavActionEntity): Action? {
var data: ActionData? = null
if (navAction.statusAction != null) {
data = navAction.statusAction.toNavActionStatus()
} else if (navAction.controlAction != null) {
data = navAction.controlAction.toNavActionControl()
} else if (navAction.freeNoteAction != null) {
data = navAction.freeNoteAction.toNavActionFreeNote()
when {
navAction.statusAction != null -> {
data = navAction.statusAction.toNavActionStatus()
}

navAction.controlAction != null -> {
data = navAction.controlAction.toNavActionControl()
}

navAction.freeNoteAction != null -> {
data = navAction.freeNoteAction.toNavActionFreeNote()
}
}
return Action(
id = navAction.id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ data class InfractionEnvTargetModel(
id = infractionTarget.id,
missionId = infractionTarget.missionId,
actionId = infractionTarget.actionId,
infraction = infraction?.let { it -> InfractionModel.fromInfractionEntity(it) },
infraction = infraction?.let { InfractionModel.fromInfractionEntity(it) },
vesselIdentifier = infractionTarget.vesselIdentifier,
identityControlledPerson = infractionTarget.identityControlledPerson,
vesselType = infractionTarget.vesselType.toString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ class JPAUserRepository(
@Transactional
override fun save(user: User): User? {
return try {
// user.setPassword(user.password)
val userModel = UserModel.fromUser(user, mapper)
dbUserRepository.save(userModel).toUser(mapper)
} catch (e: InvalidDataAccessApiUsageException) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ class APIFishActionRepositoryEnv(

val response = client.send(request, HttpResponse.BodyHandlers.ofString())

if (response.statusCode() in 200..299) {
return if (response.statusCode() in 200..299) {
mapper.registerModule(JtsModule())
val fishActions = mapper.readValue(response.body(), object : TypeReference<List<MissionAction>>() {})
return fishActions
mapper.readValue(response.body(), object : TypeReference<List<MissionAction>>() {})
} else {
logger.info("Failed to fetch data. Status code: ${response.statusCode()}")
return listOf()
emptyList()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ abstract class AbstractDBTests {

companion object {
@JvmStatic
val container = PostgreSQLContainer("postgres:15.5-alpine")
val container = PostgreSQLContainer("postgres:15.6-alpine")
.apply {
withExposedPorts(5432)
withEnv("POSTGRES_DB", "testdb")
Expand Down
Loading

0 comments on commit 4b29b62

Please sign in to comment.