From 8f111d036c156f5afe1f388851d826e220838652 Mon Sep 17 00:00:00 2001 From: Toni Van de Voorde Date: Wed, 23 Jul 2014 11:38:56 +0200 Subject: [PATCH] Add mergeWith and copyTo method --- .../java/net/rcarz/jiraclient/Version.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/main/java/net/rcarz/jiraclient/Version.java b/src/main/java/net/rcarz/jiraclient/Version.java index d3b6517..da7b247 100644 --- a/src/main/java/net/rcarz/jiraclient/Version.java +++ b/src/main/java/net/rcarz/jiraclient/Version.java @@ -47,6 +47,52 @@ public class Version extends Resource { if (json != null) deserialise(json); } + + /** + * Merges the given version with current version + * + * @param version + * The version to merge + */ + public void mergeWith(Version version) { + + JSONObject req = new JSONObject(); + req.put("description", version.getDescription()); + req.put("name", version.getName()); + req.put("archived", version.isArchived()); + req.put("released", version.isReleased()); + req.put("releaseDate", version.getReleaseDate()); + + try { + restclient.put(Resource.getBaseUri() + "version/" + id, req); + } catch (Exception ex) { + throw new RuntimeException("Failed to merge", ex); + } + } + + /** + * Copies the version to the given project + * + * @param project + * The project the version will be copied to + */ + public void copyTo(Project project) { + + JSONObject req = new JSONObject(); + req.put("description", getDescription()); + req.put("name", getName()); + req.put("archived", isArchived()); + req.put("released", isReleased()); + req.put("releaseDate", getReleaseDate()); + req.put("project", project.getKey()); + req.put("projectId", project.getId()); + + try { + restclient.post(Resource.getBaseUri() + "version/", req); + } catch (Exception ex) { + throw new RuntimeException("Failed to copy to project '" + project.getKey() + "'", ex); + } + } /** * Retrieves the given version record.