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