This is an automated email from the ASF dual-hosted git repository. desruisseaux pushed a commit to branch geoapi-4.0 in repository https://gitbox.apache.org/repos/asf/sis.git
The following commit(s) were added to refs/heads/geoapi-4.0 by this push: new 098b3bc Popup a dialog box if an error occurred while downloading optional resources. 098b3bc is described below commit 098b3bc1b8c3101bcc026a1b5961c7339c24ffee Author: Martin Desruisseaux <martin.desruisse...@geomatys.com> AuthorDate: Tue Oct 19 16:03:38 2021 +0200 Popup a dialog box if an error occurred while downloading optional resources. --- .../gui/referencing/RecentReferenceSystems.java | 9 +++++-- .../sis/internal/gui/OptionalDataDownloader.java | 31 ++++++++++++++++++++-- .../org/apache/sis/internal/gui/Resources.java | 7 ++++- .../apache/sis/internal/gui/Resources.properties | 3 ++- .../sis/internal/gui/Resources_fr.properties | 3 ++- .../apache/sis/setup/OptionalInstallations.java | 17 +++++++++--- .../java/org/apache/sis/setup/package-info.java | 2 +- 7 files changed, 60 insertions(+), 12 deletions(-) diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/RecentReferenceSystems.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/RecentReferenceSystems.java index 74c1924..909f903 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/RecentReferenceSystems.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/referencing/RecentReferenceSystems.java @@ -51,6 +51,7 @@ import org.apache.sis.internal.gui.BackgroundThreads; import org.apache.sis.internal.gui.ExceptionReporter; import org.apache.sis.internal.gui.GUIUtilities; import org.apache.sis.internal.gui.NonNullObjectProperty; +import org.apache.sis.internal.gui.OptionalDataDownloader; import org.apache.sis.internal.gui.RecentChoices; import org.apache.sis.internal.system.Modules; import org.apache.sis.internal.util.Strings; @@ -70,7 +71,7 @@ import org.apache.sis.internal.util.Strings; * </ul> * * @author Martin Desruisseaux (Geomatys) - * @version 1.1 + * @version 1.2 * @since 1.1 * @module */ @@ -883,12 +884,16 @@ next: for (int i=0; i<count; i++) { * is not expected to be present in every runtime environments. The consequence of this error is "only" * that the CRS will not be listed among the reference systems that the user can choose. * - * <p>The default implementation log the error at {@link java.util.logging.Level#FINE}. + * <p>The default implementation popups an alert dialog only if the error occurred after the user + * accepted to {@linkplain org.apache.sis.setup.OptionalInstallations download optional dependencies}, + * because the error may be caused by a problem related to the download operation. + * Otherwise this method only logs the error at {@link java.util.logging.Level#FINE}. * No other processing is done; user is not notified unless (s)he paid attention to loggings.</p> * * @param e the error that occurred. */ protected void errorOccurred(final FactoryException e) { + OptionalDataDownloader.reportIfInstalling(e); Logging.recoverableException(Logging.getLogger(Modules.APPLICATION), RecentReferenceSystems.class, "updateItems", e); } } diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/OptionalDataDownloader.java b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/OptionalDataDownloader.java index dff857a..d1b4f2c 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/OptionalDataDownloader.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/OptionalDataDownloader.java @@ -21,6 +21,7 @@ import javafx.scene.control.Alert; import javafx.scene.control.ButtonType; import javafx.scene.control.DialogPane; import javafx.scene.web.WebView; +import org.opengis.util.FactoryException; import org.apache.sis.gui.DataViewer; import org.apache.sis.internal.system.Fallback; import org.apache.sis.setup.OptionalInstallations; @@ -33,13 +34,21 @@ import org.apache.sis.setup.OptionalInstallations; * the EPSG terms of use. * * @author Martin Desruisseaux (Geomatys) - * @version 1.1 + * @version 1.2 * @since 1.1 * @module */ @Fallback public final class OptionalDataDownloader extends OptionalInstallations { /** + * Whether user accepted to download and install the resources. + * This is used for deciding if error should be reported to the user or only logged. + * + * @see #reportIfInstalling(FactoryException) + */ + private static volatile boolean accepted; + + /** * Creates a new installation scripts provider. */ public OptionalDataDownloader() { @@ -79,6 +88,24 @@ public final class OptionalDataDownloader extends OptionalInstallations { pane.setPrefHeight(600); dialog.setHeaderText(resources.getString(Resources.Keys.LicenseAgreement)); } - return dialog.showAndWait().orElse(ButtonType.NO) == ButtonType.YES; + return accepted = dialog.showAndWait().orElse(ButtonType.NO) == ButtonType.YES; + } + + /** + * Reports the given error if it happened during download and installation of a resource. + * An explicit action for reporting errors to the user is needed because callers such as + * {@link org.apache.sis.gui.referencing.RecentReferenceSystems} will be default catch + * exceptions and simply log that the CRS as unavailable. + */ + public static void reportIfInstalling(final FactoryException exception) { + final boolean s; + synchronized (OptionalInstallations.class) { + s = accepted; + accepted = false; // For avoidig to report twice. + } + if (s) { + ExceptionReporter.show(DataViewer.getCurrentStage(), null, + Resources.format(Resources.Keys.CanNotInstallResource), exception); + } } } diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java index dbee944..a2ba112 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java +++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.java @@ -96,6 +96,11 @@ public final class Resources extends IndexedResourceBundle { public static final short CanNotFetchTile_2 = 5; /** + * Can not install the resource. + */ + public static final short CanNotInstallResource = 62; + + /** * Can not open “{0}”. */ public static final short CanNotReadFile_1 = 6; @@ -172,7 +177,7 @@ public final class Resources extends IndexedResourceBundle { /** * This geodetic dataset is required for the support of Coordinate Reference Systems defined by - * {0} codes. The database will use {1} Mb in directory {2}. + * {0} codes. The database will use {1} Mb in the “{2}” directory. */ public static final short DownloadDetails_3 = 59; diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties index 1ece0b8..561c4a1 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties +++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources.properties @@ -31,6 +31,7 @@ CanNotCreateCRS_1 = Can not create reference system \u201c{0}\u201d. CanNotCreateXML = Can not create XML document. CanNotReadResource = A resource contained in the file can not be read. The cause is given below. CanNotRender = An error occurred while rendering the data. +CanNotInstallResource = Can not install the resource. CanNotUseRefSys_1 = Can not use the \u201c{0}\u201d reference system. CenteredProjection = Centered projection ClearAll = Clear all @@ -43,7 +44,7 @@ DisplayedSize = Displayed size DisplayStart = Display start DoesNotCoverAOI = Does not cover the area of interest. DownloadAndInstall_1 = Download and install {0} database? -DownloadDetails_3 = This geodetic dataset is required for the support of Coordinate Reference Systems defined by {0} codes. The database will use {1} Mb in directory {2}. +DownloadDetails_3 = This geodetic dataset is required for the support of Coordinate Reference Systems defined by {0} codes. The database will use {1} Mb in the \u201c{2}\u201d directory. ErrorDetails = Details about error ErrorExportingData = Error exporting data ErrorOpeningFile = Error opening file diff --git a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties index 2998cd0..1213f19 100644 --- a/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties +++ b/application/sis-javafx/src/main/java/org/apache/sis/internal/gui/Resources_fr.properties @@ -36,6 +36,7 @@ CanNotCreateCRS_1 = Ne peut pas cr\u00e9er le syst\u00e8me de r\u00e9f\u00e CanNotCreateXML = Ne peut pas cr\u00e9er le document XML. CanNotReadResource = Une ressource contenue dans le fichier ne peut pas \u00eatre lue. La cause est donn\u00e9e ci-dessous. CanNotRender = Une erreur est survenue lors de l\u2019affichage des donn\u00e9es. +CanNotInstallResource = Ne peut pas installer la ressource. CanNotUseRefSys_1 = Ne peut pas utiliser le syst\u00e8me de r\u00e9f\u00e9rence \u00ab\u202f{0}\u202f\u00bb. CenteredProjection = Projection centr\u00e9e ClearAll = Effacer tout @@ -48,7 +49,7 @@ DisplayedSize = Taille affich\u00e9e DisplayStart = D\u00e9but de l\u2019affichage DoesNotCoverAOI = Ne couvre pas la r\u00e9gion d\u2019int\u00e9r\u00eat. DownloadAndInstall_1 = T\u00e9l\u00e9charger et installer la base de donn\u00e9es {0}? -DownloadDetails_3 = Cette base de donn\u00e9es est n\u00e9cessaire pour le support des syst\u00e8mes de r\u00e9f\u00e9rences d\u00e9finis par des codes {0}. La base occupera {1} Mo dans le r\u00e9pertoire {2}. +DownloadDetails_3 = Cette base de donn\u00e9es est n\u00e9cessaire pour le support des syst\u00e8mes de r\u00e9f\u00e9rences d\u00e9finis par des codes {0}. La base occupera {1} Mo dans le r\u00e9pertoire \u00ab\u202f{2}\u202f\u00bb. ErrorDetails = D\u00e9tails \u00e0 propos de l\u2019erreur ErrorExportingData = Erreur \u00e0 l\u2019exportation de donn\u00e9es ErrorOpeningFile = Erreur \u00e0 l\u2019ouverture du fichier diff --git a/core/sis-utility/src/main/java/org/apache/sis/setup/OptionalInstallations.java b/core/sis-utility/src/main/java/org/apache/sis/setup/OptionalInstallations.java index 9a42c59..ed564b1 100644 --- a/core/sis-utility/src/main/java/org/apache/sis/setup/OptionalInstallations.java +++ b/core/sis-utility/src/main/java/org/apache/sis/setup/OptionalInstallations.java @@ -46,15 +46,24 @@ import static org.apache.sis.internal.util.Constants.EPSG; * </ul> * * @author Martin Desruisseaux (Geomatys) - * @version 1.1 + * @version 1.2 * @since 1.1 * @module */ public abstract class OptionalInstallations extends InstallationResources implements Localized { /** + * The {@systemProperty org.apache.sis.epsg.downloadURL} system property for overriding + * the {@link #DOWNLOAD_URL} value. This is useful for testing purpose before a release, + * or for providing a work-around for bad URL after release. + * + * @since 1.2 + */ + private static final String DOWNLOAD_PROPERTY = "org.apache.sis.epsg.downloadURL"; + + /** * Where to download the EPSG scripts after user has approved the terms of use. */ - private static final String DOWNLOAD_URL = "http://repo1.maven.org/maven2/org/apache/sis/non-free/sis-epsg/1.1/sis-epsg-1.1.jar"; + private static final String DOWNLOAD_URL = "https://repo1.maven.org/maven2/org/apache/sis/non-free/sis-epsg/1.1/sis-epsg-1.1.jar"; /** * Estimation of the EPSG database size after installation, in megabytes. @@ -167,7 +176,7 @@ public abstract class OptionalInstallations extends InstallationResources implem */ private String getDownloadURL(final String authority) { switch (authority) { - case EPSG: return DOWNLOAD_URL; + case EPSG: return System.getProperty(DOWNLOAD_PROPERTY, DOWNLOAD_URL); default: throw unsupported(authority); // More authorities may be added in the future. } } @@ -189,7 +198,7 @@ public abstract class OptionalInstallations extends InstallationResources implem return c; } } - // Should not happen. + // May happen if the URL is wrong. throw new FileNotFoundException(Errors.getResources(getLocale()).getString(Errors.Keys.FileNotFound_1, source)); } diff --git a/core/sis-utility/src/main/java/org/apache/sis/setup/package-info.java b/core/sis-utility/src/main/java/org/apache/sis/setup/package-info.java index b8a6a90..8849d09 100644 --- a/core/sis-utility/src/main/java/org/apache/sis/setup/package-info.java +++ b/core/sis-utility/src/main/java/org/apache/sis/setup/package-info.java @@ -23,7 +23,7 @@ * is created. * * @author Martin Desruisseaux (Geomatys) - * @version 1.0 + * @version 1.2 * @since 0.3 * @module */