diff --git a/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/controller/FightController.java b/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/controller/FightController.java index de81015a2..cc980a23c 100644 --- a/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/controller/FightController.java +++ b/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/controller/FightController.java @@ -30,6 +30,7 @@ import com.softwaremagico.kt.core.converters.models.FightConverterRequest; import com.softwaremagico.kt.core.converters.models.TournamentConverterRequest; import com.softwaremagico.kt.core.exceptions.ParticipantNotFoundException; +import com.softwaremagico.kt.core.exceptions.SenbatsuTournamentFightsException; import com.softwaremagico.kt.core.exceptions.TournamentNotFoundException; import com.softwaremagico.kt.core.exceptions.ValidateBadRequestException; import com.softwaremagico.kt.core.managers.TeamsOrder; @@ -42,6 +43,7 @@ import com.softwaremagico.kt.core.tournaments.SenbatsuTournamentHandler; import com.softwaremagico.kt.core.tournaments.TournamentHandlerSelector; import com.softwaremagico.kt.logger.ExceptionType; +import com.softwaremagico.kt.logger.KendoTournamentLogger; import com.softwaremagico.kt.persistence.entities.Fight; import com.softwaremagico.kt.persistence.entities.Group; import com.softwaremagico.kt.persistence.entities.Participant; @@ -222,15 +224,19 @@ public List createFights(Integer tournamentId, TeamsOrder teamsOrder, groupProvider.delete(tournament, level + 1); final ITournamentManager selectedManager = tournamentHandlerSelector.selectManager(tournament.getType()); if (selectedManager != null) { - final List createdFights = getProvider().saveAll(selectedManager.createFights(tournament, teamsOrder, level, createdBy)); - tournamentProvider.markAsFinished(tournament, false); - final List fightDTOS = convertAll(createdFights); try { - return fightDTOS; - } finally { - new Thread(() -> - fightsAddedListeners.forEach(fightsAddedListener -> fightsAddedListener.created(fightDTOS, createdBy)) - ).start(); + final List createdFights = getProvider().saveAll(selectedManager.createFights(tournament, teamsOrder, level, createdBy)); + tournamentProvider.markAsFinished(tournament, false); + final List fightDTOS = convertAll(createdFights); + try { + return fightDTOS; + } finally { + new Thread(() -> + fightsAddedListeners.forEach(fightsAddedListener -> fightsAddedListener.created(fightDTOS, createdBy)) + ).start(); + } + } catch (SenbatsuTournamentFightsException e) { + KendoTournamentLogger.warning(this.getClass(), e.getMessage()); } } return new ArrayList<>(); diff --git a/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/exceptions/SenbatsuTournamentFightsException.java b/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/exceptions/SenbatsuTournamentFightsException.java new file mode 100644 index 000000000..3cbe76f6c --- /dev/null +++ b/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/exceptions/SenbatsuTournamentFightsException.java @@ -0,0 +1,40 @@ +package com.softwaremagico.kt.core.exceptions; + +/*- + * #%L + * Kendo Tournament Manager (Core) + * %% + * Copyright (C) 2021 - 2024 Softwaremagico + * %% + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * #L% + */ + +import com.softwaremagico.kt.logger.ExceptionType; +import com.softwaremagico.kt.logger.LoggedException; +import org.springframework.http.HttpStatus; +import org.springframework.web.bind.annotation.ResponseStatus; + +@ResponseStatus(HttpStatus.BAD_REQUEST) +public class SenbatsuTournamentFightsException extends LoggedException { + private static final long serialVersionUID = -1399325226733756592L; + + public SenbatsuTournamentFightsException(Class clazz, String message) { + super(clazz, message, ExceptionType.SEVERE, HttpStatus.BAD_REQUEST); + } + + public SenbatsuTournamentFightsException(Class clazz, String message, ExceptionType exceptionType) { + super(clazz, message, exceptionType, HttpStatus.BAD_REQUEST); + } +} diff --git a/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/tournaments/SenbatsuTournamentHandler.java b/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/tournaments/SenbatsuTournamentHandler.java index 3065e4f63..33a08d30f 100644 --- a/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/tournaments/SenbatsuTournamentHandler.java +++ b/backend/kendo-tournament-core/src/main/java/com/softwaremagico/kt/core/tournaments/SenbatsuTournamentHandler.java @@ -21,9 +21,9 @@ * #L% */ -import com.softwaremagico.kt.core.exceptions.CustomTournamentFightsException; import com.softwaremagico.kt.core.exceptions.InvalidChallengeDistanceException; import com.softwaremagico.kt.core.exceptions.InvalidFightException; +import com.softwaremagico.kt.core.exceptions.SenbatsuTournamentFightsException; import com.softwaremagico.kt.core.managers.TeamsOrder; import com.softwaremagico.kt.core.providers.FightProvider; import com.softwaremagico.kt.core.providers.GroupProvider; @@ -60,7 +60,7 @@ public SenbatsuTournamentHandler(GroupProvider groupProvider, TeamProvider teamP @Override public List createFights(Tournament tournament, TeamsOrder teamsOrder, Integer level, String createdBy) { - throw new CustomTournamentFightsException(this.getClass(), "This league cannot generate fights."); + throw new SenbatsuTournamentFightsException(this.getClass(), "This league cannot generate fights."); } diff --git a/documents/UPDATING.md b/documents/UPDATING.md index 05c4c06df..3c5efdc56 100644 --- a/documents/UPDATING.md +++ b/documents/UPDATING.md @@ -20,3 +20,53 @@ alter table competitor_1_score_time alter table competitor_2_score_time alter column competitor2scoretime type int using competitor2scoretime::bigint; ``` + +# From version 2.14.X to 2.15.0 + +``` +alter table public.tournament_extra_properties + drop constraint tournament_extra_properties_property_key_check; + +alter table public.tournament_extra_properties + add constraint tournament_extra_properties_property_key_check + check ((property_key)::text = ANY + (ARRAY [('MAXIMIZE_FIGHTS'::character varying)::text, ('AVOID_DUPLICATES'::character varying)::text, ('KING_INDEX'::character varying)::text, ('KING_DRAW_RESOLUTION'::character varying)::text, ('DIPLOMA_NAME_HEIGHT'::character varying)::text, ('NUMBER_OF_WINNERS'::character varying)::text, ('LEAGUE_FIGHTS_ORDER_GENERATION'::character varying)::text, ('ODD_FIGHTS_RESOLVED_ASAP'::character varying)::text])); + +``` + + +# From version 2.15.X to 2.16.0 + +``` +alter table public.tournaments + drop constraint tournaments_tournament_type_check; + +alter table public.tournaments + add constraint tournaments_tournament_type_check + check ((tournament_type)::text = ANY + (ARRAY [('CHAMPIONSHIP'::character varying)::text, ('TREE'::character varying)::text, ('LEAGUE'::character varying)::text, ('LOOP'::character varying)::text, ('CUSTOM_CHAMPIONSHIP'::character varying)::text, ('KING_OF_THE_MOUNTAIN'::character varying)::text, ('CUSTOMIZED'::character varying)::text, ('BUBBLE_SORT'::character varying)::text])); + +``` + +# From version 2.16.0 to 2.17.0 + + +``` +alter table public.tournaments + drop constraint tournaments_tournament_type_check; + +alter table public.tournaments + add constraint tournaments_tournament_type_check + check ((tournament_type)::text = ANY + (ARRAY [('CHAMPIONSHIP'::character varying)::text, ('TREE'::character varying)::text, ('LEAGUE'::character varying)::text, ('LOOP'::character varying)::text, ('CUSTOM_CHAMPIONSHIP'::character varying)::text, ('KING_OF_THE_MOUNTAIN'::character varying)::text, ('CUSTOMIZED'::character varying)::text, ('SENBATSU'::character varying)::text, ('BUBBLE_SORT'::character varying)::text])); + + +alter table public.tournament_extra_properties + drop constraint tournament_extra_properties_property_key_check; + +alter table public.tournament_extra_properties + add constraint tournament_extra_properties_property_key_check + check ((property_key)::text = ANY + (ARRAY [('MAXIMIZE_FIGHTS'::character varying)::text, ('AVOID_DUPLICATES'::character varying)::text, ('KING_INDEX'::character varying)::text, ('KING_DRAW_RESOLUTION'::character varying)::text, ('DIPLOMA_NAME_HEIGHT'::character varying)::text, ('NUMBER_OF_WINNERS'::character varying)::text, ('LEAGUE_FIGHTS_ORDER_GENERATION'::character varying)::text, ('ODD_FIGHTS_RESOLVED_ASAP'::character varying)::text, ('SENBATSU_CHALLENGE_DISTANCE'::character varying)::text])); + +``` \ No newline at end of file