Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(action): update mission action #452

Merged
merged 9 commits into from
Dec 25, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,23 @@ abstract class BaseControlEntity {
open val observations: String? = null
open val hasBeenDone: Boolean? = null
abstract fun shouldToggleOnUnitHasConfirmed(): Boolean


override fun hashCode(): Int {
var result = id.hashCode()
result = 31 * result + actionControlId.hashCode()
result = 31 * result + (observations?.hashCode() ?: 0)
result = 31 * result + (hasBeenDone?.hashCode() ?: 0)
return result
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false
other as BaseControlEntity
return (id == other.id
&& hasBeenDone == other.hasBeenDone
&& observations == other.observations
&& actionControlId == other.actionControlId)
}
Comment on lines +17 to +33
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Par curiosité, ca fait quoi ça ?
Je suis toujours pas clair avec ces hashCode et equals

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Je vais checker que les controls sont identiques. s'ils le sont je ne les update pas.
du coup pour vérifier l'égalité == vérifie qu'on à la même adresse dans la heap (la mémoire)
a.equals(b) qu'on a le même contenu
mais quand tu modifies (override) la méthode equals tu dois modifé la méthode hascode
Pourquoi?
hashCode et un méthode de calcul du clé de crypto (le hash)
on a 2 objets: a, b

  • si a.hashcode != b.hashcode alors A et B ne peuvent pas être égaux, c'est le premier check ca ne sert à rien de de faire appel à la méthode equals.
  • si a.hashcode == b.hashcode ca ne veut pas dire qu'ils sont égaux.. mais ca veut dire on peut passer à la suite du check.

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data class ControlAdministrativeEntity(
val compliantSecurityDocuments: ControlResult? = null,
override val observations: String? = null,
override val hasBeenDone: Boolean? = null,
override val infractions: List<InfractionEntity>? = null
override var infractions: List<InfractionEntity>? = null
) : BaseControlEntity() {
override fun shouldToggleOnUnitHasConfirmed(): Boolean =
unitShouldConfirm == true &&
Expand All @@ -26,4 +26,23 @@ data class ControlAdministrativeEntity(
infractions?.isNotEmpty() == true ||
observations != null
)

override fun hashCode(): Int {
var result = missionId.hashCode()
result = 31 * result + amountOfControls
result = 31 * result + (compliantOperatingPermit?.hashCode() ?: 0)
result = 31 * result + (upToDateNavigationPermit?.hashCode() ?: 0)
result = 31 * result + (compliantSecurityDocuments?.hashCode() ?: 0)
return super.hashCode() + result
}

override fun equals(other: Any?): Boolean {
if (!super.equals(other)) return false
other as ControlAdministrativeEntity
return (missionId == other.missionId
&& amountOfControls == other.amountOfControls
&& compliantOperatingPermit == other.compliantOperatingPermit
&& upToDateNavigationPermit == other.upToDateNavigationPermit
&& compliantSecurityDocuments == other.compliantSecurityDocuments)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data class ControlGensDeMerEntity(
val knowledgeOfFrenchLawAndLanguage: ControlResult? = null,
override val observations: String? = null,
override val hasBeenDone: Boolean? = null,
override val infractions: List<InfractionEntity>? = null
override var infractions: List<InfractionEntity>? = null
) : BaseControlEntity() {
override fun shouldToggleOnUnitHasConfirmed(): Boolean =
unitShouldConfirm == true &&
Expand All @@ -26,4 +26,23 @@ data class ControlGensDeMerEntity(
infractions?.isNotEmpty() == true ||
observations != null
)

override fun hashCode(): Int {
var result = missionId.hashCode()
result = 31 * result + amountOfControls
result = 31 * result + (staffOutnumbered?.hashCode() ?: 0)
result = 31 * result + (upToDateMedicalCheck?.hashCode() ?: 0)
result = 31 * result + (knowledgeOfFrenchLawAndLanguage?.hashCode() ?: 0)
return super.hashCode() + result
}

override fun equals(other: Any?): Boolean {
if (!super.equals(other)) return false
other as ControlGensDeMerEntity
return (missionId == other.missionId
&& amountOfControls == other.amountOfControls
&& staffOutnumbered == other.staffOutnumbered
&& upToDateMedicalCheck == other.upToDateMedicalCheck
&& knowledgeOfFrenchLawAndLanguage == other.knowledgeOfFrenchLawAndLanguage)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data class ControlNavigationEntity(
override var unitHasConfirmed: Boolean? = null,
override val observations: String? = null,
override val hasBeenDone: Boolean? = null,
override val infractions: List<InfractionEntity>? = null
override var infractions: List<InfractionEntity>? = null
) : BaseControlEntity() {
override fun shouldToggleOnUnitHasConfirmed(): Boolean =
unitShouldConfirm == true &&
Expand All @@ -21,4 +21,17 @@ data class ControlNavigationEntity(
infractions?.isNotEmpty() == true ||
observations != null
)

override fun hashCode(): Int {
var result = missionId.hashCode()
result = 31 * result + amountOfControls
return super.hashCode() + result
}

override fun equals(other: Any?): Boolean {
if (!super.equals(other)) return false
other as ControlNavigationEntity
return (missionId == other.missionId
&& amountOfControls == other.amountOfControls)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ data class ControlSecurityEntity(
override var unitHasConfirmed: Boolean? = null,
override val observations: String? = null,
override val hasBeenDone: Boolean? = null,
override val infractions: List<InfractionEntity>? = null
override var infractions: List<InfractionEntity>? = null
) : BaseControlEntity() {
override fun shouldToggleOnUnitHasConfirmed(): Boolean =
unitShouldConfirm == true &&
Expand All @@ -21,4 +21,17 @@ data class ControlSecurityEntity(
infractions?.isNotEmpty() == true ||
observations != null
)

override fun hashCode(): Int {
var result = missionId.hashCode()
result = 31 * result + amountOfControls
return super.hashCode() + result
}

override fun equals(other: Any?): Boolean {
if (!super.equals(other)) return false
other as ControlSecurityEntity
return (missionId == other.missionId
&& amountOfControls == other.amountOfControls)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,19 @@ import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlAdmi
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlGensDeMerEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlNavigationEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.control.ControlSecurityEntity
import fr.gouv.dgampa.rapportnav.domain.entities.mission.nav.infraction.InfractionEntity

data class ActionControlEntity(
var controlAdministrative: ControlAdministrativeEntity? = null,
var controlGensDeMer: ControlGensDeMerEntity? = null,
var controlSecurity: ControlSecurityEntity? = null,
var controlNavigation: ControlNavigationEntity? = null
) {

fun seInfractions(infractions: List<InfractionEntity>?) {
controlSecurity?.infractions = infractions?.filter { it.controlId == controlSecurity?.id }
controlGensDeMer?.infractions = infractions?.filter { it.controlId == controlGensDeMer?.id }
controlNavigation?.infractions = infractions?.filter { it.controlId == controlNavigation?.id }
controlAdministrative?.infractions = infractions?.filter { it.controlId == controlAdministrative?.id }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,32 @@ data class InfractionEntity(
var observations: String? = null,
var natinfs: List<String>? = null,
var target: InfractionEnvTargetEntity? = null
)
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as InfractionEntity
return id == other.id
&& missionId == other.missionId
&& actionId == other.actionId
&& controlId == other.controlId
&& controlType == other.controlType
&& observations == other.observations
&& Objects.equals(target, other.target)
&& Objects.equals(natinfs, other.natinfs)
}

override fun hashCode(): Int {
var result = id.hashCode()
result = 31 * result + missionId
result = 31 * result + actionId.hashCode()
result = 31 * result + (controlId?.hashCode() ?: 0)
result = 31 * result + (controlType?.hashCode() ?: 0)
result = 31 * result + (infractionType?.hashCode() ?: 0)
result = 31 * result + (observations?.hashCode() ?: 0)
result = 31 * result + (natinfs?.hashCode() ?: 0)
result = 31 * result + (target?.hashCode() ?: 0)
return result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,31 @@ data class InfractionEnvTargetEntity(
var vesselType: VesselTypeEnum? = null,
var vesselSize: VesselSizeEnum? = null,
val vesselIdentifier: String? = null,
) {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

)
other as InfractionEnvTargetEntity
return id == other.id
&& missionId == other.missionId
&& actionId == other.actionId
&& infractionId == other.infractionId
&& identityControlledPerson == other.identityControlledPerson
&& vesselType == other.vesselType
&& vesselSize == other.vesselSize
&& vesselIdentifier == other.vesselIdentifier
}

override fun hashCode(): Int {
var result = id.hashCode()
result = 31 * result + missionId
result = 31 * result + actionId.hashCode()
result = 31 * result + infractionId.hashCode()
result = 31 * result + identityControlledPerson.hashCode()
result = 31 * result + (vesselType?.hashCode() ?: 0)
result = 31 * result + (vesselSize?.hashCode() ?: 0)
result = 31 * result + (vesselIdentifier?.hashCode() ?: 0)
return result
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,33 @@ interface BaseMissionFishAction {
val internalReferenceNumber: String?
val externalReferenceNumber: String?
val ircs: String?
val flagState: CountryCode
val flagState: CountryCode?
val districtCode: String?
val faoAreas: List<String>
val faoAreas: List<String>?
val fishActionType: MissionActionType
val actionDatetimeUtc: Instant
val actionDatetimeUtc: Instant?
val actionEndDatetimeUtc: Instant?
val emitsVms: ControlCheck?
val emitsAis: ControlCheck?
val flightGoals: List<FlightGoal>
val flightGoals: List<FlightGoal>?
val logbookMatchesActivity: ControlCheck?
val licencesMatchActivity: ControlCheck?
val speciesWeightControlled: Boolean?
val speciesSizeControlled: Boolean?
val separateStowageOfPreservedSpecies: ControlCheck?
val logbookInfractions: List<LogbookInfraction>
val logbookInfractions: List<LogbookInfraction>?
val licencesAndLogbookObservations: String?
val gearInfractions: List<GearInfraction>
val speciesInfractions: List<SpeciesInfraction>
val gearInfractions: List<GearInfraction>?
val speciesInfractions: List<SpeciesInfraction>?
val speciesObservations: String?
val seizureAndDiversion: Boolean?
val otherInfractions: List<OtherInfraction>
val otherInfractions: List<OtherInfraction>?
val numberOfVesselsFlownOver: Int?
val unitWithoutOmegaGauge: Boolean?
val controlQualityComments: String?
val feedbackSheetRequired: Boolean?
val userTrigram: String
val segments: List<FleetSegment>
val userTrigram: String?
val segments: List<FleetSegment>?
val facade: String?
val longitude: Double?
val latitude: Double?
Expand All @@ -49,19 +49,19 @@ interface BaseMissionFishAction {
val vesselTargeted: ControlCheck?
val seizureAndDiversionComments: String?
val otherComments: String?
val gearOnboard: List<GearControl>
val speciesOnboard: List<SpeciesControl>
val isFromPoseidon: Boolean
val gearOnboard: List<GearControl>?
val speciesOnboard: List<SpeciesControl>?
val isFromPoseidon: Boolean?
/**
* This field is only used by the `GetVesselControls` use-case.
* /!\ Do not use it to get `controlUnits` as the field will be empty be default.
*/
var controlUnits: List<ControlUnit>
val isDeleted: Boolean
val hasSomeGearsSeized: Boolean
val hasSomeSpeciesSeized: Boolean
var controlUnits: List<ControlUnit>?
val isDeleted: Boolean?
val hasSomeGearsSeized: Boolean?
val hasSomeSpeciesSeized: Boolean?
val completedBy: String?
val completion: Completion
val completion: Completion?
var observationsByUnit: String?
var speciesQuantitySeized: Int ?
}
Loading
Loading