Skip to content

Commit

Permalink
Migrate task data handler and attribute mapper to use new API
Browse files Browse the repository at this point in the history
Change-Id: I13f6d9928e16b70d46bff3cb3313edfc0fdf92d2
Signed-off-by: Kevin Sawicki <[email protected]>
Signed-off-by: Chris Aniszczyk <[email protected]>
  • Loading branch information
kevinsawicki authored and caniszczyk committed Apr 12, 2011
1 parent 22fe54e commit 0c4b3ac
Show file tree
Hide file tree
Showing 3 changed files with 174 additions and 149 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@
*******************************************************************************/
package org.eclipse.mylyn.github.internal;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

Expand All @@ -35,7 +38,6 @@
*/
public class GitHubRepositoryConnector extends AbstractRepositoryConnector {


/**
* GitHub kind.
*/
Expand All @@ -54,7 +56,7 @@ public class GitHubRepositoryConnector extends AbstractRepositoryConnector {
public GitHubRepositoryConnector() {
taskDataHandler = new GitHubTaskDataHandler(this);
}

/**
* {@inheritDoc}
*
Expand Down Expand Up @@ -108,70 +110,83 @@ public IStatus performQuery(TaskRepository repository,

IStatus result = Status.OK_STATUS;
String queryStatus = query.getAttribute("status");

String[] statuses;
if (queryStatus.equals("all")) {
statuses = new String[] {"open","closed"};
statuses = new String[] { "open", "closed" };
} else {
statuses = new String[] { queryStatus };
}

monitor.beginTask("Querying repository ...", statuses.length);
try {
String user = GitHub.computeTaskRepositoryUser(repository.getUrl());
String project = GitHub.computeTaskRepositoryProject(repository.getUrl());
GitHubCredentials credentials = GitHubCredentials.create(repository);

String project = GitHub.computeTaskRepositoryProject(repository
.getUrl());
GitHubCredentials credentials = GitHubCredentials
.create(repository);

GitHubClient client = new GitHubClient();
client.setCredentials(credentials.getUsername(),
credentials.getPassword());
IssueService service = new IssueService(client);

// perform query

for (String status: statuses) {
GitHubIssues issues = service.searchIssues(user, project,
status, query.getAttribute("queryText"), credentials);


for (String status : statuses) {
Map<String, String> filterData = new HashMap<String, String>();
filterData.put(IssueService.FILTER_STATE, status);

List<Issue> issues = service.getIssues(user, project,
filterData);

// collect task data
for (GitHubIssue issue : issues.getIssues()) {
for (Issue issue : issues) {
TaskData taskData = taskDataHandler.createPartialTaskData(
repository, monitor,user, project, issue);
repository, monitor, user, project, issue);
collector.accept(taskData);
}
monitor.worked(1);
}

result = Status.OK_STATUS;
} catch (GitHubServiceException e) {
} catch (IOException e) {
result = GitHub.createErrorStatus(e);
}

monitor.done();
return result;
}


@Override
public TaskData getTaskData(TaskRepository repository, String taskId,
IProgressMonitor monitor) throws CoreException {

String user = GitHub.computeTaskRepositoryUser(repository.getUrl());
String project = GitHub.computeTaskRepositoryProject(repository.getUrl());

String project = GitHub.computeTaskRepositoryProject(repository
.getUrl());

try {
GitHubCredentials credentials = GitHubCredentials.create(repository);
GitHubIssue issue = service.showIssue(user, project, taskId, credentials);
List<GitHubIssueComment> comments = null;
GitHubCredentials credentials = GitHubCredentials
.create(repository);
GitHubClient client = new GitHubClient();
client.setCredentials(credentials.getUsername(),
credentials.getPassword());
IssueService service = new IssueService(client);
Issue issue = service.getIssue(user, project, taskId);
List<Comment> comments = null;
if (issue.getComments() > 0) {
comments = service.getComments(user, project, issue,
credentials);
comments = service.getComments(user, project, taskId);
}
TaskData taskData = taskDataHandler.createTaskData(repository,
monitor, user, project, issue, comments);

return taskData;
} catch (GitHubServiceException e) {
} catch (IOException e) {
throw new CoreException(GitHub.createErrorStatus(e));
}
}


@Override
public String getRepositoryUrlFromTaskUrl(String taskFullUrl) {
if (taskFullUrl != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,43 @@
package org.eclipse.mylyn.github.internal;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.Date;
import java.util.List;

import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;

/**
* GitHub task attribute mapper class.
*/
public class GitHubTaskAttributeMapper extends TaskAttributeMapper {

private DateFormat dateFormat = SimpleDateFormat.getDateTimeInstance();

private DateFormat format = DateFormat.getDateTimeInstance(
DateFormat.MEDIUM, DateFormat.SHORT);

/**
* @param taskRepository
*/
public GitHubTaskAttributeMapper(TaskRepository taskRepository) {
super(taskRepository);
}

@Override
public String mapToRepositoryKey(TaskAttribute parent, String key) {
return key;
}

@Override
public Date getDateValue(TaskAttribute attribute) {
String value = attribute.getValue();
if (value != null) {
try {
return dateFormat.parse(value);
} catch (ParseException e) {
return super.getDateValue(attribute);
/**
* @see org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper#getValueLabels(org.eclipse.mylyn.tasks.core.data.TaskAttribute)
*/
public List<String> getValueLabels(TaskAttribute taskAttribute) {
if (TaskAttribute.TYPE_DATE.equals(taskAttribute.getMetaData()
.getType())) {
String date = taskAttribute.getValue();
if (date.length() > 0) {
synchronized (this.format) {
return Collections.singletonList(this.format
.format(new Date(Long.parseLong(date))));
}
}
}
return null;
return super.getValueLabels(taskAttribute);
}
}
Loading

0 comments on commit 0c4b3ac

Please sign in to comment.