Search in sources :

Example 31 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.

the class DefaultProcessStepTest method roundtrip.

/**
 * Tests (un)marshalling in the given version.
 */
private void roundtrip(final String filename, final Version version) throws JAXBException {
    final DefaultProcessing processing = new DefaultProcessing();
    final DefaultProcessStep processStep = new DefaultProcessStep("Some process step.");
    processing.setProcedureDescription(new SimpleInternationalString("Some procedure."));
    processing.setIdentifier(new DefaultIdentifier("P4"));
    processStep.setProcessingInformation(processing);
    /*
         * XML marshalling, and compare with the content of "ProcessStep.xml" file.
         */
    assertMarshalEqualsFile(filename, processStep, version, "xmlns:*", "xsi:schemaLocation");
    /*
         * XML unmarshalling: ensure that we didn't lost any information.
         * Note that since the XML uses the <gmi:…> namespace, we got an instance of LE_ProcessStep, which
         * in SIS implementation does not carry any useful information; it is just a consequence of the way
         * namespaces are managed. We will convert to the parent DefaultProcessStep type before comparison.
         */
    DefaultProcessStep step = unmarshalFile(DefaultProcessStep.class, filename);
    assertInstanceOf("The unmarshalled object is expected to be in GMI namespace.", LE_ProcessStep.class, step);
    step = new DefaultProcessStep(step);
    assertEquals(processStep, step);
}
Also used : SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) DefaultIdentifier(org.apache.sis.metadata.iso.DefaultIdentifier)

Example 32 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.

the class MetadataTest method createHardCoded.

/**
 * Programmatically creates the metadata to marshall, or to compare against the unmarshalled metadata.
 *
 * @return the hard-coded representation of {@code "Metadata.xml"} content.
 */
