Skip to content

Commit

Permalink
MODOAIPMH-540: invalidRecordContent error code intro
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroBykov1 committed Mar 26, 2024
1 parent 9f120e4 commit 5670a0c
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions ramls/schemas/OAI-PMH.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
<enumeration value="badResumptionToken"/>
<enumeration value="noSetHierarchy"/>
<enumeration value="serviceUnavailable"/>
<enumeration value="invalidRecordContent"/>
</restriction>
</simpleType>

Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/folio/oaipmh/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ private Constants() {
public static final String LIST_ILLEGAL_ARGUMENTS_ERROR = "Verb '%s', argument 'resumptionToken' is exclusive, no others maybe specified with it.";
public static final String INVALID_RESUMPTION_TOKEN = "Verb '%s', argument resumptionToken is invalid";
public static final String NO_RECORD_FOUND_ERROR = "There were no records found matching the search criteria";
public static final String INVALID_CHARACTER_IN_THE_RECORD = "Invalid character in the record.";
public static final String BAD_DATESTAMP_FORMAT_ERROR = "Bad datestamp format for '%s=%s' argument.";
public static final String RECORD_METADATA_PREFIX_PARAM_ERROR = "The request is missing required arguments. There is no metadataPrefix.";
public static final String RECORD_NOT_FOUND_ERROR = "No matching identifier in repository.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,10 @@ protected Future<Response> processRecords(Context ctx, Request request,
Promise<Response> oaiResponsePromise = Promise.promise();
buildRecords(ctx, request, items).onSuccess(recordsMap -> {
Response response;
if (recordsMap.isEmpty()) {
if (recordsMap.isEmpty() && items.size() > 1) {
response = buildNoRecordsFoundOaiResponse(oaipmh, request);
} else if (recordsMap.isEmpty() && items.size() == 1) {
response = buildTheByteArrayCannotBeConvertedToJaxbObjectResponse(oaipmh, request);
} else {
addRecordsToOaiResponse(oaipmh, recordsMap.values());
addResumptionTokenToOaiResponse(oaipmh, resumptionToken);
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/org/folio/oaipmh/helpers/AbstractHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
import static org.folio.oaipmh.Constants.LIST_NO_REQUIRED_PARAM_ERROR;
import static org.folio.oaipmh.Constants.NEXT_RECORD_ID_PARAM;
import static org.folio.oaipmh.Constants.NO_RECORD_FOUND_ERROR;
import static org.folio.oaipmh.Constants.INVALID_CHARACTER_IN_THE_RECORD;
import static org.folio.oaipmh.Constants.OFFSET_PARAM;
import static org.folio.oaipmh.Constants.REPOSITORY_MAX_RECORDS_PER_RESPONSE;
import static org.folio.oaipmh.Constants.REPOSITORY_RECORDS_SOURCE;
Expand All @@ -87,6 +88,7 @@
import static org.openarchives.oai._2.OAIPMHerrorcodeType.CANNOT_DISSEMINATE_FORMAT;
import static org.openarchives.oai._2.OAIPMHerrorcodeType.ID_DOES_NOT_EXIST;
import static org.openarchives.oai._2.OAIPMHerrorcodeType.NO_RECORDS_MATCH;
import static org.openarchives.oai._2.OAIPMHerrorcodeType.INVALID_RECORD_CONTENT;

/**
* Abstract helper implementation that provides some common methods.
Expand All @@ -112,6 +114,10 @@ public abstract class AbstractHelper implements VerbHelper {

protected ErrorsService errorsService;

public Response buildTheByteArrayCannotBeConvertedToJaxbObjectResponse(OAIPMH oaipmh, Request request) {
oaipmh.withErrors(createInvalidJsonContentError());
return getResponseHelper().buildFailureResponse(oaipmh, request);
}
public Response buildNoRecordsFoundOaiResponse(OAIPMH oaipmh, Request request) {
oaipmh.withErrors(createNoRecordsFoundError());
return getResponseHelper().buildFailureResponse(oaipmh, request);
Expand All @@ -134,6 +140,9 @@ public static Response buildNoRecordsFoundOaiResponse(OAIPMH oaipmh, Request req
protected static OAIPMHerrorType createNoRecordsFoundError() {
return new OAIPMHerrorType().withCode(NO_RECORDS_MATCH).withValue(NO_RECORD_FOUND_ERROR);
}
protected static OAIPMHerrorType createInvalidJsonContentError() {
return new OAIPMHerrorType().withCode(INVALID_RECORD_CONTENT).withValue(INVALID_CHARACTER_IN_THE_RECORD);
}

public static ResponseHelper getResponseHelper() {
return responseHelper;
Expand Down

0 comments on commit 5670a0c

Please sign in to comment.