summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiles Parker2012-09-09 21:36:15 (EDT)
committer Steffen Pingel2012-09-09 21:36:15 (EDT)
commit68d3bf8c09357d5965be2074e134cfce92386276 (patch)
tree63288b6f694439df29681253cbe63e6542aaaed2
parent1b9aac0aa26a56dc4c6b8d4427ae6a89d9a63cf5 (diff)
downloadorg.eclipse.mylyn.tasks-68d3bf8c09357d5965be2074e134cfce92386276.zip
org.eclipse.mylyn.tasks-68d3bf8c09357d5965be2074e134cfce92386276.tar.gz
org.eclipse.mylyn.tasks-68d3bf8c09357d5965be2074e134cfce92386276.tar.bz2
ASSIGNED - bug 387492: [api] provide iterators and other services forrefs/changes/73/7273/3
TaskSchema https://bugs.eclipse.org/bugs/show_bug.cgi?id=387492 Change-Id: I00a0c80eb8b03e71d71cc3d205c4608b1ebf38bb Signed-off-by: Miles Parker <milesparker@gmail.com>
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/AbstractTaskSchema.java20
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/DefaultTaskSchemaTest.java38
2 files changed, 58 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/AbstractTaskSchema.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/AbstractTaskSchema.java
index a70db57..4bb6cb1 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/AbstractTaskSchema.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/AbstractTaskSchema.java
@@ -11,7 +11,9 @@
package org.eclipse.mylyn.tasks.core.data;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.EnumSet;
import java.util.LinkedHashMap;
@@ -25,6 +27,7 @@ import org.eclipse.core.runtime.Assert;
*
* @author Steffen Pingel
* @author David Green
+ * @author Miles Parker
* @since 3.5
*/
public abstract class AbstractTaskSchema {
@@ -248,16 +251,33 @@ public abstract class AbstractTaskSchema {
private final Map<String, Field> fieldByKey = new LinkedHashMap<String, Field>();
+ /**
+ * Returns the specified field for the given key.
+ */
public Field getFieldByKey(String taskKey) {
return fieldByKey.get(taskKey);
}
+ /**
+ * Creates no-value attributes with default options for the supplied task for each schema field.
+ */
public void initialize(TaskData taskData) {
for (Field field : fieldByKey.values()) {
field.createAttribute(taskData.getRoot());
}
}
+ /**
+ * Provides an iterator for all fields within the schema. Subsequent modifications to the returned collection are
+ * not reflected to schema.
+ *
+ * @since 3.9
+ * @return all fields within the schema
+ */
+ public Collection<Field> getFields() {
+ return new ArrayList<Field>(fieldByKey.values());
+ }
+
protected Field createField(String key, String label, String type) {
return createField(key, label, type, null, (Flag[]) null);
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/DefaultTaskSchemaTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/DefaultTaskSchemaTest.java
index bb6942b..f4215af 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/DefaultTaskSchemaTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/DefaultTaskSchemaTest.java
@@ -11,14 +11,23 @@
package org.eclipse.mylyn.tasks.tests.core;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.Set;
+
import junit.framework.TestCase;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.AbstractTaskSchema;
+import org.eclipse.mylyn.tasks.core.data.AbstractTaskSchema.Field;
import org.eclipse.mylyn.tasks.core.data.DefaultTaskSchema;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
/**
* @author Steffen Pingel
+ * @author Miles Parker
*/
public class DefaultTaskSchemaTest extends TestCase {
@@ -55,4 +64,33 @@ public class DefaultTaskSchemaTest extends TestCase {
assertFalse(schema.REPORTER_MODIFIED.isReadOnly());
}
+ public void testIterator() {
+ AbstractTaskSchema schema = new DefaultTaskSchema();
+ Iterator<Field> fields = schema.getFields().iterator();
+ int i = 0;
+ Set<String> attributeIds = new HashSet<String>();
+ while (fields.hasNext()) {
+ Field next = fields.next();
+ attributeIds.add(next.getKey());
+ i++;
+ }
+ //Let's allow for adding fields to default schema without breaking test, but assume that no-existing attributes will be removed
+ assertTrue("Actual Attribute Count: " + i, i >= 40);
+ assertTrue(attributeIds.contains(TaskAttribute.ADD_SELF_CC));
+ assertTrue(attributeIds.contains(TaskAttribute.ATTACHMENT_AUTHOR));
+ assertTrue(attributeIds.contains(TaskAttribute.SUMMARY));
+ }
+
+ public void testInitializeTaskData() {
+ AbstractTaskSchema schema = new DefaultTaskSchema();
+ TaskData testData = new TaskData(new TaskAttributeMapper(new TaskRepository("mock", "http://mock")), "mock",
+ "http://mock", "-1");
+ schema.initialize(testData);
+ int size = testData.getRoot().getAttributes().values().size();
+ //Let's allow for adding fields to default schema without breaking test, but assume that no-existing attributes will be removed
+ assertTrue("Actual Attribute Count: " + size, size >= 40);
+ assertNotNull(testData.getRoot().getAttribute(TaskAttribute.ADD_SELF_CC));
+ assertNotNull(testData.getRoot().getAttribute(TaskAttribute.ATTACHMENT_ID));
+ assertNotNull(testData.getRoot().getAttribute(TaskAttribute.SUMMARY));
+ }
}