1
|
/**
|
2
|
* Copyright (C) 2023 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.api.dto.portal;
|
10
|
|
11
|
import org.apache.commons.lang3.exception.ExceptionUtils;
|
12
|
|
13
|
/**
|
14
|
* DTO to report errors, warnings or other types of messages.
|
15
|
* This may be errors that occur during DTO creation.
|
16
|
* Or debug messages for debug mode.
|
17
|
*
|
18
|
* @author a.mueller
|
19
|
* @date 07.01.2023
|
20
|
*/
|
21
|
public class MessagesDto {
|
22
|
|
23
|
public static enum MessageType{
|
24
|
ERROR,
|
25
|
WARN;
|
26
|
}
|
27
|
|
28
|
public static MessagesDto NewErrorInstance(String message, Exception exception) {
|
29
|
return new MessagesDto(MessageType.ERROR, message, exception);
|
30
|
}
|
31
|
public static MessagesDto NewErrorInstance() {
|
32
|
return new MessagesDto(MessageType.ERROR, null, null);
|
33
|
}
|
34
|
public static MessagesDto NewWarnInstance(String message) {
|
35
|
return new MessagesDto(MessageType.WARN, message, null);
|
36
|
}
|
37
|
|
38
|
private MessageType type;
|
39
|
private String message;
|
40
|
private String exceptionMessage;
|
41
|
private String stackTrace;
|
42
|
|
43
|
private MessagesDto(MessageType type, String message, Exception e) {
|
44
|
this.type = type;
|
45
|
this.message = message;
|
46
|
if (e != null) {
|
47
|
this.setExceptionMessage(e.getMessage());
|
48
|
this.setStackTrace(ExceptionUtils.getStackTrace(e));
|
49
|
}
|
50
|
}
|
51
|
|
52
|
//************ GETTER / SETTER *****************
|
53
|
|
54
|
|
55
|
public String getMessage() {
|
56
|
return message;
|
57
|
}
|
58
|
public MessageType getType() {
|
59
|
return type;
|
60
|
}
|
61
|
public void setType(MessageType type) {
|
62
|
this.type = type;
|
63
|
}
|
64
|
|
65
|
public void setMessage(String message) {
|
66
|
this.message = message;
|
67
|
}
|
68
|
public String getExceptionMessage() {
|
69
|
return exceptionMessage;
|
70
|
}
|
71
|
public void setExceptionMessage(String exceptionMessage) {
|
72
|
this.exceptionMessage = exceptionMessage;
|
73
|
}
|
74
|
public String getStackTrace() {
|
75
|
return stackTrace;
|
76
|
}
|
77
|
public void setStackTrace(String stackTrace) {
|
78
|
this.stackTrace = stackTrace;
|
79
|
}
|
80
|
}
|