From 429da0517f845d3a32f814dfb32114915fc2f878 Mon Sep 17 00:00:00 2001 From: Software Magico Date: Sun, 26 May 2024 09:32:29 +0200 Subject: [PATCH 1/2] Improved wordpress code style --- README.md | 2 +- .../kt/html/lists/BlogExporter.java | 73 +++++++++++++------ 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/README.md b/README.md index a9301f5f..6add0cc9 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ [![GitHub commit activity](https://img.shields.io/github/commit-activity/y/softwaremagico/KendoTournamentManager)](https://github.com/softwaremagico/KendoTournamentManager) [![GitHub last commit](https://img.shields.io/github/last-commit/softwaremagico/KendoTournamentManager)](https://github.com/softwaremagico/KendoTournamentManager) [![CircleCI](https://circleci.com/gh/softwaremagico/KendoTournamentManager.svg?style=shield)](https://circleci.com/gh/softwaremagico/KendoTournamentManager) -[![Time](https://img.shields.io/badge/development-622.5h-blueviolet.svg)]() +[![Time](https://img.shields.io/badge/development-623h-blueviolet.svg)]() [![Powered by](https://img.shields.io/badge/powered%20by%20java-orange.svg?logo=OpenJDK&logoColor=white)]() [![Vulnerabilities](https://sonarcloud.io/api/project_badges/measure?project=kendo-tournament-backend&metric=vulnerabilities)](https://sonarcloud.io/summary/new_code?id=kendo-tournament-backend) diff --git a/backend/kendo-tournament-pdf/src/main/java/com/softwaremagico/kt/html/lists/BlogExporter.java b/backend/kendo-tournament-pdf/src/main/java/com/softwaremagico/kt/html/lists/BlogExporter.java index 46399218..638c0a89 100644 --- a/backend/kendo-tournament-pdf/src/main/java/com/softwaremagico/kt/html/lists/BlogExporter.java +++ b/backend/kendo-tournament-pdf/src/main/java/com/softwaremagico/kt/html/lists/BlogExporter.java @@ -161,13 +161,13 @@ private void addScoreTables(StringBuilder stringBuilder, TournamentDTO tournamen String name; name = NameUtils.getLastnameName(competitor); columns.add(name); - columns.add(getFaults(fight, teamMember, true)); - columns.add(getScore(fight, teamMember, 1, true)); - columns.add(getScore(fight, teamMember, 0, true)); + columns.add(getFaultsDiv(fight, teamMember, true)); + columns.add(getScoreDiv(fight, teamMember, 1, true)); + columns.add(getScoreDiv(fight, teamMember, 0, true)); columns.add(getDrawFight(fight, teamMember)); - columns.add(getScore(fight, teamMember, 0, false)); - columns.add(getScore(fight, teamMember, 1, false)); - columns.add(getFaults(fight, teamMember, false)); + columns.add(getScoreDiv(fight, teamMember, 0, false)); + columns.add(getScoreDiv(fight, teamMember, 1, false)); + columns.add(getFaultsDiv(fight, teamMember, false)); // Team 2 competitor = fight.getTeam2().getMembers().get(teamMember); @@ -257,38 +257,67 @@ private String getDrawFight(FightDTO fightDTO, int duel) { // Draw Fights final String draw; if (fightDTO.getDuels().get(duel).getWinner() == 0 && fightDTO.isOver()) { - draw = String.valueOf(Score.DRAW.getPdfAbbreviation()); + return "
" + + Score.DRAW.getPdfAbbreviation() + + "
"; } else { - draw = String.valueOf(Score.EMPTY.getPdfAbbreviation()); + return String.valueOf(Score.EMPTY.getPdfAbbreviation()); } - return draw; } - private String getFaults(FightDTO fightDTO, int duel, boolean leftTeam) { - final String faultSymbol; + private String getFaultsDiv(FightDTO fightDTO, int duel, boolean leftTeam) { + final boolean fault = getFaults(fightDTO, duel, leftTeam); + if (!fault) { + return ""; + } + return "
" + + "
"; + } + + private boolean getFaults(FightDTO fightDTO, int duel, boolean leftTeam) { final boolean faults; if (leftTeam) { - faults = fightDTO.getDuels().get(duel).getCompetitor1Fault(); + return fightDTO.getDuels().get(duel).getCompetitor1Fault(); } else { - faults = fightDTO.getDuels().get(duel).getCompetitor2Fault(); + return fightDTO.getDuels().get(duel).getCompetitor2Fault(); } - if (faults) { - faultSymbol = String.valueOf(Score.FAULT.getPdfAbbreviation()); - } else { - faultSymbol = String.valueOf(Score.EMPTY.getPdfAbbreviation()); + } + + private String getScoreDiv(FightDTO fightDTO, int duel, int score, boolean leftTeam) { + final Score scoreText = getScore(fightDTO, duel, score, leftTeam); + if (scoreText == null || scoreText == Score.EMPTY) { + return ""; } - return faultSymbol; + final int scoreTime = getScoreTime(fightDTO, duel, score, leftTeam); + return "
0 ? " title=\"Duration " + scoreTime + ""\">" : ">") + + String.valueOf(scoreText.getPdfAbbreviation()).replace(" ", " ") + + "
"; } - private String getScore(FightDTO fightDTO, int duel, int score, boolean leftTeam) { + private int getScoreTime(FightDTO fightDTO, int duel, int score, boolean leftTeam) { + final int time; try { if (leftTeam) { - return String.valueOf(fightDTO.getDuels().get(duel).getCompetitor1Score().get(score).getPdfAbbreviation()); + time = fightDTO.getDuels().get(duel).getCompetitor1ScoreTime().get(score); } else { - return String.valueOf(fightDTO.getDuels().get(duel).getCompetitor2Score().get(score).getPdfAbbreviation()); + time = fightDTO.getDuels().get(duel).getCompetitor1ScoreTime().get(score); + } + return time; + } catch (Exception ignored) { + } + return -1; + } + + private Score getScore(FightDTO fightDTO, int duel, int score, boolean leftTeam) { + try { + if (leftTeam) { + return fightDTO.getDuels().get(duel).getCompetitor1Score().get(score); + } else { + return fightDTO.getDuels().get(duel).getCompetitor2Score().get(score); } } catch (IndexOutOfBoundsException | NullPointerException e) { - return ""; + return null; } } } From 7cbdf655fe4c6dce0d16882d36c6d124aca942c5 Mon Sep 17 00:00:00 2001 From: Software Magico Date: Sun, 26 May 2024 11:22:28 +0200 Subject: [PATCH 2/2] Added score time --- .../java/com/softwaremagico/kt/html/lists/BlogExporter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/kendo-tournament-pdf/src/main/java/com/softwaremagico/kt/html/lists/BlogExporter.java b/backend/kendo-tournament-pdf/src/main/java/com/softwaremagico/kt/html/lists/BlogExporter.java index 638c0a89..67faef5d 100644 --- a/backend/kendo-tournament-pdf/src/main/java/com/softwaremagico/kt/html/lists/BlogExporter.java +++ b/backend/kendo-tournament-pdf/src/main/java/com/softwaremagico/kt/html/lists/BlogExporter.java @@ -290,7 +290,7 @@ private String getScoreDiv(FightDTO fightDTO, int duel, int score, boolean leftT } final int scoreTime = getScoreTime(fightDTO, duel, score, leftTeam); return "
0 ? " title=\"Duration " + scoreTime + ""\">" : ">") + + (scoreTime > 0 ? " title=\"" + scoreTime + ""\">" : ">") + String.valueOf(scoreText.getPdfAbbreviation()).replace(" ", " ") + "
"; } @@ -301,7 +301,7 @@ private int getScoreTime(FightDTO fightDTO, int duel, int score, boolean leftTea if (leftTeam) { time = fightDTO.getDuels().get(duel).getCompetitor1ScoreTime().get(score); } else { - time = fightDTO.getDuels().get(duel).getCompetitor1ScoreTime().get(score); + time = fightDTO.getDuels().get(duel).getCompetitor2ScoreTime().get(score); } return time; } catch (Exception ignored) {