From 869ee63552e15bf606a2dcb2bd603251ba5fa48b Mon Sep 17 00:00:00 2001 From: Bob Carroll Date: Mon, 12 May 2014 20:34:24 -0700 Subject: [PATCH] moved deleteComponent to Component class for consistency, replaced getComponent with a passthrough to Component.get, and cleaned up URIs --- .../java/net/rcarz/jiraclient/Component.java | 17 ++++++++++-- .../java/net/rcarz/jiraclient/JiraClient.java | 26 +------------------ 2 files changed, 16 insertions(+), 27 deletions(-) diff --git a/src/main/java/net/rcarz/jiraclient/Component.java b/src/main/java/net/rcarz/jiraclient/Component.java index ea9b85e..1c0ed45 100644 --- a/src/main/java/net/rcarz/jiraclient/Component.java +++ b/src/main/java/net/rcarz/jiraclient/Component.java @@ -171,7 +171,7 @@ public class Component extends Resource { JSON result = null; try { - result = restclient.get(getBaseUri() + "component/" + id); + result = restclient.get(getRestUri(id)); } catch (Exception ex) { throw new JiraException("Failed to retrieve component " + id, ex); } @@ -198,7 +198,7 @@ public class Component extends Resource { private static String getRestUri(String id) { return getBaseUri() + "component/" + (id != null ? id : ""); } - + /** * Creates a new JIRA component. * @@ -211,5 +211,18 @@ public class Component extends Resource { FluentCreate fc = new FluentCreate(restclient, project); return fc; } + + /** + * Deletes a component from a project. + * + * @throws JiraException failed to delete the component + */ + public void delete() throws JiraException { + try { + restclient.delete(getRestUri(id)); + } catch (Exception ex) { + throw new JiraException("Failed to delete component " + id, ex); + } + } } diff --git a/src/main/java/net/rcarz/jiraclient/JiraClient.java b/src/main/java/net/rcarz/jiraclient/JiraClient.java index b48c5ac..8bd4ee2 100644 --- a/src/main/java/net/rcarz/jiraclient/JiraClient.java +++ b/src/main/java/net/rcarz/jiraclient/JiraClient.java @@ -421,30 +421,6 @@ public class JiraClient { * @throws JiraException failed to obtain the component */ public Component getComponent(String id) throws JiraException { - try { - URI uri = restclient.buildURI(Resource.getBaseUri() + "/component/" - + id); - JSON response = restclient.get(uri); - return new Component(restclient, ((JSONObject) response)); - } catch (Exception ex) { - throw new JiraException(ex.getMessage(), ex); - } - } - - /** - * Deletes a component from a project. - * - * @param id the component ID - * - * @throws JiraException failed to delete the component - */ - public void deleteComponent(String id) throws JiraException { - try { - URI uri = restclient.buildURI(Resource.getBaseUri() + "component/" - + id); - JSON response = restclient.delete(uri); - } catch (Exception ex) { - throw new JiraException(ex.getMessage(), ex); - } + return Component.get(restclient, id); } }