Search in sources :

Example 1 with DeprecatedCode

use of org.apache.sis.internal.referencing.DeprecatedCode 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

ResultSet (java.sql.ResultSet)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 DeprecatedCode (org.apache.sis.internal.referencing.DeprecatedCode)1 ImmutableIdentifier (org.apache.sis.metadata.iso.ImmutableIdentifier)1 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)1 NamedIdentifier (org.apache.sis.referencing.NamedIdentifier)1 DefaultNameSpace (org.apache.sis.util.iso.DefaultNameSpace)1 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)1 Citation (org.opengis.metadata.citation.Citation)1 GenericName (org.opengis.util.GenericName)1 InternationalString (org.opengis.util.InternationalString)1 NameSpace (org.opengis.util.NameSpace)1