Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle deleting task candidates #3998

Merged
merged 3 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,34 @@
*/
package org.flowable.engine.test.api.task;

import java.util.HashSet;
import java.util.Set;

import org.flowable.engine.delegate.TaskListener;
import org.flowable.identitylink.api.IdentityLink;
import org.flowable.task.service.delegate.DelegateTask;

public class DeleteCandidateTaskListener implements TaskListener {
public static final String VARNAME_CANDIDATE_USERS = "candidateUsers";
public static final String VARNAME_CANDIDATE_GROUPS = "candidateGroups";

@Override
public void notify(DelegateTask delegateTask) {
delegateTask.deleteCandidateUser("admin");
delegateTask.deleteCandidateGroup("admins");

Set<IdentityLink> candidates = delegateTask.getCandidates();
Set<String> candidateUsers = new HashSet<>();
Set<String> candidateGroups = new HashSet<>();
for (IdentityLink candidate : candidates) {
if (candidate.getUserId() != null) {
candidateUsers.add(candidate.getUserId());
} else if (candidate.getGroupId() != null) {
candidateGroups.add(candidate.getGroupId());
}
}
delegateTask.setVariable(VARNAME_CANDIDATE_USERS, candidateUsers);
delegateTask.setVariable(VARNAME_CANDIDATE_GROUPS, candidateGroups);

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.Set;

import org.flowable.common.engine.api.FlowableException;
import org.flowable.common.engine.impl.history.HistoryLevel;
Expand Down Expand Up @@ -321,16 +322,46 @@ public void testDeleteOwner() {
}

@Test
@Deployment(resources = "org/flowable/engine/test/api/task/TaskIdentityLinksTest.testDeleteCandidateUser.bpmn20.xml")
public void testDeleteCandidateUser() {
@Deployment(resources = "org/flowable/engine/test/api/task/TaskIdentityLinksTest.testDeleteCandidates.bpmn20.xml")
public void testDeleteCandidates() {
runtimeService.startProcessInstanceByKey("TaskIdentityLinks");

String taskId = taskService.createTaskQuery().singleResult().getId();

List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(taskId);
assertThat(identityLinks)
.filteredOn(identityLink -> identityLink.getUserId() != null)
.extracting(IdentityLink::getUserId)
.containsExactly("user");

assertThat(identityLinks)
.filteredOn(identityLink -> identityLink.getGroupId() != null)
.extracting(IdentityLink::getGroupId)
.containsExactly("users");

if (HistoryTestHelper.isHistoryLevelAtLeast(HistoryLevel.AUDIT, processEngineConfiguration)) {
List<HistoricIdentityLink> historicIdentityLinks = historyService.getHistoricIdentityLinksForTask(taskId);

assertThat(historicIdentityLinks)
.filteredOn(identityLink -> identityLink.getUserId() != null)
.extracting(HistoricIdentityLink::getUserId)
.containsExactly("user");

assertThat(historicIdentityLinks)
.filteredOn(identityLink -> identityLink.getGroupId() != null)
.extracting(HistoricIdentityLink::getGroupId)
.containsExactly("users");
}

@SuppressWarnings("unchecked")
Set<String> candidateUsers = (Set<String>) taskService.getVariable(taskId, DeleteCandidateTaskListener.VARNAME_CANDIDATE_USERS);
assertThat(candidateUsers)
.containsExactly("user");

@SuppressWarnings("unchecked")
Set<String> candidateGroups = (Set<String>) taskService.getVariable(taskId, DeleteCandidateTaskListener.VARNAME_CANDIDATE_GROUPS);
assertThat(candidateGroups)
.containsExactly("users");
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</extensionElements>
<potentialOwner>
<resourceAssignmentExpression>
<formalExpression>user(user),user(admin)</formalExpression>
<formalExpression>user(user),user(admin),group(users),group(admins)</formalExpression>
</resourceAssignmentExpression>
</potentialOwner>
</userTask>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,13 +395,27 @@ public void deleteCandidateGroup(String groupId) {
@Override
public void deleteUserIdentityLink(String userId, String identityLinkType) {
IdentityLinkEntityManager identityLinkEntityManager = getIdentityLinkServiceConfiguration().getIdentityLinkEntityManager();
identityLinkEntityManager.deleteTaskIdentityLink(this.id, getIdentityLinks(), userId, null, identityLinkType);
List<IdentityLinkEntity> identityLinkEntities = identityLinkEntityManager.deleteTaskIdentityLink(this.id,
getIdentityLinks(), userId, null, identityLinkType);
InternalTaskAssignmentManager taskAssignmentManager = getTaskAssignmentManager();
if (taskAssignmentManager != null) {
for (IdentityLinkEntity identityLink : identityLinkEntities) {
taskAssignmentManager.deleteUserIdentityLink(this, identityLink);
}
}
}

@Override
public void deleteGroupIdentityLink(String groupId, String identityLinkType) {
IdentityLinkEntityManager identityLinkEntityManager = getIdentityLinkServiceConfiguration().getIdentityLinkEntityManager();
identityLinkEntityManager.deleteTaskIdentityLink(this.id, getIdentityLinks(), null, groupId,identityLinkType);
List<IdentityLinkEntity> identityLinkEntities = identityLinkEntityManager.deleteTaskIdentityLink(this.id,
getIdentityLinks(), null, groupId, identityLinkType);
InternalTaskAssignmentManager taskAssignmentManager = getTaskAssignmentManager();
if (taskAssignmentManager != null) {
for (IdentityLinkEntity identityLink : identityLinkEntities) {
taskAssignmentManager.deleteGroupIdentityLink(this, identityLink);
}
}
}

@Override
Expand Down
Loading