Search in sources :

Example 1 with PatronActionType

use of org.folio.circulation.domain.notice.session.PatronActionType in project mod-circulation by folio-org.

the class EndPatronSessionRequest method from.

public static List<Result<EndPatronSessionRequest>> from(JsonObject jsonObject) {
    final String END_SESSIONS = "endSessions";
    List<Result<EndPatronSessionRequest>> resultListOfEndPatronSessionRequests = new ArrayList<>();
    JsonArray endSessions = jsonObject.getJsonArray(END_SESSIONS);
    for (int i = 0; i < endSessions.size(); i++) {
        JsonObject endSession = endSessions.getJsonObject(i);
        final String patronIdFromJson = getProperty(endSession, PATRON_ID);
        if (isBlank(patronIdFromJson)) {
            return singletonList(failedValidation("End patron session request must have patron id", PATRON_ID, null));
        }
        String actionTypeRepresentation = getProperty(endSession, ACTION_TYPE);
        if (isBlank(actionTypeRepresentation)) {
            return singletonList(failedValidation("End patron session request must have action type", ACTION_TYPE, null));
        }
        resultListOfEndPatronSessionRequests.add(PatronActionType.from(actionTypeRepresentation).map(patronActionType -> new EndPatronSessionRequest(patronIdFromJson, patronActionType)).map(Result::succeeded).orElse(failedValidation("Invalid patron action type value", ACTION_TYPE, actionTypeRepresentation)));
    }
    return resultListOfEndPatronSessionRequests;
}
Also used : JsonArray(io.vertx.core.json.JsonArray) PATRON_ID(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.PATRON_ID) Getter(lombok.Getter) ACTION_TYPE(org.folio.circulation.domain.notice.session.PatronActionSessionProperties.ACTION_TYPE) Result(org.folio.circulation.support.results.Result) Collections.singletonList(java.util.Collections.singletonList) ValidationErrorFailure.failedValidation(org.folio.circulation.support.ValidationErrorFailure.failedValidation) ArrayList(java.util.ArrayList) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) StringUtils.isBlank(org.apache.commons.lang3.StringUtils.isBlank) PatronActionType(org.folio.circulation.domain.notice.session.PatronActionType) JsonObject(io.vertx.core.json.JsonObject) AllArgsConstructor(lombok.AllArgsConstructor) JsonPropertyFetcher.getProperty(org.folio.circulation.support.json.JsonPropertyFetcher.getProperty) ArrayList(java.util.ArrayList) JsonObject(io.vertx.core.json.JsonObject) Result(org.folio.circulation.support.results.Result)

Aggregations

JsonArray (io.vertx.core.json.JsonArray)1 JsonObject (io.vertx.core.json.JsonObject)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 AllArgsConstructor (lombok.AllArgsConstructor)1 Getter (lombok.Getter)1 StringUtils.isBlank (org.apache.commons.lang3.StringUtils.isBlank)1 ACTION_TYPE (org.folio.circulation.domain.notice.session.PatronActionSessionProperties.ACTION_TYPE)1 PATRON_ID (org.folio.circulation.domain.notice.session.PatronActionSessionProperties.PATRON_ID)1 PatronActionType (org.folio.circulation.domain.notice.session.PatronActionType)1 ValidationErrorFailure.failedValidation (org.folio.circulation.support.ValidationErrorFailure.failedValidation)1 JsonPropertyFetcher.getProperty (org.folio.circulation.support.json.JsonPropertyFetcher.getProperty)1 Result (org.folio.circulation.support.results.Result)1