Commits

Jacek Jaroczynski  committed 0d9eb87

rest (get issues)

  • Participants
  • Parent commits 1739c8c

Comments (0)

Files changed (6)

File com.atlassian.connector.eclipse.jira.core/META-INF/MANIFEST.MF

  org.eclipse.mylyn.tasks.core;bundle-version="[3.0.0,4.0.0)",
  com.atlassian.connector.eclipse.commons.core;visibility:=reexport,
  com.atlassian.connector.eclipse.jira.restclient;bundle-version="3.0.7",
- org.joda.time;bundle-version="1.6.0"
+ org.joda.time;bundle-version="1.6.0",
+ org.eclipse.mylyn.tasks.ui;bundle-version="[3.0.0,4.0.0)"
 Import-Package: org.eclipse.mylyn.internal.monitor.ui
 Bundle-ActivationPolicy: lazy
 Export-Package: com.atlassian.connector.eclipse.internal.jira.core;x-friends:="com.atlassian.connector.eclipse.jira.ui",

File com.atlassian.connector.eclipse.jira.core/src/com/atlassian/connector/eclipse/internal/jira/core/JiraTaskDataHandler.java

 import org.eclipse.core.runtime.SubProgressMonitor;
 import org.eclipse.mylyn.commons.core.StatusHandler;
 import org.eclipse.mylyn.commons.net.Policy;
+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
 import org.eclipse.mylyn.tasks.core.IRepositoryPerson;
 import org.eclipse.mylyn.tasks.core.ITask;
 import org.eclipse.mylyn.tasks.core.ITaskMapping;
 	private JiraIssue getJiraIssue(JiraClient client, String taskId, String repositoryUrl, IProgressMonitor monitor) //
 			throws CoreException, JiraException {
 		try {
-			int id = Integer.parseInt(taskId);
+//			int id = Integer.parseInt(taskId);
 			// TODO consider keeping a cache of id -> key in the JIRA core plug-in
-//			AbstractTask task = TasksUiPlugin.getTaskList().getTask(repositoryUrl, "" + id);
-//			if (task != null) {
-//				return client.getIssueByKey(task.getTaskKey(), monitor);
-//			} else {
-			String issueKey = client.getKeyFromId(id + "", monitor); //$NON-NLS-1$
-			return client.getIssueByKey(issueKey, monitor);
-//			}
+			ITask task = TasksUiPlugin.getTaskList().getTask(repositoryUrl, taskId);
+
+			if (task != null) {
+				return client.getIssueByKey(task.getTaskKey(), monitor);
+			} else {
+				// TODO REST: we use key as id temporary (check JiraRestConverter)
+				return client.getIssueByUrl(taskId, monitor);
+			}
 		} catch (NumberFormatException e) {
 			return client.getIssueByKey(taskId, monitor);
 		}

File com.atlassian.connector.eclipse.jira.core/src/com/atlassian/connector/eclipse/internal/jira/core/service/FilterDefinitionConverter.java

 import java.util.Map;
 import java.util.Set;
 
+import org.apache.commons.lang.StringUtils;
 import org.eclipse.core.runtime.Assert;
 import org.eclipse.core.runtime.IProgressMonitor;
 
 import com.atlassian.connector.eclipse.internal.jira.core.model.filter.PriorityFilter;
 import com.atlassian.connector.eclipse.internal.jira.core.model.filter.ProjectFilter;
 import com.atlassian.connector.eclipse.internal.jira.core.model.filter.RelativeDateRangeFilter;
+import com.atlassian.connector.eclipse.internal.jira.core.model.filter.RelativeDateRangeFilter.RangeType;
 import com.atlassian.connector.eclipse.internal.jira.core.model.filter.ResolutionFilter;
 import com.atlassian.connector.eclipse.internal.jira.core.model.filter.SpecificUserFilter;
 import com.atlassian.connector.eclipse.internal.jira.core.model.filter.StatusFilter;
 import com.atlassian.connector.eclipse.internal.jira.core.model.filter.UserFilter;
 import com.atlassian.connector.eclipse.internal.jira.core.model.filter.UserInGroupFilter;
 import com.atlassian.connector.eclipse.internal.jira.core.model.filter.VersionFilter;
-import com.atlassian.connector.eclipse.internal.jira.core.model.filter.RelativeDateRangeFilter.RangeType;
 
 /**
  * A JiraCustomQuery represents a custom query for issues from a Jira repository.
 		return sb.toString();
 	}
 
+	public String getJqlString(FilterDefinition filter) {
+		List<String> searchParams = new ArrayList<String>();
+
+		ProjectFilter projectFilter = filter.getProjectFilter();
+		if (projectFilter != null && projectFilter.getProjects().length > 0) {
+			StringBuilder param = new StringBuilder();
+			param.append("project in (");
+			List<String> projectKeys = new ArrayList<String>();
+			for (Project project : projectFilter.getProjects()) {
+				projectKeys.add(project.getKey());
+//				addParameter(sb, PROJECT_KEY, project.getId());
+			}
+			param.append(StringUtils.join(projectKeys, ","));
+			param.append(")");
+
+			searchParams.add(param.toString());
+		}
+
+//		ComponentFilter componentFilter = filter.getComponentFilter();
+//		if (componentFilter != null) {
+//			if (componentFilter.hasNoComponent()) {
+//				addParameter(sb, COMPONENT_KEY, COMPONENT_NONE);
+//			}
+//			if (componentFilter.getComponents() != null) {
+//				for (Component component : componentFilter.getComponents()) {
+//					addParameter(sb, COMPONENT_KEY, component.getId());
+//				}
+//			}
+//		}
+//
+//		VersionFilter fixForVersionFilter = filter.getFixForVersionFilter();
+//		if (fixForVersionFilter != null) {
+//			if (fixForVersionFilter.hasNoVersion()) {
+//				addParameter(sb, FIXFOR_KEY, VERSION_NONE);
+//			}
+//			if (fixForVersionFilter.isReleasedVersions()) {
+//				addParameter(sb, FIXFOR_KEY, VERSION_RELEASED);
+//			}
+//			if (fixForVersionFilter.isUnreleasedVersions()) {
+//				addParameter(sb, FIXFOR_KEY, VERSION_UNRELEASED);
+//			}
+//			if (fixForVersionFilter.getVersions() != null) {
+//				for (Version fixVersion : fixForVersionFilter.getVersions()) {
+//					addParameter(sb, FIXFOR_KEY, fixVersion.getId());
+//				}
+//			}
+//		}
+//
+//		VersionFilter reportedInVersionFilter = filter.getReportedInVersionFilter();
+//		if (reportedInVersionFilter != null) {
+//			if (reportedInVersionFilter.hasNoVersion()) {
+//				addParameter(sb, VERSION_KEY, VERSION_NONE);
+//			}
+//			if (reportedInVersionFilter.isReleasedVersions()) {
+//				addParameter(sb, VERSION_KEY, VERSION_RELEASED);
+//			}
+//			if (reportedInVersionFilter.isUnreleasedVersions()) {
+//				addParameter(sb, VERSION_KEY, VERSION_UNRELEASED);
+//			}
+//			if (reportedInVersionFilter.getVersions() != null) {
+//				for (Version reportedVersion : reportedInVersionFilter.getVersions()) {
+//					addParameter(sb, VERSION_KEY, reportedVersion.getId());
+//				}
+//			}
+//		}
+//
+//		IssueTypeFilter issueTypeFilter = filter.getIssueTypeFilter();
+//		if (issueTypeFilter != null) {
+//			for (IssueType issueType : issueTypeFilter.getIsueTypes()) {
+//				addParameter(sb, TYPE_KEY, issueType.getId());
+//			}
+//		}
+//
+//		StatusFilter statusFilter = filter.getStatusFilter();
+//		if (statusFilter != null) {
+//			for (JiraStatus status : statusFilter.getStatuses()) {
+//				addParameter(sb, STATUS_KEY, status.getId());
+//			}
+//		}
+//
+//		ResolutionFilter resolutionFilter = filter.getResolutionFilter();
+//		if (resolutionFilter != null) {
+//			Resolution[] resolutions = resolutionFilter.getResolutions();
+//			if (resolutions.length == 0) {
+//				addParameter(sb, RESOLUTION_KEY, UNRESOLVED); // Unresolved
+//			} else {
+//				for (Resolution resolution : resolutions) {
+//					addParameter(sb, RESOLUTION_KEY, resolution.getId());
+//				}
+//			}
+//		}
+//
+//		PriorityFilter priorityFilter = filter.getPriorityFilter();
+//		if (priorityFilter != null) {
+//			for (Priority priority : priorityFilter.getPriorities()) {
+//				addParameter(sb, PRIORITY_KEY, priority.getId());
+//			}
+//		}
+//
+//		ContentFilter contentFilter = filter.getContentFilter();
+//		if (contentFilter != null) {
+//			String queryString = contentFilter.getQueryString();
+//			if (queryString != null) {
+//				addParameter(sb, QUERY_KEY, queryString);
+//			}
+//			if (contentFilter.isSearchingSummary()) {
+//				addParameter(sb, SUMMARY_KEY, "true"); //$NON-NLS-1$
+//			}
+//			if (contentFilter.isSearchingDescription()) {
+//				addParameter(sb, DESCRIPTION_KEY, "true"); //$NON-NLS-1$
+//			}
+//			if (contentFilter.isSearchingComments()) {
+//				addParameter(sb, BODY_KEY, "true"); //$NON-NLS-1$
+//			}
+//			if (contentFilter.isSearchingEnvironment()) {
+//				addParameter(sb, ENVIRONMENT_KEY, "true"); //$NON-NLS-1$
+//			}
+//		}
+//
+//		addUserFilter(sb, filter.getReportedByFilter(), REPORTER_KEY, ISSUE_NO_REPORTER);
+//		addUserFilter(sb, filter.getAssignedToFilter(), ASSIGNEE_KEY, UNASSIGNED);
+//
+//		addDateFilter(sb, filter.getCreatedDateFilter(), CREATED_KEY);
+//		addDateFilter(sb, filter.getUpdatedDateFilter(), UPDATED_KEY);
+//		addDateFilter(sb, filter.getDueDateFilter(), DUEDATE_KEY);
+//
+//		addOrdering(sb, filter.getOrdering());
+//
+//		EstimateVsActualFilter estimateFilter = filter.getEstimateVsActualFilter();
+//		if (estimateFilter != null) {
+//			float min = estimateFilter.getMinVariation();
+//			if (min != 0L) {
+//				addParameter(sb, "minRatioLimit", Float.toString(min)); //$NON-NLS-1$
+//			}
+//			float max = estimateFilter.getMaxVariation();
+//			if (max != 0L) {
+//				addParameter(sb, "maxRatioLimit", Float.toString(max)); //$NON-NLS-1$
+//			}
+//		}
+
+		return StringUtils.join(searchParams, " AND ");
+	}
+
 	private void addOrdering(StringBuilder sb, Order[] ordering) {
 		for (Order order : ordering) {
 			String fieldName = getNameFromField(order.getField());

File com.atlassian.connector.eclipse.jira.core/src/com/atlassian/connector/eclipse/internal/jira/core/service/JiraClient.java

 	public void findIssues(FilterDefinition filterDefinition, IssueCollector collector, IProgressMonitor monitor)
 			throws JiraException {
 		JiraCorePlugin.getMonitoring().logJob("findIssues", null); //$NON-NLS-1$
-		rssClient.findIssues(filterDefinition, collector, monitor);
+
+		FilterDefinitionConverter filterConverter = new FilterDefinitionConverter(getCharacterEncoding(monitor),
+				getLocalConfiguration().getDateFormat());
+
+		String jql = filterConverter.getJqlString(filterDefinition);
+
+		List<JiraIssue> issues = restClient.getIssues(jql);
+
+		if (!collector.isCancelled()) {
+			collector.start();
+
+			for (JiraIssue issue : issues) {
+				collector.collectIssue(issue);
+			}
+
+			collector.done();
+		}
+
+//		rssClient.findIssues(filterDefinition, collector, monitor);
 	}
 
 	/**
 //		return collector.getIssue();
 	}
 
+	public JiraIssue getIssueByUrl(String issueUrl, IProgressMonitor monitor) throws JiraException {
+		JiraCorePlugin.getMonitoring().logJob("getIssueByUrl", null); //$NON-NLS-1$
+
+		JiraIssue issue = restClient.getIssueByUrl(issueUrl, monitor);
+
+		return issue;
+	}
+
 	public IssueType[] getIssueTypes(IProgressMonitor monitor) throws JiraException {
 		JiraCorePlugin.getMonitoring().logJob("getIssueTypes", null); //$NON-NLS-1$
 

File com.atlassian.connector.eclipse.jira.core/src/com/atlassian/connector/eclipse/internal/jira/core/service/rest/JiraRestClientAdapter.java

 import java.io.ByteArrayInputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
+import java.util.ArrayList;
+import java.util.List;
 
 import org.eclipse.core.runtime.IProgressMonitor;
 
 	}
 
 	public JiraIssue getIssueByKey(String issueKey, IProgressMonitor monitor) throws JiraException {
-		return JiraRestConverter.convertIssue(getIssue(issueKey), cache, monitor);
+		return JiraRestConverter.convertIssue(getIssue(issueKey), cache /*, monitor*/);
 	}
 
 	public JiraStatus[] getStatuses() throws Exception {
 				.getIssueTypes());
 	}
 
+	public JiraIssue getIssueByUrl(String issueUrl, IProgressMonitor monitor) throws JiraException {
+
+		// TODO rest remove once we have id in place
+		// strip key from url
+		String key = issueUrl;
+
+		return JiraRestConverter.convertIssue(getIssue(key), cache /*, monitor*/);
+	}
+
+	public List<JiraIssue> getIssues(String jql) throws JiraException {
+		List<JiraIssue> issues = JiraRestConverter.convertIssues(restClient.getSearchClient()
+				.searchJql(jql, new NullProgressMonitor())
+				.getIssues());
+
+//		return issues;
+
+		List<JiraIssue> fullIssues = new ArrayList<JiraIssue>();
+
+		for (JiraIssue issue : issues) {
+			fullIssues.add(JiraRestConverter.convertIssue(getIssue(issue.getKey()), cache));
+		}
+
+		return fullIssues;
+	}
 }

File com.atlassian.connector.eclipse.jira.core/src/com/atlassian/connector/eclipse/internal/jira/core/service/rest/JiraRestConverter.java

 import java.util.ArrayList;
 import java.util.List;
 
-import org.eclipse.core.runtime.IProgressMonitor;
-
 import com.atlassian.connector.eclipse.internal.jira.core.model.IssueType;
 import com.atlassian.connector.eclipse.internal.jira.core.model.JiraIssue;
 import com.atlassian.connector.eclipse.internal.jira.core.model.Priority;
 import com.atlassian.connector.eclipse.internal.jira.core.model.Project;
 import com.atlassian.connector.eclipse.internal.jira.core.model.Resolution;
