All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.azbh111.utils.java.web.model.PageResponse Maven / Gradle / Ivy

/*
 * Copyright (c) 2014-2019, Deepspring Healthcare Inc. All rights reserved.
 */

package com.github.azbh111.utils.java.web.model;

import com.github.azbh111.utils.java.model.Res;
import com.github.azbh111.utils.java.model.ResStatusEnum;
import lombok.ToString;


@ToString(callSuper = true)
public class PageResponse extends JsonResponse {

    private static final long serialVersionUID = -8439068266525433175L;

    protected PageRes page;

    protected PageResponse() {
    }

    public static  PageResponse from(Res res) {
        PageResponse jr = PageResponse.of(res.getStatus().getStatus(), res.getData());
        if (res.getErrorMsg() != null) {
            jr.setErrorMsg(res.getErrorMsg());
        } else if (res.getStatus().getDisplayMsg() != null) {
            jr.setErrorMsg(res.getStatus().getDisplayMsg());
        } else {
            jr.setErrorMsg(res.getStatus().getDesc());
        }
        return jr;
    }

    public static PageResponse success() {
        return new PageResponse();
    }

    public static  PageResponse success(T data) {
        return of(ResStatusEnum.OK.getStatus(), data, null);
    }

    public static PageResponse fail(String errorMsg) {
        return of(ResStatusEnum.BAD_REQUEST.getStatus(), null, errorMsg);
    }

    public static PageResponse of(int status, String errorMsg) {
        return of(status, null, errorMsg);
    }

    public static  PageResponse of(int status, T data) {
        return of(status, data, null);
    }

    public static  PageResponse of(int status, T data, String errorMsg) {
        return PageResponse.success()
                .setStatus(status)
                .setData(data)
                .setErrorMsg(errorMsg);
    }

    public PageResponse apply(Res res) {
        super.apply(res);
        return this;
    }

    public PageResponse setStatus(int status) {
        this.status = status;
        return this;
    }

    public PageResponse setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
        return this;
    }

    public PageResponse setData(T data) {
        this.data = data;
        return this;
    }

    public PageRes getPage() {
        return page;
    }

    public PageResponse setPage(PageRes page) {
        this.page = page;
        return this;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy