diff --git a/bin/application/DBController.class b/bin/application/DBController.class index b5624fc..fe33f4a 100644 Binary files a/bin/application/DBController.class and b/bin/application/DBController.class differ diff --git a/bin/application/apiQuery.class b/bin/application/apiQuery.class index 46bc0ca..83ad53e 100644 Binary files a/bin/application/apiQuery.class and b/bin/application/apiQuery.class differ diff --git a/src/application/DBController.java b/src/application/DBController.java index 9306c0b..91ebfab 100644 --- a/src/application/DBController.java +++ b/src/application/DBController.java @@ -115,16 +115,20 @@ public class DBController { ea.printStackTrace(); } + //getting all files from the selected directory TODO rework String[] entries = new File(mainWindowController.getPath()).list(); - if(mainWindowController.getPath().equals("") || mainWindowController.getPath() == null){ + if(mainWindowController.getPath().equals("") || mainWindowController.getPath() == null){ System.out.println("Kein Pfad angegeben"); //if path == null or "" - }else{ + }else if(new File(mainWindowController.getPath()).exists()) { System.out.println(entries.length); for(int i=0;i!=entries.length;i++){ filmsDir.add(cutOffEnd(entries[i])); } + } else { + System.out.println(mainWindowController.getPath() + "dosen't exist!"); } - + + //getting all entries from the streaming lists for(int v=0; v< mainWindowController.streamingData.size(); v++){ String fileName = mainWindowController.getStreamingPath()+"/"+mainWindowController.streamingData.get(v).getStreamUrl(); try { @@ -138,7 +142,9 @@ public class DBController { } catch (IOException e) { e.printStackTrace(); } - } + } + + //add all entries to filmsAll and filmsdbAl, for later comparing filmsAll.addAll(filmsDir); filmsAll.addAll(filmsStream); filmsdbAll.addAll(filmsdbLocal); @@ -146,6 +152,11 @@ public class DBController { System.out.println("films in directory: "+filmsAll.size()); System.out.println("filme in db: "+filmsdbAll.size()); + /** + * if filmsdbAll.size() == 0 database is empty, we need to fill it + * else check if there is something to remove or to add + * TODO separate local and streaming for better error handling + */ if(filmsdbAll.size() == 0){ System.out.println("creating entries ..."); @@ -155,7 +166,7 @@ public class DBController { if(mainWindowController.getPath().equals("") || mainWindowController.getPath() == null){ System.out.println("Kein Pfad angegeben"); //if path == null or "" - }else{ + }else if(new File(mainWindowController.getPath()).exists()){ for(int j=0;j!=entries.length;j++) //goes through all the files in the directory { ps.setInt(1, 0); //rating as integer 1. column @@ -198,12 +209,10 @@ public class DBController { ps.close(); psS.close(); }catch (SQLException ea) { - System.err.println("Konnte nicht ausgef�hrt werden"); + System.err.println("Ups! an error occured!"); ea.printStackTrace(); } }else { - - try { try { checkAddEntry(); //check if added a new file @@ -271,7 +280,7 @@ public class DBController { try { stmt = connection.createStatement(); - ResultSet rs = stmt.executeQuery("SELECT * FROM film_local WHERE titel = '"+name+"';" ); + ResultSet rs = stmt.executeQuery("SELECT * FROM film_local WHERE titel = \""+name+"\";" ); if(rs.getString(4).equals("favorite_black")){ mainWindowController.localFilms.set(i, new tableData(1, 1, 1, rs.getDouble(1), "1", rs.getString(2), rs.getString(3), new ImageView(favorite_black),rs.getBoolean(5))); }else{ @@ -282,7 +291,7 @@ public class DBController { } catch (SQLException e) { try { stmt = connection.createStatement(); - ResultSet rs = stmt.executeQuery("SELECT * FROM film_streaming WHERE titel = '"+name+"';" ); + ResultSet rs = stmt.executeQuery("SELECT * FROM film_streaming WHERE titel = \""+name+"\";" ); if(rs.getString(8).equals("favorite_black")){ mainWindowController.streamingFilms.set(i,new tableData(rs.getInt(1), rs.getInt(2), rs.getInt(3), rs.getDouble(4), rs.getString(5), rs.getString(6), rs.getString(7), new ImageView(favorite_black),rs.getBoolean(9))); }else{ @@ -305,25 +314,30 @@ public class DBController { Statement stmt = connection.createStatement(); for(int a=0; a nameText = new ArrayList(); ArrayList responseText = new ArrayList(); String fontFamily = main.getFONT_FAMILY(); diff --git a/src/application/apiQuery.java b/src/application/apiQuery.java index 8ce7105..545ca89 100644 --- a/src/application/apiQuery.java +++ b/src/application/apiQuery.java @@ -38,7 +38,8 @@ public class apiQuery{ private Image im; private String[] responseString = new String[20]; private String posterCache; - private String apiURL = "https://www.omdbapi.com/?"; + private String apiURL = "https://www.omdbapi.com/?apikey="; + private String apiKey = "b9f9fd23"; ArrayList responseText = new ArrayList(); ArrayList nameText = new ArrayList(); @@ -75,7 +76,7 @@ public class apiQuery{ moviename = moviename.replace(" ", "+"); //queryURL is apiURL and additional parameters, response-types: http,json,xml (must be json, since the response is processed with minimal-json ) - queryURL = new URL(apiURL + "t=" + moviename + "&plot=full&r=json"); + queryURL = new URL(apiURL + apiKey + "&t=" + moviename + "&plot=full&r=json"); is = queryURL.openStream(); br = new BufferedReader(new InputStreamReader(is, "UTF-8")); @@ -133,7 +134,7 @@ public class apiQuery{ } //if response == false then show mainWindowController.noFilmFound else create new Texts and add them to flowText - if(responseString[19].equals("False")){ + if(retdata.contains("\"Response\":\"False\"")){ //TODO + FIXME mainWindowController.textFlow.getChildren().add(new Text(mainWindowController.noFilmFound)); im = new Image("resources/icons/close_black_2048x2048.png"); mainWindowController.image1.setImage(im);