private DefaultMetadata createHardCoded() {
    final DefaultMetadata metadata = new DefaultMetadata();
    metadata.setMetadataIdentifier(new DefaultIdentifier("Apache SIS/Metadata test"));
    metadata.setLanguages(singleton(Locale.ENGLISH));
    metadata.setCharacterSets(singleton(StandardCharsets.UTF_8));
    metadata.setMetadataScopes(singleton(new DefaultMetadataScope(ScopeCode.DATASET, "Common Data Index record")));
    metadata.setDateInfo(singleton(new DefaultCitationDate(TestUtilities.date("2009-01-01 04:00:00"), DateType.CREATION)));
    /*
         * Contact information for the author. The same party will be used for custodian and distributor,
         * with only the role changed. Note that we need to create an instance of the deprecated class,
         * because this is what will be unmarshalled from the XML document.
         */
    @SuppressWarnings("deprecation") final DefaultResponsibleParty author = new DefaultResponsibleParty(Role.AUTHOR);
    // Non-public SIS class.
    final Anchor country = new Anchor(URI.create("SDN:C320:2:FR"), "France");
    {
        final DefaultOnlineResource online = new DefaultOnlineResource(URI.create("http://www.ifremer.fr/sismer/"));
        online.setProtocol("http");
        final DefaultContact contact = new DefaultContact(online);
        contact.getIdentifierMap().putSpecialized(IdentifierSpace.ID, "IFREMER");
        contact.setPhones(Arrays.asList(telephone("+33 (0)2 xx.xx.xx.x6", "VOICE"), telephone("+33 (0)2 xx.xx.xx.x4", "FACSIMILE")));
        final DefaultAddress address = new DefaultAddress();
        address.setDeliveryPoints(singleton("Brest institute"));
        address.setCity(new SimpleInternationalString("Plouzane"));
        address.setPostalCode("29280");
        address.setCountry(country);
        address.setElectronicMailAddresses(singleton("xx@xx.fr"));
        contact.setAddresses(singleton(address));
        author.setParties(singleton(new DefaultOrganisation("Marine institutes", null, null, contact)));
        metadata.setContacts(singleton(author));
    }
    /*
         * Data indentification.
         */
    {
        final DefaultCitation citation = new DefaultCitation("90008411.ctd");
        citation.setAlternateTitles(singleton(new SimpleInternationalString("42292_5p_19900609195600")));
        citation.setDates(Arrays.asList(new DefaultCitationDate(TestUtilities.date("1990-06-04 22:00:00"), DateType.REVISION), new DefaultCitationDate(TestUtilities.date("1979-08-02 22:00:00"), DateType.CREATION)));
        {
            @SuppressWarnings("deprecation") final DefaultResponsibleParty originator = new DefaultResponsibleParty(Role.ORIGINATOR);
            final DefaultOnlineResource online = new DefaultOnlineResource(URI.create("http://www.com.univ-mrs.fr/LOB/"));
            online.setProtocol("http");
            final DefaultContact contact = new DefaultContact(online);
            contact.setPhones(Arrays.asList(telephone("+33 (0)4 xx.xx.xx.x5", "VOICE"), telephone("+33 (0)4 xx.xx.xx.x8", "FACSIMILE")));
            final DefaultAddress address = new DefaultAddress();
            address.setDeliveryPoints(singleton("Oceanology institute"));
            address.setCity(new SimpleInternationalString("Marseille"));
            address.setPostalCode("13288");
            address.setCountry(country);
            contact.setAddresses(singleton(address));
            originator.setParties(singleton(new DefaultOrganisation("Oceanology laboratory", null, null, contact)));
            citation.setCitedResponsibleParties(singleton(originator));
        }
        final DefaultDataIdentification identification = new DefaultDataIdentification(// Citation
        citation, // Abstract
        "CTD NEDIPROD VI 120", // Language,
        Locale.ENGLISH, // Topic category
        TopicCategory.OCEANS);
        {
            @SuppressWarnings("deprecation") final DefaultResponsibleParty custodian = new DefaultResponsibleParty((DefaultResponsibility) author);
            custodian.setRole(Role.CUSTODIAN);
            identification.setPointOfContacts(singleton(custodian));
        }
        /*
             * Data indentification / Keywords.
             */
        {
            final DefaultKeywords keyword = new DefaultKeywords(new Anchor(URI.create("SDN:P021:35:ATTN"), "Transmittance and attenuance of the water column"));
            keyword.setType(KeywordType.THEME);
            final DefaultCitation thesaurus = new DefaultCitation("BODC Parameter Discovery Vocabulary");
            thesaurus.setAlternateTitles(singleton(new SimpleInternationalString("P021")));
            thesaurus.setDates(singleton(new DefaultCitationDate(TestUtilities.date("2008-11-25 23:00:00"), DateType.REVISION)));
            thesaurus.setEdition(new Anchor(URI.create("SDN:C371:1:35"), "35"));
            thesaurus.setIdentifiers(singleton(new ImmutableIdentifier(null, null, "http://www.seadatanet.org/urnurl/")));
            keyword.setThesaurusName(thesaurus);
            identification.setDescriptiveKeywords(singleton(keyword));
        }
        /*
             * Data indentification / Browse graphic.
             */
        {
            final DefaultBrowseGraphic g = new DefaultBrowseGraphic(URI.create("file:///thumbnail.png"));
            g.setFileDescription(new SimpleInternationalString("Arbitrary thumbnail for this test only."));
            identification.setGraphicOverviews(singleton(g));
        }
        /*
             * Data indentification / Resource constraint.
             */
        {
            final DefaultLegalConstraints constraint = new DefaultLegalConstraints();
            constraint.setAccessConstraints(singleton(Restriction.LICENSE));
            identification.setResourceConstraints(singleton(constraint));
        }
        /*
             * Data indentification / Aggregate information.
             */
        {
            @SuppressWarnings("deprecation") final DefaultAggregateInformation aggregateInfo = new DefaultAggregateInformation();
            final DefaultCitation name = new DefaultCitation("MEDIPROD VI");
            name.setAlternateTitles(singleton(new SimpleInternationalString("90008411")));
            name.setDates(singleton(new DefaultCitationDate(TestUtilities.date("1990-06-04 22:00:00"), DateType.REVISION)));
            aggregateInfo.setName(name);
            aggregateInfo.setInitiativeType(InitiativeType.CAMPAIGN);
            // There is a typo ("WORD" → "WORK"), but we have to use the wrong spelling for this branch.
            aggregateInfo.setAssociationType(AssociationType.LARGER_WORD_CITATION);
            identification.setAggregationInfo(singleton(aggregateInfo));
        }
        /*
             * Data indentification / Extent.
             */
        {
            final DefaultCoordinateSystemAxis axis = new DefaultCoordinateSystemAxis(singletonMap(DefaultCoordinateSystemAxis.NAME_KEY, new NamedIdentifier(null, "Depth")), "d", AxisDirection.DOWN, Units.METRE);
            final DefaultVerticalCS cs = new DefaultVerticalCS(singletonMap(DefaultVerticalCS.NAME_KEY, new NamedIdentifier(null, "Depth")), axis);
            final DefaultVerticalDatum datum = new DefaultVerticalDatum(singletonMap(DefaultVerticalDatum.NAME_KEY, new NamedIdentifier(null, "D28")), VerticalDatumType.OTHER_SURFACE);
            final DefaultVerticalCRS vcrs = new DefaultVerticalCRS(singletonMap(DefaultVerticalCRS.NAME_KEY, new NamedIdentifier(null, "Depth below D28")), datum, cs);
            final DefaultTemporalExtent temporal = new DefaultTemporalExtent();
            setTemporalBounds(temporal, "1990-06-05", "1990-07-02");
            identification.setExtents(singleton(new DefaultExtent(null, new DefaultGeographicBoundingBox(1.1667, 1.1667, 36.6, 36.6), new DefaultVerticalExtent(Double.NaN, Double.NaN, vcrs), temporal)));
        }
        /*
             * Data identification / Environmental description and Supplemental information.
             */
        {
            identification.setEnvironmentDescription(new SimpleInternationalString("Possibly cloudy."));
            identification.setSupplementalInformation(new SimpleInternationalString("This metadata has been modified with dummy values."));
        }
        metadata.setIdentificationInfo(singleton(identification));
    }
    /*
         * Information about spatial representation.
         */
    {
        final DefaultVectorSpatialRepresentation rep = new DefaultVectorSpatialRepresentation();
        final DefaultGeometricObjects geoObj = new DefaultGeometricObjects(GeometricObjectType.POINT);
        rep.setGeometricObjects(singleton(geoObj));
        metadata.setSpatialRepresentationInfo(singleton(rep));
    }
    /*
         * Information about Coordinate Reference System.
         */
    {
        final DefaultCitation citation = new DefaultCitation("A geographic coordinate reference frames");
        citation.setAlternateTitles(singleton(new SimpleInternationalString("L101")));
        citation.setIdentifiers(singleton(new ImmutableIdentifier(null, null, "http://www.seadatanet.org/urnurl/")));
        citation.setEdition(new Anchor(URI.create("SDN:C371:1:2"), "2"));
        metadata.setReferenceSystemInfo(singleton(new ReferenceSystemMetadata(new ImmutableIdentifier(citation, "L101", "EPSG:4326"))));
    }
    /*
         * Information about content.
         */
    {
        final DefaultImageDescription contentInfo = new DefaultImageDescription();
        contentInfo.setCloudCoverPercentage(50.0);
        metadata.setContentInfo(singleton(contentInfo));
    }
    /*
         * Extension to metadata.
         */
    {
        final DefaultMetadataExtensionInformation extensionInfo = new DefaultMetadataExtensionInformation();
        extensionInfo.setExtendedElementInformation(singleton(new DefaultExtendedElementInformation(// Name
        "SDN:EDMO::", // Definition
        "http://www.seadatanet.org/urnurl/", // Condition
        null, // Data type
        Datatype.CODE_LIST, // Parent entity
        "SeaDataNet", // Rule
        null, // Source
        null)));
        metadata.setMetadataExtensionInfo(singleton(extensionInfo));
    }
    /*
         * Distribution information.
         */
    {
        @SuppressWarnings("deprecation") final DefaultResponsibleParty distributor = new DefaultResponsibleParty((DefaultResponsibility) author);
        final DefaultDistribution distributionInfo = new DefaultDistribution();
        distributor.setRole(Role.DISTRIBUTOR);
        distributionInfo.setDistributors(singleton(new DefaultDistributor(distributor)));
        final DefaultFormat format = new DefaultFormat();
        final DefaultCitation specification = new DefaultCitation();
        specification.setAlternateTitles(singleton(new Anchor(URI.create("SDN:L241:1:MEDATLAS"), "MEDATLAS ASCII")));
        specification.setEdition(new SimpleInternationalString("1.0"));
        format.setFormatSpecificationCitation(specification);
        distributionInfo.setDistributionFormats(singleton(format));
        final DefaultDigitalTransferOptions transfer = new DefaultDigitalTransferOptions();
        transfer.setTransferSize(2.431640625);
        final DefaultOnlineResource onlines = new DefaultOnlineResource(URI.create("http://www.ifremer.fr/data/something"));
        onlines.setDescription(new SimpleInternationalString("CTDF02"));
        onlines.setFunction(OnLineFunction.DOWNLOAD);
        onlines.setProtocol("http");
        transfer.setOnLines(singleton(onlines));
        distributionInfo.setTransferOptions(singleton(transfer));
        metadata.setDistributionInfo(distributionInfo);
    }
    return metadata;
}
Also used : DefaultVerticalCS(org.apache.sis.referencing.cs.DefaultVerticalCS) NamedIdentifier(org.apache.sis.referencing.NamedIdentifier) DefaultCoordinateSystemAxis(org.apache.sis.referencing.cs.DefaultCoordinateSystemAxis) Anchor(org.apache.sis.internal.jaxb.gcx.Anchor) DefaultVerticalCRS(org.apache.sis.referencing.crs.DefaultVerticalCRS) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) ReferenceSystemMetadata(org.apache.sis.internal.jaxb.metadata.replace.ReferenceSystemMetadata) DefaultVerticalDatum(org.apache.sis.referencing.datum.DefaultVerticalDatum)

Example 33 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.

the class AssociationRoleBuilderTest method testMetadata.

/**
 * Tests the name, designation, definition, description and cardinality associated to the role.
 */
@Test
public void testMetadata() {
    final FeatureTypeBuilder ftb = new FeatureTypeBuilder().setName("Highway");
    final NamedIdentifier target = new NamedIdentifier(null, "Bridge");
    final AssociationRoleBuilder builder = new AssociationRoleBuilder(ftb, null, target).setDescription("Bridges on the highway").setDefinition("A definition").setDesignation("A designation").setMaximumOccurs(2).setMinimumOccurs(1);
    final DefaultAssociationRole role = builder.build();
    assertEquals("minimumOccurs", 1, role.getMinimumOccurs());
    assertEquals("maximumOccurs", 2, role.getMaximumOccurs());
    assertEquals("designation", new SimpleInternationalString("A designation"), role.getDesignation());
    assertEquals("definition", new SimpleInternationalString("A definition"), role.getDefinition());
    assertEquals("description", new SimpleInternationalString("Bridges on the highway"), role.getDescription());
}
Also used : DefaultAssociationRole(org.apache.sis.feature.DefaultAssociationRole) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) NamedIdentifier(org.apache.sis.referencing.NamedIdentifier) Test(org.junit.Test)

Example 34 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.

the class FeatureTestCase method testComplexFeature.

/**
 * Tests {@link AbstractFeature#getProperty(String)} and {@link AbstractFeature#getPropertyValue(String)}
 * on a "complex" feature, involving multi-valued properties, inheritances and property overriding.
 */
@Test
@DependsOnMethod({ "testSimpleValues", "testSimpleProperties" })
public void testComplexFeature() {
    feature = createFeature(DefaultFeatureTypeTest.worldMetropolis());
    setAttributeValue("city", "Utopia", "New York");
    // Estimation for 2013.
    setAttributeValue("population", null, 8405837);
    /*
         * Set the attribute value on a property having [0 … ∞] cardinality.
         * The feature implementation should put the value in a list.
         */
    assertEquals("universities", Collections.emptyList(), getAttributeValue("universities"));
    feature.setPropertyValue("universities", "University of arts");
    assertEquals("universities", Collections.singletonList("University of arts"), getAttributeValue("universities"));
    /*
         * Switch to 'getProperty' mode only after we have set at least one value,
         * in order to test the conversion of existing values to property instances.
         */
    getValuesFromProperty = true;
    final SimpleInternationalString region = new SimpleInternationalString("State of New York");
    setAttributeValue("region", null, region);
    /*
         * Adds more universities.
         */
    @SuppressWarnings("unchecked") final Collection<String> universities = (Collection<String>) feature.getPropertyValue("universities");
    assertTrue(universities.add("University of sciences"));
    assertTrue(universities.add("University of international development"));
    /*
         * In our 'metropolis' feature type, the region can be any CharSequence. But 'worldMetropolis'
         * feature type overrides the region property with a restriction to InternationalString.
         * Verifiy that this restriction is checked.
         */
    try {
        feature.setPropertyValue("region", "State of New York");
        fail("Shall not be allowed to set a value of the wrong type.");
    } catch (ClassCastException e) {
        final String message = e.getMessage();
        assertTrue(message, message.contains("region"));
        assertTrue(message, message.contains("String"));
    }
    assertSame("region", region, getAttributeValue("region"));
    /*
         * Before we set the 'isGlobal' attribute, the feature should be considered invalid.
         * After we set it, the feature should be valid since all mandatory attributes are set.
         */
    verifyQualityReports("isGlobal", "temperature");
    setAttributeValue("isGlobal", null, Boolean.TRUE);
    verifyQualityReports("temperature");
    /*
         * Opportunist tests using the existing instance.
         */
    testSerialization();
    try {
        // A birth...
        testClone("population", 8405837, 8405838);
    } catch (CloneNotSupportedException e) {
        throw new AssertionError(e);
    }
}
Also used : SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Collection(java.util.Collection) SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) Test(org.junit.Test) DependsOnMethod(org.apache.sis.test.DependsOnMethod)

Example 35 with SimpleInternationalString

use of org.apache.sis.util.iso.SimpleInternationalString in project sis by apache.

the class XLinkMarshallingTest method testWithElement.

/**
 * Tests (un)marshalling of an object with a {@code xlink:href} attribute with an element definition.
 * The XML fragment is:
 *
 * {@preformat xml
 *   <mdb:MD_Metadata>
 *     <mdb:identificationInfo xlink:href="http://test.net">
 *       <mdb:MD_DataIdentification>
 *         <mdb:abstract>
 *           <gco:CharacterString>This is a test.</gco:CharacterString>
 *         </mdb:abstract>
 *       </mdb:MD_DataIdentification>
 *     </mdb:identificationInfo>
 *   </mdb:MD_Metadata>
 * }
 *
 * @throws JAXBException if an error occurred during (un)marshalling.
 * @throws URISyntaxException if the URI used in this test is malformed.
 */
@Test
public void testWithElement() throws JAXBException, URISyntaxException {
    final XLink xlink = new XLink();
    xlink.setHRef(new URI("http://test.net"));
    final DefaultDataIdentification identification = new DefaultDataIdentification();
    identification.getIdentifierMap().putSpecialized(IdentifierSpace.XLINK, xlink);
    identification.setAbstract(new SimpleInternationalString("This is a test."));
    final DefaultMetadata metadata = new DefaultMetadata();
    metadata.setIdentificationInfo(Collections.singleton(identification));
    assertXmlEquals(LINK_WITH_ELEMENT_XML, marshal(metadata), "xmlns:*");
    final DefaultMetadata unmarshal = unmarshal(DefaultMetadata.class, LINK_WITH_ELEMENT_XML);
    verify(false, unmarshal);
    assertTrue(metadata.equals(unmarshal, ComparisonMode.DEBUG));
}
Also used : SimpleInternationalString(org.apache.sis.util.iso.SimpleInternationalString) DefaultMetadata(org.apache.sis.metadata.iso.DefaultMetadata) DefaultDataIdentification(org.apache.sis.metadata.iso.identification.DefaultDataIdentification) URI(java.net.URI) Test(org.junit.Test)

Aggregations

SimpleInternationalString (org.apache.sis.util.iso.SimpleInternationalString)45 Test (org.junit.Test)20 DefaultCitation (org.apache.sis.metadata.iso.citation.DefaultCitation)19 InternationalString (org.opengis.util.InternationalString)14 URI (java.net.URI)4 DependsOnMethod (org.apache.sis.test.DependsOnMethod)4 NamedIdentifier (org.apache.sis.referencing.NamedIdentifier)3 Citation (org.opengis.metadata.citation.Citation)3 IdentifiedObject (org.opengis.referencing.IdentifiedObject)3 Collection (java.util.Collection)2 DefaultIdentifier (org.apache.sis.metadata.iso.DefaultIdentifier)2 DefaultMetadata (org.apache.sis.metadata.iso.DefaultMetadata)2 DefaultAcquisitionInformation (org.apache.sis.metadata.iso.acquisition.DefaultAcquisitionInformation)2 DefaultInstrument (org.apache.sis.metadata.iso.acquisition.DefaultInstrument)2 DefaultPlatform (org.apache.sis.metadata.iso.acquisition.DefaultPlatform)2 DefaultFormat (org.apache.sis.metadata.iso.distribution.DefaultFormat)2 DefaultDataQuality (org.apache.sis.metadata.iso.quality.DefaultDataQuality)2 InvocationHandler (java.lang.reflect.InvocationHandler)1 Method (java.lang.reflect.Method)1 URISyntaxException (java.net.URISyntaxException)1