+import com.atlassian.connector.eclipse.internal.jira.core.model.Subtask;
 import com.atlassian.connector.eclipse.internal.jira.core.service.JiraClientCache;
 import com.atlassian.connector.eclipse.internal.jira.core.service.JiraException;
+import com.atlassian.jira.rest.client.domain.BasicIssue;
 import com.atlassian.jira.rest.client.domain.BasicProject;
 import com.atlassian.jira.rest.client.domain.Issue;
 
 		return outPriority;
 	}
 
-	public static JiraIssue convertIssue(Issue issue, JiraClientCache cache, IProgressMonitor monitor)
+	public static JiraIssue convertIssue(Issue issue, JiraClientCache cache /*, IProgressMonitor monitor*/)
 			throws JiraException {
 		JiraIssue jiraIssue = new JiraIssue();
 
 		// TODO rest: set real id if avaialble
-		jiraIssue.setId(Integer.toString(issue.getSelf().toString().hashCode()));
+		jiraIssue.setId(issue.getSelf().toString());
 		jiraIssue.setSelf(issue.getSelf());
 		jiraIssue.setKey(issue.getKey());
 		jiraIssue.setSummary(issue.getSummary());
 		jiraIssue.setDescription(issue.getDescription());
 //		jiraIssue.setParentId();
 //		jiraIssue.setParentKey();
+		// TODO rest: do we need to use cache here? can't we create priority and other objects from issue?
 		jiraIssue.setPriority(cache.getPriorityByName(issue.getPriority().getName()));
 		jiraIssue.setStatus(cache.getStatusByName(issue.getStatus().getName()));
 		jiraIssue.setAssignee(issue.getAssignee().getName());
 
 		Project project = cache.getProjectByKey(issue.getProject().getKey());
 		jiraIssue.setProject(project);
-		if (project != null && !project.hasDetails()) {
-			cache.refreshProjectDetails(project, monitor);
-		}
+//		if (project != null && !project.hasDetails()) {
+//			cache.refreshProjectDetails(project, monitor);
+//		}
 
 		jiraIssue.setCreated(issue.getCreationDate().toDate());
 		jiraIssue.setUpdated(issue.getUpdateDate().toDate());
 			jiraIssue.setType(cache.getIssueTypeById(issue.getIssueType().getId().toString()));
 		}
 
