Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
todo-list-example
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
IT1901
todo-list-example
Commits
691ddae9
Commit
691ddae9
authored
2 years ago
by
George Adrian Stoica
Browse files
Options
Downloads
Patches
Plain Diff
refactor: moves duplicated string literals to constants
parent
8dddc5b7
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
todolist/fxui/src/main/java/todolist/ui/RemoteTodoModelAccess.java
+16
-8
16 additions, 8 deletions
...fxui/src/main/java/todolist/ui/RemoteTodoModelAccess.java
with
16 additions
and
8 deletions
todolist/fxui/src/main/java/todolist/ui/RemoteTodoModelAccess.java
+
16
−
8
View file @
691ddae9
...
...
@@ -25,6 +25,14 @@ public class RemoteTodoModelAccess implements TodoModelAccess {
private
final
URI
endpointBaseUri
;
private
static
final
String
APPLICATION_JSON
=
"application/json"
;
private
static
final
String
APPLICATION_FORM_URLENCODED
=
"application/x-www-form-urlencoded"
;
private
static
final
String
ACCEPT_HEADER
=
"Accept"
;
private
static
final
String
CONTENT_TYPE_HEADER
=
"Content-Type"
;
private
ObjectMapper
objectMapper
;
private
TodoModel
todoModel
;
...
...
@@ -37,7 +45,7 @@ public class RemoteTodoModelAccess implements TodoModelAccess {
private
TodoModel
getTodoModel
()
{
if
(
todoModel
==
null
)
{
HttpRequest
request
=
HttpRequest
.
newBuilder
(
endpointBaseUri
)
.
header
(
"Accept"
,
"application/json"
)
.
header
(
ACCEPT_HEADER
,
APPLICATION_JSON
)
.
GET
()
.
build
();
try
{
...
...
@@ -63,7 +71,7 @@ public class RemoteTodoModelAccess implements TodoModelAccess {
TodoSettings
settings
=
todoModel
.
getSettings
();
if
(
isDefaultSettings
(
settings
))
{
HttpRequest
request
=
HttpRequest
.
newBuilder
(
endpointBaseUri
.
resolve
(
"settings"
))
.
header
(
"Accept"
,
"application/json"
)
.
header
(
ACCEPT_HEADER
,
APPLICATION_JSON
)
.
GET
()
.
build
();
try
{
...
...
@@ -135,7 +143,7 @@ public class RemoteTodoModelAccess implements TodoModelAccess {
if
(
oldTodoList
==
null
||
(!
(
oldTodoList
instanceof
TodoList
)))
{
HttpRequest
request
=
HttpRequest
.
newBuilder
(
todoListUri
(
name
))
.
header
(
"Accept"
,
"application/json"
).
GET
().
build
();
.
header
(
ACCEPT_HEADER
,
APPLICATION_JSON
).
GET
().
build
();
try
{
final
HttpResponse
<
String
>
response
=
HttpClient
.
newBuilder
().
build
().
send
(
request
,
HttpResponse
.
BodyHandlers
.
ofString
());
...
...
@@ -159,8 +167,8 @@ public class RemoteTodoModelAccess implements TodoModelAccess {
try
{
String
json
=
objectMapper
.
writeValueAsString
(
todoList
);
HttpRequest
request
=
HttpRequest
.
newBuilder
(
todoListUri
(
todoList
.
getName
()))
.
header
(
"Accept"
,
"application/json"
)
.
header
(
"Content-Type"
,
"application/json"
)
.
header
(
ACCEPT_HEADER
,
APPLICATION_JSON
)
.
header
(
CONTENT_TYPE_HEADER
,
APPLICATION_JSON
)
.
PUT
(
BodyPublishers
.
ofString
(
json
))
.
build
();
final
HttpResponse
<
String
>
response
=
...
...
@@ -194,7 +202,7 @@ public class RemoteTodoModelAccess implements TodoModelAccess {
public
void
removeTodoList
(
String
name
)
{
try
{
HttpRequest
request
=
HttpRequest
.
newBuilder
(
todoListUri
(
name
))
.
header
(
"Accept"
,
"application/json"
)
.
header
(
ACCEPT_HEADER
,
APPLICATION_JSON
)
.
DELETE
()
.
build
();
final
HttpResponse
<
String
>
response
=
...
...
@@ -219,8 +227,8 @@ public class RemoteTodoModelAccess implements TodoModelAccess {
public
void
renameTodoList
(
String
oldName
,
String
newName
)
{
try
{
HttpRequest
request
=
HttpRequest
.
newBuilder
(
todoListUri
(
oldName
))
.
header
(
"Accept"
,
"application/json"
)
.
header
(
"Content-Type"
,
"application/x-www-form-urlencoded"
)
.
header
(
ACCEPT_HEADER
,
APPLICATION_JSON
)
.
header
(
CONTENT_TYPE_HEADER
,
APPLICATION_FORM_URLENCODED
)
.
POST
(
BodyPublishers
.
ofString
(
"newName="
+
uriParam
(
newName
)))
.
build
();
final
HttpResponse
<
String
>
response
=
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment