Skip to content

Commit

Permalink
Corrige la mise à jour des dates de la table hydrant lors de l'envoi …
Browse files Browse the repository at this point in the history
…des visites

Issue: #201895
Change-Id: I68367a175962d921825b826eaa6c0b0471e6e9fe
  • Loading branch information
Emilie Genton committed Jan 8, 2024
1 parent 26bc4ff commit 4ba74ec
Showing 1 changed file with 34 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import java.time.Instant;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import javax.inject.Inject;
import javax.inject.Provider;
import org.jooq.Condition;
Expand Down Expand Up @@ -252,26 +254,8 @@ public HydrantVisite addVisite(HydrantVisite visite, Long organismeId) {

TableField<Record, Instant> field = null;

TypeVisite typeVisite;
try {
typeVisite = TypeVisite.valueOf(codeTypeVisite);
switch (typeVisite) {
case CREATION:
field = HYDRANT.DATE_CREA;
break;

case RECEPTION:
field = HYDRANT.DATE_RECEP;
break;

case RECONNAISSANCE:
field = HYDRANT.DATE_RECO;
break;

case CONTROLE:
field = HYDRANT.DATE_CONTR;
break;
}
field = findFieldDate(codeTypeVisite);
} catch (IllegalArgumentException iae) {
// rien à faire
}
Expand Down Expand Up @@ -399,27 +383,9 @@ public void deleteVisite(HydrantVisite visite, String codeVisite) {
}

// On met à jour la date dans la table hydrant
TypeVisite typeVisite;
TableField<Record, Instant> field = null;
try {
typeVisite = TypeVisite.valueOf(codeVisite);
switch (typeVisite) {
case CREATION:
field = HYDRANT.DATE_CREA;
break;

case RECEPTION:
field = HYDRANT.DATE_RECEP;
break;

case RECONNAISSANCE:
field = HYDRANT.DATE_RECO;
break;

case CONTROLE:
field = HYDRANT.DATE_CONTR;
break;
}
field = findFieldDate(codeVisite);
} catch (IllegalArgumentException iae) {
// rien à faire
}
Expand Down Expand Up @@ -509,4 +475,34 @@ public HydrantVisite getLatestVisite(Long idHydrant) {
.limit(1)
.fetchOneInto(HydrantVisite.class);
}

private TableField<Record, Instant> findFieldDate(String codeTypeVisite) {
TableField<Record, Instant> field = null;
Optional<TypeVisite> optionalTypeVisite =
Arrays.stream(TypeVisite.values())
.filter(it -> it.getCode().equals(codeTypeVisite))
.findFirst();
if (optionalTypeVisite.isEmpty()) {
return null;
}
TypeVisite typeVisite = optionalTypeVisite.get();
switch (typeVisite) {
case CREATION:
field = HYDRANT.DATE_CREA;
break;

case RECEPTION:
field = HYDRANT.DATE_RECEP;
break;

case RECONNAISSANCE:
field = HYDRANT.DATE_RECO;
break;

case CONTROLE:
field = HYDRANT.DATE_CONTR;
break;
}
return field;
}
}

0 comments on commit 4ba74ec

Please sign in to comment.