Override team discussion button behavior
Goal
The behavior of the button that opens or create a new discussion from a process page can be customised
Customisable behaviors :
- the button visibility
- the title of the created discussion
- the description of the created discussion
Implementation
Behavior factory
You must create a class that extends com.moovapps.workplace.team.navigation.behaviors.AbstractTeamDiscussionButtonBehaviorFactory implements com.moovapps.workplace.sdk.navigation.behaviors.ITeamDiscussionButtonBehaviorFactory
This class has to implements public ITeamDiscussionButtonBehavior getBehavior(), a method that returns one of your custom behaviors.
The factory must set the user, the workflow instance and the url of the current process of the returned behavior.
import com.moovapps.workplace.sdk.navigation.behaviors.ITeamDiscussionButtonBehavior;
import com.moovapps.workplace.sdk.navigation.behaviors.ITeamDiscussionButtonBehaviorFactory;
import com.moovapps.workplace.sdk.team.exception.InvalidBehaviorException;
import com.moovapps.workplace.team.navigation.behaviors.AbstractTeamDiscussionButtonBehaviorFactory;
public class BehaviorFactory extends AbstractTeamDiscussionButtonBehaviorFactory implements ITeamDiscussionButtonBehaviorFactory {
@Override
public ITeamDiscussionButtonBehavior getBehavior() throws InvalidBehaviorException {
ITeamDiscussionButtonBehavior behavior;
if(getUser().isAnonymous()){
behavior = new AnonymousBehavior();
} else {
behavior = new TestBehavior();
}
behavior.setWorkflowInstance(getWorkflowInstance());
behavior.setUser(getUser());
behavior.setProcessUrl(getProcessUrl());
return behavior;
}
}
Behavior
You must create a class that extends com.moovapps.workplace.team.navigation.behaviors.AbstractTeamDiscussionButtonBehavior implements com.moovapps.workplace.sdk.navigation.behaviors.ITeamDiscussionButtonBehavior
This class has to implements :
- public boolean isDiscussionButtonVisible() defines if the button is visible in the current context
- public String getTitle() defines the title of the discussion
- public String getDescription() defines the description of the discussion
Below are two examples of behaviors matching the ones in the BehaviorFactory example.
import com.moovapps.workplace.team.navigation.behaviors.AbstractTeamDiscussionButtonBehavior;
import com.moovapps.workplace.sdk.navigation.behaviors.ITeamDiscussionButtonBehavior;
public class TestBehavior extends AbstractTeamDiscussionButtonBehavior implements ITeamDiscussionButtonBehavior
{
@Override
public boolean isDiscussionButtonVisible() {
return true;
}
@Override
public String getTitle() {
return "Discussion about " + getWorkflowInstance().getName();
}
@Override
public String getDescription() {
return "Created by " + getUser().getLogin();
}
}
import com.moovapps.workplace.team.navigation.behaviors.AbstractTeamDiscussionButtonBehavior;
import com.moovapps.workplace.sdk.navigation.behaviors.ITeamDiscussionButtonBehavior;
public class AnonymousBehavior extends AbstractTeamDiscussionButtonBehavior implements ITeamDiscussionButtonBehavior
{
@Override
public boolean isDiscussionButtonVisible() {
return false;
}
@Override
public String getTitle() {
return "Let's talk about " + getWorkflowInstance().getName();
}
@Override
public String getDescription() {
return "";
}
}
Example to invite previous operator and current task operator
import com.moovapps.workplace.team.navigation.behaviors.AbstractTeamDiscussionButtonBehavior;
import com.moovapps.workplace.sdk.navigation.behaviors.ITeamDiscussionButtonBehavior;
public class TestBehavior extends AbstractTeamDiscussionButtonBehavior implements ITeamDiscussionButtonBehavior
{
@Override
public boolean isDiscussionButtonVisible() {
return true;
}
@Override
public String getTitle() {
return "Discussion about " + getWorkflowInstance().getName();
}
@Override
public String getDescription() {
return "Created by " + getUser().getLogin();
}
@Override
public String joinDiscussion() {
String discussionUrl = super.joinDiscussion(); // create the discussion
try (ITeamModule teamModule = WorkplaceModuleFactory.getTeamModule()) {
IWorkflowInstance workflowInstance = this.getWorkflowInstance();
IContext sysadminContext = workflowInstance.getModule().getSysadminContext();
Collection<IUser> operators = new HashSet<>();
// retrieve previous operator
IResourceHistory history = workflowInstance.getHistory();
Collection<? extends IResourceHistory.IEvent> events = history.getEvents();
for (IResourceHistory.IEvent event : events) {
operators.add(event.getFulfiller());
}
// retrieve this step operator
try (IWorkplaceModule workplaceModule = WorkplaceModuleFactory.getWorkplaceModule()) {
IWorkflowModule workflowModule = workplaceModule.getWorkflowModule();
Collection<? extends ITaskInstance> manualTaskInstances = workflowModule.getManualTaskInstances(sysadminContext, workflowInstance);
for (ITaskInstance manualTaskInstance : manualTaskInstances) {
operators.addAll(manualTaskInstance.getOperators());
}
} catch (WorkflowModuleException e) {
throw new IllegalStateException(e);
}
// avoid duplicate (HashSet and same type), original creator and sysadmin
Collection<String> operatorLogins = new HashSet<>();
for (IUser operator : operators) {
String login = operator.getLogin();
if (!operator.isSysadmin() && !Objects.equals(login, getUser().getLogin())) {
operatorLogins.add(operator.getLogin());
}
}
String masterEntity = workflowInstance.getProtocolURI(true);
IDiscussion discussion = teamModule.getDiscussion(masterEntity);
for (String operatorLogin : operatorLogins) {
teamModule.joinDiscussion(discussion, operatorLogin);
}
}
return discussionUrl;
}
}
Configuration
You need to declare your factory in a properties file with the key workplace.discussion.button.behavior.factory:
workplace.discussion.button.behavior.factory=com.example.BehaviorFactory