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

org.vfdtech.models.ResponseWrapper Maven / Gradle / Ivy

Go to download

A utilities service with generic tools implementation. Can be plugged into your java project

There is a newer version: 0.3.5
Show newest version
package org.vfdtech.models;


import lombok.Builder;
import lombok.Data;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;

import java.util.Objects;


/**
 * This class is a wrapper class around the Apache Pair lib
 * and its purpose is to provide a container for a generic response
 * for web interface interaction with libraries and service.
 * 

* The statusCode is basically a Http-Standard (200,201,400, ...) compatible Integer. * The responseEntity is an Apache.Pair object, whose key is the message to show * and the Value is the data to return to the client or in case of errors, the list of errors */ @Data @Builder public class ResponseWrapper { private int statusCode; private Pair responseEntity; public static ResponseWrapper of(int statusCode, Pair responseEntity) { return builder().statusCode(statusCode).responseEntity(responseEntity).build(); } public boolean hasResponseEntityData() { return Objects.nonNull(responseEntity) && StringUtils.isNotBlank(responseEntity.getRight()); } public boolean isSuccessful() { return this.statusCode >= 200 && this.statusCode <= 299; } public boolean isClientError() { return this.statusCode >= 400 && this.statusCode <= 499; } public boolean isAuthError() { return this.statusCode == 401; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy