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();
}
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();
}
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;
}
}
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;
}
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());
}
}
Aggregations