Janusz Gorycki avatar Janusz Gorycki committed f7bbfde

PL-2739 - use JIRA REST API to talk to JIRA

Comments (0)

Files changed (25)

src/main/java/com/atlassian/jira/rest/client/MetadataRestClient.java

      */
     Iterable<IssuelinksType> getIssueLinkTypes(ProgressMonitor progressMonitor);
 
-	/**
+    /**
+     * Retrieves from the server complete list of available statuses
+     * @param progressMonitor progress monitor
+     * @return complete information about status resource
+     * @throws RestClientException in case of problems (connectivity, malformed messages, etc.)
+     * @since client 1.0, server 5.0
+     */
+    Iterable<Status> getStatuses(ProgressMonitor progressMonitor);
+
+    /**
 	 * Retrieves complete information about selected status
 	 * @param uri URI to this status resource (one can get it e.g. from <code>self</code> attribute
 	 * of <code>status</code> field of an issue)

src/main/java/com/atlassian/jira/rest/client/SearchRestClient.java

 
 package com.atlassian.jira.rest.client;
 
+import com.atlassian.jira.rest.client.domain.FavouriteFilter;
 import com.atlassian.jira.rest.client.domain.SearchResult;
 
 import javax.annotation.Nullable;
 	 * @throws RestClientException in case of problems (connectivity, malformed messages, invalid JQL query, etc.)
 	 */
 	SearchResult searchJql(@Nullable String jql, int maxResults, int startAt, ProgressMonitor progressMonitor);
+
+    /**
+     * @param pm
+     * @return list of your favourite filters
+     * @since 1.2 client 5.0 server
+     */
+    Iterable<FavouriteFilter> getFavouriteFilters(NullProgressMonitor pm);
 }

src/main/java/com/atlassian/jira/rest/client/domain/AddressableNamedEntity.java

  */
 public class AddressableNamedEntity implements AddressableEntity, NamedEntity {
 	protected final URI self;
-	protected final String name;
+    protected final String name;
 
 	public AddressableNamedEntity(URI self, String name) {
 		this.name = name;
 		this.self = self;
-	}
+    }
 
 	@Override
 	public URI getSelf() {
 		return name;
 	}
 
-	@Override
+    @Override
 	public String toString() {
 		return getToStringHelper().toString();
 	}

src/main/java/com/atlassian/jira/rest/client/domain/BasicProject.java

 package com.atlassian.jira.rest.client.domain;
 
 import com.atlassian.jira.rest.client.AddressableEntity;
+import com.atlassian.jira.rest.client.IdentifiableEntity;
 import com.atlassian.jira.rest.client.NamedEntity;
 import com.google.common.base.Objects;
 
  *
  * @since v0.1
  */
