6
6
7
7
interface IUserInQueueService {
8
8
9
- RequestValidationResult validateRequest (
9
+ RequestValidationResult validateQueueRequest (
10
10
String targetUrl ,
11
11
String queueitToken ,
12
- EventConfig config ,
12
+ QueueEventConfig config ,
13
13
String customerId ,
14
14
String secretKey ) throws Exception ;
15
15
16
- void cancelQueueCookie (String eventId , String cookieDomain );
17
-
16
+ RequestValidationResult validateCancelRequest (
17
+ String targetUrl ,
18
+ CancelEventConfig config ,
19
+ String customerId ,
20
+ String secretKey ) throws Exception ;
21
+
18
22
void extendQueueCookie (
19
23
String eventId ,
20
24
int cookieValidityMinute ,
@@ -25,7 +29,7 @@ void extendQueueCookie(
25
29
26
30
class UserInQueueService implements IUserInQueueService {
27
31
28
- public static final String SDK_VERSION = "1.0.0 .0" ;
32
+ public static final String SDK_VERSION = "3.2 .0" ;
29
33
private final IUserInQueueStateRepository _userInQueueStateRepository ;
30
34
31
35
public UserInQueueService (
@@ -34,10 +38,10 @@ public UserInQueueService(
34
38
}
35
39
36
40
@ Override
37
- public RequestValidationResult validateRequest (
41
+ public RequestValidationResult validateQueueRequest (
38
42
String targetUrl ,
39
43
String queueitToken ,
40
- EventConfig config ,
44
+ QueueEventConfig config ,
41
45
String customerId ,
42
46
String secretKey
43
47
) throws Exception {
@@ -51,7 +55,7 @@ public RequestValidationResult validateRequest(
51
55
config .getCookieValidityMinute (),
52
56
secretKey );
53
57
}
54
- return new RequestValidationResult (config .getEventId (), stateInfo .getQueueId (), null );
58
+ return new RequestValidationResult (ActionType . QUEUE_ACTION , config .getEventId (), stateInfo .getQueueId (), null );
55
59
}
56
60
57
61
QueueUrlParams queueParmas = QueueParameterHelper .extractQueueParams (queueitToken );
@@ -66,7 +70,7 @@ public RequestValidationResult validateRequest(
66
70
private RequestValidationResult getQueueITTokenValidationResult (
67
71
String targetUrl ,
68
72
String eventId ,
69
- EventConfig config ,
73
+ QueueEventConfig config ,
70
74
QueueUrlParams queueParams ,
71
75
String customerId ,
72
76
String secretKey ) throws Exception {
@@ -91,17 +95,17 @@ private RequestValidationResult getQueueITTokenValidationResult(
91
95
queueParams .getCookieValidityMinute () != null ? queueParams .getCookieValidityMinute () : config .getCookieValidityMinute (),
92
96
secretKey );
93
97
94
- return new RequestValidationResult (config .getEventId (), queueParams .getQueueId (), null );
98
+ return new RequestValidationResult (ActionType . QUEUE_ACTION , config .getEventId (), queueParams .getQueueId (), null );
95
99
}
96
100
97
101
private RequestValidationResult getVaidationErrorResult (
98
102
String customerId ,
99
103
String targetUrl ,
100
- EventConfig config ,
104
+ QueueEventConfig config ,
101
105
QueueUrlParams qParams ,
102
106
String errorCode ) throws Exception {
103
107
104
- String query = getQueryString (customerId , config )
108
+ String query = getQueryString (customerId , config . getEventId (), config . getVersion (), config . getCulture (), config . getLayoutName () )
105
109
+ "&queueittoken=" + qParams .getQueueITToken ()
106
110
+ "&ts=" + System .currentTimeMillis () / 1000L ;
107
111
if (!Utils .isNullOrWhiteSpace (targetUrl ))
@@ -113,49 +117,46 @@ private RequestValidationResult getVaidationErrorResult(
113
117
domainAlias = domainAlias + "/" ;
114
118
}
115
119
String redirectUrl = "https://" + domainAlias + "error/" + errorCode + "?" + query ;
116
- return new RequestValidationResult (config .getEventId (), null , redirectUrl );
120
+ return new RequestValidationResult (ActionType . QUEUE_ACTION , config .getEventId (), null , redirectUrl );
117
121
}
118
122
119
123
private RequestValidationResult getInQueueRedirectResult (
120
124
String targetUrl ,
121
- EventConfig config ,
125
+ QueueEventConfig config ,
122
126
String customerId ) throws Exception {
123
127
124
128
String redirectUrl = "https://" + config .getQueueDomain () + "?"
125
- + getQueryString (customerId , config );
126
- if (!Utils .isNullOrWhiteSpace (targetUrl ))
127
- {
129
+ + getQueryString (customerId , config .getEventId (), config .getVersion (), config .getCulture (), config .getLayoutName ());
130
+ if (!Utils .isNullOrWhiteSpace (targetUrl )) {
128
131
redirectUrl += "&t=" + URLEncoder .encode (targetUrl , "UTF-8" );
129
132
}
130
133
131
- return new RequestValidationResult (config .getEventId (), null , redirectUrl );
134
+ return new RequestValidationResult (ActionType . QUEUE_ACTION , config .getEventId (), null , redirectUrl );
132
135
}
133
136
134
137
private String getQueryString (
135
138
String customerId ,
136
- EventConfig config ) throws Exception {
139
+ String eventId ,
140
+ int configVersion ,
141
+ String culture ,
142
+ String layoutName ) throws Exception {
137
143
ArrayList <String > queryStringList = new ArrayList <>();
138
144
queryStringList .add ("c=" + URLEncoder .encode (customerId , "UTF-8" ));
139
- queryStringList .add ("e=" + URLEncoder .encode (config . getEventId () , "UTF-8" ));
145
+ queryStringList .add ("e=" + URLEncoder .encode (eventId , "UTF-8" ));
140
146
queryStringList .add ("ver=v3-java-" + URLEncoder .encode (SDK_VERSION , "UTF-8" ));
141
- queryStringList .add ("cver=" + URLEncoder .encode (String .valueOf (config . getVersion () ), "UTF-8" ));
147
+ queryStringList .add ("cver=" + URLEncoder .encode (String .valueOf (configVersion ), "UTF-8" ));
142
148
143
- if (!Utils .isNullOrWhiteSpace (config . getCulture () )) {
144
- queryStringList .add ("cid=" + URLEncoder .encode (config . getCulture () , "UTF-8" ));
149
+ if (!Utils .isNullOrWhiteSpace (culture )) {
150
+ queryStringList .add ("cid=" + URLEncoder .encode (culture , "UTF-8" ));
145
151
}
146
152
147
- if (!Utils .isNullOrWhiteSpace (config . getLayoutName () )) {
148
- queryStringList .add ("l=" + URLEncoder .encode (config . getLayoutName () , "UTF-8" ));
153
+ if (!Utils .isNullOrWhiteSpace (layoutName )) {
154
+ queryStringList .add ("l=" + URLEncoder .encode (layoutName , "UTF-8" ));
149
155
}
150
156
151
157
return String .join ("&" , queryStringList );
152
158
}
153
-
154
- @ Override
155
- public void cancelQueueCookie (String eventId , String cookieDomain ) {
156
- this ._userInQueueStateRepository .cancelQueueCookie (eventId , cookieDomain );
157
- }
158
-
159
+
159
160
@ Override
160
161
public void extendQueueCookie (
161
162
String eventId ,
@@ -164,4 +165,32 @@ public void extendQueueCookie(
164
165
String secretKey ) {
165
166
this ._userInQueueStateRepository .extendQueueCookie (eventId , cookieValidityMinute , cookieDomain , secretKey );
166
167
}
168
+
169
+ @ Override
170
+ public RequestValidationResult validateCancelRequest (
171
+ String targetUrl , CancelEventConfig config , String customerId , String secretKey ) throws Exception {
172
+
173
+ StateInfo state = _userInQueueStateRepository .getState (config .getEventId (), secretKey );
174
+
175
+ if (state .isValid ()) {
176
+ this ._userInQueueStateRepository .cancelQueueCookie (config .getEventId (), config .getCookieDomain ());
177
+
178
+ String query = getQueryString (customerId , config .getEventId (), config .getVersion (), null , null );
179
+
180
+ if (targetUrl != null )
181
+ query += "&r=" + URLEncoder .encode (targetUrl , "UTF-8" );
182
+
183
+ String domainAlias = config .getQueueDomain ();
184
+ if (!domainAlias .endsWith ("/" ))
185
+ domainAlias = domainAlias + "/" ;
186
+
187
+ String redirectUrl = "https://" + domainAlias + "cancel/" + customerId + "/" + config .getEventId () + "/?" + query ;
188
+
189
+ return new RequestValidationResult (ActionType .CANCEL_ACTION , config .getEventId (), state .getQueueId (), redirectUrl );
190
+ }
191
+ else
192
+ {
193
+ return new RequestValidationResult (ActionType .CANCEL_ACTION , config .getEventId (), null , null );
194
+ }
195
+ }
167
196
}
0 commit comments