Search in sources :

Example 1 with Citation

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

the class NonMarshalledAuthority method setMarshallables.

/**
 * Returns a collection containing all marshallable values of {@code newValues}, together with unmarshallable
 * values of {@code identifiers}. This method is invoked for preserving the identifiers that are conceptually
 * stored in distinct fields (XML identifier, UUID, ISBN, ISSN) when setting the collection of all identifiers
 * in a metadata object.
 *
 * <p>This method is used for implementation of {@code setIdentifiers(Collection)} methods
 * in public metadata objects.</p>
 *
 * @param  identifiers  the metadata internal identifiers collection, or {@code null} if none.
 * @param  newValues    the identifiers to add, or {@code null}.
 * @return the collection to set (may be {@code newValues}.
 *
 * @see #setMarshallable(Collection, Identifier)
 */
@SuppressWarnings("null")
public static Collection<? extends Identifier> setMarshallables(final Collection<Identifier> identifiers, final Collection<? extends Identifier> newValues) {
    int remaining;
    if (identifiers == null || (remaining = identifiers.size()) == 0) {
        return newValues;
    }
    /*
         * If there is any identifiers that need to be preserved (XML identifier, UUID, ISBN, etc.),
         * remember them. Otherwise there is nothing special to do and we can return the new values directly.
         */
    List<Identifier> toPreserve = null;
    for (final Identifier id : identifiers) {
        if (id != null && id.getAuthority() instanceof NonMarshalledAuthority<?>) {
            if (toPreserve == null) {
                toPreserve = new ArrayList<>(remaining);
            }
            toPreserve.add(id);
        }
        remaining--;
    }
    if (toPreserve == null) {
        return newValues;
    }
    /*
         * We find at least one identifier that may need to be preserved.
         * We need to create a combination of the two collections.
         */
    final Map<Citation, Identifier> authorities = new IdentityHashMap<>(4);
    final List<Identifier> merged = new ArrayList<>(newValues.size());
    for (final Identifier id : newValues) {
        merged.add(id);
        if (id != null) {
            final Citation authority = id.getAuthority();
            if (authority instanceof NonMarshalledAuthority<?>) {
                authorities.put(authority, id);
            }
        }
    }
    for (final Identifier id : toPreserve) {
        if (!authorities.containsKey(id.getAuthority())) {
            merged.add(id);
        }
    }
    /*
         * Wraps in an unmodifiable list in case the caller is creating an unmodifiable metadata.
         */
    switch(merged.size()) {
        case 0:
            return Collections.emptyList();
        case 1:
            return Collections.singletonList(merged.get(0));
        default:
            return Containers.unmodifiableList(CollectionsExt.toArray(merged, Identifier.class));
    }
}
Also used : Identifier(org.opengis.metadata.Identifier) IdentityHashMap(java.util.IdentityHashMap) ArrayList(java.util.ArrayList) UnmodifiableArrayList(org.apache.sis.internal.util.UnmodifiableArrayList) Citation(org.opengis.metadata.citation.Citation)

Example 2 with Citation

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

the class TreeNodeTest method testGetNameForMultiOccurrences.

/**
 * Tests {@link TreeNode#getName()} on a metadata with more than one entry in collections.
 * Those names <em>shall</em> contain numbering like <cite>"(1 of 2)"</cite>.
 */
@Test
@DependsOnMethod("testGetNameForSingleton")
public void testGetNameForMultiOccurrences() {
    final DefaultCitation citation = TreeNodeChildrenTest.metadataWithMultiOccurrences();
    assertColumnContentEquals(create(citation, Citation.class), TableColumn.NAME, "Citation", "Title", "Alternate title (1 of 2)", "Alternate title (2 of 2)", "Edition", "Presentation form (1 of 2)", "Presentation form (2 of 2)", "Other citation details");
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) Citation(org.opengis.metadata.citation.Citation) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 3 with Citation

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

the class DefaultMetadataTest method testMetadataStandard.

/**
 * Tests {@link DefaultMetadata#getMetadataStandardName()}, {@link DefaultMetadata#getMetadataStandardVersion()},
 * {@link DefaultMetadata#setMetadataStandardName(String)} and {@link DefaultMetadata#setMetadataStandardVersion(String)}
 * methods.
 */
@Test
@SuppressWarnings("deprecation")
public void testMetadataStandard() {
    final DefaultMetadata metadata = new DefaultMetadata();
    assertNull("metadataStandardName", metadata.getMetadataStandardName());
    assertNull("metadataStandardVersion", metadata.getMetadataStandardVersion());
    String name = "ISO 19115-2 Geographic Information - Metadata Part 2 Extensions for imagery and gridded data";
    String version = "ISO 19115-2:2009(E)";
    metadata.setMetadataStandardName(name);
    metadata.setMetadataStandardVersion(version);
    assertEquals("metadataStandardName", name, metadata.getMetadataStandardName());
    assertEquals("metadataStandardVersion", version, metadata.getMetadataStandardVersion());
    final Citation standard = getSingleton(metadata.getMetadataStandards());
    assertTitleEquals("standard", name, standard);
    assertEquals(version, standard.getEdition().toString());
}
Also used : SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Citation(org.opengis.metadata.citation.Citation) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) Test(org.junit.Test)

Example 4 with Citation

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

the class MetadataWriterTest method read.

/**
 * Reads known entries in the database.
 * Expected entry is:
 *
 * {@preformat text
 *   Citation
 *     ├─Title………………………………………………………… EPSG Geodetic Parameter Dataset
 *     ├─Identifier
 *     │   └─Code………………………………………………… EPSG
 *     ├─Cited responsible party
 *     │   ├─Party
 *     │   │   ├─Name……………………………………… International Association of Oil & Gas Producers
 *     │   │   └─Contact info
 *     │   │       └─Online resource
 *     │   │           ├─Linkage………… http://www.epsg.org
 *     │   │           └─Function……… Information
 *     │   └─Role………………………………………………… Principal investigator
 *     └─Presentation form………………………… Table digital
 * }
 *
 * @throws MetadataStoreException if an error occurred while reading the database.
 */
private void read() throws MetadataStoreException {
    final Citation c = source.lookup(Citation.class, "EPSG");
    assertEquals("EPSG Geodetic Parameter Dataset", c.getTitle().toString());
    assertEquals(PresentationForm.TABLE_DIGITAL, TestUtilities.getSingleton(c.getPresentationForms()));
    /*
         * Ask for dependencies that are known to exist.
         */
    final ResponsibleParty responsible = TestUtilities.getSingleton(c.getCitedResponsibleParties());
    assertEquals(Role.PRINCIPAL_INVESTIGATOR, responsible.getRole());
    assertEquals("International Association of Oil & Gas Producers", responsible.getOrganisationName().toString());
    OnlineResource resource = responsible.getContactInfo().getOnlineResource();
    assertEquals("http://www.epsg.org", resource.getLinkage().toString());
    assertEquals(OnLineFunction.INFORMATION, resource.getFunction());
    /*
         * Ask columns that are known to not exist.
         */
    assertNull(c.getEditionDate());
    assertTrue(c.getDates().isEmpty());
    assertEquals(0, c.getAlternateTitles().size());
    /*
         * Test the cache.
         */
    assertSame(c, source.lookup(Citation.class, "EPSG"));
    assertNotSame(c, source.lookup(Citation.class, "SIS"));
    /*
         * Should return the identifier with no search. Actually the real test is the call to "proxy",
         * since there is no way to ensure that the call to "search" tooks the short path (except by
         * looking at the debugger). But if "proxy" succeed, then "search" should be okay.
         */
    assertEquals("EPSG", source.proxy(c));
    assertEquals("EPSG", source.search(c));
}
Also used : OnlineResource(org.opengis.metadata.citation.OnlineResource) Citation(org.opengis.metadata.citation.Citation) ResponsibleParty(org.opengis.metadata.citation.ResponsibleParty)

Example 5 with Citation

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

the class FreeTextMarshallingTest method testLegacy.

/**
 * Tests parsing of a free text in the legacy (pre-Geotk 3.17) format.
 * We continue to support this format for compatibility reason, but
 * also because it is more compact and closer to what we would expect
 * inside a {@code <textGroup>} node.
 *
 * @throws JAXBException if the XML in this test can not be parsed by JAXB.
 */
@Test
public void testLegacy() throws JAXBException {
    final String legacy = "<cit:CI_Citation xmlns:lan=\"" + Namespaces.LAN + '"' + " xmlns:cit=\"" + Namespaces.CIT + '"' + " xmlns:gco=\"" + Namespaces.GCO + '"' + " xmlns:xsi=\"" + Namespaces.XSI + "\">\n" + "  <cit:title xsi:type=\"lan:PT_FreeText_PropertyType\">\n" + "    <gco:CharacterString>OpenSource Project</gco:CharacterString>\n" + "    <lan:PT_FreeText>\n" + "      <lan:textGroup>\n" + "        <lan:LocalisedCharacterString locale=\"#locale-eng\">OpenSource Project</lan:LocalisedCharacterString>\n" + "        <lan:LocalisedCharacterString locale=\"#locale-ita\">Progetto OpenSource</lan:LocalisedCharacterString>\n" + "        <lan:LocalisedCharacterString locale=\"#locale-fra\">Projet OpenSource</lan:LocalisedCharacterString>\n" + "      </lan:textGroup>\n" + "    </lan:PT_FreeText>\n" + "  </cit:title>\n" + "</cit:CI_Citation>\n";
    final Citation citation = unmarshal(Citation.class, legacy);
    assertEquals(getExpectedI18N(), citation.getTitle());
}
Also used : DefaultInternationalString(org.apache.sis.util.iso.DefaultInternationalString) Citation(org.opengis.metadata.citation.Citation) Test(org.junit.Test)

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