org.jlot.api.RestError Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jlot-api Show documentation
Show all versions of jlot-api Show documentation
This project is just a container for some resources needed by jlot-client and jlot-web,
so both projects can access Api URLs. This way jlot-client does not need to depend on jlot-web.
package org.jlot.api;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.http.HttpStatus;
import org.springframework.util.ObjectUtils;
public class RestError
{
private int statusCode;
private String message;
private String developerMessage;
private String moreInfoUrl;
private Throwable throwable;
private List objectErrors = new ArrayList();
private Map fieldErrors = new HashMap();
public RestError ()
{}
public RestError ( int code, String message, String developerMessage, String moreInfoUrl, Throwable throwable )
{
setStatusCode(code);
setMessage(message);
setDeveloperMessage(developerMessage);
setMoreInfoUrl(moreInfoUrl);
setThrowable(throwable);
}
public HttpStatus getHttpStatus ( )
{
return HttpStatus.valueOf(statusCode);
}
public int getStatusCode ( )
{
return statusCode;
}
public String getMessage ( )
{
return message;
}
public String getDeveloperMessage ( )
{
return developerMessage;
}
public String getMoreInfoUrl ( )
{
return moreInfoUrl;
}
public Throwable getThrowable ( )
{
return throwable;
}
public void setHttpStatus ( HttpStatus httpStatus )
{
if (httpStatus == null)
{
throw new NullPointerException("HttpStatus argument cannot be null.");
}
this.statusCode = httpStatus.value();
}
public void setStatusCode ( int statusCode )
{
this.statusCode = statusCode;
}
public void setMessage ( String message )
{
this.message = message;
}
public void setDeveloperMessage ( String developerMessage )
{
this.developerMessage = developerMessage;
}
public void setMoreInfoUrl ( String moreInfoUrl )
{
this.moreInfoUrl = moreInfoUrl;
}
public void setThrowable ( Throwable throwable )
{
this.throwable = throwable;
}
public void addObjectError ( String message )
{
objectErrors.add(message);
}
public void addFieldError ( String fieldName, String message )
{
fieldErrors.put(fieldName, message);
}
public Map getFieldErrors ( )
{
return Collections.unmodifiableMap(fieldErrors);
}
public List getObjectErrors ( )
{
return Collections.unmodifiableList(objectErrors);
}
@Override
public boolean equals ( Object o )
{
if (this == o)
{
return true;
}
if (o instanceof RestError)
{
RestError re = (RestError) o;
return getStatusCode() == re.getStatusCode() && ObjectUtils.nullSafeEquals(getMessage(), re.getMessage())
&& ObjectUtils.nullSafeEquals(getDeveloperMessage(), re.getDeveloperMessage())
&& ObjectUtils.nullSafeEquals(getMoreInfoUrl(), re.getMoreInfoUrl()) && ObjectUtils.nullSafeEquals(getThrowable(), re.getThrowable());
}
return false;
}
@Override
public int hashCode ( )
{
// noinspection ThrowableResultOfMethodCallIgnored
return ObjectUtils.nullSafeHashCode(new Object[] { getStatusCode(), getMessage(), getDeveloperMessage(), getMoreInfoUrl(), getThrowable() });
}
@Override
public String toString ( )
{
// noinspection StringBufferReplaceableByString
return new StringBuilder().append(getHttpStatus().value()).append(" (").append(getHttpStatus().getReasonPhrase()).append(" )").toString();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy