Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
softwaremagico committed Nov 13, 2023
2 parents 7b27feb + c8214a3 commit 1628e07
Show file tree
Hide file tree
Showing 28 changed files with 137 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

import com.softwaremagico.kt.core.controller.models.ParticipantDTO;
import com.softwaremagico.kt.core.controller.models.RoleDTO;
import com.softwaremagico.kt.core.controller.models.DTO;
import com.softwaremagico.kt.core.controller.models.TeamDTO;
import com.softwaremagico.kt.core.controller.models.TournamentDTO;
import com.softwaremagico.kt.core.controller.models.TournamentFightStatisticsDTO;
import com.softwaremagico.kt.core.converters.TeamConverter;
Expand Down Expand Up @@ -78,15 +78,15 @@ public TournamentFightStatisticsDTO estimateByMembers(TournamentDTO tournamentDT
return convert(getProvider().estimateByMembers(tournamentConverter.reverse(tournamentDTO)));
}

public TournamentFightStatisticsDTO estimate(TournamentDTO tournamentDTO, Collection<DTO> teams) {
public TournamentFightStatisticsDTO estimate(TournamentDTO tournamentDTO, Collection<TeamDTO> teams) {
return estimate(tournamentDTO, tournamentDTO.getTeamSize(), teams);
}

public TournamentFightStatisticsDTO estimateByRoles(TournamentDTO tournamentDTO, Collection<RoleDTO> roles) {
return estimate(tournamentDTO, emulateTeams(tournamentDTO, roles.stream().map(RoleDTO::getParticipant).toList()));
}

public TournamentFightStatisticsDTO estimate(TournamentDTO tournamentDTO, int teamSize, Collection<DTO> teams) {
public TournamentFightStatisticsDTO estimate(TournamentDTO tournamentDTO, int teamSize, Collection<TeamDTO> teams) {
if (tournamentDTO == null || teams == null || teams.size() < 2) {
return null;
}
Expand All @@ -102,15 +102,15 @@ public TournamentFightStatisticsDTO estimate(TournamentDTO tournamentDTO, int te
}
}

private TournamentFightStatisticsDTO estimateLeagueStatistics(int teamSize, Collection<DTO> teams) {
private TournamentFightStatisticsDTO estimateLeagueStatistics(int teamSize, Collection<TeamDTO> teams) {
return convert(getProvider().estimateLeagueStatistics(teamSize, teamConverter.reverseAll(teams)));
}

private TournamentFightStatisticsDTO estimateLoopStatistics(TournamentDTO tournamentDTO, int teamSize, Collection<DTO> teams) {
private TournamentFightStatisticsDTO estimateLoopStatistics(TournamentDTO tournamentDTO, int teamSize, Collection<TeamDTO> teams) {
return convert(getProvider().estimateLoopStatistics(tournamentConverter.reverse(tournamentDTO), teamSize, teamConverter.reverseAll(teams)));
}

private int getDuels(int fightByTeam, int teamSize, Collection<DTO> teams) {
private int getDuels(int fightByTeam, int teamSize, Collection<TeamDTO> teams) {
final AtomicInteger counter = new AtomicInteger();
final AtomicInteger missingMembers = new AtomicInteger();

Expand All @@ -130,18 +130,18 @@ private int getDuels(int fightByTeam, int teamSize, Collection<DTO> teams) {
* @param participants the list of members that will participate on the tournament.
* @return a list of transient teams.
*/
private List<DTO> emulateTeams(TournamentDTO tournamentDTO, Collection<ParticipantDTO> participants) {
private List<TeamDTO> emulateTeams(TournamentDTO tournamentDTO, Collection<ParticipantDTO> participants) {
int teamIndex = 0;
final List<DTO> teams = new ArrayList<>();
DTO team = null;
final List<TeamDTO> teams = new ArrayList<>();
TeamDTO team = null;
int teamMember = 0;


for (final ParticipantDTO competitor : participants) {
// Create a new team.
if (team == null) {
teamIndex++;
team = new DTO("Team" + String.format("%02d", teamIndex), tournamentDTO);
team = new TeamDTO("Team" + String.format("%02d", teamIndex), tournamentDTO);
teamMember = 0;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.softwaremagico.kt.core.controller.models.DuelDTO;
import com.softwaremagico.kt.core.controller.models.FightDTO;
import com.softwaremagico.kt.core.controller.models.GroupDTO;
import com.softwaremagico.kt.core.controller.models.DTO;
import com.softwaremagico.kt.core.controller.models.TeamDTO;
import com.softwaremagico.kt.core.controller.models.TournamentDTO;
import com.softwaremagico.kt.core.converters.DuelConverter;
import com.softwaremagico.kt.core.converters.FightConverter;
Expand Down Expand Up @@ -147,11 +147,11 @@ public GroupDTO update(GroupDTO groupDTO, String username) {
return create(groupDTO, null);
}

public GroupDTO addTeams(Integer groupId, List<DTO> teams, String username) {
public GroupDTO addTeams(Integer groupId, List<TeamDTO> teams, String username) {
return convert(getProvider().addTeams(groupId, teamConverter.reverseAll(teams), username));
}

public GroupDTO deleteTeams(Integer groupId, List<DTO> teams, String username) {
public GroupDTO deleteTeams(Integer groupId, List<TeamDTO> teams, String username) {
return convert(getProvider().deleteTeams(groupId, teamConverter.reverseAll(teams), username));
}

Expand All @@ -161,13 +161,13 @@ public List<GroupDTO> deleteTeamsFromTournament(Integer tournamentId, String use
username));
}

public List<GroupDTO> deleteTeamsFromTournament(Integer tournamentId, List<DTO> teams, String username) {
public List<GroupDTO> deleteTeamsFromTournament(Integer tournamentId, List<TeamDTO> teams, String username) {
return convertAll(getProvider().deleteTeams(tournamentProvider.get(tournamentId).orElseThrow(() ->
new TournamentNotFoundException(this.getClass(), "Tournament with id" + tournamentId + " not found!")),
teamConverter.reverseAll(teams), username));
}

public GroupDTO setTeams(Integer groupId, List<DTO> teams, String username) {
public GroupDTO setTeams(Integer groupId, List<TeamDTO> teams, String username) {
GroupDTO groupDTO = get(groupId);

final List<FightDTO> fights = new ArrayList<>(groupDTO.getFights());
Expand All @@ -185,7 +185,7 @@ public GroupDTO setTeams(Integer groupId, List<DTO> teams, String username) {
return convert(getProvider().save(reverse(groupDTO)));
}

public GroupDTO setTeams(List<DTO> teams, String username) {
public GroupDTO setTeams(List<TeamDTO> teams, String username) {
if (teams.isEmpty()) {
throw new TeamNotFoundException(this.getClass(), "No teams found!");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.softwaremagico.kt.core.controller.models.ParticipantDTO;
import com.softwaremagico.kt.core.controller.models.ScoreOfCompetitorDTO;
import com.softwaremagico.kt.core.controller.models.ScoreOfTeamDTO;
import com.softwaremagico.kt.core.controller.models.DTO;
import com.softwaremagico.kt.core.controller.models.TeamDTO;
import com.softwaremagico.kt.core.controller.models.TournamentDTO;
import com.softwaremagico.kt.core.converters.DuelConverter;
import com.softwaremagico.kt.core.converters.FightConverter;
Expand Down Expand Up @@ -105,9 +105,9 @@ public RankingController(GroupProvider groupProvider, GroupConverter groupConver
this.scoreOfTeamConverter = scoreOfTeamConverter;
}

private static Set<ParticipantDTO> getParticipants(List<DTO> teams) {
private static Set<ParticipantDTO> getParticipants(List<TeamDTO> teams) {
final Set<ParticipantDTO> allCompetitors = new HashSet<>();
for (final DTO team : teams) {
for (final TeamDTO team : teams) {
allCompetitors.addAll(team.getMembers());
}
return allCompetitors;
Expand All @@ -117,7 +117,7 @@ private boolean checkLevel(TournamentDTO tournament) {
return tournament == null || tournament.getType() != TournamentType.KING_OF_THE_MOUNTAIN;
}

public List<DTO> getTeamsRanking(GroupDTO groupDTO) {
public List<TeamDTO> getTeamsRanking(GroupDTO groupDTO) {
return teamConverter.convertAll(rankingProvider.getTeamsRanking(groupConverter.reverse(groupDTO))
.stream().map(TeamConverterRequest::new).toList());
}
Expand All @@ -143,7 +143,7 @@ public List<ScoreOfTeamDTO> getTeamsScoreRanking(GroupDTO groupDTO) {
groupDTO.getTeams(), groupDTO.getFights(), groupDTO.getUnties(), checkLevel(groupDTO.getTournament()));
}

public List<ScoreOfTeamDTO> getTeamsScoreRanking(ScoreType type, List<DTO> teams, List<FightDTO> fights, List<DuelDTO> unties,
public List<ScoreOfTeamDTO> getTeamsScoreRanking(ScoreType type, List<TeamDTO> teams, List<FightDTO> fights, List<DuelDTO> unties,
boolean checkLevel) {
return scoreOfTeamConverter.convertAll(rankingProvider.getTeamsScoreRanking(
type,
Expand All @@ -165,27 +165,27 @@ public List<ScoreOfTeamDTO> getTeamsScoreRanking(TournamentDTO tournamentDTO) {
*
* @return classification of the teams
*/
public Map<Integer, List<DTO>> getTeamsByPosition(GroupDTO groupDTO) {
public Map<Integer, List<TeamDTO>> getTeamsByPosition(GroupDTO groupDTO) {
final Map<Integer, List<Team>> teamsByPosition = rankingProvider.getTeamsByPosition(groupConverter.reverse(groupDTO));
final Map<Integer, List<DTO>> teamsByPositionDTO = new HashMap<>();
final Map<Integer, List<TeamDTO>> teamsByPositionDTO = new HashMap<>();
teamsByPosition.keySet().forEach(key -> teamsByPositionDTO.put(key, teamConverter.convertAll(teamsByPosition.get(key)
.stream().map(TeamConverterRequest::new).toList())));
return teamsByPositionDTO;
}

public List<DTO> getFirstTeamsWithDrawScore(GroupDTO groupDTO, Integer maxWinners) {
final Map<Integer, List<DTO>> teamsByPosition = getTeamsByPosition(groupDTO);
public List<TeamDTO> getFirstTeamsWithDrawScore(GroupDTO groupDTO, Integer maxWinners) {
final Map<Integer, List<TeamDTO>> teamsByPosition = getTeamsByPosition(groupDTO);
for (int i = 0; i < maxWinners; i++) {
final List<DTO> teamsInDraw = teamsByPosition.get(i);
final List<TeamDTO> teamsInDraw = teamsByPosition.get(i);
if (teamsInDraw.size() > 1) {
return teamsInDraw;
}
}
return new ArrayList<>();
}

public DTO getTeam(GroupDTO groupDTO, Integer order) {
final List<DTO> teamsOrder = getTeamsRanking(groupDTO);
public TeamDTO getTeam(GroupDTO groupDTO, Integer order) {
final List<TeamDTO> teamsOrder = getTeamsRanking(groupDTO);
if (order >= 0 && order < teamsOrder.size()) {
return teamsOrder.get(order);
}
Expand Down Expand Up @@ -262,7 +262,7 @@ public ScoreOfCompetitorDTO getScoreOfCompetitor(GroupDTO groupDTO, Integer orde
.getScoreOfCompetitor(groupConverter.reverse(groupDTO), order)));
}

public Integer getOrder(GroupDTO groupDTO, DTO teamDTO) {
public Integer getOrder(GroupDTO groupDTO, TeamDTO teamDTO) {
return rankingProvider.getOrder(groupConverter.reverse(groupDTO), teamConverter.reverse(teamDTO));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@
* #L%
*/

import com.softwaremagico.kt.core.controller.models.DTO;
import com.softwaremagico.kt.core.controller.models.ParticipantDTO;
import com.softwaremagico.kt.core.controller.models.TeamDTO;
import com.softwaremagico.kt.core.controller.models.TournamentDTO;
import com.softwaremagico.kt.core.converters.ParticipantConverter;
import com.softwaremagico.kt.core.converters.TeamConverter;
Expand All @@ -45,7 +45,7 @@
import java.util.List;

@Controller
public class TeamController extends BasicInsertableController<Team, DTO, TeamRepository,
public class TeamController extends BasicInsertableController<Team, TeamDTO, TeamRepository,
TeamProvider, TeamConverterRequest, TeamConverter> {
private final TournamentProvider tournamentProvider;
private final TournamentConverter tournamentConverter;
Expand All @@ -68,18 +68,18 @@ protected TeamConverterRequest createConverterRequest(Team entity) {
return new TeamConverterRequest(entity);
}

public List<DTO> getAllByTournament(TournamentDTO tournamentDTO, String createdBy) {
final List<DTO> teams = convertAll(getProvider().getAll(tournamentConverter.reverse(tournamentDTO)));
public List<TeamDTO> getAllByTournament(TournamentDTO tournamentDTO, String createdBy) {
final List<TeamDTO> teams = convertAll(getProvider().getAll(tournamentConverter.reverse(tournamentDTO)));
if (teams.isEmpty()) {
return convertAll(getProvider().createDefaultTeams(tournamentConverter.reverse(tournamentDTO), createdBy));
}
return teams;
}

public List<DTO> getAllByTournament(Integer tournamentId, String createdBy) {
public List<TeamDTO> getAllByTournament(Integer tournamentId, String createdBy) {
final Tournament tournament = tournamentProvider.get(tournamentId)
.orElseThrow(() -> new TournamentNotFoundException(getClass(), "No tournament found with id '" + tournamentId + "'."));
final List<DTO> teams = convertAll(getProvider().getAll(tournament));
final List<TeamDTO> teams = convertAll(getProvider().getAll(tournament));
if (teams.isEmpty()) {
return convertAll(getProvider().createDefaultTeams(tournament, createdBy));
}
Expand All @@ -92,21 +92,21 @@ public long countByTournament(Integer tournamentId) {
}

@Override
public DTO create(DTO teamDTO, String username) {
public TeamDTO create(TeamDTO teamDTO, String username) {
if (teamDTO.getName() == null) {
teamDTO.setName(getProvider().getNextDefaultName(tournamentConverter.reverse(teamDTO.getTournament())));
}
final DTO storedTeamDTO = super.create(teamDTO, username);
final TeamDTO storedTeamDTO = super.create(teamDTO, username);
storedTeamDTO.setTournament(teamDTO.getTournament());
return storedTeamDTO;
}

public List<DTO> create(TournamentDTO tournamentDTO, String createdBy) {
public List<TeamDTO> create(TournamentDTO tournamentDTO, String createdBy) {
return convertAll(getProvider().createDefaultTeams(tournamentConverter.reverse(tournamentDTO), createdBy));
}

@Override
public List<DTO> create(Collection<DTO> teamsDTOs, String username) {
public List<TeamDTO> create(Collection<TeamDTO> teamsDTOs, String username) {
teamsDTOs.forEach(teamDTO -> {
if (teamDTO.getName() == null) {
teamDTO.setName(getProvider().getNextDefaultName(tournamentConverter.reverse(teamDTO.getTournament())));
Expand All @@ -115,7 +115,7 @@ public List<DTO> create(Collection<DTO> teamsDTOs, String username) {
return super.create(teamsDTOs, username);
}

public DTO delete(TournamentDTO tournamentDTO, ParticipantDTO member) {
public TeamDTO delete(TournamentDTO tournamentDTO, ParticipantDTO member) {
final Team team = getProvider().delete(tournamentConverter.reverse(tournamentDTO), participantConverter.reverse(member)).orElse(null);
if (team != null) {
return convert(team);
Expand All @@ -133,7 +133,7 @@ public void delete(TournamentDTO tournamentDTO) {
}

@Override
public DTO update(DTO teamDTO, String username) {
public TeamDTO update(TeamDTO teamDTO, String username) {
teamDTO.setUpdatedBy(username);
validate(teamDTO);
final Team dbTeam = super.getProvider().save(reverse(teamDTO));
Expand All @@ -146,7 +146,7 @@ public long count(TournamentDTO tournament) {
}

@Override
public void validate(DTO teamDTO) throws ValidateBadRequestException {
public void validate(TeamDTO teamDTO) throws ValidateBadRequestException {
if (teamDTO == null || teamDTO.getTournament() == null) {
throw new ValidateBadRequestException(getClass(), "Team data is missing");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.util.Objects;

public class FightDTO extends ElementDTO {
private DTO team1;
private DTO team2;
private TeamDTO team1;
private TeamDTO team2;
private TournamentDTO tournament;
private Integer shiaijo;
private List<DuelDTO> duels = new ArrayList<>();
Expand All @@ -39,7 +39,7 @@ public FightDTO() {
super();
}

public FightDTO(TournamentDTO tournament, DTO team1, DTO team2, Integer shiaijo, Integer level) {
public FightDTO(TournamentDTO tournament, TeamDTO team1, TeamDTO team2, Integer shiaijo, Integer level) {
this();
setTournament(tournament);
setTeam1(team1);
Expand All @@ -49,19 +49,19 @@ public FightDTO(TournamentDTO tournament, DTO team1, DTO team2, Integer shiaijo,
}


public DTO getTeam1() {
public TeamDTO getTeam1() {
return team1;
}

public void setTeam1(DTO team1) {
public void setTeam1(TeamDTO team1) {
this.team1 = team1;
}

public DTO getTeam2() {
public TeamDTO getTeam2() {
return team2;
}

public void setTeam2(DTO team2) {
public void setTeam2(TeamDTO team2) {
this.team2 = team2;
}

Expand Down Expand Up @@ -109,7 +109,7 @@ public boolean isOver() {
return duels.stream().anyMatch(DuelDTO::isOver);
}

public DTO getWinner() {
public TeamDTO getWinner() {
int points = 0;
for (int i = 0; i < getDuels().size(); i++) {
points += getDuels().get(i).getWinner();
Expand Down Expand Up @@ -145,7 +145,7 @@ public boolean isDrawFight() {
return getWinner() == null;
}

public int getWonDuels(DTO team) {
public int getWonDuels(TeamDTO team) {
if (Objects.equals(team1, team)) {
return (int) getDuels().stream().filter(duel -> duel.getWinner() == -1).count();
}
Expand All @@ -155,7 +155,7 @@ public int getWonDuels(DTO team) {
return 0;
}

public Integer getDrawDuels(DTO team) {
public Integer getDrawDuels(TeamDTO team) {
int drawDuels = 0;
if ((getTeam1().equals(team) || getTeam2().equals(team))) {
drawDuels = (int) getDuels().stream().filter(duel -> duel.getWinner() == 0).count();
Expand All @@ -178,7 +178,7 @@ public Integer getScore(ParticipantDTO competitor) {
return score;
}

public Integer getScore(DTO team) {
public Integer getScore(TeamDTO team) {
if (Objects.equals(team1, team)) {
return getScoreTeam1();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class GroupDTO extends ElementDTO {

private TournamentDTO tournament;

private List<DTO> teams;
private List<TeamDTO> teams;

private Integer shiaijo;

Expand All @@ -50,11 +50,11 @@ public void setTournament(TournamentDTO tournamentDTO) {
this.tournament = tournamentDTO;
}

public List<DTO> getTeams() {
public List<TeamDTO> getTeams() {
return teams;
}

public void setTeams(List<DTO> teams) {
public void setTeams(List<TeamDTO> teams) {
this.teams = teams;
}

Expand Down
Loading

0 comments on commit 1628e07

Please sign in to comment.