Search in sources :

Example 1 with IdentifyType

use of org.openarchives.oai._2.IdentifyType 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 IdentifyType

use of org.openarchives.oai._2.IdentifyType 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 3 with IdentifyType

use of org.openarchives.oai._2.IdentifyType 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 IdentifyType

use of org.openarchives.oai._2.IdentifyType 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

IdentifyType (org.openarchives.oai._2.IdentifyType)3 JAXBElement (javax.xml.bind.JAXBElement)2 DescriptionType (org.openarchives.oai._2.DescriptionType)2 OaiIdentifierType (org.openarchives.oai._2_0.oai_identifier.OaiIdentifierType)2 MalformedURLException (java.net.MalformedURLException)1 Predicate (java.util.function.Predicate)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1 OAIPMH (org.openarchives.oai._2.OAIPMH)1 Element (org.w3c.dom.Element)1