-public class BasicProject implements AddressableEntity, NamedEntity {
+public class BasicProject implements AddressableEntity, NamedEntity, IdentifiableEntity<Long> {
 	private final URI self;
 	private final String key;
     @Nullable
     @Nullable
     private final Long id;
 
-    public BasicProject(URI self, String key, String name) {
-		this(self, key, name, null);
-    }
-
-    public BasicProject(URI self, String key, String name, Long id) {
+    public BasicProject(URI self, String key, String name, @Nullable Long id) {
         this.self = self;
         this.key = key;
         this.name = name;
 				add("self", self).
 				add("key", key).
 				add("name", name)
-                .add("id", name);
+                .add("id", id);
 	}
 
 	@Override

src/main/java/com/atlassian/jira/rest/client/domain/BasicResolution.java

 
 package com.atlassian.jira.rest.client.domain;
 
+import com.atlassian.jira.rest.client.IdentifiableEntity;
+import org.jetbrains.annotations.Nullable;
+
 import java.net.URI;
 
 /**
  *
  * @since v0.1
  */
-public class BasicResolution extends AddressableNamedEntity {
+public class BasicResolution extends AddressableNamedEntity implements IdentifiableEntity<Long> {
+
+    @Nullable
+    private final Long id;
 
-	public BasicResolution(URI self, String name) {
+    public BasicResolution(URI self, String name, @Nullable Long id) {
 		super(self, name);
-	}
+        this.id = id;
+    }
+
+    @Override
+    public Long getId() {
+        return id;
+    }
 }

src/main/java/com/atlassian/jira/rest/client/domain/BasicStatus.java

 
 package com.atlassian.jira.rest.client.domain;
 
+import com.atlassian.jira.rest.client.IdentifiableEntity;
+import org.jetbrains.annotations.Nullable;
+
 import java.net.URI;
 
 /**
  *
  * @since v0.1
  */
-public class BasicStatus extends AddressableNamedEntity {
+public class BasicStatus extends AddressableNamedEntity implements IdentifiableEntity<Long> {
+    @Nullable
+    private final Long id;
 
-	public BasicStatus(URI self, String name) {
+    public BasicStatus(URI self, String name, @Nullable Long id) {
 		super(self, name);
-	}
-	
+        this.id = id;
+    }
+
+    @Override
+    public Long getId() {
+        return null;
+    }
 }

src/main/java/com/atlassian/jira/rest/client/domain/CimProject.java

 import com.atlassian.jira.rest.client.IssueRestClient;
 import com.atlassian.jira.rest.client.ProgressMonitor;
 import com.google.common.base.Objects;
+import org.jetbrains.annotations.Nullable;
 
 import java.net.URI;
 import java.util.Map;
 	private final Map<String, URI> avatarUris;
 	private final Iterable<CimIssueType> issueTypes;
 
-	public CimProject(URI self, String key, String name, Map<String, URI> avatarUris, Iterable<CimIssueType> issueTypes) {
-		super(self, key, name);
+	public CimProject(URI self, String key, String name, @Nullable Long id, Map<String, URI> avatarUris, Iterable<CimIssueType> issueTypes) {
+		super(self, key, name, id);
 		this.avatarUris = avatarUris;
 		this.issueTypes = issueTypes;
 	}

src/main/java/com/atlassian/jira/rest/client/domain/FavouriteFilter.java

+package com.atlassian.jira.rest.client.domain;
+
+import com.atlassian.jira.rest.client.IdentifiableEntity;
+import com.google.common.base.Objects;
+
+import java.net.URI;
+
+/**
+ * User: kalamon
+ * Date: 16.11.12
+ * Time: 11:31
+ */
+public class FavouriteFilter extends AddressableNamedEntity implements IdentifiableEntity<Long> {
+    private final Long id;
+    private final String jql;
+    private final URI viewUrl;
+    private final URI searchUrl;
+
+    public FavouriteFilter(URI self, String name, Long id, String jql, URI viewUrl, URI searchUrl) {
+        super(self, name);
+        this.id = id;
+        this.jql = jql;
+        this.viewUrl = viewUrl;
+        this.searchUrl = searchUrl;
+    }
+
+    @Override
+    public Long getId() {
+        return id;
+    }
+
+    public String getJql() {
+        return jql;
+    }
+
+    public URI getViewUrl() {
+        return viewUrl;
+    }
+
+    public URI getSearchUrl() {
+        return searchUrl;
+    }
+
+    @Override
+    public String toString() {
+        return getToStringHelper().toString();
+    }
+
+    protected Objects.ToStringHelper getToStringHelper() {
+        return Objects.toStringHelper(this).
+                add("self", self).
+                add("name", name).
+                add("id", id).
+                add("jql", jql).
+                add("searchUrl", searchUrl).
+                add("viewUrl", viewUrl);
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (obj instanceof FavouriteFilter) {
+            FavouriteFilter that = (FavouriteFilter) obj;
+            return Objects.equal(this.self, that.self)
+                    && Objects.equal(this.name, that.name)
+                    && Objects.equal(this.id, that.id)
+                    && Objects.equal(this.jql, that.jql)
+                    && Objects.equal(this.searchUrl, that.searchUrl)
+                    && Objects.equal(this.viewUrl, that.viewUrl);
+        }
+        return false;
+    }
+
+    @Override
+    public int hashCode() {
+        return Objects.hashCode(self, name, id, jql, searchUrl, viewUrl);
+    }
+}

src/main/java/com/atlassian/jira/rest/client/domain/Project.java

 	private final OptionalIterable<IssueType> issueTypes;
 	private final Collection<BasicProjectRole> projectRoles;
 
-	public Project(URI self, String key, String name, String description, BasicUser lead, URI uri,
+	public Project(URI self, String key, String name, @Nullable Long id, String description, BasicUser lead, URI uri,
 			Collection<Version> versions,Collection<BasicComponent> components,
 			OptionalIterable<IssueType> issueTypes, Collection<BasicProjectRole> projectRoles) {
-		super(self, key, name);
+		super(self, key, name, id);
 		this.description = description;
 		this.lead = lead;
 		this.uri = uri;

src/main/java/com/atlassian/jira/rest/client/domain/Resolution.java

 package com.atlassian.jira.rest.client.domain;
 
 import com.google.common.base.Objects;
+import org.jetbrains.annotations.Nullable;
 
 import java.net.URI;
 
  */
 public class Resolution extends BasicResolution {
 	private final String description;
-	public Resolution(URI self, String name, String description) {
-		super(self, name);
+	public Resolution(URI self, String name, String description, @Nullable Long id) {
+		super(self, name, id);
 		this.description = description;
 	}
 

src/main/java/com/atlassian/jira/rest/client/domain/Status.java

 package com.atlassian.jira.rest.client.domain;
 
 import com.google.common.base.Objects;
+import org.jetbrains.annotations.Nullable;
 
 import java.net.URI;
 
 public class Status extends BasicStatus {
 	private final String description;
 	private final URI iconUrl;
+    @Nullable
+    private final Long id;
 
-	public Status(URI self, String name, String description, URI iconUrl) {
-		super(self, name);
+    public Status(URI self, String name, String description, URI iconUrl) {
+        this(self, name, description, iconUrl, null);
+    }
+
+    public Status(URI self, String name, String description, URI iconUrl, @Nullable Long id) {
+		super(self, name, id);
 		this.description = description;
 		this.iconUrl = iconUrl;
+        this.id = id;
 	}
 
 	public String getDescription() {
 		return iconUrl;
 	}
 
-	@Override
+    @Nullable
+    public Long getId() {
+        return id;
+    }
+
+    @Override
 	public String toString() {
 		return getToStringHelper().
 				add("description", description).
 				add("iconUrl", iconUrl).
+                add("id", id).
 				toString();
 	}
 
 		if (obj instanceof Status) {
 			Status that = (Status) obj;
 			return super.equals(obj) && Objects.equal(this.description, that.description)
-					&& Objects.equal(this.iconUrl, that.iconUrl);
+					&& Objects.equal(this.iconUrl, that.iconUrl)
+                    && Objects.equal(this.id, that.id);
 		}
 		return false;
 	}
 
 	@Override
 	public int hashCode() {
-		return Objects.hashCode(super.hashCode(), description, iconUrl);
+		return Objects.hashCode(super.hashCode(), description, iconUrl, id);
 	}
 
 }

src/main/java/com/atlassian/jira/rest/client/internal/jersey/JerseyMetadataRestClient.java

 	private final IssueTypeJsonParser issueTypeJsonParser = new IssueTypeJsonParser();
 	private final GenericJsonArrayParser<IssueType> issueTypesJsonParser = GenericJsonArrayParser.create(issueTypeJsonParser);
 	private final StatusJsonParser statusJsonParser = new StatusJsonParser();
-	private final PriorityJsonParser priorityJsonParser = new PriorityJsonParser();
+    private final GenericJsonArrayParser<Status> statusesJsonParser = GenericJsonArrayParser.create(statusJsonParser);
+    private final PriorityJsonParser priorityJsonParser = new PriorityJsonParser();
 	private final GenericJsonArrayParser<Priority> prioritiesJsonParser = GenericJsonArrayParser.create(priorityJsonParser);
 	private final ResolutionJsonParser resolutionJsonParser = new ResolutionJsonParser();
 	private final GenericJsonArrayParser<Resolution> resolutionsJsonParser = GenericJsonArrayParser.create(resolutionJsonParser);
 		return getAndParse(uri, issueTypesJsonParser, progressMonitor);
 	}
 
-	@Override
+    @Override
 	public Iterable<IssuelinksType> getIssueLinkTypes(ProgressMonitor progressMonitor) {
 		final URI uri = UriBuilder.fromUri(baseUri).path("issueLinkType").build();
 		return getAndParse(uri, issueLinkTypesJsonParser, progressMonitor);
 	}
 
-	@Override
+    @Override
+    public Iterable<Status> getStatuses(ProgressMonitor progressMonitor) {
+        final URI uri = UriBuilder.fromUri(baseUri).path("status").build();
+        return getAndParse(uri, statusesJsonParser, progressMonitor);
+    }
+
+    @Override
 	public Status getStatus(final URI uri, ProgressMonitor progressMonitor) {
 		return getAndParse(uri, statusJsonParser, progressMonitor);
 	}

src/main/java/com/atlassian/jira/rest/client/internal/jersey/JerseySearchRestClient.java

 
 package com.atlassian.jira.rest.client.internal.jersey;
 
+import com.atlassian.jira.rest.client.NullProgressMonitor;
 import com.atlassian.jira.rest.client.ProgressMonitor;
 import com.atlassian.jira.rest.client.RestClientException;
 import com.atlassian.jira.rest.client.SearchRestClient;
+import com.atlassian.jira.rest.client.domain.FavouriteFilter;
 import com.atlassian.jira.rest.client.domain.SearchResult;
+import com.atlassian.jira.rest.client.internal.json.FavouriteFilterJsonParser;
+import com.atlassian.jira.rest.client.internal.json.GenericJsonArrayParser;
 import com.atlassian.jira.rest.client.internal.json.SearchResultJsonParser;
 import com.sun.jersey.client.apache.ApacheHttpClient;
 import org.codehaus.jettison.json.JSONException;
 	private static final int MAX_JQL_LENGTH_FOR_HTTP_GET = 500;
 	private static final String JQL_ATTRIBUTE = "jql";
 	private final SearchResultJsonParser searchResultJsonParser = new SearchResultJsonParser();
+    private final GenericJsonArrayParser<FavouriteFilter> favouriteFiltersJsonParser = GenericJsonArrayParser.create(new FavouriteFilterJsonParser());
 
 	private static final String SEARCH_URI_PREFIX = "search";
 	private final URI searchUri;
 			return getAndParse(uri, searchResultJsonParser, progressMonitor);
 		}
 	}
+
+    @Override
+    public Iterable<FavouriteFilter> getFavouriteFilters(NullProgressMonitor progressMonitor) {
+        final URI uri = UriBuilder.fromUri(baseUri).path("filter/favourite").build();
+        return getAndParse(uri, favouriteFiltersJsonParser, progressMonitor);
+    }
 }

src/main/java/com/atlassian/jira/rest/client/internal/json/BasicResolutionJsonParser.java

 	public BasicResolution parse(JSONObject json) throws JSONException {
 		final String name = json.getString("name");
 		final URI selfUri = JsonParseUtil.getSelfUri(json);
-		return new BasicResolution(selfUri, name);
+        final Long id = JsonParseUtil.getOptionalLong(json, "id");
+		return new BasicResolution(selfUri, name, id);
 	}
 }

src/main/java/com/atlassian/jira/rest/client/internal/json/BasicStatusJsonParser.java

     public BasicStatus parse(JSONObject json) throws JSONException {
 		final URI self = JsonParseUtil.getSelfUri(json);
 		final String name = json.getString("name");
-		return new BasicStatus(self, name);
+        final Long id = JsonParseUtil.getOptionalLong(json, "id");
+		return new BasicStatus(self, name, id);
 	}
 }

src/main/java/com/atlassian/jira/rest/client/internal/json/CimProjectJsonParser.java

 
 		final Map<String, URI> avatarUris = JsonParseUtil.getAvatarUris(json.getJSONObject("avatarUrls"));
 		return new CimProject(basicProject.getSelf(), basicProject.getKey(),
-				basicProject.getName(), avatarUris, issueTypes);
+				basicProject.getName(), basicProject.getId(), avatarUris, issueTypes);
 	}
 }

src/main/java/com/atlassian/jira/rest/client/internal/json/FavouriteFilterJsonParser.java

+package com.atlassian.jira.rest.client.internal.json;
+
+import com.atlassian.jira.rest.client.domain.FavouriteFilter;
+import org.codehaus.jettison.json.JSONException;
+import org.codehaus.jettison.json.JSONObject;
+
+import java.net.URI;
+
+/**
+ * User: kalamon
+ * Date: 16.11.12
+ * Time: 11:44
+ */
+public class FavouriteFilterJsonParser implements JsonObjectParser<FavouriteFilter>  {
+    @Override
+    public FavouriteFilter parse(JSONObject json) throws JSONException {
+        final URI selfUri = JsonParseUtil.getSelfUri(json);
+        final long id = json.getLong("id");
+        final String name = json.getString("name");
+        final String jql = json.getString("jql");
+        final URI searchUrl = JsonParseUtil.parseURI(json.getString("searchUrl"));
+        final URI viewUrl = JsonParseUtil.parseURI(json.getString("viewUrl"));
+        return new FavouriteFilter(selfUri, name, id, jql, viewUrl, searchUrl);
+    }
+}

src/main/java/com/atlassian/jira/rest/client/internal/json/ProjectJsonParser.java

 		final String key = json.getString("key");
         final String name = JsonParseUtil.getOptionalString(json, "name");
 		final String urlStr = JsonParseUtil.getOptionalString(json, "url");
+        final Long id = JsonParseUtil.getOptionalLong(json, "id");
 		URI uri;
 		try {
 			 uri = urlStr == null || "".equals(urlStr) ? null : new URI(urlStr);
 		final JSONArray issueTypesArray = json.optJSONArray("issueTypes");
 		final OptionalIterable<IssueType> issueTypes = JsonParseUtil.parseOptionalJsonArray(issueTypesArray, issueTypeJsonParser);
 		final Collection<BasicProjectRole> projectRoles = basicProjectRoleJsonParser.parse(JsonParseUtil.getOptionalJsonObject(json, "roles"));
-		return new Project(self, key, name, description, lead, uri, versions, components, issueTypes, projectRoles);
+		return new Project(self, key, name, id, description, lead, uri, versions, components, issueTypes, projectRoles);
 	}
 
 

src/main/java/com/atlassian/jira/rest/client/internal/json/ResolutionJsonParser.java

 	public Resolution parse(JSONObject json) throws JSONException {
 		final BasicResolution basicResolution = basicResolutionJsonParser.parse(json);
 		final String description = json.getString("description");
-		return new Resolution(basicResolution.getSelf(), basicResolution.getName(), description);
+        final Long id = JsonParseUtil.getOptionalLong(json, "id");
+		return new Resolution(basicResolution.getSelf(), basicResolution.getName(), description, id);
 	}
 }

