BookmarkResource: Fix user feed IDs and links.
Change-Id: If5238caf54334f6ac47eeefae04f2134dc4de856
diff --git a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java
index 45eeb2e..12abb2b 100644
--- a/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java
+++ b/src/main/java/eu/mulk/mulkcms2/benki/bookmarks/BookmarkResource.java
@@ -100,6 +100,7 @@
var bookmarkQuery = selectBookmarks(null);
return bookmarkList
.data("bookmarks", bookmarkQuery)
+ .data("feedUri", "/bookmarks/feed")
.data("authenticated", !identity.isAnonymous());
}
@@ -111,14 +112,15 @@
var bookmarkQuery = selectBookmarks(owner);
return bookmarkList
.data("bookmarks", bookmarkQuery)
+ .data("feedUri", String.format("/bookmarks/~%s/feed", ownerName))
.data("authenticated", !identity.isAnonymous());
}
@GET
@Path("feed")
@Produces(APPLICATION_ATOM_XML)
- public String getFeed(@Nullable User owner) throws FeedException {
- return makeFeed(null);
+ public String getFeed() throws FeedException {
+ return makeFeed(null, null);
}
@GET
@@ -126,18 +128,22 @@
@Produces(APPLICATION_ATOM_XML)
public String getUserFeed(@PathParam("ownerName") String ownerName) throws FeedException {
var owner = User.findByNickname(ownerName);
- return makeFeed(owner);
+ return makeFeed(owner, ownerName);
}
- private String makeFeed(@Nullable User owner) throws FeedException {
+ private String makeFeed(@Nullable User owner, @Nullable String ownerName) throws FeedException {
var bookmarks = selectBookmarks(owner);
var feed = new Feed("atom_1.0");
+ var feedSubId = owner == null ? "" : String.format("/%d", owner.id);
+
feed.setTitle("Book Marx");
feed.setId(
String.format(
- "tag:%s,2019:marx:%s",
- tagBase, identity.isAnonymous() ? "world" : identity.getPrincipal().getName()));
+ "tag:%s,2019:marx%s:%s",
+ tagBase,
+ feedSubId,
+ identity.isAnonymous() ? "world" : identity.getPrincipal().getName()));
feed.setUpdated(
Date.from(
bookmarks.stream()
@@ -152,7 +158,8 @@
feed.setOtherLinks(List.of(selfLink));
var htmlAltLink = new Link();
- htmlAltLink.setHref(uri.resolve(URI.create("/bookmarks")).toString());
+ var htmlAltPath = owner == null ? "/bookmarks" : String.format("~%s/bookmarks", ownerName);
+ htmlAltLink.setHref(uri.resolve(URI.create(htmlAltPath)).toString());
htmlAltLink.setRel("alternate");
htmlAltLink.setType("text/html");
feed.setAlternateLinks(List.of(htmlAltLink));
diff --git a/src/main/resources/templates/benki/bookmarks/bookmarkList.html b/src/main/resources/templates/benki/bookmarks/bookmarkList.html
index 7d23d45..9b5025c 100644
--- a/src/main/resources/templates/benki/bookmarks/bookmarkList.html
+++ b/src/main/resources/templates/benki/bookmarks/bookmarkList.html
@@ -8,7 +8,7 @@
{#bookmarksClass}this-page{/bookmarksClass}
{#head}
- <link href="/bookmarks/feed" rel="alternate" type="application/atom+xml" />
+ <link href="{feedUri}" rel="alternate" type="application/atom+xml" />
{/head}
{#body}