sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] branch geoapi-4.0 updated: Provide information about the netCDF file format in metadata.
Date Thu, 17 Jan 2019 10:32:43 GMT
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 4a94e78  Provide information about the netCDF file format in metadata.
4a94e78 is described below

commit 4a94e78319cc349406fe9deec45f70051d92a2f9
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Thu Jan 17 11:28:32 2019 +0100

    Provide information about the netCDF file format in metadata.
---
 .../org/apache/sis/internal/netcdf/Decoder.java    | 25 +++++++++++++++----
 .../sis/internal/netcdf/impl/ChannelDecoder.java   | 11 ++++++++
 .../sis/internal/netcdf/ucar/DecoderWrapper.java   | 19 ++++++++++++++
 .../apache/sis/storage/netcdf/MetadataReader.java  | 14 +++++++++--
 .../sis/internal/storage/MetadataBuilder.java      | 29 ++++++++++++++++++++++
 5 files changed, 91 insertions(+), 7 deletions(-)

diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java
index 425611b..aca6d33 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Decoder.java
@@ -130,12 +130,27 @@ public abstract class Decoder extends ReferencingFactoryContainer implements
Clo
     public abstract String getFilename();
 
     /**
+     * Returns an identification of the file format. This method should returns an array
of length 1, 2 or 3 as below:
+     *
+     * <ul>
+     *   <li>One of the following identifier in the first element: {@code "NetCDF"},
{@code "NetCDF-4"} or other values
+     *       defined by the UCAR library. If known, it will be used as an identifier for
a more complete description to
+     *       be provided by {@link org.apache.sis.metadata.sql.MetadataSource#lookup(Class,
String)}.</li>
+     *   <li>Optionally a human-readable description in the second array element.</li>
+     *   <li>Optionally a version in the third array element.</li>
+     * </ul>
+     *
+     * @return identification of the file format, human-readable description and version
number.
+     */
+    public abstract String[] getFormatDescription();
+
+    /**
      * Defines the groups where to search for named attributes, in preference order.
      * The {@code null} group name stands for the global attributes.
      *
      * @param  groupNames  the name of the group where to search, in preference order.
      */
-    public abstract void setSearchPath(final String... groupNames);
+    public abstract void setSearchPath(String... groupNames);
 
     /**
      * Returns the path which is currently set. The array returned by this method may be
only
@@ -161,7 +176,7 @@ public abstract class Decoder extends ReferencingFactoryContainer implements
Clo
      * @param  name  the name of the attribute to search, or {@code null}.
      * @return the attribute value, or {@code null} if none or empty or if the given name
was null.
      */
-    public abstract String stringValue(final String name);
+    public abstract String stringValue(String name);
 
     /**
      * Returns the value of the attribute of the given name as a number, or {@code null}
if none.
@@ -169,7 +184,7 @@ public abstract class Decoder extends ReferencingFactoryContainer implements
Clo
      * @param  name  the name of the attribute to search, or {@code null}.
      * @return the attribute value, or {@code null} if none or unparsable or if the given
name was null.
      */
-    public abstract Number numericValue(final String name);
+    public abstract Number numericValue(String name);
 
     /**
      * Convenience method for {@link #numericValue(String)} implementation.
@@ -200,7 +215,7 @@ public abstract class Decoder extends ReferencingFactoryContainer implements
Clo
      * @param  name  the name of the attribute to search, or {@code null}.
      * @return the attribute value, or {@code null} if none or unparsable or if the given
name was null.
      */
-    public abstract Date dateValue(final String name);
+    public abstract Date dateValue(String name);
 
     /**
      * Converts the given numerical values to date, using the information provided in the
given unit symbol.
@@ -210,7 +225,7 @@ public abstract class Decoder extends ReferencingFactoryContainer implements
Clo
      * @param  values  the values to convert. May contains {@code null} elements.
      * @return the converted values. May contains {@code null} elements.
      */
-    public abstract Date[] numberToDate(final String symbol, final Number... values);
+    public abstract Date[] numberToDate(String symbol, Number... values);
 
     /**
      * Returns the value of the {@code "_Id"} global attribute. The UCAR library defines
a
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
index 720b172..0620282 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/impl/ChannelDecoder.java
@@ -650,6 +650,17 @@ public final class ChannelDecoder extends Decoder {
     }
 
     /**
+     * Returns an identification of the file format. The returned value is a reference to
a database entry
+     * known to {@link org.apache.sis.metadata.sql.MetadataSource#lookup(Class, String)}.
+     *
+     * @return an identification of the file format in an array of length 1.
+     */
+    @Override
+    public String[] getFormatDescription() {
+        return new String[] {"NetCDF"};
+    }
+
+    /**
      * Defines the groups where to search for named attributes, in preference order.
      * The {@code null} group name stands for the global attributes.
      *
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
index 4afcd83..5910b5c 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/DecoderWrapper.java
@@ -152,6 +152,25 @@ public final class DecoderWrapper extends Decoder implements CancelTask
{
     }
 
     /**
+     * Returns the file format information provided by the UCAR library.
+     *
+     * @return identification of the file format, human-readable description and version
number.
+     */
+    @Override
+    @SuppressWarnings("fallthrough")
+    public String[] getFormatDescription() {
+        final String version = file.getFileTypeVersion();
+        final String[] format = new String["N/A".equalsIgnoreCase(version) ? 2 : 3];
+        switch (format.length) {
+            default: format[2] = version;                           // Fallthrough everywhere.
+            case 2:  format[1] = file.getFileTypeDescription();
+            case 1:  format[0] = file.getFileTypeId();
+            case 0:  break;                                         // As a matter of principle.
+        }
+        return format;
+    }
+
+    /**
      * Defines the groups where to search for named attributes, in preference order.
      * The {@code null} group name stands for the global attributes.
      */
diff --git a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
index db25359..950819f 100644
--- a/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
+++ b/storage/sis-netcdf/src/main/java/org/apache/sis/storage/netcdf/MetadataReader.java
@@ -688,12 +688,22 @@ split:  while ((start = CharSequences.skipLeadingWhitespaces(value,
start, lengt
             addBoundingPolygon(new StoreFormat(decoder.geomlib, decoder.listeners).parseGeometry(wkt,
                     stringValue(GEOSPATIAL_BOUNDS + "_crs"), stringValue(GEOSPATIAL_BOUNDS
+ "_vertical_crs")));
         }
-        try {
+        final String[] format = decoder.getFormatDescription();
+        String id = format[0];
+        if (NetcdfStoreProvider.NAME.equalsIgnoreCase(id)) try {
             setFormat(NetcdfStoreProvider.NAME);
+            id = null;
         } catch (MetadataStoreException e) {
-            addFormatName(NetcdfStoreProvider.NAME);
+            // Will add 'id' at the end of this method.
             warning(e);
         }
+        if (format.length >= 2) {
+            addFormatName(format[1]);
+            if (format.length >= 3) {
+                setFormatEdition(format[2]);
+            }
+        }
+        addFormatName(id);          // Do nothing is 'id' is null.
     }
 
     /**
diff --git a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
index 26b8e8c..ae639fe 100644
--- a/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
+++ b/storage/sis-storage/src/main/java/org/apache/sis/internal/storage/MetadataBuilder.java
@@ -2844,6 +2844,7 @@ parse:      for (int i = 0; i < length;) {
      * @param value  the format name, or {@code null} for no-operation.
      *
      * @see #setFormat(String)
+     * @see #setFormatEdition(CharSequence)
      * @see #addCompression(CharSequence)
      */
     public final void addFormatName(final CharSequence value) {
@@ -2861,6 +2862,34 @@ parse:      for (int i = 0; i < length;) {
     }
 
     /**
+     * Sets a version number for the resource format. Storage location is:
+     *
+     * <ul>
+     *   <li>{@code metadata/identificationInfo/resourceFormat/formatSpecificationCitation/edition}</li>
+     * </ul>
+     *
+     * If this method is used together with {@link #setFormat(String)},
+     * then {@code setFormat} should be invoked <strong>before</strong> this
method.
+     *
+     * @param value  the format edition, or {@code null} for no-operation.
+     *
+     * @see #setFormat(String)
+     * @see #addFormatName(CharSequence)
+     */
+    public final void setFormatEdition(final CharSequence value) {
+        final InternationalString i18n = trim(value);
+        if (i18n != null) {
+            final DefaultFormat format = format();
+            DefaultCitation citation = DefaultCitation.castOrCopy(format.getFormatSpecificationCitation());
+            if (citation == null) {
+                citation = new DefaultCitation();
+                format.setFormatSpecificationCitation(citation);
+            }
+            citation.setEdition(i18n);
+        }
+    }
+
+    /**
      * Adds a compression name.
      * Storage location is:
      *


Mime
View raw message