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 2021/09/19 15:32:25 UTC

[sis] 02/02: Fix the lost of `Scope` element in `DataQuality` at unmarshalling time. The problem and the fix are specific to the geoapi-3.x branches.

This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-3.1
in repository https://gitbox.apache.org/repos/asf/sis.git

commit e495c9ff26b63345b02dfe4ba7c24be23b5fb7d8
Author: Martin Desruisseaux <ma...@geomatys.com>
AuthorDate: Sun Sep 19 16:58:59 2021 +0200

    Fix the lost of `Scope` element in `DataQuality` at unmarshalling time.
    The problem and the fix are specific to the geoapi-3.x branches.
---
 .../org/apache/sis/internal/jaxb/gco/PropertyType.java   |  3 ++-
 .../org/apache/sis/internal/jaxb/metadata/MD_Scope.java  | 16 ++++++++++++++++
 .../apache/sis/metadata/iso/quality/DefaultScope.java    |  6 +++---
 .../apache/sis/metadata/iso/quality/package-info.java    |  2 +-
 .../apache/sis/metadata/iso/quality/ScopeCodeTest.java   |  1 -
 5 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/PropertyType.java b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/PropertyType.java
index 7de63d7..cc450ef 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/PropertyType.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/gco/PropertyType.java
@@ -583,7 +583,8 @@ public abstract class PropertyType<ValueType extends PropertyType<ValueType,Boun
      * @throws URISyntaxException if a URI can not be parsed.
      */
     @Override
-    public final BoundType unmarshal(final ValueType value) throws URISyntaxException {
+    // Overridden by `MD_Scope` on the geoapi-3.x branches only.
+    public BoundType unmarshal(final ValueType value) throws URISyntaxException {
         return (value != null) ? value.resolve(Context.current()) : null;
     }
 
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/MD_Scope.java b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/MD_Scope.java
index 0e8efd6..72aa3b6 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/MD_Scope.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/internal/jaxb/metadata/MD_Scope.java
@@ -16,6 +16,7 @@
  */
 package org.apache.sis.internal.jaxb.metadata;
 
+import java.net.URISyntaxException;
 import javax.xml.bind.annotation.XmlElementRef;
 import org.opengis.metadata.maintenance.Scope;
 import org.apache.sis.metadata.iso.maintenance.DefaultScope;
@@ -92,6 +93,21 @@ public class MD_Scope extends PropertyType<MD_Scope, Scope> {
     }
 
     /**
+     * On unmarshalling, creates an instance of the deprecated
+     * {@link org.apache.sis.metadata.iso.quality.DefaultScope} subclass.
+     */
+    public static final class Legacy extends MD_Scope {
+        /** Empty constructor used only by JAXB. */
+        public Legacy() {
+        }
+
+        /** Converts an adapter read from an XML stream. */
+        @Override public Scope unmarshal(final MD_Scope value) throws URISyntaxException {
+            return org.apache.sis.metadata.iso.quality.DefaultScope.castOrCopy( super.unmarshal(value));
+        }
+    }
+
+    /**
      * Wraps the value only if marshalling an element from the ISO 19115:2003 metadata model.
      * Otherwise (i.e. if marshalling according legacy ISO 19115:2014 model), omits the element.
      */
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultScope.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultScope.java
index b7fe7ab..6b48ff8 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultScope.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/DefaultScope.java
@@ -40,7 +40,7 @@ import org.apache.sis.internal.util.CollectionsExt;
  *
  * @author  Martin Desruisseaux (IRD, Geomatys)
  * @author  Touraïvane (IRD)
- * @version 1.0
+ * @version 1.1
  * @since   0.3
  * @module
  *
@@ -79,7 +79,7 @@ public class DefaultScope extends org.apache.sis.metadata.iso.maintenance.Defaul
      *
      * @see #castOrCopy(Scope)
      */
-    public DefaultScope(final Scope object) {
+    public DefaultScope(final org.opengis.metadata.maintenance.Scope object) {
         super(object);
     }
 
@@ -101,7 +101,7 @@ public class DefaultScope extends org.apache.sis.metadata.iso.maintenance.Defaul
      * @return a SIS implementation containing the values of the given object (may be the
      *         given object itself), or {@code null} if the argument was null.
      */
-    public static DefaultScope castOrCopy(final Scope object) {
+    public static DefaultScope castOrCopy(final org.opengis.metadata.maintenance.Scope object) {
         if (object == null || object instanceof DefaultScope) {
             return (DefaultScope) object;
         }
diff --git a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/package-info.java b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/package-info.java
index 8fb66e9..f68c3e3 100644
--- a/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/package-info.java
+++ b/core/sis-metadata/src/main/java/org/apache/sis/metadata/iso/quality/package-info.java
@@ -141,7 +141,7 @@
     @XmlJavaTypeAdapter(MD_ContentInformation.class),
     @XmlJavaTypeAdapter(MD_Format.class),
     @XmlJavaTypeAdapter(MD_Identifier.class),
-    @XmlJavaTypeAdapter(MD_Scope.class),
+    @XmlJavaTypeAdapter(MD_Scope.Legacy.class),
     @XmlJavaTypeAdapter(MD_SpatialRepresentation.class),
     @XmlJavaTypeAdapter(MD_SpatialRepresentationTypeCode.class),
     @XmlJavaTypeAdapter(MX_DataFile.class),
diff --git a/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/ScopeCodeTest.java b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/ScopeCodeTest.java
index 4d0f706..126617c 100644
--- a/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/ScopeCodeTest.java
+++ b/core/sis-metadata/src/test/java/org/apache/sis/metadata/iso/quality/ScopeCodeTest.java
@@ -70,7 +70,6 @@ public final strictfp class ScopeCodeTest extends TestCase {
      * @throws JAXBException if an error occurred during XML unmarshalling.
      */
     @Test
-    @org.junit.Ignore("Pass on geoapi-4.0 branch but not on geoapi-3.1 branch")
     public void testUnmarshallingLegacy() throws JAXBException {
         final DefaultDataQuality metadata = unmarshal(DefaultDataQuality.class, XML);
         final Scope scope = metadata.getScope();