1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package info.magnolia.config.registry;
35
36 import lombok.AccessLevel;
37 import lombok.AllArgsConstructor;
38 import lombok.Data;
39
40
41
42
43
44
45
46
47
48
49 public class DefinitionProviderProblemBuilder {
50
51 private DefinitionProvider.Problem.SeverityType severityType;
52
53 private DefinitionProvider.Problem.Type type;
54
55 private String title;
56
57 private String details;
58
59 private String location = "/";
60
61 private Exception relatedException;
62
63 DefinitionProviderProblemBuilder() {
64 }
65
66 public DefinitionProviderProblemBuilder withSeverityType(DefinitionProvider.Problem.SeverityType severityType) {
67 this.severityType = severityType;
68 return this;
69 }
70
71 public DefinitionProviderProblemBuilder withType(DefinitionProvider.Problem.Type type) {
72 this.type = type;
73 return this;
74 }
75
76 public DefinitionProviderProblemBuilder withTitle(String title) {
77 this.title = title;
78 return this;
79 }
80
81 public DefinitionProviderProblemBuilder withDetails(String details) {
82 this.details = details;
83 return this;
84 }
85
86 public DefinitionProviderProblemBuilder withRelatedException(Exception relatedException) {
87 this.relatedException = relatedException;
88 return this;
89 }
90
91
92
93
94
95 public DefinitionProviderProblemBuilder withLocation(String location) {
96 this.location = location;
97 return this;
98 }
99
100 public DefinitionProvider.Problem build() {
101 return new ProblemImpl(severityType, type, location, title, details, relatedException);
102 }
103
104 @Data
105 @AllArgsConstructor(access = AccessLevel.PRIVATE)
106 private class ProblemImpl implements DefinitionProvider.Problem {
107 private SeverityType severityType;
108 private Type type;
109 private String location;
110 private String title;
111 private String details;
112 private Exception relatedException;
113
114 @Override
115 public String toString() {
116
117
118 return String.format("\nSeverity type: %s " +
119 "\nTitle: %s: [%s] - %s " +
120 "\nProblem details: %s", severityType.name(), location, type.getCaption(), title, details == null ? "" : details);
121 }
122 }
123 }