Search in sources :

Example 16 with Citation

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

the class MetadataBuilderTest method verifyCopyrightParsing.

/**
 * Verifies the metadata that contains the result of parsing a copyright statement.
 * Should contains the "John Smith" name and 1992 year.
 *
 * @param notice  the copyright statement to parse.
 */
private static void verifyCopyrightParsing(final String notice) {
    final MetadataBuilder builder = new MetadataBuilder();
    builder.parseLegalNotice(notice);
    final DefaultLegalConstraints constraints = (DefaultLegalConstraints) getSingleton(getSingleton(builder.build(false).getIdentificationInfo()).getResourceConstraints());
    assertEquals("useConstraints", Restriction.COPYRIGHT, getSingleton(constraints.getUseConstraints()));
    final Citation ref = getSingleton(constraints.getReferences());
    assertTitleEquals("reference.title", notice, ref);
    assertPartyNameEquals("reference.citedResponsibleParty", "John Smith", (DefaultCitation) ref);
    assertEquals("date", date("1992-01-01 00:00:00"), getSingleton(ref.getDates()).getDate());
}
Also used : DefaultLegalConstraints(org.apache.sis.metadata.iso.constraint.DefaultLegalConstraints) Citation(org.opengis.metadata.citation.Citation) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation)

Example 17 with Citation

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

the class DefaultMetadata method getDataSetUri.

/**
 * Provides the URI of the dataset to which the metadata applies.
 *
 * @return Uniform Resource Identifier of the dataset, or {@code null}.
 *
 * @deprecated As of ISO 19115:2014, replaced by {@link #getIdentificationInfo()} followed by
 *    {@link DefaultDataIdentification#getCitation()} followed by {@link DefaultCitation#getOnlineResources()}.
 */
@Override
@Deprecated
@Dependencies("getIdentificationInfo")
@XmlElement(name = "dataSetURI", namespace = LegacyNamespaces.GMD)
public String getDataSetUri() {
    String linkage = null;
    final Collection<Identification> info;
    if (FilterByVersion.LEGACY_METADATA.accept() && (info = getIdentificationInfo()) != null) {
        for (final Identification identification : info) {
            final Citation citation = identification.getCitation();
            if (citation instanceof DefaultCitation) {
                final Collection<? extends OnlineResource> onlineResources = ((DefaultCitation) citation).getOnlineResources();
                if (onlineResources != null) {
                    for (final OnlineResource link : onlineResources) {
                        final URI uri = link.getLinkage();
                        if (uri != null) {
                            if (linkage == null) {
                                linkage = uri.toString();
                            } else {
                                LegacyPropertyAdapter.warnIgnoredExtraneous(OnlineResource.class, DefaultMetadata.class, "getDataSetUri");
                                break;
                            }
                        }
                    }
                }
            }
        }
    }
    return linkage;
}
Also used : OnlineResource(org.opengis.metadata.citation.OnlineResource) DefaultOnlineResource(org.apache.sis.metadata.iso.citation.DefaultOnlineResource) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) DefaultDataIdentification(org.apache.sis.metadata.iso.identification.DefaultDataIdentification) Identification(org.opengis.metadata.identification.Identification) AbstractIdentification(org.apache.sis.metadata.iso.identification.AbstractIdentification) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Citation(org.opengis.metadata.citation.Citation) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) CI_Citation(org.apache.sis.internal.jaxb.metadata.CI_Citation) URI(java.net.URI) XmlElement(javax.xml.bind.annotation.XmlElement) Dependencies(org.apache.sis.internal.metadata.Dependencies)

Example 18 with Citation

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

the class ImmutableIdentifier method formatTo.

/**
 * Formats this identifier as a <cite>Well Known Text</cite> {@code Id[…]} element.
 * See class javadoc for more information on the WKT format.
 *
 * @param  formatter  the formatter where to format the inner content of this WKT element.
 * @return {@code "Id"} (WKT 2) or {@code "Authority"} (WKT 1).
 *
 * @see <a href="http://docs.opengeospatial.org/is/12-063r5/12-063r5.html#33">WKT 2 specification §7.3.4</a>
 */
@Override
protected String formatTo(final Formatter formatter) {
    String keyword = null;
    /*
         * The code, codeSpace, authority and version local variables in this method usually have the exact same
         * value than the fields of the same name in this class.  But we get those values by invoking the public
         * methods in order to give to users a chance to override those properties.  The intent is also to use a
         * consistent approach for all 'formatTo' implementations, since some other classes have no choice other
         * than using the public methods.
         */
    final String code = getCode();
    if (code != null) {
        final String codeSpace = getCodeSpace();
        final Citation authority = getAuthority();
        final String cs = (codeSpace != null) ? codeSpace : org.apache.sis.internal.util.Citations.getIdentifier(authority, true);
        if (cs != null) {
            final Convention convention = formatter.getConvention();
            if (convention.majorVersion() == 1) {
                keyword = WKTKeywords.Authority;
                formatter.append(cs, ElementKind.IDENTIFIER);
                formatter.append(code, ElementKind.IDENTIFIER);
            } else {
                keyword = WKTKeywords.Id;
                formatter.append(cs, ElementKind.IDENTIFIER);
                appendCode(formatter, code);
                final String version = getVersion();
                if (version != null) {
                    appendCode(formatter, version);
                }
                /*
                     * In order to simplify the WKT, format the citation only if it is different than the code space.
                     * We will also omit the citation if this identifier is for a parameter value, because parameter
                     * values are handled in a special way by the international standard:
                     *
                     *   - ISO 19162 explicitely said that we shall format the identifier for the root element only,
                     *     and omit the identifier for all inner elements EXCEPT parameter values and operation method.
                     *   - Exclusion of identifier for inner elements is performed by the Formatter class, so it does
                     *     not need to be checked here.
                     *   - Parameter values are numerous, while operation methods typically appear only once in a WKT
                     *     document. So we will simplify the parameter values only (not the operation methods) except
                     *     if the parameter value is the root element (in which case we will format full identifier).
                     */
                final FormattableObject enclosing = formatter.getEnclosingElement(1);
                final boolean isRoot = formatter.getEnclosingElement(2) == null;
                if (isRoot || !(enclosing instanceof ParameterValue<?>)) {
                    final String citation = org.apache.sis.internal.util.Citations.getIdentifier(authority, false);
                    if (citation != null && !citation.equals(cs)) {
                        formatter.append(new Cite(citation));
                    }
                }
                /*
                     * Do not format the optional URI element for internal convention,
                     * because this property is currently computed rather than stored.
                     * Other conventions format only for the ID[…] of root element.
                     */
                if (isRoot && enclosing != null && convention != Convention.INTERNAL) {
                    final String urn = NameMeaning.toURN(enclosing.getClass(), cs, version, code);
                    if (urn != null) {
                        formatter.append(new FormattableObject() {

                            @Override
                            protected String formatTo(final Formatter formatter) {
                                formatter.append(urn, null);
                                return WKTKeywords.URI;
                            }
                        });
                    }
                }
            }
        }
    }
    return keyword;
}
Also used : Convention(org.apache.sis.io.wkt.Convention) Formatter(org.apache.sis.io.wkt.Formatter) InternationalString(org.opengis.util.InternationalString) Citation(org.opengis.metadata.citation.Citation) FormattableObject(org.apache.sis.io.wkt.FormattableObject)

Example 19 with Citation

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

the class CitationConstant method delegate.

/**
 * Returns the citation instance which contain the actual data. That instance is provided by the
 * {@code sis-metadata} module, which is optional.  If that module is not on the classpath, then
 * this {@code delegate()} method will use the few information provided by the current instance.
 *
 * <p>Note that it should be very rare to not have {@code sis-metadata} on the classpath,
 * since that module is required by {@code sis-referencing} which is itself required by
 * almost all other SIS modules.</p>
 */
@SuppressWarnings("DoubleCheckedLocking")
private Citation delegate() {
    Citation c = delegate;
    if (c == null) {
        synchronized (this) {
            c = delegate;
            if (c == null) {
                c = ServicesForUtility.createCitation(title);
                if (c == null) {
                    /*
                         * 'sis-metadata' module not on the classpath (should be very rare)
                         * or no citation defined for the given primary key.
                         */
                    c = new SimpleCitation(title);
                }
                delegate = c;
            }
        }
    }
    return c;
}
Also used : Citation(org.opengis.metadata.citation.Citation)

Example 20 with Citation

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

the class EPSGDataAccess method createProperties.

/**
 * Returns the name and aliases for the {@link IdentifiedObject} to construct.
 *
 * @param  table       the table on which a query has been executed.
 * @param  name        the name for the {@link IdentifiedObject} to construct.
 * @param  code        the EPSG code of the object to construct.
 * @param  remarks     remarks as a {@link String} or {@link InternationalString}, or {@code null} if none.
 * @param  deprecated  {@code true} if the object to create is deprecated.
 * @return the name together with a set of properties.
 */
