| author | Steffen Pingel | 2012-12-08 15:47:06 (EST) |
|---|---|---|
| committer | Steffen Pingel | 2012-12-08 15:57:29 (EST) |
| commit | 6a15b70c52501a22235d8cec9e910806af5c8fda (patch) (side-by-side diff) | |
| tree | 2bf5b684fd1ecbc9d89a5f97c3b3dc09f69813b3 | |
| parent | c6c540f90f8f2102135f5be8c70cb015e3a7fc7e (diff) | |
| download | org.eclipse.mylyn.tasks-6a15b70c52501a22235d8cec9e910806af5c8fda.zip org.eclipse.mylyn.tasks-6a15b70c52501a22235d8cec9e910806af5c8fda.tar.gz org.eclipse.mylyn.tasks-6a15b70c52501a22235d8cec9e910806af5c8fda.tar.bz2 | |
310545: changed Bugzilla tasks occasionally do not show as incomingrefs/changes/05/9105/3
Change-Id: I10322d4faa6c382f0fca02f93ccf2b8ab61ee04d
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=310545
3 files changed, 70 insertions, 37 deletions
diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttributeMapper.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttributeMapper.java index 7e0d240..e533289 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttributeMapper.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaAttributeMapper.java @@ -30,21 +30,21 @@ import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper; */ public class BugzillaAttributeMapper extends TaskAttributeMapper { - private final String dateFormat_1 = "yyyy-MM-dd HH:mm:ss"; //$NON-NLS-1$ + private static final String dateFormat_1 = "yyyy-MM-dd HH:mm:ss"; //$NON-NLS-1$ - private final String dateFormat_2 = "yyyy-MM-dd HH:mm"; //$NON-NLS-1$ + private static final String dateFormat_2 = "yyyy-MM-dd HH:mm"; //$NON-NLS-1$ - private final String dateFormat_3 = "yyyy-MM-dd"; //$NON-NLS-1$ + private static final String dateFormat_3 = "yyyy-MM-dd"; //$NON-NLS-1$ - private final String dateFormat_1_TimeZone = "yyyy-MM-dd HH:mm:ss Z"; //$NON-NLS-1$ + private static final String dateFormat_1_TimeZone = "yyyy-MM-dd HH:mm:ss Z"; //$NON-NLS-1$ - private final String dateFormat_2_TimeZone = "yyyy-MM-dd HH:mm z"; //$NON-NLS-1$ + private static final String dateFormat_2_TimeZone = "yyyy-MM-dd HH:mm z"; //$NON-NLS-1$ - private final String dateFormat_3_TimeZone = "yyyy-MM-dd z"; //$NON-NLS-1$ + private static final String dateFormat_3_TimeZone = "yyyy-MM-dd z"; //$NON-NLS-1$ // Order is significant - private final String[] dateFormats = { dateFormat_1_TimeZone, dateFormat_1, dateFormat_2_TimeZone, dateFormat_2, - dateFormat_3_TimeZone, dateFormat_3 }; + private static final String[] dateFormats = { dateFormat_1_TimeZone, dateFormat_1, dateFormat_2_TimeZone, + dateFormat_2, dateFormat_3_TimeZone, dateFormat_3 }; private final BugzillaRepositoryConnector connector; @@ -58,13 +58,11 @@ public class BugzillaAttributeMapper extends TaskAttributeMapper { if (attribute == null) { return null; } - String dateString = attribute.getValue(); - String id = attribute.getId(); - Date parsedDate = getDate(id, dateString); - if (parsedDate == null) { - parsedDate = super.getDateValue(attribute); + Date parsedDate = parseDate(attribute.getValue()); + if (parsedDate != null) { + return parsedDate; } - return parsedDate; + return super.getDateValue(attribute); } @Override @@ -90,20 +88,16 @@ public class BugzillaAttributeMapper extends TaskAttributeMapper { /** * Note: Date formatter constructed within method for thread safety */ - protected Date getDate(String attributeId, String dateString) { - Date parsedDate = null; - + public static final Date parseDate(String dateString) { for (String format : dateFormats) { try { SimpleDateFormat simpleFormatter = new SimpleDateFormat(format); - parsedDate = simpleFormatter.parse(dateString); - break; + return simpleFormatter.parse(dateString); } catch (ParseException e) { } catch (NumberFormatException e) { } } - - return parsedDate; + return null; } @Override diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java index 70d63d5..5908592 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaRepositoryConnector.java @@ -359,10 +359,14 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { changedTasks.add(changedTask); } } + if (syncSession.getData() == null && collector.getQueryTimestamp() != null) { - syncSession.setData(collector.getQueryTimestamp()); + Date queryDate = BugzillaAttributeMapper.parseDate(collector.getQueryTimestamp()); + if (queryDate != null) { + // Ensure time is in right format + syncSession.setData(new SimpleDateFormat(TIMESTAMP_WITH_OFFSET).format(queryDate)); + } } - } @Override @@ -391,19 +395,6 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { client.logout(monitor); client.getSearchHits(query, resultCollector, mapper, monitor); } - - if (resultCollector instanceof BugzillaTaskDataCollector) { - BugzillaTaskDataCollector bCollector = (BugzillaTaskDataCollector) resultCollector; - if (bCollector.getQueryTimestamp() != null) { - Date queryDate = ((BugzillaAttributeMapper) mapper).getDate(BugzillaAttribute.DELTA_TS.getKey(), - bCollector.getQueryTimestamp()); - if (queryDate != null) { - // Ensure time is in right format - event.setData(new SimpleDateFormat(TIMESTAMP_WITH_OFFSET).format(queryDate)); - } - } - } - return Status.OK_STATUS; } catch (UnrecognizedReponseException e) { return new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, IStatus.INFO, @@ -515,6 +506,7 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { @Override public void postSynchronization(ISynchronizationSession event, IProgressMonitor monitor) throws CoreException { + monitor = Policy.monitorFor(monitor); try { monitor.beginTask("", 1); //$NON-NLS-1$ if (event.isFullSynchronization() && event.getStatus() == null) { @@ -563,7 +555,7 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { } BugzillaAttributeMapper mapper = (BugzillaAttributeMapper) taskData.getAttributeMapper(); - Date oldModDate = mapper.getDate(BugzillaAttribute.DELTA_TS.getKey(), lastKnownMod); + Date oldModDate = BugzillaAttributeMapper.parseDate(lastKnownMod); Date newModDate = mapper.getDateValue(attrModification); // If either of the dates can't be parsed, fall back to string comparison diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java index 54dda35..14c67cc 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java @@ -32,6 +32,7 @@ import org.eclipse.mylyn.internal.bugzilla.core.BugzillaClient; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaOperation; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaStatus; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaTaskDataCollector; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaTaskDataHandler; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaUserMatchResponse; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaVersion; @@ -44,6 +45,7 @@ import org.eclipse.mylyn.internal.tasks.core.sync.SynchronizationSession; import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin; import org.eclipse.mylyn.internal.tasks.ui.util.AttachmentUtil; import org.eclipse.mylyn.internal.tasks.ui.util.TasksUiInternal; +import org.eclipse.mylyn.tasks.core.IRepositoryQuery; import org.eclipse.mylyn.tasks.core.ITask; import org.eclipse.mylyn.tasks.core.ITask.SynchronizationState; import org.eclipse.mylyn.tasks.core.RepositoryResponse; @@ -949,6 +951,51 @@ public class BugzillaRepositoryConnectorTest extends AbstractBugzillaTest { } } + public void testMissingHitsWhileTaskChanged() throws Exception { + String summary1 = "testMissingHitsWhileTaskChanged" + System.currentTimeMillis(); + TaskData data1 = BugzillaFixture.current().createTask(PrivilegeLevel.USER, summary1, null); + ITask task1 = generateLocalTaskAndDownload(data1.getTaskId()); + // ensure that time advances by 1 second between creation and query time + Thread.sleep(1000); + + repository = BugzillaFixture.current().repository(); + String stamp = data1.getRoot().getMappedAttribute(TaskAttribute.DATE_MODIFICATION).getValue(); + repository.setSynchronizationTimeStamp(stamp); + SynchronizationSession session = new SynchronizationSession(); + session.setFullSynchronization(true); + session.setTasks(Collections.singleton(task1)); + session.setTaskRepository(repository); + + // pre synchronization + connector.preSynchronization(session, null); + Object data = session.getData(); + assertNotNull(session.getData()); + assertEquals(Collections.singleton(task1), session.getStaleTasks()); + + // update task + data1.getRoot().getMappedAttribute(TaskAttribute.SUMMARY).setValue(summary1 + "updated"); + connector.getTaskDataHandler().postTaskData(repository, data1, null, null); + + // perform query + IRepositoryQuery query = TasksUi.getRepositoryModel().createRepositoryQuery(repository); + query.setUrl(repository.getUrl() + + "buglist.cgi?query_format=advanced&short_desc_type=allwordssubstr&short_desc=" + summary1); + BugzillaTaskDataCollector collector = new BugzillaTaskDataCollector(); + connector.performQuery(repository, query, collector, session, null); + assertEquals(data, session.getData()); + + // post synchronizaion + connector.postSynchronization(session, null); + assertFalse(stamp.equals(repository.getSynchronizationTimeStamp())); + + // second pre synchronization + SynchronizationSession session2 = new SynchronizationSession(); + session2.setTasks(Collections.singleton(task1)); + session2.setTaskRepository(repository); + connector.preSynchronization(session2, null); + assertEquals(Collections.singleton(task1), session2.getStaleTasks()); + } + public void testAnonymousRepositoryAccess() throws Exception { assertNotNull(repository); AuthenticationCredentials anonymousCreds = new AuthenticationCredentials("", ""); |

