Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2009-11-19 02:08:58 +0000
committerspingel2009-11-19 02:08:58 +0000
commit449f183c7d5f4f6b7a8c224db89a202520817f9e (patch)
tree07667e0215e2f88c81b562ea14115e9e8a585f7e /org.eclipse.mylyn.tasks.core
parent63d1ce6c6411334bba819708dec21a8c3a1e7221 (diff)
downloadorg.eclipse.mylyn.tasks-449f183c7d5f4f6b7a8c224db89a202520817f9e.tar.gz
org.eclipse.mylyn.tasks-449f183c7d5f4f6b7a8c224db89a202520817f9e.tar.xz
org.eclipse.mylyn.tasks-449f183c7d5f4f6b7a8c224db89a202520817f9e.zip
NEW - bug 247595: extend TaskMapper with default schema
https://bugs.eclipse.org/bugs/show_bug.cgi?id=247595
Diffstat (limited to 'org.eclipse.mylyn.tasks.core')
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/DefaultTaskSchema.java240
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttachmentMapper.java36
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskCommentMapper.java18
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskMapper.java13
4 files changed, 277 insertions, 30 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/DefaultTaskSchema.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/DefaultTaskSchema.java
new file mode 100644
index 000000000..524a11b59
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/internal/tasks/core/data/DefaultTaskSchema.java
@@ -0,0 +1,240 @@
+/*******************************************************************************
+ * Copyright (c) 2009 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.tasks.core.data;
+
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import org.eclipse.core.runtime.Assert;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskAttributeMetaData;
+
+/**
+ * @author Steffen Pingel
+ */
+public class DefaultTaskSchema {
+
+ public static class Field {
+
+ private EnumSet<Flag> flags;
+
+ private final String key;
+
+ private final String label;
+
+ private final String type;
+
+ Field(String key, String label, String type) {
+ this(key, label, type, null);
+ }
+
+ Field(String key, String label, String type, Flag firstFlag, Flag... moreFlags) {
+ Assert.isNotNull(key);
+ Assert.isNotNull(label);
+ Assert.isNotNull(type);
+ this.key = key;
+ this.label = label;
+ this.type = type;
+ if (firstFlag == null) {
+ this.flags = NO_FLAGS;
+ } else {
+ this.flags = EnumSet.of(firstFlag, moreFlags);
+ }
+ }
+
+ public TaskAttribute createAttribute(TaskAttribute parent) {
+ TaskAttribute attribute = parent.createMappedAttribute(getKey());
+ // meta data
+ TaskAttributeMetaData metaData = attribute.getMetaData();
+ metaData.setLabel(getLabel());
+ metaData.setType(getType());
+ metaData.setReadOnly(isReadOnly());
+ metaData.setKind(getKind());
+ // options
+ Map<String, String> options = getDefaultOptions();
+ if (options != null) {
+ for (Entry<String, String> option : options.entrySet()) {
+ attribute.putOption(option.getKey(), option.getValue());
+ }
+ }
+ return attribute;
+ }
+
+ public Map<String, String> getDefaultOptions() {
+ return Collections.emptyMap();
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public String getKind() {
+ if (flags.contains(Flag.ATTRIBUTE)) {
+ return TaskAttribute.KIND_DEFAULT;
+ } else if (flags.contains(Flag.PEOPLE)) {
+ return TaskAttribute.KIND_PEOPLE;
+ }
+ return null;
+ }
+
+ public String getLabel() {
+ return label;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ public boolean isReadOnly() {
+ return flags.contains(Flag.READ_ONLY);
+ }
+
+ @Override
+ public String toString() {
+ return getLabel();
+ }
+
+ };
+
+ public enum Flag {
+ ATTRIBUTE, PEOPLE, READ_ONLY
+ }
+
+ private static Map<String, Field> fieldByKey = new HashMap<String, Field>();
+
+ public static final EnumSet<Flag> NO_FLAGS = EnumSet.noneOf(Flag.class);
+
+ public static Field getField(String taskKey) {
+ return fieldByKey.get(taskKey);
+ }
+
+ public static final Field ADD_SELF_CC = createField(TaskAttribute.ADD_SELF_CC, "Add Self to CC",
+ TaskAttribute.TYPE_BOOLEAN);
+
+ public static final Field ATTACHMENT_AUTHOR = createField(TaskAttribute.ATTACHMENT_AUTHOR, "Author",
+ TaskAttribute.TYPE_PERSON);
+
+ public static final Field ATTACHMENT_CONTENT_TYPE = createField(TaskAttribute.ATTACHMENT_CONTENT_TYPE,
+ "Content-Type", TaskAttribute.TYPE_SHORT_TEXT);
+
+ public static final Field ATTACHMENT_DATE = createField(TaskAttribute.ATTACHMENT_DATE, "Created",
+ TaskAttribute.TYPE_DATETIME);
+
+ public static final Field ATTACHMENT_DESCRIPTION = createField(TaskAttribute.ATTACHMENT_DESCRIPTION, "Description",
+ TaskAttribute.TYPE_SHORT_RICH_TEXT);
+
+ public static final Field ATTACHMENT_FILENAME = createField(TaskAttribute.ATTACHMENT_FILENAME, "Filename",
+ TaskAttribute.TYPE_SHORT_TEXT);
+
+ public static final Field ATTACHMENT_ID = createField(TaskAttribute.ATTACHMENT_ID, "ID",
+ TaskAttribute.TYPE_SHORT_TEXT, Flag.READ_ONLY);
+
+ public static final Field ATTACHMENT_IS_DEPRECATED = createField(TaskAttribute.ATTACHMENT_IS_DEPRECATED,
+ "Deprecated", TaskAttribute.TYPE_BOOLEAN);
+
+ public static final Field ATTACHMENT_IS_PATCH = createField(TaskAttribute.ATTACHMENT_IS_PATCH, "Patch",
+ TaskAttribute.TYPE_BOOLEAN);
+
+ public static final Field ATTACHMENT_SIZE = createField(TaskAttribute.ATTACHMENT_SIZE, "Size",
+ TaskAttribute.TYPE_LONG, Flag.READ_ONLY);
+
+ public static final Field ATTACHMENT_URL = createField(TaskAttribute.ATTACHMENT_URL, "URL", TaskAttribute.TYPE_URL);
+
+ public static final Field COMMENT_ATTACHMENT_ID = createField(TaskAttribute.COMMENT_ATTACHMENT_ID, "Attachment ID",
+ TaskAttribute.TYPE_SHORT_TEXT, Flag.READ_ONLY);
+
+ public static final Field COMMENT_AUTHOR = createField(TaskAttribute.COMMENT_AUTHOR, "Author",
+ TaskAttribute.TYPE_PERSON);
+
+ public static final Field COMMENT_DATE = createField(TaskAttribute.COMMENT_DATE, "Created",
+ TaskAttribute.TYPE_DATETIME);
+
+ public static final Field COMMENT_HAS_ATTACHMENT = createField(TaskAttribute.COMMENT_HAS_ATTACHMENT, "Attachment",
+ TaskAttribute.TYPE_BOOLEAN);
+
+ public static final Field COMMENT_NUMBER = createField(TaskAttribute.COMMENT_NUMBER, "Number",
+ TaskAttribute.TYPE_INTEGER, Flag.READ_ONLY);
+
+ public static final Field COMMENT_TEXT = createField(TaskAttribute.COMMENT_TEXT, "Description",
+ TaskAttribute.TYPE_LONG_RICH_TEXT);
+
+ public static final Field COMMENT_URL = createField(TaskAttribute.COMMENT_URL, "URL", TaskAttribute.TYPE_URL);
+
+ public static final Field COMPONENT = createField(TaskAttribute.COMPONENT, "Component",
+ TaskAttribute.TYPE_SINGLE_SELECT, Flag.ATTRIBUTE);
+
+ public static final Field DATE_COMPLETION = createField(TaskAttribute.DATE_COMPLETION, "Completion",
+ TaskAttribute.TYPE_DATE, Flag.READ_ONLY);
+
+ public static final Field DATE_CREATION = createField(TaskAttribute.DATE_CREATION, "Created",
+ TaskAttribute.TYPE_DATE, Flag.READ_ONLY);
+
+ public static final Field DATE_DUE = createField(TaskAttribute.DATE_DUE, "Due", TaskAttribute.TYPE_DATE);
+
+ public static final Field DATE_MODIFICATION = createField(TaskAttribute.DATE_MODIFICATION, "Modified",
+ TaskAttribute.TYPE_DATE, Flag.READ_ONLY);
+
+ public static final Field DESCRIPTION = createField(TaskAttribute.DESCRIPTION, "Description",
+ TaskAttribute.TYPE_LONG_RICH_TEXT);
+
+ public static final Field KEYWORDS = createField(TaskAttribute.KEYWORDS, "Keywords",
+ TaskAttribute.TYPE_MULTI_SELECT, Flag.ATTRIBUTE);
+
+ public static final Field PRIORITY = createField(TaskAttribute.PRIORITY, "Priority",
+ TaskAttribute.TYPE_SINGLE_SELECT, Flag.ATTRIBUTE);
+
+ public static final Field PRODUCT = createField(TaskAttribute.PRIORITY, "Product",
+ TaskAttribute.TYPE_SINGLE_SELECT, Flag.ATTRIBUTE);
+
+ public static final Field RANK = createField(TaskAttribute.RANK, "Rank", TaskAttribute.TYPE_INTEGER, Flag.READ_ONLY);
+
+ public static final Field RESOLUTION = createField(TaskAttribute.RESOLUTION, "Resolution",
+ TaskAttribute.TYPE_SINGLE_SELECT, Flag.READ_ONLY);
+
+ public static final Field SEVERITY = createField(TaskAttribute.SEVERITY, "Severity",
+ TaskAttribute.TYPE_SINGLE_SELECT, Flag.ATTRIBUTE);
+
+ public static final Field STATUS = createField(TaskAttribute.STATUS, "Status", TaskAttribute.TYPE_SHORT_TEXT,
+ Flag.READ_ONLY);
+
+ public static final Field SUMMARY = createField(TaskAttribute.SUMMARY, "Summary",
+ TaskAttribute.TYPE_SHORT_RICH_TEXT);
+
+ public static final Field TASK_KEY = createField(TaskAttribute.TASK_KEY, "Key", TaskAttribute.TYPE_SHORT_TEXT,
+ Flag.READ_ONLY);
+
+ public static final Field TASK_KIND = createField(TaskAttribute.TASK_KIND, "Kind",
+ TaskAttribute.TYPE_SINGLE_SELECT, Flag.ATTRIBUTE);
+
+ public static final Field USER_ASSIGNED = createField(TaskAttribute.USER_ASSIGNED, "Owner",
+ TaskAttribute.TYPE_PERSON, Flag.PEOPLE);
+
+ public static final Field USER_REPORTER = createField(TaskAttribute.USER_REPORTER, "Reporter",
+ TaskAttribute.TYPE_PERSON, Flag.PEOPLE);
+
+ public static final Field TASK_URL = createField(TaskAttribute.TASK_URL, "URL", TaskAttribute.TYPE_URL,
+ Flag.READ_ONLY);
+
+ private static Field createField(String key, String label, String type) {
+ return createField(key, label, type, null);
+ }
+
+ private static Field createField(String key, String label, String type, Flag firstFlag, Flag... moreFlags) {
+ Field field = new Field(key, label, type, firstFlag, moreFlags);
+ fieldByKey.put(key, field);
+ return field;
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttachmentMapper.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttachmentMapper.java
index 4007e61ff..935a9d431 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttachmentMapper.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttachmentMapper.java
@@ -14,6 +14,7 @@ package org.eclipse.mylyn.tasks.core.data;
import java.util.Date;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.mylyn.internal.tasks.core.data.DefaultTaskSchema;
import org.eclipse.mylyn.tasks.core.IRepositoryPerson;
import org.eclipse.mylyn.tasks.core.ITaskAttachment;
@@ -192,47 +193,48 @@ public class TaskAttachmentMapper {
mapper.setValue(taskAttribute, getAttachmentId());
}
if (getAuthor() != null) {
- TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_AUTHOR);
- child.getMetaData().defaults().setType(TaskAttribute.TYPE_PERSON);
+ TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.ATTACHMENT_AUTHOR).createAttribute(
+ taskAttribute);
mapper.setRepositoryPerson(child, getAuthor());
}
if (getContentType() != null) {
- TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_CONTENT_TYPE);
- child.getMetaData().defaults().setType(TaskAttribute.TYPE_SHORT_TEXT);
+ TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.ATTACHMENT_CONTENT_TYPE).createAttribute(
+ taskAttribute);
mapper.setValue(child, getContentType());
}
if (getCreationDate() != null) {
- TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_DATE);
- child.getMetaData().defaults().setType(TaskAttribute.TYPE_DATE);
+ TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.ATTACHMENT_DATE).createAttribute(
+ taskAttribute);
mapper.setDateValue(child, getCreationDate());
}
if (getDescription() != null) {
- TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_DESCRIPTION);
- child.getMetaData().defaults().setType(TaskAttribute.TYPE_SHORT_TEXT);
+ TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.ATTACHMENT_DESCRIPTION).createAttribute(
+ taskAttribute);
mapper.setValue(child, getDescription());
}
if (getFileName() != null) {
- TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_FILENAME);
- child.getMetaData().defaults().setType(TaskAttribute.TYPE_SHORT_TEXT);
+ TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.ATTACHMENT_FILENAME).createAttribute(
+ taskAttribute);
mapper.setValue(child, getFileName());
}
if (isDeprecated() != null) {
- TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_IS_DEPRECATED);
- child.getMetaData().defaults().setType(TaskAttribute.TYPE_BOOLEAN);
+ TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.ATTACHMENT_IS_DEPRECATED).createAttribute(
+ taskAttribute);
mapper.setBooleanValue(child, isDeprecated());
}
if (isPatch() != null) {
- TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_IS_PATCH);
- child.getMetaData().defaults().setType(TaskAttribute.TYPE_BOOLEAN);
+ TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.ATTACHMENT_IS_PATCH).createAttribute(
+ taskAttribute);
mapper.setBooleanValue(child, isPatch());
}
if (getLength() != null) {
- TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_SIZE);
+ TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.ATTACHMENT_SIZE).createAttribute(
+ taskAttribute);
mapper.setLongValue(child, getLength());
}
if (getUrl() != null) {
- TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.ATTACHMENT_URL);
- child.getMetaData().defaults().setType(TaskAttribute.TYPE_URL);
+ TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.ATTACHMENT_URL).createAttribute(
+ taskAttribute);
mapper.setValue(child, getUrl());
}
}
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskCommentMapper.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskCommentMapper.java
index d70c229cf..3df9d6c58 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskCommentMapper.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskCommentMapper.java
@@ -14,6 +14,7 @@ package org.eclipse.mylyn.tasks.core.data;
import java.util.Date;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.mylyn.internal.tasks.core.data.DefaultTaskSchema;
import org.eclipse.mylyn.tasks.core.IRepositoryPerson;
import org.eclipse.mylyn.tasks.core.ITaskComment;
@@ -133,28 +134,25 @@ public class TaskCommentMapper {
mapper.setValue(taskAttribute, getCommentId());
}
if (getAuthor() != null) {
- TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.COMMENT_AUTHOR);
- child.getMetaData().defaults().setType(TaskAttribute.TYPE_PERSON);
+ TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.COMMENT_AUTHOR).createAttribute(
+ taskAttribute);
mapper.setRepositoryPerson(child, getAuthor());
}
if (getCreationDate() != null) {
- TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.COMMENT_DATE);
- child.getMetaData().defaults().setType(TaskAttribute.TYPE_DATE);
+ TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.COMMENT_DATE).createAttribute(taskAttribute);
mapper.setDateValue(child, getCreationDate());
}
if (getNumber() != null) {
- TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.COMMENT_NUMBER);
- child.getMetaData().defaults().setType(TaskAttribute.TYPE_INTEGER);
+ TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.COMMENT_NUMBER).createAttribute(
+ taskAttribute);
mapper.setIntegerValue(child, getNumber());
}
if (getUrl() != null) {
- TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.COMMENT_URL);
- child.getMetaData().defaults().setType(TaskAttribute.TYPE_URL);
+ TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.COMMENT_URL).createAttribute(taskAttribute);
mapper.setValue(child, getUrl());
}
if (getText() != null) {
- TaskAttribute child = taskAttribute.createMappedAttribute(TaskAttribute.COMMENT_TEXT);
- child.getMetaData().defaults().setType(TaskAttribute.TYPE_LONG_RICH_TEXT);
+ TaskAttribute child = DefaultTaskSchema.getField(TaskAttribute.COMMENT_TEXT).createAttribute(taskAttribute);
mapper.setValue(child, getText());
taskAttribute.putMetaDatum(TaskAttribute.META_ASSOCIATED_ATTRIBUTE_ID, child.getId());
}
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 1a4107e8b..57fed5498 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
@@ -15,6 +15,8 @@ import java.util.Date;
import java.util.List;
import org.eclipse.core.runtime.Assert;
+import org.eclipse.mylyn.internal.tasks.core.data.DefaultTaskSchema;
+import org.eclipse.mylyn.internal.tasks.core.data.DefaultTaskSchema.Field;
import org.eclipse.mylyn.tasks.core.ITask;
import org.eclipse.mylyn.tasks.core.ITaskMapping;
import org.eclipse.mylyn.tasks.core.ITask.PriorityLevel;
@@ -181,9 +183,14 @@ public class TaskMapper implements ITaskMapping {
}
private TaskAttribute createAttribute(String attributeKey, String type) {
- attributeKey = taskData.getAttributeMapper().mapToRepositoryKey(taskData.getRoot(), attributeKey);
- TaskAttribute attribute = taskData.getRoot().createAttribute(attributeKey);
- attribute.getMetaData().defaults().setType(type);
+ TaskAttribute attribute;
+ Field field = DefaultTaskSchema.getField(attributeKey);
+ if (field != null) {
+ attribute = field.createAttribute(taskData.getRoot());
+ } else {
+ attribute = taskData.getRoot().createMappedAttribute(attributeKey);
+ attribute.getMetaData().defaults().setType(type);
+ }
return attribute;
}

Back to the top