Search in sources :

Example 1 with DescriptionType

use of org.geotoolkit.se.xml.v110.DescriptionType in project mod-oai-pmh by folio-org.

the class GetOaiRepositoryInfoHelper method buildOaiIdentifierDescription.

/**
 * Creates oai-identifier description
 *
 * @param request the OAI-PMH request holder
 * @return oai-identifier {@link DescriptionType} elements
 */
private DescriptionType buildOaiIdentifierDescription(Request request) throws MalformedURLException {
    OaiIdentifier oaiIdentifier = new OaiIdentifier();
    oaiIdentifier.setRepositoryIdentifier(new URL(request.getOaiRequest().getValue()).getHost());
    oaiIdentifier.setSampleIdentifier(getIdentifier(request.getIdentifierPrefix(), STORAGE_IDENTIFIER_SAMPLE));
    return new DescriptionType().withAny(oaiIdentifier);
}
Also used : DescriptionType(org.openarchives.oai._2.DescriptionType) OaiIdentifier(org.openarchives.oai._2_0.oai_identifier.OaiIdentifier) URL(java.net.URL)

Example 2 with DescriptionType

use of org.geotoolkit.se.xml.v110.DescriptionType in project geotoolkit by Geomatys.

the class ProvidersXmlTest method testMarshallingWithSLD.

/**
 * Test for the marshalling process of a {@link MapContext}.
 *
 * @throws JAXBException
 */
@Test
public void testMarshallingWithSLD() throws JAXBException, Exception {
    final List<MapItem> mapLayers2 = new ArrayList<>();
    final StyledLayerDescriptor sld = new StyledLayerDescriptor();
    final UserStyle us = new UserStyle();
    final DescriptionType title = new DescriptionType();
    title.setTitle("test_sld");
    us.setDescription(title);
    final FeatureTypeStyleType fts = new FeatureTypeStyleType();
    fts.setName("ft_test");
    us.getFeatureTypeStyleOrCoverageStyleOrOnlineResource().add(fts);
    final UserLayer ul = new UserLayer();
    ul.getUserStyle().add(us);
    sld.getNamedLayerOrUserLayer().add(ul);
    mapLayers2.add(new MapLayer(new DataReference("postgis_test:my_otherlayer"), sld));
    mapLayers2.add(new MapLayer(new DataReference("coverage:my_thirdlayer"), new StyleReference("my_newstyle")));
    final List<MapItem> mapItems = new ArrayList<>();
    mapItems.add(new MapItem(mapLayers2));
    final MapLayer ml = new MapLayer(new DataReference("postgis_test:my_layer"), new StyleReference("my_style"));
    mapItems.add(new MapItem());
    mapItems.add(ml);
    final MapItem mapItem = new MapItem(mapItems);
    final MapContext mapContext = new MapContext(mapItem);
    final StringWriter sw = new StringWriter();
    marshaller.marshal(mapContext, sw);
    final String result = sw.toString();
    try {
        sw.close();
    } catch (IOException e) {
        fail("Unable to close the writer");
    }
    assertNotNull(result);
    assertFalse(result.isEmpty());
    DocumentComparator comparator = new DocumentComparator(RESULT_MARSHALLING_WITH_SLD, result.trim());
    comparator.ignoredAttributes.add("http://www.w3.org/2000/xmlns:*");
    comparator.compare();
}
Also used : UserStyle(org.geotoolkit.sld.xml.v110.UserStyle) DescriptionType(org.geotoolkit.se.xml.v110.DescriptionType) ArrayList(java.util.ArrayList) IOException(java.io.IOException) StyledLayerDescriptor(org.geotoolkit.sld.xml.v110.StyledLayerDescriptor) StringWriter(java.io.StringWriter) DocumentComparator(org.apache.sis.test.xml.DocumentComparator) FeatureTypeStyleType(org.geotoolkit.se.xml.v110.FeatureTypeStyleType) UserLayer(org.geotoolkit.sld.xml.v110.UserLayer)

Example 3 with DescriptionType

use of org.geotoolkit.se.xml.v110.DescriptionType in project openaire-cris-validator by EuroCRIS.

the class FileLoggingConnectionStreamFactory method check000_Identify.

/**
 * Ask for ?verb=Identity and test it for consistence – checks (1).
 * @throws Exception on any unexpected circumstance
 */
