feat: add classement match system
This commit is contained in:
@@ -45,6 +45,12 @@ public class CategoryModel {
|
||||
|
||||
String liceName = "1";
|
||||
|
||||
@Column(nullable = false, columnDefinition = "boolean default false")
|
||||
boolean treeAreClassement = false;
|
||||
|
||||
@Column(nullable = false, columnDefinition = "boolean default false")
|
||||
boolean fullClassement = false;
|
||||
|
||||
@ManyToOne(fetch = FetchType.EAGER)
|
||||
@JoinColumn(name = "id_preset", referencedColumnName = "id")
|
||||
CatPresetModel preset;
|
||||
|
||||
@@ -109,6 +109,22 @@ public class MatchModel {
|
||||
return sum;
|
||||
}
|
||||
|
||||
public CombModel getC1() {
|
||||
if (this.c1_id != null)
|
||||
return this.c1_id;
|
||||
if (this.c1_guest != null)
|
||||
return this.c1_guest;
|
||||
return null;
|
||||
}
|
||||
|
||||
public CombModel getC2() {
|
||||
if (this.c2_id != null)
|
||||
return this.c2_id;
|
||||
if (this.c2_guest != null)
|
||||
return this.c2_guest;
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isC1(Object comb) {
|
||||
if (this.c1_guest != null && this.c1_guest.isInTeam(comb))
|
||||
return true;
|
||||
|
||||
@@ -40,6 +40,14 @@ public class TreeModel {
|
||||
@JoinColumn(referencedColumnName = "id")
|
||||
TreeModel right;
|
||||
|
||||
public TreeModel(Long category, Integer level, MatchModel match) {
|
||||
this.category = category;
|
||||
this.level = level;
|
||||
this.match = match;
|
||||
this.left = null;
|
||||
this.right = null;
|
||||
}
|
||||
|
||||
public List<TreeModel> flat() {
|
||||
List<TreeModel> out = new ArrayList<>();
|
||||
this.flat(out);
|
||||
@@ -55,4 +63,44 @@ public class TreeModel {
|
||||
if (this.left != null)
|
||||
this.left.flat(out);
|
||||
}
|
||||
|
||||
public int death() {
|
||||
int dg = 0;
|
||||
int dd = 0;
|
||||
|
||||
if (this.right != null)
|
||||
dg = this.right.death();
|
||||
|
||||
if (this.left != null)
|
||||
dg = this.left.death();
|
||||
|
||||
return 1 + Math.max(dg, dd);
|
||||
}
|
||||
|
||||
public int getMaxChildrenAtDepth(int death, int current) {
|
||||
if (current == death)
|
||||
return 1;
|
||||
|
||||
int tmp = 0;
|
||||
if (this.right != null)
|
||||
tmp += this.right.getMaxChildrenAtDepth(death, current + 1);
|
||||
|
||||
if (this.left != null)
|
||||
tmp += this.left.getMaxChildrenAtDepth(death, current + 1);
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public void getChildrenAtDepth (int death, int current, List<TreeModel> out) {
|
||||
if (current == death) {
|
||||
out.add(this);
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.right != null)
|
||||
this.right.getChildrenAtDepth(death, current + 1, out);
|
||||
|
||||
if (this.left != null)
|
||||
this.left.getChildrenAtDepth(death, current + 1, out);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@ public class MatchRepository implements PanacheRepositoryBase<MatchModel, Long>
|
||||
}
|
||||
|
||||
public Uni<Void> create(List<MatchModel> matchModel) {
|
||||
if (matchModel.isEmpty())
|
||||
return Uni.createFrom().voidItem();
|
||||
|
||||
matchModel.forEach(model -> model.setSystem(CompetitionSystem.INTERNAL));
|
||||
return Panache.withTransaction(() -> this.persist(matchModel)
|
||||
.call(__ -> this.flush())
|
||||
|
||||
@@ -173,4 +173,12 @@ public class MatchModelExtend {
|
||||
public boolean isC2(Object comb) {
|
||||
return match.isC2(comb);
|
||||
}
|
||||
|
||||
public CombModel getC1() {
|
||||
return match.getC1();
|
||||
}
|
||||
|
||||
public CombModel getC2() {
|
||||
return match.getC2();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,14 +151,16 @@ public class ResultService {
|
||||
out.setLiceName(categoryModel.getLiceName() == null ? new String[]{} : categoryModel.getLiceName()
|
||||
.split(";"));
|
||||
out.setGenTime(System.currentTimeMillis());
|
||||
out.setTreeIsClassement(categoryModel.isTreeAreClassement());
|
||||
|
||||
getArray2(matchModels, membreModel, out);
|
||||
getTree(categoryModel.getTree(), membreModel, cards, out);
|
||||
getClassementArray(categoryModel, membreModel, cards, out);
|
||||
return out;
|
||||
});
|
||||
}
|
||||
|
||||
private void getArray2(List<MatchModelExtend> matchModels_, MembreModel membreModel, ResultCategoryData out) {
|
||||
public void getArray2(List<MatchModelExtend> matchModels_, MembreModel membreModel, ResultCategoryData out) {
|
||||
List<MatchModelExtend> matchModels = matchModels_.stream().filter(o -> o.getCategory_ord() >= 0).toList();
|
||||
|
||||
HashMap<Character, List<MatchModelExtend>> matchMap = new HashMap<>();
|
||||
@@ -182,7 +184,7 @@ public class ResultService {
|
||||
.filter(Objects::nonNull)
|
||||
.map(comb -> {
|
||||
CombStat stat = makeStat(matchEntities, comb);
|
||||
return new ResultCategoryData.RankArray(0,
|
||||
return new ResultCategoryData.RankArray(0, comb,
|
||||
comb.getName(membreModel, ResultPrivacy.REGISTERED_ONLY_NO_DETAILS), stat.score, stat.w,
|
||||
stat.pointMake, stat.pointTake, stat.getPointRate());
|
||||
})
|
||||
@@ -210,10 +212,66 @@ public class ResultService {
|
||||
});
|
||||
}
|
||||
|
||||
private void getClassementArray(CategoryModel categoryModel, MembreModel membreModel, List<CardModel> cards,
|
||||
ResultCategoryData out) {
|
||||
if ((categoryModel.getType() & 2) != 0) {
|
||||
AtomicInteger rank = new AtomicInteger(0);
|
||||
categoryModel.getTree().stream()
|
||||
.filter(t -> t.getLevel() > 0)
|
||||
.sorted(Comparator.comparing(TreeModel::getLevel))
|
||||
.forEach(treeModel -> makeClassementRow(membreModel,
|
||||
new MatchModelExtend(treeModel.getMatch(), cards), out, rank));
|
||||
|
||||
categoryModel.getTree().stream()
|
||||
.filter(t -> t.getLevel() <= -10)
|
||||
.sorted(Comparator.comparing(TreeModel::getLevel).reversed())
|
||||
.forEach(treeModel -> makeClassementRow(membreModel,
|
||||
new MatchModelExtend(treeModel.getMatch(), cards), out, rank));
|
||||
} else {
|
||||
for (List<ResultCategoryData.RankArray> list : out.getRankArray().values()) {
|
||||
for (ResultCategoryData.RankArray r : list) {
|
||||
out.getClassement().add(new ResultCategoryData.ClassementData(r.getRank(), r.getComb(), r.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void makeClassementRow(MembreModel membreModel, MatchModelExtend m, ResultCategoryData out,
|
||||
AtomicInteger rank) {
|
||||
if (m.isEnd()) {
|
||||
if (m.getWin() > 0) {
|
||||
out.getClassement()
|
||||
.add(new ResultCategoryData.ClassementData(rank.incrementAndGet(), m.getC1(),
|
||||
m.getC1Name(membreModel, ResultPrivacy.REGISTERED_ONLY_NO_DETAILS)));
|
||||
out.getClassement()
|
||||
.add(new ResultCategoryData.ClassementData(rank.incrementAndGet(), m.getC2(),
|
||||
m.getC2Name(membreModel, ResultPrivacy.REGISTERED_ONLY_NO_DETAILS)));
|
||||
} else if (m.getWin() < 0) {
|
||||
out.getClassement()
|
||||
.add(new ResultCategoryData.ClassementData(rank.incrementAndGet(), m.getC2(),
|
||||
m.getC2Name(membreModel, ResultPrivacy.REGISTERED_ONLY_NO_DETAILS)));
|
||||
out.getClassement()
|
||||
.add(new ResultCategoryData.ClassementData(rank.incrementAndGet(), m.getC1(),
|
||||
m.getC1Name(membreModel, ResultPrivacy.REGISTERED_ONLY_NO_DETAILS)));
|
||||
} else {
|
||||
out.getClassement()
|
||||
.add(new ResultCategoryData.ClassementData(rank.incrementAndGet(), m.getC1(),
|
||||
m.getC1Name(membreModel, ResultPrivacy.REGISTERED_ONLY_NO_DETAILS)));
|
||||
out.getClassement()
|
||||
.add(new ResultCategoryData.ClassementData(rank.getAndIncrement(), m.getC2(),
|
||||
m.getC2Name(membreModel, ResultPrivacy.REGISTERED_ONLY_NO_DETAILS)));
|
||||
}
|
||||
} else {
|
||||
out.getClassement().add(new ResultCategoryData.ClassementData(rank.incrementAndGet(), null, null));
|
||||
out.getClassement().add(new ResultCategoryData.ClassementData(rank.incrementAndGet(), null, null));
|
||||
}
|
||||
}
|
||||
|
||||
private static void convertTree(TreeModel src, TreeNode<ResultCategoryData.TreeData> dst, MembreModel membreModel,
|
||||
ResultPrivacy privacy, List<CardModel> cards) {
|
||||
dst.setData(
|
||||
ResultCategoryData.TreeData.from(new MatchModelExtend(src.getMatch(), cards), membreModel, privacy));
|
||||
ResultCategoryData.TreeData.from(new MatchModelExtend(src.getMatch(), cards), src.getLevel(),
|
||||
membreModel, privacy));
|
||||
if (src.getLeft() != null) {
|
||||
dst.setLeft(new TreeNode<>());
|
||||
convertTree(src.getLeft(), dst.getLeft(), membreModel, privacy, cards);
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
package fr.titionfire.ffsaf.domain.service;
|
||||
|
||||
import io.quarkus.websockets.next.WebSocketConnection;
|
||||
import jakarta.enterprise.context.RequestScoped;
|
||||
import jakarta.enterprise.inject.Instance;
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.ws.rs.container.ContainerRequestContext;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
@@ -21,11 +23,20 @@ public class TradService {
|
||||
return translate(key);
|
||||
}
|
||||
|
||||
public String t(String key, WebSocketConnection connection) {
|
||||
List<String> lang = connection.handshakeRequest().headers().get("Accept-Language");
|
||||
Locale userLocale = lang != null && !lang.isEmpty() ? Locale.forLanguageTag(lang.get(0)) : fallbackLocale;
|
||||
return translate(key, userLocale);
|
||||
}
|
||||
|
||||
public String translate(String key) {
|
||||
ContainerRequestContext requestContext = requestContextInstance.get();
|
||||
Locale userLocale = (Locale) requestContext.getProperty("userLocale");
|
||||
|
||||
return translate(key, userLocale);
|
||||
}
|
||||
|
||||
public String translate(String key, Locale userLocale) {
|
||||
try {
|
||||
ResourceBundle messages = ResourceBundle.getBundle("lang.messages", userLocale);
|
||||
return messages.getString(key);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package fr.titionfire.ffsaf.rest.data;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import fr.titionfire.ffsaf.data.model.CombModel;
|
||||
import fr.titionfire.ffsaf.data.model.MembreModel;
|
||||
import fr.titionfire.ffsaf.domain.entity.MatchModelExtend;
|
||||
import fr.titionfire.ffsaf.utils.ResultPrivacy;
|
||||
@@ -21,9 +23,11 @@ import java.util.List;
|
||||
public class ResultCategoryData {
|
||||
int type;
|
||||
String name;
|
||||
boolean treeIsClassement;
|
||||
HashMap<Character, List<PouleArrayData>> matchs = new HashMap<>();
|
||||
HashMap<Character, List<RankArray>> rankArray = new HashMap<>();
|
||||
ArrayList<TreeNode<TreeData>> trees;
|
||||
List<ClassementData> classement = new ArrayList<>();
|
||||
String[] liceName;
|
||||
long genTime;
|
||||
|
||||
@@ -32,6 +36,8 @@ public class ResultCategoryData {
|
||||
@RegisterForReflection
|
||||
public static class RankArray {
|
||||
int rank;
|
||||
@JsonIgnore
|
||||
CombModel comb;
|
||||
String name;
|
||||
int score;
|
||||
int win;
|
||||
@@ -43,12 +49,14 @@ public class ResultCategoryData {
|
||||
@RegisterForReflection
|
||||
public record PouleArrayData(String red, boolean red_w, List<Integer[]> score, boolean blue_w, String blue,
|
||||
boolean eq, boolean end, Date date) {
|
||||
public static PouleArrayData fromModel(MatchModelExtend matchModel, MembreModel membreModel, ResultPrivacy privacy) {
|
||||
public static PouleArrayData fromModel(MatchModelExtend matchModel, MembreModel membreModel,
|
||||
ResultPrivacy privacy) {
|
||||
return new PouleArrayData(
|
||||
matchModel.getC1Name(membreModel, privacy),
|
||||
matchModel.isEnd() && matchModel.getWin() > 0,
|
||||
matchModel.isEnd() ?
|
||||
matchModel.getScoresToPrint().stream().map(s -> new Integer[]{s.getS1(), s.getS2()}).toList()
|
||||
matchModel.getScoresToPrint().stream().map(s -> new Integer[]{s.getS1(), s.getS2()})
|
||||
.toList()
|
||||
: new ArrayList<>(),
|
||||
matchModel.isEnd() && matchModel.getWin() < 0,
|
||||
matchModel.getC2Name(membreModel, privacy),
|
||||
@@ -60,10 +68,16 @@ public class ResultCategoryData {
|
||||
|
||||
@RegisterForReflection
|
||||
public static record TreeData(long id, String c1FullName, String c2FullName, List<ScoreEmbeddable> scores,
|
||||
boolean end, int win) {
|
||||
public static TreeData from(MatchModelExtend match, MembreModel membreModel, ResultPrivacy privacy) {
|
||||
boolean end, int win, int level, Date date) {
|
||||
public static TreeData from(MatchModelExtend match, int level, MembreModel membreModel, ResultPrivacy privacy) {
|
||||
return new TreeData(match.getId(), match.getC1Name(membreModel, privacy),
|
||||
match.getC2Name(membreModel, privacy), match.getScoresToPrint(), match.isEnd(), match.getWin());
|
||||
match.getC2Name(membreModel, privacy), match.getScoresToPrint(), match.isEnd(), match.getWin(),
|
||||
level, match.getDate());
|
||||
}
|
||||
}
|
||||
|
||||
@RegisterForReflection
|
||||
public static record ClassementData(int rank, @JsonIgnore CombModel comb, String name) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,9 +51,9 @@ public class RCard {
|
||||
return matchRepository.findById(id)
|
||||
.invoke(Unchecked.consumer(o -> {
|
||||
if (o == null)
|
||||
throw new DNotFoundException(trad.t("matche.non.trouver"));
|
||||
throw new DNotFoundException(trad.t("matche.non.trouver", connection));
|
||||
if (!o.getCategory().getCompet().getUuid().equals(connection.pathParam("uuid")))
|
||||
throw new DForbiddenException(trad.t("permission.denied"));
|
||||
throw new DForbiddenException(trad.t("permission.denied", connection));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ public class RCard {
|
||||
.firstResult()
|
||||
.invoke(Unchecked.consumer(o -> {
|
||||
if (o == null)
|
||||
throw new DNotFoundException(trad.t("carton.non.trouver"));
|
||||
throw new DNotFoundException(trad.t("carton.non.trouver", connection));
|
||||
SSCard.sendRmCards(connection, List.of(o.getId()));
|
||||
}))
|
||||
.chain(cardModel -> Panache.withTransaction(() -> cardRepository.delete(cardModel)))
|
||||
|
||||
@@ -1,22 +1,25 @@
|
||||
package fr.titionfire.ffsaf.ws.recv;
|
||||
|
||||
import fr.titionfire.ffsaf.data.model.CardModel;
|
||||
import fr.titionfire.ffsaf.data.model.CategoryModel;
|
||||
import fr.titionfire.ffsaf.data.model.MatchModel;
|
||||
import fr.titionfire.ffsaf.data.model.TreeModel;
|
||||
import fr.titionfire.ffsaf.data.model.*;
|
||||
import fr.titionfire.ffsaf.data.repository.*;
|
||||
import fr.titionfire.ffsaf.domain.entity.MatchEntity;
|
||||
import fr.titionfire.ffsaf.domain.entity.MatchModelExtend;
|
||||
import fr.titionfire.ffsaf.domain.entity.TreeEntity;
|
||||
import fr.titionfire.ffsaf.domain.service.CardService;
|
||||
import fr.titionfire.ffsaf.domain.service.ResultService;
|
||||
import fr.titionfire.ffsaf.domain.service.TradService;
|
||||
import fr.titionfire.ffsaf.rest.data.PresetData;
|
||||
import fr.titionfire.ffsaf.rest.data.ResultCategoryData;
|
||||
import fr.titionfire.ffsaf.rest.exception.DForbiddenException;
|
||||
import fr.titionfire.ffsaf.rest.exception.DNotFoundException;
|
||||
import fr.titionfire.ffsaf.utils.TreeNode;
|
||||
import fr.titionfire.ffsaf.ws.PermLevel;
|
||||
import fr.titionfire.ffsaf.ws.send.SSCategorie;
|
||||
import fr.titionfire.ffsaf.ws.send.SSMatch;
|
||||
import io.quarkus.hibernate.reactive.panache.Panache;
|
||||
import io.quarkus.hibernate.reactive.panache.common.WithSession;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
import io.quarkus.websockets.next.UserData;
|
||||
import io.quarkus.websockets.next.WebSocketConnection;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
import io.smallrye.mutiny.unchecked.Unchecked;
|
||||
@@ -25,8 +28,8 @@ import jakarta.inject.Inject;
|
||||
import lombok.Data;
|
||||
import org.hibernate.reactive.mutiny.Mutiny;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@WithSession
|
||||
@ApplicationScoped
|
||||
@@ -49,6 +52,12 @@ public class RCategorie {
|
||||
@Inject
|
||||
CardService cardService;
|
||||
|
||||
@Inject
|
||||
CardRepository cardRepository;
|
||||
|
||||
@Inject
|
||||
ResultService resultService;
|
||||
|
||||
@Inject
|
||||
TradService trad;
|
||||
|
||||
@@ -56,9 +65,9 @@ public class RCategorie {
|
||||
return categoryRepository.findById(id)
|
||||
.invoke(Unchecked.consumer(o -> {
|
||||
if (o == null)
|
||||
throw new DNotFoundException(trad.t("categorie.non.trouver"));
|
||||
throw new DNotFoundException(trad.t("categorie.non.trouver", connection));
|
||||
if (!o.getCompet().getUuid().equals(connection.pathParam("uuid")))
|
||||
throw new DForbiddenException(trad.t("permission.denied"));
|
||||
throw new DForbiddenException(trad.t("permission.denied", connection));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -78,6 +87,9 @@ public class RCategorie {
|
||||
fullCategory.setName(cat.getName());
|
||||
fullCategory.setLiceName(cat.getLiceName());
|
||||
fullCategory.setType(cat.getType());
|
||||
fullCategory.setTreeAreClassement(cat.isTreeAreClassement());
|
||||
fullCategory.setFullClassement(cat.isFullClassement());
|
||||
fullCategory.setPreset(PresetData.fromModel(cat.getPreset()));
|
||||
})
|
||||
.call(cat -> Mutiny.fetch(cat.getMatchs())
|
||||
.map(matchModels -> matchModels.stream().filter(o -> o.getCategory_ord() >= 0)
|
||||
@@ -116,6 +128,9 @@ public class RCategorie {
|
||||
cat.setName(categorie.name);
|
||||
cat.setLiceName(categorie.liceName);
|
||||
cat.setType(categorie.type);
|
||||
cat.setTreeAreClassement(categorie.treeAreClassement);
|
||||
cat.setFullClassement(categorie.fullClassement);
|
||||
// cat.setPreset(cat.getPreset()); //TODO preset update
|
||||
return Panache.withTransaction(() -> categoryRepository.persist(cat));
|
||||
})
|
||||
.call(cat -> {
|
||||
@@ -224,10 +239,149 @@ public class RCategorie {
|
||||
.replaceWithVoid();
|
||||
}
|
||||
|
||||
@WSReceiver(code = "createClassementMatchs", permission = PermLevel.TABLE)
|
||||
public Uni<Void> createClassementMatchs(WebSocketConnection connection, Long categoryId) {
|
||||
return getById(categoryId, connection)
|
||||
.call(cat -> {
|
||||
PermLevel perm = PermLevel.valueOf(connection.userData().get(UserData.TypedKey.forString("prem")));
|
||||
if (perm == PermLevel.TABLE) {
|
||||
return matchRepository.list("category = ?1 AND category_ord = -42", cat.getId())
|
||||
.chain(l -> l.stream().anyMatch(MatchModel::isEnd) ?
|
||||
Uni.createFrom().failure(
|
||||
new DForbiddenException(trad.t("err.match.termine", connection))) :
|
||||
Uni.createFrom().voidItem());
|
||||
}
|
||||
return Uni.createFrom().voidItem();
|
||||
})
|
||||
.call(cat -> treeRepository.list("category = ?1 AND level <= -10", cat.getId())
|
||||
.map(l -> l.stream().map(o -> o.getMatch().getId()).toList())
|
||||
.call(__ -> treeRepository.delete("category = ?1 AND level <= -10", cat.getId()))
|
||||
.call(ids -> matchRepository.delete("id IN ?1", ids)))
|
||||
.call(cat -> Mutiny.fetch(cat.getTree()))
|
||||
.call(cat -> {
|
||||
List<MatchModel> toSave = new ArrayList<>();
|
||||
if (!cat.getTree().isEmpty()) {
|
||||
for (TreeModel treeModel : cat.getTree())
|
||||
cleanTree(treeModel, toSave);
|
||||
}
|
||||
return Panache.withTransaction(() -> matchRepository.persist(toSave))
|
||||
.invoke(__ -> SSMatch.sendMatch(connection,
|
||||
toSave.stream().map(MatchEntity::fromModel).toList()));
|
||||
})
|
||||
.chain(cat -> Mutiny.fetch(cat.getMatchs())
|
||||
.chain(list -> cardRepository.list("competition = ?1", cat.getCompet())
|
||||
.map(c -> list.stream().map(m -> new MatchModelExtend(m, c)).toList()))
|
||||
.map(matchModels -> {
|
||||
ResultCategoryData out = new ResultCategoryData();
|
||||
resultService.getArray2(matchModels, null, out);
|
||||
out.getRankArray().remove('-');
|
||||
return out;
|
||||
})
|
||||
.invoke(Unchecked.consumer(result -> {
|
||||
if (result.getRankArray().size() != 2) {
|
||||
throw new DForbiddenException(trad.t("configuration.non.supportee", connection));
|
||||
}
|
||||
}))
|
||||
.chain(result -> {
|
||||
List<MatchModel> toSave = new ArrayList<>();
|
||||
List<MatchModel> toCreate = new ArrayList<>();
|
||||
List<TreeModel> toSaveTree = new ArrayList<>();
|
||||
|
||||
int treeSize = 0;
|
||||
List<TreeModel> lastNode = new ArrayList<>();
|
||||
Optional<TreeModel> tree = cat.getTree().stream().filter(t -> t.getLevel() > 0)
|
||||
.min(Comparator.comparing(TreeModel::getLevel));
|
||||
if (tree.isPresent()) {
|
||||
tree.get().getChildrenAtDepth(tree.get().death() - 1, 0, lastNode);
|
||||
treeSize = lastNode.size();
|
||||
}
|
||||
|
||||
Iterator<List<ResultCategoryData.RankArray>> iterator = result.getRankArray().values()
|
||||
.iterator();
|
||||
List<ResultCategoryData.RankArray> poule1 = iterator.next();
|
||||
List<ResultCategoryData.RankArray> poule2 = iterator.next();
|
||||
|
||||
int maxToMixFill = Math.min(poule1.size(), poule2.size());
|
||||
int maxToMixTreeFill = Math.min(treeSize, maxToMixFill);
|
||||
for (int i = 0; i < maxToMixTreeFill; i++) {
|
||||
CombModel comb1 = poule1.get(i).getComb();
|
||||
CombModel comb2 = poule2.get(treeSize - i - 1).getComb();
|
||||
|
||||
fillMatchComb(lastNode.get(i).getMatch(), comb1, comb2);
|
||||
toSave.add(lastNode.get(i).getMatch());
|
||||
}
|
||||
|
||||
if (cat.isFullClassement()) {
|
||||
for (int i = maxToMixTreeFill; i < maxToMixFill; i++) {
|
||||
MatchModel match = new MatchModel();
|
||||
match.setCategory(cat);
|
||||
match.setCategory_ord(-42);
|
||||
match.setEnd(false);
|
||||
|
||||
CombModel comb1 = poule1.get(i).getComb();
|
||||
CombModel comb2 = poule2.get(i).getComb();
|
||||
|
||||
fillMatchComb(match, comb1, comb2);
|
||||
toCreate.add(match);
|
||||
|
||||
toSaveTree.add(new TreeModel(cat.getId(), -10 - i, match));
|
||||
}
|
||||
}
|
||||
|
||||
return Panache.withTransaction(() -> matchRepository.persist(toSave)
|
||||
.call(__ -> matchRepository.create(toCreate)))
|
||||
.call(__ -> toSaveTree.isEmpty() ? Uni.createFrom().voidItem()
|
||||
: Panache.withTransaction(() -> treeRepository.persist(toSaveTree)))
|
||||
.map(__ -> Stream.concat(toSave.stream(), toCreate.stream())
|
||||
.map(MatchEntity::fromModel).toList());
|
||||
})
|
||||
)
|
||||
.onFailure().invoke(t -> System.out.println("error: " + t.getMessage()))
|
||||
.invoke(matchEntities -> SSMatch.sendMatch(connection, matchEntities))
|
||||
.call(__ -> treeRepository.list("category = ?1 AND level != 0", categoryId)
|
||||
.map(treeModels -> treeModels.stream().map(TreeEntity::fromModel).toList())
|
||||
.invoke(trees -> SSCategorie.sendTreeCategory(connection, trees)))
|
||||
.replaceWithVoid();
|
||||
}
|
||||
|
||||
private void cleanTree(TreeModel treeModel, List<MatchModel> toSave) {
|
||||
MatchModel model = treeModel.getMatch();
|
||||
if (model != null) {
|
||||
model.setC1_id(null);
|
||||
model.setC1_guest(null);
|
||||
model.setC2_id(null);
|
||||
model.setC2_guest(null);
|
||||
model.setEnd(false);
|
||||
model.setDate(null);
|
||||
model.getScores().clear();
|
||||
|
||||
toSave.add(model);
|
||||
}
|
||||
if (treeModel.getLeft() != null)
|
||||
cleanTree(treeModel.getLeft(), toSave);
|
||||
if (treeModel.getRight() != null)
|
||||
cleanTree(treeModel.getRight(), toSave);
|
||||
}
|
||||
|
||||
private void fillMatchComb(MatchModel match, CombModel comb1, CombModel comb2) {
|
||||
if (comb1 instanceof MembreModel m)
|
||||
match.setC1_id(m);
|
||||
else if (comb1 instanceof CompetitionGuestModel g)
|
||||
match.setC1_guest(g);
|
||||
|
||||
if (comb2 instanceof MembreModel m)
|
||||
match.setC2_id(m);
|
||||
else if (comb2 instanceof CompetitionGuestModel g)
|
||||
match.setC2_guest(g);
|
||||
}
|
||||
|
||||
|
||||
@RegisterForReflection
|
||||
public record JustCategorie(long id, String name, int type, String liceName) {
|
||||
public record JustCategorie(long id, String name, int type, String liceName, boolean treeAreClassement,
|
||||
boolean fullClassement, PresetData preset) {
|
||||
public static JustCategorie from(CategoryModel m) {
|
||||
return new JustCategorie(m.getId(), m.getName(), m.getType(), m.getLiceName());
|
||||
return new JustCategorie(m.getId(), m.getName(), m.getType(), m.getLiceName(), m.isTreeAreClassement(),
|
||||
m.isFullClassement(), PresetData.fromModel(m.getPreset()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -242,6 +396,9 @@ public class RCategorie {
|
||||
String name;
|
||||
int type;
|
||||
String liceName;
|
||||
boolean treeAreClassement = false;
|
||||
boolean fullClassement = false;
|
||||
PresetData preset;
|
||||
List<TreeEntity> trees = null;
|
||||
List<MatchEntity> matches;
|
||||
List<CardModel> cards;
|
||||
|
||||
@@ -55,9 +55,9 @@ public class RMatch {
|
||||
return matchRepository.findById(id)
|
||||
.invoke(Unchecked.consumer(o -> {
|
||||
if (o == null)
|
||||
throw new DNotFoundException(trad.t("matche.non.trouver"));
|
||||
throw new DNotFoundException(trad.t("matche.non.trouver", connection));
|
||||
if (!o.getCategory().getCompet().getUuid().equals(connection.pathParam("uuid")))
|
||||
throw new DForbiddenException(trad.t("permission.denied"));
|
||||
throw new DForbiddenException(trad.t("permission.denied", connection));
|
||||
}));
|
||||
}
|
||||
|
||||
@@ -85,9 +85,9 @@ public class RMatch {
|
||||
return categoryRepository.findById(m.categorie)
|
||||
.invoke(Unchecked.consumer(o -> {
|
||||
if (o == null)
|
||||
throw new DNotFoundException(trad.t("categorie.non.trouver"));
|
||||
throw new DNotFoundException(trad.t("categorie.non.trouver", connection));
|
||||
if (!o.getCompet().getUuid().equals(connection.pathParam("uuid")))
|
||||
throw new DForbiddenException(trad.t("permission.denied"));
|
||||
throw new DForbiddenException(trad.t("permission.denied", connection));
|
||||
}))
|
||||
.chain(categoryModel -> creatMatch(categoryModel, m))
|
||||
.chain(mm -> Panache.withTransaction(() -> matchRepository.create(mm)))
|
||||
@@ -297,9 +297,9 @@ public class RMatch {
|
||||
return categoryRepository.findById(data.categorie)
|
||||
.invoke(Unchecked.consumer(o -> {
|
||||
if (o == null)
|
||||
throw new DNotFoundException(trad.t("categorie.non.trouver"));
|
||||
throw new DNotFoundException(trad.t("categorie.non.trouver", connection));
|
||||
if (!o.getCompet().getUuid().equals(connection.pathParam("uuid")))
|
||||
throw new DForbiddenException(trad.t("permission.denied"));
|
||||
throw new DForbiddenException(trad.t("permission.denied", connection));
|
||||
}))
|
||||
.call(cm -> data.matchesToRemove.isEmpty() ? Uni.createFrom().voidItem() :
|
||||
(Panache.withTransaction(
|
||||
|
||||
Reference in New Issue
Block a user