src/main/java/com/atlassian/jira/rest/client/internal/json/StatusJsonParser.java

 		final BasicStatus basicStatus = basicStatusJsonParser.parse(json);
 		final String description = json.getString("description");
 		final URI iconUri = JsonParseUtil.parseURI(json.getString("iconUrl"));
-		return new Status(basicStatus.getSelf(), basicStatus.getName(), description, iconUri);
+        final Long id = JsonParseUtil.getOptionalLong(json, "id");
+        return new Status(basicStatus.getSelf(), basicStatus.getName(), description, iconUri, id);
 	}
 }

src/test/java/com/atlassian/jira/rest/client/internal/json/BasicProjectsJsonParserTest.java

 
 public class BasicProjectsJsonParserTest {
 
-	private static final BasicProject TST_PROJECT = new BasicProject(TestUtil.toUri("http://localhost:8090/jira/rest/api/latest/project/TST"), "TST", "Test Project");
+	private static final BasicProject TST_PROJECT = new BasicProject(TestUtil.toUri("http://localhost:8090/jira/rest/api/latest/project/TST"), "TST", "Test Project", null);
 	@Test
 	public void testParse() throws Exception {
 		BasicProjectsJsonParser parser = new BasicProjectsJsonParser();

src/test/java/com/atlassian/jira/rest/client/internal/json/BasicResolutionJsonParserTest.java

 	public void testParse() throws Exception {
 		final BasicResolutionJsonParser parser = new BasicResolutionJsonParser();
 		final BasicResolution basicresolution = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/resolution/valid.json"));
-		Assert.assertEquals(new BasicResolution(TestUtil.toUri("http://localhost:8090/jira/rest/api/latest/resolution/4"), "Incomplete"), basicresolution);
+		Assert.assertEquals(new BasicResolution(TestUtil.toUri("http://localhost:8090/jira/rest/api/latest/resolution/4"), "Incomplete", null), basicresolution);
 	}
 }

src/test/java/com/atlassian/jira/rest/client/internal/json/BasicStatusJsonParserTest.java

 	public void testParse() throws JSONException {
 		final BasicStatusJsonParser parser = new BasicStatusJsonParser();
 		final BasicStatus basicStatus = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/status/valid.json"));
-		Assert.assertEquals(new BasicStatus(TestUtil.toUri("http://localhost:8090/jira/rest/api/latest/status/1"), "Open"), basicStatus);
+		Assert.assertEquals(new BasicStatus(TestUtil.toUri("http://localhost:8090/jira/rest/api/latest/status/1"), "Open", null), basicStatus);
 	}
 }

