Skip to content

Scope authoring resource lookups to the action weblog - #162

Open
snoopdave wants to merge 1 commit into
masterfrom
authoring-resource-scoping
Open

Scope authoring resource lookups to the action weblog#162
snoopdave wants to merge 1 commit into
masterfrom
authoring-resource-scoping

Conversation

@snoopdave

@snoopdave snoopdave commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Summary

Roller's manager APIs expose two styles of lookup: by id, and by a weblog plus
some other key — getTemplateByLink(Weblog, String),
getTemplateByName(Weblog, String) and friends. The authoring UI operates in
the context of a single weblog throughout, but has only the id-based form
available for several resource types, so the two styles are mixed within the
same action.

This adds weblog-scoped overloads beside the existing id-based lookups and
points the authoring actions at them, so the lookups an action performs are
consistently expressed in terms of the weblog it is working on. The new
methods follow the shape of the existing getTemplateByLink(Weblog, String)
rather than introducing a different convention.

Manager methods added

Manager Method Named query
WeblogManager getTemplate(Weblog, String) WeblogTemplate.getByWeblog&Id
WeblogEntryManager getWeblogEntry(Weblog, String) WeblogEntry.getByWebsite&Id
WeblogEntryManager getWeblogCategory(Weblog, String) WeblogCategory.getByWeblog&Id
WeblogEntryManager getComment(Weblog, String) WeblogEntryComment.getByWebsite&Id
BookmarkManager getBookmark(Weblog, String) WeblogBookmark.getByWebsite&Id
BookmarkManager getFolderById(Weblog, String) WeblogBookmarkFolder.getByWebsite&Id
MediaFileManager getMediaFile(Weblog, String) MediaFile.getByWeblogAndId
MediaFileManager getMediaFileDirectory(Weblog, String) MediaFileDirectory.getByWeblogAndId

Each is backed by a named query filtering on the owning weblog, and returns
null when there is no match.

The folder lookup is named getFolderById rather than being an overload:
getFolder(Weblog, String) already exists as the by-name lookup, and the two
would otherwise share an erasure.

Call sites

Updated across templates, entries, categories, comments, bookmarks, folders
and media files in ui/struts2/editor/. The action weblog is resolved by the
interceptor stack (params -> UIActionInterceptor -> UISecurityInterceptor
-> UIActionPrepareInterceptor) before myPrepare() runs, so
getActionWeblog() is available at each of these call sites without
reordering anything.

The two comment loops in Comments previously compared the weblog after
loading; they now use the scoped lookup instead, which also removes an NPE on
ids with no match.

Not changed

RollerResourceLoader and GlobalCommentManagement have no single weblog in
context by design and keep the id-based lookups. EntryBean,
StylesheetEdit, CommentDataServlet and the XML-RPC and Atom handlers reach
their weblog by other means and were left alone.

Tests

  • business/WeblogScopedLookupTest — manager layer, covering each new overload
  • ui/struts2/editor/TemplateEditScopingTest — action layer
  • ui/struts2/editor/AuthoringActionScopingTest — action layer, covering
    EntryRemove, EntryEdit, CategoryRemove and BookmarkEdit

Full suite on JDK 11: 182 run, 0 failures, 0 errors, 1 skipped.

Authoring actions resolve the resource named by a request parameter by id
alone, independently of the weblog the action is operating on. Add
weblog-scoped lookups beside the existing unscoped ones, modelled on
getTemplateByLink(Weblog, String), and point the authoring actions at them:

  WeblogManager      getTemplate(Weblog, String)
  WeblogEntryManager getWeblogEntry / getWeblogCategory / getComment
  BookmarkManager    getBookmark, getFolderById
  MediaFileManager   getMediaFile, getMediaFileDirectory

Each is backed by a named query filtering on the owning weblog, and returns
null when the id does not belong to that weblog, the same as for an id that
does not exist. The bookmark folder lookup is named getFolderById because
getFolder(Weblog, String) already exists as the by-name lookup and the two
would otherwise share an erasure.

Call sites updated across templates, entries, categories, comments,
bookmarks, folders and media files. The two comment loops in Comments
already compared the weblog after loading; they now use the scoped lookup
instead, which also removes an NPE on ids that do not exist.

Left unchanged, having been verified to resolve correctly by other means:
EntryBean, StylesheetEdit, CommentDataServlet, and the XML-RPC and Atom
handlers, which derive the weblog from the entity itself.

Tests: WeblogScopedLookupTest (manager layer), TemplateEditScopingTest and
AuthoringActionScopingTest (action layer). Full suite 182 run, 0 failures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant