Custom workspace assignment on a per-object basis
This ticket is about making custom workspace assignment even more flexible.
In a preCreate
listener you might want request custom workspace assignment for the object being created. The Workspaces plugin should fulfill the request as part of its regular workspace assignment duty then.
#397 (closed) supports custom workspace assignments already. But that runInWorkspaceContext()
utility is not usable in preCreate
as the object will not be created by your code -- so you have no Callable
here --, but by platform code.
IMPORTANT: you can't use the postCreate
listener for custom workspace assignment. The result would be indeterministic behavior as a race condition between your plugin and the Workspaces plugin (whose regular workspace assignment duty relies on postCreate
) is created.
Proposal: to request custom workspace assignment, in a preCreate
listener set the model's regular "Workspace Facet":
import static systems.dmx.workspaces.Constants.*;
public void preCreateTopic(TopicModel topic) {
// request custom workspace assignment
long workspaceId = ...;
topic.getChildTopics().setRef(WORKSPACE + "#" + WORKSPACE_ASSIGNMENT, workspaceId);
}
Thats all it needs. Once the topic (or assoc) is created the Workspaces plugin does the requested assignment then (in postCreate
).
So, in summary, when doing the assignment the Workspaces plugins determines the workspace by looking at 3 sources in order:
- The object model's "Workspace Facet", if set (this ticket)
- The execution context's workspace ID, if code runs via
runInWorkspaceContext()
(#397 (closed)) - The request's
dmx_workspace_id
cookie, if available (as usual)
@mukil FYI
This feature is a prerequisite for fixing #395 (closed)