@Test
public void check000_Identify() throws Exception {
    final IdentifyType identify = endpoint.callIdentify();
    CheckingIterable<DescriptionType> checker = CheckingIterable.over(identify.getDescription());
    checker = checker.checkContainsOne(new Predicate<DescriptionType>() {

        @Override
        public boolean test(final DescriptionType description) {
            final Object obj = description.getAny();
            if (obj instanceof JAXBElement<?>) {
                final JAXBElement<?> jaxbEl = (JAXBElement<?>) obj;
                final Object obj1 = jaxbEl.getValue();
                if (obj1 instanceof OaiIdentifierType) {
                    final OaiIdentifierType oaiIdentifier = (OaiIdentifierType) obj1;
                    sampleIdentifier = Optional.ofNullable(oaiIdentifier.getSampleIdentifier());
                    return true;
                }
            }
            return false;
        }
    }, "the Identify descriptions list (1b)", "an 'oai-identifier' element");
    checker = checker.checkContainsOne(new Predicate<DescriptionType>() {

        @Override
        public boolean test(final DescriptionType description) {
            final Object obj = description.getAny();
            if (obj instanceof Element) {
                final Element el = (Element) obj;
                if ("Service".equals(el.getLocalName()) && OPENAIRE_CERIF_XMLNS.equals(el.getNamespaceURI())) {
                    serviceAcronym = XmlUtils.getTextContents(XmlUtils.getFirstMatchingChild(el, "Acronym", el.getNamespaceURI()));
                    validateMetadataPayload(el);
                    return true;
                }
            }
            return false;
        }
    }, "the Identify descriptions list (1a)", "a 'Service' element");
    checker.run();
    if (!endpoint.getBaseUrl().startsWith("file:")) {
        assertEquals("Identify response has a different endpoint base URL (1d)", endpoint.getBaseUrl(), identify.getBaseURL());
    }
    final Optional<String> repoIdentifier = endpoint.getRepositoryIdentifer();
    if (serviceAcronym.isPresent() && repoIdentifier.isPresent()) {
        assertEquals("Service acronym is not the same as the repository identifier (1c)", serviceAcronym.get(), repoIdentifier.get());
    }
}
Also used : IdentifyType(org.openarchives.oai._2.IdentifyType) DescriptionType(org.openarchives.oai._2.DescriptionType) OaiIdentifierType(org.openarchives.oai._2_0.oai_identifier.OaiIdentifierType) JAXBElement(javax.xml.bind.JAXBElement) Element(org.w3c.dom.Element) JAXBElement(javax.xml.bind.JAXBElement) Predicate(java.util.function.Predicate) Test(org.junit.Test)

Example 4 with DescriptionType

use of org.geotoolkit.se.xml.v110.DescriptionType in project openaire-cris-validator by EuroCRIS.

the class OAIPMHEndpoint method extractRepoIdentifier.

/**
 * Extracts the OAI identifier's repository identifier value.
 * @param identifyResponse the response to an Identify request
 * @param the repository identifier if one is provided, an empty {@link Optional} otherwise.
 */
private Optional<String> extractRepoIdentifier(final IdentifyType identifyResponse) {
    for (final DescriptionType description : identifyResponse.getDescription()) {
        final Object obj = description.getAny();
        if (obj instanceof JAXBElement<?>) {
            final JAXBElement<?> jaxbEl = (JAXBElement<?>) obj;
            final Object obj1 = jaxbEl.getValue();
            if (obj1 instanceof OaiIdentifierType) {
                final OaiIdentifierType oaiIdentifier = (OaiIdentifierType) obj1;
                return Optional.ofNullable(oaiIdentifier.getRepositoryIdentifier());
            }
        }
    }
    return Optional.empty();
}
Also used : DescriptionType(org.openarchives.oai._2.DescriptionType) OaiIdentifierType(org.openarchives.oai._2_0.oai_identifier.OaiIdentifierType) JAXBElement(javax.xml.bind.JAXBElement)

Aggregations

DescriptionType (org.openarchives.oai._2.DescriptionType)3 JAXBElement (javax.xml.bind.JAXBElement)2 OaiIdentifierType (org.openarchives.oai._2_0.oai_identifier.OaiIdentifierType)2 IOException (java.io.IOException)1 StringWriter (java.io.StringWriter)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 Predicate (java.util.function.Predicate)1 DocumentComparator (org.apache.sis.test.xml.DocumentComparator)1 DescriptionType (org.geotoolkit.se.xml.v110.DescriptionType)1 FeatureTypeStyleType (org.geotoolkit.se.xml.v110.FeatureTypeStyleType)1 StyledLayerDescriptor (org.geotoolkit.sld.xml.v110.StyledLayerDescriptor)1 UserLayer (org.geotoolkit.sld.xml.v110.UserLayer)1 UserStyle (org.geotoolkit.sld.xml.v110.UserStyle)1 Test (org.junit.Test)1 IdentifyType (org.openarchives.oai._2.IdentifyType)1 OaiIdentifier (org.openarchives.oai._2_0.oai_identifier.OaiIdentifier)1 Element (org.w3c.dom.Element)1