use of org.opengis.metadata.Identifier in project sis by apache.
the class ModifiableIdentifierMapTest method testPutSpecialized.
/**
* Tests write operations on an {@link IdentifierMap} using specific API.
*/
@Test
public void testPutSpecialized() {
final List<Identifier> identifiers = new ArrayList<>();
final IdentifierMap map = new ModifiableIdentifierMap(identifiers);
final String myID = "myID";
final java.util.UUID myUUID = fromString("a1eb6e53-93db-4942-84a6-d9e7fb9db2c7");
final URI myURI = URI.create("http://mylink");
assertNull(map.putSpecialized(ID, myID));
assertNull(map.putSpecialized(UUID, myUUID));
assertNull(map.putSpecialized(HREF, myURI));
assertMapEquals("{gml:id=“myID”," + " gco:uuid=“a1eb6e53-93db-4942-84a6-d9e7fb9db2c7”," + " xlink:href=“http://mylink”}", map);
assertSame(myID, map.getSpecialized(ID));
assertSame(myUUID, map.getSpecialized(UUID));
assertSame(myURI, map.getSpecialized(HREF));
assertEquals("myID", map.get(ID));
assertEquals("a1eb6e53-93db-4942-84a6-d9e7fb9db2c7", map.get(UUID));
assertEquals("http://mylink", map.get(HREF));
}
use of org.opengis.metadata.Identifier in project sis by apache.
the class ConsistencyTest method lookup.
/**
* Verifies that {@code IdentifiedObjects.lookupURN(…)} on the parsed CRS can find back the original CRS.
*/
private static void lookup(final CoordinateReferenceSystem parsed, final CoordinateReferenceSystem crs) throws FactoryException {
final Identifier id = IdentifiedObjects.getIdentifier(crs, null);
/*
* Lookup operation is not going to work if the CRS are not approximatively equal.
*/
final String urn = IdentifiedObjects.toURN(crs.getClass(), id);
assertNotNull(crs.getName().getCode(), urn);
assertTrue(urn, Utilities.deepEquals(crs, parsed, ComparisonMode.DEBUG));
/*
* Now test the lookup operation. Since the parsed CRS has an identifier,
* that lookup operation should not do a lot of work actually.
*/
final String lookup = IdentifiedObjects.lookupURN(parsed, null);
assertEquals("Failed to lookup the parsed CRS.", urn, lookup);
}
use of org.opengis.metadata.Identifier in project sis by apache.
the class Citations method hasCommonIdentifier.
/**
* Determines whether a match or mismatch is found between the two given collections of identifiers.
* If any of the given collections is {@code null} or empty, then this method returns {@code null}.
*
* <p>According ISO 19162 (<cite>Well known text representation of coordinate reference systems</cite>),
* {@linkplain org.apache.sis.referencing.AbstractIdentifiedObject#getIdentifiers() identifiers} should have precedence over
* {@linkplain org.apache.sis.referencing.AbstractIdentifiedObject#getName() name} for identifying {@code IdentifiedObject}s,
* at least in the case of {@linkplain org.apache.sis.referencing.operation.DefaultOperationMethod operation methods} and
* {@linkplain org.apache.sis.parameter.AbstractParameterDescriptor parameters}.</p>
*
* @param id1 the first collection of identifiers, or {@code null}.
* @param id2 the second collection of identifiers, or {@code null}.
* @return {@code TRUE} or {@code FALSE} on match or mismatch respectively, or {@code null} if this method
* can not determine if there is a match or mismatch.
*/
public static Boolean hasCommonIdentifier(final Iterable<? extends Identifier> id1, final Iterable<? extends Identifier> id2) {
if (id1 != null && id2 != null) {
boolean hasFound = false;
for (final Identifier identifier : id1) {
final Citation authority = identifier.getAuthority();
final String codeSpace = (identifier instanceof ReferenceIdentifier) ? ((ReferenceIdentifier) identifier).getCodeSpace() : null;
for (final Identifier other : id2) {
if (authorityMatches(identifier, authority, codeSpace)) {
if (CharSequences.equalsFiltered(identifier.getCode(), other.getCode(), Characters.Filter.UNICODE_IDENTIFIER, true)) {
return Boolean.TRUE;
}
hasFound = true;
}
}
}
if (hasFound) {
return Boolean.FALSE;
}
}
return null;
}
use of org.opengis.metadata.Identifier in project sis by apache.
the class Citations method identifierMatches.
/**
* Returns {@code true} if the given citation has at least one identifier equals to the given string,
* ignoring case and non-alphanumeric characters. If and <em>only</em> if the citation does not contain
* any identifier, then this method fallback on titles comparison.
* See {@link org.apache.sis.metadata.iso.citation.Citations#identifierMatches(Citation, String)}
* for the public documentation of this method.
*
* @param citation the citation to check for, or {@code null}.
* @param identifier the identifier to compare, or {@code null} if unknown.
* @param code value of {@code identifier.getCode()}, or {@code null}.
* @return {@code true} if both arguments are non-null, and an identifier matches the given string.
*/
public static boolean identifierMatches(final Citation citation, final Identifier identifier, final CharSequence code) {
if (citation != null && code != null) {
final Collection<? extends Identifier> citIds = citation.getIdentifiers();
Iterator<? extends Identifier> it = iterator(citIds);
if (it == null) {
return titleMatches(citation, code);
}
while (it.hasNext()) {
final Identifier citId = it.next();
if (citId != null && equalsFiltered(code, citId.getCode())) {
/*
* Found a possible match. We will take the code space in account only if it is defined
* by both identifiers. If a code space is undefined, we consider that we have a match.
*/
if (identifier instanceof ReferenceIdentifier) {
final String codeSpace = ((ReferenceIdentifier) identifier).getCodeSpace();
if (codeSpace != null && citId instanceof ReferenceIdentifier) {
final String cs = ((ReferenceIdentifier) citId).getCodeSpace();
if (cs != null && !equalsFiltered(codeSpace, cs)) {
// Check other identifiers.
continue;
}
}
}
return true;
}
}
/*
* Before to give up, maybe the given code argument is actually written using a "codeSpace:code" syntax.
* Try to parse that syntax only if no Identifier argument were specified (otherwise we require the code
* and code space to be splitted as defined in the identifier).
*/
if (identifier == null) {
int s = 0;
final int length = code.length();
while ((s = CharSequences.indexOf(code, DEFAULT_SEPARATOR, s, length)) >= 0) {
final CharSequence codeSpace = code.subSequence(0, s);
final CharSequence localPart = code.subSequence(++s, length);
for (it = citIds.iterator(); it.hasNext(); ) {
final Identifier id = it.next();
if (id instanceof ReferenceIdentifier && equalsFiltered(codeSpace, ((ReferenceIdentifier) id).getCodeSpace()) && equalsFiltered(localPart, id.getCode())) {
return true;
}
}
}
}
}
return false;
}
use of org.opengis.metadata.Identifier in project sis by apache.
the class MetadataBuilder method addPlatform.
/**
* Adds a platform on which instrument are installed. If a platform was already defined
* with a different identifier, then a new platform instance will be created.
* Storage location is:
*
* <ul>
* <li>{@code metadata/acquisitionInformation/platform/identifier}</li>
* </ul>
*
* @param authority identifiers the authority that define platform codes, or {@code null} if none.
* @param identifier identifier of the platform to add, or {@code null} for no-operation.
*/
public final void addPlatform(final CharSequence authority, String identifier) {
if (identifier != null && !(identifier = identifier.trim()).isEmpty()) {
if (platform != null) {
final Identifier current = platform.getIdentifier();
if (current != null) {
if (identifier.equals(current.getCode())) {
return;
}
acquisition().getPlatforms().add(platform);
platform = null;
}
}
platform().setIdentifier(sharedIdentifier(authority, identifier));
}
}
Aggregations