490542: REST Connector: add support for "Reassign to default assignee"
(rebased version of patch set#1)
Change-Id: I6a3aff1ebb230d76db7fdb2064a6b13def360245
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=490542
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/internal/bugzilla/rest/core/tests/BugzillaRestClientTest.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/internal/bugzilla/rest/core/tests/BugzillaRestClientTest.java
index 0667cb2..8d3dbc9 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/internal/bugzilla/rest/core/tests/BugzillaRestClientTest.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core.tests/src/org/eclipse/mylyn/internal/bugzilla/rest/core/tests/BugzillaRestClientTest.java
@@ -488,6 +488,7 @@
 		taskDataGet.getRoot().removeAttribute("addCC");
 		taskDataGet.getRoot().removeAttribute("removeCC");
 		taskDataGet.getRoot().removeAttribute(BugzillaRestTaskSchema.getDefault().RESET_QA_CONTACT.getKey());
+		taskDataGet.getRoot().removeAttribute(BugzillaRestTaskSchema.getDefault().RESET_ASSIGNED_TO.getKey());
 
 		// attributes for operations
 		taskDataGet.getRoot().removeAttribute("task.common.operation-CONFIRMED");
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConfiguration.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConfiguration.java
index 8c4cc4e..49c3f78 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConfiguration.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConfiguration.java
@@ -122,7 +122,8 @@
 					|| key.equals(BugzillaRestTaskSchema.getDefault().NEW_COMMENT.getKey())
 					|| key.equals(BugzillaRestTaskSchema.getDefault().DUPE_OF.getKey())
 					|| key.equals(TaskAttribute.OPERATION)
-					|| key.equals(BugzillaRestTaskSchema.getDefault().DATE_MODIFICATION.getKey())) {
+					|| key.equals(BugzillaRestTaskSchema.getDefault().DATE_MODIFICATION.getKey())
+					|| key.equals(BugzillaRestTaskSchema.getDefault().RESET_ASSIGNED_TO.getKey())) {
 				continue;
 			}
 			TaskAttribute attribute = data.getRoot().getAttribute(key);
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPutUpdateTask.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPutUpdateTask.java
index fd35cb3..4dbd1af 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPutUpdateTask.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPutUpdateTask.java
@@ -80,6 +80,7 @@
 			.add(BugzillaRestTaskSchema.getDefault().DEPENDS_ON.getKey())
 			.add(BugzillaRestTaskSchema.getDefault().KEYWORDS.getKey())
 			.add(BugzillaRestTaskSchema.getDefault().RESET_QA_CONTACT.getKey())
+			.add(BugzillaRestTaskSchema.getDefault().RESET_ASSIGNED_TO.getKey())
 			.build();
 
 	class TaskAttributeTypeAdapter extends TypeAdapter<OldAttributes> {
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestTaskSchema.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestTaskSchema.java
index 677bd13..470a347 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestTaskSchema.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestTaskSchema.java
@@ -151,6 +151,9 @@
 	public final Field RESET_QA_CONTACT = createField("reset_qa_contact", "Reset QA Contact to default",
 			TaskAttribute.TYPE_BOOLEAN, Flag.PEOPLE);
 
+	public final Field RESET_ASSIGNED_TO = createField("reset_assigned_to", "Reassign to default assignee",
+			TaskAttribute.TYPE_BOOLEAN, Flag.PEOPLE);
+
 	@Override
 	public void initialize(TaskData taskData) {
 		for (Field field : getFields()) {
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestTaskEditorPage.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestTaskEditorPage.java
index dbc4c84..1898d36 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestTaskEditorPage.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestTaskEditorPage.java
@@ -11,13 +11,17 @@
 
 package org.eclipse.mylyn.internal.bugzilla.rest.ui;
 
+import java.util.Set;
+
 import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestCore;
 import org.eclipse.mylyn.internal.bugzilla.rest.core.IBugzillaRestConstants;
 import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
 import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
 import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPage;
+import org.eclipse.mylyn.tasks.ui.editors.AbstractTaskEditorPart;
 import org.eclipse.mylyn.tasks.ui.editors.AttributeEditorFactory;
 import org.eclipse.mylyn.tasks.ui.editors.TaskEditor;
+import org.eclipse.mylyn.tasks.ui.editors.TaskEditorPartDescriptor;
 
 public class BugzillaRestTaskEditorPage extends AbstractTaskEditorPage {
 
@@ -51,4 +55,25 @@
 		return factory;
 	}
 
+	@Override
+	protected Set<TaskEditorPartDescriptor> createPartDescriptors() {
+		Set<TaskEditorPartDescriptor> descriptors = super.createPartDescriptors();
+		// remove unnecessary default editor parts
+		for (TaskEditorPartDescriptor taskEditorPartDescriptor : descriptors) {
+			if (taskEditorPartDescriptor.getId().equals(ID_PART_PEOPLE)) {
+				descriptors.remove(taskEditorPartDescriptor);
+				break;
+			}
+		}
+		// Add the updated Bugzilla people part
+		descriptors.add(new TaskEditorPartDescriptor(ID_PART_PEOPLE) {
+			@Override
+			public AbstractTaskEditorPart createPart() {
+				return new BugzillaRestTaskEditorPeoplePart();
+			}
+		}.setPath(PATH_PEOPLE));
+
+		return descriptors;
+	}
+
 }
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestTaskEditorPeoplePart.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestTaskEditorPeoplePart.java
new file mode 100644
index 0000000..08b6282
--- /dev/null
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestTaskEditorPeoplePart.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2016 Tasktop Technologies and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.bugzilla.rest.ui;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestTaskSchema;
+import org.eclipse.mylyn.internal.tasks.ui.editors.TaskEditorPeoplePart;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData;
+
+public class BugzillaRestTaskEditorPeoplePart extends TaskEditorPeoplePart {
+
+	@Override
+	protected Collection<TaskAttribute> getAttributes() {
+		Map<String, TaskAttribute> allAttributes = getTaskData().getRoot().getAttributes();
+		List<TaskAttribute> attributes = new ArrayList<TaskAttribute>(allAttributes.size());
+		attributes.add(getTaskData().getRoot().getMappedAttribute(TaskAttribute.USER_ASSIGNED));
+		attributes.add(getTaskData().getRoot()
+				.getMappedAttribute(BugzillaRestTaskSchema.getDefault().RESET_ASSIGNED_TO.getKey()));
+		attributes.add(getTaskData().getRoot().getMappedAttribute(TaskAttribute.USER_REPORTER));
+		attributes.add(getTaskData().getRoot().getMappedAttribute(TaskAttribute.ADD_SELF_CC));
+		attributes.add(getTaskData().getRoot().getMappedAttribute(TaskAttribute.USER_CC));
+		for (TaskAttribute attribute : allAttributes.values()) {
+			TaskAttributeMetaData properties = attribute.getMetaData();
+			if (TaskAttribute.KIND_PEOPLE.equals(properties.getKind())) {
+				if (!attributes.contains(attribute)) {
+					attributes.add(attribute);
+				}
+			}
+		}
+		return attributes;
+	}
+
+}