Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrelves2006-12-12 18:53:54 -0500
committerrelves2006-12-12 18:53:54 -0500
commit8b77ec186d49585f39ac07e59c416402080c8549 (patch)
tree722aeb36e86155af194ee9d3baa010691a2236b8
parent7cd376493a693fc68c567e5df3b493f3286474be (diff)
downloadorg.eclipse.mylyn.tasks-8b77ec186d49585f39ac07e59c416402080c8549.tar.gz
org.eclipse.mylyn.tasks-8b77ec186d49585f39ac07e59c416402080c8549.tar.xz
org.eclipse.mylyn.tasks-8b77ec186d49585f39ac07e59c416402080c8549.zip
NEW - bug 167359: support restore of queries orphaned by missing connectors
https://bugs.eclipse.org/bugs/show_bug.cgi?id=167359
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/TaskListStandaloneTest.java48
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListManagerTest.java32
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskListWriter.java22
3 files changed, 81 insertions, 21 deletions
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/TaskListStandaloneTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/TaskListStandaloneTest.java
index d4b2e0716..3148c69ff 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/TaskListStandaloneTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/TaskListStandaloneTest.java
@@ -19,7 +19,9 @@ import java.util.Set;
import junit.framework.TestCase;
+import org.eclipse.mylar.internal.bugzilla.core.BugzillaRepositoryQuery;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaTask;
+import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaTaskExternalizer;
import org.eclipse.mylar.tasks.core.ITask;
import org.eclipse.mylar.tasks.core.ITaskListExternalizer;
@@ -104,7 +106,8 @@ public class TaskListStandaloneTest extends TestCase {
assertEquals(task.getScheduledForDate(), readTask.getScheduledForDate());
}
- public void testTaskRetentionWhenConnectorMissing() {
+ // Task retention when connector missing upon startup
+ public void testOrphanedTasks() {
List<ITaskListExternalizer> originalExternalizers = manager.getTaskListWriter().getExternalizers();
List<ITaskListExternalizer> externalizers;
externalizers = new ArrayList<ITaskListExternalizer>();
@@ -145,6 +148,49 @@ public class TaskListStandaloneTest extends TestCase {
manager.getTaskListWriter().setDelegateExternalizers(originalExternalizers);
}
+ // Query retention when connector missing/fails to load
+ public void testOrphanedQueries() {
+ List<ITaskListExternalizer> originalExternalizers = manager.getTaskListWriter().getExternalizers();
+ List<ITaskListExternalizer> externalizers;
+ externalizers = new ArrayList<ITaskListExternalizer>();
+ externalizers.add(new BugzillaTaskExternalizer());
+ // make a query
+ BugzillaRepositoryQuery query = new BugzillaRepositoryQuery(IBugzillaConstants.TEST_BUGZILLA_222_URL,
+ "http://queryurl", "description", "-1", TasksUiPlugin.getTaskListManager().getTaskList());
+
+ manager.getTaskList().addQuery(query);
+ manager.saveTaskList();
+
+ // reload tasklist and check that they persist
+ manager.resetTaskList();
+ manager.readExistingOrCreateNewList();
+ assertEquals(1, manager.getTaskList().getQueries().size());
+
+ // removed/disable externalizers
+ externalizers.clear();
+ manager.getTaskListWriter().setDelegateExternalizers(externalizers);
+
+ // reload tasklist ensure query didn't load
+ manager.resetTaskList();
+ manager.readExistingOrCreateNewList();
+ assertEquals(0, manager.getTaskList().getQueries().size());
+ // Save the task list (queries with missing connectors should get
+ // persisted)
+ manager.saveTaskList();
+
+ // re-enable connector
+ externalizers.add(new BugzillaTaskExternalizer());
+ manager.getTaskListWriter().setDelegateExternalizers(externalizers);
+
+ // re-load tasklist
+ manager.resetTaskList();
+ manager.readExistingOrCreateNewList();
+
+ // ensure that task now gets loaded
+ assertEquals(1, manager.getTaskList().getQueries().size());
+ manager.getTaskListWriter().setDelegateExternalizers(originalExternalizers);
+ }
+
public void assertDatesCloseEnough(Date first, Date second) {
assertTrue(second.getTime() - first.getTime() < 100);
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListManagerTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListManagerTest.java
index 09f51f3f8..9e2b29e94 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListManagerTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListManagerTest.java
@@ -82,31 +82,30 @@ public class TaskListManagerTest extends TestCase {
TasksUiPlugin.getDefault().getRepositoriesFilePath());
}
-
- public void testUniqueTaskID() {
- Task task1 = new Task(TasksUiPlugin.getTaskListManager().genUniqueTaskHandle(),"label", true);
+ public void testUniqueTaskID() {
+ Task task1 = new Task(TasksUiPlugin.getTaskListManager().genUniqueTaskHandle(), "label", true);
manager.getTaskList().addTask(task1);
- Task task2 = new Task(TasksUiPlugin.getTaskListManager().genUniqueTaskHandle(),"label", true);
+ Task task2 = new Task(TasksUiPlugin.getTaskListManager().genUniqueTaskHandle(), "label", true);
manager.getTaskList().addTask(task2);
assertEquals(2, manager.getTaskList().getLastTaskNum());
manager.getTaskList().deleteTask(task2);
- Task task3 = new Task(TasksUiPlugin.getTaskListManager().genUniqueTaskHandle(),"label", true);
+ Task task3 = new Task(TasksUiPlugin.getTaskListManager().genUniqueTaskHandle(), "label", true);
manager.getTaskList().addTask(task3);
- assertTrue(task3.getHandleIdentifier()+" should end with 3", task3.getHandleIdentifier().endsWith("3"));
+ assertTrue(task3.getHandleIdentifier() + " should end with 3", task3.getHandleIdentifier().endsWith("3"));
assertEquals(3, manager.getTaskList().getLastTaskNum());
-
+
assertEquals(2, manager.getTaskList().getAllTasks().size());
manager.saveTaskList();
manager.resetTaskList();
assertEquals(0, manager.getTaskList().getAllTasks().size());
- assertEquals(0, manager.getTaskList().getLastTaskNum());
+ assertEquals(0, manager.getTaskList().getLastTaskNum());
manager.readExistingOrCreateNewList();
assertEquals(2, manager.getTaskList().getAllTasks().size());
assertEquals(3, manager.getTaskList().getLastTaskNum());
- Task task4 = new Task(TasksUiPlugin.getTaskListManager().genUniqueTaskHandle(),"label", true);
- assertTrue(task4.getHandleIdentifier()+" should end with 4", task4.getHandleIdentifier().endsWith("4"));
+ Task task4 = new Task(TasksUiPlugin.getTaskListManager().genUniqueTaskHandle(), "label", true);
+ assertTrue(task4.getHandleIdentifier() + " should end with 4", task4.getHandleIdentifier().endsWith("4"));
}
-
+
public void testSingleTaskDeletion() {
MockRepositoryTask task = new MockRepositoryTask("mock-1");
manager.getTaskList().moveToRoot(task);
@@ -568,7 +567,7 @@ public class TaskListManagerTest extends TestCase {
public void testgetQueriesAndHitsForHandle() {
TaskList taskList = manager.getTaskList();
-
+
MockQueryHit hit1 = new MockQueryHit(taskList, "repositoryURL", "description1", "1");
MockQueryHit hit2 = new MockQueryHit(taskList, "repositoryURL", "description2", "2");
MockQueryHit hit3 = new MockQueryHit(taskList, "repositoryURL", "description3", "3");
@@ -601,8 +600,7 @@ public class TaskListManagerTest extends TestCase {
assertTrue(queriesReturned.contains(query2));
Set<String> handles = new HashSet<String>();
- handles.add(AbstractRepositoryTask.getHandle(
- "repositoryURL", 2));
+ handles.add(AbstractRepositoryTask.getHandle("repositoryURL", 2));
Set<AbstractQueryHit> hitsReturned = taskList.getQueryHits(handles);
assertNotNull(hitsReturned);
assertEquals(1, hitsReturned.size());
@@ -613,7 +611,7 @@ public class TaskListManagerTest extends TestCase {
public void testQueryHitHasParent() {
TaskList taskList = manager.getTaskList();
-
+
MockQueryHit hit1 = new MockQueryHit(taskList, MOCK_REPOSITORY_URL, "description1", "1");
assertNull(hit1.getParent());
MockRepositoryQuery query1 = new MockRepositoryQuery("query1", manager.getTaskList());
@@ -625,7 +623,7 @@ public class TaskListManagerTest extends TestCase {
public void testUpdateQueryHits() {
TaskList taskList = manager.getTaskList();
-
+
MockQueryHit hit1 = new MockQueryHit(taskList, "repositoryURL", "description1", "1");
MockQueryHit hit2 = new MockQueryHit(taskList, "repositoryURL", "description2", "2");
MockQueryHit hit3 = new MockQueryHit(taskList, "repositoryURL", "description3", "3");
@@ -784,7 +782,5 @@ public class TaskListManagerTest extends TestCase {
fail();
}
}
-
}
-
} \ No newline at end of file
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskListWriter.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskListWriter.java
index e6059f2ec..33e12a414 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskListWriter.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/util/TaskListWriter.java
@@ -55,6 +55,7 @@ import org.xml.sax.SAXException;
/**
* @author Mik Kersten
* @author Ken Sueda
+ * @author Rob Elves
*/
public class TaskListWriter {
// Last number given to new local task
@@ -75,6 +76,8 @@ public class TaskListWriter {
private DelegatingTaskExternalizer delagatingExternalizer;
private List<Node> orphanedTaskNodes = new ArrayList<Node>();
+
+ private List<Node> orphanedQueryNodes = new ArrayList<Node>();
private String readVersion = "";
@@ -140,13 +143,22 @@ public class TaskListWriter {
for (ITask task : new ArrayList<ITask>(taskList.getAllTasks())) {
createTaskElement(doc, root, task);
}
-
+
+ // Persist orphaned tasks...
for (Node orphanedTaskNode : orphanedTaskNodes) {
Node tempNode = doc.importNode(orphanedTaskNode, true);
if (tempNode != null) {
root.appendChild(tempNode);
}
}
+
+ // Persist orphaned queries....
+ for (Node orphanedQueryNode : orphanedQueryNodes) {
+ Node tempNode = doc.importNode(orphanedQueryNode, true);
+ if (tempNode != null) {
+ root.appendChild(tempNode);
+ }
+ }
doc.appendChild(root);
writeDOMtoFile(doc, outFile);
@@ -237,6 +249,7 @@ public class TaskListWriter {
public void readTaskList(TaskList taskList, File inFile, TaskDataManager taskDataManager) {
hasCaughtException = false;
orphanedTaskNodes.clear();
+ orphanedQueryNodes.clear();
try {
if (!inFile.exists())
return;
@@ -303,20 +316,25 @@ public class TaskListWriter {
}
}
- // then query hits hits, which get corresponded to tasks
+ // then queries and hits which get linked to tasks
for (int i = 0; i < list.getLength(); i++) {
Node child = list.item(i);
try {
+ boolean wasRead = false;
if (child.getNodeName().endsWith(DelegatingTaskExternalizer.KEY_QUERY)) {
for (ITaskListExternalizer externalizer : externalizers) {
if (externalizer.canReadQuery(child)) {
AbstractRepositoryQuery query = externalizer.readQuery(child, taskList);
if (query != null) {
+ wasRead = true;
taskList.internalAddQuery(query);
}
break;
}
}
+ if(!wasRead) {
+ orphanedQueryNodes.add(child);
+ }
}
} catch (Exception e) {
handleException(inFile, child, e);

Back to the top