From 4c53e07d3355fb9f656397e79767c109a4e911c9 Mon Sep 17 00:00:00 2001 From: Steffen Pingel Date: Sat, 8 Dec 2012 21:47:06 +0100 Subject: 310545: changed Bugzilla tasks occasionally do not show as incoming Change-Id: I10322d4faa6c382f0fca02f93ccf2b8ab61ee04d Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=310545 --- .../bugzilla/core/BugzillaAttributeMapper.java | 36 +++++++---------- .../bugzilla/core/BugzillaRepositoryConnector.java | 24 ++++------- .../tests/BugzillaRepositoryConnectorTest.java | 47 ++++++++++++++++++++++ 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 b920d0b65..866ba8df5 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 83eacf15c..6f0afcd6d 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 @@ -358,10 +358,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 @@ -390,19 +394,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, @@ -514,6 +505,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) { @@ -562,7 +554,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 1e6ae71cd..604c2d35c 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; @@ -940,6 +942,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("", ""); -- cgit v1.2.3