diff options
author | sminto | 2009-11-05 19:33:44 +0000 |
---|---|---|
committer | sminto | 2009-11-05 19:33:44 +0000 |
commit | 492e31efb480045e10670db3e0c2bb7b36c46efc (patch) | |
tree | 00e48230880135692ecb2b2b1689c1222c8e9acd /org.eclipse.mylyn.monitor.usage | |
parent | 30007b3b489e5ce963c014fdd276f0795e3cab34 (diff) | |
download | org.eclipse.mylyn.incubator-492e31efb480045e10670db3e0c2bb7b36c46efc.tar.gz org.eclipse.mylyn.incubator-492e31efb480045e10670db3e0c2bb7b36c46efc.tar.xz org.eclipse.mylyn.incubator-492e31efb480045e10670db3e0c2bb7b36c46efc.zip |
RESOLVED - bug 294364: [usage] UsageDataUploadManager.getNewUid assumes that is is running in the UI thread
https://bugs.eclipse.org/bugs/show_bug.cgi?id=294364
Diffstat (limited to 'org.eclipse.mylyn.monitor.usage')
8 files changed, 160 insertions, 115 deletions
diff --git a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/Messages.java b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/Messages.java index 8caf9dde..8d80a9b5 100644 --- a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/Messages.java +++ b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/Messages.java @@ -75,6 +75,8 @@ public class Messages extends NLS { public static String UsageUploadManager_Error_Uploading_X_No_Network; public static String UsageUploadManager_Error_Uploading_X_Y; + + public static String UsageUploadManager_Unable_To_Upload_X; static { // initialize resource bundle NLS.initializeMessages(BUNDLE_NAME, Messages.class); diff --git a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/UsageDataException.java b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/UsageDataException.java new file mode 100644 index 00000000..bee45d65 --- /dev/null +++ b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/UsageDataException.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2009 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.monitor.usage; + +/** + * @author Shawn Minto + */ +public class UsageDataException extends Exception { + + private static final long serialVersionUID = 3037413397893076406L; + + public UsageDataException(String message) { + this(message, null); + } + + public UsageDataException(String message, Exception cause) { + super(message, cause); + } + +}
\ No newline at end of file diff --git a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/UsageUploadManager.java b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/UsageUploadManager.java index 434781f2..35cedb32 100644 --- a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/UsageUploadManager.java +++ b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/UsageUploadManager.java @@ -33,13 +33,10 @@ import org.apache.commons.httpclient.methods.multipart.Part; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Status; -import org.eclipse.jface.dialogs.MessageDialog; -import org.eclipse.mylyn.commons.core.StatusHandler; import org.eclipse.mylyn.commons.net.AbstractWebLocation; import org.eclipse.mylyn.commons.net.WebLocation; import org.eclipse.mylyn.commons.net.WebUtil; import org.eclipse.osgi.util.NLS; -import org.eclipse.ui.PlatformUI; public class UsageUploadManager { @@ -47,7 +44,7 @@ public class UsageUploadManager { private static final int SIZE_OF_INT = 8; - public boolean uploadFile(final String postUrl, final File file, final int uid, IProgressMonitor monitor) { + public IStatus uploadFile(final String postUrl, final File file, final int uid, IProgressMonitor monitor) { // make sure that we send the uid with all files String filename = file.getName(); if (!filename.startsWith(uid + ".")) { //$NON-NLS-1$ @@ -57,7 +54,7 @@ public class UsageUploadManager { } - public boolean uploadFile(final String postUrl, final String name, final File file, final String filename, + public IStatus uploadFile(final String postUrl, final String name, final File file, final String filename, final int uid, IProgressMonitor monitor) { PostMethod filePost = new PostMethod(postUrl); @@ -72,69 +69,46 @@ public class UsageUploadManager { if (status == HttpStatus.SC_UNAUTHORIZED) { // The uid was incorrect so inform the user - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - public void run() { - MessageDialog.openError(null, Messages.UsageUploadManager_Error_Uploading, NLS.bind( - Messages.UsageUploadManager_Error_Uploading_Uid_Incorrect, file.getName(), uid)); - } - }); + return new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, status, NLS.bind( + Messages.UsageUploadManager_Error_Uploading_Uid_Incorrect, file.getName(), uid), + new Exception()); + } else if (status == HttpStatus.SC_PROXY_AUTHENTICATION_REQUIRED) { - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - public void run() { - MessageDialog.openError(null, Messages.UsageUploadManager_Error_Uploading, - Messages.UsageUploadManager_Error_Uploading_Proxy_Authentication); - } - }); + return new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, status, + Messages.UsageUploadManager_Error_Uploading_Proxy_Authentication, new Exception()); } else if (status != 200) { // there was a problem with the file upload so throw up an error // dialog to inform the user - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - public void run() { - MessageDialog.openError(null, Messages.UsageUploadManager_Error_Uploading, NLS.bind( - Messages.UsageUploadManager_Error_Uploading_Http_Response, file.getName(), status)); - } - }); + return new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, status, NLS.bind( + Messages.UsageUploadManager_Error_Uploading_Http_Response, file.getName(), status), + new Exception()); } else { // the file was uploaded successfully - return true; + return Status.OK_STATUS; } } catch (final FileNotFoundException e) { - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - public void run() { - MessageDialog.openError(null, Messages.UsageUploadManager_Error_Uploading, NLS.bind( - Messages.UsageUploadManager_Error_Uploading_X_Y, file.getName(), e.getClass() - .getCanonicalName())); - } - }); - StatusHandler.log(new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, - Messages.UsageUploadManager_Error_Uploading, e)); + return new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, NLS.bind( + Messages.UsageUploadManager_Error_Uploading_X_Y, file.getName(), e.getClass().getCanonicalName()), + e); + } catch (final IOException e) { if (e instanceof NoRouteToHostException || e instanceof UnknownHostException) { - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - public void run() { - MessageDialog.openError(null, Messages.UsageUploadManager_Error_Uploading, NLS.bind( - Messages.UsageUploadManager_Error_Uploading_X_No_Network, file.getName())); - } - }); + return new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, NLS.bind( + Messages.UsageUploadManager_Error_Uploading_X_No_Network, file.getName()), e); + } else { - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - public void run() { - MessageDialog.openError(null, Messages.UsageUploadManager_Error_Uploading, NLS.bind( - Messages.UsageUploadManager_Error_Uploading_X_Y, file.getName(), e.getClass() - .getCanonicalName())); - } - }); - StatusHandler.log(new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, "Error uploading", e)); //$NON-NLS-1$ + return new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, NLS.bind( + Messages.UsageUploadManager_Error_Uploading_X_Y, file.getName(), e.getClass() + .getCanonicalName()), e); } } finally { filePost.releaseConnection(); } - return false; } public int getExistingUid(StudyParameters studyParameters, String firstName, String lastName, String emailAddress, - boolean anonymous, IProgressMonitor monitor) { + boolean anonymous, IProgressMonitor monitor) throws UsageDataException { // TODO extract url for servlet String url = studyParameters.getUserIdServletUrl(); final GetMethod getUidMethod = new GetMethod(url); @@ -172,51 +146,26 @@ public class UsageUploadManager { int uid = Integer.parseInt(response); return uid; } else { - // there was a problem with the file upload so throw up an error - // dialog to inform the user - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - public void run() { - MessageDialog.openError(null, Messages.UsageUploadManager_Error_Getting_Uid, NLS.bind( - Messages.UsageUploadManager_Error_Getting_Uid_Http_Response, status)); - } - }); - return -1; + throw new UsageDataException(NLS.bind(Messages.UsageUploadManager_Error_Getting_Uid_Http_Response, + status)); } + } catch (UsageDataException e) { + throw e; } catch (final IOException e) { - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - public void run() { - MessageDialog.openError(null, Messages.UsageUploadManager_Error_Uploading, NLS.bind( - Messages.UsageUploadManager_Error_Getting_UidX_Y, e.getClass().getCanonicalName(), - e.getMessage())); - } - }); - StatusHandler.log(new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, - Messages.UsageUploadManager_Error_Uploading, e)); + throw new UsageDataException(NLS.bind(Messages.UsageUploadManager_Error_Getting_UidX_Y, e.getClass() + .getCanonicalName(), e.getMessage()), e); } catch (final Exception e) { if (e instanceof NoRouteToHostException || e instanceof UnknownHostException) { - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - public void run() { - MessageDialog.openError(null, Messages.UsageUploadManager_Error_Uploading, - Messages.UsageUploadManager_Error_Getting_Uid_No_Network); - } - }); + throw new UsageDataException(Messages.UsageUploadManager_Error_Getting_Uid_No_Network, e); } else { - PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { - public void run() { - MessageDialog.openError(null, Messages.UsageUploadManager_Error_Uploading, NLS.bind( - Messages.UsageUploadManager_Error_Getting_Uid_X_Y, e.getClass().getCanonicalName(), - e.getMessage())); - } - }); - StatusHandler.log(new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, - Messages.UsageUploadManager_Error_Uploading, e)); + throw new UsageDataException(NLS.bind(Messages.UsageUploadManager_Error_Getting_Uid_X_Y, e.getClass() + .getCanonicalName(), e.getMessage()), e); } } finally { getUidMethod.releaseConnection(); } - return -1; } private String getStringFromStream(InputStream i) throws IOException { @@ -230,7 +179,7 @@ public class UsageUploadManager { return data; } - public int getNewUid(StudyParameters studyParameters, IProgressMonitor monitor) { + public int getNewUid(StudyParameters studyParameters, IProgressMonitor monitor) throws UsageDataException { // TODO extract url for servlet String url = studyParameters.getUserIdServletUrl(); final PostMethod getUserIdMethod = new PostMethod(url); @@ -249,30 +198,26 @@ public class UsageUploadManager { inputStream.close(); return uid; } else { - StatusHandler.log(new Status(IStatus.WARNING, UiUsageMonitorPlugin.ID_PLUGIN, - "Unable to get new user id. Server retured: " + status)); //$NON-NLS-1$ - return -1; + throw new UsageDataException(NLS.bind(Messages.UsageUploadManager_Error_Getting_Uid_Http_Response, + status)); } } catch (final IOException e) { if (e instanceof NoRouteToHostException || e instanceof UnknownHostException) { - MessageDialog.openError(null, Messages.UsageUploadManager_Error_Uploading, - Messages.UsageUploadManager_Error_Getting_Uid_No_Network); + throw new UsageDataException(Messages.UsageUploadManager_Error_Getting_Uid_No_Network, e); } else { - MessageDialog.openError(null, Messages.UsageUploadManager_Error_Uploading, NLS.bind( - Messages.UsageUploadManager_Error_Getting_Uid_X, e.getClass().getCanonicalName())); - StatusHandler.log(new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, - Messages.UsageUploadManager_Error_Uploading, e)); + throw new UsageDataException(NLS.bind(Messages.UsageUploadManager_Error_Getting_Uid_X, e.getClass() + .getCanonicalName()), e); + } } finally { getUserIdMethod.releaseConnection(); } - return -1; } public int getNewUid(StudyParameters studyParameters, String firstName, String lastName, String emailAddress, boolean anonymous, String jobFunction, String companySize, String companyFunction, boolean contactEmail, - IProgressMonitor monitor) { + IProgressMonitor monitor) throws UsageDataException { return getNewUid(studyParameters, monitor); // TODO add back the code for dealing with creasting a user given a name // // NameValuePair first = new NameValuePair("firstName", firstName); diff --git a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/messages.properties b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/messages.properties index 4a0b3ca4..7566d4ce 100644 --- a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/messages.properties +++ b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/messages.properties @@ -28,3 +28,4 @@ UsageUploadManager_Error_Uploading_Proxy_Authentication=Could not upload because UsageUploadManager_Error_Uploading_Uid_Incorrect=There was an error uploading the {0}: \nYour uid was incorrect: {1}\n UsageUploadManager_Error_Uploading_X_No_Network=There was an error uploading the file: {0}\nNo network connection. Please try again later UsageUploadManager_Error_Uploading_X_Y=There was an error uploading the file{0}: \n{1} +UsageUploadManager_Unable_To_Upload_X=Unable to upload {0}. An unknown error occurred diff --git a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/wizards/GetNewUserIdPage.java b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/wizards/GetNewUserIdPage.java index 11f571ed..224b2ff1 100644 --- a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/wizards/GetNewUserIdPage.java +++ b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/wizards/GetNewUserIdPage.java @@ -26,6 +26,7 @@ import org.eclipse.jface.wizard.WizardPage; import org.eclipse.mylyn.commons.core.StatusHandler; import org.eclipse.mylyn.internal.monitor.usage.StudyParameters; import org.eclipse.mylyn.internal.monitor.usage.UiUsageMonitorPlugin; +import org.eclipse.mylyn.internal.monitor.usage.UsageDataException; import org.eclipse.osgi.util.NLS; import org.eclipse.swt.SWT; import org.eclipse.swt.browser.Browser; @@ -388,9 +389,15 @@ public class GetNewUserIdPage extends WizardPage { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - uid[0] = UiUsageMonitorPlugin.getDefault().getUploadManager().getNewUid( - studyParameters, first, last, email, anon, jobFunction, companySize, - companyFunction, contactEmail, monitor); + try { + uid[0] = UiUsageMonitorPlugin.getDefault().getUploadManager().getNewUid( + studyParameters, first, last, email, anon, jobFunction, companySize, + companyFunction, contactEmail, monitor); + } catch (UsageDataException e) { + StatusHandler.log(new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, + e.getMessage(), e)); + uid[0] = -1; + } } }); } catch (InvocationTargetException e1) { @@ -400,7 +407,7 @@ public class GetNewUserIdPage extends WizardPage { StatusHandler.log(new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, e1.getMessage(), e1)); } - if (uid[0] != -1) { + if (uid[0] != -1 && uid[0] != 0) { UiUsageMonitorPlugin.getDefault().getPreferenceStore().setValue( studyParameters.getUserIdPreferenceId(), uid[0]); if (wizard.getUploadPage() != null) { @@ -411,6 +418,9 @@ public class GetNewUserIdPage extends WizardPage { Messages.GetNewUserIdPage_X_User_Study_Id, studyParameters.getStudyName()), NLS.bind(Messages.GetNewUserIdPage_Your_X_User_Study_Id_Y, studyParameters.getStudyName(), wizard.getUid())); + } else { + MessageDialog.openError(null, Messages.UsageSubmissionWizard_Error_Getting_User_Id, + Messages.UsageSubmissionWizard_Unable_To_Get_New_User_Id); } } else { MessageDialog.openError(Display.getDefault().getActiveShell(), @@ -441,8 +451,14 @@ public class GetNewUserIdPage extends WizardPage { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - uid[0] = UiUsageMonitorPlugin.getDefault().getUploadManager().getExistingUid( - studyParameters, first, last, email, anon, monitor); + try { + uid[0] = UiUsageMonitorPlugin.getDefault().getUploadManager().getExistingUid( + studyParameters, first, last, email, anon, monitor); + } catch (UsageDataException e) { + uid[0] = -1; + StatusHandler.log(new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, + e.getMessage(), e)); + } } }); } catch (InvocationTargetException e1) { @@ -452,7 +468,7 @@ public class GetNewUserIdPage extends WizardPage { StatusHandler.log(new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, e1.getMessage(), e1)); } - if (uid[0] != -1) { + if (uid[0] != -1 && uid[0] != 0) { UiUsageMonitorPlugin.getDefault().getPreferenceStore().setValue( studyParameters.getUserIdPreferenceId(), uid[0]); @@ -465,7 +481,8 @@ public class GetNewUserIdPage extends WizardPage { NLS.bind(Messages.GetNewUserIdPage_Your_X_User_Study_Id_Y_Retrieve_By_Repeating, studyParameters.getStudyName(), wizard.getUid())); } else { - // TODO handle the error better here + MessageDialog.openError(null, Messages.UsageSubmissionWizard_Error_Getting_User_Id, + Messages.UsageSubmissionWizard_Unable_To_Get_New_User_Id); } } else { MessageDialog.openError(Display.getDefault().getActiveShell(), @@ -516,8 +533,14 @@ public class GetNewUserIdPage extends WizardPage { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - uid[0] = UiUsageMonitorPlugin.getDefault().getUploadManager().getNewUid( - studyParameters, monitor); + try { + uid[0] = UiUsageMonitorPlugin.getDefault().getUploadManager().getNewUid( + studyParameters, monitor); + } catch (UsageDataException e) { + uid[0] = -1; + StatusHandler.log(new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, + e.getMessage(), e)); + } } }); } catch (InvocationTargetException e1) { @@ -525,7 +548,7 @@ public class GetNewUserIdPage extends WizardPage { } catch (InterruptedException e1) { StatusHandler.log(new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, e1.getMessage(), e1)); } - if (uid[0] != -1) { + if (uid[0] != -1 && uid[0] != 0) { UiUsageMonitorPlugin.getDefault().getPreferenceStore().setValue( studyParameters.getUserIdPreferenceId(), uid[0]); if (wizard.getUploadPage() != null) { @@ -536,6 +559,9 @@ public class GetNewUserIdPage extends WizardPage { Messages.GetNewUserIdPage_X_User_Study_Id, studyParameters.getStudyName()), NLS.bind( Messages.GetNewUserIdPage_Your_X_User_Study_Id_Y_Record, studyParameters.getStudyName(), wizard.getUid())); + } else { + MessageDialog.openError(null, Messages.UsageSubmissionWizard_Error_Getting_User_Id, + Messages.UsageSubmissionWizard_Unable_To_Get_New_User_Id); } GetNewUserIdPage.this.setPageComplete(GetNewUserIdPage.this.isPageComplete()); } diff --git a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/wizards/Messages.java b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/wizards/Messages.java index 6a113103..1487ce64 100644 --- a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/wizards/Messages.java +++ b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/wizards/Messages.java @@ -139,8 +139,16 @@ public class Messages extends NLS { public static String UsageFileSelectionWizardPage_Please_Selected_Archived_Usage_Files; public static String UsageFileSelectionWizardPage_Select_Archived_File_To_Upload; + public static String UsageSubmissionWizard_Error_Getting_User_Id; + + public static String UsageSubmissionWizard_Error_Uploading_Usage_Data; + + public static String UsageSubmissionWizard_Error_While_Uploading; + public static String UsageSubmissionWizard_Successful_Upload; + public static String UsageSubmissionWizard_Unable_To_Get_New_User_Id; + public static String UsageSubmissionWizard_Upload_User_Statistics; public static String UsageSubmissionWizard_Uploading_User_Statistics; diff --git a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/wizards/UsageSubmissionWizard.java b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/wizards/UsageSubmissionWizard.java index a3744e64..c310f0a3 100644 --- a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/wizards/UsageSubmissionWizard.java +++ b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/wizards/UsageSubmissionWizard.java @@ -22,6 +22,7 @@ import java.util.List; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.MultiStatus; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.jobs.Job; @@ -36,6 +37,7 @@ import org.eclipse.mylyn.internal.monitor.usage.InteractionEventLogger; import org.eclipse.mylyn.internal.monitor.usage.MonitorFileRolloverJob; import org.eclipse.mylyn.internal.monitor.usage.StudyParameters; import org.eclipse.mylyn.internal.monitor.usage.UiUsageMonitorPlugin; +import org.eclipse.mylyn.internal.monitor.usage.UsageDataException; import org.eclipse.mylyn.monitor.core.InteractionEvent; import org.eclipse.mylyn.monitor.usage.AbstractStudyBackgroundPage; import org.eclipse.mylyn.monitor.usage.AbstractStudyQuestionnairePage; @@ -119,8 +121,14 @@ public class UsageSubmissionWizard extends Wizard implements INewWizard { service.run(false, true, new IRunnableWithProgress() { public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { - newUid[0] = UiUsageMonitorPlugin.getDefault().getUploadManager().getNewUid(studyParameters, - monitor); + try { + newUid[0] = UiUsageMonitorPlugin.getDefault().getUploadManager().getNewUid(studyParameters, + monitor); + } catch (UsageDataException e) { + StatusHandler.log(new Status(IStatus.ERROR, UiUsageMonitorPlugin.ID_PLUGIN, e.getMessage(), + e)); + newUid[0] = -1; + } } }); } catch (InvocationTargetException e1) { @@ -133,6 +141,16 @@ public class UsageSubmissionWizard extends Wizard implements INewWizard { UiUsageMonitorPlugin.getDefault().getPreferenceStore().setValue(studyParameters.getUserIdPreferenceId(), uid); } + + if (uid == 0 || uid == -1) { + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + public void run() { + MessageDialog.openError(null, Messages.UsageSubmissionWizard_Error_Getting_User_Id, + Messages.UsageSubmissionWizard_Unable_To_Get_New_User_Id); + } + }); + } + uploadPage = new UsageUploadWizardPage(this, studyParameters); fileSelectionPage = new UsageFileSelectionWizardPage(this, studyParameters); if (studyParameters.isBackgroundEnabled()) { @@ -206,10 +224,11 @@ public class UsageSubmissionWizard extends Wizard implements INewWizard { public void performUpload(IProgressMonitor monitor) { String servletUrl = studyParameters.getUploadServletUrl(); - boolean failed = false; + MultiStatus uploadStatus = new MultiStatus(UiUsageMonitorPlugin.ID_PLUGIN, 0, "Error uploading usage data", //$NON-NLS-1$ + null); if (studyParameters.isBackgroundEnabled() && performUpload && backgroundFile != null) { - failed = !UiUsageMonitorPlugin.getDefault().getUploadManager().uploadFile(servletUrl, backgroundFile, uid, - monitor); + uploadStatus.add(UiUsageMonitorPlugin.getDefault().getUploadManager().uploadFile(servletUrl, + backgroundFile, uid, monitor)); if (backgroundFile.exists()) { backgroundFile.delete(); @@ -217,8 +236,8 @@ public class UsageSubmissionWizard extends Wizard implements INewWizard { } if (studyParameters.isQuestionnaireEnabled() && performUpload && questionnaireFile != null) { - failed = !UiUsageMonitorPlugin.getDefault().getUploadManager().uploadFile(servletUrl, questionnaireFile, - uid, monitor); + uploadStatus.add(UiUsageMonitorPlugin.getDefault().getUploadManager().uploadFile(servletUrl, + questionnaireFile, uid, monitor)); if (questionnaireFile.exists()) { questionnaireFile.delete(); @@ -229,13 +248,14 @@ public class UsageSubmissionWizard extends Wizard implements INewWizard { return; } - failed = !UiUsageMonitorPlugin.getDefault().getUploadManager().uploadFile(servletUrl, zipFile, uid, monitor); + uploadStatus.add(UiUsageMonitorPlugin.getDefault().getUploadManager().uploadFile(servletUrl, zipFile, uid, + monitor)); if (zipFile.exists()) { zipFile.delete(); } - if (!failed) { + if (uploadStatus.isOK()) { UiUsageMonitorPlugin.getDefault().resetEventsSinceUpload(); PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { public void run() { @@ -245,6 +265,16 @@ public class UsageSubmissionWizard extends Wizard implements INewWizard { Messages.UsageSubmissionWizard_Your_Usage_Statistics_Have_Been_Uploaded); } }); + } else { + StatusHandler.log(uploadStatus); + PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() { + public void run() { + // popup a dialog telling the user that the upload was good + MessageDialog.openInformation(Display.getCurrent().getActiveShell(), + Messages.UsageSubmissionWizard_Error_Uploading_Usage_Data, + Messages.UsageSubmissionWizard_Error_While_Uploading); + } + }); } UiUsageMonitorPlugin.getDefault().getInteractionLogger().startMonitoring(); diff --git a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/wizards/messages.properties b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/wizards/messages.properties index 2588e92a..120c494b 100644 --- a/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/wizards/messages.properties +++ b/org.eclipse.mylyn.monitor.usage/src/org/eclipse/mylyn/internal/monitor/usage/wizards/messages.properties @@ -61,7 +61,11 @@ GetNewUserIdPage_Your_X_User_Study_Id_Y_Retrieve_By_Repeating=Your {0} user stuy NewUsageSummaryEditorWizard_New_Usage_Summary_Report=New Usage Summary Report UsageFileSelectionWizardPage_Please_Selected_Archived_Usage_Files=Please select the archived usage files you want to upload to UsageFileSelectionWizardPage_Select_Archived_File_To_Upload=Select any archived Mylyn usage files you wish to upload +UsageSubmissionWizard_Error_Getting_User_Id=Error Getting User Id +UsageSubmissionWizard_Error_Uploading_Usage_Data=Error Uploading Usage Data +UsageSubmissionWizard_Error_While_Uploading=An error occurred while uploading your usage data. Please see the Error Log for more details. UsageSubmissionWizard_Successful_Upload=Successful Upload +UsageSubmissionWizard_Unable_To_Get_New_User_Id=Unable to get a new user id. Please see the Error Log for more details. UsageSubmissionWizard_Upload_User_Statistics=Upload User Statistics UsageSubmissionWizard_Uploading_User_Statistics=Uploading user statistics UsageSubmissionWizard_X_Feedback={0} Feedback |