Skip to content

Commit

Permalink
Modifie les appels en dur aux types de visites sous forme de chaîne...
Browse files Browse the repository at this point in the history
... pour les remplacer par des appels au type énuméré

Change-Id: I0da41c20dd7fd6031a9f4af5a6e7d1c096a45b42
  • Loading branch information
hboAtol committed Jan 9, 2024
1 parent f385e9f commit fb20422
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ private int getNbVisitesCtrlWithCondition(long idHydrant, Condition predicatInst
HYDRANT_VISITE
.HYDRANT
.eq(idHydrant)
.and(TYPE_HYDRANT_SAISIE.CODE.eq("CTRL"))
.and(TYPE_HYDRANT_SAISIE.CODE.eq(GlobalConstants.TypeVisite.CONTROLE.getCode()))
.and(HYDRANT_VISITE.CTRL_DEBIT_PRESSION)
.and(predicatInstant))
.fetchOneInto(int.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package fr.sdis83.remocra.repository;

import static fr.sdis83.remocra.GlobalConstants.TypeVisite;
import static fr.sdis83.remocra.db.model.remocra.Tables.HYDRANT;
import static fr.sdis83.remocra.db.model.remocra.Tables.HYDRANT_ANOMALIES;
import static fr.sdis83.remocra.db.model.remocra.Tables.HYDRANT_PIBI;
Expand Down Expand Up @@ -86,26 +87,28 @@ public HydrantVisite addVisiteFromFiche(Long id, String visiteData) throws Excep
.where(HYDRANT_VISITE.HYDRANT.eq(id))
.fetchOneInto(Integer.class);

String typeVisite =
String strTypeVisite =
context
.select(TYPE_HYDRANT_SAISIE.CODE)
.from(TYPE_HYDRANT_SAISIE)
.where(TYPE_HYDRANT_SAISIE.ID.eq(JSONUtil.getLong(data, "type")))
.fetchOneInto(String.class);

if (nbVisites == 0 && !typeVisite.toUpperCase().equals("CREA")) {
TypeVisite typeVisite = TypeVisite.fromCode(strTypeVisite.toUpperCase());

if (nbVisites == 0 && !typeVisite.equals(TypeVisite.CREATION)) {
throw new Exception(
"Le contexte de visite doit être de type CREA (première visite du PEI)");
} else if (nbVisites == 1 && !typeVisite.toUpperCase().equals("RECEP")) {
} else if (nbVisites == 1 && !typeVisite.equals(TypeVisite.RECEPTION)) {
throw new Exception(
"Le contexte de visite doit être de type RECEP (deuxième visite du PEI)");
} else if (nbVisites > 1
&& (!typeVisite.toUpperCase().equals("NP")
&& !typeVisite.toUpperCase().equals("RECO")
&& !typeVisite.equals("CTRL"))) {
&& (!typeVisite.equals(TypeVisite.NON_PROGRAMMEE)
&& !typeVisite.equals(TypeVisite.RECONNAISSANCE)
&& !typeVisite.equals(TypeVisite.CONTROLE))) {
throw new Exception(
"Une visite de type "
+ typeVisite.toUpperCase()
+ typeVisite.getCode()
+ " existe déjà. Veuillez utiliser une visite de type NP, RECO ou CTRL");
}

Expand Down Expand Up @@ -268,17 +271,18 @@ public HydrantVisite addVisite(HydrantVisite visite) {
.fetchOneInto(String.class);

TableField<Record, Instant> field = null;
switch (codeTypeVisite) {
case "CREA":
TypeVisite typeVisite = TypeVisite.fromCode(codeTypeVisite);
switch (typeVisite) {
case CREATION:
field = HYDRANT.DATE_CREA;
break;
case "RECEP":
case RECEPTION:
field = HYDRANT.DATE_RECEP;
break;
case "RECO":
case RECONNAISSANCE:
field = HYDRANT.DATE_RECO;
break;
case "CTRL":
case CONTROLE:
field = HYDRANT.DATE_CONTR;
break;
}
Expand Down Expand Up @@ -375,17 +379,18 @@ private void deleteVisite(HydrantVisite visite) {
}
// On met à jour la date dans la table hydrant
TableField<Record, Instant> field = null;
switch (codeVisite) {
case "CREA":
TypeVisite typeVisite = TypeVisite.fromCode(codeVisite);
switch (typeVisite) {
case CREATION:
field = HYDRANT.DATE_CREA;
break;
case "RECEP":
case RECEPTION:
field = HYDRANT.DATE_RECEP;
break;
case "RECO":
case RECONNAISSANCE:
field = HYDRANT.DATE_RECO;
break;
case "CTRL":
case CONTROLE:
field = HYDRANT.DATE_CONTR;
break;
}
Expand Down Expand Up @@ -451,7 +456,7 @@ public Long getIdControle() {
return context
.select(TYPE_HYDRANT_SAISIE.ID)
.from(TYPE_HYDRANT_SAISIE)
.where(TYPE_HYDRANT_SAISIE.CODE.equalIgnoreCase("CTRL"))
.where(TYPE_HYDRANT_SAISIE.CODE.equalIgnoreCase(TypeVisite.CONTROLE.getCode()))
.fetchOneInto(Long.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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_SAISIE;

import fr.sdis83.remocra.GlobalConstants;
import fr.sdis83.remocra.db.model.remocra.Tables;
import fr.sdis83.remocra.db.model.remocra.tables.pojos.TypeHydrantAnomalie;
import java.util.List;
Expand Down Expand Up @@ -39,7 +40,8 @@ public List<Long> getIdsAnomaliesCTP() {
TYPE_HYDRANT_ANOMALIE_NATURE.ID))
.join(TYPE_HYDRANT_SAISIE)
.on(TYPE_HYDRANT_SAISIE.ID.eq(TYPE_HYDRANT_ANOMALIE_NATURE_SAISIES.SAISIES))
.where(TYPE_HYDRANT_SAISIE.CODE.equalIgnoreCase("CTRL"))
.where(
TYPE_HYDRANT_SAISIE.CODE.equalIgnoreCase(GlobalConstants.TypeVisite.CONTROLE.getCode()))
.fetchInto(Long.class);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -1404,7 +1404,7 @@ private Hydrant.TYPE_SAISIE getTypeSaisie(Hydrant hydrant, String typeSaisie)
return Hydrant.TYPE_SAISIE.RECEP;
} else if (authUtils.hasRight(TypeDroitEnum.HYDRANTS_CONTROLE_C)
&& authUtils.hasRight(TypeDroitEnum.HYDRANTS_RECONNAISSANCE_C)) {
return (typeSaisie != null && "CTRL".equals(typeSaisie))
return (GlobalConstants.TypeVisite.CONTROLE.getCode().equals(typeSaisie))
? Hydrant.TYPE_SAISIE.CTRL
: Hydrant.TYPE_SAISIE.RECO;
} else if (authUtils.hasRight(TypeDroitEnum.HYDRANTS_CONTROLE_C)) {
Expand Down

0 comments on commit fb20422

Please sign in to comment.