diff options
author | relves | 2009-09-09 18:57:33 +0000 |
---|---|---|
committer | relves | 2009-09-09 18:57:33 +0000 |
commit | 0925405e58d797b96cdefdbae944f2933438386f (patch) | |
tree | 1fed8b68043b549a8cab7fb07339df1d0b960fe1 /org.eclipse.mylyn.bugzilla.core | |
parent | 73f9c913981491fe4eee76b0c665a81315f7bb53 (diff) | |
download | org.eclipse.mylyn.tasks-0925405e58d797b96cdefdbae944f2933438386f.tar.gz org.eclipse.mylyn.tasks-0925405e58d797b96cdefdbae944f2933438386f.tar.xz org.eclipse.mylyn.tasks-0925405e58d797b96cdefdbae944f2933438386f.zip |
NEW - bug 288309: detect changes using date compare when time zone available on repository
https://bugs.eclipse.org/bugs/show_bug.cgi?id=288309
Diffstat (limited to 'org.eclipse.mylyn.bugzilla.core')
3 files changed, 63 insertions, 8 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 99f5a03ed..bdc2be37e 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 @@ -83,7 +83,7 @@ public class BugzillaAttributeMapper extends TaskAttributeMapper { /** * Note: Date formatters constructed within method for thread safety */ - private Date getDate(String attributeId, String dateString) { + protected Date getDate(String attributeId, String dateString) { Date parsedDate = null; /** 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 05e1a4cba..af51989a6 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 @@ -66,7 +66,11 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { private static final String COMMENT_FORMAT = "yyyy-MM-dd HH:mm"; //$NON-NLS-1$ - private static final String DEADLINE_FORMAT = "yyyy-MM-dd"; //$NON-NLS-1$ + //private static final String DEADLINE_FORMAT = "yyyy-MM-dd"; //$NON-NLS-1$ + + private static final String TIMESTAMP_WITH_OFFSET = "yyyy-MM-dd HH:mm:ss Z"; //$NON-NLS-1$ + + private static final long HOUR = 1000 * 60 * 60; private final BugzillaTaskAttachmentHandler attachmentHandler = new BugzillaTaskAttachmentHandler(this); @@ -76,7 +80,7 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { protected static BugzillaLanguageSettings enSetting; - protected final static Set<BugzillaLanguageSettings> languages = new LinkedHashSet<BugzillaLanguageSettings>(); + protected static final Set<BugzillaLanguageSettings> languages = new LinkedHashSet<BugzillaLanguageSettings>(); @Override public String getLabel() { @@ -312,7 +316,12 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { if (resultCollector instanceof BugzillaTaskDataCollector) { BugzillaTaskDataCollector bCollector = (BugzillaTaskDataCollector) resultCollector; if (bCollector.getQueryTimestamp() != null) { - event.setData(bCollector.getQueryTimestamp()); + 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)); + } } } @@ -488,15 +497,59 @@ public class BugzillaRepositoryConnector extends AbstractRepositoryConnector { String lastKnownMod = task.getAttribute(BugzillaAttribute.DELTA_TS.getKey()); if (lastKnownMod != null) { + TaskAttribute attrModification = taskData.getRoot().getMappedAttribute(TaskAttribute.DATE_MODIFICATION); - if (attrModification != null) { - return !lastKnownMod.equals(attrModification.getValue()); - } + if (attrModification != null && attrModification.getValue() != null + && attrModification.getValue().length() > 0) { + + boolean cachedHasTZ = hasTimzone(lastKnownMod); + boolean repoHasTZ = hasTimzone(attrModification.getValue()); + if (!cachedHasTZ && !repoHasTZ) { // State 1 + return !lastKnownMod.equals(attrModification.getValue()); + } + + BugzillaAttributeMapper mapper = (BugzillaAttributeMapper) taskData.getAttributeMapper(); + Date oldModDate = mapper.getDate(BugzillaAttribute.DELTA_TS.getKey(), lastKnownMod); + Date newModDate = mapper.getDateValue(attrModification); + + // If either of the dates can't be parsed, fall back to string comparison + if (oldModDate == null) { + ((AbstractTask) task).setStatus(new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, + "Unable to parse cached task modification timestamp " + lastKnownMod)); //$NON-NLS-1$ + return !lastKnownMod.equals(attrModification.getValue()); + } else if (newModDate == null) { + ((AbstractTask) task).setStatus(new Status(IStatus.ERROR, BugzillaCorePlugin.ID_PLUGIN, + "Unable to parse incoming task modification timestamp " + attrModification.getValue())); //$NON-NLS-1$ + return !lastKnownMod.equals(attrModification.getValue()); + } + if ((cachedHasTZ && !repoHasTZ) || (!cachedHasTZ && repoHasTZ)) { // State 2 (unlikely) || Sate 3 + long delta = Math.abs(newModDate.getTime() - oldModDate.getTime()); + if (delta == 0) { + return false; + } else if (delta > 0 && delta % HOUR == 0 && delta < 24 * HOUR) { + // If same time but in different time zones, ignore/migrate + return false; + } + return true; + } else if (cachedHasTZ && repoHasTZ) { //State 4 (of 4) + // Date Compare + return oldModDate.compareTo(newModDate) != 0; + } + } } return true; } + private boolean hasTimzone(String dateString) { + if (dateString == null || dateString.length() == 0) { + return false; + } + String[] parts = dateString.split(" "); //$NON-NLS-1$ + boolean hasTimeZone = (parts != null && parts.length == 3); + return hasTimeZone; + } + @Override public Collection<TaskRelation> getTaskRelations(TaskData taskData) { List<TaskRelation> relations = new ArrayList<TaskRelation>(); diff --git a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaVersion.java b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaVersion.java index 409a7b285..0842358ca 100644 --- a/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaVersion.java +++ b/org.eclipse.mylyn.bugzilla.core/src/org/eclipse/mylyn/internal/bugzilla/core/BugzillaVersion.java @@ -30,7 +30,9 @@ public class BugzillaVersion implements Comparable<BugzillaVersion>, Serializabl public final static BugzillaVersion BUGZILLA_3_2 = new BugzillaVersion("3.2"); //$NON-NLS-1$ - public final static BugzillaVersion MAX_VERSION = new BugzillaVersion("3.2"); //$NON-NLS-1$ + public final static BugzillaVersion BUGZILLA_3_4 = new BugzillaVersion("3.4"); //$NON-NLS-1$ + + public final static BugzillaVersion MAX_VERSION = new BugzillaVersion("3.4"); //$NON-NLS-1$ private final int major; |