Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfbecker2010-04-21 21:10:26 +0000
committerfbecker2010-04-21 21:10:26 +0000
commit610de152db7ae9172109bf0182ca48ad323ee95a (patch)
tree6e85f5a0eb238ff28a0f1227c036f83a0b4da9a4 /org.eclipse.mylyn.bugzilla.core
parentaa164611d33f5ff40d720aee7fe93aa0b7412335 (diff)
downloadorg.eclipse.mylyn.tasks-610de152db7ae9172109bf0182ca48ad323ee95a.tar.gz
org.eclipse.mylyn.tasks-610de152db7ae9172109bf0182ca48ad323ee95a.tar.xz
org.eclipse.mylyn.tasks-610de152db7ae9172109bf0182ca48ad323ee95a.zip
ASSIGNED - bug 282211: create Webservice API
https://bugs.eclipse.org/bugs/show_bug.cgi?id=282211
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.core')
-rw-r--r--org.eclipse.mylyn.bugzilla.core/META-INF/MANIFEST.MF4
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/BugzillaXmlRpcClient.java367
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/BugzillaXmlRpcOperation.java25
-rw-r--r--org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/XmlRpcClassCastException.java39
4 files changed, 434 insertions, 1 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/META-INF/MANIFEST.MF b/org.eclipse.mylyn.bugzilla.core/META-INF/MANIFEST.MF
index c7fcbc447..606fca09d 100644
--- a/org.eclipse.mylyn.bugzilla.core/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.bugzilla.core/META-INF/MANIFEST.MF
@@ -8,7 +8,9 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.mylyn.tasks.core;bundle-version="[3.0.0,4.0.0)",
org.eclipse.mylyn.commons.net;bundle-version="[3.0.0,4.0.0)",
org.eclipse.mylyn.commons.core;bundle-version="[3.0.0,4.0.0)",
- org.eclipse.core.net
+ org.eclipse.core.net,
+ org.eclipse.mylyn.commons.xmlrpc;bundle-version="[3.4.0,4.0.0)",
+ org.apache.xmlrpc
Bundle-ActivationPolicy: lazy
Bundle-Vendor: %Bundle-Vendor
Bundle-ClassPath: .
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/BugzillaXmlRpcClient.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/BugzillaXmlRpcClient.java
new file mode 100644
index 000000000..64114533a
--- /dev/null
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/BugzillaXmlRpcClient.java
@@ -0,0 +1,367 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Frank Becker and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Frank Becker - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.bugzilla.core.service;
+
+import java.util.Date;
+import java.util.HashMap;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.xmlrpc.XmlRpcException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.mylyn.commons.net.AbstractWebLocation;
+import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
+import org.eclipse.mylyn.commons.net.AuthenticationType;
+import org.eclipse.mylyn.internal.commons.xmlrpc.CommonXmlRpcClient;
+
+@SuppressWarnings("restriction")
+public class BugzillaXmlRpcClient extends CommonXmlRpcClient {
+
+ public static final String XML_BUGZILLA_VERSION = "Bugzilla.version"; //$NON-NLS-1$
+
+ public static final String XML_BUGZILLA_TIME = "Bugzilla.time"; //$NON-NLS-1$
+
+ public static final String XML_USER_LOGIN = "User.login"; //$NON-NLS-1$
+
+ public static final String XML_USER_GET = "User.get"; //$NON-NLS-1$
+
+ public static final String XML_BUG_FIELDS = "Bug.fields"; //$NON-NLS-1$
+
+ public static final String XML_PRODUCT_GET_SELECTABLE = "Product.get_selectable_products"; //$NON-NLS-1$
+
+ public static final String XML_PRODUCT_GET_ENTERABLE = "Product.get_enterable_products"; //$NON-NLS-1$
+
+ public static final String XML_PRODUCT_GET_ACCESSIBLE = "Product.get_accessible_products"; //$NON-NLS-1$
+
+ public static final String XML_PRODUCT_GET = "Product.get"; //$NON-NLS-1$
+
+ /*
+ * Parameter Definitions
+ *
+ */
+
+ public static final String XML_PARAMETER_LOGIN = "login"; //$NON-NLS-1$
+
+ public static final String XML_PARAMETER_PASSWORD = "password"; //$NON-NLS-1$
+
+ public static final String XML_PARAMETER_REMEMBER = "remember"; //$NON-NLS-1$
+
+ public static final String XML_PARAMETER_IDS = "ids"; //$NON-NLS-1$
+
+ public static final String XML_PARAMETER_NAMES = "names"; //$NON-NLS-1$
+
+ public static final String XML_PARAMETER_MATCH = "match"; //$NON-NLS-1$
+
+ /*
+ * Response Parameter Definitions
+ *
+ */
+
+ public static final String XML_RESPONSE_DB_TIME = "db_time"; //$NON-NLS-1$
+
+ public static final String XML_RESPONSE_WEB_TIME = "web_time"; //$NON-NLS-1$
+
+ public static final String[] XML_BUGZILLA_TIME_RESPONSE_TO_REMOVE = {
+ "tz_offset", "tz_short_name", "web_time_utc", "tz_name" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
+ public static final String XML_RESPONSE_VERSION = "version"; //$NON-NLS-1$
+
+ public static final String XML_RESPONSE_USERS = "users"; //$NON-NLS-1$
+
+ public static final String XML_RESPONSE_ID = "id"; //$NON-NLS-1$
+
+ public static final String XML_RESPONSE_IDS = "ids"; //$NON-NLS-1$
+
+ public static final String XML_RESPONSE_FIELDS = "fields"; //$NON-NLS-1$
+
+ public static final String XML_RESPONSE_PRODUCTS = "products"; //$NON-NLS-1$
+
+ /*
+ * Fields
+ *
+ */
+ private int userID = -1;
+
+ public BugzillaXmlRpcClient(AbstractWebLocation location, HttpClient client) {
+ super(location, client);
+ }
+
+ public BugzillaXmlRpcClient(AbstractWebLocation location) {
+ super(location);
+ }
+
+ public String getVersion() throws XmlRpcException {
+ return (new BugzillaXmlRpcOperation<String>(this) {
+ @Override
+ public String execute() throws XmlRpcException {
+ String result = ""; //$NON-NLS-1$
+ HashMap<?, ?> response = (HashMap<?, ?>) call(new NullProgressMonitor(), XML_BUGZILLA_VERSION,
+ (Object[]) null);
+ result = response2String(response, XML_RESPONSE_VERSION);
+ return result;
+ }
+ }).execute();
+ }
+
+ public Date getDBTime() throws XmlRpcException {
+ return (new BugzillaXmlRpcOperation<Date>(this) {
+ @Override
+ public Date execute() throws XmlRpcException {
+ Date result = null;
+ HashMap<?, ?> response = (HashMap<?, ?>) call(new NullProgressMonitor(), XML_BUGZILLA_TIME,
+ (Object[]) null);
+ result = response2Date(response, XML_RESPONSE_DB_TIME);
+ return result;
+ }
+ }).execute();
+ }
+
+ public Date getWebTime() throws XmlRpcException {
+ return (new BugzillaXmlRpcOperation<Date>(this) {
+ @Override
+ public Date execute() throws XmlRpcException {
+ Date result = null;
+ HashMap<?, ?> response = (HashMap<?, ?>) call(new NullProgressMonitor(), XML_BUGZILLA_TIME,
+ (Object[]) null);
+ result = response2Date(response, XML_RESPONSE_WEB_TIME);
+ return result;
+ }
+ }).execute();
+ }
+
+ public HashMap<?, ?> getTime() throws XmlRpcException {
+ return (new BugzillaXmlRpcOperation<HashMap<?, ?>>(this) {
+ @Override
+ public HashMap<?, ?> execute() throws XmlRpcException {
+ HashMap<?, ?> response = (HashMap<?, ?>) call(new NullProgressMonitor(), XML_BUGZILLA_TIME,
+ (Object[]) null);
+ if (response != null) {
+ for (String exclude : XML_BUGZILLA_TIME_RESPONSE_TO_REMOVE) {
+ response.remove(exclude);
+ }
+ }
+ return response;
+ }
+ }).execute();
+ }
+
+ public int login() throws XmlRpcException {
+ userID = -1;
+ final AuthenticationCredentials credentials = this.getLocation().getCredentials(AuthenticationType.REPOSITORY);
+ if (credentials != null) {
+ userID = (new BugzillaXmlRpcOperation<Integer>(this) {
+ @SuppressWarnings("serial")
+ @Override
+ public Integer execute() throws XmlRpcException {
+ HashMap<?, ?> response = (HashMap<?, ?>) call(new NullProgressMonitor(), XML_USER_LOGIN,
+ new Object[] { new HashMap<String, Object>() {
+ {
+ put(XML_PARAMETER_LOGIN, credentials.getUserName());
+ put(XML_PARAMETER_PASSWORD, credentials.getPassword());
+ put(XML_PARAMETER_REMEMBER, true);
+ }
+ } });
+ if (response != null) {
+ Integer result = response2Integer(response, XML_RESPONSE_ID);
+ return result;
+ }
+ return null;
+ }
+ }).execute();
+ }
+ return userID;
+ }
+
+ private Object[] getUserInfoInternal(final Object[] callParm) throws XmlRpcException {
+ return (new BugzillaXmlRpcOperation<Object[]>(this) {
+ @Override
+ public Object[] execute() throws XmlRpcException {
+ Object[] result = null;
+ HashMap<?, ?> response = (HashMap<?, ?>) call(new NullProgressMonitor(), XML_USER_GET, callParm);
+ result = response2ObjectArray(response, XML_RESPONSE_USERS);
+ return result;
+ }
+ }).execute();
+ }
+
+ @SuppressWarnings("serial")
+ public Object[] getUserInfoFromIDs(final Integer[] ids) throws XmlRpcException {
+ return getUserInfoInternal(new Object[] { new HashMap<String, Object[]>() {
+ {
+ put(XML_PARAMETER_IDS, ids);
+ }
+ } });
+ }
+
+ @SuppressWarnings("serial")
+ public Object[] getUserInfoFromNames(final String[] names) throws XmlRpcException {
+ return getUserInfoInternal(new Object[] { new HashMap<String, Object[]>() {
+ {
+ put(XML_PARAMETER_NAMES, names);
+ }
+ } });
+ }
+
+ public Object[] getUserInfoWithMatch(String[] matchs) throws XmlRpcException {
+ HashMap<String, Object[]> parmArray = new HashMap<String, Object[]>();
+ Object[] callParm = new Object[] { parmArray };
+ parmArray.put(XML_PARAMETER_MATCH, matchs);
+ return getUserInfoInternal(callParm);
+ }
+
+ private Object[] getFieldsInternal(final Object[] callParm) throws XmlRpcException {
+ return (new BugzillaXmlRpcOperation<Object[]>(this) {
+ @Override
+ public Object[] execute() throws XmlRpcException {
+ Object[] result = null;
+ HashMap<?, ?> response = (HashMap<?, ?>) call(new NullProgressMonitor(), XML_BUG_FIELDS, callParm);
+ result = response2ObjectArray(response, XML_RESPONSE_FIELDS);
+ return result;
+ }
+ }).execute();
+ }
+
+ public Object[] getAllFields() throws XmlRpcException {
+ return getFieldsInternal(null);
+ }
+
+ @SuppressWarnings("serial")
+ public Object[] getFieldsWithNames(final String[] names) throws XmlRpcException {
+ return getFieldsInternal(new Object[] { new HashMap<String, Object[]>() {
+ {
+ put(XML_PARAMETER_NAMES, names);
+ }
+ } });
+ }
+
+ @SuppressWarnings("serial")
+ public Object[] getFieldsWithIDs(final Integer[] ids) throws XmlRpcException {
+ return getFieldsInternal(new Object[] { new HashMap<String, Object[]>() {
+ {
+ put(XML_PARAMETER_IDS, ids);
+ }
+ } });
+ }
+
+ public Object[] getSelectableProducts() throws XmlRpcException {
+ return (new BugzillaXmlRpcOperation<Object[]>(this) {
+ @Override
+ public Object[] execute() throws XmlRpcException {
+ Object[] result = null;
+ HashMap<?, ?> response = (HashMap<?, ?>) call(new NullProgressMonitor(), XML_PRODUCT_GET_SELECTABLE,
+ (Object[]) null);
+ result = response2ObjectArray(response, XML_RESPONSE_IDS);
+ return result;
+ }
+ }).execute();
+ }
+
+ public Object[] getEnterableProducts() throws XmlRpcException {
+ return (new BugzillaXmlRpcOperation<Object[]>(this) {
+ @Override
+ public Object[] execute() throws XmlRpcException {
+ Object[] result = null;
+ HashMap<?, ?> response = (HashMap<?, ?>) call(new NullProgressMonitor(), XML_PRODUCT_GET_ENTERABLE,
+ (Object[]) null);
+ result = response2ObjectArray(response, XML_RESPONSE_IDS);
+ return result;
+ }
+ }).execute();
+ }
+
+ public Object[] getAccessibleProducts() throws XmlRpcException {
+ return (new BugzillaXmlRpcOperation<Object[]>(this) {
+ @Override
+ public Object[] execute() throws XmlRpcException {
+ Object[] result = null;
+ HashMap<?, ?> response = (HashMap<?, ?>) call(new NullProgressMonitor(), XML_PRODUCT_GET_ACCESSIBLE,
+ (Object[]) null);
+ result = response2ObjectArray(response, XML_RESPONSE_IDS);
+ return result;
+ }
+ }).execute();
+ }
+
+ public Object[] getProducts(final Integer[] ids) throws XmlRpcException {
+ return (new BugzillaXmlRpcOperation<Object[]>(this) {
+ @SuppressWarnings("serial")
+ @Override
+ public Object[] execute() throws XmlRpcException {
+ Object[] result = null;
+ HashMap<?, ?> response = (HashMap<?, ?>) call(new NullProgressMonitor(), XML_PRODUCT_GET,
+ new Object[] { new HashMap<String, Object[]>() {
+ {
+ put(XML_PARAMETER_IDS, ids);
+ }
+ } });
+ result = response2ObjectArray(response, XML_RESPONSE_PRODUCTS);
+ return result;
+ }
+ }).execute();
+ }
+
+ private Object[] response2ObjectArray(HashMap<?, ?> response, String name) throws XmlRpcException {
+ Object[] result;
+ if (response == null) {
+ return null;
+ }
+ try {
+ result = (Object[]) response.get(name);
+ } catch (ClassCastException e) {
+ result = null;
+ throw new XmlRpcClassCastException(e);
+ }
+ return result;
+ }
+
+ private Integer response2Integer(HashMap<?, ?> response, String name) throws XmlRpcException {
+ Integer result;
+ if (response == null) {
+ return null;
+ }
+ try {
+ result = (Integer) response.get(name);
+ } catch (ClassCastException e) {
+ result = null;
+ throw new XmlRpcClassCastException(e);
+ }
+ return result;
+ }
+
+ private String response2String(HashMap<?, ?> response, String name) throws XmlRpcException {
+ String result;
+ if (response == null) {
+ return null;
+ }
+ try {
+ result = (String) response.get(name);
+ } catch (ClassCastException e) {
+ result = null;
+ throw new XmlRpcClassCastException(e);
+ }
+ return result;
+ }
+
+ private Date response2Date(HashMap<?, ?> response, String name) throws XmlRpcException {
+ Date result;
+ if (response == null) {
+ return null;
+ }
+ try {
+ result = (Date) response.get(name);
+ } catch (ClassCastException e) {
+ result = null;
+ throw new XmlRpcClassCastException(e);
+ }
+ return result;
+ }
+
+}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/BugzillaXmlRpcOperation.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/BugzillaXmlRpcOperation.java
new file mode 100644
index 000000000..99344c506
--- /dev/null
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/BugzillaXmlRpcOperation.java
@@ -0,0 +1,25 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Frank Becker and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Frank Becker - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.bugzilla.core.service;
+
+import org.eclipse.mylyn.internal.commons.xmlrpc.CommonXmlRpcClient;
+import org.eclipse.mylyn.internal.commons.xmlrpc.XmlRpcOperation;
+
+@SuppressWarnings("restriction")
+public abstract class BugzillaXmlRpcOperation<T> extends XmlRpcOperation<T> {
+
+ public BugzillaXmlRpcOperation(CommonXmlRpcClient client) {
+ super(client);
+ // ignore
+ }
+
+}
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/XmlRpcClassCastException.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/XmlRpcClassCastException.java
new file mode 100644
index 000000000..81df23d1a
--- /dev/null
+++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/service/XmlRpcClassCastException.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Frank Becker and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Frank Becker - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.bugzilla.core.service;
+
+import org.apache.xmlrpc.XmlRpcException;
+
+public class XmlRpcClassCastException extends XmlRpcException {
+
+ private static final long serialVersionUID = -4092811363954657375L;
+
+ public XmlRpcClassCastException(String pMessage) {
+ super(pMessage);
+ }
+
+ public XmlRpcClassCastException(int pCode, String pMessage) {
+ super(pCode, pMessage);
+ }
+
+ public XmlRpcClassCastException(String pMessage, Throwable pLinkedException) {
+ super(pMessage, pLinkedException);
+ }
+
+ public XmlRpcClassCastException(int pCode, String pMessage, Throwable pLinkedException) {
+ super(pCode, pMessage, pLinkedException);
+ }
+
+ public XmlRpcClassCastException(Throwable pLinkedException) {
+ super("XMLRPC Cast error: " + pLinkedException.getMessage(), pLinkedException); //$NON-NLS-1$
+ }
+}

Back to the top