use of org.apache.sis.metadata.iso.ImmutableIdentifier in project sis by apache.
the class DefaultOperationMethodTest method create.
/**
* Creates a new two-dimensional operation method for an operation of the given name and identifier.
*
* @param method the operation name (example: "Mercator (variant A)").
* @param identifier the EPSG numeric identifier (example: "9804").
* @param formula formula citation (example: "EPSG guidance note #7-2").
* @param dimension the number of input and output dimension, or {@code null}.
* @param parameters the parameters (can be empty).
* @return the operation method.
*/
static DefaultOperationMethod create(final String method, final String identifier, final String formula, final Integer dimension, final ParameterDescriptor<?>... parameters) {
final Map<String, Object> properties = new HashMap<>(8);
assertNull(properties.put(OperationMethod.NAME_KEY, method));
assertNull(properties.put(ReferenceIdentifier.CODESPACE_KEY, "EPSG"));
assertNull(properties.put(Identifier.AUTHORITY_KEY, Citations.EPSG));
/*
* The parameter group for a Mercator projection is actually not empty, but it is not the purpose of
* this class to test DefaultParameterDescriptorGroup. So we use an empty group of parameters here.
*/
final ParameterDescriptorGroup pg = new DefaultParameterDescriptorGroup(properties, 1, 1, parameters);
/*
* NAME_KEY share the same Identifier instance for saving a little bit of memory.
* Then define the other properties to be given to OperationMethod.
*/
assertNotNull(properties.put(OperationMethod.NAME_KEY, pg.getName()));
assertNull(properties.put(OperationMethod.IDENTIFIERS_KEY, new ImmutableIdentifier(Citations.EPSG, "EPSG", identifier)));
assertNull(properties.put(OperationMethod.FORMULA_KEY, new DefaultCitation(formula)));
return new DefaultOperationMethod(properties, dimension, dimension, pg);
}
use of org.apache.sis.metadata.iso.ImmutableIdentifier in project sis by apache.
the class DefaultTemporalDatumTest method create.
/**
* Creates the temporal datum to use for testing purpose.
*/
private static DefaultTemporalDatum create() {
final Map<String, Object> properties = new HashMap<>(4);
assertNull(properties.put(DefaultTemporalDatum.IDENTIFIERS_KEY, new ImmutableIdentifier(HardCodedCitations.SIS, "SIS", "MJ")));
assertNull(properties.put(DefaultTemporalDatum.NAME_KEY, "Modified Julian"));
assertNull(properties.put(DefaultTemporalDatum.SCOPE_KEY, "History."));
assertNull(properties.put(DefaultTemporalDatum.REMARKS_KEY, "Time measured as days since November 17, 1858 at 00:00 UTC."));
return new DefaultTemporalDatum(properties, new Date(ORIGIN));
}
use of org.apache.sis.metadata.iso.ImmutableIdentifier 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;
}
use of org.apache.sis.metadata.iso.ImmutableIdentifier in project sis by apache.
the class InverseOperationMethod method create.
/**
* Returns or create the inverse of the given operation method. If the same operation method can be used
* for the inverse operation either with the exact same parameter values or with the sign of some values
* reversed, then the given method is returned as-is. Otherwise a synthetic method is created.
*/
static OperationMethod create(final OperationMethod method) {
if (method instanceof InverseOperationMethod) {
return ((InverseOperationMethod) method).inverse;
}
if (!isInvertible(method)) {
boolean useSameParameters = false;
for (final GeneralParameterDescriptor descriptor : method.getParameters().descriptors()) {
useSameParameters = (descriptor.getRemarks() instanceof SignReversalComment);
if (!useSameParameters)
break;
}
if (!useSameParameters) {
Identifier name = method.getName();
name = new ImmutableIdentifier(null, null, "Inverse of " + name.getCode());
final Map<String, Object> properties = new HashMap<>(6);
properties.put(NAME_KEY, name);
properties.put(FORMULA_KEY, method.getFormula());
properties.put(REMARKS_KEY, method.getRemarks());
if (method instanceof Deprecable) {
properties.put(DEPRECATED_KEY, ((Deprecable) method).isDeprecated());
}
return new InverseOperationMethod(properties, method);
}
}
return method;
}
use of org.apache.sis.metadata.iso.ImmutableIdentifier in project sis by apache.
the class AbstractIdentifiedObjectTest method testWithSingleIdentifier.
/**
* Tests the {@link AbstractIdentifiedObject#AbstractIdentifiedObject(Map)} constructor
* with only one identifier. The methods of interest for this test are:
*
* <ul>
* <li>{@link AbstractIdentifiedObject#getIdentifiers()}</li>
* <li>{@link AbstractIdentifiedObject#getIdentifier()}</li>
* <li>{@link AbstractIdentifiedObject#getID()}</li>
* </ul>
*/
@Test
@DependsOnMethod("testWithoutIdentifier")
public void testWithSingleIdentifier() {
final ReferenceIdentifier identifier = new ImmutableIdentifier(null, "EPSG", "7019");
final Set<ReferenceIdentifier> identifiers = Collections.singleton(identifier);
final AbstractIdentifiedObject object = new AbstractIdentifiedObject(properties(identifiers));
final ReferenceIdentifier gmlId = validate(object, identifiers, "epsg-7019");
assertNotNull("gmlId", gmlId);
assertEquals("gmlId.codespace", "EPSG", gmlId.getCodeSpace());
assertEquals("gmlId.code", "7019", gmlId.getCode());
}
Aggregations