提交 f7d73fb7 编写于 作者: J jbarrez

ACT-750: refactored TaskNavigator to delegate to ViewManager when URL doesnt match

上级 4b157b39
......@@ -61,10 +61,6 @@ public class TaskManager extends AbstractManager {
.getVariableInstanceManager()
.deleteVariableInstanceByTaskId(taskId);
commandContext
.getAttachmentManager()
.deleteAttachmentsByTaskId(taskId);
if (cascade) {
commandContext
.getHistoricTaskInstanceManager()
......
......@@ -174,8 +174,10 @@ public class TaskServiceTest extends PluggableActivitiTestCase {
assertEquals("someprocessinstanceid", attachment.getProcessInstanceId());
assertEquals("http://weather.com", attachment.getUrl());
assertNull(taskService.getAttachmentContent(attachment.getId()));
// Finally, delete task
// Finally, clean up
taskService.deleteTask(taskId, true);
taskService.deleteAttachment(attachment.getId());
}
}
......
......@@ -13,9 +13,16 @@
package org.activiti.explorer;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.activiti.engine.HistoryService;
import org.activiti.engine.IdentityService;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.TaskService;
import org.activiti.engine.identity.Group;
import org.activiti.engine.task.IdentityLink;
import org.activiti.engine.task.Task;
import org.activiti.explorer.ui.AbstractPage;
import org.activiti.explorer.ui.MainWindow;
......@@ -59,10 +66,12 @@ public class ViewManager {
protected TaskService taskService;
protected HistoryService historyService;
protected IdentityService identityService;
public ViewManager() {
this.taskService = ProcessEngines.getDefaultProcessEngine().getTaskService();
this.historyService = ProcessEngines.getDefaultProcessEngine().getHistoryService();
this.identityService = ProcessEngines.getDefaultProcessEngine().getIdentityService();
}
public void showLoginPage() {
......@@ -106,9 +115,36 @@ public class ViewManager {
} else if (taskService.createTaskQuery().taskInvolvedUser(loggedInUserId).count() == 1) {
showInvolvedPage(taskId);
} else {
showNavigationError(taskId);
// queued
List<String> groupIds = getGroupIds(loggedInUserId);
List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(task.getId());
Iterator<IdentityLink> identityLinkIterator = identityLinks.iterator();
boolean pageFound = false;
while (!pageFound && identityLinkIterator.hasNext()) {
IdentityLink identityLink = identityLinkIterator.next();
if (identityLink.getGroupId() != null && groupIds.contains(identityLink.getGroupId())) {
showQueuedPage(identityLink.getGroupId(), task.getId());
pageFound = true;
}
}
// We've tried hard enough, the user now gets a notification. He deserves it.
if (!pageFound) {
showNavigationError(taskId);
}
}
}
protected List<String> getGroupIds(String userId) {
List<String> groupIds = new ArrayList<String>();
List<Group> groups = identityService.createGroupQuery().groupMember(userId).list();
for (Group group : groups) {
groupIds.add(group.getId());
}
return groupIds;
}
protected void showNavigationError(String taskId) {
ExplorerApp.get().getNotificationManager().showErrorNotification(
......
......@@ -149,57 +149,10 @@ public class TaskNavigator implements Navigator {
if (!pageFound) {
// If URL doesnt match anymore, we must use the task data to redirect to the right page
directToPageBasedOnTaskData(viewManager, taskId, task, loggedInUserId);
viewManager.showTaskPage(taskId);
}
}
protected void directToPageBasedOnTaskData(ViewManager viewManager, String taskId, Task task, String loggedInUserId) {
if (task == null) {
// If task is not found, our only hope is the archived page
boolean isOwner = historyService.createHistoricTaskInstanceQuery()
.taskId(taskId)
.taskOwner(loggedInUserId)
.finished()
.count() == 1;
if (isOwner) {
viewManager.showArchivedPage(taskId);
} else {
showNavigationError(taskId);
}
} else if (loggedInUserId.equals(task.getOwner())) {
viewManager.showCasesPage(task.getId());
} else if (loggedInUserId.equals(task.getAssignee())) {
viewManager.showInboxPage(task.getId());
} else {
boolean pageFound = false;
// First check involved
boolean userInvolved = taskService.createTaskQuery().taskInvolvedUser(loggedInUserId).count() == 1;
if (userInvolved) {
viewManager.showInvolvedPage(task.getId());
pageFound = true;
} else {
// Then check queued
List<String> groupIds = getGroupIds(loggedInUserId);
List<IdentityLink> identityLinks = taskService.getIdentityLinksForTask(task.getId());
Iterator<IdentityLink> identityLinkIterator = identityLinks.iterator();
while (!pageFound && identityLinkIterator.hasNext()) {
IdentityLink identityLink = identityLinkIterator.next();
if (identityLink.getGroupId() != null && groupIds.contains(identityLink.getGroupId())) {
viewManager.showQueuedPage(identityLink.getGroupId(), task.getId());
pageFound = true;
}
}
}
// We've tried hard enough, the user now gets a notification. He deserves it.
if (!pageFound) {
showNavigationError(taskId);
}
}
}
protected void showNavigationError(String taskId) {
String description = ExplorerApp.get().getI18nManager().getMessage(Messages.NAVIGATION_ERROR_NOT_INVOLVED, taskId);
ExplorerApp.get().getNotificationManager().showErrorNotification(Messages.NAVIGATION_ERROR_NOT_INVOLVED_TITLE, description);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册