From dd62414dd526d7a08da6f8f3ecd85dd52d049e2f Mon Sep 17 00:00:00 2001
From: Sam Davis
Date: Mon, 6 Oct 2014 14:24:16 -0700
Subject: 446091: [api] allow clients to determine when the current user owns
an ITask
Change-Id: Ie6fb5d4c27fd31be4f4127be7fc82e892b503466
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=446091
---
.../mylyn/internal/tasks/core/AbstractTask.java | 14 ++++++++++
.../tasks/core/AbstractRepositoryConnector.java | 9 +++----
.../src/org/eclipse/mylyn/tasks/core/ITask.java | 18 +++++++++++++
.../org/eclipse/mylyn/tasks/core/ITaskMapping.java | 5 ++++
.../mylyn/tasks/core/TaskInitializationData.java | 11 ++++++++
.../org/eclipse/mylyn/tasks/core/TaskMapping.java | 8 ++++++
.../eclipse/mylyn/tasks/core/data/TaskMapper.java | 30 +++++++++++++++++++++-
7 files changed, 89 insertions(+), 6 deletions(-)
(limited to 'org.eclipse.mylyn.tasks.core/src/org')
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/AbstractTask.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/AbstractTask.java
index a632c09bf..6eeefead6 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/AbstractTask.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/AbstractTask.java
@@ -93,6 +93,8 @@ public abstract class AbstractTask extends AbstractTaskContainer implements ITas
private boolean changed;
+ private String ownerId;
+
public AbstractTask(String repositoryUrl, String taskId, String summary) {
super(RepositoryTaskHandleUtil.getHandle(repositoryUrl, taskId));
this.repositoryUrl = repositoryUrl;
@@ -172,6 +174,18 @@ public abstract class AbstractTask extends AbstractTaskContainer implements ITas
}
}
+ public String getOwnerId() {
+ return ownerId;
+ }
+
+ public void setOwnerId(String ownerId) {
+ if (!areEqual(this.ownerId, ownerId)) {
+ String oldValue = this.ownerId;
+ this.ownerId = (ownerId != null) ? ownerId.intern() : null;
+ firePropertyChange("ownerId", oldValue, ownerId); //$NON-NLS-1$
+ }
+ }
+
/**
* Return the status, such as an error or warning, associated with this task.
*/
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java
index 9a6ca49b3..80df14c36 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java
@@ -605,10 +605,8 @@ public abstract class AbstractRepositoryConnector {
* @since 3.5
*/
public boolean isOwnedByUser(@NonNull TaskRepository repository, @NonNull ITask task) {
- if (task.getOwner() != null) {
- return task.getOwner().equals(repository.getUserName());
- }
- return false;
+ return (task.getOwner() != null && task.getOwner().equals(repository.getUserName()))
+ || (task.getOwnerId() != null && task.getOwnerId().equals(repository.getUserName()));
}
/**
@@ -647,7 +645,8 @@ public abstract class AbstractRepositoryConnector {
* @since 3.11
*/
@NonNull
- public RepositoryInfo validateRepository(@NonNull TaskRepository repository, @Nullable IProgressMonitor monitor) throws CoreException {
+ public RepositoryInfo validateRepository(@NonNull TaskRepository repository, @Nullable IProgressMonitor monitor)
+ throws CoreException {
throw new UnsupportedOperationException();
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITask.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITask.java
index 6cf012962..d2a9d1598 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITask.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITask.java
@@ -15,6 +15,7 @@ import java.util.Date;
import org.eclipse.core.runtime.Assert;
import org.eclipse.mylyn.internal.tasks.core.Messages;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
/**
* @author Mik Kersten
@@ -280,10 +281,22 @@ public interface ITask extends IRepositoryElement, IAttributeContainer {
public abstract Date getModificationDate();
/**
+ * Returns the label of the owner, that is, the option label corresponding to the value of the
+ * {@link TaskAttribute#USER_ASSIGNED} attribute in the TaskData. If the connector does not provide option labels
+ * for this attribute, the {@link #getOwnerId() ID} is returned instead.
+ *
* @since 3.0
*/
public abstract String getOwner();
+ /**
+ * Returns the ID of the owner, that is, the value of the {@link TaskAttribute#USER_ASSIGNED} attribute in
+ * the TaskData.
+ *
+ * @since 3.15
+ */
+ public abstract String getOwnerId();
+
/**
* @since 3.0
*/
@@ -357,6 +370,11 @@ public interface ITask extends IRepositoryElement, IAttributeContainer {
*/
public abstract void setOwner(String owner);
+ /**
+ * @since 3.15
+ */
+ public abstract void setOwnerId(String ownerId);
+
/**
* @since 3.0
*/
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITaskMapping.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITaskMapping.java
index 5d6972e68..414770b82 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITaskMapping.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITaskMapping.java
@@ -45,6 +45,11 @@ public interface ITaskMapping {
public abstract String getOwner();
+ /**
+ * @since 3.15
+ */
+ public abstract String getOwnerId();
+
public abstract String getPriority();
public abstract PriorityLevel getPriorityLevel();
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskInitializationData.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskInitializationData.java
index 39c3f1f51..0b3efbf25 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskInitializationData.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskInitializationData.java
@@ -109,6 +109,17 @@ public class TaskInitializationData implements ITaskMapping {
}
+ /**
+ * Returns null
.
+ *
+ * @since 3.15
+ */
+ @Nullable
+ public String getOwnerId() {
+ return null;
+
+ }
+
@Nullable
public String getPriority() {
return attributesById.getAttribute(TaskAttribute.PRIORITY);
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskMapping.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskMapping.java
index 7b63369c1..f9f2f885c 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskMapping.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskMapping.java
@@ -88,6 +88,14 @@ public class TaskMapping implements ITaskMapping {
return null;
}
+ /**
+ * @since 3.15
+ */
+ public String getOwnerId() {
+ // ignore
+ return null;
+ }
+
/**
* @since 3.0
*/
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskMapper.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskMapper.java
index c9b35586f..ff5dbe7ef 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskMapper.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskMapper.java
@@ -64,6 +64,10 @@ public class TaskMapper implements ITaskMapping {
task.setOwner(getOwner());
changed = true;
}
+ if (hasChanges(task.getOwnerId(), getOwnerId(), TaskAttribute.USER_ASSIGNED)) {
+ task.setOwnerId(getOwnerId());
+ changed = true;
+ }
if (hasChanges(task.getPriority(), getPriorityLevelString(), TaskAttribute.PRIORITY)) {
task.setPriority(getPriorityLevelString());
changed = true;
@@ -135,7 +139,7 @@ public class TaskMapper implements ITaskMapping {
*
sourceTaskData
and targetTaskData
.
- *
+ *
* @param sourceTaskData
* the source task data values are copied from, the connector kind of repository of
* sourceTaskData
can be different from targetTaskData
@@ -265,6 +269,14 @@ public class TaskMapper implements ITaskMapping {
return getValue(TaskAttribute.USER_ASSIGNED);
}
+ /**
+ * @since 3.15
+ */
+ @Nullable
+ public String getOwnerId() {
+ return getValueId(TaskAttribute.USER_ASSIGNED);
+ }
+
@Nullable
public String getPriority() {
return getValue(TaskAttribute.PRIORITY);
@@ -334,6 +346,9 @@ public class TaskMapper implements ITaskMapping {
return getValue(TaskAttribute.TASK_URL);
}
+ /**
+ * Returns the label of the attribute value.
+ */
@Nullable
public String getValue(@NonNull String attributeKey) {
TaskAttribute attribute = taskData.getRoot().getMappedAttribute(attributeKey);
@@ -343,6 +358,18 @@ public class TaskMapper implements ITaskMapping {
return null;
}
+ /**
+ * Returns the id of the attribute value.
+ */
+ @Nullable
+ private String getValueId(@NonNull String attributeKey) {
+ TaskAttribute attribute = taskData.getRoot().getMappedAttribute(attributeKey);
+ if (attribute != null) {
+ return taskData.getAttributeMapper().getValue(attribute);
+ }
+ return null;
+ }
+
@Nullable
private List