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

[Missions] Afficher un message d'avertissement quand une mission est déjà ouverte sur une unité #948

Merged
merged 8 commits into from
Nov 15, 2023

Conversation

louptheron
Copy link
Collaborator

@louptheron louptheron requested a review from claire2212 November 7, 2023 15:46
.first { controlUnit -> controlUnit.first.id == entry.first }.first

Pair(controlUnit, entry.second)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

ca me paraît complexe de faire trois fonctions pour ce résultat mais je m'y connais pas assez pour trouver une autre manière de faire :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Pareil, c'est la dernière étape (l. 42) qui est un peu dommage, à mon sens avant c'est indispensable (flatMap + groupBy).

En gros le groupBy doit être fait sur un id (ici), donc par la suite je dois re-composer l'objet (ici)

@ivangabriele t'aurais une idée ?

Copy link
Contributor

Choose a reason for hiding this comment

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

        // Create a list of pairs `(LegacyControlUnit, MissionSourceEnum)`
        val controlUnitAndMissionSourcePairs = openedMissions.flatMap { mission ->
            mission.mission.controlUnits.map { controlUnit ->
                logger.info("DBG ${controlUnit.id} - ${controlUnit.name}")
                controlUnit to mission.mission.missionSource
            }
        }

        // Group them by ControlUnit into a map `LegacyControlUnitEntity => List<MissionSourceEnum>`
        val controlUnitToMissionSources = controlUnitAndMissionSourcePairs.groupBy({ it.first }, { it.second })
            // Remove duplicates from each map entry values
            .map { (controlUnit, missionSources) ->
                ControlUnitToMissionSources(
                    controlUnit,
                    missionSources.distinct(),
                )
            }

        logger.info("Found ${controlUnitToMissionSources.size} engaged control unit(s).")

        return controlUnitToMissionSources

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

J'avais essayé cette méthode, ça ne fonctionnait pas, ça ne regroupait pas par controlUnit. Je n'ai pas compris pourquoi, alors que le groupby est censé utilisé equals

@louptheron louptheron force-pushed the loup/show-warning-on-engaged-control-units-v2 branch from c84cc52 to d9df20e Compare November 15, 2023 09:18
@louptheron louptheron merged commit 6d3f9ec into main Nov 15, 2023
@louptheron louptheron deleted the loup/show-warning-on-engaged-control-units-v2 branch November 15, 2023 10:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants