Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaQueryHit.java47
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractQueryHit.java96
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/DelegatingTaskExternalizer.java9
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskListManagerTest.java46
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockQueryHit.java26
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryExternalizer.java2
-rw-r--r--org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracQueryHit.java42
7 files changed, 116 insertions, 152 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaQueryHit.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaQueryHit.java
index f0c673123..a40c304f9 100644
--- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaQueryHit.java
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaQueryHit.java
@@ -13,7 +13,6 @@ package org.eclipse.mylar.internal.bugzilla.core;
import org.eclipse.mylar.tasks.core.AbstractQueryHit;
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
-import org.eclipse.mylar.tasks.core.ITask;
import org.eclipse.mylar.tasks.core.TaskList;
/**
@@ -22,31 +21,20 @@ import org.eclipse.mylar.tasks.core.TaskList;
*/
public class BugzillaQueryHit extends AbstractQueryHit {
- private BugzillaTask task;
-
private String status;
- private TaskList taskList;
-
- public BugzillaQueryHit(TaskList tasklist, String description, String priority, String repositoryUrl, String id,
+ public BugzillaQueryHit(TaskList taskList, String description, String priority, String repositoryUrl, String id,
BugzillaTask task, String status) {
- super(repositoryUrl, description, id);
+ super(taskList, repositoryUrl, description, id);
super.priority = priority;
- this.taskList = tasklist;
this.task = task;
this.status = status;
}
- public BugzillaTask getCorrespondingTask() {
- return task;
- }
-
- public void setCorrespondingTask(AbstractRepositoryTask task) {
- if (task instanceof BugzillaTask) {
- this.task = (BugzillaTask) task;
- }
+ protected AbstractRepositoryTask createTask() {
+ return new BugzillaTask(this, true);
}
-
+
public String getPriority() {
if (task != null) {
return task.getPriority();
@@ -55,36 +43,11 @@ public class BugzillaQueryHit extends AbstractQueryHit {
}
}
- public String getDescription() {
- // return HtmlStreamTokenizer.unescape(description);
- if (task != null) {
- return task.getDescription();
- } else {
- return description;
- }
- }
-
public String getUrl() {
Integer idInt = new Integer(id);
return BugzillaClient.getBugUrlWithoutLogin(repositoryUrl, idInt);
}
- public AbstractRepositoryTask getOrCreateCorrespondingTask() {
- if (taskList == null)
- return null;
-
- ITask existingTask = taskList.getTask(getHandleIdentifier());
-
- if (existingTask instanceof BugzillaTask) {
- this.task = (BugzillaTask) existingTask;
- } else {
- task = new BugzillaTask(this, true);
- // task.setSyncState(RepositoryTaskSyncState.INCOMING);
- taskList.addTask(task);
- }
- return task;
- }
-
public boolean isCompleted() {
if (status != null
&& (status.startsWith("RESO") || status.startsWith("CLO") || status.startsWith("VERI") || status
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractQueryHit.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractQueryHit.java
index 501e32739..621e22ccc 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractQueryHit.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractQueryHit.java
@@ -16,24 +16,29 @@ package org.eclipse.mylar.tasks.core;
*/
public abstract class AbstractQueryHit implements ITaskListElement {
+ protected TaskList taskList;
+
+ protected AbstractRepositoryTask task;
+
protected String repositoryUrl;
-
+
protected String description;
protected String priority;
-
+
protected String id;
protected boolean isNotified = false;
private AbstractRepositoryQuery parent;
-
- protected AbstractQueryHit(String repositoryUrl, String description, String id) {
+
+ protected AbstractQueryHit(TaskList taskList, String repositoryUrl, String description, String id) {
+ this.taskList = taskList;
this.repositoryUrl = repositoryUrl;
this.description = description;
this.id = id;
}
-
+
public AbstractRepositoryQuery getParent() {
return parent;
}
@@ -41,7 +46,7 @@ public abstract class AbstractQueryHit implements ITaskListElement {
public void setParent(AbstractRepositoryQuery parent) {
this.parent = parent;
}
-
+
public String getRepositoryUrl() {
return repositoryUrl;
}
@@ -50,54 +55,94 @@ public abstract class AbstractQueryHit implements ITaskListElement {
this.repositoryUrl = repositoryUrl;
}
- public abstract AbstractRepositoryTask getOrCreateCorrespondingTask();
-
+ public String getDescription() {
+ if (task != null) {
+ return task.getDescription();
+ } else {
+ return description;
+ }
+ }
+
+ public AbstractRepositoryTask getOrCreateCorrespondingTask() {
+ if (taskList == null) {
+ return null;
+ }
+
+ ITask existingTask = taskList.getTask(getHandleIdentifier());
+
+ if (existingTask instanceof AbstractRepositoryTask) {
+ this.task = (AbstractRepositoryTask) existingTask;
+ } else {
+ task = createTask();
+ taskList.addTask(task);
+ }
+ return task;
+ }
+
+ protected abstract AbstractRepositoryTask createTask();
+
/**
- * @return null if there is no corresponding report
+ * @return null if there is no corresponding task
*/
- public abstract AbstractRepositoryTask getCorrespondingTask();
+ public AbstractRepositoryTask getCorrespondingTask() {
+ return task;
+ }
+
+ public void setCorrespondingTask(AbstractRepositoryTask task) {
+ this.task = task;
+ }
public abstract boolean isCompleted();
-
- public abstract void setCorrespondingTask(AbstractRepositoryTask task);
public String getHandleIdentifier() {
return AbstractRepositoryTask.getHandle(repositoryUrl, id);
}
+ /**
+ * @return Unique identifier for this task on the corresponding server, must
+ * be robust to changing attributes on the task.
+ */
public String getId() {
return id;
}
-
+
+ /**
+ * @return An ID that can be presented to the user for identifying the task,
+ * override to return null if no such ID exists.
+ */
+ public String getIdLabel() {
+ return getId();
+ }
+
public boolean isNotified() {
return isNotified;
}
-
+
public void setNotified(boolean notified) {
isNotified = notified;
}
@Override
public boolean equals(Object obj) {
- if(!(obj instanceof AbstractQueryHit)) {
+ if (!(obj instanceof AbstractQueryHit)) {
return false;
}
- AbstractQueryHit hit = (AbstractQueryHit)obj;
- return hit.getHandleIdentifier().equals(this.getHandleIdentifier());
+ AbstractQueryHit hit = (AbstractQueryHit) obj;
+ return hit.getHandleIdentifier().equals(this.getHandleIdentifier());
}
@Override
public int hashCode() {
return this.getHandleIdentifier().hashCode();
}
-
+
/**
* @return the url of the hit without any additional login information etc.
*/
public String getUrl() {
return "";
}
-
+
public String getPriority() {
AbstractRepositoryTask task = getCorrespondingTask();
if (task != null) {
@@ -107,15 +152,6 @@ public abstract class AbstractQueryHit implements ITaskListElement {
}
}
- public String getDescription() {
- AbstractRepositoryTask task = getCorrespondingTask();
- if (task != null) {
- return task.getDescription();
- } else {
- return description;
- }
- }
-
public void setPriority(String priority) {
this.priority = priority;
}
@@ -125,7 +161,7 @@ public abstract class AbstractQueryHit implements ITaskListElement {
}
public void setHandleIdentifier(String id) {
- //ignore
+ // ignore
}
-
+
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/DelegatingTaskExternalizer.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/DelegatingTaskExternalizer.java
index ae35ceb49..6af10d2b3 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/DelegatingTaskExternalizer.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/DelegatingTaskExternalizer.java
@@ -129,8 +129,11 @@ public class DelegatingTaskExternalizer implements ITaskListExternalizer {
}
}
+ /**
+ * Override to create specific elements
+ */
public boolean canCreateElementFor(ITask task) {
- return true;
+ return false;
}
public Element createTaskElement(ITask task, Document doc, Element parent) {
@@ -452,7 +455,7 @@ public class DelegatingTaskExternalizer implements ITaskListExternalizer {
}
public boolean canCreateElementFor(AbstractRepositoryQuery query) {
- return true;
+ return false;
}
public Element createQueryElement(AbstractRepositoryQuery query, Document doc, Element parent) {
@@ -500,7 +503,7 @@ public class DelegatingTaskExternalizer implements ITaskListExternalizer {
}
public boolean canCreateElementFor(AbstractQueryHit queryHit) {
- return true;
+ return false;
}
public Element createQueryHitElement(AbstractQueryHit queryHit, Document doc, Element parent) {
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 2b3c9a58f..35481edef 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
@@ -396,9 +396,9 @@ public class TaskListManagerTest extends TestCase {
TaskList taskList = TasksUiPlugin.getTaskListManager().getTaskList();
taskList.moveToRoot(task);
MockRepositoryQuery query = new MockRepositoryQuery("query", taskList);
- MockQueryHit hit = new MockQueryHit(repositoryUrl, task.getDescription(), "1");
+ MockQueryHit hit = new MockQueryHit(taskList, repositoryUrl, task.getDescription(), "1");
hit.setCorrespondingTask(task);
- query.addHit(new MockQueryHit(repositoryUrl, task.getDescription(), "1"));
+ query.addHit(new MockQueryHit(taskList, repositoryUrl, task.getDescription(), "1"));
taskList.addQuery(query);
assertEquals(1, taskList.getAllTasks().size());
assertEquals(1, taskList.getRootTasks().size());
@@ -566,14 +566,15 @@ 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");
- MockQueryHit hit1 = new MockQueryHit("repositoryURL", "description1", "1");
- MockQueryHit hit2 = new MockQueryHit("repositoryURL", "description2", "2");
- MockQueryHit hit3 = new MockQueryHit("repositoryURL", "description3", "3");
-
- MockQueryHit hit1twin = new MockQueryHit("repositoryURL", "description1", "1");
- MockQueryHit hit2twin = new MockQueryHit("repositoryURL", "description2", "2");
- MockQueryHit hit3twin = new MockQueryHit("repositoryURL", "description3", "3");
+ MockQueryHit hit1twin = new MockQueryHit(taskList, "repositoryURL", "description1", "1");
+ MockQueryHit hit2twin = new MockQueryHit(taskList, "repositoryURL", "description2", "2");
+ MockQueryHit hit3twin = new MockQueryHit(taskList, "repositoryURL", "description3", "3");
MockRepositoryQuery query1 = new MockRepositoryQuery("query1", manager.getTaskList());
MockRepositoryQuery query2 = new MockRepositoryQuery("query2", manager.getTaskList());
@@ -591,7 +592,6 @@ public class TaskListManagerTest extends TestCase {
manager.getTaskList().addQuery(query1);
manager.getTaskList().addQuery(query2);
- TaskList taskList = manager.getTaskList();
Set<AbstractRepositoryQuery> queriesReturned = taskList.getQueriesForHandle(AbstractRepositoryTask.getHandle(
"repositoryURL", 1));
assertNotNull(queriesReturned);
@@ -611,7 +611,9 @@ public class TaskListManagerTest extends TestCase {
}
public void testQueryHitHasParent() {
- MockQueryHit hit1 = new MockQueryHit(MOCK_REPOSITORY_URL, "description1", "1");
+ TaskList taskList = manager.getTaskList();
+
+ MockQueryHit hit1 = new MockQueryHit(taskList, MOCK_REPOSITORY_URL, "description1", "1");
assertNull(hit1.getParent());
MockRepositoryQuery query1 = new MockRepositoryQuery("query1", manager.getTaskList());
query1.addHit(hit1);
@@ -621,13 +623,15 @@ public class TaskListManagerTest extends TestCase {
public void testUpdateQueryHits() {
- MockQueryHit hit1 = new MockQueryHit("repositoryURL", "description1", "1");
- MockQueryHit hit2 = new MockQueryHit("repositoryURL", "description2", "2");
- MockQueryHit hit3 = new MockQueryHit("repositoryURL", "description3", "3");
+ 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");
- MockQueryHit hit1twin = new MockQueryHit("repositoryURL", "description1", "1");
- MockQueryHit hit2twin = new MockQueryHit("repositoryURL", "description2", "2");
- MockQueryHit hit3twin = new MockQueryHit("repositoryURL", "description3", "3");
+ MockQueryHit hit1twin = new MockQueryHit(taskList, "repositoryURL", "description1", "1");
+ MockQueryHit hit2twin = new MockQueryHit(taskList, "repositoryURL", "description2", "2");
+ MockQueryHit hit3twin = new MockQueryHit(taskList, "repositoryURL", "description3", "3");
MockRepositoryQuery query1 = new MockRepositoryQuery("query1", manager.getTaskList());
@@ -711,8 +715,8 @@ public class TaskListManagerTest extends TestCase {
assertEquals(RepositoryTaskSyncState.SYNCHRONIZED, task2.getSyncState());
manager.getTaskList().reset();
- MockQueryHit hit1 = new MockQueryHit(repositoryUrl, "description", "1");
- MockQueryHit hit2 = new MockQueryHit(repositoryUrl, "description", "2");
+ MockQueryHit hit1 = new MockQueryHit(manager.getTaskList(), repositoryUrl, "description", "1");
+ MockQueryHit hit2 = new MockQueryHit(manager.getTaskList(), repositoryUrl, "description", "2");
MockRepositoryQuery query = new MockRepositoryQuery("description", manager.getTaskList());
query.addHit(hit1);
query.addHit(hit2);
@@ -747,8 +751,8 @@ public class TaskListManagerTest extends TestCase {
assertEquals(RepositoryTaskSyncState.INCOMING, task2.getSyncState());
manager.getTaskList().reset();
- MockQueryHit hit1 = new MockQueryHit(repositoryUrl, "description", "1");
- MockQueryHit hit2 = new MockQueryHit(repositoryUrl, "description", "2");
+ MockQueryHit hit1 = new MockQueryHit(manager.getTaskList(), repositoryUrl, "description", "1");
+ MockQueryHit hit2 = new MockQueryHit(manager.getTaskList(), repositoryUrl, "description", "2");
MockRepositoryQuery query = new MockRepositoryQuery("description", manager.getTaskList());
query.addHit(hit1);
query.addHit(hit2);
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockQueryHit.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockQueryHit.java
index 3a6a13cbd..d22b10058 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockQueryHit.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockQueryHit.java
@@ -10,29 +10,20 @@ package org.eclipse.mylar.tasks.tests.connector;
import org.eclipse.mylar.tasks.core.AbstractQueryHit;
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
+import org.eclipse.mylar.tasks.core.TaskList;
/**
* @author Rob Elves
+ *
*/
public class MockQueryHit extends AbstractQueryHit {
- AbstractRepositoryTask task = null;
-
- public MockQueryHit(String repositoryUrl, String description, String id) {
- super(repositoryUrl, description, id);
+ public MockQueryHit(TaskList taskList, String repositoryUrl, String description, String id) {
+ super(taskList, repositoryUrl, description, id);
}
- @Override
- public AbstractRepositoryTask getCorrespondingTask() {
- return task;
- }
-
- @Override
- public AbstractRepositoryTask getOrCreateCorrespondingTask() {
- if(task == null) {
- task = new MockRepositoryTask(AbstractRepositoryTask.getHandle(repositoryUrl, id));
- }
- return task;
+ protected AbstractRepositoryTask createTask() {
+ return new MockRepositoryTask(AbstractRepositoryTask.getHandle(repositoryUrl, id));
}
@Override
@@ -40,9 +31,4 @@ public class MockQueryHit extends AbstractQueryHit {
return task.isCompleted();
}
- @Override
- public void setCorrespondingTask(AbstractRepositoryTask task) {
- this.task = task;
- }
-
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryExternalizer.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryExternalizer.java
index abcc319a5..bec5106fb 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryExternalizer.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/connector/MockRepositoryExternalizer.java
@@ -34,7 +34,7 @@ public class MockRepositoryExternalizer extends DelegatingTaskExternalizer {
@Override
public boolean canCreateElementFor(AbstractQueryHit queryHit) {
- return false;
+ return queryHit instanceof AbstractQueryHit;
}
@Override
diff --git a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracQueryHit.java b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracQueryHit.java
index 261312ed8..7e7e7946e 100644
--- a/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracQueryHit.java
+++ b/org.eclipse.mylyn.trac.core/src/org/eclipse/mylyn/internal/trac/core/TracQueryHit.java
@@ -13,7 +13,6 @@ package org.eclipse.mylar.internal.trac.core;
import org.eclipse.mylar.tasks.core.AbstractQueryHit;
import org.eclipse.mylar.tasks.core.AbstractRepositoryTask;
-import org.eclipse.mylar.tasks.core.ITask;
import org.eclipse.mylar.tasks.core.TaskList;
/**
@@ -21,41 +20,21 @@ import org.eclipse.mylar.tasks.core.TaskList;
*/
public class TracQueryHit extends AbstractQueryHit {
- private TracTask task;
-
private boolean completed;
- private TaskList taskList;
-
public TracQueryHit(TaskList taskList, String repositoryUrl, String description, String id) {
- super(repositoryUrl, description, id);
-
- this.taskList = taskList;
+ super(taskList, repositoryUrl, description, id);
}
public TracQueryHit(TaskList taskList, String handle) {
- super(AbstractRepositoryTask.getRepositoryUrl(handle), "", AbstractRepositoryTask.getTaskId(handle));
-
- this.taskList = taskList;
+ super(taskList, AbstractRepositoryTask.getRepositoryUrl(handle), "", AbstractRepositoryTask.getTaskId(handle));
}
- @Override
- public AbstractRepositoryTask getCorrespondingTask() {
- return task;
- }
-
- @Override
- public AbstractRepositoryTask getOrCreateCorrespondingTask() {
- ITask existingTask = taskList.getTask(getHandleIdentifier());
- if (existingTask instanceof TracTask) {
- this.task = (TracTask) existingTask;
- } else {
- this.task = new TracTask(getHandleIdentifier(), getDescription(), true);
- task.setCompleted(completed);
- task.setPriority(priority);
- taskList.addTask(task);
- }
- return task;
+ protected AbstractRepositoryTask createTask() {
+ TracTask newTask = new TracTask(getHandleIdentifier(), getDescription(), true);
+ newTask.setCompleted(completed);
+ newTask.setPriority(priority);
+ return newTask;
}
@Override
@@ -63,13 +42,6 @@ public class TracQueryHit extends AbstractQueryHit {
return (task != null) ? task.isCompleted() : completed;
}
- @Override
- public void setCorrespondingTask(AbstractRepositoryTask task) {
- if (task instanceof TracTask) {
- this.task = (TracTask) task;
- }
- }
-
public String getUrl() {
return getRepositoryUrl() + ITracClient.TICKET_URL + getId();
}

Back to the top