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);
}
}
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);
}
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;
}
Aggregations