Improve error handling

This commit is contained in:
2020-10-18 22:20:56 +02:00
parent 2f66771b0d
commit 81b68b27f7
2 changed files with 13 additions and 9 deletions

View File

@@ -18,7 +18,7 @@ public class App {
private static int season; private static int season;
private static int league; private static int league;
private static String configFile; private static String configFile;
private static Logger logger = LogManager.getLogger(App.class); private static final Logger logger = LogManager.getLogger(App.class);
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
initOptions(args); initOptions(args);

View File

@@ -1,9 +1,12 @@
package de.jeyp91.tippliga; package de.jeyp91.tippliga;
import com.google.api.client.util.DateTime; import com.google.api.client.util.DateTime;
import de.jeyp91.App;
import de.jeyp91.TeamIDMatcher; import de.jeyp91.TeamIDMatcher;
import de.jeyp91.apifootball.APIFootballMatch; import de.jeyp91.apifootball.APIFootballMatch;
import de.jeyp91.apifootball.APIFootballMatchesProvider; import de.jeyp91.apifootball.APIFootballMatchesProvider;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.simple.JSONArray; import org.json.simple.JSONArray;
import org.json.simple.JSONObject; import org.json.simple.JSONObject;
@@ -13,11 +16,12 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase { public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
private static Logger logger = LogManager.getLogger(App.class);
ArrayList<TLWMatch> tlwMatchesOriginal; ArrayList<TLWMatch> tlwMatchesOriginal;
ArrayList<TLWMatch> tlwMatchesUpdated; ArrayList<TLWMatch> tlwMatchesUpdated;
public TLWMatchesUpdaterFootball(int season, int league, String configFileName) throws Exception { public TLWMatchesUpdaterFootball(int season, int league, String configFileName) {
this.season = season; this.season = season;
this.league = league; this.league = league;
@@ -29,7 +33,7 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
this.initUpdates(); this.initUpdates();
} }
private void initUpdates() throws Exception { private void initUpdates() {
APIFootballMatchesProvider apiFootballMatchesProvider = new APIFootballMatchesProvider(this.season); APIFootballMatchesProvider apiFootballMatchesProvider = new APIFootballMatchesProvider(this.season);
TippligaSQLConnector tippligaSQLConnector = new TippligaSQLConnector(); TippligaSQLConnector tippligaSQLConnector = new TippligaSQLConnector();
@@ -44,7 +48,7 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
for (TLWMatch match : tlwMatchesOriginalMatchday) tlwMatchesUpdatedMatchday.add(new TLWMatch(match)); for (TLWMatch match : tlwMatchesOriginalMatchday) tlwMatchesUpdatedMatchday.add(new TLWMatch(match));
if (apiFootballMatches.size() > tlwMatchesUpdatedMatchday.size()) { if (apiFootballMatches.size() > tlwMatchesUpdatedMatchday.size()) {
throw new Exception("Not matching config!"); logger.error("Not matching config!");
} }
addMissingMatches(tlwMatchesUpdatedMatchday, apiFootballMatches); addMissingMatches(tlwMatchesUpdatedMatchday, apiFootballMatches);
@@ -105,7 +109,7 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
} }
private void addMissingMatches(ArrayList<TLWMatch> tlwMatches, private void addMissingMatches(ArrayList<TLWMatch> tlwMatches,
ArrayList<APIFootballMatch> apiFootballMatches) throws Exception { ArrayList<APIFootballMatch> apiFootballMatches) {
ArrayList<APIFootballMatch> missingMatches = new ArrayList<>(); ArrayList<APIFootballMatch> missingMatches = new ArrayList<>();
@@ -125,14 +129,14 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
} }
} }
if(!done) { if(!done) {
throw new Exception("Could not add missing match"); logger.error("Could not add missing match");
} }
} }
} }
private void updateMatchDateTimes( private void updateMatchDateTimes(
ArrayList<TLWMatch> tlwMatches, ArrayList<TLWMatch> tlwMatches,
ArrayList<APIFootballMatch> apiFootballMatches) throws Exception ArrayList<APIFootballMatch> apiFootballMatches)
{ {
for(APIFootballMatch apiFootballMatch : apiFootballMatches) { for(APIFootballMatch apiFootballMatch : apiFootballMatches) {
TLWMatch tlwMatch = getMatchingMatch(apiFootballMatch, tlwMatches); TLWMatch tlwMatch = getMatchingMatch(apiFootballMatch, tlwMatches);
@@ -155,7 +159,7 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
} }
} }
private TLWMatch getMatchingMatch(APIFootballMatch apiFootballMatch, ArrayList<TLWMatch> tlwMatches) throws Exception { private TLWMatch getMatchingMatch(APIFootballMatch apiFootballMatch, ArrayList<TLWMatch> tlwMatches) {
int foundMatches = 0; int foundMatches = 0;
TLWMatch matchingMatch = null; TLWMatch matchingMatch = null;
for(TLWMatch match : tlwMatches) { for(TLWMatch match : tlwMatches) {
@@ -170,7 +174,7 @@ public class TLWMatchesUpdaterFootball extends TLWMatchesManagerBase {
} }
} }
if(foundMatches > 1) { if(foundMatches > 1) {
throw new Exception("Found more than one matching matches"); logger.error("Found more than one matching matches");
} }
return matchingMatch; return matchingMatch;
} }