You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2018/05/20 20:54:31 UTC

svn commit: r1831945 - in /sis/branches/JDK8/storage/sis-netcdf/src: main/java/org/apache/sis/internal/netcdf/Variable.java main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java

Author: desruisseaux
Date: Sun May 20 20:54:31 2018
New Revision: 1831945

URL: http://svn.apache.org/viewvc?rev=1831945&view=rev
Log:
Re-enable the last ignored test in netCDF module.

Modified:
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
    sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
    sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java?rev=1831945&r1=1831944&r2=1831945&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/Variable.java [UTF-8] Sun May 20 20:54:31 2018
@@ -158,6 +158,8 @@ public abstract class Variable extends N
      * Returns the names of all attributes associated to this variable.
      *
      * @return names of all attributes associated to this variable.
+     *
+     * @todo Remove this method if it still not used.
      */
     public abstract Collection<String> getAttributeNames();
 

Modified: sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java?rev=1831945&r1=1831944&r2=1831945&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/main/java/org/apache/sis/internal/netcdf/ucar/VariableWrapper.java [UTF-8] Sun May 20 20:54:31 2018
@@ -25,6 +25,7 @@ import ucar.ma2.InvalidRangeException;
 import ucar.nc2.Attribute;
 import ucar.nc2.Dimension;
 import ucar.nc2.VariableIF;
+import ucar.nc2.dataset.VariableEnhanced;
 import org.apache.sis.math.Vector;
 import org.apache.sis.internal.netcdf.DataType;
 import org.apache.sis.internal.netcdf.Variable;
@@ -38,21 +39,37 @@ import org.apache.sis.storage.DataStoreC
  *
  * @author  Martin Desruisseaux (Geomatys)
  * @author  Johann Sorel (Geomatys)
- * @version 0.8
+ * @version 1.0
  * @since   0.3
  * @module
  */
 final class VariableWrapper extends Variable {
     /**
-     * The netCDF variable.
+     * The netCDF variable. This is typically an instance of {@link VariableEnhanced}.
      */
     private final VariableIF variable;
 
     /**
+     * The variable without enhancements. May be the same instance than {@link #variable}
+     * if that variable was not enhanced. This field is preferred to {@code variable} for
+     * fetching attribute values because the {@code "scale_factor"} and {@code "add_offset"}
+     * attributes are hidden by {@link VariableEnhanced}. In order to allow metadata reader
+     * to find them, we query attributes in the original variable instead.
+     */
+    private final VariableIF raw;
+
+    /**
      * Creates a new variable wrapping the given netCDF interface.
      */
-    VariableWrapper(final VariableIF variable) {
-        this.variable = variable;
+    VariableWrapper(VariableIF v) {
+        variable = v;
+        if (v instanceof VariableEnhanced) {
+            v = ((VariableEnhanced) v).getOriginalVariable();
+            if (v == null) {
+                v = variable;
+            }
+        }
+        raw = v;
     }
 
     /**
@@ -148,7 +165,7 @@ final class VariableWrapper extends Vari
      */
     @Override
     public Object[] getAttributeValues(final String attributeName, final boolean numeric) {
-        final Attribute attribute = variable.findAttributeIgnoreCase(attributeName);
+        final Attribute attribute = raw.findAttributeIgnoreCase(attributeName);
         if (attribute != null) {
             boolean hasValues = false;
             final Object[] values = new Object[attribute.getLength()];

Modified: sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java?rev=1831945&r1=1831944&r2=1831945&view=diff
==============================================================================
--- sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java [UTF-8] (original)
+++ sis/branches/JDK8/storage/sis-netcdf/src/test/java/org/apache/sis/storage/netcdf/MetadataReaderTest.java [UTF-8] Sun May 20 20:54:31 2018
@@ -86,7 +86,6 @@ public final strictfp class MetadataRead
      * @throws DataStoreException if a logical error occurred.
      */
     @Test
-    @org.junit.Ignore("To be modified after GeoAPI update.")
     public void testUCAR() throws IOException, DataStoreException {
         final Metadata metadata;
         try (Decoder input = createDecoder(TestData.NETCDF_2D_GEOGRAPHIC)) {