-
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.
Revoit le useCase des visites de l'API...
... on utilise les "moments" plutôt que java.util.Date, on met les requêtes dans des repositories, on crée des constantes et enum pour les valeurs prédéfinies, et on factorise ce qui peut l'être Change-Id: Ie66f7fdbe9e8b916d8dff68728a6fd3fa6b070e5
- Loading branch information
Showing
13 changed files
with
1,156 additions
and
921 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
api-remocra/api/src/main/java/fr/sdis83/remocra/repository/HydrantAnomalieRepository.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,28 @@ | ||
package fr.sdis83.remocra.repository; | ||
|
||
import org.jooq.DSLContext; | ||
|
||
import javax.inject.Inject; | ||
|
||
import static fr.sdis83.remocra.db.model.remocra.tables.HydrantAnomalies.HYDRANT_ANOMALIES; | ||
|
||
public class HydrantAnomalieRepository { | ||
|
||
private final DSLContext context; | ||
|
||
|
||
|
||
|
||
@Inject | ||
public HydrantAnomalieRepository(DSLContext context) { | ||
this.context = context; | ||
} | ||
|
||
public void insertAnomalie(Long peiId, long anomalieId) { | ||
context | ||
.insertInto(HYDRANT_ANOMALIES) | ||
.set(HYDRANT_ANOMALIES.HYDRANT, peiId) | ||
.set(HYDRANT_ANOMALIES.ANOMALIES, anomalieId) | ||
.execute(); | ||
} | ||
} |
439 changes: 253 additions & 186 deletions
439
api-remocra/api/src/main/java/fr/sdis83/remocra/repository/HydrantVisitesRepository.java
Large diffs are not rendered by default.
Oops, something went wrong.
706 changes: 359 additions & 347 deletions
706
api-remocra/api/src/main/java/fr/sdis83/remocra/repository/PeiRepository.java
Large diffs are not rendered by default.
Oops, something went wrong.
72 changes: 72 additions & 0 deletions
72
...remocra/api/src/main/java/fr/sdis83/remocra/repository/TypeHydrantAnomalieRepository.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,72 @@ | ||
package fr.sdis83.remocra.repository; | ||
|
||
import fr.sdis83.remocra.authn.CurrentUser; | ||
import fr.sdis83.remocra.authn.UserInfo; | ||
import fr.sdis83.remocra.db.model.remocra.tables.pojos.TypeHydrantAnomalie; | ||
import org.jooq.DSLContext; | ||
|
||
import javax.inject.Inject; | ||
import javax.inject.Provider; | ||
|
||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
import static fr.sdis83.remocra.db.model.remocra.Tables.HYDRANT_ANOMALIES; | ||
import static fr.sdis83.remocra.db.model.remocra.Tables.TYPE_HYDRANT_ANOMALIE; | ||
import static fr.sdis83.remocra.db.model.remocra.Tables.TYPE_HYDRANT_ANOMALIE_NATURE; | ||
import static fr.sdis83.remocra.db.model.remocra.Tables.TYPE_HYDRANT_ANOMALIE_NATURE_SAISIES; | ||
import static fr.sdis83.remocra.db.model.remocra.Tables.TYPE_HYDRANT_NATURE; | ||
import static fr.sdis83.remocra.db.model.remocra.Tables.TYPE_HYDRANT_SAISIE; | ||
|
||
public class TypeHydrantAnomalieRepository { | ||
private final DSLContext context; | ||
|
||
@Inject | ||
@CurrentUser | ||
Provider<UserInfo> currentUser; | ||
|
||
@Inject | ||
public TypeHydrantAnomalieRepository(DSLContext context) { | ||
this.context = context; | ||
} | ||
|
||
public List<TypeHydrantAnomalie> getAll() { | ||
return context.selectFrom(TYPE_HYDRANT_ANOMALIE).fetchInto(TypeHydrantAnomalie.class); | ||
} | ||
|
||
public int getNbAnomaliesChecked(String codeTypeVisite, String codeTypeHydrantNature, List<String> controlees) { | ||
return context | ||
.selectCount() | ||
.from(TYPE_HYDRANT_ANOMALIE) | ||
.join(TYPE_HYDRANT_ANOMALIE_NATURE).on(TYPE_HYDRANT_ANOMALIE_NATURE.ANOMALIE.eq(TYPE_HYDRANT_ANOMALIE.ID)) | ||
.join(TYPE_HYDRANT_ANOMALIE_NATURE_SAISIES).on(TYPE_HYDRANT_ANOMALIE_NATURE_SAISIES.TYPE_HYDRANT_ANOMALIE_NATURE.eq(TYPE_HYDRANT_ANOMALIE_NATURE.ID)) | ||
.join(TYPE_HYDRANT_SAISIE).on(TYPE_HYDRANT_SAISIE.ID.eq(TYPE_HYDRANT_ANOMALIE_NATURE_SAISIES.SAISIES)) | ||
.join(TYPE_HYDRANT_NATURE).on(TYPE_HYDRANT_ANOMALIE_NATURE.NATURE.eq(TYPE_HYDRANT_NATURE.ID)) | ||
.where(TYPE_HYDRANT_SAISIE.CODE.equalIgnoreCase(codeTypeVisite) | ||
.and(TYPE_HYDRANT_NATURE.CODE.eq(codeTypeHydrantNature)) | ||
.and(TYPE_HYDRANT_ANOMALIE.CODE.in(controlees))) | ||
.fetchOneInto(Integer.class); | ||
} | ||
|
||
public List<TypeHydrantAnomalie> getAnomaliesSysteme() { | ||
return context | ||
.selectFrom(TYPE_HYDRANT_ANOMALIE) | ||
.where(TYPE_HYDRANT_ANOMALIE.CRITERE.isNull()) | ||
.fetchInto(TypeHydrantAnomalie.class); | ||
} | ||
|
||
public void deleteAnomaliesNonSysteme(Long peiId) { | ||
Collection<Long> anomaliesSysteme = getAnomaliesSysteme() | ||
.stream() | ||
.map(TypeHydrantAnomalie::getId) | ||
.collect(Collectors.toList()); | ||
|
||
// Suppression des anomalies (hors anomalies système) enregistrées de cet hydrant | ||
context | ||
.deleteFrom(HYDRANT_ANOMALIES) | ||
.where(HYDRANT_ANOMALIES.HYDRANT.eq(peiId).and(HYDRANT_ANOMALIES.ANOMALIES.notIn(anomaliesSysteme))) | ||
.execute(); | ||
} | ||
|
||
} |
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
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
28 changes: 28 additions & 0 deletions
28
api-remocra/api/src/main/java/fr/sdis83/remocra/usecase/utils/DateUtils.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,28 @@ | ||
package fr.sdis83.remocra.usecase.utils; | ||
|
||
import java.time.ZoneId; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
|
||
/** | ||
* Classe utilitaire pour tous les objets "date" | ||
* On passe par une représentation en ZoneDateTime pour gérer la différence de fuseau, | ||
* en BDD on est sur de l'UTC mais sur le front et les appels, on veut l'heure en GMT+1 | ||
*/ | ||
public class DateUtils { | ||
/** | ||
* Pattern attendu pour les chaînes représentatives d'une date (moment) | ||
*/ | ||
public static final String PATTERN = "yyyy-MM-dd HH:mm:ss"; | ||
|
||
/** | ||
* Retourne un moment (ZoneDateTime) à partir d'une chaîne de date à l'heure "naturelle" | ||
* @param dateString String | ||
* @return ZonedDateTime | ||
* @throws DateTimeParseException si le format PATTERN n'est pas respecté | ||
*/ | ||
public static ZonedDateTime getMoment(String dateString) throws DateTimeParseException { | ||
return ZonedDateTime.parse(dateString, DateTimeFormatter.ofPattern(PATTERN).withZone(ZoneId.systemDefault())); | ||
} | ||
} |
Oops, something went wrong.