commit
f018e52afa
@ -2,6 +2,7 @@ package fr.titionfire.ffsaf.domain.service;
|
|||||||
|
|
||||||
import fr.titionfire.ffsaf.data.model.*;
|
import fr.titionfire.ffsaf.data.model.*;
|
||||||
import fr.titionfire.ffsaf.data.repository.*;
|
import fr.titionfire.ffsaf.data.repository.*;
|
||||||
|
import fr.titionfire.ffsaf.rest.client.StateIdService;
|
||||||
import fr.titionfire.ffsaf.rest.data.SimpleAffiliation;
|
import fr.titionfire.ffsaf.rest.data.SimpleAffiliation;
|
||||||
import fr.titionfire.ffsaf.rest.data.SimpleReqAffiliation;
|
import fr.titionfire.ffsaf.rest.data.SimpleReqAffiliation;
|
||||||
import fr.titionfire.ffsaf.rest.exception.DBadRequestException;
|
import fr.titionfire.ffsaf.rest.exception.DBadRequestException;
|
||||||
@ -21,11 +22,13 @@ import io.smallrye.mutiny.unchecked.Unchecked;
|
|||||||
import jakarta.enterprise.context.ApplicationScoped;
|
import jakarta.enterprise.context.ApplicationScoped;
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
import org.eclipse.microprofile.config.inject.ConfigProperty;
|
||||||
|
import org.eclipse.microprofile.rest.client.inject.RestClient;
|
||||||
import org.hibernate.reactive.mutiny.Mutiny;
|
import org.hibernate.reactive.mutiny.Mutiny;
|
||||||
import org.jboss.logging.Logger;
|
import org.jboss.logging.Logger;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
@WithSession
|
@WithSession
|
||||||
@ -60,6 +63,9 @@ public class AffiliationService {
|
|||||||
@Inject
|
@Inject
|
||||||
LoggerService ls;
|
LoggerService ls;
|
||||||
|
|
||||||
|
@RestClient
|
||||||
|
StateIdService stateIdService;
|
||||||
|
|
||||||
@ConfigProperty(name = "upload_dir")
|
@ConfigProperty(name = "upload_dir")
|
||||||
String media;
|
String media;
|
||||||
|
|
||||||
@ -73,6 +79,8 @@ public class AffiliationService {
|
|||||||
public Uni<AffiliationRequestModel> pre_save(AffiliationRequestForm form, boolean unique) {
|
public Uni<AffiliationRequestModel> pre_save(AffiliationRequestForm form, boolean unique) {
|
||||||
AffiliationRequestModel affModel = form.toModel();
|
AffiliationRequestModel affModel = form.toModel();
|
||||||
int currentSaison = Utils.getSaison();
|
int currentSaison = Utils.getSaison();
|
||||||
|
List<String> out = new ArrayList<>();
|
||||||
|
out.add(affModel.getState_id());
|
||||||
|
|
||||||
return Uni.createFrom().item(affModel)
|
return Uni.createFrom().item(affModel)
|
||||||
.invoke(Unchecked.consumer(model -> {
|
.invoke(Unchecked.consumer(model -> {
|
||||||
@ -80,14 +88,24 @@ public class AffiliationService {
|
|||||||
throw new DBadRequestException("Saison non valid");
|
throw new DBadRequestException("Saison non valid");
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
.chain(() -> repositoryRequest.count("state_id = ?1 and saison = ?2", affModel.getState_id(),
|
.chain(() -> stateIdService.get_status(affModel.getState_id()).onItem().transform(o -> {
|
||||||
affModel.getSaison()))
|
if (o.getId_rna() != null && !o.getId_rna().isBlank())
|
||||||
.onItem().invoke(Unchecked.consumer(count -> {
|
out.add(o.getId_rna());
|
||||||
if (count != 0 && unique) {
|
if (o.getId_siren() != null && !o.getId_siren().isBlank())
|
||||||
throw new DBadRequestException("Demande d'affiliation déjà existante");
|
out.add(o.getId_siren());
|
||||||
}
|
if (o.getIdentite().getId_siret_siege() != null && !o.getIdentite().getId_siret_siege().isBlank())
|
||||||
}))
|
out.add(o.getIdentite().getId_siret_siege());
|
||||||
.chain(() -> clubRepository.find("StateId = ?1", affModel.getState_id()).firstResult().chain(club ->
|
return out;
|
||||||
|
}).onFailure().recoverWithItem(out)
|
||||||
|
.chain(a -> repositoryRequest.count("state_id IN ?1 and saison = ?2",
|
||||||
|
out, affModel.getSaison()))
|
||||||
|
.onItem().invoke(Unchecked.consumer(count -> {
|
||||||
|
if (count != 0 && unique) {
|
||||||
|
throw new DBadRequestException("Demande d'affiliation déjà existante");
|
||||||
|
}
|
||||||
|
}))
|
||||||
|
)
|
||||||
|
.chain(() -> clubRepository.find("StateId IN ?1", out).firstResult().chain(club ->
|
||||||
repository.count("club = ?1 and saison = ?2", club, affModel.getSaison())))
|
repository.count("club = ?1 and saison = ?2", club, affModel.getSaison())))
|
||||||
.onItem().invoke(Unchecked.consumer(count -> {
|
.onItem().invoke(Unchecked.consumer(count -> {
|
||||||
if (count != 0) {
|
if (count != 0) {
|
||||||
@ -349,17 +367,23 @@ public class AffiliationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private Uni<ClubModel> acceptOld(AffiliationRequestSaveForm form, AffiliationRequestModel model, ClubModel club) {
|
private Uni<ClubModel> acceptOld(AffiliationRequestSaveForm form, AffiliationRequestModel model, ClubModel club) {
|
||||||
|
AtomicBoolean nameChange = new AtomicBoolean(false);
|
||||||
LOGGER.debug("Old Club Accepted");
|
LOGGER.debug("Old Club Accepted");
|
||||||
return Uni.createFrom().nullItem()
|
return Uni.createFrom().nullItem()
|
||||||
.chain(() -> {
|
.chain(() -> {
|
||||||
club.setName(form.getName());
|
if (!form.getName().equals(club.getName())) {
|
||||||
|
club.setName(form.getName());
|
||||||
|
nameChange.set(true);
|
||||||
|
}
|
||||||
club.setCountry("FR");
|
club.setCountry("FR");
|
||||||
club.setStateId(form.getState_id());
|
club.setStateId(form.getState_id());
|
||||||
club.setAddress(form.getAddress());
|
club.setAddress(form.getAddress());
|
||||||
club.setContact_intern(form.getContact());
|
club.setContact_intern(form.getContact());
|
||||||
return Panache.withTransaction(() -> clubRepository.persist(club)
|
return Panache.withTransaction(() -> clubRepository.persist(club)
|
||||||
.chain(() -> repository.persist(new AffiliationModel(null, club, model.getSaison())))
|
.chain(() -> repository.persist(new AffiliationModel(null, club, model.getSaison())))
|
||||||
.chain(() -> repositoryRequest.delete(model)));
|
.chain(() -> repositoryRequest.delete(model)))
|
||||||
|
.call(() -> nameChange.get() ? keycloakService.updateGroupFromClub(club) // update group in keycloak
|
||||||
|
: Uni.createFrom().nullItem());
|
||||||
})
|
})
|
||||||
.map(__ -> club);
|
.map(__ -> club);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,7 @@ import org.eclipse.microprofile.config.inject.ConfigProperty;
|
|||||||
import org.hibernate.reactive.mutiny.Mutiny;
|
import org.hibernate.reactive.mutiny.Mutiny;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import static fr.titionfire.ffsaf.net2.Client_Thread.MAPPER;
|
import static fr.titionfire.ffsaf.net2.Client_Thread.MAPPER;
|
||||||
@ -193,12 +194,17 @@ public class ClubService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Uni<String> update(long id, FullClubForm input) {
|
public Uni<String> update(long id, FullClubForm input) {
|
||||||
|
AtomicBoolean nameChange = new AtomicBoolean(false);
|
||||||
|
|
||||||
return repository.findById(id).call(m -> Mutiny.fetch(m.getContact()))
|
return repository.findById(id).call(m -> Mutiny.fetch(m.getContact()))
|
||||||
.onItem().transformToUni(Unchecked.function(m -> {
|
.onItem().transformToUni(Unchecked.function(m -> {
|
||||||
TypeReference<HashMap<Contact, String>> typeRef = new TypeReference<>() {
|
TypeReference<HashMap<Contact, String>> typeRef = new TypeReference<>() {
|
||||||
};
|
};
|
||||||
|
|
||||||
m.setName(input.getName());
|
if (!input.getName().equals(m.getName())) {
|
||||||
|
m.setName(input.getName());
|
||||||
|
nameChange.set(true);
|
||||||
|
}
|
||||||
m.setCountry(input.getCountry());
|
m.setCountry(input.getCountry());
|
||||||
m.setInternational(input.isInternational());
|
m.setInternational(input.isInternational());
|
||||||
|
|
||||||
@ -228,6 +234,8 @@ public class ClubService {
|
|||||||
}
|
}
|
||||||
return Panache.withTransaction(() -> repository.persist(m)).call(() -> ls.append());
|
return Panache.withTransaction(() -> repository.persist(m)).call(() -> ls.append());
|
||||||
}))
|
}))
|
||||||
|
.call(clubModel -> nameChange.get() ? keycloakService.updateGroupFromClub(clubModel) // update group in keycloak
|
||||||
|
: Uni.createFrom().nullItem())
|
||||||
.invoke(membreModel -> SReqClub.sendIfNeed(serverCustom.clients,
|
.invoke(membreModel -> SReqClub.sendIfNeed(serverCustom.clients,
|
||||||
SimpleClubModel.fromModel(membreModel)))
|
SimpleClubModel.fromModel(membreModel)))
|
||||||
.map(__ -> "OK");
|
.map(__ -> "OK");
|
||||||
|
|||||||
@ -85,6 +85,31 @@ public class KeycloakService {
|
|||||||
return Uni.createFrom().item(club::getClubId);
|
return Uni.createFrom().item(club::getClubId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Uni<String> updateGroupFromClub(ClubModel club) {
|
||||||
|
if (club.getClubId() == null) {
|
||||||
|
return getGroupFromClub(club);
|
||||||
|
} else {
|
||||||
|
LOGGER.infof("Updating name of club group %d-%s...", club.getId(), club.getName());
|
||||||
|
return vertx.getOrCreateContext().executeBlocking(() -> {
|
||||||
|
GroupRepresentation clubGroup =
|
||||||
|
keycloak.realm(realm).groups().groups().stream().filter(g -> g.getName().equals("club"))
|
||||||
|
.findAny()
|
||||||
|
.orElseThrow(() -> new KeycloakException("Fail to fetch group %s".formatted("club")));
|
||||||
|
|
||||||
|
keycloak.realm(realm).groups().group(clubGroup.getId()).getSubGroups(0, 1000, true).stream()
|
||||||
|
.filter(g -> g.getName().startsWith(club.getId() + "-")).findAny()
|
||||||
|
.ifPresent(groupRepresentation -> {
|
||||||
|
groupRepresentation.setName(club.getId() + "-" + club.getName());
|
||||||
|
keycloak.realm(realm).groups().group(groupRepresentation.getId())
|
||||||
|
.update(groupRepresentation);
|
||||||
|
});
|
||||||
|
|
||||||
|
return club.getClubId();
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Uni<String> getUserFromMember(MembreModel membreModel) {
|
public Uni<String> getUserFromMember(MembreModel membreModel) {
|
||||||
if (membreModel.getUserId() == null) {
|
if (membreModel.getUserId() == null) {
|
||||||
return Uni.createFrom()
|
return Uni.createFrom()
|
||||||
@ -199,16 +224,16 @@ public class KeycloakService {
|
|||||||
|
|
||||||
public Uni<String> initCompte(long id) {
|
public Uni<String> initCompte(long id) {
|
||||||
return membreService.getById(id).invoke(Unchecked.consumer(membreModel -> {
|
return membreService.getById(id).invoke(Unchecked.consumer(membreModel -> {
|
||||||
if (membreModel.getUserId() != null)
|
if (membreModel.getUserId() != null)
|
||||||
throw new KeycloakException("User already linked to the user id=" + id);
|
throw new KeycloakException("User already linked to the user id=" + id);
|
||||||
if (membreModel.getEmail() == null)
|
if (membreModel.getEmail() == null)
|
||||||
throw new KeycloakException("User email is null");
|
throw new KeycloakException("User email is null");
|
||||||
if (membreModel.getFname() == null || membreModel.getLname() == null)
|
if (membreModel.getFname() == null || membreModel.getLname() == null)
|
||||||
throw new KeycloakException("User name is null");
|
throw new KeycloakException("User name is null");
|
||||||
})).chain(membreModel -> creatUser(membreModel).chain(user -> {
|
})).chain(membreModel -> creatUser(membreModel).chain(user -> {
|
||||||
LOGGER.infof("Set user id %s to membre %s", user.getId(), membreModel.getId());
|
LOGGER.infof("Set user id %s to membre %s", user.getId(), membreModel.getId());
|
||||||
return membreService.setUserId(membreModel.getId(), user.getId()).map(__ -> user.getId());
|
return membreService.setUserId(membreModel.getId(), user.getId()).map(__ -> user.getId());
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
private Uni<UserRepresentation> creatUser(MembreModel membreModel) {
|
private Uni<UserRepresentation> creatUser(MembreModel membreModel) {
|
||||||
|
|||||||
@ -15,6 +15,7 @@ public class AssoData {
|
|||||||
@RegisterForReflection
|
@RegisterForReflection
|
||||||
public static class Identite {
|
public static class Identite {
|
||||||
String nom;
|
String nom;
|
||||||
|
String id_siret_siege;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
|||||||
@ -257,7 +257,7 @@ function AssoInfo({initData, needFile}) {
|
|||||||
|
|
||||||
<div className="input-group mb-3">
|
<div className="input-group mb-3">
|
||||||
<span className="input-group-text">N° SIRET ou RNA*</span>
|
<span className="input-group-text">N° SIRET ou RNA*</span>
|
||||||
<input type="text" className="form-control" placeholder="state_id" name="state_id" required value={stateId} disabled={!needFile}
|
<input type="text" className="form-control" placeholder="N° SIRET ou RNA*" name="state_id" required value={stateId} disabled={!needFile}
|
||||||
onChange={e => setStateId(e.target.value)}/>
|
onChange={e => setStateId(e.target.value)}/>
|
||||||
<button className="btn btn-outline-secondary" type="button" id="button-addon2"
|
<button className="btn btn-outline-secondary" type="button" id="button-addon2"
|
||||||
onClick={fetchStateId}>Rechercher
|
onClick={fetchStateId}>Rechercher
|
||||||
|
|||||||
@ -169,6 +169,10 @@ function FileOutput() {
|
|||||||
certifDate: e.certif ? new Date(e.certif.split("¤")[1]) : '',
|
certifDate: e.certif ? new Date(e.certif.split("¤")[1]) : '',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isNaN(tmp.certifDate) || tmp.certifDate === 'NaN') {
|
||||||
|
tmp.certifDate = ''
|
||||||
|
}
|
||||||
|
|
||||||
//tmp.birthdate.setMilliseconds(0);
|
//tmp.birthdate.setMilliseconds(0);
|
||||||
//tmp.birthdate.setSeconds(0);
|
//tmp.birthdate.setSeconds(0);
|
||||||
//tmp.birthdate.setMinutes(0);
|
//tmp.birthdate.setMinutes(0);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user