+		jiraIssue.setSubtasks(JiraRestConverter.convert(issue.getSubtasks()));
+
 		return jiraIssue;
 	}
 
+	private static Subtask[] convert(Iterable<com.atlassian.jira.rest.client.domain.Subtask> allSubtasks) {
+		List<Subtask> subtasks = new ArrayList<Subtask>();
+
+		for (com.atlassian.jira.rest.client.domain.Subtask subtask : allSubtasks) {
+			subtasks.add(convert(subtask));
+		}
+
+		return subtasks.toArray(new Subtask[subtasks.size()]);
+	}
+
+	private static Subtask convert(com.atlassian.jira.rest.client.domain.Subtask subtask) {
+		// TODO rest use real id if available 
+		return new Subtask(subtask.getIssueUri().toString(), subtask.getIssueKey());
+	}
+
 	public static IssueType[] convertIssueTypes(Iterable<com.atlassian.jira.rest.client.domain.IssueType> allIssueTypes) {
 		List<IssueType> issueTypes = new ArrayList<IssueType>();
 
 
 		return outIssueType;
 	}
+
+	public static List<JiraIssue> convertIssues(Iterable<BasicIssue> issues) {
+		List<JiraIssue> outIssues = new ArrayList<JiraIssue>();
+
+		for (BasicIssue issue : issues) {
+			outIssues.add(convert(issue));
+		}
+
+		return outIssues;
+	}
+
+	private static JiraIssue convert(BasicIssue issue) {
+		JiraIssue outIssue = new JiraIssue();
+
+		outIssue.setId(issue.getSelf().toString());
+		outIssue.setKey(issue.getKey());
+		outIssue.setSelf(issue.getSelf());
+
+		return outIssue;
+	}
 }