src/test/java/com/atlassian/jira/rest/client/internal/json/IssueJsonParserTest.java

 	private void assertExpectedIssue(Issue issue) {
 		assertEquals("Testing issue", issue.getSummary());
 		assertEquals("TST-2", issue.getKey());
-		assertEquals(new BasicProject(toUri("http://localhost:8090/jira/rest/api/latest/project/TST"), "TST", null), issue.getProject());
+		assertEquals(new BasicProject(toUri("http://localhost:8090/jira/rest/api/latest/project/TST"), "TST", null, null), issue.getProject());
 		assertEquals("Major", issue.getPriority().getName());
 		assertNull(issue.getResolution());
 		assertEquals(toDateTime("2010-07-26T13:29:18.262+0200"), issue.getCreationDate());

src/test/java/com/atlassian/jira/rest/client/internal/json/ResolutionJsonParserTest.java

 		final ResolutionJsonParser parser = new ResolutionJsonParser();
 		final Resolution resolution = parser.parse(ResourceUtil.getJsonObjectFromResource("/json/resolution/complete.json"));
 		Assert.assertEquals(new Resolution(toUri("http://localhost:8090/jira/rest/api/latest/resolution/4"), "Incomplete",
-				"The problem is not completely described."), resolution);
+				"The problem is not completely described.", null), resolution);
 	}
 }
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.