When using the built-in dataspace merge script task, all the merged updates are shown as done by a "System user".
Indeed, in the context of a script task, updates are done in a system session.
In order to modify this behavior, we will have to replace the built-in merge script task with a custom one using the API.
This article will give an example of such a ScriptTaskBean implementation that performs a merge in the context of a user session.
The class has two input parameters:
These parameters can be data context variables that are previously filled in the workflow.
For the userId variable, you would maybe need to add an output variable to a built-in service.
The following article explains how to achieve this:
Extending a built-in service to add input/output parameters
The output parameter can be set in the handleWorkItemCompletion method of a UserTask extension.
In our script task, we will create a session related to a specific user.
For this we will use the createSessionFromArray method of Repository class.
In order to this method, you have to create your own directory and implement authenticateUserFromArray(Object[] args). It will return a UserReference depending on a given Object[] argument. This authentification method can only be called from custom code.
To create your custom directory, you have to create a DirectoryFactory.
You can extend the default directory and just implement authenticateUserFromArray(Object[] args).
Then, you will have to specify your custom directory in ebx.properties:
https://docs.tibco.com/pub/ebx/5.9.8/doc/html/en/installation/properties.html#userDirectory
The DirectoryFactory has to be in the same folder as ebx.jar.
This is our implementation of authenticateUserFromArray:
myCustomDirectory.javapublic UserReference authenticateUserFromArray( final Object[] args) { if (args != null && args[ 0 ] != null && args[ 0 ] instanceof UserReference) { final UserReference user = (UserReference) args[ 0 ]; return user; } return super .authenticateUserFromArray(args); |
MergeScriptTaskWithUserSession.java
Repository repository = context.getRepository(); Session createdSession = null ; // User session creation. UserReference user = Profile.forUser( "this.userId" ); Object[] args = new Object[]{ user, }; createdSession = repository.createSessionFromArray(args); |
Once our user session is created, we will create a programmatic service and execute a merge procedure that will be executed in the context of this user session.
MergeScriptTaskWithUserSession.javaAdaptationHome childDataspace = repository.lookupHome(HomeKey.forBranchName(childDataspaceName)); AdaptationHome parentDataspace = childDataspace.getParentBranch(); ProgrammaticService.createForSession(createdSession, parentDataspace).execute( new Procedure() { @Override public void execute(ProcedureContext context) throws Exception { context.doMergeToParent(childDataspace); } }); |
< bean className = "com.orchestranetworks.support.module.MergeScriptTaskWithUserSession" > < documentation xml:lang = "en-US" > < label >Merge script with user session.</ label > </ documentation > < properties > < property name = "userId" input = "true" > < documentation xml:lang = "en-US" > < label >User login</ label > < description > The user login. </ description > </ documentation > </ property > < property name = "childDataspaceName" input = "true" > < documentation xml:lang = "en-US" > < label >Child dataspace name</ label > < description > The child dataspace name. </ description > </ documentation > </ property > </ properties > </ bean > |