Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2014-10-06 17:24:16 -0400
committerSam Davis2015-03-11 17:02:17 -0400
commitdd62414dd526d7a08da6f8f3ecd85dd52d049e2f (patch)
tree5e3d168f2af0714f415309137815bd33a6ff74a7
parent66369afb5c49a63829059cb2ec1d9663f2159833 (diff)
downloadorg.eclipse.mylyn.tasks-dd62414dd526d7a08da6f8f3ecd85dd52d049e2f.tar.gz
org.eclipse.mylyn.tasks-dd62414dd526d7a08da6f8f3ecd85dd52d049e2f.tar.xz
org.eclipse.mylyn.tasks-dd62414dd526d7a08da6f8f3ecd85dd52d049e2f.zip
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
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/AbstractTask.java14
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/AbstractRepositoryConnector.java9
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITask.java18
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/ITaskMapping.java5
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskInitializationData.java11
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/TaskMapping.java8
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskMapper.java30
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskMapperTest.java32
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/AbstractRepositoryConnectorTest.java49
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/MyTasksFilter.java6
10 files changed, 172 insertions, 10 deletions
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,11 +281,23 @@ public interface ITask extends IRepositoryElement, IAttributeContainer {
public abstract Date getModificationDate();
/**
+ * Returns the label of the owner, that is, the <i>option label</i> 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 <i>value</i> of the {@link TaskAttribute#USER_ASSIGNED} attribute in
+ * the TaskData.
+ *
+ * @since 3.15
+ */
+ public abstract String getOwnerId();
+
+ /**
* @since 3.0
*/
public abstract String getPriority();
@@ -358,6 +371,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
*/
public abstract void setPriority(String priority);
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 <code>null</code>.
+ *
+ * @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
@@ -89,6 +89,14 @@ public class TaskMapping implements ITaskMapping {
}
/**
+ * @since 3.15
+ */
+ public String getOwnerId() {
+ // ignore
+ return null;
+ }
+
+ /**
* @since 3.0
*/
public PriorityLevel getPriorityLevel() {
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 {
* <li>description
* </ul>
* Other attribute values are only set if they exist on <code>sourceTaskData</code> and <code>targetTaskData</code>.
- *
+ *
* @param sourceTaskData
* the source task data values are copied from, the connector kind of repository of
* <code>sourceTaskData</code> can be different from <code>targetTaskData</code>
@@ -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<String> getValues(@NonNull String attributeKey) {
TaskAttribute attribute = taskData.getRoot().getMappedAttribute(attributeKey);
@@ -367,6 +394,7 @@ public class TaskMapper implements ITaskMapping {
changed |= hasChanges(task.getModificationDate(), getModificationDate(), TaskAttribute.DATE_MODIFICATION);
changed |= hasChanges(task.getDueDate(), getDueDate(), TaskAttribute.DATE_DUE);
changed |= hasChanges(task.getOwner(), getOwner(), TaskAttribute.USER_ASSIGNED);
+ changed |= hasChanges(task.getOwnerId(), getOwnerId(), TaskAttribute.USER_ASSIGNED);
changed |= hasChanges(task.getPriority(), getPriorityLevelString(), TaskAttribute.PRIORITY);
changed |= hasChanges(task.getSummary(), getSummary(), TaskAttribute.SUMMARY);
changed |= hasChanges(task.getTaskKey(), getTaskKey(), TaskAttribute.TASK_KEY);
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskMapperTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskMapperTest.java
index acf2dc7f1..7427efa02 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskMapperTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/TaskMapperTest.java
@@ -17,6 +17,7 @@ import java.util.Map;
import junit.framework.TestCase;
+import org.eclipse.mylyn.internal.tasks.core.TaskTask;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.TaskAttachmentMapper;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
@@ -215,4 +216,35 @@ public class TaskMapperTest extends TestCase {
}
+ public void testApplyOwnerAndId() throws Exception {
+ TaskTask task = new TaskTask("kind", "http://url", "1");
+ TaskAttribute assigneeAttribute = source.getTaskData().getRoot().createAttribute(TaskAttribute.USER_ASSIGNED);
+ assigneeAttribute.putOption("joel.user", "Joel K. User");
+ assigneeAttribute.putOption("jacob.user", "Jacob F. User");
+
+ assigneeAttribute.setValue("joel.user");
+ assertOwnerAndId(task, "joel.user", "Joel K. User");
+
+ assigneeAttribute.setValue("jacob.user");
+ assertOwnerAndId(task, "jacob.user", "Jacob F. User");
+
+ assigneeAttribute.putOption("jacob.user", "Jacob Frederick User");
+ assertOwnerAndId(task, "jacob.user", "Jacob Frederick User");
+
+ assigneeAttribute.clearOptions();
+ assertOwnerAndId(task, "jacob.user", "jacob.user");
+
+ assigneeAttribute.setValue("joel.user");
+ assertOwnerAndId(task, "joel.user", "joel.user");
+ }
+
+ private void assertOwnerAndId(TaskTask task, String ownerId, String owner) {
+ assertTrue(source.hasChanges(task));
+ assertTrue(source.applyTo(task));
+ assertEquals(owner, task.getOwner());
+ assertEquals(ownerId, task.getOwnerId());
+ assertFalse(source.hasChanges(task));
+ assertFalse(source.applyTo(task));
+ }
+
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/AbstractRepositoryConnectorTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/AbstractRepositoryConnectorTest.java
index c7b4d190c..06dd4940b 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/AbstractRepositoryConnectorTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/AbstractRepositoryConnectorTest.java
@@ -11,8 +11,11 @@
package org.eclipse.mylyn.tasks.tests.core;
+import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
+import org.eclipse.mylyn.commons.net.AuthenticationType;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.tests.connector.MockTask;
import org.eclipse.mylyn.tasks.tests.util.MockRepositoryConnectorTestCase;
@@ -49,4 +52,50 @@ public class AbstractRepositoryConnectorTest extends MockRepositoryConnectorTest
assertNull(TasksUiInternal.getTaskByUrl(""));
}
+ public void testIsOwnedByUser() throws Exception {
+ assertIsOwnedByUser("joel.user", "joel.user", "joel.user", true);
+ assertIsOwnedByUser("joel.user", "Joel K. User", "joel.user", true);
+ assertIsOwnedByUser("joel.user", null, "joel.user", true);
+ assertIsOwnedByUser("joel.user", "joel.user", "123", true);
+ assertIsOwnedByUser("joel.user", "joel.user", null, true);
+ assertIsOwnedByUser("joel.user", "Joel K. User", "123", false);
+ assertIsOwnedByUser("joel.user", "Joel K. User", null, false);
+ assertIsOwnedByUser("joel.user", null, "123", false);
+ assertIsOwnedByUser("joel.user", null, null, false);
+ assertIsOwnedByUser(null, null, null, false);
+ assertIsOwnedByUser(null, null, "123", false);
+ assertIsOwnedByUser(null, "Joel K. User", null, false);
+ assertIsOwnedByUser(null, "joel.user", "joel.user", false);
+ }
+
+ private void assertIsOwnedByUser(String repositoryUserName, String taskOwner, String taskOwnerId, boolean expected) {
+ // if one parameter is null, test both the null and empty string cases; if multiple are null, don't bother
+ // testing all possible combinations of null and empty
+ if (repositoryUserName == null) {
+ assertIsOwnedByUserHelper(null, taskOwner, taskOwnerId, expected);
+ assertIsOwnedByUserHelper("", taskOwner, taskOwnerId, expected);
+ } else if (taskOwner == null) {
+ assertIsOwnedByUserHelper(repositoryUserName, null, taskOwnerId, expected);
+ assertIsOwnedByUserHelper(repositoryUserName, "", taskOwnerId, expected);
+ } else if (taskOwnerId == null) {
+ assertIsOwnedByUserHelper(repositoryUserName, taskOwner, null, expected);
+ assertIsOwnedByUserHelper(repositoryUserName, taskOwner, "", expected);
+ } else {
+ assertIsOwnedByUserHelper(repositoryUserName, taskOwner, taskOwnerId, expected);
+ }
+ }
+
+ private void assertIsOwnedByUserHelper(String repositoryUserName, String taskOwner, String taskOwnerId,
+ boolean expected) {
+ TaskRepository repository = new TaskRepository(MockRepositoryWithUrl.CONNECTOR_KIND,
+ MockRepositoryWithUrl.REPOSITORY_URL);
+ if (repositoryUserName != null) {
+ repository.setCredentials(AuthenticationType.REPOSITORY, new AuthenticationCredentials(repositoryUserName,
+ ""), false);
+ }
+ taskWithUrl.setOwner(taskOwner);
+ taskWithUrl.setOwnerId(taskOwnerId);
+ assertEquals(expected, connectorWithUrl.isOwnedByUser(repository, taskWithUrl));
+ }
+
}
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/MyTasksFilter.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/MyTasksFilter.java
index cec6d8673..e22fb5719 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/MyTasksFilter.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/internal/tasks/ui/MyTasksFilter.java
@@ -29,12 +29,10 @@ public class MyTasksFilter extends AbstractTaskListFilter {
}
if (element instanceof AbstractTask) {
AbstractTask task = (AbstractTask) element;
- String owner = task.getOwner();
TaskRepository repository = TasksUi.getRepositoryManager().getRepository(task.getConnectorKind(),
task.getRepositoryUrl());
- if (repository != null && repository.getUserName() != null
- && repository.getUserName().equalsIgnoreCase(owner)) {
- return true;
+ if (repository != null) {
+ return TasksUi.getRepositoryConnector(task.getConnectorKind()).isOwnedByUser(repository, task);
}
return false;
}

Back to the top