Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ARSnova Backend
Manage
Activity
Members
Labels
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Privacy
Imprint
Contact
Snippets
Groups
Projects
Show more breadcrumbs
Paul-Christian Volkmer
ARSnova Backend
Commits
4437659f
Commit
4437659f
authored
11 years ago
by
Christoph Thelen
Browse files
Options
Downloads
Patches
Plain Diff
Added number support for keys
parent
11c58140
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/main/java/de/thm/arsnova/dao/NovaView.java
+20
-3
20 additions, 3 deletions
src/main/java/de/thm/arsnova/dao/NovaView.java
src/test/java/de/thm/arsnova/dao/NovaViewTest.java
+24
-0
24 additions, 0 deletions
src/test/java/de/thm/arsnova/dao/NovaViewTest.java
with
44 additions
and
3 deletions
src/main/java/de/thm/arsnova/dao/NovaView.java
+
20
−
3
View file @
4437659f
...
...
@@ -35,7 +35,11 @@ public class NovaView extends View {
}
public
void
setStartKeyArray
(
String
key
)
{
this
.
startKey
=
encode
(
"[\""
+
key
+
"\"]"
);
if
(
isNumber
(
key
))
{
this
.
startKey
=
encode
(
"["
+
key
+
"]"
);
}
else
{
this
.
startKey
=
encode
(
"[\""
+
key
+
"\"]"
);
}
}
public
void
setStartKeyArray
(
String
...
keys
)
{
...
...
@@ -48,7 +52,11 @@ public class NovaView extends View {
}
public
void
setEndKeyArray
(
String
key
)
{
this
.
endKey
=
encode
(
"[\""
+
key
+
"\"]"
);
if
(
isNumber
(
key
))
{
this
.
endKey
=
encode
(
"["
+
key
+
"]"
);
}
else
{
this
.
endKey
=
encode
(
"[\""
+
key
+
"\"]"
);
}
}
public
void
setEndKeyArray
(
String
...
keys
)
{
...
...
@@ -75,7 +83,9 @@ public class NovaView extends View {
private
String
toJsonArray
(
String
[]
strings
)
{
StringBuilder
sb
=
new
StringBuilder
();
for
(
String
str
:
strings
)
{
if
(
str
.
equals
(
"{}"
))
{
if
(
isNumber
(
str
))
{
sb
.
append
(
str
+
","
);
}
else
if
(
str
.
equals
(
"{}"
))
{
sb
.
append
(
str
+
","
);
}
else
{
sb
.
append
(
"\""
+
str
+
"\""
+
","
);
...
...
@@ -88,8 +98,15 @@ public class NovaView extends View {
}
private
String
quote
(
String
string
)
{
if
(
isNumber
(
string
))
{
return
encode
(
string
);
}
return
encode
(
"\""
+
string
+
"\""
);
}
private
boolean
isNumber
(
String
string
)
{
return
string
.
matches
(
"^[0-9]+$"
);
}
private
String
encode
(
String
string
)
{
try
{
...
...
This diff is collapsed.
Click to expand it.
src/test/java/de/thm/arsnova/dao/NovaViewTest.java
+
24
−
0
View file @
4437659f
...
...
@@ -90,6 +90,30 @@ public class NovaViewTest {
assertEncodedEquals
(
"key"
,
"[\"foo\",\"bar\",{}]"
,
v
.
getQueryString
());
}
@Test
public
void
arrayKeysShouldNotEnquoteNumbers
()
{
NovaView
v
=
new
NovaView
(
null
);
v
.
setKey
(
"foo"
,
"bar"
,
"2"
);
assertEncodedEquals
(
"key"
,
"[\"foo\",\"bar\",2]"
,
v
.
getQueryString
());
}
@Test
public
void
singleKeysShouldNotEnquoteNumbers
()
{
NovaView
v
=
new
NovaView
(
null
);
v
.
setKey
(
"2"
);
assertEncodedEquals
(
"key"
,
"2"
,
v
.
getQueryString
());
}
@Test
public
void
singleArrayKeysShouldNotEnquoteNumbers
()
{
NovaView
v1
=
new
NovaView
(
null
);
NovaView
v2
=
new
NovaView
(
null
);
v1
.
setStartKeyArray
(
"2"
);
v2
.
setEndKeyArray
(
"2"
);
assertEncodedEquals
(
"startkey"
,
"[2]"
,
v1
.
getQueryString
());
assertEncodedEquals
(
"endkey"
,
"[2]"
,
v2
.
getQueryString
());
}
private
void
assertEncodedEquals
(
String
key
,
String
expected
,
String
actual
)
{
try
{
assertEquals
(
key
+
"="
+
URLEncoder
.
encode
(
expected
,
"UTF-8"
),
actual
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
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