@SuppressWarnings("ReturnOfCollectionOrArrayField")
private Map<String, Object> createProperties(final String table, String name, final Integer code, CharSequence remarks, final boolean deprecated) throws SQLException, FactoryDataException {
    /*
         * Search for aliases. Note that searching for the object code is not sufficient. We also need to check if the
         * record is really from the table we are looking for since different tables may have objects with the same ID.
         *
         * Some aliases are identical to the name except that some letters are replaced by their accented letters.
         * For example "Reseau Geodesique Francais" → "Réseau Géodésique Français". If we find such alias, replace
         * the name by the alias so we have proper display in user interface. Notes:
         *
         *   - WKT formatting will still be compliant with ISO 19162 because the WKT formatter replaces accented
         *     letters by ASCII ones.
         *   - We do not perform this replacement directly in our EPSG database because ASCII letters are more
         *     convenient for implementing accent-insensitive searches.
         */
    final List<GenericName> aliases = new ArrayList<>();
    try (ResultSet result = executeQuery("Alias", "SELECT OBJECT_TABLE_NAME, NAMING_SYSTEM_NAME, ALIAS" + " FROM [Alias] INNER JOIN [Naming System]" + " ON [Alias].NAMING_SYSTEM_CODE =" + " [Naming System].NAMING_SYSTEM_CODE" + " WHERE OBJECT_CODE = ?", code)) {
        while (result.next()) {
            if (tableMatches(table, result.getString(1))) {
                final String naming = getOptionalString(result, 2);
                final String alias = getString(code, result, 3);
                NameSpace ns = null;
                if (naming != null) {
                    ns = namingSystems.get(naming);
                    if (ns == null) {
                        ns = owner.nameFactory.createNameSpace(owner.nameFactory.createLocalName(null, naming), null);
                        namingSystems.put(naming, ns);
                    }
                }
                if (CharSequences.toASCII(alias).toString().equals(name)) {
                    name = alias;
                } else {
                    aliases.add(owner.nameFactory.createLocalName(ns, alias));
                }
            }
        }
    }
    /*
         * At this point we can fill the properties map.
         */
    properties.clear();
    GenericName gn = null;
    final Locale locale = getLocale();
    final Citation authority = owner.getAuthority();
    final InternationalString edition = authority.getEdition();
    final String version = (edition != null) ? edition.toString() : null;
    if (name != null) {
        gn = owner.nameFactory.createGenericName(namespace, Constants.EPSG, name);
        properties.put("name", gn);
        properties.put(NamedIdentifier.CODE_KEY, name);
        properties.put(NamedIdentifier.VERSION_KEY, version);
        properties.put(NamedIdentifier.AUTHORITY_KEY, authority);
        properties.put(AbstractIdentifiedObject.LOCALE_KEY, locale);
        final NamedIdentifier id = new NamedIdentifier(properties);
        properties.clear();
        properties.put(IdentifiedObject.NAME_KEY, id);
    }
    if (!aliases.isEmpty()) {
        properties.put(IdentifiedObject.ALIAS_KEY, aliases.toArray(new GenericName[aliases.size()]));
    }
    if (code != null) {
        final String codeString = code.toString();
        final ImmutableIdentifier identifier;
        if (deprecated) {
            final String replacedBy = getSupersession(table, code, locale);
            identifier = new DeprecatedCode(authority, Constants.EPSG, codeString, version, Character.isDigit(replacedBy.charAt(0)) ? replacedBy : null, Vocabulary.formatInternational(Vocabulary.Keys.SupersededBy_1, replacedBy));
            properties.put(AbstractIdentifiedObject.DEPRECATED_KEY, Boolean.TRUE);
        } else {
            identifier = new ImmutableIdentifier(authority, Constants.EPSG, codeString, version, (gn != null) ? gn.toInternationalString() : null);
        }
        properties.put(IdentifiedObject.IDENTIFIERS_KEY, identifier);
    }
    properties.put(IdentifiedObject.REMARKS_KEY, remarks);
    properties.put(AbstractIdentifiedObject.LOCALE_KEY, locale);
    properties.put(ReferencingServices.MT_FACTORY, owner.mtFactory);
    return properties;
}
Also used : Locale(java.util.Locale) GenericName(org.opengis.util.GenericName) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) NamedIdentifier(org.apache.sis.referencing.NamedIdentifier) ArrayList(java.util.ArrayList) ResultSet(java.sql.ResultSet) NameSpace(org.opengis.util.NameSpace) DefaultNameSpace(org.apache.sis.util.iso.DefaultNameSpace) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Citation(org.opengis.metadata.citation.Citation) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) DeprecatedCode(org.apache.sis.internal.referencing.DeprecatedCode) ImmutableIdentifier(org.apache.sis.metadata.iso.ImmutableIdentifier)

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