Search in sources :

Example 26 with Identifier

use of org.opengis.metadata.Identifier in project sis by apache.

the class PropertyAccessorTest method getSingletonCode.

/**
 * Returns the code of the singleton identifier found in the given collection.
 * This method verifies that the object is of the expected type.
 *
 * @param  identifiers  a singleton {@code Collection<Identifier>}.
 * @return {@link Identifier#getCode()}.
 */
static String getSingletonCode(final Object identifiers) {
    assertInstanceOf("identifiers", Collection.class, identifiers);
    final Object identifier = getSingleton((Collection<?>) identifiers);
    assertInstanceOf("identifier", Identifier.class, identifier);
    return ((Identifier) identifier).getCode();
}
Also used : ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) Identifier(org.opengis.metadata.Identifier) IdentifiedObject(org.opengis.referencing.IdentifiedObject)

Example 27 with Identifier

use of org.opengis.metadata.Identifier in project sis by apache.

the class ModifiableIdentifierMapTest method testHRefSubstitution.

/**
 * Tests explicitely the special handling of {@code href} values.
 */
@Test
public void testHRefSubstitution() {
    final List<Identifier> identifiers = new ArrayList<>();
    final IdentifierMap map = new ModifiableIdentifierMap(identifiers);
    assertNull(map.put(HREF, "myHREF"));
    assertEquals("Shall contain the entry we added.", "myHREF", map.get(HREF));
    // Check the XLink object
    final XLink link = map.getSpecialized(XLINK);
    assertEquals("Added href shall be stored as XLink attribute.", "myHREF", String.valueOf(link.getHRef()));
    assertEquals("Identifier list shall contain the XLink.", link.toString(), getSingleton(identifiers).getCode());
    // Modidfy the XLink object directly
    link.setHRef(URI.create("myNewHREF"));
    assertEquals("Change in XLink shall be reflected in href.", "myNewHREF", map.get(HREF));
}
Also used : Identifier(org.opengis.metadata.Identifier) IdentifierMap(org.apache.sis.xml.IdentifierMap) ArrayList(java.util.ArrayList) XLink(org.apache.sis.xml.XLink) Test(org.junit.Test)

Example 28 with Identifier

use of org.opengis.metadata.Identifier in project sis by apache.

the class ModifiableIdentifierMapTest method testUUIDs.

/**
 * Tests with UUIDs.
 */
@Test
public void testUUIDs() {
    final List<Identifier> identifiers = new ArrayList<>();
    final IdentifierMap map = new ModifiableIdentifierMap(identifiers);
    final java.util.UUID id1 = fromString("434f3107-c6d2-4c8c-bb25-553f68641c5c");
    final java.util.UUID id2 = fromString("42924124-032a-4dfe-b06e-113e3cb81cf0");
    // Add first UUID.
    assertNull(map.putSpecialized(UUID, id1));
    // Replace UUID by a new one.
    assertSame(id1, map.putSpecialized(UUID, id2));
}
Also used : Identifier(org.opengis.metadata.Identifier) IdentifierMap(org.apache.sis.xml.IdentifierMap) ArrayList(java.util.ArrayList) UUID(java.util.UUID) Test(org.junit.Test)

Example 29 with Identifier

use of org.opengis.metadata.Identifier in project sis by apache.

the class ModifiableIdentifierMapTest method testDuplicatedAuthorities.

/**
 * Tests the handling of duplicated authorities.
 */
@Test
public void testDuplicatedAuthorities() {
    final List<Identifier> identifiers = new ArrayList<>();
    assertTrue(identifiers.add(new IdentifierMapEntry(ID, "myID1")));
    assertTrue(identifiers.add(new IdentifierMapEntry(UUID, "myUUID")));
    assertTrue(identifiers.add(new IdentifierMapEntry(ID, "myID2")));
    final IdentifierMap map = new ModifiableIdentifierMap(identifiers);
    assertEquals("Duplicated authorities shall be filtered.", 2, map.size());
    assertEquals("Duplicated authorities shall still exist.", 3, identifiers.size());
    assertEquals("myID1", map.get(ID));
    assertEquals("myUUID", map.get(UUID));
    final Iterator<Citation> it = map.keySet().iterator();
    assertTrue(it.hasNext());
    assertSame(ID, it.next());
    it.remove();
    assertTrue(it.hasNext());
    assertSame(UUID, it.next());
    assertFalse("Duplicated authority shall have been removed.", it.hasNext());
    assertEquals(1, identifiers.size());
    assertEquals(1, map.size());
}
Also used : Identifier(org.opengis.metadata.Identifier) IdentifierMap(org.apache.sis.xml.IdentifierMap) ArrayList(java.util.ArrayList) Citation(org.opengis.metadata.citation.Citation) Test(org.junit.Test)

Example 30 with Identifier

use of org.opengis.metadata.Identifier in project sis by apache.

the class DefaultCitationTest method testIdentifierMap.

/**
 * Tests the identifier map, which handles ISBN and ISSN codes in a special way.
 */
@Test
public void testIdentifierMap() {
    final DefaultCitation citation = new DefaultCitation();
    final Collection<Identifier> identifiers = citation.getIdentifiers();
    final IdentifierMap identifierMap = citation.getIdentifierMap();
    assertTrue("Expected an initially empty set of identifiers.", identifiers.isEmpty());
    /*
         * Set the ISBN code, and ensure that the the ISBN is reflected in the identifier map.
         */
    citation.setISBN("MyISBN");
    assertEquals("MyISBN", citation.getISBN());
    assertEquals("ISBN code shall be included in the set of identifiers.", 1, identifiers.size());
    assertEquals("{ISBN=“MyISBN”}", identifierMap.toString());
    /*
         * Set the identifiers with a list containing ISBN and ISSN codes.
         * The ISBN code shall be ignored because and ISBN property was already set.
         * The ISSN code shall be retained because it is a new code.
         */
    assertNull("ISSN shall be initially null.", citation.getISSN());
    citation.setIdentifiers(Arrays.asList(new DefaultIdentifier(Citations.NETCDF, "MyNetCDF"), new DefaultIdentifier(Citations.EPSG, "MyEPSG"), new DefaultIdentifier(Citations.ISBN, "NewISBN"), new DefaultIdentifier(Citations.ISSN, "MyISSN")));
    assertEquals("The ISBN value shall have been overwritten.", "NewISBN", citation.getISBN());
    assertEquals("The ISSN value shall have been added, because new.", "MyISSN", citation.getISSN());
    assertEquals("{NetCDF=“MyNetCDF”, EPSG=“MyEPSG”, ISBN=“NewISBN”, ISSN=“MyISSN”}", identifierMap.toString());
}
Also used : DefaultIdentifier(org.apache.sis.metadata.iso.DefaultIdentifier) Identifier(org.opengis.metadata.Identifier) IdentifierMap(org.apache.sis.xml.IdentifierMap) DefaultIdentifier(org.apache.sis.metadata.iso.DefaultIdentifier) Test(org.junit.Test)

Aggregations

Identifier (org.opengis.metadata.Identifier)60 ReferenceIdentifier (org.opengis.referencing.ReferenceIdentifier)21 Test (org.junit.Test)14 ImmutableIdentifier (org.apache.sis.metadata.iso.ImmutableIdentifier)11 Citation (org.opengis.metadata.citation.Citation)10 IdentifiedObject (org.opengis.referencing.IdentifiedObject)10 InternationalString (org.opengis.util.InternationalString)10 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)6 DefaultIdentifier (org.apache.sis.metadata.iso.DefaultIdentifier)6 IdentifierMap (org.apache.sis.xml.IdentifierMap)6 GeneralParameterDescriptor (org.opengis.parameter.GeneralParameterDescriptor)5 OperationMethod (org.opengis.referencing.operation.OperationMethod)5 NameToIdentifier (org.apache.sis.internal.metadata.NameToIdentifier)4 NamedIdentifier (org.apache.sis.referencing.NamedIdentifier)4 GenericName (org.opengis.util.GenericName)4 URI (java.net.URI)3 ParameterValueGroup (org.opengis.parameter.ParameterValueGroup)3 IdentityHashMap (java.util.IdentityHashMap)2 LinkedHashMap (java.util.LinkedHashMap)2