1
|
package eu.dnetlib.uoaadmintoolslibrary.entities.email;
|
2
|
|
3
|
import com.fasterxml.jackson.annotation.*;
|
4
|
|
5
|
import java.util.HashMap;
|
6
|
import java.util.Map;
|
7
|
|
8
|
@JsonInclude(JsonInclude.Include.NON_NULL)
|
9
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
10
|
@JsonPropertyOrder({
|
11
|
"success",
|
12
|
"challenge_ts",
|
13
|
"hostname",
|
14
|
"error-codes"
|
15
|
})
|
16
|
public class GoogleResponse {
|
17
|
|
18
|
@JsonProperty("success")
|
19
|
private boolean success;
|
20
|
|
21
|
@JsonProperty("challenge_ts")
|
22
|
private String challengeTs;
|
23
|
|
24
|
@JsonProperty("hostname")
|
25
|
private String hostname;
|
26
|
|
27
|
@JsonProperty("error-codes")
|
28
|
private ErrorCode[] errorCodes;
|
29
|
|
30
|
@JsonIgnore
|
31
|
public boolean hasClientError() {
|
32
|
ErrorCode[] errors = getErrorCodes();
|
33
|
if(errors == null) {
|
34
|
return false;
|
35
|
}
|
36
|
for(ErrorCode error : errors) {
|
37
|
switch(error) {
|
38
|
case InvalidResponse:
|
39
|
case MissingResponse:
|
40
|
return true;
|
41
|
}
|
42
|
}
|
43
|
return false;
|
44
|
}
|
45
|
|
46
|
static enum ErrorCode {
|
47
|
MissingSecret, InvalidSecret,
|
48
|
MissingResponse, InvalidResponse;
|
49
|
|
50
|
private static Map<String, ErrorCode> errorsMap = new HashMap<>(4);
|
51
|
|
52
|
static {
|
53
|
errorsMap.put("missing-input-secret", MissingSecret);
|
54
|
errorsMap.put("invalid-input-secret", InvalidSecret);
|
55
|
errorsMap.put("missing-input-response", MissingResponse);
|
56
|
errorsMap.put("invalid-input-response", InvalidResponse);
|
57
|
}
|
58
|
|
59
|
@JsonCreator
|
60
|
public static ErrorCode forValue(String value) {
|
61
|
return errorsMap.get(value.toLowerCase());
|
62
|
}
|
63
|
}
|
64
|
|
65
|
public boolean isSuccess() {
|
66
|
return success;
|
67
|
}
|
68
|
|
69
|
public void setSuccess(boolean success) {
|
70
|
this.success = success;
|
71
|
}
|
72
|
|
73
|
public String getChallengeTs() {
|
74
|
return challengeTs;
|
75
|
}
|
76
|
|
77
|
public void setChallengeTs(String challengeTs) {
|
78
|
this.challengeTs = challengeTs;
|
79
|
}
|
80
|
|
81
|
public String getHostname() {
|
82
|
return hostname;
|
83
|
}
|
84
|
|
85
|
public void setHostname(String hostname) {
|
86
|
this.hostname = hostname;
|
87
|
}
|
88
|
|
89
|
public ErrorCode[] getErrorCodes() {
|
90
|
return errorCodes;
|
91
|
}
|
92
|
|
93
|
public void setErrorCodes(ErrorCode[] errorCodes) {
|
94
|
this.errorCodes = errorCodes;
|
95
|
}
|
96
|
}
|