Search in sources :

Example 1 with CitationDate

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

the class CodeListMarshallingTest method testLocalization.

/**
 * Implementation of {@link #testLocalization()} and {@link #testLocalizationLegacyXML()}.
 */
private void testLocalization(final boolean legacy) throws JAXBException {
    final MarshallerPool pool = getMarshallerPool();
    final Marshaller marshaller = pool.acquireMarshaller();
    if (legacy) {
        marshaller.setProperty(XML.METADATA_VERSION, VERSION_2007);
    }
    /*
         * First, test using the French locale.
         */
    marshaller.setProperty(XML.LOCALE, Locale.FRENCH);
    String expected = getCitationXML("fra", "Création", legacy);
    CitationDate ci = unmarshal(CitationDate.class, expected);
    assertEquals(DateType.CREATION, ci.getDateType());
    String actual = marshal(marshaller, ci);
    assertXmlEquals(expected, actual, "xmlns:*");
    /*
         * Tests again using the English locale.
         */
    marshaller.setProperty(XML.LOCALE, Locale.ENGLISH);
    expected = getCitationXML("eng", "Creation", legacy);
    ci = unmarshal(CitationDate.class, expected);
    assertEquals(DateType.CREATION, ci.getDateType());
    actual = marshal(marshaller, ci);
    assertXmlEquals(expected, actual, "xmlns:*");
    pool.recycle(marshaller);
}
Also used : Marshaller(javax.xml.bind.Marshaller) CitationDate(org.opengis.metadata.citation.CitationDate) MarshallerPool(org.apache.sis.xml.MarshallerPool)

Example 2 with CitationDate

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

the class MetadataBuilder method addEarliest.

/**
 * Adds a date in the given collection, making sure that there is no two dates of the same type.
 * If two dates are of the same type, retains the latest one if the type name starts with {@code "LATE_"}
 * or retains the earliest date otherwise.
 */
private static void addEarliest(final Collection<CitationDate> dates, final CitationDate cd, final DateType type) {
    for (final Iterator<CitationDate> it = dates.iterator(); it.hasNext(); ) {
        final CitationDate co = it.next();
        if (type.equals(co.getDateType())) {
            final Date oldDate = co.getDate();
            final Date newDate = cd.getDate();
            if (type.name().startsWith("LATE_") ? oldDate.before(newDate) : oldDate.after(newDate)) {
                it.remove();
                break;
            }
            return;
        }
    }
    dates.add(cd);
}
Also used : CitationDate(org.opengis.metadata.citation.CitationDate) DefaultCitationDate(org.apache.sis.metadata.iso.citation.DefaultCitationDate) CitationDate(org.opengis.metadata.citation.CitationDate) DefaultCitationDate(org.apache.sis.metadata.iso.citation.DefaultCitationDate) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 3 with CitationDate

use of org.opengis.metadata.citation.CitationDate in project tika by apache.

the class GeographicInformationParser method getMetaDataIdentificationInfo.

private void getMetaDataIdentificationInfo(Metadata metadata, DefaultMetadata defaultMetaData) {
    ArrayList<Identification> identifications = (ArrayList<Identification>) defaultMetaData.getIdentificationInfo();
    for (Identification i : identifications) {
        DefaultDataIdentification defaultDataIdentification = (DefaultDataIdentification) i;
        if (i.getCitation() != null && i.getCitation().getTitle() != null)
            metadata.add("IdentificationInfoCitationTitle ", i.getCitation().getTitle().toString());
        ArrayList<CitationDate> dateArrayList = (ArrayList<CitationDate>) i.getCitation().getDates();
        for (CitationDate d : dateArrayList) {
            if (d.getDateType() != null)
                metadata.add("CitationDate ", d.getDateType().name() + "-->" + d.getDate());
        }
        ArrayList<ResponsibleParty> responsiblePartyArrayList = (ArrayList<ResponsibleParty>) i.getCitation().getCitedResponsibleParties();
        for (ResponsibleParty r : responsiblePartyArrayList) {
            if (r.getRole() != null)
                metadata.add("CitedResponsiblePartyRole ", r.getRole().toString());
            if (r.getIndividualName() != null)
                metadata.add("CitedResponsiblePartyName ", r.getIndividualName().toString());
            if (r.getOrganisationName() != null)
                metadata.add("CitedResponsiblePartyOrganizationName ", r.getOrganisationName().toString());
            if (r.getPositionName() != null)
                metadata.add("CitedResponsiblePartyPositionName ", r.getPositionName().toString());
            if (r.getContactInfo() != null) {
                for (String s : r.getContactInfo().getAddress().getElectronicMailAddresses()) {
                    metadata.add("CitedResponsiblePartyEMail ", s.toString());
                }
            }
        }
        if (i.getAbstract() != null)
            metadata.add("IdentificationInfoAbstract ", i.getAbstract().toString());
        for (Progress p : i.getStatus()) {
            metadata.add("IdentificationInfoStatus ", p.name());
        }
        ArrayList<Format> formatArrayList = (ArrayList<Format>) i.getResourceFormats();
        for (Format f : formatArrayList) {
            if (f.getName() != null)
                metadata.add("ResourceFormatSpecificationAlternativeTitle ", f.getName().toString());
        }
        CheckedHashSet<Locale> localeCheckedHashSet = (CheckedHashSet<Locale>) defaultDataIdentification.getLanguages();
        for (Locale l : localeCheckedHashSet) {
            metadata.add("IdentificationInfoLanguage-->", l.getDisplayLanguage(Locale.ENGLISH));
        }
        CodeListSet<TopicCategory> categoryList = (CodeListSet<TopicCategory>) defaultDataIdentification.getTopicCategories();
        for (TopicCategory t : categoryList) {
            metadata.add("IdentificationInfoTopicCategory-->", t.name());
        }
        ArrayList<Keywords> keywordList = (ArrayList<Keywords>) i.getDescriptiveKeywords();
        int j = 1;
        for (Keywords k : keywordList) {
            j++;
            ArrayList<InternationalString> stringList = (ArrayList<InternationalString>) k.getKeywords();
            for (InternationalString s : stringList) {
                metadata.add("Keywords " + j, s.toString());
            }
            if (k.getType() != null)
                metadata.add("KeywordsType " + j, k.getType().name());
            if (k.getThesaurusName() != null && k.getThesaurusName().getTitle() != null)
                metadata.add("ThesaurusNameTitle " + j, k.getThesaurusName().getTitle().toString());
            if (k.getThesaurusName() != null && k.getThesaurusName().getAlternateTitles() != null)
                metadata.add("ThesaurusNameAlternativeTitle " + j, k.getThesaurusName().getAlternateTitles().toString());
            ArrayList<CitationDate> citationDates = (ArrayList<CitationDate>) k.getThesaurusName().getDates();
            for (CitationDate cd : citationDates) {
                if (cd.getDateType() != null)
                    metadata.add("ThesaurusNameDate ", cd.getDateType().name() + "-->" + cd.getDate());
            }
        }
        ArrayList<DefaultLegalConstraints> constraintList = (ArrayList<DefaultLegalConstraints>) i.getResourceConstraints();
        for (DefaultLegalConstraints c : constraintList) {
            for (Restriction r : c.getAccessConstraints()) {
                metadata.add("AccessContraints ", r.name());
            }
            for (InternationalString s : c.getOtherConstraints()) {
                metadata.add("OtherConstraints ", s.toString());
            }
            for (Restriction r : c.getUseConstraints()) {
                metadata.add("UserConstraints ", r.name());
            }
        }
        Collection<Extent> extentList = ((DefaultDataIdentification) i).getExtents();
        for (Extent e : extentList) {
            ArrayList<GeographicExtent> geoElements = (ArrayList<GeographicExtent>) e.getGeographicElements();
            for (GeographicExtent g : geoElements) {
                if (g instanceof DefaultGeographicDescription) {
                    if (((DefaultGeographicDescription) g).getGeographicIdentifier() != null && ((DefaultGeographicDescription) g).getGeographicIdentifier().getCode() != null)
                        metadata.add("GeographicIdentifierCode ", ((DefaultGeographicDescription) g).getGeographicIdentifier().getCode().toString());
                    if (((DefaultGeographicDescription) g).getGeographicIdentifier() != null && ((DefaultGeographicDescription) g).getGeographicIdentifier().getAuthority() != null && ((DefaultGeographicDescription) g).getGeographicIdentifier().getAuthority().getTitle() != null)
                        metadata.add("GeographicIdentifierAuthorityTitle ", ((DefaultGeographicDescription) g).getGeographicIdentifier().getAuthority().getTitle().toString());
                    for (InternationalString s : ((DefaultGeographicDescription) g).getGeographicIdentifier().getAuthority().getAlternateTitles()) {
                        metadata.add("GeographicIdentifierAuthorityAlternativeTitle ", s.toString());
                    }
                    for (CitationDate cd : ((DefaultGeographicDescription) g).getGeographicIdentifier().getAuthority().getDates()) {
                        if (cd.getDateType() != null && cd.getDate() != null)
                            metadata.add("GeographicIdentifierAuthorityDate ", cd.getDateType().name() + " " + cd.getDate().toString());
                    }
                }
            }
        }
    }
}
Also used : Locale(java.util.Locale) CodeListSet(org.apache.sis.util.collection.CodeListSet) Keywords(org.opengis.metadata.identification.Keywords) GeographicExtent(org.opengis.metadata.extent.GeographicExtent) Extent(org.opengis.metadata.extent.Extent) CheckedArrayList(org.apache.sis.internal.util.CheckedArrayList) ArrayList(java.util.ArrayList) DefaultDataIdentification(org.apache.sis.metadata.iso.identification.DefaultDataIdentification) Identification(org.opengis.metadata.identification.Identification) InternationalString(org.opengis.util.InternationalString) Format(org.opengis.metadata.distribution.Format) DefaultLegalConstraints(org.apache.sis.metadata.iso.constraint.DefaultLegalConstraints) DefaultDataIdentification(org.apache.sis.metadata.iso.identification.DefaultDataIdentification) CitationDate(org.opengis.metadata.citation.CitationDate) Progress(org.opengis.metadata.identification.Progress) TopicCategory(org.opengis.metadata.identification.TopicCategory) ResponsibleParty(org.opengis.metadata.citation.ResponsibleParty) CheckedHashSet(org.apache.sis.internal.util.CheckedHashSet) GeographicExtent(org.opengis.metadata.extent.GeographicExtent) DefaultGeographicDescription(org.apache.sis.metadata.iso.extent.DefaultGeographicDescription) Restriction(org.opengis.metadata.constraint.Restriction) InternationalString(org.opengis.util.InternationalString)

Example 4 with CitationDate

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

the class DefaultCitationDateTest method testCopyConstructor.

/**
 * Tests the copy constructor.
 *
 * @see <a href="http://jira.geotoolkit.org/browse/GEOTK-170">GEOTK-170</a>
 */
@Test
public void testCopyConstructor() {
    final CitationDate original = new CitationDate() {

        @Override
        public Date getDate() {
            return new Date(1305716658508L);
        }

        @Override
        public DateType getDateType() {
            return DateType.CREATION;
        }
    };
    final DefaultCitationDate copy = new DefaultCitationDate(original);
    assertEquals(new Date(1305716658508L), copy.getDate());
    assertEquals(DateType.CREATION, copy.getDateType());
    assertTrue(copy.equals(original, ComparisonMode.BY_CONTRACT));
    // Opportunist test.
    assertFalse(copy.equals(original, ComparisonMode.STRICT));
}
Also used : CitationDate(org.opengis.metadata.citation.CitationDate) Date(java.util.Date) CitationDate(org.opengis.metadata.citation.CitationDate) Test(org.junit.Test)

Example 5 with CitationDate

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

the class DefaultCitationTest method testUnmarshalling.

/**
 * Tests XML unmarshalling for a metadata version.
 * The version is not specified since it should be detected automatically.
 *
 * @param  file  file containing the metadata to unmarshal.
 */
private void testUnmarshalling(final String file) throws JAXBException {
    final DefaultCitation c = unmarshalFile(DefaultCitation.class, file);
    assertTitleEquals("title", "Fight against poverty", c);
    final CitationDate date = getSingleton(c.getDates());
    assertEquals("date", date.getDate(), TestUtilities.date("2015-10-17 00:00:00"));
    assertEquals("dateType", DateType.valueOf("adopted"), date.getDateType());
    assertEquals("presentationForm", PresentationForm.valueOf("physicalObject"), getSingleton(c.getPresentationForms()));
    final Iterator<ResponsibleParty> it = c.getCitedResponsibleParties().iterator();
    final Contact contact = assertResponsibilityEquals(Role.ORIGINATOR, "Maid Marian", it.next());
    assertEquals("Contact instruction", "Send carrier pigeon.", String.valueOf(contact.getContactInstructions()));
    final OnlineResource resource = contact.getOnlineResource();
    assertEquals("Resource name", "IP over Avian Carriers", String.valueOf(resource.getName()));
    assertEquals("Resource description", "High delay, low throughput, and low altitude service.", String.valueOf(resource.getDescription()));
    assertEquals("Resource linkage", "https://tools.ietf.org/html/rfc1149", String.valueOf(resource.getLinkage()));
    assertEquals("Resource function", OnLineFunction.OFFLINE_ACCESS, resource.getFunction());
    // Thanks to xlink:href, the Contact shall be the same instance as above.
    assertSame("contact", contact, assertResponsibilityEquals(Role.valueOf("funder"), "Robin Hood", it.next()));
    assertFalse(it.hasNext());
}
Also used : OnlineResource(org.opengis.metadata.citation.OnlineResource) CitationDate(org.opengis.metadata.citation.CitationDate) ResponsibleParty(org.opengis.metadata.citation.ResponsibleParty) Contact(org.opengis.metadata.citation.Contact)

Aggregations

CitationDate (org.opengis.metadata.citation.CitationDate)7 DefaultCitationDate (org.apache.sis.metadata.iso.citation.DefaultCitationDate)3 Date (java.util.Date)2 ResponsibleParty (org.opengis.metadata.citation.ResponsibleParty)2 LocalDate (java.time.LocalDate)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 Marshaller (javax.xml.bind.Marshaller)1 CheckedArrayList (org.apache.sis.internal.util.CheckedArrayList)1 CheckedHashSet (org.apache.sis.internal.util.CheckedHashSet)1 DefaultLegalConstraints (org.apache.sis.metadata.iso.constraint.DefaultLegalConstraints)1 DefaultGeographicDescription (org.apache.sis.metadata.iso.extent.DefaultGeographicDescription)1 DefaultDataIdentification (org.apache.sis.metadata.iso.identification.DefaultDataIdentification)1 CodeListSet (org.apache.sis.util.collection.CodeListSet)1 MarshallerPool (org.apache.sis.xml.MarshallerPool)1 Test (org.junit.Test)1 Contact (org.opengis.metadata.citation.Contact)1 OnlineResource (org.opengis.metadata.citation.OnlineResource)1 Restriction (org.opengis.metadata.constraint.Restriction)1 Format (org.opengis.metadata.distribution.Format)1