Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorspingel2008-06-01 02:55:17 +0000
committerspingel2008-06-01 02:55:17 +0000
commitf9bcb12c35ed1d071bd36024efb03124ae055e49 (patch)
treef45cca8f68db52da977e7b7c689e72823b237125 /org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data
parent52431c05795f159fe2b7f30fc1d2934b4f32c134 (diff)
downloadorg.eclipse.mylyn.tasks-f9bcb12c35ed1d071bd36024efb03124ae055e49.tar.gz
org.eclipse.mylyn.tasks-f9bcb12c35ed1d071bd36024efb03124ae055e49.tar.xz
org.eclipse.mylyn.tasks-f9bcb12c35ed1d071bd36024efb03124ae055e49.zip
RESOLVED - bug 225033: [api] ensure consistent naming of API classes and methods
https://bugs.eclipse.org/bugs/show_bug.cgi?id=225033
Diffstat (limited to 'org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data')
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMapper.java21
-rw-r--r--org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskMapper.java325
2 files changed, 191 insertions, 155 deletions
diff --git a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMapper.java b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMapper.java
index a3d2dea05..7617214b1 100644
--- a/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMapper.java
+++ b/org.eclipse.mylyn.tasks.core/src/org/eclipse/mylyn/tasks/core/data/TaskAttributeMapper.java
@@ -8,7 +8,6 @@
package org.eclipse.mylyn.tasks.core.data;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
@@ -65,7 +64,7 @@ public class TaskAttributeMapper {
return null;
}
- public TaskAttribute[] getAttributesByType(TaskData taskData, String type) {
+ public List<TaskAttribute> getAttributesByType(TaskData taskData, String type) {
Assert.isNotNull(taskData);
Assert.isNotNull(type);
List<TaskAttribute> result = new ArrayList<TaskAttribute>();
@@ -74,7 +73,7 @@ public class TaskAttributeMapper {
result.add(taskAttribute);
}
}
- return result.toArray(new TaskAttribute[0]);
+ return result;
}
public boolean getBooleanValue(TaskAttribute attribute) {
@@ -145,7 +144,7 @@ public class TaskAttributeMapper {
return person;
}
- public TaskOperation[] getTaskOperations(TaskAttribute operationsAttribute) {
+ public List<TaskOperation> getTaskOperations(TaskAttribute operationsAttribute) {
Assert.isNotNull(operationsAttribute);
TaskData taskData = operationsAttribute.getTaskData();
List<TaskOperation> result = new ArrayList<TaskOperation>();
@@ -155,7 +154,7 @@ public class TaskAttributeMapper {
result.add(TaskOperation.createFrom(taskAttribute));
}
}
- return result.toArray(new TaskOperation[0]);
+ return result;
}
public TaskOperation getTaskOperation(TaskAttribute taskAttribute) {
@@ -189,7 +188,7 @@ public class TaskAttributeMapper {
return sb.toString();
}
- public String[] getValueLabels(TaskAttribute taskAttribute) {
+ public List<String> getValueLabels(TaskAttribute taskAttribute) {
List<String> values = taskAttribute.getValues();
List<String> result = new ArrayList<String>(values.size());
for (String value : values) {
@@ -199,11 +198,11 @@ public class TaskAttributeMapper {
}
result.add(value);
}
- return result.toArray(new String[0]);
+ return result;
}
- public String[] getValues(TaskAttribute attribute) {
- return attribute.getValues().toArray(new String[0]);
+ public List<String> getValues(TaskAttribute attribute) {
+ return new ArrayList<String>(attribute.getValues());
}
public boolean hasValue(TaskAttribute attribute) {
@@ -260,8 +259,8 @@ public class TaskAttributeMapper {
attribute.setValue(value);
}
- public void setValues(TaskAttribute attribute, String[] values) {
- attribute.setValues(Arrays.asList(values));
+ public void setValues(TaskAttribute attribute, List<String> values) {
+ attribute.setValues(values);
}
public void updateTaskAttachment(ITaskAttachment taskAttachment, TaskAttribute taskAttribute) {
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 f3c9fb41b..f3501085c 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
@@ -22,65 +22,158 @@ import org.eclipse.mylyn.tasks.core.ITask.PriorityLevel;
*/
public class TaskMapper implements ITaskMapping {
+ private final boolean createNonExistingAttributes;
+
private final TaskData taskData;
public TaskMapper(TaskData taskData) {
+ this(taskData, false);
+ }
+
+ public TaskMapper(TaskData taskData, boolean createNonExistingAttributes) {
+ this.createNonExistingAttributes = createNonExistingAttributes;
Assert.isNotNull(taskData);
this.taskData = taskData;
}
public boolean applyTo(ITask task) {
boolean changed = false;
- if ((task.getCompletionDate() != null && getCompletionDate() == null) //
- || hasTaskPropertyChanged(task.getCompletionDate(), getCompletionDate())) {
+ if (hasChanges(task.getCompletionDate(), TaskAttribute.DATE_COMPLETION)) {
task.setCompletionDate(getCompletionDate());
changed = true;
}
- if (hasTaskPropertyChanged(task.getCreationDate(), getCreationDate())) {
+ if (hasChanges(task.getCreationDate(), TaskAttribute.DATE_CREATION)) {
task.setCreationDate(getCreationDate());
changed = true;
}
- if (hasTaskPropertyChanged(task.getModificationDate(), getModificationDate())) {
+ if (hasChanges(task.getModificationDate(), TaskAttribute.DATE_MODIFICATION)) {
task.setModificationDate(getModificationDate());
changed = true;
}
- if (hasTaskPropertyChanged(task.getDueDate(), getDueDate())) {
+ if (hasChanges(task.getDueDate(), TaskAttribute.DATE_DUE)) {
task.setDueDate(getDueDate());
changed = true;
}
- if (hasTaskPropertyChanged(task.getOwner(), getOwner())) {
+ if (hasChanges(task.getOwner(), TaskAttribute.USER_ASSIGNED)) {
task.setOwner(getOwner());
changed = true;
}
- if (getPriority() != null && hasTaskPropertyChanged(task.getPriority(), getPriority().toString())) {
- task.setPriority(getPriority().toString());
+ if (hasChanges(task.getPriority(), TaskAttribute.PRIORITY)) {
+ if (getPriority() != null) {
+ task.setPriority(getPriority().toString());
+ } else {
+ task.setPriority(PriorityLevel.getDefault().toString());
+ }
changed = true;
}
- if (hasTaskPropertyChanged(task.getSummary(), getSummary())) {
+ if (hasChanges(task.getSummary(), TaskAttribute.SUMMARY)) {
task.setSummary(getSummary());
changed = true;
}
- if (hasTaskPropertyChanged(task.getTaskKey(), getTaskKey())) {
+ if (hasChanges(task.getTaskKey(), TaskAttribute.TASK_KEY)) {
task.setTaskKey(getTaskKey());
changed = true;
}
- if (hasTaskPropertyChanged(task.getTaskKind(), getTaskKind())) {
+ if (hasChanges(task.getTaskKind(), TaskAttribute.TASK_KIND)) {
task.setTaskKind(getTaskKind());
changed = true;
}
- if (hasTaskPropertyChanged(task.getUrl(), getTaskUrl())) {
+ if (hasChanges(task.getUrl(), TaskAttribute.TASK_URL)) {
task.setUrl(getTaskUrl());
changed = true;
}
return changed;
}
- protected boolean getBooleanValue(String attributeKey) {
- TaskAttribute attribute = taskData.getRoot().getMappedAttribute(attributeKey);
- if (attribute != null) {
- return taskData.getAttributeMapper().getBooleanValue(attribute);
+ private boolean areEquals(Object existingProperty, Object newProperty) {
+ return (existingProperty != null) ? !existingProperty.equals(newProperty) : newProperty != null;
+ }
+
+ private void copyAttributeValue(TaskAttribute sourceAttribute, TaskAttribute targetAttribute) {
+ if (targetAttribute == null) {
+ return;
+ }
+ if (!sourceAttribute.getMetaData().isReadOnly() && !targetAttribute.getMetaData().isReadOnly()) {
+ targetAttribute.clearValues();
+ if (targetAttribute.getOptions().size() > 0) {
+ List<String> values = sourceAttribute.getValues();
+ for (String value : values) {
+ if (targetAttribute.getOptions().containsValue(value)) {
+ targetAttribute.addValue(value);
+ }
+ }
+ } else {
+ List<String> values = sourceAttribute.getValues();
+ for (String value : values) {
+ targetAttribute.addValue(value);
+ }
+ }
}
- return false;
+ }
+
+ /**
+ * TODO update comment
+ *
+ * Sets attribute values from <code>sourceTaskData</code> on <code>targetTaskData</code>. Sets the following
+ * attributes:
+ * <ul>
+ * <li>summary
+ * <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>
+ * @param targetTaskData
+ * the target task data values are copied to, the connector kind matches the one of this task data
+ * handler
+ * @since 2.2
+ */
+ public void copyFrom(ITaskMapping source) {
+ if (source.getTaskData() != null && this.getTaskData() != null
+ && source.getTaskData().equals(this.getTaskData().getConnectorKind())) {
+ // task data objects are from the same connector, copy all attributes
+ for (TaskAttribute sourceAttribute : source.getTaskData().getRoot().getAttributes().values()) {
+ copyAttributeValue(sourceAttribute, this.getTaskData().getRoot().getAttribute(sourceAttribute.getId()));
+ }
+ } else {
+ if (source.getCc() != null) {
+ setCc(source.getCc());
+ }
+ if (source.getDescription() != null) {
+ setDescription(source.getDescription());
+ }
+ if (source.getComponent() != null) {
+ setComponent(source.getComponent());
+ }
+ if (source.getKeywords() != null) {
+ setKeywords(source.getKeywords());
+ }
+ if (source.getOwner() != null) {
+ setOwner(source.getOwner());
+ }
+ if (source.getPriority() != null) {
+ setPriority(source.getPriority());
+ }
+ if (source.getProduct() != null) {
+ setProduct(source.getProduct());
+ }
+ if (source.getSummary() != null) {
+ setSummary(source.getSummary());
+ }
+
+ }
+ }
+
+ private TaskAttribute createAttribute(String attributeKey) {
+ attributeKey = taskData.getAttributeMapper().mapToRepositoryKey(taskData.getRoot(), attributeKey);
+ TaskAttribute attribute = taskData.getRoot().createAttribute(attributeKey);
+ return attribute;
+ }
+
+ public List<String> getCc() {
+ return getValues(TaskAttribute.USER_CC);
}
public Date getCompletionDate() {
@@ -95,7 +188,7 @@ public class TaskMapper implements ITaskMapping {
return getDateValue(TaskAttribute.DATE_CREATION);
}
- protected Date getDateValue(String attributeKey) {
+ private Date getDateValue(String attributeKey) {
TaskAttribute attribute = taskData.getRoot().getMappedAttribute(attributeKey);
if (attribute != null) {
return taskData.getAttributeMapper().getDateValue(attribute);
@@ -111,6 +204,18 @@ public class TaskMapper implements ITaskMapping {
return getDateValue(TaskAttribute.DATE_DUE);
}
+ public List<String> getKeywords() {
+ return getValues(TaskAttribute.KEYWORDS);
+ }
+
+ private TaskAttribute getMappedAttribute(String attributeKey) {
+ TaskAttribute attribute = taskData.getRoot().getMappedAttribute(attributeKey);
+ if (createNonExistingAttributes && attribute == null) {
+ attribute = createAttribute(attributeKey);
+ }
+ return attribute;
+ }
+
public Date getModificationDate() {
return getDateValue(TaskAttribute.DATE_MODIFICATION);
}
@@ -128,6 +233,14 @@ public class TaskMapper implements ITaskMapping {
return getValue(TaskAttribute.PRODUCT);
}
+ public String getReporter() {
+ return getValue(TaskAttribute.USER_REPORTER);
+ }
+
+ public String getResolution() {
+ return getValue(TaskAttribute.RESOLUTION);
+ }
+
public String getSummary() {
return getValue(TaskAttribute.SUMMARY);
}
@@ -144,11 +257,15 @@ public class TaskMapper implements ITaskMapping {
return getValue(TaskAttribute.TASK_KIND);
}
+ public String getTaskStatus() {
+ return getValue(TaskAttribute.STATUS);
+ }
+
public String getTaskUrl() {
return getValue(TaskAttribute.TASK_URL);
}
- public String getValue(String attributeKey) {
+ private String getValue(String attributeKey) {
TaskAttribute attribute = taskData.getRoot().getMappedAttribute(attributeKey);
if (attribute != null) {
return taskData.getAttributeMapper().getValueLabel(attribute);
@@ -156,7 +273,7 @@ public class TaskMapper implements ITaskMapping {
return null;
}
- public String[] getValues(String attributeKey) {
+ private List<String> getValues(String attributeKey) {
TaskAttribute attribute = taskData.getRoot().getMappedAttribute(attributeKey);
if (attribute != null) {
return taskData.getAttributeMapper().getValueLabels(attribute);
@@ -164,27 +281,39 @@ public class TaskMapper implements ITaskMapping {
return null;
}
- protected boolean hasTaskPropertyChanged(Object existingProperty, Object newProperty) {
- // the query hit does not have this property
- if (newProperty == null) {
- return false;
- }
- return (existingProperty == null) ? true : !existingProperty.equals(newProperty);
+ public boolean hasChanges(ITask task) {
+ boolean changed = false;
+ changed |= hasChanges(task.getCompletionDate(), TaskAttribute.DATE_COMPLETION);
+ changed |= hasChanges(task.getCreationDate(), TaskAttribute.DATE_CREATION);
+ changed |= hasChanges(task.getModificationDate(), TaskAttribute.DATE_MODIFICATION);
+ changed |= hasChanges(task.getDueDate(), TaskAttribute.DATE_DUE);
+ changed |= hasChanges(task.getOwner(), TaskAttribute.USER_ASSIGNED);
+ changed |= hasChanges(task.getPriority(), TaskAttribute.PRIORITY);
+ changed |= hasChanges(task.getSummary(), TaskAttribute.SUMMARY);
+ changed |= hasChanges(task.getTaskKey(), TaskAttribute.TASK_KEY);
+ changed |= hasChanges(task.getTaskKind(), TaskAttribute.TASK_KIND);
+ changed |= hasChanges(task.getUrl(), TaskAttribute.TASK_URL);
+ return changed;
}
- public TaskAttribute setBooleanValue(String attributeKey, boolean value) {
+ private boolean hasChanges(Object value, String attributeKey) {
TaskAttribute attribute = taskData.getRoot().getMappedAttribute(attributeKey);
- if (attribute == null) {
- attribute = createAttribute(attributeKey);
+ if (attribute != null) {
+ if (TaskAttribute.TYPE_BOOLEAN.equals(attribute.getMetaData().getType())) {
+ return areEquals(value, taskData.getAttributeMapper().getBooleanValue(attribute));
+ } else if (TaskAttribute.TYPE_DATE.equals(attribute.getMetaData().getType())) {
+ return areEquals(value, taskData.getAttributeMapper().getDateValue(attribute));
+ } else if (TaskAttribute.TYPE_INTEGER.equals(attribute.getMetaData().getType())) {
+ return areEquals(value, taskData.getAttributeMapper().getIntegerValue(attribute));
+ } else {
+ return areEquals(value, taskData.getAttributeMapper().getValue(attribute));
+ }
}
- taskData.getAttributeMapper().setBooleanValue(attribute, value);
- return attribute;
+ return false;
}
- private TaskAttribute createAttribute(String attributeKey) {
- attributeKey = taskData.getAttributeMapper().mapToRepositoryKey(taskData.getRoot(), attributeKey);
- TaskAttribute attribute = taskData.getRoot().createAttribute(attributeKey);
- return attribute;
+ public void setCc(List<String> cc) {
+ setValues(TaskAttribute.USER_CC, cc);
}
public void setCompletionDate(Date dateCompleted) {
@@ -199,12 +328,11 @@ public class TaskMapper implements ITaskMapping {
setDateValue(TaskAttribute.DATE_CREATION, dateCreated);
}
- protected TaskAttribute setDateValue(String attributeKey, Date value) {
- TaskAttribute attribute = taskData.getRoot().getMappedAttribute(attributeKey);
- if (attribute == null) {
- attribute = createAttribute(attributeKey);
+ private TaskAttribute setDateValue(String attributeKey, Date value) {
+ TaskAttribute attribute = getMappedAttribute(attributeKey);
+ if (attribute != null) {
+ taskData.getAttributeMapper().setDateValue(attribute, value);
}
- taskData.getAttributeMapper().setDateValue(attribute, value);
return attribute;
}
@@ -216,6 +344,10 @@ public class TaskMapper implements ITaskMapping {
setDateValue(TaskAttribute.DATE_DUE, value);
}
+ public void setKeywords(List<String> keywords) {
+ setValues(TaskAttribute.KEYWORDS, keywords);
+ }
+
public void setModificationDate(Date dateModified) {
setDateValue(TaskAttribute.DATE_MODIFICATION, dateModified);
}
@@ -250,116 +382,21 @@ public class TaskMapper implements ITaskMapping {
setValue(TaskAttribute.TASK_URL, taskUrl);
}
- protected TaskAttribute setValue(String attributeKey, String value) {
- TaskAttribute attribute = taskData.getRoot().getMappedAttribute(attributeKey);
- if (attribute == null) {
- attribute = createAttribute(attributeKey);
+ private TaskAttribute setValue(String attributeKey, String value) {
+ TaskAttribute attribute = getMappedAttribute(attributeKey);
+ if (attribute != null) {
+ taskData.getAttributeMapper().setValue(attribute, value);
}
- taskData.getAttributeMapper().setValue(attribute, value);
return attribute;
- }
- /**
- * TODO update comment
- *
- * Sets attribute values from <code>sourceTaskData</code> on <code>targetTaskData</code>. Sets the following
- * attributes:
- * <ul>
- * <li>summary
- * <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>
- * @param targetTaskData
- * the target task data values are copied to, the connector kind matches the one of this task data
- * handler
- * @since 2.2
- */
- public void copyFrom(ITaskMapping source) {
- if (source.getTaskData() != null && this.getTaskData() != null
- && source.getTaskData().equals(this.getTaskData().getConnectorKind())) {
- // task data objects are from the same connector, copy all attributes
- for (TaskAttribute sourceAttribute : source.getTaskData().getRoot().getAttributes().values()) {
- copyAttributeValue(sourceAttribute, this.getTaskData().getRoot().getAttribute(sourceAttribute.getId()));
- }
- } else {
- if (source.getDescription() != null) {
- setDescription(source.getDescription());
- }
- if (source.getSummary() != null) {
- setSummary(source.getSummary());
- }
- if (source.getPriority() != null) {
- setPriority(source.getPriority());
- }
- if (source.getProduct() != null) {
- setProduct(source.getProduct());
- }
- }
-// targetTaskData.setSummary(sourceTaskData.getSummary());
-// targetTaskData.setDescription(sourceTaskData.getDescription());
-// if (sourceTaskData.getConnectorKind().equals(targetTaskData.getConnectorKind())
-// && sourceTaskData.getTaskKind().equals(targetTaskData.getTaskKind())) {
-// } else {
-// // map attributes from common schema
-// String[] commonAttributeKeys = new String[] { RepositoryTaskAttribute.KEYWORDS,
-// RepositoryTaskAttribute.PRIORITY, RepositoryTaskAttribute.PRODUCT,
-// RepositoryTaskAttribute.COMPONENT, RepositoryTaskAttribute.RESOLUTION,
-// RepositoryTaskAttribute.USER_ASSIGNED, RepositoryTaskAttribute.USER_CC, };
-// for (String key : commonAttributeKeys) {
-// RepositoryTaskAttribute sourceAttribute = sourceTaskData.getAttribute(key);
-// if (sourceAttribute != null) {
-// copyAttributeValue(sourceAttribute, targetTaskData.getAttribute(key));
-// }
-// }
-// }
}
- private void copyAttributeValue(TaskAttribute sourceAttribute, TaskAttribute targetAttribute) {
- if (targetAttribute == null) {
- return;
- }
- if (!sourceAttribute.getMetaData().isReadOnly() && !targetAttribute.getMetaData().isReadOnly()) {
- targetAttribute.clearValues();
- if (targetAttribute.getOptions().size() > 0) {
- List<String> values = sourceAttribute.getValues();
- for (String value : values) {
- if (targetAttribute.getOptions().containsValue(value)) {
- targetAttribute.addValue(value);
- }
- }
- } else {
- List<String> values = sourceAttribute.getValues();
- for (String value : values) {
- targetAttribute.addValue(value);
- }
- }
+ private TaskAttribute setValues(String attributeKey, List<String> values) {
+ TaskAttribute attribute = getMappedAttribute(attributeKey);
+ if (attribute != null) {
+ taskData.getAttributeMapper().setValues(attribute, values);
}
- }
-
- public String[] getCc() {
- // ignore
- return null;
- }
-
- public String[] getKeywords() {
- // ignore
- return null;
- }
-
- public String getReporter() {
- return getValue(TaskAttribute.USER_REPORTER);
- }
-
- public String getResolution() {
- return getValue(TaskAttribute.RESOLUTION);
- }
-
- public String getTaskStatus() {
- return getValue(TaskAttribute.STATUS);
+ return attribute;
}
}

Back to the top