1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.common.lib.to;
20
21 import java.util.Collection;
22 import org.apache.commons.lang3.StringUtils;
23 import org.apache.commons.lang3.builder.ToStringBuilder;
24 import org.apache.syncope.common.lib.BaseBean;
25 import org.apache.syncope.common.lib.types.ResourceOperation;
26 import org.apache.syncope.common.lib.types.TraceLevel;
27
28 public class ProvisioningReport implements BaseBean {
29
30 private static final long serialVersionUID = 9201119472070963385L;
31
32 public enum Status {
33
34 SUCCESS,
35 IGNORE,
36 FAILURE
37
38 }
39
40 private String message;
41
42 private Status status;
43
44 private String anyType;
45
46 private ResourceOperation operation;
47
48 private String key;
49
50 private String name;
51
52 private String uidValue;
53
54 public String getMessage() {
55 return message;
56 }
57
58 public void setMessage(final String message) {
59 this.message = message;
60 }
61
62 public String getName() {
63 return name;
64 }
65
66 public void setName(final String name) {
67 this.name = name;
68 }
69
70 public String getKey() {
71 return key;
72 }
73
74 public void setKey(final String key) {
75 this.key = key;
76 }
77
78 public Status getStatus() {
79 return status;
80 }
81
82 public void setStatus(final Status status) {
83 this.status = status;
84 }
85
86 public String getAnyType() {
87 return anyType;
88 }
89
90 public void setAnyType(final String anyType) {
91 this.anyType = anyType;
92 }
93
94 public ResourceOperation getOperation() {
95 return operation;
96 }
97
98 public void setOperation(final ResourceOperation operation) {
99 this.operation = operation;
100 }
101
102 public String getUidValue() {
103 return uidValue;
104 }
105
106 public void setUidValue(final String uidValue) {
107 this.uidValue = uidValue;
108 }
109
110
111
112
113
114
115
116 public String getReportString(final TraceLevel level) {
117 if (level == TraceLevel.SUMMARY) {
118
119 return null;
120 } else if (level == TraceLevel.FAILURES && status == Status.FAILURE) {
121
122 return String.format("Failed %s (key/name): %s/%s with message: %s", operation, key, name, message);
123 } else {
124
125 return String.format("%s %s (key/name): %s/%s %s", operation, status, key, name,
126 StringUtils.isBlank(message)
127 ? ""
128 : "with message: " + message);
129 }
130 }
131
132
133
134
135
136
137
138
139 public static String generate(final Collection<ProvisioningReport> results, final TraceLevel level) {
140 StringBuilder sb = new StringBuilder();
141 results.forEach(result -> sb.append(result.getReportString(level)).append('\n'));
142 return sb.toString();
143 }
144
145 @Override
146 public String toString() {
147 return new ToStringBuilder(this).
148 append(message).
149 append(status).
150 append(anyType).
151 append(operation).
152 append(key).
153 append(name).
154 append(uidValue).
155 build();
156 }
157 }