Search in sources :

Example 1 with IDENTIFY

use of org.openarchives.oai._2.VerbType.IDENTIFY in project mod-oai-pmh by folio-org.

the class GetOaiRepositoryInfoHelper method handle.

@Override
public Future<Response> handle(Request request, Context ctx) {
    Promise<Response> promise = Promise.promise();
    try {
        OAIPMH oai = getResponseHelper().buildBaseOaipmhResponse(request).withIdentify(new IdentifyType().withRepositoryName(getRepositoryName(request.getRequestId())).withBaseURL(request.getOaiRequest().getValue()).withProtocolVersion(REPOSITORY_PROTOCOL_VERSION_2_0).withEarliestDatestamp(getEarliestDatestamp()).withGranularity(GranularityType.fromValue(RepositoryConfigurationUtil.getProperty(request.getRequestId(), REPOSITORY_TIME_GRANULARITY))).withDeletedRecord(DeletedRecordType.fromValue(RepositoryConfigurationUtil.getProperty(request.getRequestId(), REPOSITORY_DELETED_RECORDS))).withAdminEmails(getEmails(request.getRequestId())).withCompressions(GZIP, DEFLATE).withDescriptions(getDescriptions(request)));
        promise.complete(getResponseHelper().buildSuccessResponse(oai));
    } catch (Exception e) {
        logger.error("Error happened while processing Identify verb request.", e);
        promise.fail(e);
    }
    return promise.future();
}
Also used : Response(javax.ws.rs.core.Response) OAIPMH(org.openarchives.oai._2.OAIPMH) IdentifyType(org.openarchives.oai._2.IdentifyType) MalformedURLException(java.net.MalformedURLException)

Example 2 with IDENTIFY

use of org.openarchives.oai._2.VerbType.IDENTIFY in project mod-oai-pmh by folio-org.

the class OaiPmhImplTest method getOaiRepositoryInfoSuccess.

@Test
void getOaiRepositoryInfoSuccess(VertxTestContext testContext) {
    RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, IDENTIFY.value());
    OAIPMH oaipmhFromString = verify200WithXml(request, IDENTIFY);
    verifyRepositoryInfoResponse(oaipmhFromString);
    testContext.completeNow();
}
Also used : OAIPMH(org.openarchives.oai._2.OAIPMH) RequestSpecification(io.restassured.specification.RequestSpecification) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 3 with IDENTIFY

use of org.openarchives.oai._2.VerbType.IDENTIFY in project openaire-cris-validator by EuroCRIS.

the class OAIPMHEndpoint method makeConnection.

/**
 * Contact the data provider with a request and return the parsed response.
 * The response must be schema-valid.
 * @param repoWideRequest true for Identify, ListMetadataFormats and ListSets
 * @param verb the verb of the request
 * @param params parameters of the request: pairs of ( name, value )
 * @return the unmarshalled response
 * @throws IOException on network error
 * @throws SAXException on XML parsing error
 * @throws JAXBException on XML processing error
 */
@SuppressWarnings("unchecked")
private OAIPMHtype makeConnection(final boolean repoWideRequest, final String verb, final String... params) throws IOException, SAXException, JAXBException {
    final URL url = makeUrl(verb, params);
    System.out.println("Fetching and validating " + url.toExternalForm());
    final URLConnection conn = handleCompression(url.openConnection());
    conn.setRequestProperty("User-Agent", userAgent);
    conn.setRequestProperty("Accept", "text/xml, application/xml");
    conn.connect();
    checkResponseCode(conn);
    checkContentTypeHeader(conn);
    checkContentEncodingHeader(conn);
    try (final InputStream inputStream = connStreamFactory.makeInputStream(conn)) {
        final Unmarshaller u = createUnmarshaller();
        final JAXBElement<OAIPMHtype> x = (JAXBElement<OAIPMHtype>) u.unmarshal(inputStream);
        final OAIPMHtype response = x.getValue();
        checkForErrors(response);
        return response;
    }
}
Also used : InputStream(java.io.InputStream) OAIPMHtype(org.openarchives.oai._2.OAIPMHtype) JAXBElement(javax.xml.bind.JAXBElement) Unmarshaller(javax.xml.bind.Unmarshaller) URL(java.net.URL) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection)

Example 4 with IDENTIFY

use of org.openarchives.oai._2.VerbType.IDENTIFY in project openaire-cris-validator by EuroCRIS.

the class OAIPMHEndpoint method callIdentify.

/**
 * Sends the Identify request and returns the result.
 * @return the result of the Identify call
 * @throws IOException on network error
 * @throws SAXException on XML parsing error
 * @throws JAXBException on XML processing error
 */
public IdentifyType callIdentify() throws IOException, SAXException, JAXBException {
    final IdentifyType identifyResponse = makeConnection(true, "Identify").getIdentify();
    supportedCompressions = Optional.of(identifyResponse.getCompression());
    repositoryIdentifier = extractRepoIdentifier(identifyResponse);
    return identifyResponse;
}
Also used : IdentifyType(org.openarchives.oai._2.IdentifyType)

Example 5 with IDENTIFY

use of org.openarchives.oai._2.VerbType.IDENTIFY 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)

Aggregations

JAXBElement (javax.xml.bind.JAXBElement)3 IdentifyType (org.openarchives.oai._2.IdentifyType)3 DescriptionType (org.openarchives.oai._2.DescriptionType)2 OAIPMH (org.openarchives.oai._2.OAIPMH)2 OaiIdentifierType (org.openarchives.oai._2_0.oai_identifier.OaiIdentifierType)2 RequestSpecification (io.restassured.specification.RequestSpecification)1 InputStream (java.io.InputStream)1 HttpURLConnection (java.net.HttpURLConnection)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 URLConnection (java.net.URLConnection)1 Predicate (java.util.function.Predicate)1 Response (javax.ws.rs.core.Response)1 Unmarshaller (javax.xml.bind.Unmarshaller)1 Test (org.junit.Test)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 OAIPMHtype (org.openarchives.oai._2.OAIPMHtype)1 Element (org.w3c.dom.Element)1