Search in sources :

Example 1 with Telephone

use of org.opengis.metadata.citation.Telephone in project sis by apache.

the class DefaultContactTest method testSetPhone.

/**
 * Implementation of {@link #testSetPhone()} and {@link #testSetNonSISPhone()}.
 *
 * @param hideSIS  whether to hide to {@link DefaultContact} the fact that
 *                 we are using a SIS implementation of {@code Telephone}.
 */
@SuppressWarnings("deprecation")
private void testSetPhone(final boolean hideSIS) {
    init();
    final DefaultTelephone tel = new DefaultTelephone();
    tel.setVoices(Arrays.asList("00.02", "00.04"));
    tel.setFacsimiles(Arrays.asList("00.03"));
    final Telephone view;
    if (hideSIS) {
        view = new Telephone() {

            @Override
            public Collection<String> getVoices() {
                return tel.getVoices();
            }

            @Override
            public Collection<String> getFacsimiles() {
                return tel.getFacsimiles();
            }
        };
    } else {
        view = tel;
    }
    verifyLegacyLists(tel);
    /*
         * Give the telephone to a contact, and verify that new telephone instances were created.
         */
    final DefaultContact contact = new DefaultContact();
    contact.setPhone(view);
    verifyLegacyLists(view);
    assertArrayEquals("getPhones", new DefaultTelephone[] { new DefaultTelephone("00.02", UnsupportedCodeList.VOICE), new DefaultTelephone("00.04", UnsupportedCodeList.VOICE), new DefaultTelephone("00.03", UnsupportedCodeList.FACSIMILE) }, contact.getPhones().toArray());
}
Also used : Telephone(org.opengis.metadata.citation.Telephone) Collection(java.util.Collection)

Example 2 with Telephone

use of org.opengis.metadata.citation.Telephone in project sis by apache.

the class DefaultContact method setPhones.

/**
 * Sets telephone numbers at which the organization or individual may be contacted.
 *
 * @param  newValues  the new telephones.
 *
 * @since 0.5
 */
public void setPhones(Collection<? extends Telephone> newValues) {
    phones = writeCollection(newValues, phones, Telephone.class);
    /*
         * Code below this point will be deleted after we removed the deprecated methods in DefaultTelephone.
         * This code notifies all DefaultTelephone instances about the list of phones in order to allow the
         * deprecated Telephone.getVoices() and Telephone.getFacsimiles() methods to fetches information from
         * the phones list.
         */
    if (phones != null) {
        boolean modified = false;
        final Telephone[] p = phones.toArray(new Telephone[newValues.size()]);
        for (int i = 0; i < p.length; i++) {
            final Telephone phone = p[i];
            if (phone instanceof DefaultTelephone) {
                p[i] = ((DefaultTelephone) phone).setOwner(phones);
                modified |= (p[i] != phone);
            }
        }
        if (modified) {
            phones.clear();
            phones.addAll(Arrays.asList(p));
        }
    }
}
Also used : Telephone(org.opengis.metadata.citation.Telephone)

Example 3 with Telephone

use of org.opengis.metadata.citation.Telephone in project sis by apache.

the class DefaultContact method setPhone.

/**
 * Sets telephone numbers at which the organization or individual may be contacted.
 * This method delegates to {@link #setPhones(Collection)}.
 *
 * @param  newValue  the new telephone, or {@code null} if none.
 *
 * @deprecated As of ISO 19115:2014, replaced by {@link #setPhones(Collection)}.
 */
@Deprecated
public void setPhone(Telephone newValue) {
    Collection<Telephone> newValues = null;
    if (newValue != null) {
        if (newValue instanceof DefaultTelephone) {
            newValues = ((DefaultTelephone) newValue).getOwner();
        } else {
            newValues = new ArrayList<>(4);
            for (String number : newValue.getVoices()) {
                newValues.add(new DefaultTelephone(number, UnsupportedCodeList.VOICE));
            }
            for (String number : newValue.getFacsimiles()) {
                newValues.add(new DefaultTelephone(number, UnsupportedCodeList.FACSIMILE));
            }
        }
    }
    setPhones(newValues);
}
Also used : Telephone(org.opengis.metadata.citation.Telephone) InternationalString(org.opengis.util.InternationalString)

Example 4 with Telephone

use of org.opengis.metadata.citation.Telephone in project sis by apache.

the class DefaultContactTest method verifyLegacyLists.

/**
 * Verify that the {@link DefaultTelephone#getVoices()} and {@link DefaultTelephone#getFacsimiles()} methods see
 * all numbers declared in the parent {@link DefaultContact}. This method presumes that each telephone contains:
 *
 * <ul>
 *   <li>Two voice numbers: "00.02" and "00.04" in that order.</li>
 *   <li>One facsimile number: "00.03".</li>
 * </ul>
 */
@SuppressWarnings("deprecation")
private static void verifyLegacyLists(final Telephone... tels) {
    final String[] voices = { "00.02", "00.04" };
    final String[] facsimiles = { "00.03" };
    for (final Telephone tel : tels) {
        assertArrayEquals("getVoices", voices, tel.getVoices().toArray());
        assertArrayEquals("getFacsimiles", facsimiles, tel.getFacsimiles().toArray());
    }
}
Also used : Telephone(org.opengis.metadata.citation.Telephone)

Example 5 with Telephone

use of org.opengis.metadata.citation.Telephone in project sis by apache.

the class MetadataWriterTest method readWriteDeprecated.

/**
 * Read and write a metadata object containing deprecated properties.
 * The metadata tested by this method is:
 *
 * {@preformat text
 *   Telephone
 *     ├─Number………………… 01.02.03.04
 *     └─Number type…… Voice
 * }
 *
 * The metadata should be stored in columns named {@code "number"} and {@code "numberType"} even if we
 * constructed the metadata using the deprecated {@code "voice"} property. Conversely, at reading time
 * the deprecated {@code "voice"} property should be converted in reading of non-deprecated properties.
 */
@SuppressWarnings("deprecation")
private void readWriteDeprecated() throws MetadataStoreException {
    final DefaultTelephone tel = new DefaultTelephone();
    tel.setVoices(Collections.singleton("01.02.03.04"));
    assertEquals("01.02.03.04", source.add(tel));
    final Telephone check = source.lookup(Telephone.class, "01.02.03.04");
    assertEquals("01.02.03.04", TestUtilities.getSingleton(check.getVoices()));
}
Also used : DefaultTelephone(org.apache.sis.metadata.iso.citation.DefaultTelephone) Telephone(org.opengis.metadata.citation.Telephone) DefaultTelephone(org.apache.sis.metadata.iso.citation.DefaultTelephone)

Aggregations

Telephone (org.opengis.metadata.citation.Telephone)6 InternationalString (org.opengis.util.InternationalString)2 Collection (java.util.Collection)1 XmlElement (javax.xml.bind.annotation.XmlElement)1 Dependencies (org.apache.sis.internal.metadata.Dependencies)1 DefaultTelephone (org.apache.sis.metadata.iso.citation.DefaultTelephone)1