wip: LoggerService
This commit is contained in:
@@ -69,6 +69,9 @@ public class MembreService {
|
||||
@Inject
|
||||
RegisterRepository registerRepository;
|
||||
|
||||
@Inject
|
||||
LoggerService ls;
|
||||
|
||||
public SimpleCombModel find(int licence, String np) throws Throwable {
|
||||
return VertxContextSupport.subscribeAndAwait(() -> Panache.withTransaction(() ->
|
||||
repository.find(
|
||||
@@ -139,16 +142,6 @@ public class MembreService {
|
||||
.map(l -> membres.stream().map(m -> SimpleMembreInOutData.fromModel(m, l)).toList()));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
public Uni<List<SimpleMembre>> getSimilar(String fname, String lname) {
|
||||
return repository.listAll().map(membreModels -> membreModels.stream()
|
||||
.filter(m -> StringSimilarity.similarity(m.getFname(), fname) <= 3 &&
|
||||
StringSimilarity.similarity(m.getLname(), lname) <= 3)
|
||||
.map(SimpleMembre::fromModel).toList());
|
||||
}+
|
||||
*/
|
||||
|
||||
public Uni<String> allImporte(String subject, List<SimpleMembreInOutData> data) {
|
||||
if (data == null)
|
||||
return Uni.createFrom().nullItem();
|
||||
@@ -187,40 +180,58 @@ public class MembreService {
|
||||
return mm;
|
||||
});
|
||||
|
||||
if ((model.getId() != null && StringSimilarity.similarity(model.getLname().toUpperCase(),
|
||||
dataIn.getNom()
|
||||
.toUpperCase()) > 3) || (model.getId() != null && StringSimilarity.similarity(
|
||||
boolean add = model.getId() == null;
|
||||
Uni<Void> log = Uni.createFrom().voidItem();
|
||||
|
||||
if ((!add && StringSimilarity.similarity(model.getLname().toUpperCase(),
|
||||
dataIn.getNom().toUpperCase()) > 3) || (!add && StringSimilarity.similarity(
|
||||
model.getFname().toUpperCase(), dataIn.getPrenom().toUpperCase()) > 3)) {
|
||||
throw new DBadRequestException(
|
||||
"Pour enregistrer un nouveau membre, veuillez laisser le champ licence vide.");
|
||||
}
|
||||
|
||||
ls.logChange("Nom", model.getLname(), dataIn.getNom().toUpperCase(), model);
|
||||
ls.logChange("Prénom", model.getFname(),
|
||||
dataIn.getPrenom().toUpperCase().charAt(0) + dataIn.getPrenom().substring(1), model);
|
||||
|
||||
model.setLname(dataIn.getNom().toUpperCase());
|
||||
model.setFname(dataIn.getPrenom().toUpperCase().charAt(0) + dataIn.getPrenom().substring(1));
|
||||
|
||||
if (dataIn.getEmail() != null && !dataIn.getEmail().isBlank())
|
||||
|
||||
if (dataIn.getEmail() != null && !dataIn.getEmail().isBlank()) {
|
||||
ls.logChange("Email", model.getEmail(), dataIn.getEmail(), model);
|
||||
model.setEmail(dataIn.getEmail());
|
||||
}
|
||||
model.setGenre(Genre.fromString(dataIn.getGenre()));
|
||||
if (dataIn.getBirthdate() != null) {
|
||||
if (!Objects.equals(model.getBirth_date().getTime(), dataIn.getBirthdate().getTime()))
|
||||
ls.logChange("Date de naissance", model.getBirth_date(), dataIn.getBirthdate(), model);
|
||||
model.setBirth_date(dataIn.getBirthdate());
|
||||
model.setCategorie(Utils.getCategoryFormBirthDate(model.getBirth_date(), new Date()));
|
||||
}
|
||||
|
||||
uniResult = uniResult.call(() -> Panache.withTransaction(() -> repository.persist(model)
|
||||
.chain(membreModel1 -> dataIn.isLicenceCurrent() ? licenceRepository.find(
|
||||
"membre.id = ?1 AND saison = ?2", membreModel1.getId(), Utils.getSaison())
|
||||
.firstResult()
|
||||
.call(l -> {
|
||||
if (l == null) {
|
||||
l = new LicenceModel();
|
||||
l.setMembre(membreModel1);
|
||||
l.setValidate(false);
|
||||
l.setSaison(Utils.getSaison());
|
||||
}
|
||||
l.setCertificate(dataIn.getCertif());
|
||||
return licenceRepository.persist(l);
|
||||
}) : licenceRepository.delete(
|
||||
"membre = ?1 AND saison = ?2 AND validate = false", membreModel1,
|
||||
Utils.getSaison()))));
|
||||
uniResult = uniResult
|
||||
.call(() -> Panache.withTransaction(() -> repository.persist(model)
|
||||
.chain(membreModel1 -> dataIn.isLicenceCurrent() ? licenceRepository.find(
|
||||
"membre.id = ?1 AND saison = ?2", membreModel1.getId(),
|
||||
Utils.getSaison())
|
||||
.firstResult()
|
||||
.call(l -> {
|
||||
if (l == null) {
|
||||
l = new LicenceModel();
|
||||
l.setMembre(membreModel1);
|
||||
l.setValidate(false);
|
||||
l.setSaison(Utils.getSaison());
|
||||
}
|
||||
l.setCertificate(dataIn.getCertif());
|
||||
return licenceRepository.persist(l);
|
||||
}) : licenceRepository.delete(
|
||||
"membre = ?1 AND saison = ?2 AND validate = false", membreModel1,
|
||||
Utils.getSaison()))));
|
||||
if (add)
|
||||
uniResult = uniResult.call(() -> ls.logAAdd(model));
|
||||
else
|
||||
uniResult = uniResult.call(() -> ls.append());
|
||||
}
|
||||
return uniResult;
|
||||
}))
|
||||
|
||||
Reference in New Issue
Block a user