-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajoute la récupération dynamique des caractéristiques des PEI
Change-Id: Ic4f88917877bfc177b52af16551ea5ec5c49e0e2
- Loading branch information
Showing
5 changed files
with
279 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
...a/api/src/main/java/fr/sdis83/remocra/usecase/referentiel/PeiCaracteristiquesUseCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package fr.sdis83.remocra.usecase.referentiel; | ||
|
||
import fr.sdis83.remocra.db.model.remocra.tables.pojos.Parametre; | ||
import fr.sdis83.remocra.enums.PeiCaracteristique; | ||
import fr.sdis83.remocra.repository.ParametreRepository; | ||
import fr.sdis83.remocra.repository.ReferentielRepository; | ||
import fr.sdis83.remocra.util.GlobalConstants; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
import javax.inject.Inject; | ||
|
||
/** | ||
* UseCase permettant de gérer la récupération dynamique des caractéristiques des PEI, et leur | ||
* transformation en vue d'être affichées par l'appli mobile | ||
*/ | ||
public class PeiCaracteristiquesUseCase { | ||
|
||
@Inject ReferentielRepository referentielRepository; | ||
|
||
@Inject ParametreRepository parametreRepository; | ||
|
||
@Inject | ||
public Map<Long, String> getPeiCaracteristiques() { | ||
Map<String, Parametre> mapParametres = | ||
parametreRepository.getParametres( | ||
Set.of( | ||
GlobalConstants.PARAMETRE_CARACTERISTIQUE_PIBI, | ||
GlobalConstants.PARAMETRE_CARACTERISTIQUE_PENA)); | ||
|
||
String pibiSelectedCaracteristiques = | ||
mapParametres.get(GlobalConstants.PARAMETRE_CARACTERISTIQUE_PIBI).getValeurParametre(); | ||
String penaSelectedCaracteristiques = | ||
mapParametres.get(GlobalConstants.PARAMETRE_CARACTERISTIQUE_PENA).getValeurParametre(); | ||
Map<Long, List<ReferentielRepository.PeiCaracteristiquePojo>> map = | ||
referentielRepository.getPeiCaracteristiques( | ||
fromStringParameter(pibiSelectedCaracteristiques), | ||
fromStringParameter(penaSelectedCaracteristiques)); | ||
|
||
// On transforme la liste de caractéristiques en HTML (liste à puces dans une DIV) | ||
Map<Long, String> mapRetour = new HashMap<>(); | ||
map.forEach( | ||
(key, value) -> { | ||
String decorated = | ||
"<div><ul>" | ||
+ value.stream() | ||
.map( | ||
it -> | ||
"<li>" | ||
+ it.getCaracteristique().getLibelle() | ||
+ " : " | ||
+ it.getValue() | ||
+ "</li>") | ||
.collect(Collectors.joining()) | ||
+ "</ul></div>"; | ||
mapRetour.put(key, decorated); | ||
}); | ||
|
||
return mapRetour; | ||
} | ||
|
||
private static List<PeiCaracteristique> fromStringParameter(String selectedCaracteristiques) { | ||
return Arrays.stream(selectedCaracteristiques.split(",")) | ||
.map(String::trim) | ||
.map(PeiCaracteristique::fromString) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters