| @@ -1,5 +1,6 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | <?xml version="1.0" encoding="UTF-8"?> | ||||
| <classpath> | <classpath> | ||||
| <classpathentry exported="true" kind="lib" path="lib/"/> | |||||
| <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> | <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"> | ||||
| <attributes> | <attributes> | ||||
| <attribute name="maven.pomderived" value="true"/> | <attribute name="maven.pomderived" value="true"/> | ||||
| @@ -20,3 +20,4 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8 | |||||
| Import-Package: javax.inject;version="1.0.0", | Import-Package: javax.inject;version="1.0.0", | ||||
| org.eclipse.e4.ui.model.application.descriptor.basic, | org.eclipse.e4.ui.model.application.descriptor.basic, | ||||
| org.eclipse.e4.ui.model.application.ui.basic | org.eclipse.e4.ui.model.application.ui.basic | ||||
| Bundle-ClassPath: lib/sqlite-jdbc-3.34.0.jar | |||||
| @@ -1,6 +1,8 @@ | |||||
| output.. = bin/ | output.. = bin/ | ||||
| bin.includes = META-INF/,\ | bin.includes = META-INF/,\ | ||||
| .,\ | |||||
| plugin.xml,\ | plugin.xml,\ | ||||
| Application.e4xmi | |||||
| source.. = src/ | |||||
| Application.e4xmi,\ | |||||
| lib/,\ | |||||
| ./,\ | |||||
| lib/sqlite-jdbc-3.34.0.jar | |||||
| source.lib/sqlite-jdbc-3.34.0.jar = src/ | |||||
| @@ -2,6 +2,18 @@ | |||||
| <?eclipse version="3.4"?> | <?eclipse version="3.4"?> | ||||
| <plugin> | <plugin> | ||||
| <extension | |||||
| id="anotherproduct" | |||||
| point="org.eclipse.core.runtime.products"> | |||||
| <product | |||||
| name="BggToolAnother" | |||||
| application="org.eclipse.e4.ui.workbench.swt.E4Application"> | |||||
| <property | |||||
| name="appName" | |||||
| value="BggToolAnother"> | |||||
| </property> | |||||
| </product> | |||||
| </extension> | |||||
| <extension | <extension | ||||
| id="bggtoolanother" | id="bggtoolanother" | ||||
| point="org.eclipse.core.runtime.products"> | point="org.eclipse.core.runtime.products"> | ||||
| @@ -1,6 +1,5 @@ | |||||
| package xyz.veronie.bgg.localdb; | package xyz.veronie.bgg.localdb; | ||||
| import java.io.File; | |||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.List; | import java.util.List; | ||||
| @@ -16,11 +15,7 @@ public class LocalDbAdapterService { | |||||
| private void initDb() { | private void initDb() { | ||||
| sqliteController = SqliteController.getInstance(); | sqliteController = SqliteController.getInstance(); | ||||
| File dbFile = sqliteController.getDbPath().toFile(); | |||||
| if(!dbFile.exists()) { | |||||
| sqliteController.createSchema(); | |||||
| } | |||||
| sqliteController.createSchema(); | |||||
| } | } | ||||
| @@ -75,15 +75,11 @@ public class SqliteController { | |||||
| try { | try { | ||||
| if(connection != null) { | if(connection != null) { | ||||
| Statement stmt = connection.createStatement(); | Statement stmt = connection.createStatement(); | ||||
| stmt.executeUpdate("DROP TABLE IF EXISTS Thing;"); | |||||
| stmt.executeUpdate("DROP TABLE IF EXISTS ThingList"); | |||||
| stmt.executeUpdate("DROP TABLE IF EXISTS ThingListToThing"); | |||||
| stmt.executeUpdate("CREATE TABLE Thing (ThingId INTEGER PRIMARY KEY, Name, ImgUrl, ThumbUrl, Comment, NumPlays);"); | |||||
| stmt.executeUpdate("CREATE TABLE ThingList (ListId INTEGER PRIMARY KEY, Name) ON DELETE CASCADE;"); | |||||
| stmt.executeUpdate("CREATE UNIQUE INDEX idx1 ON ThingList(Name)"); | |||||
| stmt.executeUpdate("CREATE TABLE ThingListToThing (ListId, ThingId, FOREIGN KEY (ListId) REFERENCES ThingList(ListId), FOREIGN KEY (ThingId) REFERENCES Thing(ThingId));"); | |||||
| stmt.executeUpdate("CREATE UNIQUE INDEX idx2 ON ThingListToThing(ListId, ThingId)"); | |||||
| stmt.executeUpdate("CREATE TABLE IF NOT EXISTS Thing (ThingId INTEGER PRIMARY KEY, Name, ImgUrl, ThumbUrl, Comment, NumPlays);"); | |||||
| stmt.executeUpdate("CREATE TABLE IF NOT EXISTS ThingList (ListId INTEGER PRIMARY KEY, Name);"); | |||||
| stmt.executeUpdate("CREATE UNIQUE INDEX IF NOT EXISTS idx1 ON ThingList(Name)"); | |||||
| stmt.executeUpdate("CREATE TABLE IF NOT EXISTS ThingListToThing (ListId, ThingId, FOREIGN KEY (ListId) REFERENCES ThingList(ListId), FOREIGN KEY (ThingId) REFERENCES Thing(ThingId));"); | |||||
| stmt.executeUpdate("CREATE UNIQUE INDEX IF NOT EXISTS idx2 ON ThingListToThing(ListId, ThingId)"); | |||||
| } else { | } else { | ||||
| System.err.println("ERROR: Couldn't create Schema, connection is null."); | System.err.println("ERROR: Couldn't create Schema, connection is null."); | ||||
| } | } | ||||
| @@ -15,7 +15,7 @@ public class ResultConfig { | |||||
| // TODO: integrate different filters (or extend?) | // TODO: integrate different filters (or extend?) | ||||
| public SourceFilter source = SourceFilter.BGG_USER; | public SourceFilter source = SourceFilter.BGG_USER; | ||||
| public ResultAction action = ResultAction.REP; | |||||
| public ResultAction action = ResultAction.ONLY_NEW; | |||||
| public Subtype subtype = Subtype.BOARDGAME; | public Subtype subtype = Subtype.BOARDGAME; | ||||
| // bgg user filter settings | // bgg user filter settings | ||||
| @@ -120,5 +120,14 @@ public class Thing { | |||||
| return returnStr; | return returnStr; | ||||
| } | } | ||||
| @Override | |||||
| public boolean equals(Object o) { | |||||
| if(o instanceof Thing) { | |||||
| return ((Thing)o).getId() == getId(); | |||||
| } else { | |||||
| return false; | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -51,7 +51,7 @@ public class ThingProvider { | |||||
| // helper function for subtractThingMetas | // helper function for subtractThingMetas | ||||
| private static Predicate<Thing> thingEqual(final Thing other) | private static Predicate<Thing> thingEqual(final Thing other) | ||||
| { | { | ||||
| return p -> p.getId() == other.getId(); | |||||
| return p -> p.equals(other); | |||||
| } | } | ||||
| /// remove the things in the argument from the current list of things (using their ID) | /// remove the things in the argument from the current list of things (using their ID) | ||||
| @@ -60,6 +60,18 @@ public class ThingProvider { | |||||
| this.things.removeIf(thingEqual(thing)); | this.things.removeIf(thingEqual(thing)); | ||||
| } | } | ||||
| } | } | ||||
| /// keep only things that are new in the argument vs the internal thing list | |||||
| public void keepOnlyNew(ArrayList<Thing> things) { | |||||
| List<Thing> newThings = new ArrayList<Thing>(); | |||||
| for(Thing thing : things) { | |||||
| if(!this.things.contains(thing)) { | |||||
| newThings.add(thing); | |||||
| } | |||||
| } | |||||
| this.things = newThings; | |||||
| } | |||||
| /// keep only things that exist in both argument list and current list (by ID) | /// keep only things that exist in both argument list and current list (by ID) | ||||
| public void intersectThings(ArrayList<Thing> things) { | public void intersectThings(ArrayList<Thing> things) { | ||||
| @@ -84,5 +96,6 @@ public class ThingProvider { | |||||
| public List<Thing> getThings() { | public List<Thing> getThings() { | ||||
| return things; | return things; | ||||
| } | } | ||||
| } | } | ||||
| @@ -4,8 +4,8 @@ public enum ResultAction { | |||||
| ADD("add to"), | ADD("add to"), | ||||
| REP("replace"), | REP("replace"), | ||||
| SUB("subtract from"), | SUB("subtract from"), | ||||
| AND("intercept with"); | |||||
| //MIS("mis"); | |||||
| AND("intersect with"), | |||||
| ONLY_NEW("keep not in"); | |||||
| private String name; | private String name; | ||||
| @@ -211,6 +211,9 @@ public class PreparePart { | |||||
| case AND: | case AND: | ||||
| thingProvider.intersectThings(things); | thingProvider.intersectThings(things); | ||||
| break; | break; | ||||
| case ONLY_NEW: | |||||
| thingProvider.keepOnlyNew(things); | |||||
| break; | |||||
| } | } | ||||
| eventBroker.send(EventConstants.TOPIC_RESULT_CHANGED, ""); | eventBroker.send(EventConstants.TOPIC_RESULT_CHANGED, ""); | ||||
| eventBroker.send(EventConstants.TOPIC_STATUS, "Fetched " + Integer.toString(things.size()) + " things."); | eventBroker.send(EventConstants.TOPIC_STATUS, "Fetched " + Integer.toString(things.size()) + " things."); | ||||