Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestClient.java33
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConfiguration.java9
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConnector.java18
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPostNewTask.java1
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestTaskAttributeMapper.java34
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/META-INF/MANIFEST.MF1
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/build.properties3
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestRepositoryConnectorUi.java35
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestQueryTypeWizardPage.java87
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestSearchQueryPage.java185
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestSearchQueryPageSchema.java48
-rw-r--r--connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestUiUtil.java106
12 files changed, 536 insertions, 24 deletions
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestClient.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestClient.java
index 105e7868c..26e06bcaf 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestClient.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestClient.java
@@ -16,7 +16,9 @@ import java.util.Map;
import java.util.Set;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.ISafeRunnable;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.SafeRunner;
import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.commons.core.StatusHandler;
import org.eclipse.mylyn.commons.core.operations.IOperationMonitor;
@@ -32,12 +34,14 @@ import org.eclipse.mylyn.internal.bugzilla.rest.core.response.data.ProductRespon
import org.eclipse.mylyn.internal.bugzilla.rest.core.response.data.PutUpdateResult;
import org.eclipse.mylyn.internal.bugzilla.rest.core.response.data.RestResponse;
import org.eclipse.mylyn.internal.bugzilla.rest.core.response.data.VersionResponse;
+import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
import org.eclipse.mylyn.tasks.core.RepositoryResponse;
import org.eclipse.mylyn.tasks.core.RepositoryResponse.ResponseKind;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.core.data.TaskDataCollector;
+import org.eclipse.osgi.util.NLS;
import com.google.common.base.Function;
import com.google.common.base.Joiner;
@@ -65,7 +69,7 @@ public class BugzillaRestClient {
public BugzillaRestVersion getVersion(IOperationMonitor monitor) throws BugzillaRestException {
- VersionResponse versionResponse = new BugzillaRestUnauthenticatedGetRequest<VersionResponse>(client, "/version",
+ VersionResponse versionResponse = new BugzillaRestUnauthenticatedGetRequest<VersionResponse>(client, "/version", //$NON-NLS-1$
new TypeToken<VersionResponse>() {
}).run(monitor);
return new BugzillaRestVersion(versionResponse.getVersion());
@@ -180,4 +184,31 @@ public class BugzillaRestClient {
}
+ public IStatus performQuery(TaskRepository taskRepository, final IRepositoryQuery query,
+ final TaskDataCollector resultCollector, IOperationMonitor monitor) throws BugzillaRestException {
+ String urlIDList = query.getUrl();
+ urlIDList = urlIDList.substring(urlIDList.indexOf("?") + 1); //$NON-NLS-1$
+ List<TaskData> taskDataArray = new BugzillaRestGetTaskData(client, connector, urlIDList, taskRepository)
+ .run(monitor);
+ for (final TaskData taskData : taskDataArray) {
+ taskData.setPartial(true);
+ SafeRunner.run(new ISafeRunnable() {
+
+ @Override
+ public void run() throws Exception {
+ resultCollector.accept(taskData);
+ }
+
+ @Override
+ public void handleException(Throwable exception) {
+ StatusHandler.log(new Status(IStatus.ERROR, BugzillaRestCore.ID_PLUGIN,
+ NLS.bind("Unexpected error during result collection. TaskID {0} in repository {1}", //$NON-NLS-1$
+ taskData.getTaskId(), taskData.getRepositoryUrl()),
+ exception));
+ }
+ });
+ }
+ return Status.OK_STATUS;
+ }
+
}
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConfiguration.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConfiguration.java
index 3dbf3bc8b..f70778574 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConfiguration.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConfiguration.java
@@ -344,7 +344,13 @@ public class BugzillaRestConfiguration implements Serializable {
}
public boolean updateProductOptions(@NonNull TaskData taskData) {
+ if (taskData == null) {
+ return false;
+ }
TaskAttribute attributeProduct = taskData.getRoot().getMappedAttribute(SCHEMA.PRODUCT.getKey());
+ if (attributeProduct == null) {
+ return false;
+ }
if (!attributeProduct.getValue().isEmpty()) {
Product actualProduct = getProductWithName(attributeProduct.getValue());
@@ -362,6 +368,9 @@ public class BugzillaRestConfiguration implements Serializable {
setAttributeOptionsForProduct(attributeTargetMilestone, actualProduct);
}
} else {
+ for (Product product : getProducts().values()) {
+ attributeProduct.putOption(product.getName(), product.getName());
+ }
TaskAttribute attributeComponent = taskData.getRoot().getMappedAttribute(SCHEMA.COMPONENT.getKey());
if (attributeComponent != null) {
setAllAttributeOptions(attributeComponent, getFieldWithName("component")); //$NON-NLS-1$
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConnector.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConnector.java
index e6b322abb..8dc2b3836 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConnector.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestConnector.java
@@ -23,6 +23,7 @@ import org.eclipse.core.runtime.Status;
import org.eclipse.mylyn.commons.core.operations.IOperationMonitor;
import org.eclipse.mylyn.commons.core.operations.OperationUtil;
import org.eclipse.mylyn.commons.net.AuthenticationCredentials;
+import org.eclipse.mylyn.commons.net.Policy;
import org.eclipse.mylyn.commons.repositories.core.RepositoryLocation;
import org.eclipse.mylyn.commons.repositories.core.auth.AuthenticationType;
import org.eclipse.mylyn.commons.repositories.core.auth.UserCredentials;
@@ -221,8 +222,21 @@ public class BugzillaRestConnector extends AbstractRepositoryConnector {
@Override
public IStatus performQuery(TaskRepository repository, IRepositoryQuery query, TaskDataCollector collector,
ISynchronizationSession session, IProgressMonitor monitor) {
- // ignore
- return null;
+ monitor = Policy.monitorFor(monitor);
+ try {
+ monitor.beginTask("performQuery", IProgressMonitor.UNKNOWN);
+ BugzillaRestClient client = getClient(repository);
+ IOperationMonitor progress = OperationUtil.convert(monitor, "performQuery", 3);
+ return client.performQuery(repository, query, collector, progress);
+ } catch (CoreException e) {
+ return new Status(IStatus.ERROR, BugzillaRestCore.ID_PLUGIN, IStatus.INFO,
+ "CoreException from performQuery", e);
+ } catch (BugzillaRestException e) {
+ return new Status(IStatus.ERROR, BugzillaRestCore.ID_PLUGIN, IStatus.INFO,
+ "BugzillaRestException from performQuery", e);
+ } finally {
+ monitor.done();
+ }
}
@Override
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPostNewTask.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPostNewTask.java
index 7b9b8a75c..8fe3c11b5 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPostNewTask.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestPostNewTask.java
@@ -107,7 +107,6 @@ public class BugzillaRestPostNewTask extends BugzillaRestAuthenticatedPostReques
throw new UnsupportedOperationException(
"TaskAttributeTypeAdapter in BugzillaRestPostNewTask only supports write"); //$NON-NLS-1$
}
-
}
@Override
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestTaskAttributeMapper.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestTaskAttributeMapper.java
index 8c4535ab8..6b899dc42 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestTaskAttributeMapper.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.core/src/org/eclipse/mylyn/internal/bugzilla/rest/core/BugzillaRestTaskAttributeMapper.java
@@ -43,18 +43,24 @@ public class BugzillaRestTaskAttributeMapper extends TaskAttributeMapper {
BugzillaRestConfiguration repositoryConfiguration;
try {
repositoryConfiguration = connector.getRepositoryConfiguration(this.getTaskRepository());
+ // TODO: change this when we have offline cache for the repository configuration so we build the options in an temp var
if (repositoryConfiguration != null) {
if (!productAttribute.getValue().equals("")) { //$NON-NLS-1$
- Product actualProduct = repositoryConfiguration.getProductWithName(productAttribute.getValue());
- if (attribute.getId()
- .equals(BugzillaRestCreateTaskSchema.getDefault().TARGET_MILESTONE.getKey())) {
- internalSetAttributeOptions(attribute, actualProduct.getMilestones());
- } else
- if (attribute.getId().equals(BugzillaRestCreateTaskSchema.getDefault().VERSION.getKey())) {
- internalSetAttributeOptions(attribute, actualProduct.getVersions());
- } else if (attribute.getId()
- .equals(BugzillaRestCreateTaskSchema.getDefault().COMPONENT.getKey())) {
- internalSetAttributeOptions(attribute, actualProduct.getComponents());
+ boolean found = false;
+ attribute.clearOptions();
+ for (String productName : productAttribute.getValues()) {
+ Product actualProduct = repositoryConfiguration.getProductWithName(productName);
+ if (attribute.getId()
+ .equals(BugzillaRestCreateTaskSchema.getDefault().COMPONENT.getKey())) {
+ internalSetAttributeOptions4Product(attribute, actualProduct.getComponents());
+
+ } else if (attribute.getId()
+ .equals(BugzillaRestCreateTaskSchema.getDefault().TARGET_MILESTONE.getKey())) {
+ internalSetAttributeOptions4Product(attribute, actualProduct.getMilestones());
+ } else if (attribute.getId()
+ .equals(BugzillaRestCreateTaskSchema.getDefault().VERSION.getKey())) {
+ internalSetAttributeOptions4Product(attribute, actualProduct.getVersions());
+ }
}
}
}
@@ -66,17 +72,15 @@ public class BugzillaRestTaskAttributeMapper extends TaskAttributeMapper {
return super.getOptions(attribute);
}
- private void internalSetAttributeOptions(TaskAttribute taskAttribute, SortableActiveEntry[] actualProductEntry) {
+ private void internalSetAttributeOptions4Product(TaskAttribute taskAttribute,
+ SortableActiveEntry[] actualProductEntry) {
boolean found = false;
String actualValue = taskAttribute.getValue();
- taskAttribute.clearOptions();
for (SortableActiveEntry SortableActiveEntry : actualProductEntry) {
if (SortableActiveEntry.isActive()) {
// TODO: remove when we have offline cache for the repository configuration
taskAttribute.putOption(SortableActiveEntry.getName(), SortableActiveEntry.getName());
- if (!found) {
- found = actualValue.equals(SortableActiveEntry.getName());
- }
+ found |= actualValue.equals(SortableActiveEntry.getName());
}
}
if (!found) {
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/META-INF/MANIFEST.MF b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/META-INF/MANIFEST.MF
index df91d31de..9466e1849 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/META-INF/MANIFEST.MF
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/META-INF/MANIFEST.MF
@@ -7,6 +7,7 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.ui,
org.eclipse.ui.forms,
org.eclipse.mylyn.commons.core;bundle-version="3.11.0",
+ org.eclipse.mylyn.commons.workbench;bundle-version="3.17.0",
org.eclipse.mylyn.commons.ui;bundle-version="3.11.0",
org.eclipse.mylyn.tasks.ui;bundle-version="3.11.0",
org.eclipse.mylyn.tasks.core;bundle-version="3.11.0",
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/build.properties b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/build.properties
index 9cbab3c13..101ae799c 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/build.properties
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/build.properties
@@ -2,5 +2,6 @@ source.. = src/
output.. = bin/
bin.includes = META-INF/,\
.,\
- about.html
+ about.html,\
+ plugin.xml
src.includes = about.html
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestRepositoryConnectorUi.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestRepositoryConnectorUi.java
index 9c83fff9c..f3cd48ce7 100644
--- a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestRepositoryConnectorUi.java
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/bugzilla/rest/ui/BugzillaRestRepositoryConnectorUi.java
@@ -12,14 +12,20 @@
package org.eclipse.mylyn.internal.bugzilla.rest.ui;
import org.eclipse.jface.wizard.IWizard;
+import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestConnector;
import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestCore;
+import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestTaskAttributeMapper;
+import org.eclipse.mylyn.internal.provisional.bugzilla.rest.ui.BugzillaRestQueryTypeWizardPage;
+import org.eclipse.mylyn.internal.provisional.bugzilla.rest.ui.BugzillaRestUiUtil;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
import org.eclipse.mylyn.tasks.core.ITaskMapping;
import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi;
import org.eclipse.mylyn.tasks.ui.wizards.ITaskRepositoryPage;
import org.eclipse.mylyn.tasks.ui.wizards.NewTaskWizard;
+import org.eclipse.mylyn.tasks.ui.wizards.RepositoryQueryWizard;
public class BugzillaRestRepositoryConnectorUi extends AbstractRepositoryConnectorUi {
@@ -42,8 +48,30 @@ public class BugzillaRestRepositoryConnectorUi extends AbstractRepositoryConnect
@Override
public IWizard getQueryWizard(TaskRepository repository, IRepositoryQuery query) {
- // ignore
- return null;
+ RepositoryQueryWizard wizard = new RepositoryQueryWizard(repository);
+ AbstractRepositoryConnector connector = getConnector();
+ BugzillaRestConnector connectorREST = (BugzillaRestConnector) connector;
+
+ TaskData taskData = new TaskData(new BugzillaRestTaskAttributeMapper(repository, connectorREST),
+ repository.getConnectorKind(), "Query", "Query");
+
+ if (query == null) {
+ wizard.addPage(new BugzillaRestQueryTypeWizardPage(repository, connector));
+ } else {
+ if (isCustomQuery(query)) {
+ wizard.addPage(BugzillaRestUiUtil.createBugzillaRestSearchPage(true, true, taskData, connectorREST,
+ repository, query));
+ } else {
+ wizard.addPage(BugzillaRestUiUtil.createBugzillaRestSearchPage(false, true, taskData, connectorREST,
+ repository, query));
+ }
+ }
+ return wizard;
+ }
+
+ private boolean isCustomQuery(IRepositoryQuery query2) {
+ String custom = query2.getAttribute("SimpleURLQueryPage");
+ return custom != null && custom.equals(Boolean.TRUE.toString());
}
@Override
@@ -53,8 +81,7 @@ public class BugzillaRestRepositoryConnectorUi extends AbstractRepositoryConnect
@Override
public boolean hasSearchPage() {
- // ignore
- return false;
+ return true;
}
}
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestQueryTypeWizardPage.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestQueryTypeWizardPage.java
new file mode 100644
index 000000000..559bc6c68
--- /dev/null
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestQueryTypeWizardPage.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.provisional.bugzilla.rest.ui;
+
+import org.eclipse.jface.dialogs.Dialog;
+import org.eclipse.jface.wizard.IWizardPage;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestConnector;
+import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestTaskAttributeMapper;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+import org.eclipse.mylyn.tasks.ui.TasksUiImages;
+import org.eclipse.mylyn.tasks.ui.wizards.AbstractRepositoryQueryPage2;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+
+public class BugzillaRestQueryTypeWizardPage extends WizardPage {
+
+ private final AbstractRepositoryQueryPage2 customPage;
+
+ private final AbstractRepositoryQueryPage2 searchPage;
+
+ private Button buttonCustom;
+
+ private Button buttonForm;
+
+ private Composite composite;
+
+ public BugzillaRestQueryTypeWizardPage(TaskRepository repository, AbstractRepositoryConnector connector) {
+ super("Choose query type");
+ setTitle("Choose query type");
+ setDescription("Select from the available query types.");
+ setImageDescriptor(TasksUiImages.BANNER_REPOSITORY);
+ BugzillaRestConnector connectorREST = (BugzillaRestConnector) connector;
+ TaskData taskDataSimpleURL = new TaskData(new BugzillaRestTaskAttributeMapper(repository, connectorREST),
+ repository.getConnectorKind(), "Query", "Query");
+ TaskData taskDataSearch = new TaskData(new BugzillaRestTaskAttributeMapper(repository, connectorREST),
+ repository.getConnectorKind(), "Query", "Query");
+ customPage = BugzillaRestUiUtil.createBugzillaRestSearchPage(true, false, taskDataSimpleURL, connectorREST,
+ repository, null);
+ searchPage = BugzillaRestUiUtil.createBugzillaRestSearchPage(false, false, taskDataSearch, connectorREST,
+ repository, null);
+ }
+
+ @Override
+ public void createControl(Composite parent) {
+ composite = new Composite(parent, SWT.NONE);
+ GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
+ gridData.grabExcessVerticalSpace = false;
+ composite.setLayoutData(gridData);
+ composite.setLayout(new GridLayout(1, false));
+
+ buttonForm = new Button(composite, SWT.RADIO);
+ buttonForm.setText("Cre&ate query using a form");
+ buttonForm.setSelection(true);
+
+ buttonCustom = new Button(composite, SWT.RADIO);
+ buttonCustom.setText("&Create query from existing URL");
+
+ setPageComplete(true);
+ setControl(composite);
+ Dialog.applyDialogFont(composite);
+ }
+
+ @Override
+ public IWizardPage getNextPage() {
+ if (buttonForm.getSelection()) {
+ searchPage.setWizard(this.getWizard());
+ return searchPage;
+ }
+ customPage.setWizard(this.getWizard());
+ return customPage;
+ }
+}
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestSearchQueryPage.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestSearchQueryPage.java
new file mode 100644
index 000000000..b23367d46
--- /dev/null
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestSearchQueryPage.java
@@ -0,0 +1,185 @@
+package org.eclipse.mylyn.internal.provisional.bugzilla.rest.ui;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLDecoder;
+import java.net.URLEncoder;
+import java.util.Map.Entry;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.mylyn.commons.core.StatusHandler;
+import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestConfiguration;
+import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestConnector;
+import org.eclipse.mylyn.internal.bugzilla.rest.ui.BugzillaRestUiPlugin;
+import org.eclipse.mylyn.internal.provisional.tasks.ui.wizards.AbstractQueryPageSchema;
+import org.eclipse.mylyn.internal.provisional.tasks.ui.wizards.QueryPageDetails;
+import org.eclipse.mylyn.internal.provisional.tasks.ui.wizards.RepositoryQuerySchemaPage;
+import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
+
+public class BugzillaRestSearchQueryPage extends RepositoryQuerySchemaPage {
+
+ public BugzillaRestSearchQueryPage(String pageName, TaskRepository repository, IRepositoryQuery query,
+ AbstractQueryPageSchema schema, TaskData data, QueryPageDetails pageDetails) {
+ super(pageName, repository, query, schema, data, pageDetails);
+ }
+
+ @Override
+ protected void doRefreshControls() {
+ try {
+ BugzillaRestConnector connectorREST = (BugzillaRestConnector) getConnector();
+ connectorREST.getRepositoryConfiguration(getTaskRepository()).updateProductOptions(targetTaskData);
+
+ for (Entry<String, AbstractAttributeEditor> entry : editorMap.entrySet()) {
+ entry.getValue().refresh();
+ }
+ } catch (CoreException e) {
+ StatusHandler.log(new Status(IStatus.ERROR, BugzillaRestUiPlugin.PLUGIN_ID,
+ "BugzillaRestSearchQueryPage could not refresh!", e)); //$NON-NLS-1$
+ }
+ }
+
+ @Override
+ protected boolean hasRepositoryConfiguration() {
+ return getRepositoryConfiguration() != null;
+ }
+
+ private BugzillaRestConfiguration getRepositoryConfiguration() {
+ try {
+ return ((BugzillaRestConnector) getConnector()).getRepositoryConfiguration(getTaskRepository());
+ } catch (CoreException e) {
+ StatusHandler.log(new Status(IStatus.ERROR, BugzillaRestUiPlugin.PLUGIN_ID,
+ "BugzillaRestSearchQueryPage could get the RepositoryConfiguration!", e)); //$NON-NLS-1$
+ }
+ return null;
+ }
+
+ @Override
+ protected boolean restoreState(IRepositoryQuery query) {
+ if (query != null) {
+ try {
+ restoreStateFromUrl(query.getUrl());
+ doRefreshControls();
+ return true;
+ } catch (UnsupportedEncodingException e) {
+ // ignore
+ }
+ }
+ return false;
+ }
+
+ private void restoreStateFromUrl(String queryUrl) throws UnsupportedEncodingException {
+ queryUrl = queryUrl.substring(queryUrl.indexOf("?") + 1); //$NON-NLS-1$
+ String[] options = queryUrl.split("&"); //$NON-NLS-1$
+ for (String option : options) {
+ String key;
+ int endindex = option.indexOf("="); //$NON-NLS-1$
+ if (endindex == -1) {
+ key = null;
+ } else {
+ key = option.substring(0, option.indexOf("=")); //$NON-NLS-1$
+ }
+ if (key == null || key.equals("order")) {
+ continue;
+ }
+ String value = URLDecoder.decode(option.substring(option.indexOf("=") + 1), //$NON-NLS-1$
+ getTaskRepository().getCharacterEncoding());
+ key = mapAttributeKey(key);
+ TaskAttribute attr = targetTaskData.getRoot().getAttribute(key);
+ if (attr != null) {
+ if (targetTaskData.getRoot().getAttribute(key).getValue().equals("")) {
+ targetTaskData.getRoot().getAttribute(key).setValue(value);
+ } else {
+ targetTaskData.getRoot().getAttribute(key).addValue(value);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected String getQueryUrl(String repsitoryUrl) {
+ return getQueryURL(repsitoryUrl, getQueryParameters());
+ }
+
+ private StringBuilder getQueryParameters() {
+ StringBuilder sb = new StringBuilder();
+ for (Entry<String, AbstractAttributeEditor> entry : editorMap.entrySet()) {
+ TaskAttribute attrib = targetTaskData.getRoot().getAttribute(entry.getKey());
+ for (String string : attrib.getValues()) {
+ if (string != null && !string.equals("")) {
+ try {
+ appendToBuffer(sb, mapUrlKey(entry.getKey()) + "=", URLEncoder
+ .encode(string.replaceAll(" ", "%20"), getTaskRepository().getCharacterEncoding())
+ .replaceAll("%2520", "%20"));
+ } catch (UnsupportedEncodingException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+ return sb;
+ }
+
+ private String getQueryURL(String repsitoryUrl, StringBuilder params) {
+ StringBuilder url = new StringBuilder(getQueryURLStart(repsitoryUrl));
+ url.append(params);
+
+ // HACK make sure that the searches come back sorted by priority. This
+ // should be a search option though
+ url.append("&order=Importance"); //$NON-NLS-1$
+ return url.toString();
+ }
+
+ /**
+ * Creates the bugzilla query URL start. Example: https://bugs.eclipse.org/bugs/buglist.cgi?
+ */
+ private String getQueryURLStart(String repsitoryUrl) {
+ return repsitoryUrl + (repsitoryUrl.endsWith("/") ? "" : "/") + "rest.cgi/bug?";
+ }
+
+ private void appendToBuffer(StringBuilder sb, String key, String value) {
+ if (sb.length() > 0) {
+ sb.append('&');
+ }
+ sb.append(key);
+ sb.append(value);
+ }
+
+ protected String mapUrlKey(String attributeKey) {
+ String key;
+ if (TaskAttribute.SUMMARY.equals(attributeKey)) {
+ key = "summary";
+ } else if (TaskAttribute.PRODUCT.equals(attributeKey)) {
+ key = "product";
+ } else if (TaskAttribute.COMPONENT.equals(attributeKey)) {
+ key = "component";
+ } else if (TaskAttribute.VERSION.equals(attributeKey)) {
+ key = "version";
+ } else {
+ key = attributeKey;
+ }
+ return key;
+ }
+
+ protected String mapAttributeKey(String attributeKey) {
+ String key;
+ if ("summary".equals(attributeKey)) {
+ key = TaskAttribute.SUMMARY;
+ } else if ("product".equals(attributeKey)) {
+ key = TaskAttribute.PRODUCT;
+ } else if ("component".equals(attributeKey)) {
+ key = TaskAttribute.COMPONENT;
+ } else if ("version".equals(attributeKey)) {
+ key = TaskAttribute.VERSION;
+ } else {
+ key = attributeKey;
+ }
+ return key;
+ }
+
+} \ No newline at end of file
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestSearchQueryPageSchema.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestSearchQueryPageSchema.java
new file mode 100644
index 000000000..f3f38cea8
--- /dev/null
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestSearchQueryPageSchema.java
@@ -0,0 +1,48 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.provisional.bugzilla.rest.ui;
+
+import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestTaskSchema;
+import org.eclipse.mylyn.internal.provisional.tasks.ui.wizards.AbstractQueryPageSchema;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+
+public class BugzillaRestSearchQueryPageSchema extends AbstractQueryPageSchema {
+
+ private final BugzillaRestTaskSchema parent = BugzillaRestTaskSchema.getDefault();
+
+ private static final BugzillaRestSearchQueryPageSchema instance = new BugzillaRestSearchQueryPageSchema();
+
+ public BugzillaRestSearchQueryPageSchema() {
+ }
+
+ public static BugzillaRestSearchQueryPageSchema getInstance() {
+ return instance;
+ }
+
+ public final Field summary = copyFrom(parent.SUMMARY).create();
+
+ public final Field product = copyFrom(parent.PRODUCT).type(TaskAttribute.TYPE_MULTI_SELECT)
+ .layoutPriority(11)
+ .create();
+
+ public final Field component = copyFrom(parent.COMPONENT).type(TaskAttribute.TYPE_MULTI_SELECT)
+ .layoutPriority(11)
+ .create();
+
+ public final Field version = copyFrom(parent.VERSION).type(TaskAttribute.TYPE_MULTI_SELECT)
+ .layoutPriority(11)
+ .create();
+
+ public final Field target_milestone = copyFrom(parent.TARGET_MILESTONE).type(TaskAttribute.TYPE_MULTI_SELECT)
+ .layoutPriority(11)
+ .create();
+}
diff --git a/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestUiUtil.java b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestUiUtil.java
new file mode 100644
index 000000000..80d600911
--- /dev/null
+++ b/connector-bugzilla-rest/org.eclipse.mylyn.bugzilla.rest.ui/src/org/eclipse/mylyn/internal/provisional/bugzilla/rest/ui/BugzillaRestUiUtil.java
@@ -0,0 +1,106 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.provisional.bugzilla.rest.ui;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.mylyn.internal.bugzilla.rest.core.BugzillaRestConnector;
+import org.eclipse.mylyn.internal.provisional.tasks.ui.wizards.QueryPageDetails;
+import org.eclipse.mylyn.internal.provisional.tasks.ui.wizards.SimpleURLQueryPageSchema;
+import org.eclipse.mylyn.tasks.core.IRepositoryQuery;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+
+public class BugzillaRestUiUtil {
+
+ protected static BugzillaRestSearchQueryPage createSimpleURLQueryPage(TaskData taskData,
+ BugzillaRestConnector connectorREST, TaskRepository repository) {
+ try {
+ SimpleURLQueryPageSchema.getInstance().initialize(taskData);
+ connectorREST.getRepositoryConfiguration(repository).updateProductOptions(taskData);
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return new BugzillaRestSearchQueryPage("Create query from URL", repository, null,
+ SimpleURLQueryPageSchema.getInstance(), taskData,
+ new QueryPageDetails(true, "buglist.cgi?", "Enter query parameters", "Please anter a title and an URL",
+ "([a-zA-Z][a-zA-Z+.-]{0,10}://[a-zA-Z0-9%._~!$&?#'()*+,;:@/=-]+)", "SimpleURLQueryPage"));
+ }
+
+ protected static BugzillaRestSearchQueryPage createBugzillaRestSearchQueryPage(TaskData taskData,
+ BugzillaRestConnector connectorREST, TaskRepository repository) {
+ try {
+ BugzillaRestSearchQueryPageSchema.getInstance().initialize(taskData);
+ connectorREST.getRepositoryConfiguration(repository).updateProductOptions(taskData);
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return new BugzillaRestSearchQueryPage("Create query from a form", repository, null,
+ BugzillaRestSearchQueryPageSchema.getInstance(), taskData,
+ new QueryPageDetails(true, "buglist.cgi?", "fill the form", "Please enter a title and fill the form",
+ "([a-zA-Z][a-zA-Z+.-]{0,10}://[a-zA-Z0-9%._~!$&?#'()*+,;:@/=-]+)", null));
+ }
+
+ public static BugzillaRestSearchQueryPage createBugzillaRestSearchPage(boolean simplePage, boolean updateMode,
+ TaskData taskData, BugzillaRestConnector connectorREST, TaskRepository repository, IRepositoryQuery query) {
+ BugzillaRestSearchQueryPage result = null;
+ if (simplePage && !updateMode) {
+ result = createSimpleURLQueryPage(taskData, connectorREST, repository);
+ }
+ if (!simplePage && !updateMode) {
+ result = createBugzillaRestSearchQueryPage(taskData, connectorREST, repository);
+ }
+ if (simplePage && updateMode) {
+ result = updateSimpleURLQueryPage(taskData, connectorREST, repository, query);
+ }
+ if (!simplePage && updateMode) {
+ result = updateBugzillaRestSearchQueryPage(taskData, connectorREST, repository, query);
+ }
+ return result;
+ }
+
+ protected static BugzillaRestSearchQueryPage updateSimpleURLQueryPage(TaskData taskData,
+ BugzillaRestConnector connectorREST, TaskRepository repository, IRepositoryQuery query) {
+ try {
+ SimpleURLQueryPageSchema.getInstance().initialize(taskData);
+ connectorREST.getRepositoryConfiguration(repository).updateProductOptions(taskData);
+ BugzillaRestSearchQueryPageSchema.getInstance().initialize(taskData);
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return new BugzillaRestSearchQueryPage("Create query from URL", repository, query,
+ SimpleURLQueryPageSchema.getInstance(), taskData,
+ new QueryPageDetails(true, "buglist.cgi?", "Enter query parameters", "Please anter a title and an URL",
+ "([a-zA-Z][a-zA-Z+.-]{0,10}://[a-zA-Z0-9%._~!$&?#'()*+,;:@/=-]+)", "SimpleURLQueryPage"));
+ }
+
+ protected static BugzillaRestSearchQueryPage updateBugzillaRestSearchQueryPage(TaskData taskData,
+ BugzillaRestConnector connectorREST, TaskRepository repository, IRepositoryQuery query) {
+ try {
+ BugzillaRestSearchQueryPageSchema.getInstance().initialize(taskData);
+ connectorREST.getTaskDataHandler().initializeTaskData(repository, taskData, null,
+ new NullProgressMonitor());
+ BugzillaRestSearchQueryPageSchema.getInstance().initialize(taskData);
+ } catch (CoreException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return new BugzillaRestSearchQueryPage("Create query from a form", repository, query,
+ BugzillaRestSearchQueryPageSchema.getInstance(), taskData,
+ new QueryPageDetails(true, "buglist.cgi?", "fill the form", "Please enter a title and fill the form",
+ "([a-zA-Z][a-zA-Z+.-]{0,10}://[a-zA-Z0-9%._~!$&?#'()*+,;:@/=-]+)", null));
+ }
+
+}

Back to the top