summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin Sawicki2011-04-13 19:43:50 (EDT)
committerChris Aniszczyk2011-04-14 11:07:32 (EDT)
commit8d1fdd24dd440ddb91a5d578ceba6fee745b00bc (patch)
treed8c6ab7d67891a57916c5da0a73c8d6595a936a3
parent1e11979bbbe8340b309e985dbd8941c6feb0c0ae (diff)
downloadegit-github-8d1fdd24dd440ddb91a5d578ceba6fee745b00bc.zip
egit-github-8d1fdd24dd440ddb91a5d578ceba6fee745b00bc.tar.gz
egit-github-8d1fdd24dd440ddb91a5d578ceba6fee745b00bc.tar.bz2
Add initial gist task data handlerrefs/changes/03/3103/2
Change-Id: I7188109e80eed229f380600cf9ca46b20fa39916 Signed-off-by: Kevin Sawicki <kevin@github.com> Signed-off-by: Chris Aniszczyk <caniszczyk@gmail.com>
-rw-r--r--org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java142
1 files changed, 142 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java
new file mode 100644
index 0000000..60f8299
--- /dev/null
+++ b/org.eclipse.mylyn.github.core/src/org/eclipse/mylyn/internal/github/core/gist/GistTaskDataHandler.java
@@ -0,0 +1,142 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * 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:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.mylyn.internal.github.core.gist;
+
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.mylyn.github.internal.Comment;
+import org.eclipse.mylyn.github.internal.Gist;
+import org.eclipse.mylyn.github.internal.GitHubTaskAttributeMapper;
+import org.eclipse.mylyn.github.internal.User;
+import org.eclipse.mylyn.tasks.core.IRepositoryPerson;
+import org.eclipse.mylyn.tasks.core.ITaskMapping;
+import org.eclipse.mylyn.tasks.core.RepositoryResponse;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
+import org.eclipse.mylyn.tasks.core.data.TaskCommentMapper;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+
+/**
+ * Gist task data handler class.
+ */
+public class GistTaskDataHandler extends AbstractTaskDataHandler {
+
+ /**
+ * Fill task data with comments
+ *
+ * @param repository
+ * @param data
+ * @param comments
+ * @return specified task data
+ */
+ public TaskData fillComments(TaskRepository repository, TaskData data,
+ List<Comment> comments) {
+ if (comments == null || comments.isEmpty())
+ return data;
+
+ int count = 1;
+ TaskAttribute root = data.getRoot();
+ for (Comment comment : comments) {
+ TaskCommentMapper commentMapper = new TaskCommentMapper();
+ User author = comment.getUser();
+ if (author != null) {
+ IRepositoryPerson authorPerson = repository.createPerson(author
+ .getLogin());
+ authorPerson.setName(author.getName());
+ commentMapper.setAuthor(authorPerson);
+ }
+ commentMapper.setCreationDate(comment.getCreatedAt());
+ commentMapper.setText(comment.getBody());
+ commentMapper.setCommentId(comment.getUrl());
+ commentMapper.setNumber(count);
+
+ TaskAttribute attribute = root
+ .createAttribute(TaskAttribute.PREFIX_COMMENT + count);
+ commentMapper.applyTo(attribute);
+ count++;
+ }
+ return data;
+ }
+
+ /**
+ * Get gist url
+ *
+ * @param repositoryUrl
+ * @param gist
+ * @return url
+ */
+ public String getGistUrl(String repositoryUrl, Gist gist) {
+ return repositoryUrl + '/' + gist.getRepo();
+ }
+
+ /**
+ * Fill task data with data from gist
+ *
+ * @param data
+ * @param gist
+ * @return specified task data
+ */
+ public TaskData fillTaskData(TaskData data, Gist gist) {
+ TaskAttributeMapper mapper = data.getAttributeMapper();
+
+ TaskAttribute key = GistAttribute.KEY.create(data);
+ mapper.setValue(key, gist.getRepo());
+
+ TaskAttribute description = GistAttribute.DESCRIPTION.create(data);
+ mapper.setValue(description, gist.getDescription());
+
+ TaskAttribute created = GistAttribute.CREATED.create(data);
+ mapper.setDateValue(created, gist.getCreatedAt());
+
+ TaskAttribute url = GistAttribute.URL.create(data);
+ url.setValue(getGistUrl(data.getRepositoryUrl(), gist));
+
+ GistAttribute.COMMENT_NEW.create(data);
+
+ return data;
+ }
+
+ /**
+ * @see org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#postTaskData(org.eclipse.mylyn.tasks.core.TaskRepository,
+ * org.eclipse.mylyn.tasks.core.data.TaskData, java.util.Set,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public RepositoryResponse postTaskData(TaskRepository repository,
+ TaskData taskData, Set<TaskAttribute> oldAttributes,
+ IProgressMonitor monitor) throws CoreException {
+ return null;
+ }
+
+ /**
+ * @see org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#initializeTaskData(org.eclipse.mylyn.tasks.core.TaskRepository,
+ * org.eclipse.mylyn.tasks.core.data.TaskData,
+ * org.eclipse.mylyn.tasks.core.ITaskMapping,
+ * org.eclipse.core.runtime.IProgressMonitor)
+ */
+ public boolean initializeTaskData(TaskRepository repository, TaskData data,
+ ITaskMapping initializationData, IProgressMonitor monitor)
+ throws CoreException {
+ return true;
+ }
+
+ /**
+ * @see org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler#getAttributeMapper(org.eclipse.mylyn.tasks.core.TaskRepository)
+ */
+ public TaskAttributeMapper getAttributeMapper(TaskRepository taskRepository) {
+ return new GitHubTaskAttributeMapper(taskRepository);
+ }
+
+}