Search in sources :

Example 1 with DefaultOnlineResource

use of org.apache.sis.metadata.iso.citation.DefaultOnlineResource in project sis by apache.

the class MetadataBuilder method addCompleteMetadata.

/**
 * Adds a URL to a more complete description of the metadata.
 * Storage location is:
 *
 * <ul>
 *   <li>{@code metadata/metadataLinkage/linkage}
 *     with {@code function} set to {@code OnLineFunction.COMPLETE_METADATA}</li>
 * </ul>
 *
 * @param  link  URL to a more complete description of the metadata, or {@code null}.
 */
public final void addCompleteMetadata(final URI link) {
    if (link != null) {
        final DefaultOnlineResource ln = new DefaultOnlineResource(link);
        ln.setFunction(OnLineFunction.valueOf("COMPLETE_METADATA"));
        ln.setProtocol(link.getScheme());
        addIfNotPresent(metadata().getMetadataLinkages(), ln);
    }
}
Also used : DefaultOnlineResource(org.apache.sis.metadata.iso.citation.DefaultOnlineResource)

Example 2 with DefaultOnlineResource

use of org.apache.sis.metadata.iso.citation.DefaultOnlineResource in project sis by apache.

the class DefaultMetadata method setDataSetUri.

/**
 * Sets the URI of the dataset to which the metadata applies.
 * This method sets the linkage of the first online resource in the citation of the first identification info.
 *
 * @param  newValue  the new data set URI.
 * @throws URISyntaxException if the given value can not be parsed as a URI.
 *
 * @deprecated As of ISO 19115:2014, replaced by {@link #getIdentificationInfo()}
 *    followed by {@link DefaultDataIdentification#getCitation()}
 *    followed by {@link DefaultCitation#setOnlineResources(Collection)}.
 */
@Deprecated
public void setDataSetUri(final String newValue) throws URISyntaxException {
    final URI uri = new URI(newValue);
    checkWritePermission();
    // See "Note about deprecated methods implementation"
    Collection<Identification> info = identificationInfo;
    AbstractIdentification firstId = AbstractIdentification.castOrCopy(CollectionsExt.first(info));
    if (firstId == null) {
        firstId = new DefaultDataIdentification();
    }
    DefaultCitation citation = DefaultCitation.castOrCopy(firstId.getCitation());
    if (citation == null) {
        citation = new DefaultCitation();
    }
    Collection<OnlineResource> onlineResources = citation.getOnlineResources();
    DefaultOnlineResource firstOnline = DefaultOnlineResource.castOrCopy(CollectionsExt.first(onlineResources));
    if (firstOnline == null) {
        firstOnline = new DefaultOnlineResource();
    }
    firstOnline.setLinkage(uri);
    onlineResources = OtherLocales.setFirst(onlineResources, firstOnline);
    citation.setOnlineResources(onlineResources);
    firstId.setCitation(citation);
    info = OtherLocales.setFirst(info, firstId);
    setIdentificationInfo(info);
}
Also used : OnlineResource(org.opengis.metadata.citation.OnlineResource) DefaultOnlineResource(org.apache.sis.metadata.iso.citation.DefaultOnlineResource) DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) AbstractIdentification(org.apache.sis.metadata.iso.identification.AbstractIdentification) DefaultDataIdentification(org.apache.sis.metadata.iso.identification.DefaultDataIdentification) DefaultDataIdentification(org.apache.sis.metadata.iso.identification.DefaultDataIdentification) Identification(org.opengis.metadata.identification.Identification) AbstractIdentification(org.apache.sis.metadata.iso.identification.AbstractIdentification) DefaultOnlineResource(org.apache.sis.metadata.iso.citation.DefaultOnlineResource) URI(java.net.URI)

Example 3 with DefaultOnlineResource

use of org.apache.sis.metadata.iso.citation.DefaultOnlineResource in project sis by apache.

the class EPSGDataAccess method getAuthority.

/**
 * Returns the authority for this EPSG dataset. The returned citation contains the database version
 * in the {@linkplain Citation#getEdition() edition} attribute, together with date of last update in
 * the {@linkplain Citation#getEditionDate() edition date}.
 * Example (the exact content will vary with Apache SIS versions, JDBC driver and EPSG dataset versions):
 *
 * {@preformat text
 *   Citation
 *   ├─ Title ……………………………………………………… EPSG Geodetic Parameter Dataset
 *   ├─ Identifier ………………………………………… EPSG
 *   ├─ Online resource (1 of 2)
 *   │  ├─ Linkage ………………………………………… http://epsg-registry.org/
 *   │  └─ Function ……………………………………… Browse
 *   └─ Online resource (2 of 2)
 *      ├─ Linkage ………………………………………… jdbc:derby:/my/path/to/SIS_DATA/Databases/SpatialMetadata
 *      ├─ Description ……………………………… EPSG dataset version 8.9 on “Apache Derby Embedded JDBC Driver” version 10.12.
 *      └─ Function ……………………………………… Connection
 * }
 */
@Override
public synchronized Citation getAuthority() {
    /*
         * We do not cache this citation because the caching service is already provided by ConcurrentAuthorityFactory.
         */
    final DefaultCitation c = new DefaultCitation("EPSG Geodetic Parameter Dataset");
    c.setIdentifiers(Collections.singleton(new ImmutableIdentifier(null, null, Constants.EPSG)));
    try {
        /*
             * Get the most recent version number from the history table. We get the date in local timezone
             * instead then UTC because the date is for information purpose only, and the local timezone is
             * more likely to be shown nicely (without artificial hours) to the user.
             */
        final String query = translator.apply("SELECT VERSION_NUMBER, VERSION_DATE FROM [Version History]" + " ORDER BY VERSION_DATE DESC, VERSION_HISTORY_CODE DESC");
        String version = null;
        try (Statement statement = connection.createStatement();
            ResultSet result = statement.executeQuery(query)) {
            while (result.next()) {
                version = getOptionalString(result, 1);
                // Local timezone.
                final Date date = result.getDate(2);
                if (version != null && date != null) {
                    // Paranoiac check.
                    c.setEdition(new SimpleInternationalString(version));
                    c.setEditionDate(date);
                    break;
                }
            }
        }
        /*
             * Add some hard-coded links to EPSG resources, and finally add the JDBC driver name and version number.
             * The list last OnlineResource looks like:
             *
             *    Linkage:      jdbc:derby:/my/path/to/SIS_DATA/Databases/SpatialMetadata
             *    Function:     Connection
             *    Description:  EPSG dataset version 8.9 on “Apache Derby Embedded JDBC Driver” version 10.12.
             *
             * TODO: A future version should use Citations.EPSG as a template.
             *       See the "EPSG" case in ServiceForUtility.createCitation(String).
             */
        final DatabaseMetaData metadata = connection.getMetaData();
        addURIs: for (int i = 0; ; i++) {
            String url;
            OnLineFunction function;
            InternationalString description = null;
            switch(i) {
                case 0:
                    url = "http://epsg-registry.org/";
                    function = OnLineFunction.SEARCH;
                    break;
                case 1:
                    url = "http://www.epsg.org/";
                    function = OnLineFunction.DOWNLOAD;
                    break;
                case 2:
                    {
                        url = SQLUtilities.getSimplifiedURL(metadata);
                        function = OnLineFunction.valueOf(CONNECTION);
                        description = Resources.formatInternational(Resources.Keys.GeodeticDataBase_4, Constants.EPSG, version, metadata.getDatabaseProductName(), Version.valueOf(metadata.getDatabaseMajorVersion(), metadata.getDatabaseMinorVersion()));
                        break;
                    }
                // Finished adding all URIs.
                default:
                    break addURIs;
            }
            final DefaultOnlineResource r = new DefaultOnlineResource();
            try {
                r.setLinkage(new URI(url));
            } catch (URISyntaxException exception) {
                unexpectedException("getAuthority", exception);
            }
            r.setFunction(function);
            r.setDescription(description);
            c.getOnlineResources().add(r);
        }
    } catch (SQLException exception) {
        unexpectedException("getAuthority", exception);
    } finally {
        c.freeze();
    }
    return c;
}
Also used : DefaultCitation(org.apache.sis.metadata.iso.citation.DefaultCitation) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) OnLineFunction(org.opengis.metadata.citation.OnLineFunction) URISyntaxException(java.net.URISyntaxException) DatabaseMetaData(java.sql.DatabaseMetaData) DefaultOnlineResource(org.apache.sis.metadata.iso.citation.DefaultOnlineResource) URI(java.net.URI) Date(java.util.Date) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) InternationalString(org.opengis.util.InternationalString) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) ResultSet(java.sql.ResultSet) ImmutableIdentifier(org.apache.sis.metadata.iso.ImmutableIdentifier)

Aggregations

DefaultOnlineResource (org.apache.sis.metadata.iso.citation.DefaultOnlineResource)3 URI (java.net.URI)2 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)2 URISyntaxException (java.net.URISyntaxException)1 DatabaseMetaData (java.sql.DatabaseMetaData)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Statement (java.sql.Statement)1 Date (java.util.Date)1 ImmutableIdentifier (org.apache.sis.metadata.iso.ImmutableIdentifier)1 AbstractIdentification (org.apache.sis.metadata.iso.identification.AbstractIdentification)1 DefaultDataIdentification (org.apache.sis.metadata.iso.identification.DefaultDataIdentification)1 SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)1 OnLineFunction (org.opengis.metadata.citation.OnLineFunction)1 OnlineResource (org.opengis.metadata.citation.OnlineResource)1 Identification (org.opengis.metadata.identification.Identification)1 InternationalString (org.opengis.util.InternationalString)1