FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
openapi-java-migration/examples/SearchCannedResponsesByKey.java at main · unblu/openapi-java-migration · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
unblu
/
openapi-java-migration
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
openapi-java-migration
/
examples
/
SearchCannedResponsesByKey.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
83 lines (68 loc) · 3.83 KB
Breadcrumbs
openapi-java-migration
/
examples
/
SearchCannedResponsesByKey.java
Copy path
File metadata and controls
executable file
·
83 lines (68 loc) · 3.83 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
///usr/bin/env jbang "$0" "$@" ; exit $?
//JAVA 11
//DEPS com.unblu.openapi:jersey3-client-v4:8.2.0
//SOURCES Util.java
/*
* Creates a canned response, searches the canned responses on the 'key' field, then
* deletes it again.
*
* Targets the findings of revapi/8.2.0_8.3.1/models-v4:
*
* java.class.removed class KeyCannedResponseSearchFilter
* java.field.removed field ECannedResponseSearchFilterField.KEY
*
* Searching canned responses on their 'key' was dropped in 8.3.1: the dedicated filter
* class and the enum constant selecting that field were both removed. Note that the
* CannedResponse model of 8.2.0 has no 'key' property at all, so this filter could
* never match anything. This example compiles against 8.2.0 and no longer compiles when
* the dependency above is changed to 8.3.1.
*
* Usage:
* ./SearchCannedResponsesByKey.java <server> --admin <username> --password <password>
*/
import
java
.
util
.
List
;
import
com
.
unblu
.
webapi
.
jersey
.
v4
.
V4ApiUtil
;
import
com
.
unblu
.
webapi
.
jersey
.
v4
.
api
.
AuthenticatorApi
;
import
com
.
unblu
.
webapi
.
jersey
.
v4
.
api
.
CannedResponsesApi
;
import
com
.
unblu
.
webapi
.
jersey
.
v4
.
invoker
.
ApiClient
;
import
com
.
unblu
.
webapi
.
model
.
v4
.
CannedResponse
;
import
com
.
unblu
.
webapi
.
model
.
v4
.
CannedResponseQuery
;
import
com
.
unblu
.
webapi
.
model
.
v4
.
CannedResponseResult
;
import
com
.
unblu
.
webapi
.
model
.
v4
.
ECannedResponseSearchFilterField
;
import
com
.
unblu
.
webapi
.
model
.
v4
.
EPropertyOwnerType
;
import
com
.
unblu
.
webapi
.
model
.
v4
.
EqualsStringOperator
;
import
com
.
unblu
.
webapi
.
model
.
v4
.
KeyCannedResponseSearchFilter
;
import
com
.
unblu
.
webapi
.
model
.
v4
.
PersonData
;
public
class
SearchCannedResponsesByKey
{
private
static
final
String
SCRIPT_NAME
=
"SearchCannedResponsesByKey.java"
;
public
static
void
main
(
String
[]
args
)
throws
Exception
{
Util
arguments
=
Util
.
parseAdminArgs
(
args
,
SCRIPT_NAME
);
ApiClient
client
=
V4ApiUtil
.
getWithBasicAuth
(
arguments
.
getServerUrl
(),
arguments
.
getUsername
(),
arguments
.
getPassword
());
Util
.
applyRecommendedDeserialization
(
client
.
getJSON
().
getContext
(
null
));
AuthenticatorApi
authenticatorApi
=
new
AuthenticatorApi
(
client
);
CannedResponsesApi
cannedResponsesApi
=
new
CannedResponsesApi
(
client
);
PersonData
currentPerson
=
authenticatorApi
.
authenticatorGetCurrentPerson
(
null
);
String
key
=
"example-greeting-"
+
Util
.
randomSuffix
();
CannedResponse
cannedResponse
=
new
CannedResponse
();
cannedResponse
.
setTitle
(
"Greeting "
+
key
);
cannedResponse
.
setText
(
"Welcome to the Example Company support desk."
);
cannedResponse
.
setOwnerId
(
currentPerson
.
getAccountId
());
cannedResponse
.
setOwnerType
(
EPropertyOwnerType
.
ACCOUNT
);
CannedResponse
createdCannedResponse
=
cannedResponsesApi
.
cannedResponsesCreate
(
cannedResponse
);
System
.
out
.
println
(
"Created canned response '"
+
createdCannedResponse
.
getTitle
() +
"' with id '"
+
createdCannedResponse
.
getId
() +
"'"
);
// Both the filter and the enum constant it uses were removed in 8.3.1.
KeyCannedResponseSearchFilter
filter
=
new
KeyCannedResponseSearchFilter
()
.
field
(
ECannedResponseSearchFilterField
.
KEY
)
.
operator
(
new
EqualsStringOperator
().
value
(
key
));
CannedResponseQuery
query
=
new
CannedResponseQuery
()
.
addSearchFiltersItem
(
filter
);
CannedResponseResult
result
=
cannedResponsesApi
.
cannedResponsesSearch
(
query
);
List
<
CannedResponse
>
found
=
result
.
getItems
();
System
.
out
.
println
(
"Search by key '"
+
key
+
"' returned "
+
found
.
size
() +
" canned response(s)"
);
for
(
CannedResponse
item
:
found
) {
System
.
out
.
println
(
"- '"
+
item
.
getTitle
() +
"': "
+
item
.
getText
());
}
cannedResponsesApi
.
cannedResponsesDelete
(
createdCannedResponse
.
getId
());
System
.
out
.
println
(
"Deleted canned response '"
+
createdCannedResponse
.
getId
() +
"'"
);
}
}
Back
|
FazBrowse Home
|
New Git URL