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
786ff5ef
There was an error fetching the commit references. Please try again later.
Commit
786ff5ef
authored
10 years ago
by
Christoph Thelen
Browse files
Options
Downloads
Patches
Plain Diff
Add support for querying stale views
parent
3fd3b41f
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
-0
20 additions, 0 deletions
src/main/java/de/thm/arsnova/dao/NovaView.java
src/test/java/de/thm/arsnova/dao/NovaViewTest.java
+18
-2
18 additions, 2 deletions
src/test/java/de/thm/arsnova/dao/NovaViewTest.java
with
38 additions
and
2 deletions
src/main/java/de/thm/arsnova/dao/NovaView.java
+
20
−
0
View file @
786ff5ef
...
@@ -28,8 +28,14 @@ import com.fourspaces.couchdb.View;
...
@@ -28,8 +28,14 @@ import com.fourspaces.couchdb.View;
public
class
NovaView
extends
View
{
public
class
NovaView
extends
View
{
public
enum
StaleMode
{
NONE
,
OK
,
UPDATE_AFTER
}
protected
String
keys
;
protected
String
keys
;
protected
StaleMode
stale
=
StaleMode
.
NONE
;
public
NovaView
(
final
String
fullname
)
{
public
NovaView
(
final
String
fullname
)
{
super
(
fullname
);
super
(
fullname
);
}
}
...
@@ -89,6 +95,10 @@ public class NovaView extends View {
...
@@ -89,6 +95,10 @@ public class NovaView extends View {
this
.
keys
=
toJsonArray
(
keys
.
toArray
(
new
String
[
keys
.
size
()]));
this
.
keys
=
toJsonArray
(
keys
.
toArray
(
new
String
[
keys
.
size
()]));
}
}
public
void
setStale
(
StaleMode
stale
)
{
this
.
stale
=
stale
;
}
@Override
@Override
public
String
getQueryString
()
{
public
String
getQueryString
()
{
final
String
tempQuery
=
super
.
getQueryString
();
final
String
tempQuery
=
super
.
getQueryString
();
...
@@ -102,6 +112,16 @@ public class NovaView extends View {
...
@@ -102,6 +112,16 @@ public class NovaView extends View {
}
}
query
.
append
(
"keys="
+
keys
);
query
.
append
(
"keys="
+
keys
);
}
}
if
(
stale
!=
null
&&
stale
!=
StaleMode
.
NONE
)
{
if
(
query
.
length
()
>
0
)
{
query
.
append
(
"&"
);
}
if
(
stale
==
StaleMode
.
OK
)
{
query
.
append
(
"stale=ok"
);
}
else
if
(
stale
==
StaleMode
.
UPDATE_AFTER
)
{
query
.
append
(
"stale=update_after"
);
}
}
if
(
query
.
length
()
==
0
)
{
if
(
query
.
length
()
==
0
)
{
return
null
;
return
null
;
...
...
This diff is collapsed.
Click to expand it.
src/test/java/de/thm/arsnova/dao/NovaViewTest.java
+
18
−
2
View file @
786ff5ef
...
@@ -18,8 +18,7 @@
...
@@ -18,8 +18,7 @@
*/
*/
package
de.thm.arsnova.dao
;
package
de.thm.arsnova.dao
;
import
static
org
.
junit
.
Assert
.
assertEquals
;
import
static
org
.
junit
.
Assert
.*;
import
static
org
.
junit
.
Assert
.
fail
;
import
java.io.UnsupportedEncodingException
;
import
java.io.UnsupportedEncodingException
;
import
java.net.URLEncoder
;
import
java.net.URLEncoder
;
...
@@ -27,6 +26,8 @@ import java.util.Arrays;
...
@@ -27,6 +26,8 @@ import java.util.Arrays;
import
org.junit.Test
;
import
org.junit.Test
;
import
de.thm.arsnova.dao.NovaView.StaleMode
;
public
class
NovaViewTest
{
public
class
NovaViewTest
{
@Test
@Test
...
@@ -133,6 +134,21 @@ public class NovaViewTest {
...
@@ -133,6 +134,21 @@ public class NovaViewTest {
assertEncodedEquals
(
"keys"
,
"[]"
,
v5
.
getQueryString
());
assertEncodedEquals
(
"keys"
,
"[]"
,
v5
.
getQueryString
());
}
}
@Test
public
void
shouldSupportStaleViews
()
{
final
NovaView
v1
=
new
NovaView
(
null
);
final
NovaView
v2
=
new
NovaView
(
null
);
final
NovaView
v3
=
new
NovaView
(
null
);
final
NovaView
v4
=
new
NovaView
(
null
);
v1
.
setStale
(
StaleMode
.
NONE
);
v2
.
setStale
(
StaleMode
.
OK
);
v3
.
setStale
(
StaleMode
.
UPDATE_AFTER
);
assertNull
(
v1
.
getQueryString
());
assertEncodedEquals
(
"stale"
,
"ok"
,
v2
.
getQueryString
());
assertEncodedEquals
(
"stale"
,
"update_after"
,
v3
.
getQueryString
());
assertNull
(
v4
.
getQueryString
());
}
private
void
assertEncodedEquals
(
final
String
key
,
final
String
expected
,
final
String
actual
)
{
private
void
assertEncodedEquals
(
final
String
key
,
final
String
expected
,
final
String
actual
)
{
try
{
try
{
assertEquals
(
key
+
"="
+
URLEncoder
.
encode
(
expected
,
"UTF-8"
),
actual
);
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