use of org.openarchives.oai._2.OAIPMHerrorType in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method getOaiListVerbWithWrongDatesAndWrongSet.
@ParameterizedTest
@EnumSource(value = VerbType.class, names = { "LIST_IDENTIFIERS", "LIST_RECORDS" })
void getOaiListVerbWithWrongDatesAndWrongSet(VerbType verb) {
String metadataPrefix = MetadataPrefix.MARC21XML.getName();
String from = "2018-09-19T02:52:08.873";
String until = "2018-10-20T02:03:04.567";
String set = "single";
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(FROM_PARAM, from).param(UNTIL_PARAM, until).param(METADATA_PREFIX_PARAM, metadataPrefix).param(SET_PARAM, set);
OAIPMH oaipmh = verifyResponseWithErrors(request, verb, 400, 3);
assertThat(oaipmh.getRequest().getSet(), equalTo(set));
assertThat(oaipmh.getRequest().getMetadataPrefix(), equalTo(metadataPrefix));
// The dates are of invalid format so they are not present in request
assertThat(oaipmh.getRequest().getFrom(), nullValue());
assertThat(oaipmh.getRequest().getUntil(), nullValue());
List<OAIPMHerrorType> errors = oaipmh.getErrors();
List<OAIPMHerrorcodeType> codes = errors.stream().map(OAIPMHerrorType::getCode).collect(Collectors.toList());
assertThat(codes, containsInAnyOrder(BAD_ARGUMENT, BAD_ARGUMENT, NO_RECORDS_MATCH));
Optional<String> noRecordsMsg = errors.stream().filter(error -> error.getCode() == NO_RECORDS_MATCH).map(OAIPMHerrorType::getValue).findAny();
noRecordsMsg.ifPresent(msg -> assertThat(msg, equalTo(NO_RECORD_FOUND_ERROR)));
}
use of org.openarchives.oai._2.OAIPMHerrorType in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method getOaiListVerbWithResumptionTokenAndMetadataPrefix.
@ParameterizedTest
@EnumSource(value = VerbType.class, names = { "LIST_IDENTIFIERS", "LIST_RECORDS" })
void getOaiListVerbWithResumptionTokenAndMetadataPrefix(VerbType verb) {
String resumptionToken = "abc";
String metadataPrefix = "oai_dc";
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(METADATA_PREFIX_PARAM, metadataPrefix).param(RESUMPTION_TOKEN_PARAM, resumptionToken);
OAIPMH oaipmh = verifyResponseWithErrors(request, verb, 400, 2);
assertThat(oaipmh.getRequest().getResumptionToken(), equalTo(resumptionToken));
assertThat(oaipmh.getRequest().getMetadataPrefix(), equalTo(metadataPrefix));
List<OAIPMHerrorType> errors = oaipmh.getErrors();
assertThat(oaipmh.getErrors().get(0).getCode(), is(equalTo(BAD_ARGUMENT)));
Optional<String> badArgMsg = errors.stream().filter(error -> error.getCode() == BAD_ARGUMENT).map(OAIPMHerrorType::getValue).findAny();
badArgMsg.ifPresent(msg -> assertThat(msg, equalTo(format(LIST_ILLEGAL_ARGUMENTS_ERROR, verb.name()))));
}
use of org.openarchives.oai._2.OAIPMHerrorType in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method getOaiListVerbWithInvalidDateRange.
@ParameterizedTest
@EnumSource(value = VerbType.class, names = { "LIST_IDENTIFIERS", "LIST_RECORDS" })
void getOaiListVerbWithInvalidDateRange(VerbType verb) {
String metadataPrefix = MetadataPrefix.MARC21XML.getName();
String from = "2018-12-19T02:52:08Z";
String until = "2018-10-20T02:03:04Z";
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(FROM_PARAM, from).param(UNTIL_PARAM, until).param(METADATA_PREFIX_PARAM, metadataPrefix);
OAIPMH oaipmh = verifyResponseWithErrors(request, verb, 400, 1);
assertThat(oaipmh.getRequest().getMetadataPrefix(), equalTo(metadataPrefix));
assertThat(oaipmh.getRequest().getFrom(), equalTo(from));
assertThat(oaipmh.getRequest().getUntil(), equalTo(until));
OAIPMHerrorType error = oaipmh.getErrors().get(0);
assertThat(error.getCode(), equalTo(BAD_ARGUMENT));
}
use of org.openarchives.oai._2.OAIPMHerrorType in project mod-oai-pmh by folio-org.
the class OaiPmhImplTest method getOaiListVerbWithWrongSet.
@ParameterizedTest
@EnumSource(value = VerbType.class, names = { "LIST_IDENTIFIERS", "LIST_RECORDS" })
void getOaiListVerbWithWrongSet(VerbType verb) {
String metadataPrefix = MetadataPrefix.MARC21XML.getName();
String set = "single";
RequestSpecification request = createBaseRequest().with().param(VERB_PARAM, verb.value()).param(METADATA_PREFIX_PARAM, metadataPrefix).param(SET_PARAM, set);
OAIPMH oaipmh = verifyResponseWithErrors(request, verb, 404, 1);
assertThat(oaipmh.getRequest().getMetadataPrefix(), equalTo(metadataPrefix));
assertThat(oaipmh.getRequest().getSet(), equalTo(set));
OAIPMHerrorType error = oaipmh.getErrors().get(0);
assertThat(error.getCode(), equalTo(NO_RECORDS_MATCH));
assertThat(error.getValue(), equalTo(NO_RECORD_FOUND_ERROR));
}
use of org.openarchives.oai._2.OAIPMHerrorType in project mod-oai-pmh by folio-org.
the class MarcWithHoldingsRequestHelper method handle.
/**
* Handle MarcWithHoldings request
*/
@Override
public Future<Response> handle(Request request, Context vertxContext) {
Promise<Response> oaipmhResponsePromise = Promise.promise();
metricsCollectingService.startMetric(request.getRequestId(), SEND_REQUEST);
try {
String resumptionToken = request.getResumptionToken();
List<OAIPMHerrorType> errors = validateListRequest(request);
if (!errors.isEmpty()) {
return buildResponseWithErrors(request, oaipmhResponsePromise, errors);
}
String requestId;
OffsetDateTime lastUpdateDate = OffsetDateTime.now(ZoneId.systemDefault());
RequestMetadataLb requestMetadata = new RequestMetadataLb().setLastUpdatedDate(lastUpdateDate);
Future<RequestMetadataLb> updateRequestMetadataFuture;
if (resumptionToken == null) {
requestId = request.getRequestId();
requestMetadata.setRequestId(UUID.fromString(requestId));
updateRequestMetadataFuture = instancesService.saveRequestMetadata(requestMetadata, request.getTenant());
} else {
requestId = request.getRequestId();
updateRequestMetadataFuture = instancesService.updateRequestUpdatedDate(requestId, lastUpdateDate, request.getTenant());
}
updateRequestMetadataFuture.onSuccess(res -> {
boolean isFirstBatch = resumptionToken == null;
processBatch(request, vertxContext, oaipmhResponsePromise, requestId, isFirstBatch);
if (isFirstBatch) {
saveInstancesExecutor.executeBlocking(downloadInstancesPromise -> downloadInstances(request, oaipmhResponsePromise, downloadInstancesPromise, downloadContext), downloadInstancesResult -> {
instancesService.updateRequestStreamEnded(requestId, true, request.getTenant());
if (downloadInstancesResult.succeeded()) {
logger.info("Downloading instances complete.");
} else {
logger.error("Downloading instances was canceled due to the error. ", downloadInstancesResult.cause());
if (!oaipmhResponsePromise.future().isComplete()) {
oaipmhResponsePromise.fail(new IllegalStateException(downloadInstancesResult.cause()));
}
}
});
}
}).onFailure(th -> handleException(oaipmhResponsePromise, th));
} catch (Exception e) {
handleException(oaipmhResponsePromise, e);
}
return oaipmhResponsePromise.future().onComplete(responseAsyncResult -> metricsCollectingService.endMetric(request.getRequestId(), SEND_REQUEST));
}
Aggregations