Skip to content

Commit

Permalink
Merge/rel8 (#2071)
Browse files Browse the repository at this point in the history
* #1797 create beta (#2052)

* Fix build (#2054)

* #1797 create beta

* #1797 fix build

* #2055 fix slow opening of team analyzer panel (#2056)

* update release_notes.md

* #2055 remove unused info label

* #2055 remove unused info label (code analysis results)

* #2055 release_notes.md

* #2055 release_notes.md

* Use SwingWorker to properly fix hanging UI. (#2057)

* Update dependencies, in particular OkHttp to fix CVE. (#2058)

This fixes CVE-2023-3635, cf. https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2023-3635

* #2059 fix currency error in team analyzer's total salary column (#2060)

* #2063 add 5 new countries to international flags module (#2064)

* #2063 add 5 new countries to international flags module

* #2063 add 5 new countries to international flags module (review)

* release_notes.md translator

* #2063 the flag files

* #2065 truncate match report if string is too long for database column (#2066)

* #2065 truncate match report if string is too long for database column

* #2065 rename AbstractTable.truncateString

* #2063 Guinea (#2068)

* #2063 download missing world details (#2070)

* #2063 download missing world details

* #2063 download missing world details

* #2063 download missing world details

* #2063 fix database error on matches reload

---------

Co-authored-by: Sébastien Le Callonnec <sebastien@weblogism.com>
  • Loading branch information
wsbrenk and tychobrailleur committed May 21, 2024
1 parent 1cb63b5 commit 33b965b
Show file tree
Hide file tree
Showing 14 changed files with 117 additions and 112 deletions.
17 changes: 13 additions & 4 deletions src/main/java/core/db/DBManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public void disconnect() {
/**
* connect to the database
*/
private void connect() throws Exception {
private void connect() {
User current_user = UserManager.instance().getCurrentUser();
if (connectionManager != null) {
connectionManager.connect(current_user.getDbURL(), current_user.getDbUsername(), current_user.getDbPwd(), UserManager.instance().getDriver());
Expand Down Expand Up @@ -1560,7 +1560,6 @@ public void setTransferType(TransferType type) {
*
* @return the world detail league [ ]
*/
// WorldDetail
public List<WorldDetailLeague> getAllWorldDetailLeagues() {
return ((WorldDetailsTable) getTable(WorldDetailsTable.TABLENAME))
.getAllWorldDetailLeagues();
Expand All @@ -1571,14 +1570,24 @@ public List<WorldDetailLeague> getAllWorldDetailLeagues() {
*
* @param leagues the leagues
*/
public void saveWorldDetailLeagues(List<WorldDetailLeague> leagues) {
public void storeWorldDetailLeagues(List<WorldDetailLeague> leagues) {
WorldDetailsTable table = (WorldDetailsTable) getTable(WorldDetailsTable.TABLENAME);
table.truncateTable();
for (WorldDetailLeague league : leagues) {
table.insertWorldDetailsLeague(league);
table.storeWorldDetailsLeague(league);
}
}

/**
* Save single world detail league.
*
* @param league The league
*/
public void storeWorldDetailLeague(WorldDetailLeague league) {
WorldDetailsTable table = (WorldDetailsTable) getTable(WorldDetailsTable.TABLENAME);
table.storeWorldDetailsLeague(league);
}

// --------------------------------------------------------------------------------
// -------------------------------- Statistik Part
// --------------------------------
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/core/db/IfaMatchTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,10 @@ void insertMatch(IfaMatch match) {
}

@Override
protected String createSelectStatement(){
return createSelectStatement("");
protected String createDeleteStatement() {
return createDeleteStatement(" WHERE TRUE");
}

void deleteAllMatches() {
executePreparedDelete();
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/core/db/WorldDetailsTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ protected String createSelectStatement() {
return createSelectStatement("");
}

void insertWorldDetailsLeague(WorldDetailLeague league){
void storeWorldDetailsLeague(WorldDetailLeague league){
if(league == null)
return;
store(league);
Expand All @@ -44,7 +44,7 @@ List<WorldDetailLeague> getAllWorldDetailLeagues(){
@Override
protected void insertDefaultValues(){
for ( var league : WorldDetailLeague.allLeagues){
insertWorldDetailsLeague(league);
storeWorldDetailsLeague(league);
}
}
}
6 changes: 6 additions & 0 deletions src/main/java/core/model/WorldDetailLeague.java
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ public class WorldDetailLeague extends AbstractTable.Storable {
new WorldDetailLeague(163,191,"San Marino"),
new WorldDetailLeague(164,188,"Haiti"),
new WorldDetailLeague(165,190,"Puerto Rico"),
new WorldDetailLeague(166,194,"Grenada"),
new WorldDetailLeague(167,193,"Burkina Faso"),
new WorldDetailLeague(168,192,"Nepal"),
new WorldDetailLeague(169,197,"Guyana"),
new WorldDetailLeague(170,196,"Tahiti"),
new WorldDetailLeague(171,198,"Guinea"),
new WorldDetailLeague(1000,1000,"International")
};

Expand Down
46 changes: 41 additions & 5 deletions src/main/java/core/model/WorldDetailsManager.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package core.model;

import core.db.DBManager;
import core.file.xml.XMLManager;
import core.file.xml.XMLWorldDetailsParser;
import core.net.MyConnector;
import core.util.HOLogger;

import java.util.HashMap;
import java.util.List;
import java.util.*;

public class WorldDetailsManager {

private static WorldDetailsManager WMANAGER = null;
private List<WorldDetailLeague> leagues;
private HashMap<Integer, WorldDetailLeague> countryMap = new HashMap<Integer, WorldDetailLeague>();
private HashMap<Integer, WorldDetailLeague> leagueMap = new HashMap<Integer, WorldDetailLeague>();
private final HashMap<Integer, WorldDetailLeague> countryMap = new HashMap<>();
private final HashMap<Integer, WorldDetailLeague> leagueMap = new HashMap<>();
private int totalUsers;

public static WorldDetailsManager instance() {
Expand Down Expand Up @@ -48,12 +51,45 @@ public WorldDetailLeague getWorldDetailLeagueByLeagueId(Integer leagueId) {
return leagueMap.get(leagueId);
}

/**
* Get world detail information of country id.
* If cache is empty, it will be initialized by the details stored in the database.
* If this information does not contain the requested country id, the world details will be downloaded
* from hattrick. The downloaded object will be added to the cache and the database.
* @param countryId Country Id
* @return WorldDetailLeague
*/
public WorldDetailLeague getWorldDetailLeagueByCountryId(Integer countryId) {
if (countryMap.isEmpty()) {
initialize();
}
var ret = countryMap.get(countryId);
if (ret == null) {
ret = downloadWorldDetailLeague(countryId);
DBManager.instance().storeWorldDetailLeague(ret);
initialize();
}
return ret;
}

return countryMap.get(countryId);
/**
* Download missing world detail information
* @param countryId Country Id
* @return WorldDetailLeague
*/
private WorldDetailLeague downloadWorldDetailLeague(Integer countryId) {
WorldDetailLeague ret = null;
try {
var worldDetails = MyConnector.instance().getWorldDetailsByCountryId(countryId);
var leagues = XMLWorldDetailsParser.parseDetails(XMLManager.parseString(worldDetails));
if (!leagues.isEmpty()) {
ret = leagues.get(0);
}
}
catch (Exception e) {
HOLogger.instance().warning(getClass(), "Error downloading world details from " + countryId);
}
return ret;
}

public final List<WorldDetailLeague> getLeagues() {
Expand Down
17 changes: 5 additions & 12 deletions src/main/java/core/net/MyConnector.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import com.github.scribejava.core.model.*;
import core.file.xml.XMLCHPPPreParser;
import core.file.xml.XMLTeamDetailsParser;
import core.gui.CursorToolkit;
import core.gui.HOMainFrame;
import core.model.HOVerwaltung;
Expand Down Expand Up @@ -508,6 +507,11 @@ public String getWorldDetails(int leagueId) throws IOException {
return getCHPPWebFile(url);
}

public String getWorldDetailsByCountryId(int countryId) {
String url = htUrl + "?file=worlddetails&version=1.9&countryID=" + countryId;
return getCHPPWebFile(url);
}

// ///////////////////////////////////////////////////////////////////////////////
// Update Checker
// //////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -572,17 +576,6 @@ public void enableProxy(ProxySettings proxySettings) {
}
}

/**
* Get the region id for a certain team.
*/
public String fetchRegionID(int teamId) {
String xml = getTeamDetails(teamId);
if (!xml.isEmpty()){
return XMLTeamDetailsParser.fetchRegionID(xml);
}
return "-1";
}

public InputStream getFileFromWeb(String url, boolean displaysettingsScreen) {
if (displaysettingsScreen) {
// Show Screen
Expand Down
18 changes: 6 additions & 12 deletions src/main/java/module/ifa/FlagPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void initialize(boolean away, IfaModel ifaModel, FlagDisplayModel flagDi
constraints.gridwidth = 1;

if (this.flagLabels != null) {
int i=0;
int i = 0;
for (var flagLabel : this.flagLabels) {
constraints.gridx = i % flagDisplayModel.getFlagWidth();
constraints.gridy = 2 + i / flagDisplayModel.getFlagWidth();
Expand All @@ -94,11 +94,11 @@ void setHeaderVisible(boolean enable) {
}

private void createFlagLabels(boolean away, IfaModel ifaModel, FlagDisplayModel flagDisplayModel) {
this.flagLabels = new ArrayList<FlagLabel>();
this.flagLabels = new ArrayList<>();
WorldDetailsManager.instance().getLeagues().stream()
.filter(l->l.getLeagueId()!=APACHE_LEAGUE_ID)
.sorted((l1,l2)-> ObjectUtils.compare(l1.getCountryName(),l2.getCountryName()))
.forEach(l->addFlagLabel(l, away, ifaModel, flagDisplayModel));
.filter(l -> l.getLeagueId() != APACHE_LEAGUE_ID)
.sorted((l1, l2) -> ObjectUtils.compare(l1.getCountryName(), l2.getCountryName()))
.forEach(l -> addFlagLabel(l, away, ifaModel, flagDisplayModel));
}

private void addFlagLabel(WorldDetailLeague league, boolean away, IfaModel ifaModel, FlagDisplayModel flagDisplayModel) {
Expand All @@ -107,13 +107,7 @@ private void addFlagLabel(WorldDetailLeague league, boolean away, IfaModel ifaMo
flagLabel.setCountryName(league.getCountryName());
flagLabel.setIcon(ImageUtilities.getCountryFlagIcon(flagLabel.getCountryId()));
flagLabel.setToolTipText(flagLabel.getCountryName());

if ((away && ifaModel.isVisited(league.getCountryId()))
|| (!away && ifaModel.isHosted(league.getCountryId()))) {
flagLabel.setEnabled(true);
} else {
flagLabel.setEnabled(false);
}
flagLabel.setEnabled((away && ifaModel.isVisited(league.getCountryId())) || (!away && ifaModel.isHosted(league.getCountryId())));
this.flagLabels.add(flagLabel);
}
}
Loading

0 comments on commit 33b965b

Please sign in to comment.