Commit 298f5442 authored by Eric Duminil's avatar Eric Duminil
Browse files

Make sure Repository is defined, and it exists, before trying to import anything.

parent 155d5e85
No related merge requests found
Pipeline #7228 passed with stage
in 33 seconds
Showing with 28 additions and 5 deletions
+28 -5
...@@ -42,8 +42,8 @@ public class RegionChooserBrowser extends Region ...@@ -42,8 +42,8 @@ public class RegionChooserBrowser extends Region
public JavaScriptFXBridge() { public JavaScriptFXBridge() {
Preferences userPrefs = Preferences.userRoot().node("/eu/simstadt/desktop"); Preferences userPrefs = Preferences.userRoot().node("/eu/simstadt/desktop");
String repoString = userPrefs.get(PREF_RECENT_REPOSITORY, "../TestRepository"); String repoString = userPrefs.get(PREF_RECENT_REPOSITORY, null);
repo = Paths.get(repoString); repo = repoString == null? null : Paths.get(repoString);
} }
/** /**
...@@ -51,6 +51,9 @@ public JavaScriptFXBridge() { ...@@ -51,6 +51,9 @@ public JavaScriptFXBridge() {
* to the JS app in order to be displayed. * to the JS app in order to be displayed.
*/ */
public void refreshHulls() { public void refreshHulls() {
if (repo == null || !Files.exists(repo)) {
selectRepository();
}
Task<Void> task = new Task<Void>() { Task<Void> task = new Task<Void>() {
@Override @Override
public Void call() throws IOException { public Void call() throws IOException {
...@@ -62,7 +65,9 @@ public Void call() throws IOException { ...@@ -62,7 +65,9 @@ public Void call() throws IOException {
task.setOnRunning(e -> { task.setOnRunning(e -> {
jsApp.call("display", "Importing citgyml. Please wait."); jsApp.call("display", "Importing citgyml. Please wait.");
if (repo != null) {
jsApp.call("showRepositoryName", repo.getFileName().toString()); jsApp.call("showRepositoryName", repo.getFileName().toString());
}
jsApp.call("init"); jsApp.call("init");
}); });
...@@ -105,13 +110,15 @@ public Integer call() throws IOException, XPathParseException, NavException, Par ...@@ -105,13 +110,15 @@ public Integer call() throws IOException, XPathParseException, NavException, Par
public void selectRepository() { public void selectRepository() {
//TODO: Check if it's really a repository, and not just a project
Preferences userPrefs = Preferences.userRoot().node("/eu/simstadt/desktop"); Preferences userPrefs = Preferences.userRoot().node("/eu/simstadt/desktop");
String currentRepo = userPrefs.get(PREF_RECENT_REPOSITORY, "../TestRepository");
DirectoryChooser fileChooser = new DirectoryChooser(); DirectoryChooser fileChooser = new DirectoryChooser();
Stage mainStage = (Stage) RegionChooserBrowser.this.getScene().getWindow(); Stage mainStage = (Stage) RegionChooserBrowser.this.getScene().getWindow();
fileChooser.setTitle("Select Repository"); fileChooser.setTitle("Select Repository");
fileChooser.setInitialDirectory(new File(currentRepo)); if (repo != null && Files.exists(repo)) {
fileChooser.setInitialDirectory(repo.toFile());
}
File repoLocation = fileChooser.showDialog(mainStage); File repoLocation = fileChooser.showDialog(mainStage);
if (repoLocation != null) { if (repoLocation != null) {
......
...@@ -89,6 +89,10 @@ public static Geometry calculateFromCityGML(Path citygmlPath) throws XPathParseE ...@@ -89,6 +89,10 @@ public static Geometry calculateFromCityGML(Path citygmlPath) throws XPathParseE
* @throws IOException * @throws IOException
*/ */
public static void extractHullsForEveryCityGML(Path repository, Consumer<String> callback) throws IOException { public static void extractHullsForEveryCityGML(Path repository, Consumer<String> callback) throws IOException {
if (!Files.exists(repository)) {
LOGGER.warning(repository + " does not appear to exist.");
return;
}
LOGGER.info("Parsing " + repository); LOGGER.info("Parsing " + repository);
RegionChooserUtils.everyCityGML(repository) RegionChooserUtils.everyCityGML(repository)
.map(gmlPath -> { .map(gmlPath -> {
......
package eu.simstadt.regionchooser.fast_xml_parser; package eu.simstadt.regionchooser.fast_xml_parser;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.nio.file.Files; import java.nio.file.Files;
...@@ -22,6 +25,7 @@ ...@@ -22,6 +25,7 @@
{ {
private static final GeometryFactory gf = new GeometryFactory(); private static final GeometryFactory gf = new GeometryFactory();
private static final Path repository = Paths.get("src/test/resources/testdata"); private static final Path repository = Paths.get("src/test/resources/testdata");
private static final Path notExistingRepository = Paths.get("src/test/resources/surely_not_here");
@Test @Test
public void testExtractConvexHullFromOneBuilding() throws IOException, XPathParseException { public void testExtractConvexHullFromOneBuilding() throws IOException, XPathParseException {
...@@ -72,4 +76,12 @@ public void testExtractConvexHullFromEveryCitygmlInRepository() throws IOExcepti ...@@ -72,4 +76,12 @@ public void testExtractConvexHullFromEveryCitygmlInRepository() throws IOExcepti
assertTrue(gmlCount >= minHullCount, "At least " + minHullCount + " citygmls should be present in repository"); assertTrue(gmlCount >= minHullCount, "At least " + minHullCount + " citygmls should be present in repository");
assertTrue(hullCount.get() >= minHullCount, "At least " + minHullCount + " hulls should have been calculated"); assertTrue(hullCount.get() >= minHullCount, "At least " + minHullCount + " hulls should have been calculated");
} }
@Test
public void testDontDoMuchWithBrokenRepo() throws IOException {
ConvexHullCalculator.extractHullsForEveryCityGML(notExistingRepository, kmlHull -> {
fail("I really shouldn't be called for any gml.");
});
assertFalse(Files.exists(notExistingRepository));
}
} }
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment