Search in sources :

Example 11 with Citation

use of org.opengis.metadata.citation.Citation in project sis by apache.

the class NilReasonTest method testCreateNilObject.

/**
 * Tests the creation of {@link NilObject} instances.
 */
@Test
public void testCreateNilObject() {
    final Citation citation = NilReason.TEMPLATE.createNilObject(Citation.class);
    assertInstanceOf("Unexpected proxy.", NilObject.class, citation);
    assertNull(citation.getTitle());
    assertTrue(citation.getDates().isEmpty());
    assertEquals("NilObject.toString()", "Citation[template]", citation.toString());
    assertSame("NilReason.forObject(…)", NilReason.TEMPLATE, NilReason.forObject(citation));
    assertSame("Expected cached value.", citation, NilReason.TEMPLATE.createNilObject(Citation.class));
}
Also used : Citation(org.opengis.metadata.citation.Citation) Test(org.junit.Test)

Example 12 with Citation

use of org.opengis.metadata.citation.Citation in project sis by apache.

the class NilReasonTest method testNilObjectComparison.

/**
 * Tests the comparison of {@link NilObject} instances.
 */
@Test
public void testNilObjectComparison() {
    final Citation e1 = NilReason.TEMPLATE.createNilObject(Citation.class);
    final Citation e2 = NilReason.MISSING.createNilObject(Citation.class);
    final Citation e3 = NilReason.TEMPLATE.createNilObject(Citation.class);
    assertEquals("NilObject.hashCode()", e1.hashCode(), e3.hashCode());
    assertFalse("NilObject.hashCode()", e1.hashCode() == e2.hashCode());
    assertEquals("NilObject.equals(Object)", e1, e3);
    assertFalse("NilObject.equals(Object)", e1.equals(e2));
    assertInstanceOf("e1", LenientComparable.class, e1);
    final LenientComparable c = (LenientComparable) e1;
    assertTrue(c.equals(e3, ComparisonMode.STRICT));
    assertFalse(c.equals(e2, ComparisonMode.STRICT));
    assertFalse(c.equals(e2, ComparisonMode.BY_CONTRACT));
    assertTrue(c.equals(e2, ComparisonMode.IGNORE_METADATA));
    assertTrue(c.equals(e2, ComparisonMode.APPROXIMATIVE));
    assertTrue(c.equals(e2, ComparisonMode.DEBUG));
    // Following object should alway be different because it does not implement the same interface.
    final ResponsibleParty r1 = NilReason.TEMPLATE.createNilObject(ResponsibleParty.class);
    assertFalse(c.equals(r1, ComparisonMode.STRICT));
    assertFalse(c.equals(r1, ComparisonMode.BY_CONTRACT));
    assertFalse(c.equals(r1, ComparisonMode.IGNORE_METADATA));
    assertFalse(c.equals(r1, ComparisonMode.APPROXIMATIVE));
    assertFalse(c.equals(r1, ComparisonMode.DEBUG));
}
Also used : Citation(org.opengis.metadata.citation.Citation) LenientComparable(org.apache.sis.util.LenientComparable) ResponsibleParty(org.opengis.metadata.citation.ResponsibleParty) Test(org.junit.Test)

Example 13 with Citation

use of org.opengis.metadata.citation.Citation in project sis by apache.

the class UUIDMarshallingTest method testReferenceInEmptyObject.

/**
 * The same test than {@link #testReference()}, except that the {@code <gmd:CI_Series>} element is empty.
 * This situation shall force the creation of a new, empty, element for storing the {@code uuidref} information.
 *
 * @throws JAXBException if an error occurred during (un)marshalling.
 */
@Test
@DependsOnMethod("testReference")
public void testReferenceInEmptyObject() throws JAXBException {
    final Citation citation = (Citation) XML.unmarshal(REFERENCED_XML);
    assertTitleEquals("Citation.title", "My data", citation);
    /*
         * Programmatic verification of the Series properties,
         * which is the main object of interest in this test.
         */
    final Series series = citation.getSeries();
    assertInstanceOf("Citation.series", IdentifiedObject.class, series);
    assertNull("Citation.series.name", series.getName());
    assertTrue("Citation.series.isProxy", Proxy.isProxyClass(series.getClass()));
    assertInstanceOf("Citation.series", NilObject.class, series);
    assertEquals("Series[{gco:uuid=“" + UUID_VALUE + "”}]", series.toString());
    final IdentifierMap map = ((IdentifiedObject) series).getIdentifierMap();
    assertNull("href", map.get(IdentifierSpace.HREF));
    assertEquals("uuid", UUID_VALUE, map.get(IdentifierSpace.UUID));
    /*
         * Marshal the object back to XML and compare with the expected result.
         */
    final String actual = XML.marshal(citation);
    assertXmlEquals(REFERENCED_XML, actual, "xmlns:*");
    assertEquals(citation, XML.unmarshal(actual));
}
Also used : Series(org.opengis.metadata.citation.Series) Citation(org.opengis.metadata.citation.Citation) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 14 with Citation

use of org.opengis.metadata.citation.Citation in project sis by apache.

the class UUIDMarshallingTest method testIdentification.

/**
 * Tests (un)marshalling of an object identified by the {@code uuid} attribute.
 * The element of interest for this test is the {@code "uuid"} attribute value
 * in the {@code <gmd:CI_Series>} element of the following XML fragment:
 *
 * {@preformat xml
 *   <cit:CI_Citation>
 *     <cit:title>
 *       <gco:CharacterString>My data</gco:CharacterString>
 *     </cit:title>
 *     <cit:series>
 *       <cit:CI_Series uuid="f8f5fcb1-d57b-4013-b3a4-4eaa40df6dcf">
 *         <cit:name>
 *           <gco:CharacterString>My aggregate dataset</gco:CharacterString>
 *         </cit:name>
 *       </cit:CI_Series>
 *     </cit:series>
 *   </cit:CI_Citation>
 * }
 *
 * On an implementation note, the {@code uuid} and other attributes of the {@code <gmd:CI_Series>}
 * elements are handled by {@link org.apache.sis.internal.jaxb.gco.PropertyType}.
 *
 * @throws JAXBException if an error occurred during (un)marshalling.
 */
@Test
public void testIdentification() throws JAXBException {
    final Citation citation = (Citation) XML.unmarshal(IDENTIFIED_XML);
    assertTitleEquals("Citation", "My data", citation);
    /*
         * Programmatic verification of the Series properties,
         * which is the main object of interest in this test.
         */
    final Series series = citation.getSeries();
    assertFalse("Unexpected proxy", Proxy.isProxyClass(series.getClass()));
    assertInstanceOf("Expected IdentifiedObject", IdentifiedObject.class, series);
    final IdentifierMap map = ((IdentifiedObject) series).getIdentifierMap();
    assertEquals("series", "My aggregate dataset", series.getName().toString());
    assertNull("href", map.get(IdentifierSpace.HREF));
    assertEquals(UUID_VALUE, String.valueOf(map.get(IdentifierSpace.UUID)));
    /*
         * Marshal the object back to XML and compare with the original string
         * supplied to this method.
         */
    final String actual = XML.marshal(citation);
    assertXmlEquals(IDENTIFIED_XML, actual, "xmlns:*");
    assertEquals(citation, XML.unmarshal(actual));
}
Also used : Series(org.opengis.metadata.citation.Series) Citation(org.opengis.metadata.citation.Citation) Test(org.junit.Test)

Example 15 with Citation

use of org.opengis.metadata.citation.Citation in project sis by apache.

the class Citations method hasCommonIdentifier.

/**
 * Determines whether a match or mismatch is found between the two given collections of identifiers.
 * If any of the given collections is {@code null} or empty, then this method returns {@code null}.
 *
 * <p>According ISO 19162 (<cite>Well known text representation of coordinate reference systems</cite>),
 * {@linkplain org.apache.sis.referencing.AbstractIdentifiedObject#getIdentifiers() identifiers} should have precedence over
 * {@linkplain org.apache.sis.referencing.AbstractIdentifiedObject#getName() name} for identifying {@code IdentifiedObject}s,
 * at least in the case of {@linkplain org.apache.sis.referencing.operation.DefaultOperationMethod operation methods} and
 * {@linkplain org.apache.sis.parameter.AbstractParameterDescriptor parameters}.</p>
 *
 * @param  id1  the first collection of identifiers, or {@code null}.
 * @param  id2  the second collection of identifiers, or {@code null}.
 * @return {@code TRUE} or {@code FALSE} on match or mismatch respectively, or {@code null} if this method
 *         can not determine if there is a match or mismatch.
 */
public static Boolean hasCommonIdentifier(final Iterable<? extends Identifier> id1, final Iterable<? extends Identifier> id2) {
    if (id1 != null && id2 != null) {
        boolean hasFound = false;
        for (final Identifier identifier : id1) {
            final Citation authority = identifier.getAuthority();
            final String codeSpace = (identifier instanceof ReferenceIdentifier) ? ((ReferenceIdentifier) identifier).getCodeSpace() : null;
            for (final Identifier other : id2) {
                if (authorityMatches(identifier, authority, codeSpace)) {
                    if (CharSequences.equalsFiltered(identifier.getCode(), other.getCode(), Characters.Filter.UNICODE_IDENTIFIER, true)) {
                        return Boolean.TRUE;
                    }
                    hasFound = true;
                }
            }
        }
        if (hasFound) {
            return Boolean.FALSE;
        }
    }
    return null;
}
Also used : Identifier(org.opengis.metadata.Identifier) ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) Citation(org.opengis.metadata.citation.Citation) InternationalString(org.opengis.util.InternationalString)

Aggregations

Citation (org.opengis.metadata.citation.Citation)43 Test (org.junit.Test)17 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)12 InternationalString (org.opengis.util.InternationalString)11 Identifier (org.opengis.metadata.Identifier)10 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)7 Series (org.opengis.metadata.citation.Series)6 DependsOnMethod (org.apache.sis.test.DependsOnMethod)5 ArrayList (java.util.ArrayList)4 NamedIdentifier (org.apache.sis.referencing.NamedIdentifier)4 ReferenceIdentifier (org.opengis.referencing.ReferenceIdentifier)4 ResponsibleParty (org.opengis.metadata.citation.ResponsibleParty)3 CI_Citation (org.apache.sis.internal.jaxb.metadata.CI_Citation)2 FormattableObject (org.apache.sis.io.wkt.FormattableObject)2 ImmutableIdentifier (org.apache.sis.metadata.iso.ImmutableIdentifier)2 DefaultInternationalString (org.apache.sis.util.iso.DefaultInternationalString)2 OnlineResource (org.opengis.metadata.citation.OnlineResource)2 NoSuchAuthorityCodeException (org.opengis.referencing.NoSuchAuthorityCodeException)2 VendorOptionVersion (com.sldeditor.common.vendoroption.VendorOptionVersion)1 ValueComboBoxData (com.sldeditor.ui.widgets.ValueComboBoxData)1