nl.vpro.domain.api.Error Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of api-domain Show documentation
Show all versions of api-domain Show documentation
Contains the objects used by the Frontend API, like forms and result objects
/*
* Copyright (C) 2013 All rights reserved
* VPRO The Netherlands
*/
package nl.vpro.domain.api;
import lombok.Getter;
import lombok.Setter;
import java.util.ArrayList;
import java.util.List;
import javax.ws.rs.core.Response;
import javax.xml.bind.annotation.*;
import org.apache.commons.lang3.ClassUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import nl.vpro.domain.constraint.*;
/**
*
* @author Roelof Jan Koekoek
* @since 2.0
*/
@XmlAccessorType(XmlAccessType.NONE)
@XmlRootElement(name = "error")
@XmlType(name = "errorType", propOrder = {
"message",
"classes",
"cause",
"violations",
"testResult"
})
@JsonPropertyOrder({"status", "message", "classes", "cause", "violations", "testResult"})
public class Error {
@XmlAttribute
@Getter
private Integer status;
@XmlElement
@Getter
private String message;
@XmlElement
@Getter
private String cause;
@XmlElement(name = "class")
@JsonProperty("classes")
@Getter
private List classes;
@XmlAnyElement(lax = true)
@Getter
@Setter
List> violations;
@Getter
@Setter
@XmlElement
private PredicateTestResult testResult;
public Error() {
}
public Error(Integer status, String message) {
this.status = status;
this.message = message;
}
public Error(Integer status, Throwable t) {
this.status = status;
this.message = t.getMessage();
this.cause = ExceptionUtils.getStackTrace(t);
this.classes = listOfClasses(t);
}
public Error(Response.Status status, Throwable t) {
this.status = status.getStatusCode();
this.message = t.getMessage();
this.cause = ExceptionUtils.getStackTrace(t);
this.classes = listOfClasses(t);
}
public Error(Integer status, String message, Throwable t) {
this.status = status;
this.message = message + " " + t.getMessage();
this.cause = ExceptionUtils.getStackTrace(t);
this.classes = listOfClasses(t);
}
public Error(Response.Status status, String message) {
this.status = status.getStatusCode();
this.message = message;
}
void causeString(String string) {
this.cause = string;
}
@Override
public String toString() {
return status + ":" + message;
}
private static List listOfClasses(Throwable t) {
List result = new ArrayList<>();
listOfClasses(t.getClass(), result);
for (Class> c : ClassUtils.getAllInterfaces(t.getClass())) {
result.add(c.getCanonicalName());
}
return result;
}
private static void listOfClasses(Class t, List result) {
if (t != null) {
String cannonicalName = t.getCanonicalName();
if (! result.contains(cannonicalName)) {
result.add(cannonicalName);
Class> superclass = t.getSuperclass();
if (Throwable.class.isAssignableFrom(superclass)) {
listOfClasses((Class) superclass, result);
}
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy